JIT: Fix mask AND with zero incorrectly folded#123603
Merged
Conversation
Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix incorrect folding of AND with zero in JIT
JIT: Fix mask AND with zero incorrectly folded
Jan 25, 2026
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib |
This was referenced Jan 26, 2026
Open
Member
|
PTAL @dotnet/jit-contrib trivial bug-fix for No diffs |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a JIT optimization bug where AND operations between mask types and zero were incorrectly folded to return the mask value instead of zero. The issue occurred in gtFoldExprHWIntrinsic and has been regression since .NET 9.0. The fix makes mask type handling consistent with vector type handling for the same operation.
Changes:
- Fixed incorrect constant folding for mask AND operations with zero
- Added regression test to prevent future occurrences
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/coreclr/jit/gentree.cpp |
Fixed GT_AND case for mask types to use gtWrapWithSideEffects when ANDing with zero, making it consistent with vector type handling |
src/tests/JIT/Regression/JitBlue/Runtime_123399/Runtime_123399.cs |
Added AVX512-gated regression test that verifies AND between an all-ones mask and a zero mask returns zero |
src/tests/JIT/Regression/Regression_ro_1.csproj |
Added new test file to the project |
jakobbotsch
approved these changes
Jan 26, 2026
tannergooding
approved these changes
Jan 26, 2026
Member
|
/ba-g deadletter |
This was referenced Jan 27, 2026
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.
Description
ANDbetween a mask and constant zero was incorrectly folded to return the mask value instead of zero in the JIT'sgtFoldExprHWIntrinsic.Changes
src/coreclr/jit/gentree.cpp: For mask types inGT_ANDcase, changedresultNode = otherNodetoresultNode = gtWrapWithSideEffects(cnsNode, otherNode, GTF_ALL_EFFECT)— matching the non-mask vector casesrc/tests/JIT/Regression/JitBlue/Runtime_123399/: Added regression test (requires AVX-512)Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.