From c86c4dd18da287e439770c47fa384d438c134f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 29 Jan 2019 20:35:45 +0100 Subject: Speed up beam_ssa_dead when there are many sequential blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit beam_ssa_dead could be very slow if there were many blocks connected with unconditional branches (for example, if a block had contained many `call` instructions and been split by ssa_opt_split_blocks). It turns out that `comb_get_sw/3` does an unnecessary (and perhaps incorrect) recursive call to itself when the terminator for the block is an unconditional branch. Removing the recursive call does not disable any optimizations, but will be much faster if there are many blocks connected with unconditional branches. Reported-by: Michał Muskała --- lib/compiler/src/beam_ssa_dead.erl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/compiler/src/beam_ssa_dead.erl b/lib/compiler/src/beam_ssa_dead.erl index 09b29025c6..db82aaa8e6 100644 --- a/lib/compiler/src/beam_ssa_dead.erl +++ b/lib/compiler/src/beam_ssa_dead.erl @@ -850,7 +850,7 @@ combine_eqs_1([], St) -> St. comb_get_sw(L, Blocks) -> comb_get_sw(L, true, Blocks). -comb_get_sw(L, Safe0, #st{bs=Blocks,skippable=Skippable}=St) -> +comb_get_sw(L, Safe0, #st{bs=Blocks,skippable=Skippable}) -> #b_blk{is=Is,last=Last} = maps:get(L, Blocks), Safe1 = Safe0 andalso is_map_key(L, Skippable), case Last of @@ -865,8 +865,8 @@ comb_get_sw(L, Safe0, #st{bs=Blocks,skippable=Skippable}=St) -> {#b_set{},_} -> none end; - #b_br{bool=#b_literal{val=true},succ=Succ} -> - comb_get_sw(Succ, Safe1, St); + #b_br{} -> + none; #b_switch{arg=#b_var{}=Arg,fail=Fail,list=List} -> {none,Safe} = comb_is(Is, none, Safe1), {Safe,Arg,L,Fail,List} -- cgit v1.2.3