diff options
author | Björn Gustavsson <[email protected]> | 2019-01-26 03:58:11 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2019-01-28 05:51:41 +0100 |
commit | 3347d260556cbc04db37db1f0e339bb6f4dbc921 (patch) | |
tree | 020db27424801460df24468763451c53fed8a7e3 /lib/compiler | |
parent | 1ea703443fa0bbc3aade0bb61fc96b2f0cf6b84c (diff) | |
download | otp-3347d260556cbc04db37db1f0e339bb6f4dbc921.tar.gz otp-3347d260556cbc04db37db1f0e339bb6f4dbc921.tar.bz2 otp-3347d260556cbc04db37db1f0e339bb6f4dbc921.zip |
Speed up ssa_opt_merge_blocks
It is never possible to merge a block ending in a switch with the
next block, so it is not necessary to call `beam_ssa:successors/1` in
that case. Avoiding the call slightly improves compilation speeds
for switches with many branches.
Diffstat (limited to 'lib/compiler')
-rw-r--r-- | lib/compiler/src/beam_ssa_opt.erl | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/compiler/src/beam_ssa_opt.erl b/lib/compiler/src/beam_ssa_opt.erl index 2c898ba6f8..aa94d8d671 100644 --- a/lib/compiler/src/beam_ssa_opt.erl +++ b/lib/compiler/src/beam_ssa_opt.erl @@ -1972,13 +1972,17 @@ verify_merge_is([#b_set{op=Op}|_]) -> verify_merge_is(_) -> ok. -is_merge_allowed(_, _, #b_blk{is=[#b_set{op=peek_message}|_]}) -> +is_merge_allowed(_, #b_blk{}, #b_blk{is=[#b_set{op=peek_message}|_]}) -> false; -is_merge_allowed(L, Blk0, #b_blk{}) -> - case beam_ssa:successors(Blk0) of +is_merge_allowed(L, #b_blk{last=#b_br{}}=Blk, #b_blk{}) -> + %% The predecessor block must have exactly one successor (L) for + %% the merge to be safe. + case beam_ssa:successors(Blk) of [L] -> true; [_|_] -> false - end. + end; +is_merge_allowed(_, #b_blk{last=#b_switch{}}, #b_blk{}) -> + false. %%% %%% When a tuple is matched, the pattern matching compiler generates a |