[WIP] Add local value numbering implementation in ZJIT#4
Draft
[WIP] Add local value numbering implementation in ZJIT#4
Conversation
Don't abort the entire compilation. Fix Shopify#700
Copilot stopped work on behalf of
tekknolagi due to an error
February 1, 2026 19:48
Copilot stopped work on behalf of
tekknolagi due to an error
February 1, 2026 20:00
tekknolagi
pushed a commit
that referenced
this pull request
Mar 24, 2026
When we call `asm.load`, many times we're passing in a VReg, and that
causes extra loads when we lower to machine code. I'd like to only emit
a load in the case that the operand _isn't_ a VReg.
For example this code:
```ruby
class Foo
def initialize
@foo = 123
end
def foo
@foo
end
end
foo = Foo.new
5.times { foo.foo }
```
Before this patch, the machine code for `LoadField` looks like this:
```
# Insn: v18 LoadField v17, :_shape_id@0x4
# Load field id=_shape_id offset=4
0x121308320: mov x1, x0
0x121308324: ldur w1, [x1, #4]
```
Now it looks like this:
```
# Insn: v18 LoadField v17, :_shape_id@0x4
# Load field id=_shape_id offset=4
0x12339c320: ldur w1, [x0, #4]
```
We were able to eliminate a reg-reg copy.
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.
Implementation Plan for Local Value Numbering in ZJIT
Overview
Implement local value numbering (LVN) optimization to eliminate redundant computations within basic blocks. The Effect/AbstractHeap API already exists in the upstream codebase (
zjit/src/hir_effect), so we'll use and potentially extend it as needed.Implementation Checklist
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.