aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_dead.erl
AgeCommit message (Collapse)Author
2015-05-21compiler: Use Maps instead of gb_trees in beam_deadBjörn-Egil Dahlberg
2015-04-22beam_block: Optimize matching of binary literalsBjörn Gustavsson
When matching a binary literal as in: <<"abc">> = Bin the compiler will produce a sequence of three instructions (some details in the instructions removed for simplicity): bs_start_match2 Fail BinReg CtxtReg bs_match_string Fail CtxtReg "abc" bs_test_tail2 Fail CtxtReg 0 The sequence can be replaced with: is_eq_exact Fail BinReg "abc"
2015-04-22Move rewriting of bs_match from beam_clean to beam_zBjörn Gustavsson
The actual bs_match_string instruction has four operands: bs_match_string {f,Lbl} Ctxt NumBits {string,ListOfBytes} However, v3_codegen emits a more compact representation where the bits to match are packaged in a bitstring: bs_match_string {f,Lbl} Ctxt Bitstring Currently, beam_clean:clean_labels/1 will rewrite the compact representation to the final representation. That is unfortunate since clean_labels/1 is called by beam_dead, which means that the less compact representation will be introduced long before it is actually needed by beam_asm. It will also complicate any optimizations that we might want to do. Move the rewriting of bs_match_string from beam_clean:clean_labels/1 to the beam_z pass, which is the last pass executed before beam_validator and beam_asm.
2015-03-09beam_dead: Improve optimization by eliminating fallthroughsBjörn Gustavsson
2015-03-09beam_dead: Optimize Var =:= VarBjörn Gustavsson
2015-03-09sys_core_fold: Improve optimization of 'not'Björn Gustavsson
Optimize away 'not' in sys_core_fold instead of in beam_block and beam_dead, as we can do a better job in sys_core_fold. I modified the test suite temporarily to never turn off Core Erlang modifications and looked at the coverage. With the new optimizations active in sys_core_fold, the code in beam_block and beam_dead did not find a single 'not' that it could optimize. That proves that the new optimization is at least as good as the old one. Manually, I could also verify that the new optimization would optimize some variations of 'not' that the old one would not handle.
2015-01-12Update the comments that explain what beam_dead doesBjörn Gustavsson
2015-01-09Improve optimization of bs_start_match2Björn Gustavsson
2015-01-09Extend count_bits_matched/3 to handle the UTF instructionsBjörn Gustavsson
While we are, clean up the comments and rearrange the code for clarity. Also add a test to cover the last uncovered line in beam_dead.erl.
2015-01-09Generalize optimizations using shortcut_rel_op/4Björn Gustavsson
Better optimizations with less code.
2015-01-09beam_dead: Optimize branches from relational conditionalsBjörn Gustavsson
The BEAM compiler translates code such as: is_hex_digit(D) when $0 =< D, D =< $9 -> true; is_hex_digit(D) when $a =< D, D =< $z -> true; is_hex_digit(D) when $A =< D, D =< $Z -> true; is_hex_digit(_) -> false. to something like this: L0: test is_ge L1 {x,0} 48 test is_ge L1 57 {x,0} move true {x,0} return. L1: test is_ge L2 {x,0} 97 test is_ge L2 122 {x,0} move true {x,0} return L2: test is_ge L3 {x,0} 65 test is_ge L3 90 {x,0} move true {x,0} return L3: move false {x,0} return We can see that tests will be repeated even if they cannot possibly succeed. For instance, if we pass in {x,0} equal to 32, the first test that {x,0} is greater than or equal to 48 at L0 will fail. The control will transfer to L1, where it will be tested whether {x,0} is greater than 97. That test will fail and control will pass to L2, where again the test will fail. The compiler can do better by short-circuiting repeating tests: L0: test is_ge L3 {x,0} 48 test is_ge L1 57 {x,0} move true {x,0} return. L1: test is_ge L2 {x,0} 97 test is_ge L3 122 {x,0} move true {x,0} return L2: test is_ge L3 {x,0} 65 test is_ge L3 90 {x,0} move true {x,0} return L3: move false {x,0} return
2013-01-25Update copyright yearsBjörn-Egil Dahlberg
2012-10-10Rewrite select_val and select_tuple_arity to a select instructionBjörn Gustavsson
Eliminate some code bloat.
2012-10-09Improve binary matching of literalsBjörn Gustavsson
The bs_match_string instruction is used to speed up matching of binary literals. For example, given this source code: foo1(<<1,2,3>>) -> ok. The matching part of the code will look like: {test,bs_start_match2,{f,1},1,[{x,0},0],{x,0}}. {test,bs_match_string,{f,3},[{x,0},24,{string,[1,2,3]}]}. {test,bs_test_tail2,{f,3},[{x,0},0]}. Nice. However, if we do a simple change to the source code: foo2(<<1,2,3>>) -> ok; foo2(<<>>) -> error. the resulting matching code will look like (sligthly simplified): {test,bs_start_match2,{f,4},1,[{x,0},0],{x,0}}. {test,bs_get_integer2,{f,7},1,[{x,0},{integer,8},1,Flags],{x,1}}. {test,is_eq_exact,{f,8},[{x,1},{integer,1}]}. {test,bs_match_string,{f,6},[{x,0},16,{string,[2,3]}]}. {test,bs_test_tail2,{f,6},[{x,0},0]}. {move,{atom,ok},{x,0}}. return. {label,6}. {bs_restore2,{x,0},{atom,start}}. {label,7}. {test,bs_test_tail2,{f,8},[{x,0},0]}. That is, matching of the first byte is not combined into the bs_match_string instruction that follows. Fix this problem by allowing a bs_match_string instruction to be used if all clauses will match either the same integer literal or the empty binary.
2011-12-06Teach the compiler the 'no_dead' optionBjörn Gustavsson
To facilitate debugging of compiler bugs, teach the compiler the 'no_dead' option. Since the beam_dead pass used to do the necessary splitting of basic blocks to expose all labels, we must move that splitting into a separate pass that is always run.
2011-08-16compiler: Generate line instructionsBjörn Gustavsson
2011-05-20Update copyright yearsBjörn-Egil Dahlberg
2011-04-12beam_dead: Remove uncovered special case handling of empty blocksBjörn Gustavsson
There is never any empty blocks when beam_dead is invoked. Even if there were, they will be removed a little bit later in forward/4.
2011-04-12beam_dead: Remove uncovered clauses in binary matching optimizationBjörn Gustavsson
In the optimization of binary matching, it seems that two clauses cannot never be reached. Removing the clauses is safe, since that would only mean that an opportunity for an optimization is lost
2011-04-12beam_dead: Remove uncoverable case clause in update_value_dict/3Björn Gustavsson
Because the code generator (v3_codegen) would not include the same value more than once in a select_val/3 instruction and because a label can only be referenced by one select_val/3 instruction, there is no way that the correct value could already be in the gb_tree. (Even if it could happen, this change is safe because only opportunity for an optimization would be missed; incorrect code would not be generated.)
2011-04-12beam_dead: Remove code that cannot be covered in forward/4Björn Gustavsson
Since the optimizations in forward/4 already depends on some assumptions on how code is generated anyway, document the assumptions in a comment and remove the uncoverable code.
2010-06-02Merge branch 'bg/compiler' into devErlang/OTP
* bg/compiler: beam_peep: Remove optimization already done by beam_dead beam_dead: Combine is_eq_exact instructions into select_val instructions Evaluate is_record/3 at compile-time using type information Evaluate element/2 at compile-time using type information erl_expand_records: Replace is_record() with matching OTP-8668 bg/compiler The compiler optimizes record operations better.
2010-06-02beam_dead: Combine is_eq_exact instructions into select_val instructionsBjörn Gustavsson
Combine a sequence of chained is_eq_exact instructions into a select_val instruction.
2009-11-20The R13B03 release.OTP_R13B03Erlang/OTP