diff options
author | Björn Gustavsson <[email protected]> | 2015-08-24 10:38:22 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2015-08-24 10:38:22 +0200 |
commit | beb851eedcf7407f0a0db167dc9212f2a7f13bd8 (patch) | |
tree | dfa31c179886d4ba7e25fa651e3b4b10df160bf6 /lib/compiler/src/beam_dead.erl | |
parent | f81065c4296c679bfdd023e988289b4d884cfdd2 (diff) | |
parent | 93c5e457faeccfd8ccbb1e6c587ad6df1f200408 (diff) | |
download | otp-beb851eedcf7407f0a0db167dc9212f2a7f13bd8.tar.gz otp-beb851eedcf7407f0a0db167dc9212f2a7f13bd8.tar.bz2 otp-beb851eedcf7407f0a0db167dc9212f2a7f13bd8.zip |
Merge branch 'bjorn/compiler/opt/OTP-12951'
* bjorn/compiler/opt/OTP-12951:
beam_validator: Don't allow x(1023) to be used
v3_core: Improve code generation for guards
Move rewriting of select_val to is_boolean from beam_peep to beam_dead
Put 'try' in blocks to optimize allocation instructions
Reorder instructions across try/catch
Delay get_tuple_element instructions until they are needed
Optimize get_tuple_element instructions by moving them forward
beam_block: Improve the move optimizations
beam_block: Clean up optimization of move optimizations
beam_block: Eliminate redundant wasteful call to opt/1
Teach the compiler the 'da' and 'dz' options
Diffstat (limited to 'lib/compiler/src/beam_dead.erl')
-rw-r--r-- | lib/compiler/src/beam_dead.erl | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/compiler/src/beam_dead.erl b/lib/compiler/src/beam_dead.erl index ead88b57e9..0cb5040177 100644 --- a/lib/compiler/src/beam_dead.erl +++ b/lib/compiler/src/beam_dead.erl @@ -242,8 +242,15 @@ backward([{select,select_val,Reg,{f,Fail0},List0}|Is], D, Acc) -> List = shortcut_select_list(List0, Reg, D, []), Fail1 = shortcut_label(Fail0, D), Fail = shortcut_bs_test(Fail1, Is, D), - Sel = {select,select_val,Reg,{f,Fail},List}, - backward(Is, D, [Sel|Acc]); + case List of + [{atom,B1},F,{atom,B2},F] when B1 =:= not B2 -> + Test = {test,is_boolean,{f,Fail},[Reg]}, + Jump = {jump,F}, + backward([Jump,Test|Is], D, Acc); + [_|_] -> + Sel = {select,select_val,Reg,{f,Fail},List}, + backward(Is, D, [Sel|Acc]) + end; backward([{jump,{f,To0}},{move,Src,Reg}=Move|Is], D, Acc) -> To = shortcut_select_label(To0, Reg, Src, D), Jump = {jump,{f,To}}, @@ -295,7 +302,18 @@ backward([{test,Op,{f,To0},Ops0}|Is], D, Acc) -> is_eq_exact -> combine_eqs(To, Ops0, D, Acc); _ -> {test,Op,{f,To},Ops0} end, - backward(Is, D, [I|Acc]); + case {I,Acc} of + {{test,is_atom,Fail,Ops0},[{test,is_boolean,Fail,Ops0}|_]} -> + %% An is_atom test before an is_boolean test (with the + %% same failure label) is redundant. + backward(Is, D, Acc); + {{test,_,_,_},_} -> + %% Still a test instruction. Done. + backward(Is, D, [I|Acc]); + {_,_} -> + %% Rewritten to a select_val. Rescan. + backward([I|Is], D, Acc) + end; backward([{test,Op,{f,To0},Live,Ops0,Dst}|Is], D, Acc) -> To1 = shortcut_bs_test(To0, Is, D), To2 = shortcut_label(To1, D), |