Skip to content

Commit

Permalink
Fix internal consistency error
Browse files Browse the repository at this point in the history
Fixes #6163
  • Loading branch information
bjorng committed Jul 25, 2022
1 parent 0863bd3 commit c8e684e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/compiler/src/beam_ssa_opt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1077,13 +1077,15 @@ cse_suitable(#b_set{}) -> false.
-record(fs,
{regs=#{} :: #{beam_ssa:b_var():=beam_ssa:b_var()},
non_guards :: gb_sets:set(beam_ssa:label()),
bs :: beam_ssa:block_map()
bs :: beam_ssa:block_map(),
preds :: #{beam_ssa:label() => [beam_ssa:label()]}
}).

ssa_opt_float({#opt_st{ssa=Linear0,cnt=Count0}=St, FuncDb}) ->
NonGuards = non_guards(Linear0),
Blocks = maps:from_list(Linear0),
Fs = #fs{non_guards=NonGuards,bs=Blocks},
Preds = beam_ssa:predecessors(Blocks),
Fs = #fs{non_guards=NonGuards,bs=Blocks,preds=Preds},
{Linear,Count} = float_opt(Linear0, Count0, Fs),
{St#opt_st{ssa=Linear,cnt=Count}, FuncDb}.

Expand Down Expand Up @@ -1207,9 +1209,15 @@ float_maybe_flush(Blk0, Fs0, Count0) ->
{FlushBs,Blk,Fs,Count}
end.

float_safe_to_skip_flush(L, #fs{bs=Blocks}=Fs) ->
float_safe_to_skip_flush(L, #fs{bs=Blocks,preds=Preds}=Fs) ->
#b_blk{is=Is} = Blk = map_get(L, Blocks),
float_can_optimize_blk(Blk, Fs) andalso float_optimizable_is(Is).
case Preds of
#{L := [_]} ->
float_can_optimize_blk(Blk, Fs) andalso float_optimizable_is(Is);
#{} ->
%% This block can be reached from more than one block; must flush.
false
end.

float_optimizable_is([#b_set{anno=#{float_op:=_}}|_]) ->
true;
Expand Down
8 changes: 8 additions & 0 deletions lib/compiler/test/float_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,19 @@ math_functions(Config) when is_list(Config) ->

mixed_float_and_int(Config) when is_list(Config) ->
129.0 = pc(77, 23, 5),

{'EXIT',{badarith,_}} = catch mixed_1(id({a,b,c})),
{'EXIT',{{badarg,1/42},_}} = catch mixed_1(id(42)),

ok.

pc(Cov, NotCov, X) ->
round(Cov/(Cov+NotCov)*100) + 42 + 2.0*X.

mixed_1(V) ->
{is_tuple(V) orelse 1 / V,
1 / V andalso true}.

subtract_number_type(Config) when is_list(Config) ->
120 = fact(5).

Expand Down

0 comments on commit c8e684e

Please sign in to comment.