-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[DAGCombiner] Fix type check in visitSRA: use VT for SIGN_EXTEND and TruncVT for TRUNCATE #157580
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
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-llvm-selectiondag Author: Stephen Young (StephenYoung2754) Changes…TruncVT for TRUNCATE Full diff: https://github.com/llvm/llvm-project/pull/157580.diff 1 Files Affected:
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index fed5e7238433e..48441005b960e 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -10856,8 +10856,8 @@ SDValue DAGCombiner::visitSRA(SDNode *N) {
// on that type, and the truncate to that type is both legal and free,
// perform the transform.
if ((ShiftAmt > 0) &&
- TLI.isOperationLegalOrCustom(ISD::SIGN_EXTEND, TruncVT) &&
TLI.isOperationLegalOrCustom(ISD::TRUNCATE, VT) &&
+ TLI.isOperationLegalOrCustom(ISD::SIGN_EXTEND, TruncVT) &&
TLI.isTruncateFree(VT, TruncVT)) {
SDValue Amt = DAG.getShiftAmountConstant(ShiftAmt, VT, DL);
SDValue Shift = DAG.getNode(ISD::SRL, DL, VT,
|
1c664be
to
c91dbd9
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
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.
? This changes nothing.
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.
Thank you for pointing this out. You’re right — I accidentally submitted a wrong edit which didn’t fix the issue.
I’ve updated the patch so that SIGN_EXTEND is checked against VT (the result type) and TRUNCATE against TruncVT (the truncated type).
Please take another look.
e18f668
to
beb4a8b
Compare
…TruncVT for TRUNCATE
beb4a8b
to
1c87083
Compare
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.
missing test coverage and duplicate of #153762 - please coordinate
Summary
Fix incorrect type checks in
DAGCombiner::visitSRA
.SIGN_EXTEND
should be checked againstVT
(the result type), andTRUNCATE
should be checked againstTruncVT
(the truncated type).Details
The original code swapped the type arguments:
This could lead to missed optimizations or invalid folding decisions for
patterns such as
(sra (extend x), k)
.The patch corrects the checks to:
Testing
Issue
Fixes #153543