Skip to content

Commit 1021b0a

Browse files
committed
[InstSimplify] Simplify 'x u>= 1' to true when x is known non-zero
1 parent b7d0c9b commit 1021b0a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,7 +2981,7 @@ static Value *simplifyICmpWithZero(CmpPredicate Pred, Value *LHS, Value *RHS,
29812981
}
29822982

29832983
static Value *simplifyICmpWithConstant(CmpPredicate Pred, Value *LHS,
2984-
Value *RHS, const InstrInfoQuery &IIQ) {
2984+
Value *RHS, const SimplifyQuery &Q) {
29852985
Type *ITy = getCompareTy(RHS); // The return type.
29862986

29872987
Value *X;
@@ -3007,7 +3007,7 @@ static Value *simplifyICmpWithConstant(CmpPredicate Pred, Value *LHS,
30073007
return ConstantInt::getTrue(ITy);
30083008

30093009
ConstantRange LHS_CR =
3010-
computeConstantRange(LHS, CmpInst::isSigned(Pred), IIQ.UseInstrInfo);
3010+
computeConstantRange(LHS, CmpInst::isSigned(Pred), Q.IIQ.UseInstrInfo);
30113011
if (!LHS_CR.isFullSet()) {
30123012
if (RHS_CR.contains(LHS_CR))
30133013
return ConstantInt::getTrue(ITy);
@@ -3018,13 +3018,16 @@ static Value *simplifyICmpWithConstant(CmpPredicate Pred, Value *LHS,
30183018
// (mul nuw/nsw X, MulC) != C --> true (if C is not a multiple of MulC)
30193019
// (mul nuw/nsw X, MulC) == C --> false (if C is not a multiple of MulC)
30203020
const APInt *MulC;
3021-
if (IIQ.UseInstrInfo && ICmpInst::isEquality(Pred) &&
3021+
if (Q.IIQ.UseInstrInfo && ICmpInst::isEquality(Pred) &&
30223022
((match(LHS, m_NUWMul(m_Value(), m_APIntAllowPoison(MulC))) &&
30233023
*MulC != 0 && C->urem(*MulC) != 0) ||
30243024
(match(LHS, m_NSWMul(m_Value(), m_APIntAllowPoison(MulC))) &&
30253025
*MulC != 0 && C->srem(*MulC) != 0)))
30263026
return ConstantInt::get(ITy, Pred == ICmpInst::ICMP_NE);
30273027

3028+
if (Pred == ICmpInst::ICMP_UGE && C->isOne() && isKnownNonZero(LHS, Q))
3029+
return ConstantInt::getTrue(ITy);
3030+
30283031
return nullptr;
30293032
}
30303033

@@ -3776,7 +3779,7 @@ static Value *simplifyICmpInst(CmpPredicate Pred, Value *LHS, Value *RHS,
37763779
if (Value *V = simplifyICmpWithZero(Pred, LHS, RHS, Q))
37773780
return V;
37783781

3779-
if (Value *V = simplifyICmpWithConstant(Pred, LHS, RHS, Q.IIQ))
3782+
if (Value *V = simplifyICmpWithConstant(Pred, LHS, RHS, Q))
37803783
return V;
37813784

37823785
// If both operands have range metadata, use the metadata

0 commit comments

Comments
 (0)