Fix Arm64 conditional select lowering#128700
Open
jonathandavies-arm wants to merge 2 commits into
Open
Conversation
Arm64 lowering could form SELECT_INCCC from an int local while the select result was long. That could emit a 64-bit csinc using the int local value as the increment source, changing -1 + 1 from 0 to 0x1_0000_0000. Arm64 lowering could also replace checked add or neg operations feeding a select with csinc or csneg. Those instructions do not report overflow, so the transformed code could skip required OverflowException behavior. Solution: Require the compared local width to match the select result before applying the constant-select-to-cinc transform, and recreate valid replacement locals with their own type. Also bail out of the conditional-select-to-CS-op transform when the operation being removed may overflow and is marked as checked overflow. Add Arm64 regression coverage for both cases.
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
This was referenced May 28, 2026
Open
| var_types lclType = genActualType(lclNode); | ||
| var_types selectType = genActualType(select); | ||
|
|
||
| if (genTypeSize(lclType) != genTypeSize(selectType)) |
Contributor
There was a problem hiding this comment.
simplify to if (lclType != selectType) ?
| // The checked negation must remain explicit so the overflow path is preserved. | ||
| //ARM64-NOT: csneg | ||
| //ARM64-NOT: cneg | ||
| return condition ? x : checked(-x); |
Contributor
There was a problem hiding this comment.
I wonder if this test might be unneeded - TryLowerCselToCSOp doesn't operate on SUB, and "OperMayOverflow" is false for GT_NEG.
Is it easy to check quickly what we do for
return condition ? x : (-x);
(without the checked)?
Contributor
|
Change lgtm aside from a couple nits, thanks for finding and submitting the fix |
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.
Arm64 lowering could form SELECT_INCCC from an int local while the select result was long. That could emit a 64-bit csinc using the int local value as the increment source, changing -1 + 1 from 0 to 0x1_0000_0000.
Arm64 lowering could also replace checked add or neg operations feeding a select with csinc or csneg. Those instructions do not report overflow, so the transformed code could skip required OverflowException behavior.
Solution: Require the compared local width to match the select result before applying the constant-select-to-cinc transform, and recreate valid replacement locals with their own type. Also bail out of the conditional-select-to-CS-op transform when the operation being removed may overflow and is marked as checked overflow. Add Arm64 regression coverage for both cases.