aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_block.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2018-01-10 13:09:33 +0100
committerBjörn Gustavsson <[email protected]>2018-01-11 12:00:59 +0100
commitce67e91a851273c8aee58f7dad270c39f18fe0de (patch)
treebf096d8821e4afaee7d2dbdeb0ee5cd428fac3ac /lib/compiler/src/beam_block.erl
parentad72a944c03095c3505cb151c9a93d243fb698b6 (diff)
downloadotp-ce67e91a851273c8aee58f7dad270c39f18fe0de.tar.gz
otp-ce67e91a851273c8aee58f7dad270c39f18fe0de.tar.bz2
otp-ce67e91a851273c8aee58f7dad270c39f18fe0de.zip
beam_block: Reorder element/2 calls in guards
In a guard, reorder two consecutive calls to the element/2 BIF that access the same tuple and have the same failure label so that highest index is fetched first. That will allow the second element/2 to be replace with the slightly cheaper get_tuple_element/3 instruction.
Diffstat (limited to 'lib/compiler/src/beam_block.erl')
-rw-r--r--lib/compiler/src/beam_block.erl4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/compiler/src/beam_block.erl b/lib/compiler/src/beam_block.erl
index 570fc05ae5..7b3a95e03e 100644
--- a/lib/compiler/src/beam_block.erl
+++ b/lib/compiler/src/beam_block.erl
@@ -240,6 +240,10 @@ opt([{set,_,_,{line,_}}=Line1,
{set,[D2],[{integer,Idx2},Reg],{bif,element,{f,0}}}=I2|Is])
when Idx1 < Idx2, D1 =/= D2, D1 =/= Reg, D2 =/= Reg ->
opt([Line2,I2,Line1,I1|Is]);
+opt([{set,[D1],[{integer,Idx1},Reg],{bif,element,{f,L}}}=I1,
+ {set,[D2],[{integer,Idx2},Reg],{bif,element,{f,L}}}=I2|Is])
+ when Idx1 < Idx2, D1 =/= D2, D1 =/= Reg, D2 =/= Reg ->
+ opt([I2,I1|Is]);
opt([{set,Ds0,Ss,Op}|Is0]) ->
{Ds,Is} = opt_moves(Ds0, Is0),
[{set,Ds,Ss,Op}|opt(Is)];