-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[InstCombine] Drop samesign flag in foldAndOrOfICmpsWithConstEq
#112489
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
|
@llvm/pr-subscribers-llvm-transforms Author: Yingwei Zheng (dtcxzyw) ChangesIn 5dbfca3 we assume that RHS is poison implies LHS is also poison. It doesn't hold after introducing samesign flag. This patch drops the It is an alternative to #112475. Full diff: https://github.com/llvm/llvm-project/pull/112489.diff 3 Files Affected:
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 64bee4ab974ede..c8407e8ba5aba8 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -3369,8 +3369,14 @@ Value *InstCombinerImpl::foldAndOrOfICmps(ICmpInst *LHS, ICmpInst *RHS,
// We can convert this case to bitwise and, because both operands are used
// on the LHS, and as such poison from both will propagate.
if (Value *V = foldAndOrOfICmpsWithConstEq(RHS, LHS, IsAnd,
- /*IsLogical*/ false, Builder, Q))
+ /*IsLogical=*/false, Builder, Q)) {
+ // If RHS is still used, we should drop samesign flag.
+ if (IsLogical && RHS->hasSameSign() && !RHS->use_empty()) {
+ RHS->setSameSign(false);
+ addToWorklist(RHS);
+ }
return V;
+ }
if (Value *V = foldIsPowerOf2OrZero(LHS, RHS, IsAnd, Builder, *this))
return V;
diff --git a/llvm/test/Transforms/InstCombine/and-or-icmp-min-max.ll b/llvm/test/Transforms/InstCombine/and-or-icmp-min-max.ll
index 058847a75bde7f..cc55c4a39a2678 100644
--- a/llvm/test/Transforms/InstCombine/and-or-icmp-min-max.ll
+++ b/llvm/test/Transforms/InstCombine/and-or-icmp-min-max.ll
@@ -689,6 +689,17 @@ define i1 @sge_and_max_logical(i8 %x, i8 %y) {
ret i1 %r
}
+define i1 @sge_and_max_logical_samesign(i8 %x, i8 %y) {
+; CHECK-LABEL: @sge_and_max_logical_samesign(
+; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq i8 [[X:%.*]], 127
+; CHECK-NEXT: ret i1 [[CMPEQ]]
+;
+ %cmp = icmp sge i8 %x, %y
+ %cmpeq = icmp samesign eq i8 %x, 127
+ %r = select i1 %cmp, i1 %cmpeq, i1 false
+ ret i1 %r
+}
+
define i1 @sge_and_max_commute(i8 %x, i8 %y) {
; CHECK-LABEL: @sge_and_max_commute(
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq i8 [[X:%.*]], 127
diff --git a/llvm/test/Transforms/InstCombine/and-or-icmp-nullptr.ll b/llvm/test/Transforms/InstCombine/and-or-icmp-nullptr.ll
index d533cc7048536c..8650b89c3b9ef3 100644
--- a/llvm/test/Transforms/InstCombine/and-or-icmp-nullptr.ll
+++ b/llvm/test/Transforms/InstCombine/and-or-icmp-nullptr.ll
@@ -592,6 +592,19 @@ define i1 @sgt_and_min_logical(ptr %x, ptr %y) {
ret i1 %r
}
+define i1 @sgt_and_min_logical_samesign(ptr %x, ptr %y) {
+; CHECK-LABEL: @sgt_and_min_logical_samesign(
+; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[X:%.*]], null
+; CHECK-NEXT: [[TMP1:%.*]] = icmp slt ptr [[Y:%.*]], null
+; CHECK-NEXT: [[R:%.*]] = and i1 [[CMPEQ]], [[TMP1]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %cmp = icmp sgt ptr %x, %y
+ %cmpeq = icmp samesign eq ptr %x, null
+ %r = select i1 %cmp, i1 %cmpeq, i1 false
+ ret i1 %r
+}
+
define i1 @sle_or_not_min(ptr %x, ptr %y) {
; CHECK-LABEL: @sle_or_not_min(
; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X:%.*]], null
|
nikic
left a comment
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
antoniofrighetto
left a comment
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.
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/7139 Here is the relevant piece of the build log for the reference |
In 5dbfca3 we assume that RHS is poison implies LHS is also poison. It doesn't hold after introducing samesign flag.
This patch drops the
samesignflag on RHS if the original expression is a logical and/or.It is an alternative to #112475.
Closes #112467.