Repository navigation
JIT: retain complete metadata of reassociated folded constants - #135461
Merged
Merged
Conversation
PR description draft: <!-- --> Use the constant node returned by constant folding when reassociating commutative arithmetic, instead of copying only its value, VN, and field sequence into the original constant. This prevents handle flags and other stale metadata from surviving after arithmetic changes a handle into an ordinary numeric constant. Keep the existing constant-folding relocation safeguards and arithmetic optimization. Add a single-file regression covering addition in both constant orders and XOR with a type handle; checked disassembly exercises the original bogus-handle assertion. Fixes dotnet#134475 Co-authored-by: Copilot <[email protected]> Copilot-Session: ae8155d6-f240-4542-a1da-c721ba933c91
|
Azure Pipelines: Successfully started running 5 pipeline(s). 11 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The regression test does not enable the disassembly path that exposes the stale metadata.
1 open finding
What changed in this PR
Fixes stale JIT constant metadata after commutative reassociation by retaining the folded node.
Changes:
- Replaces the original constant with the fully folded constant node.
- Adds regression coverage for handle arithmetic and XOR.
| File | Description |
|---|---|
src/coreclr/jit/morph.cpp |
Preserves complete folded-constant metadata. |
src/tests/JIT/Regression_ro_2/Runtime_134475.cs |
Tests affected handle expressions. |
🧠 Review effort: Balanced
EgorBo
marked this pull request as ready for review
October 9, 2026 01:52
Member
Author
|
PTAL @dotnet/jit-contrib |
JulieLeeMSFT
approved these changes
Oct 9, 2026
JulieLeeMSFT
left a comment
Member
There was a problem hiding this comment.
LGTM. It assigns a fully-formed folded node into op1->AsOp()->gtOp2 instead of hand-copying value/VN/field-sequence onto cns1.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.

Use the constant node returned by constant folding when reassociating commutative arithmetic, instead of copying only its value, VN, and field sequence into the original constant. This prevents handle flags and other stale metadata from surviving after arithmetic changes a handle into an ordinary numeric constant.
Keep the existing constant-folding relocation safeguards and arithmetic optimization.
Fixes #134475
No diffs