-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[AArch64][SelectionDAG] Mask for SUBS with multiple users cannot be elided #90911
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
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be 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 If you have received no comments on your PR for a week, you can request a review 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-backend-aarch64 Author: None (weihangf-apple) ChangesIn DAGCombiner, the Full diff: https://github.com/llvm/llvm-project/pull/90911.diff 2 Files Affected:
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index b27d204f3dded0..855573fdab9358 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -22833,7 +22833,8 @@ SDValue performCONDCombine(SDNode *N,
SDNode *SubsNode = N->getOperand(CmpIndex).getNode();
unsigned CondOpcode = SubsNode->getOpcode();
- if (CondOpcode != AArch64ISD::SUBS || SubsNode->hasAnyUseOfValue(0))
+ if (CondOpcode != AArch64ISD::SUBS || SubsNode->hasAnyUseOfValue(0) ||
+ !SubsNode->hasOneUse())
return SDValue();
// There is a SUBS feeding this condition. Is it fed by a mask we can
diff --git a/llvm/test/CodeGen/AArch64/and-mask-removal.ll b/llvm/test/CodeGen/AArch64/and-mask-removal.ll
index a8a59f1591268f..493d503de2cc13 100644
--- a/llvm/test/CodeGen/AArch64/and-mask-removal.ll
+++ b/llvm/test/CodeGen/AArch64/and-mask-removal.ll
@@ -526,4 +526,26 @@ define i64 @pr58109b(i8 signext %0, i64 %a, i64 %b) {
ret i64 %4
}
+define i64 @test_2_selects(i8 zeroext %a) {
+; CHECK-LABEL: test_2_selects:
+; CHECK: ; %bb.0:
+; CHECK-NEXT: add w9, w0, #24
+; CHECK-NEXT: mov w8, #131
+; CHECK-NEXT: and w9, w9, #0xff
+; CHECK-NEXT: cmp w9, #81
+; CHECK-NEXT: mov w9, #57
+; CHECK-NEXT: csel x8, x8, xzr, lo
+; CHECK-NEXT: csel x9, xzr, x9, eq
+; CHECK-NEXT: add x0, x8, x9
+; CHECK-NEXT: ret
+ %1 = add i8 %a, 24
+ %2 = zext i8 %1 to i64
+ %3 = icmp ult i8 %1, 81
+ %4 = select i1 %3, i64 131, i64 0
+ %5 = icmp eq i8 %1, 81
+ %6 = select i1 %5, i64 0, i64 57
+ %7 = add i64 %4, %6
+ ret i64 %7
+}
+
declare i8 @llvm.usub.sat.i8(i8, i8) #0
|
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.
Looks like a sensible one. Thanks for the fix. LGTM
feb0276
to
f946821
Compare
f946821
to
b70dd1f
Compare
@davemgreen Do you mind merging this PR for me since I don't have commit access? Thanks in advance! |
@weihangf-apple Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested Please check whether problems have been caused by your change specifically, as How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
…lided (llvm#90911) In DAGCombiner, the `performCONDCombine` function attempts to remove AND instructions in front of SUBS (cmp) instructions for which the AND is transparent. The rules for that are correct, but it fails to take into account the case where the SUBS instruction has multiple users with different condition codes for comparison and simply removes the AND for all of them. This causes a miscompilation in the attached test case. (cherry picked from commit 72eaa0e)
…lided (llvm#90911) In DAGCombiner, the `performCONDCombine` function attempts to remove AND instructions in front of SUBS (cmp) instructions for which the AND is transparent. The rules for that are correct, but it fails to take into account the case where the SUBS instruction has multiple users with different condition codes for comparison and simply removes the AND for all of them. This causes a miscompilation in the attached test case. (cherry picked from commit 72eaa0e)
…lided (llvm#90911) In DAGCombiner, the `performCONDCombine` function attempts to remove AND instructions in front of SUBS (cmp) instructions for which the AND is transparent. The rules for that are correct, but it fails to take into account the case where the SUBS instruction has multiple users with different condition codes for comparison and simply removes the AND for all of them. This causes a miscompilation in the attached test case. (cherry picked from commit 72eaa0e)
In DAGCombiner, the
performCONDCombine
function attempts to remove AND instructions in front of SUBS (cmp) instructions for which the AND is transparent. The rules for that are correct, but it fails to take into account the case where the SUBS instruction has multiple users with different condition codes for comparison and simply removes the AND for all of them. This causes a miscompilation in the attached test case.