Skip to content

Ensure we preserve vn and produce a canonical tree - #127689

Merged
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:fix-morph
May 4, 2026
Merged

tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:fix-morph

Conversation

@tannergooding

Copy link
Copy Markdown
Member

This ensures that we preserve the VN when morphing a particular MOD->AND pattern and ensures that a particular SUB->ADD pattern produces a "canonical" tree with the constant as the second operand.

Copilot AI review requested due to automatic review settings May 2, 2026 22:56
@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 May 2, 2026
@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.

Pull request overview

This PR updates CoreCLR JIT morphing to (1) preserve value numbering (VN) across a specific MOD -> AND strength-reduction used under ==/!= 0 comparisons, and (2) canonicalize a SUB -> ADD rewrite so the constant ends up as the second operand.

Changes:

  • Preserve VN when rewriting (a % c) ==/!= 0 (power-of-2 c) into a & (c - 1) ==/!= 0.
  • Adjust the cns1 - op2 rewrite to produce ((-op2) + cns1) (constant as operand 2).
  • Update the in-code comment to reflect the intended canonical tree form.

Comment thread src/coreclr/jit/morph.cpp Resolved
Copilot AI review requested due to automatic review settings May 3, 2026 03:18

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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/jit/morph.cpp Resolved
@tannergooding

Copy link
Copy Markdown
Member Author

CC. @EgorBo, no diffs but cleans up the pre-existing PreserveVN case you commented on in the other PR

Comment thread src/coreclr/jit/morph.cpp Resolved
Comment thread src/coreclr/jit/morph.cpp Resolved
@tannergooding
tannergooding enabled auto-merge (squash) May 4, 2026 03:42
@tannergooding
tannergooding merged commit b6b7d92 into dotnet:main May 4, 2026
135 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 3, 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.

4 participants