Skip to content

JIT: retain complete metadata of reassociated folded constants - #135461

Merged
EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:egorbo/fix-jit-134475
Oct 10, 2026
Merged

EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:egorbo/fix-jit-134475

Conversation

@EgorBo

@EgorBo EgorBo commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

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

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
@EgorBo
EgorBo requested a balanced review from Copilot October 9, 2026 00:33
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Oct 9, 2026
@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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
EgorBo marked this pull request as ready for review October 9, 2026 01:52
@EgorBo

EgorBo commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

PTAL @dotnet/jit-contrib

@EgorBo
EgorBo requested a review from a team October 9, 2026 14:49

@JulieLeeMSFT JulieLeeMSFT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. It assigns a fully-formed folded node into op1->AsOp()->gtOp2 instead of hand-copying value/VN/field-sequence onto cns1.

@EgorBo
EgorBo merged commit e23d559 into dotnet:main Oct 10, 2026
149 checks passed
@EgorBo
EgorBo deleted the egorbo/fix-jit-134475 branch October 10, 2026 13:07
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 13, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT: (bug) fgMorphCommutative keeps GTF_ICON_CLASS_HDL on folded "H + C" constant (bogus class handle)

3 participants