Skip to content

Commit 1c6aab2

Browse files
committed
Change predicate match to expect same sign state
1 parent 821f62d commit 1c6aab2

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,12 +2182,14 @@ static Value *simplifyAndInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
21822182
m_c_ICmp(Pred0, m_Value(X), m_Not(m_Value(Y)))) &&
21832183
match(Op1, m_c_ICmp(Pred1, m_Specific(Y),
21842184
m_Not(m_Specific(X))))) {
2185-
if (ICmpInst::isLE(Pred0) && ICmpInst::isGT(Pred1))
2186-
return ConstantInt::getFalse(Op0->getType());
2187-
if (ICmpInst::isLT(Pred0) && ICmpInst::isGE(Pred1))
2188-
return ConstantInt::getFalse(Op0->getType());
2189-
if (ICmpInst::isLT(Pred0) && ICmpInst::isGT(Pred1))
2190-
return ConstantInt::getFalse(Op0->getType());
2185+
if (ICmpInst::isSigned(Pred0) == ICmpInst::isSigned(Pred1)) {
2186+
if (ICmpInst::isLE(Pred0) && ICmpInst::isGT(Pred1))
2187+
return ConstantInt::getFalse(Op0->getType());
2188+
if (ICmpInst::isLT(Pred0) && ICmpInst::isGE(Pred1))
2189+
return ConstantInt::getFalse(Op0->getType());
2190+
if (ICmpInst::isLT(Pred0) && ICmpInst::isGT(Pred1))
2191+
return ConstantInt::getFalse(Op0->getType());
2192+
}
21912193
}
21922194

21932195
if (Op0->getType()->isIntOrIntVectorTy(1)) {

llvm/test/Transforms/InstCombine/and-comparison-not-always-false.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,23 @@ common.ret:
136136
%common.ret.op = and i1 %6, %4
137137
ret i1 %common.ret.op
138138
}
139+
140+
define i1 @test_no_change_su(i32 %0, i32 %1) {
141+
; CHECK-LABEL: define i1 @test_no_change_su(
142+
; CHECK-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]]) {
143+
; CHECK-NEXT: [[COMMON_RET:.*:]]
144+
; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP0]], -1
145+
; CHECK-NEXT: [[TMP3:%.*]] = icmp sle i32 [[TMP1]], [[TMP2]]
146+
; CHECK-NEXT: [[TMP4:%.*]] = xor i32 [[TMP1]], -1
147+
; CHECK-NEXT: [[TMP5:%.*]] = icmp ugt i32 [[TMP0]], [[TMP4]]
148+
; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = and i1 [[TMP3]], [[TMP5]]
149+
; CHECK-NEXT: ret i1 [[COMMON_RET_OP]]
150+
;
151+
common.ret:
152+
%2 = xor i32 %0, -1
153+
%3 = icmp sle i32 %1, %2
154+
%4 = xor i32 %1, -1
155+
%5 = icmp ugt i32 %0, %4
156+
%common.ret.op = and i1 %3, %5
157+
ret i1 %common.ret.op
158+
}

0 commit comments

Comments
 (0)