You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Notice that the field 1 is updated twice to the atom a - first in the first setelement call (which result is completely thrown away) and then again after the second call to setelement.
With optimisations disabled and compiling with erlc +to_asm +no_ssa_opt test.erl we end up with:
Taking advantage of the set_tuple_element optimisation and avoiding the unnecessary extra call to setelement. This is possible because of the guard, we know the first setelement operation can't fail.
I believe what happens is that the set_tuple_element optimisation expects another pass to remove the, now redundant, first call to setelement, but for some reason that is not happening correctly.
Affected versions
Tested on OTP 27.1
The text was updated successfully, but these errors were encountered:
Describe the bug
Given the following code:
The compiler produces following bytecode (when compiled with
erlc +to_asm test.erl
):Notice that the field 1 is updated twice to the atom
a
- first in the firstsetelement
call (which result is completely thrown away) and then again after the second call tosetelement
.With optimisations disabled and compiling with
erlc +to_asm +no_ssa_opt test.erl
we end up with:which is actually better - no stack juggling and no unnecessary operation.
Expected behavior
I would expect the produced code to be something like:
Taking advantage of the
set_tuple_element
optimisation and avoiding the unnecessary extra call tosetelement
. This is possible because of the guard, we know the firstsetelement
operation can't fail.I believe what happens is that the
set_tuple_element
optimisation expects another pass to remove the, now redundant, first call tosetelement
, but for some reason that is not happening correctly.Affected versions
Tested on OTP 27.1
The text was updated successfully, but these errors were encountered: