diff options
author | Björn Gustavsson <[email protected]> | 2019-02-18 14:33:55 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2019-02-19 10:18:08 +0100 |
commit | 26c93c06ebb9b1585418d463142f63bdca071f85 (patch) | |
tree | 3dc2f224419bc854c59debac04e15b3fb7901383 /lib/compiler/src/v3_core.erl | |
parent | 6c0c1f69353b14bb9cec8d6d2ae134b54bf3b2d7 (diff) | |
download | otp-26c93c06ebb9b1585418d463142f63bdca071f85.tar.gz otp-26c93c06ebb9b1585418d463142f63bdca071f85.tar.bz2 otp-26c93c06ebb9b1585418d463142f63bdca071f85.zip |
Do the destructive setelement optimization in SSA
The expansion of record field updates, when more than one field is
updated, but not a majority of the fields, will create a sequence of
calls to `erlang:setelement(Index, Value, Tuple)` where Tuple in the
first call is the original record tuple, and in the subsequent calls
Tuple is the result of the previous call. Furthermore, all Index
values are constant positive integers, and the first call to
`setelement` will have the greatest index. Thus all the following
calls do not actually need to test at run-time whether Tuple has type
tuple, nor that the index is within the tuple bounds.
Since OTP R7, the `sys_core_dsetel` pass, run as the very last Core
Erlang pass, has optimized this sequence of `setelement` calls to use
a special destructive version of `setelement` (called
`set_tuple_element`) for all but the very first `setelement` in the
sequence.
It turns out that the presence of the `set_tuple_element` in SSA code
is awkward and can prevent or complicate type analysis and aggressive
optimizations.
Therefore, this commit removes the `sys_core_dsetel` pass and
reimplements it for SSA code. The optimization will be done in the
`beam_ssa_pre_codegen` pass (that is, just before code generation and
after running all other SSA code optimization passes).
In most cases, the resulting BEAM code is identical to previous
code. For a few modules, the BEAM code is actually slightly better,
with smaller stack frames.
Diffstat (limited to 'lib/compiler/src/v3_core.erl')
0 files changed, 0 insertions, 0 deletions