-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Don't do an invalid mask conversion optimization for conditional select nodes #118154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 fixes a bug in the mask conversion optimization pass that was creating invalid IR by incorrectly handling conditional select nodes. The optimization was transforming ConditionalSelect(mask, simd, simd)
when IR requires ConditionalSelect(simd, simd, simd)
format.
Key changes:
- Removes invalid conditional select handling from mask conversion optimization
- Eliminates the
OperIsVectorConditionalSelect
method that enabled the faulty transform - Cleans up whitespace in the optimization visitor code
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/coreclr/jit/optimizemaskconversions.cpp | Removes conditional select handling logic and cleans up whitespace |
src/coreclr/jit/gentree.h | Removes OperIsVectorConditionalSelect method declaration |
src/coreclr/jit/gentree.cpp | Removes OperIsVectorConditionalSelect method implementation |
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, do we need to backport this to any 10.0 preview branch?
Also, worth adding the original repro as a test case maybe? |
/backport to release/10.0-preview7 |
Started backporting to release/10.0-preview7: https://github.com/dotnet/runtime/actions/runs/16599485416 |
This resolves #118143
This was exposed in, but not actually introduced by, #116983. The actual bug was introduced a bit over 10 months ago (still unique to .NET 10), as part of enabling the
mask conversion
optimization pass for xarch.The general issue was that the transform was introducing invalid IR as it was creating a
ConditionalSelect(mask, simd, simd)
node when in actuality IR requires this to be:ConditionalSelect(simd, simd, simd)
. Cases likeSve.ConditionalSelect(mask, simd, simd)
andBlendVariableMask(simd, simd, mask)
do exist. But they will already be in the right shape as the mask operand will either directly be taking a mask (no conversion necessary) or they will have something likeCvtSimdToMask(simd)
for that argument position (which is handled by a different logical path in the mask conversion optimization phase).The side effect of this invalid IR is that we would end up with an incorrect mask, which was logically being treated as
zero
when it should have been treated as a bitwise operation instead. This resulted in one path being dropped as dead code and us always returningop2
ofConditionalSelect(mask, op1, op2)
.The intent of the handling was rather to look for cases that were logically
ConditionalSelect(MaskToSimd(mask), simd, simd)
and say "this could instead beBlendVariableMask(simd, simd, mask)
, but that is a bit more involved and is largely irrelevant with #116983 as we're preferring importing things to be handled as masks natively where possible already, which would allow the normalCvtSimdToMask(lcl)
andCvtMaskToSimd(lcl)
handling to kick-in.