aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_ssa_dead.erl
AgeCommit message (Collapse)Author
2019-05-29Merge branch 'maint'Björn Gustavsson
* maint: Eliminate crash in the beam_ssa_dead compiler pass
2019-05-29Merge pull request #2263 from ↵Björn Gustavsson
bjorng/bjorn/compiler/fix-beam_ssa_dead-crash/ERL-956/OTP-15848 Eliminate crash in the beam_ssa_dead compiler pass
2019-05-28Eliminate crash in the beam_ssa_dead compiler passBjörn Gustavsson
The compiler could crash in the beam_ssa_dead pass while compiling complex nested `case` expressions. See the added test case for an example and explanation. https://bugs.erlang.org/browse/ERL-956
2019-05-27Merge branch 'maint'Björn Gustavsson
* maint: Fix loading of Core Erlang code for extracting a map element Fix unsafe optimizations where guard tests could be removed
2019-05-25Fix unsafe optimizations where guard tests could be removedBjörn Gustavsson
A repeated test could be optimized away. Example: bar(A) -> if is_bitstring(A) -> if is_binary(A) -> binary; true -> bitstring end; true -> other end. In the example, the `is_binary/1` test would be optimized away, basically turning the example into: bar(A) -> if is_bitstring(A) -> bitstring; true -> other end. Thanks user Marcus Kruse in the Elixir forum for noticing this bug.
2019-05-20Improve optimization of redundant testsBjörn Gustavsson
The `beam_ssa_dead` pass is supposed to eliminate tests that are determined to be redundant based on the outcome of a previous test. For example, in the following example that repeats a guard test, the second clause can never be executed: foo(A) when A >= 42 -> one; foo(A) when A >= 42 -> two; foo(_) -> three. `beam_ssa_dead` should have eliminated the second clause, but didn't: {test,is_ge,{f,5},[{x,0},{integer,42}]}. {move,{atom,one},{x,0}}. return. {label,5}. {test,is_ge,{f,6},[{x,0},{integer,42}]}. {move,{atom,two},{x,0}}. return. {label,6}. {move,{atom,three},{x,0}}. return. Correct the optimization of four different combinations of relational operations that were too conservate. To ensure the correctness of the optimization, also add an exahaustive test of all combinations of relational operations with one variable and one literal. (Also remove the weak and now redundant coverage tests in `beam_ssa_SUITE`.) With this correction, the following code will be generated for the example: {test,is_ge,{f,5},[{x,0},{integer,42}]}. {move,{atom,one},{x,0}}. return. {label,5}. {move,{atom,three},{x,0}}. return. Thanks to Dániel Szoboszlay (@dszoboszlay), whose talk at Code BEAM STO 2019 made me aware of this missed opportunity for optimization.
2019-03-01Add a comment about the time complexity of beam_ssa_deadBjörn Gustavsson
2019-03-01Pass the from node as a function argument instead of in a mapBjörn Gustavsson
This is cleaner and slightly faster.
2019-03-01Do some minor optimizations of compilation timesBjörn Gustavsson
The general complexity of the shortcut sub pass of `beam_ssa_dead` is quadratic, but those optimizations will reduce the constant factor somewhat.
2019-03-01Keep the set of unset variables as small as possibleBjörn Gustavsson
Refactor the code to avoid putting any variable from a skippable block into the set of unset variables. Keeping the set of unset variables as small as possible will make beam_ssa_dead almost twice as fast when compiling lib/unicode/tokenizer.ex in elixir.
2019-02-01Make helper functions tail-recursiveBjörn Gustavsson
Two helper functions in beam_ssa_opt and beam_ssa_dead are body-recursive for no good reason. While at it, add some clarifying comments to the functions.
2019-02-01Prefer map syntax and guard BIFs over the maps modulesBjörn Gustavsson
Avoiding calls usually reduces the size of the stack frame and reduces register shuffling.
2019-02-01Speed up beam_ssa_dead when there are many sequential blocksBjörn Gustavsson
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
2019-01-28Speed up beam_ssa_deadBjörn Gustavsson
Compilation of code similar the following would be very slow: uts46_map(CP) when 0 =< CP, CP =< 44 -> '3'; uts46_map(CP) when 45 =< CP, CP =< 46 -> 'V'; uts46_map(CP) when 48 =< CP, CP =< 57 -> 'V'; %% More than 2500 similar lines follows. . . . The code is from from: https://github.com/benoitc/erlang-idna/blob/3eb54ccbfa6fb917c0f4ca9197da337ad888ffe0/src/idna_mapping.erl#L6780 By using information about skippable blocks, the beam_ssa_dead pass can be sped up to compile idna_mapping.erl about 10 times faster.
2018-11-15beam_ssa_dead: Speed up optimization of switch instructionsBjörn Gustavsson
`beam_ssa_dead` can waste a lot of time trying to optimize an unoptimizable `switch` instruction. By being a little bit smarter when optimizing `switch` instructions, the runtime for the beam_ssa_dead pass was reduced approximately by half on my computer for this module: https://github.com/aggelgian/cuter/blob/master/src/cuter_binlib.erl Noticed-by: Kostis Sagonas
2018-09-20Consistently use #b_var{} instead of var_name()John Högberg
We chose to refer to variables through their var_name() because we anticipated the need to annotate them, but it turned out we didn't really need that, and many things become a lot cleaner if the entire #b_var{} is used to represent variables.
2018-09-17Add beam_ssa_dead.erlBjörn Gustavsson
Add beam_ssa_dead to perform the main optimizations done by beam_dead: * Shortcut branches that jump to another block with a branch. If it can be seen that the second branch will always branch to a specific block, replace the target of the first branch. * Combined nested sequences of '=:=' tests and switch instructions operating on the same variable to a single switch. Diffing the compiler output, it seems that beam_ssa_dead finds many more opportunities for optimizations than beam_dead, although it does not find all opportunities that beam_dead does. In total, beam_ssa_dead is such improvement over beam_dead that there is no reason to keep beam_dead as well as beam_ssa_dead. Note that beam_ssa_dead does not attempt to optimize away redundant bs_context_binary instructions, because that instruction will be superseded by new instructions in the near future.