Repository navigation
ZJIT: Remove redundant PatchPoints within basic blocks - #16231
Merged
Merged
Conversation
Add a new optimization pass that deduplicates PatchPoint instructions asserting the same invariant within a basic block when no intervening instruction could invalidate it. This is common in practice — e.g., `1 + 2 + 3` produces two identical `PatchPoint MethodRedefined(Integer, +, cme)` because each `+` call inserts one. The second is redundant since nothing between them can redefine Integer#+. The approach adds a `PatchPoint` leaf to the abstract heap DAG so the effect system can distinguish instructions that could invalidate invariants (writes to PatchPoint, e.g. Send/CCall) from those that cannot (e.g. IncrCounter, Const). The pass maintains a HashSet of seen invariants per block and skips duplicates, clearing the set when an instruction writes to the PatchPoint heap. Removed PatchPoints' orphaned Snapshot dependencies are cleaned up by the subsequent DCE pass.
rwstauner
force-pushed
the
rwstauner/zjit-patchpoints
branch
from
February 24, 2026 00:55
26fd99d to
88cf26b
Compare
tekknolagi
approved these changes
Feb 24, 2026
tekknolagi
left a comment
Contributor
There was a problem hiding this comment.
This looks great! Thank you. Is there an ARM code size reduction?
Contributor
Author
|
With a quick lobsters run I'm seeing |
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.
Add a new optimization pass that deduplicates PatchPoint instructions
asserting the same invariant within a basic block when no intervening
instruction could invalidate it.
This is common in practice — e.g.,
1 + 2 + 3produces two identicalPatchPoint MethodRedefined(Integer, +, cme)because each+callinserts one. The second is redundant since nothing between them can
redefine Integer#+.
The approach adds a
PatchPointleaf to the abstract heap DAG so theeffect system can distinguish instructions that could invalidate
invariants (writes to PatchPoint, e.g. Send/CCall) from those that
cannot (e.g. IncrCounter, Const). The pass maintains a HashSet of
seen invariants per block and skips duplicates, clearing the set when
an instruction writes to the PatchPoint heap.
Removed PatchPoints' orphaned Snapshot dependencies are cleaned up by
the subsequent DCE pass.
I added a new test with snapshots to
zjit/src/hir/tests.rsin the first commitso that you can see how the change affects it in the second commit:
88cf26b#diff-38be021d8d0035cca77d3eab5ccc530109e7832f4711a5beb4dfced7001787ae
closes Shopify#779