-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[SelectionDAG] Fix incorrect fold condition in foldSetCCWithFunnelShift. #137637
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4462,11 +4462,14 @@ static SDValue foldSetCCWithFunnelShift(EVT VT, SDValue N0, SDValue N1, | |
|
|
||
| unsigned BitWidth = N0.getScalarValueSizeInBits(); | ||
| auto *ShAmtC = isConstOrConstSplat(N0.getOperand(2)); | ||
| if (!ShAmtC || ShAmtC->getAPIntValue().uge(BitWidth)) | ||
| if (!ShAmtC) | ||
| return SDValue(); | ||
|
|
||
| uint64_t ShAmt = ShAmtC->getAPIntValue().urem(BitWidth); | ||
| if (ShAmt == 0) | ||
| return SDValue(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not: uint64_t AmtVal = ShAmtC->getAPIntValue().urem(BitWidth);
if (AmtVal == 0)
return SDValue();
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my point of view - just because it should not come up from non-canonical code IIUC, and so fixing the bug is the more important issue and trying to handle other cases that could lead to further bugs for little benefit. But it sounds OK so long as the rest of the code handles it correctly.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RKSimon You're right. It's OK to take the modulo first. I've fixed it. Thanks! |
||
|
|
||
| // Canonicalize fshr as fshl to reduce pattern-matching. | ||
| unsigned ShAmt = ShAmtC->getZExtValue(); | ||
| if (N0.getOpcode() == ISD::FSHR) | ||
| ShAmt = BitWidth - ShAmt; | ||
|
|
||
|
|
||
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.
Doesn't this need a
.getZExtValueto convert from APInt to uint64_t?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.
urem(uint64_t) returns a uint64_t