diff options
author | Björn Gustavsson <[email protected]> | 2018-08-30 06:55:37 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2018-09-12 14:19:05 +0200 |
commit | 8e4f23224a90d35683dbd45007682c861c4eb354 (patch) | |
tree | 4e1b6246c1f1389d716a7df2882481250cb8a20c /lib/compiler/src/beam_peep.erl | |
parent | 71182c868e97dac0833c710c033fde871eb3a8f0 (diff) | |
download | otp-8e4f23224a90d35683dbd45007682c861c4eb354.tar.gz otp-8e4f23224a90d35683dbd45007682c861c4eb354.tar.bz2 otp-8e4f23224a90d35683dbd45007682c861c4eb354.zip |
beam_peep: Add is_boolean optimization of select_val
A select_val instruction that test whether a register is a boolean
like this:
{select_val,Reg,{f,Fail},{list,[{atom,true},Lbl,{atom,false},Lbl]}}.
can be replaced with an is_boolean test:
{test,is_boolean,{f,Fail},[Reg]}.
{jump,{f,Lbl}}.
This optimization is currently done in beam_dead. However, if done in
the beam_peep, it can catch more opportunities to do the optimization,
because after having run beam_jump, labels that were different have
been coalesced.
Diffstat (limited to 'lib/compiler/src/beam_peep.erl')
-rw-r--r-- | lib/compiler/src/beam_peep.erl | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/compiler/src/beam_peep.erl b/lib/compiler/src/beam_peep.erl index 74da6aa704..2323a439e9 100644 --- a/lib/compiler/src/beam_peep.erl +++ b/lib/compiler/src/beam_peep.erl @@ -112,6 +112,10 @@ peep([{select,Op,R,F,Vls0}|Is], SeenTests0, Acc0) -> %% Single value left. Convert to regular test Is1 = [{test,test_arity,F,[R,Arity]},{jump,Lbl}|Is], peep(Is1, SeenTests0, Acc0); + [{atom,B1},Lbl,{atom,B2},Lbl] when B1 =:= not B2 -> + %% Replace with is_boolean test. + Is1 = [{test,is_boolean,F,[R]},{jump,Lbl}|Is], + peep(Is1, SeenTests0, Acc0); [_|_]=Vls -> I = {select,Op,R,F,Vls}, peep(Is, gb_sets:empty(), [I|Acc0]) |