diff options
author | Björn Gustavsson <[email protected]> | 2017-08-29 18:02:58 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2017-08-31 10:11:24 +0200 |
commit | 00c13ed24a08799ba938a64e3198e75f07329486 (patch) | |
tree | 6f66bd4fe10da017d269eb1f15b80d082e3c7f66 /bootstrap/lib | |
parent | f0b2ac51019181cc765b55e95b2723f5ed03d3fa (diff) | |
download | otp-00c13ed24a08799ba938a64e3198e75f07329486.tar.gz otp-00c13ed24a08799ba938a64e3198e75f07329486.tar.bz2 otp-00c13ed24a08799ba938a64e3198e75f07329486.zip |
Eliminate unnecessary 'move' instructions
The compiler could sometimes emit unnecessary 'move'
instructions in the code for binary matching, for
example for this function:
escape(<<Byte, Rest/bits>>, Pos) when Byte >= 127 ->
escape(Rest, Pos + 1);
escape(<<Byte, Rest/bits>>, Pos) ->
escape(Rest, Pos + Byte);
escape(<<_Rest/bits>>, Pos) ->
Pos.
The generated code would look like this:
{function, escape, 2, 2}.
{label,1}.
{line,[{location,"t.erl",17}]}.
{func_info,{atom,t},{atom,escape},2}.
{label,2}.
{test,bs_start_match2,{f,1},2,[{x,0},0],{x,0}}.
{test,bs_get_integer2,
{f,4},
2,
[{x,0},
{integer,8},
1,
{field_flags,[{anno,[17,{file,"t.erl"}]},unsigned,big]}],
{x,2}}.
{'%',{bin_opt,[17,{file,"t.erl"}]}}.
{move,{x,0},{x,3}}. %% UNECESSARY!
{test,is_ge,{f,3},[{x,2},{integer,127}]}.
{line,[{location,"t.erl",18}]}.
{gc_bif,'+',{f,0},4,[{x,1},{integer,1}],{x,1}}.
{move,{x,3},{x,0}}. %% UNECESSARY!
{call_only,2,{f,2}}.
{label,3}.
{line,[{location,"t.erl",20}]}.
{gc_bif,'+',{f,0},4,[{x,1},{x,2}],{x,1}}.
{move,{x,3},{x,0}}. %% UNECESSARY!
{call_only,2,{f,2}}.
{label,4}.
{move,{x,1},{x,0}}.
return.
The redundant 'move' instructions have been marked.
To avoid the 'move' instructions, we can extend the existing
function is_context_unused/1 in v3_codegen. If v3_codegen can
know that the match context will not be used again, it can reuse
the register for the match context and avoid the extra 'move'
instructions.
https://bugs.erlang.org/browse/ERL-444
Diffstat (limited to 'bootstrap/lib')
0 files changed, 0 insertions, 0 deletions