Skip to content

Commit

Permalink
Only allocate BEAM registers for instructions that produce values
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorng committed Sep 7, 2024
1 parent f45a14c commit 613a31e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/compiler/src/beam_ssa_pre_codegen.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2709,16 +2709,17 @@ reserve_zregs(RPO, Blocks, Intervals, Res) ->

reserve_zreg([#b_set{op={bif,tuple_size},dst=Dst},
#b_set{op={bif,'=:='},args=[Dst,Val],dst=Bool}],
Last, ShortLived, A) ->
Last, ShortLived, A0) ->
case {Val,Last} of
{#b_literal{val=Arity},#b_br{bool=Bool}} when Arity bsr 32 =:= 0 ->
%% These two instructions can be combined to a test_arity
%% instruction provided that the arity variable is short-lived.
reserve_test_zreg(Dst, ShortLived, A);
A1 = reserve_test_zreg(Dst, ShortLived, A0),
reserve_test_zreg(Bool, ShortLived, A1);
{_,_} ->
%% Either the arity is too big, or the boolean value is not
%% used in a conditional branch.
A
A0
end;
reserve_zreg([#b_set{op={bif,tuple_size},dst=Dst}],
#b_switch{arg=Dst}, ShortLived, A) ->
Expand All @@ -2743,6 +2744,7 @@ use_zreg(bs_set_position) -> yes;
use_zreg(executable_line) -> yes;
use_zreg(kill_try_tag) -> yes;
use_zreg(landingpad) -> yes;
use_zreg(nif_start) -> yes;
use_zreg(recv_marker_bind) -> yes;
use_zreg(recv_marker_clear) -> yes;
use_zreg(remove_message) -> yes;
Expand Down

0 comments on commit 613a31e

Please sign in to comment.