aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2015-04-15 09:59:05 +0200
committerBjörn Gustavsson <[email protected]>2015-04-22 10:14:55 +0200
commit37225949b6cf177934848fff21a1a551b7f6faee (patch)
tree090c584959ca6736df3ccd79e5df6dbebf50be87 /lib/compiler/src
parent2e2d583a49939026ec9b959f9b7941d3c2d084f2 (diff)
downloadotp-37225949b6cf177934848fff21a1a551b7f6faee.tar.gz
otp-37225949b6cf177934848fff21a1a551b7f6faee.tar.bz2
otp-37225949b6cf177934848fff21a1a551b7f6faee.zip
beam_block: Optimize matching of binary literals
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"
Diffstat (limited to 'lib/compiler/src')
-rw-r--r--lib/compiler/src/beam_dead.erl10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/compiler/src/beam_dead.erl b/lib/compiler/src/beam_dead.erl
index adc3cebc62..5932d8ce1d 100644
--- a/lib/compiler/src/beam_dead.erl
+++ b/lib/compiler/src/beam_dead.erl
@@ -255,6 +255,16 @@ backward([{jump,{f,To}}=J|[{bif,Op,_,Ops,Reg}|Is]=Is0], D, Acc) ->
catch
throw:not_possible -> backward(Is0, D, [J|Acc])
end;
+backward([{test,bs_start_match2,F,_,[R,_],Ctxt}=I|Is], D,
+ [{test,bs_match_string,F,[Ctxt,Bs]},
+ {test,bs_test_tail2,F,[Ctxt,0]}|Acc0]=Acc) ->
+ case beam_utils:is_killed(Ctxt, Acc0, D) of
+ true ->
+ Eq = {test,is_eq_exact,F,[R,{literal,Bs}]},
+ backward(Is, D, [Eq|Acc0]);
+ false ->
+ backward(Is, D, [I|Acc])
+ end;
backward([{test,bs_start_match2,{f,To0},Live,[Src|_]=Info,Dst}|Is], D, Acc) ->
To = shortcut_bs_start_match(To0, Src, D),
I = {test,bs_start_match2,{f,To},Live,Info,Dst},