GH-115802: Don't JIT zero-length jumps #116177
Merged
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.
Many of our JIT templates end with a jump to the next opcode. This is generally needed to ensure correct control flow... but when the jump is the very last instruction, it's entirely unnecessary. Instead, we can just continue execution into the next instruction.
This removes these jumps for the following platforms (performance results):
x86_64-pc-windows-msvc(2% faster)i686-pc-windows-msvc(3% slower)x86_64-apple-darwin(no benchmarks)aarch64-unknown-linux-gnu(no benchmarks)x86_64-unknown-linux-gnu(2% faster)(
aarch64-apple-darwinneeds a bit more work, since the final jump is still made up of 3 instructions. That can come next.)I'm assuming that the 32-bit Windows result is a fluke. If it's indeed the case that leaving the zero-length jumps in is faster, then we could easily remove this later by commenting out that case in
remove_jump. If so, maybe it's an alignment thing and we should just pad withnops instead.Also, this will probably be even more effective once we have hot/cold splitting of some kind. Most of the templates end with error handling or deoptimization code, and still have to jump over it to get to the next instruction.