Skip to content

Commit

Permalink
Merge branch 'bjorn/compiler/fix-unsafe-float-op/erlangGH-6163/OTP-18…
Browse files Browse the repository at this point in the history
…182' into maint

* bjorn/compiler/fix-unsafe-float-op/erlangGH-6163/OTP-18182:
  Fix internal consistency error
  • Loading branch information
bjorng committed Jul 27, 2022
2 parents 1512c14 + c8e684e commit e6a1714
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 @@ -1063,13 +1063,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 @@ -1193,9 +1195,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 e6a1714

Please sign in to comment.