Repository navigation
Improve code generation for the JIT - #7713
Merged
Merged
Conversation
Contributor
CT Test Results 3 files 140 suites 1h 0m 27s ⏱️ For more details on these failures, see this check. Results for commit 7b28b97. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
jhogberg
reviewed
Oct 4, 2023
| a.mov(dst_ptr, RET); | ||
| break; | ||
| } | ||
| for (j = i + 1; j < size && args[i] == args[j]; j++) { |
Contributor
There was a problem hiding this comment.
std::adjacent_find (inverted)?
bjorng
force-pushed
the
bjorn/jit/misc-improvements
branch
from
October 4, 2023 10:52
3ae08fd to
a3c4d54
Compare
No BIFs have more than four arguments, so there is no need to
save and restore {x,4} and {x,5}.
When `try_end` with `deallocate` are combined the clearing of the catch on the stack can be omitted. That eliminates one instruction for x86_64 (9 bytes) and two instructions for AArch64 (8 bytes). Also combine `try_end` followed by `move` and `deallocate` for AArch64. These instruction combinations are used more than 800 times in the OTP code base.
With the ancient introduction of literals, this test case no longer
builds anything, but simply moves a literal into a BEAM register:
{move,{literal,[{<<>>,1}, . . ., {<<>>,1}]},{x,0}}.
The combination of `move`, `deallocate`, and `return` occurs about
1600 times in the OTP sources.
By combining those three BEAM instructions into one, the first three
native instructions of the combined instruction:
ldr x25, [x20]
add x20, x20, 8
ldr x30, [x20], 8
can be combined to:
ldp x25, x30, [x20], 16
Whenever possible, use SSE/AVX to copy two registers at once to the fun environment.
We used to only combine `is_tuple` and `test_arity` instructions having the same failure labels.
While at it, for AArch64 reduce tuple construction by one instruction when the destination register is also a source register.
Improve reuse of registers by recognizing more neutral instructions that will not force the cache to be discarded and by updating the cache when reading from memory. For the x86_64 JIT, with this commit 115697 loads of BEAM registers are avoided, compared to 88786 loads before this commit. For the AArch64 JIT, with this commit 14938 loads of BEAM registers are avoided, compared to 14422 loads before this commit.
Inline the code for `element/2` when the first argument (the position) is not a literal but the second argument is known to be a tuple. That typically requires 13 native instructions.
There are more than 4700 occurrences of the following instruction
sequence in the OTP code base:
ldr x25, [x20], 8
ldr x30, [x20], 8
It can be simplified like so:
ldp x25, x30, [x20], 16
* Replace the instructions `store_two_xregs` and `move_two_yregs` with the more general `store_two_values`, which also supports storing any value into Y registers. * Replace an `init_yreg` instruction that initializes a single register with a `move` instruction. That give more opportunities for optimizations, such as combining it with another `move` instruction or with a `trim` instruction.
Because of the limited reach of branch instructions, stubs that forward branches need to be emitted at regular intervals. Each stubs section is always preceded by a `b` instruction skipping the section. Frquently, this `b` instruction is unreachable (for example, if the preceding instruction is a `ret` instruction). By keeping track of whether the current position is unreachable, unnecessary `b` instructions can be omitted. We can also emit stubs sections somewhat earlier than strictly necessary if the current position is unreachable. That will reduce the number of `b` instructions that will need to be executed.
bjorng
force-pushed
the
bjorn/jit/misc-improvements
branch
from
October 13, 2023 04:14
7b28b97 to
57bc32d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces many small improvements to the code generation for the JIT.