Skip to content

Ensure we preserve vn and produce a canonical tree#127689

Draft
tannergooding wants to merge 1 commit intodotnet:mainfrom
tannergooding:fix-morph
Draft

Ensure we preserve vn and produce a canonical tree#127689
tannergooding wants to merge 1 commit intodotnet: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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 Outdated
Comment on lines 7932 to 7934
tree->AsOp()->gtOp2 = op2 = op1;
tree->AsOp()->gtOp1 = op1 = gtNewOperNode(GT_NEG, genActualType(op2->TypeGet()), op2);
fgMorphTreeDone(op2);
Copilot AI review requested due to automatic review settings May 3, 2026 03:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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
}

/* Check for "cns1 - op2" , we change it to "(cns1 + (-op2))" */
/* Check for "cns1 - op2" , we change it to "((-op2) + cns1)" */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.

2 participants