diff options
author | Björn Gustavsson <[email protected]> | 2018-11-02 10:02:34 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2018-11-02 10:02:34 +0100 |
commit | 3e742b1d270069ede1aa8b6ae69c83fc6e71f814 (patch) | |
tree | cb57c0cf90b1c2c7726698eb761efb97ff8d3c49 /lib/compiler/src | |
parent | 7999ddad6121db7d1b7fe44b3c6a80a8d7ff70f3 (diff) | |
parent | 94517048c3dad66c6c6469088d174cefcbbdb552 (diff) | |
download | otp-3e742b1d270069ede1aa8b6ae69c83fc6e71f814.tar.gz otp-3e742b1d270069ede1aa8b6ae69c83fc6e71f814.tar.bz2 otp-3e742b1d270069ede1aa8b6ae69c83fc6e71f814.zip |
Merge branch 'bjorn/compiler/fix-beam_jump/ERL-759/OTP-15400' into maint
* bjorn/compiler/fix-beam_jump/ERL-759/OTP-15400:
Fix bug when beam_jump removes put_tuple instructions
Diffstat (limited to 'lib/compiler/src')
-rw-r--r-- | lib/compiler/src/beam_jump.erl | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/compiler/src/beam_jump.erl b/lib/compiler/src/beam_jump.erl index 9eee56d604..22974da398 100644 --- a/lib/compiler/src/beam_jump.erl +++ b/lib/compiler/src/beam_jump.erl @@ -128,7 +128,7 @@ %%% on the program state. %%% --import(lists, [reverse/1,reverse/2,foldl/3]). +-import(lists, [dropwhile/2,reverse/1,reverse/2,foldl/3]). -type instruction() :: beam_utils:instruction(). @@ -411,14 +411,19 @@ opt_useless_loads([{test,_,{f,L},_}=I|Is], L, St) -> opt_useless_loads(Is, _L, St) -> {Is,St}. -opt_useless_block_loads([{set,[Dst],_,_}=I|Is], L, Index) -> - BlockJump = [{block,Is},{jump,{f,L}}], +opt_useless_block_loads([{set,[Dst],_,_}=I|Is0], L, Index) -> + BlockJump = [{block,Is0},{jump,{f,L}}], case beam_utils:is_killed(Dst, BlockJump, Index) of true -> - %% The register is killed and not used, we can remove the load + %% The register is killed and not used, we can remove the load. + %% Remove any `put` instructions in case we just + %% removed a `put_tuple` instruction. + Is = dropwhile(fun({set,_,_,put}) -> true; + (_) -> false + end, Is0), opt_useless_block_loads(Is, L, Index); false -> - [I|opt_useless_block_loads(Is, L, Index)] + [I|opt_useless_block_loads(Is0, L, Index)] end; opt_useless_block_loads([I|Is], L, Index) -> [I|opt_useless_block_loads(Is, L, Index)]; |