aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_a.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2018-08-24 14:14:09 +0200
committerBjörn Gustavsson <[email protected]>2018-09-12 14:19:05 +0200
commit52abce861178bbce0dc3acb22cc8935f9a434981 (patch)
tree3e6be6f21ffc06783f8dada3bc5bb6e50ca04ca7 /lib/compiler/src/beam_a.erl
parentecbe1327a5da4ecc02cdbc636bd54d901b92c215 (diff)
downloadotp-52abce861178bbce0dc3acb22cc8935f9a434981.tar.gz
otp-52abce861178bbce0dc3acb22cc8935f9a434981.tar.bz2
otp-52abce861178bbce0dc3acb22cc8935f9a434981.zip
Move two optimizations from beam_dead to beam_a
The 'move' instruction can be eliminated in code such as: {test,is_eq_exact,{f,42},[{x,0},{atom,value}]}. {move,{atom,value},{x,0}}. Move that optimization from beam_dead to beam_a. The optimization will be simpler because the 'move' instruction has not yet been moved into a block. Getting rid of 'move' earlier will also save work for later passes. Also move the optimization that eliminates instructions such as from beam_dead to beam_a: {test_is_eq_exact,{f,42},[{x,0},{x,0}]}.
Diffstat (limited to 'lib/compiler/src/beam_a.erl')
-rw-r--r--lib/compiler/src/beam_a.erl7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/compiler/src/beam_a.erl b/lib/compiler/src/beam_a.erl
index 266e8f46c8..0abc845310 100644
--- a/lib/compiler/src/beam_a.erl
+++ b/lib/compiler/src/beam_a.erl
@@ -52,6 +52,13 @@ function({function,Name,Arity,CLabel,Is0}) ->
erlang:raise(Class, Error, Stack)
end.
+rename_instrs([{test,is_eq_exact,_,[Dst,Src]}=Test,
+ {move,Src,Dst}|Is]) ->
+ %% The move instruction is not needed.
+ rename_instrs([Test|Is]);
+rename_instrs([{test,is_eq_exact,_,[Same,Same]}|Is]) ->
+ %% Same literal or same register. Will always succeed.
+ rename_instrs(Is);
rename_instrs([{apply_last,A,N}|Is]) ->
[{apply,A},{deallocate,N},return|rename_instrs(Is)];
rename_instrs([{call_last,A,F,N}|Is]) ->