Skip to content

Commit b80b7de

Browse files
committed
[ValueTracking] Convert isKnownNonZero to use SimplifyQuery
1 parent 9b725ff commit b80b7de

22 files changed

+83
-101
lines changed

llvm/include/llvm/Analysis/ValueTracking.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,7 @@ bool isOnlyUsedInZeroEqualityComparison(const Instruction *CxtI);
124124
/// specified, perform context-sensitive analysis and return true if the
125125
/// pointer couldn't possibly be null at the specified instruction.
126126
/// Supports values with integer or pointer type and vectors of integers.
127-
bool isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth = 0,
128-
AssumptionCache *AC = nullptr,
129-
const Instruction *CxtI = nullptr,
130-
const DominatorTree *DT = nullptr,
131-
bool UseInstrInfo = true);
127+
bool isKnownNonZero(const Value *V, unsigned Depth, const SimplifyQuery &Q);
132128

133129
/// Return true if the two given values are negation.
134130
/// Currently can recoginze Value pair:

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,8 @@ AliasResult BasicAAResult::aliasGEP(
12831283
// VarIndex = Scale*V.
12841284
const VariableGEPIndex &Var = DecompGEP1.VarIndices[0];
12851285
if (Var.Val.TruncBits == 0 &&
1286-
isKnownNonZero(Var.Val.V, DL, 0, &AC, Var.CxtI, DT)) {
1286+
isKnownNonZero(Var.Val.V, /*Depth=*/0,
1287+
SimplifyQuery(DL, DT, &AC, Var.CxtI))) {
12871288
// Check if abs(V*Scale) >= abs(Scale) holds in the presence of
12881289
// potentially wrapping math.
12891290
auto MultiplyByScaleNoWrap = [](const VariableGEPIndex &Var) {

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,12 +1586,10 @@ static Value *simplifyUnsignedRangeCheck(ICmpInst *ZeroICmp,
15861586
if (match(UnsignedICmp,
15871587
m_c_ICmp(UnsignedPred, m_Specific(Y), m_Specific(A)))) {
15881588
if (UnsignedPred == ICmpInst::ICMP_UGE && IsAnd &&
1589-
EqPred == ICmpInst::ICMP_NE &&
1590-
isKnownNonZero(B, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
1589+
EqPred == ICmpInst::ICMP_NE && isKnownNonZero(B, /*Depth=*/0, Q))
15911590
return UnsignedICmp;
15921591
if (UnsignedPred == ICmpInst::ICMP_ULT && !IsAnd &&
1593-
EqPred == ICmpInst::ICMP_EQ &&
1594-
isKnownNonZero(B, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
1592+
EqPred == ICmpInst::ICMP_EQ && isKnownNonZero(B, /*Depth=*/0, Q))
15951593
return UnsignedICmp;
15961594
}
15971595
}
@@ -1609,13 +1607,13 @@ static Value *simplifyUnsignedRangeCheck(ICmpInst *ZeroICmp,
16091607
// X > Y && Y == 0 --> Y == 0 iff X != 0
16101608
// X > Y || Y == 0 --> X > Y iff X != 0
16111609
if (UnsignedPred == ICmpInst::ICMP_UGT && EqPred == ICmpInst::ICMP_EQ &&
1612-
isKnownNonZero(X, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
1610+
isKnownNonZero(X, /*Depth=*/0, Q))
16131611
return IsAnd ? ZeroICmp : UnsignedICmp;
16141612

16151613
// X <= Y && Y != 0 --> X <= Y iff X != 0
16161614
// X <= Y || Y != 0 --> Y != 0 iff X != 0
16171615
if (UnsignedPred == ICmpInst::ICMP_ULE && EqPred == ICmpInst::ICMP_NE &&
1618-
isKnownNonZero(X, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
1616+
isKnownNonZero(X, /*Depth=*/0, Q))
16191617
return IsAnd ? UnsignedICmp : ZeroICmp;
16201618

16211619
// The transforms below here are expected to be handled more generally with
@@ -2821,11 +2819,10 @@ static Constant *computePointerICmp(CmpInst::Predicate Pred, Value *LHS,
28212819
// the other operand can not be based on the alloc - if it were, then
28222820
// the cmp itself would be a capture.
28232821
Value *MI = nullptr;
2824-
if (isAllocLikeFn(LHS, TLI) &&
2825-
llvm::isKnownNonZero(RHS, DL, 0, nullptr, CxtI, DT))
2822+
if (isAllocLikeFn(LHS, TLI) && llvm::isKnownNonZero(RHS, /*Depth=*/0, Q))
28262823
MI = LHS;
28272824
else if (isAllocLikeFn(RHS, TLI) &&
2828-
llvm::isKnownNonZero(LHS, DL, 0, nullptr, CxtI, DT))
2825+
llvm::isKnownNonZero(LHS, /*Depth=*/0, Q))
28292826
MI = RHS;
28302827
if (MI) {
28312828
// FIXME: This is incorrect, see PR54002. While we can assume that the
@@ -2981,12 +2978,12 @@ static Value *simplifyICmpWithZero(CmpInst::Predicate Pred, Value *LHS,
29812978
return getTrue(ITy);
29822979
case ICmpInst::ICMP_EQ:
29832980
case ICmpInst::ICMP_ULE:
2984-
if (isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT, Q.IIQ.UseInstrInfo))
2981+
if (isKnownNonZero(LHS, /*Depth=*/0, Q))
29852982
return getFalse(ITy);
29862983
break;
29872984
case ICmpInst::ICMP_NE:
29882985
case ICmpInst::ICMP_UGT:
2989-
if (isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT, Q.IIQ.UseInstrInfo))
2986+
if (isKnownNonZero(LHS, /*Depth=*/0, Q))
29902987
return getTrue(ITy);
29912988
break;
29922989
case ICmpInst::ICMP_SLT: {
@@ -3001,8 +2998,7 @@ static Value *simplifyICmpWithZero(CmpInst::Predicate Pred, Value *LHS,
30012998
KnownBits LHSKnown = computeKnownBits(LHS, /* Depth */ 0, Q);
30022999
if (LHSKnown.isNegative())
30033000
return getTrue(ITy);
3004-
if (LHSKnown.isNonNegative() &&
3005-
isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
3001+
if (LHSKnown.isNonNegative() && isKnownNonZero(LHS, /*Depth=*/0, Q))
30063002
return getFalse(ITy);
30073003
break;
30083004
}
@@ -3018,8 +3014,7 @@ static Value *simplifyICmpWithZero(CmpInst::Predicate Pred, Value *LHS,
30183014
KnownBits LHSKnown = computeKnownBits(LHS, /* Depth */ 0, Q);
30193015
if (LHSKnown.isNegative())
30203016
return getFalse(ITy);
3021-
if (LHSKnown.isNonNegative() &&
3022-
isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
3017+
if (LHSKnown.isNonNegative() && isKnownNonZero(LHS, /*Depth=*/0, Q))
30233018
return getTrue(ITy);
30243019
break;
30253020
}
@@ -3172,7 +3167,7 @@ static Value *simplifyICmpWithBinOpOnLHS(CmpInst::Predicate Pred,
31723167
const APInt *C;
31733168
if ((match(LBO, m_LShr(m_Specific(RHS), m_APInt(C))) && *C != 0) ||
31743169
(match(LBO, m_UDiv(m_Specific(RHS), m_APInt(C))) && *C != 1)) {
3175-
if (isKnownNonZero(RHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT)) {
3170+
if (isKnownNonZero(RHS, /*Depth=*/0, Q)) {
31763171
switch (Pred) {
31773172
default:
31783173
break;
@@ -3405,7 +3400,7 @@ static Value *simplifyICmpWithBinOp(CmpInst::Predicate Pred, Value *LHS,
34053400
bool NUW = Q.IIQ.hasNoUnsignedWrap(LBO) && Q.IIQ.hasNoUnsignedWrap(RBO);
34063401
bool NSW = Q.IIQ.hasNoSignedWrap(LBO) && Q.IIQ.hasNoSignedWrap(RBO);
34073402
if (!NUW || (ICmpInst::isSigned(Pred) && !NSW) ||
3408-
!isKnownNonZero(LBO->getOperand(0), Q.DL))
3403+
!isKnownNonZero(LBO->getOperand(0), /*Depth=*/0, Q))
34093404
break;
34103405
if (Value *V = simplifyICmpInst(Pred, LBO->getOperand(1),
34113406
RBO->getOperand(1), Q, MaxRecurse - 1))

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ LazyValueInfoImpl::solveBlockValueImpl(Value *Val, BasicBlock *BB) {
645645
// instruction is placed, even if it could legally be hoisted much higher.
646646
// That is unfortunate.
647647
PointerType *PT = dyn_cast<PointerType>(BBI->getType());
648-
if (PT && isKnownNonZero(BBI, DL))
648+
if (PT && isKnownNonZero(BBI, /*Depth=*/0, DL))
649649
return ValueLatticeElement::getNot(ConstantPointerNull::get(PT));
650650

651651
if (BBI->getType()->isIntegerTy()) {
@@ -1863,7 +1863,8 @@ LazyValueInfo::getPredicateAt(unsigned Pred, Value *V, Constant *C,
18631863
Module *M = CxtI->getModule();
18641864
const DataLayout &DL = M->getDataLayout();
18651865
if (V->getType()->isPointerTy() && C->isNullValue() &&
1866-
isKnownNonZero(V->stripPointerCastsSameRepresentation(), DL)) {
1866+
isKnownNonZero(V->stripPointerCastsSameRepresentation(), /*Depth=*/0,
1867+
DL)) {
18671868
if (Pred == ICmpInst::ICMP_EQ)
18681869
return LazyValueInfo::False;
18691870
else if (Pred == ICmpInst::ICMP_NE)

llvm/lib/Analysis/Loads.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ static bool isDereferenceableAndAlignedPointer(
9999
CheckForFreed));
100100
if (KnownDerefBytes.getBoolValue() && KnownDerefBytes.uge(Size) &&
101101
!CheckForFreed)
102-
if (!CheckForNonNull || isKnownNonZero(V, DL, 0, AC, CtxI, DT)) {
102+
if (!CheckForNonNull ||
103+
isKnownNonZero(V, /*Depth=*/0, SimplifyQuery(DL, DT, AC, CtxI))) {
103104
// As we recursed through GEPs to get here, we've incrementally checked
104105
// that each step advanced by a multiple of the alignment. If our base is
105106
// properly aligned, then the original offset accessed must also be.
@@ -133,7 +134,8 @@ static bool isDereferenceableAndAlignedPointer(
133134
if (getObjectSize(V, ObjSize, DL, TLI, Opts)) {
134135
APInt KnownDerefBytes(Size.getBitWidth(), ObjSize);
135136
if (KnownDerefBytes.getBoolValue() && KnownDerefBytes.uge(Size) &&
136-
isKnownNonZero(V, DL, 0, AC, CtxI, DT) && !V->canBeFreed()) {
137+
isKnownNonZero(V, /*Depth=*/0, SimplifyQuery(DL, DT, AC, CtxI)) &&
138+
!V->canBeFreed()) {
137139
// As we recursed through GEPs to get here, we've incrementally
138140
// checked that each step advanced by a multiple of the alignment. If
139141
// our base is properly aligned, then the original offset accessed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6893,7 +6893,7 @@ const ConstantRange &ScalarEvolution::getRangeRef(
68936893
uint64_t Rem = MaxVal.urem(Align);
68946894
MaxVal -= APInt(BitWidth, Rem);
68956895
APInt MinVal = APInt::getZero(BitWidth);
6896-
if (llvm::isKnownNonZero(V, DL))
6896+
if (llvm::isKnownNonZero(V, /*Depth=*/0, DL))
68976897
MinVal = Align;
68986898
ConservativeResult = ConservativeResult.intersectWith(
68996899
ConstantRange::getNonEmpty(MinVal, MaxVal + 1), RangeType);

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,6 @@ bool llvm::isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL,
274274
static bool isKnownNonZero(const Value *V, const APInt &DemandedElts,
275275
unsigned Depth, const SimplifyQuery &Q);
276276

277-
static bool isKnownNonZero(const Value *V, unsigned Depth,
278-
const SimplifyQuery &Q);
279-
280-
bool llvm::isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth,
281-
AssumptionCache *AC, const Instruction *CxtI,
282-
const DominatorTree *DT, bool UseInstrInfo) {
283-
return ::isKnownNonZero(
284-
V, Depth, SimplifyQuery(DL, DT, AC, safeCxtI(V, CxtI), UseInstrInfo));
285-
}
286-
287277
bool llvm::isKnownNonNegative(const Value *V, const SimplifyQuery &SQ,
288278
unsigned Depth) {
289279
return computeKnownBits(V, Depth, SQ).isNonNegative();
@@ -298,7 +288,7 @@ bool llvm::isKnownPositive(const Value *V, const SimplifyQuery &SQ,
298288
// this updated.
299289
KnownBits Known = computeKnownBits(V, Depth, SQ);
300290
return Known.isNonNegative() &&
301-
(Known.isNonZero() || ::isKnownNonZero(V, Depth, SQ));
291+
(Known.isNonZero() || isKnownNonZero(V, Depth, SQ));
302292
}
303293

304294
bool llvm::isKnownNegative(const Value *V, const SimplifyQuery &SQ,
@@ -3093,11 +3083,12 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
30933083
return false;
30943084
}
30953085

3096-
bool isKnownNonZero(const Value *V, unsigned Depth, const SimplifyQuery &Q) {
3086+
bool llvm::isKnownNonZero(const Value *V, unsigned Depth,
3087+
const SimplifyQuery &Q) {
30973088
auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
30983089
APInt DemandedElts =
30993090
FVTy ? APInt::getAllOnes(FVTy->getNumElements()) : APInt(1, 1);
3100-
return isKnownNonZero(V, DemandedElts, Depth, Q);
3091+
return ::isKnownNonZero(V, DemandedElts, Depth, Q);
31013092
}
31023093

31033094
/// If the pair of operators are the same invertible function, return the

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2314,7 +2314,7 @@ static bool despeculateCountZeros(IntrinsicInst *CountZeros,
23142314

23152315
// Bail if the value is never zero.
23162316
Use &Op = CountZeros->getOperandUse(0);
2317-
if (isKnownNonZero(Op, *DL))
2317+
if (isKnownNonZero(Op, /*Depth=*/0, SimplifyQuery(*DL)))
23182318
return false;
23192319

23202320
// The intrinsic will be sunk behind a compare against zero and branch.

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,8 +2452,9 @@ bool AANonNull::isImpliedByIR(Attributor &A, const IRPosition &IRP,
24522452
}
24532453

24542454
if (llvm::any_of(Worklist, [&](AA::ValueAndContext VAC) {
2455-
return !isKnownNonZero(VAC.getValue(), A.getDataLayout(), 0, AC,
2456-
VAC.getCtxI(), DT);
2455+
return !isKnownNonZero(
2456+
VAC.getValue(), /*Depth=*/0,
2457+
SimplifyQuery(A.getDataLayout(), DT, AC, VAC.getCtxI()));
24572458
}))
24582459
return false;
24592460

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ static bool isReturnNonNull(Function *F, const SCCNodeSet &SCCNodes,
11751175
Value *RetVal = FlowsToReturn[i];
11761176

11771177
// If this value is locally known to be non-null, we're good
1178-
if (isKnownNonZero(RetVal, DL))
1178+
if (isKnownNonZero(RetVal, /*Depth=*/0, DL))
11791179
continue;
11801180

11811181
// Otherwise, we need to look upwards since we can't make any local

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ Instruction *InstCombinerImpl::foldAddWithConstant(BinaryOperator &Add) {
988988
if (C->isOne()) {
989989
if (match(Op0, m_ZExt(m_Add(m_Value(X), m_AllOnes())))) {
990990
const SimplifyQuery Q = SQ.getWithInstruction(&Add);
991-
if (llvm::isKnownNonZero(X, DL, 0, Q.AC, Q.CxtI, Q.DT))
991+
if (llvm::isKnownNonZero(X, /*Depth=*/0, Q))
992992
return new ZExtInst(X, Ty);
993993
}
994994
}

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,10 +1031,6 @@ static Value *foldUnsignedUnderflowCheck(ICmpInst *ZeroICmp,
10311031
!ICmpInst::isEquality(EqPred))
10321032
return nullptr;
10331033

1034-
auto IsKnownNonZero = [&](Value *V) {
1035-
return isKnownNonZero(V, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT);
1036-
};
1037-
10381034
ICmpInst::Predicate UnsignedPred;
10391035

10401036
Value *A, *B;
@@ -1043,9 +1039,9 @@ static Value *foldUnsignedUnderflowCheck(ICmpInst *ZeroICmp,
10431039
match(ZeroCmpOp, m_c_Add(m_Specific(A), m_Value(B))) &&
10441040
(ZeroICmp->hasOneUse() || UnsignedICmp->hasOneUse())) {
10451041
auto GetKnownNonZeroAndOther = [&](Value *&NonZero, Value *&Other) {
1046-
if (!IsKnownNonZero(NonZero))
1042+
if (!isKnownNonZero(NonZero, /*Depth=*/0, Q))
10471043
std::swap(NonZero, Other);
1048-
return IsKnownNonZero(NonZero);
1044+
return isKnownNonZero(NonZero, /*Depth=*/0, Q);
10491045
};
10501046

10511047
// Given ZeroCmpOp = (A + B)

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,8 @@ static Instruction *foldCttzCtlz(IntrinsicInst &II, InstCombinerImpl &IC) {
601601
// then change the 'ZeroIsPoison' parameter to 'true'
602602
// because we know the zero behavior can't affect the result.
603603
if (!Known.One.isZero() ||
604-
isKnownNonZero(Op0, IC.getDataLayout(), 0, &IC.getAssumptionCache(), &II,
605-
&IC.getDominatorTree())) {
604+
isKnownNonZero(Op0, /*Depth=*/0,
605+
IC.getSimplifyQuery().getWithInstruction(&II))) {
606606
if (!match(II.getArgOperand(1), m_One()))
607607
return IC.replaceOperand(II, 1, IC.Builder.getTrue());
608608
}
@@ -2061,7 +2061,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
20612061
// See if we can deduce non-null.
20622062
if (!CI.hasRetAttr(Attribute::NonNull) &&
20632063
(Known.isNonZero() ||
2064-
isKnownNonZero(II, DL, /*Depth*/ 0, &AC, II, &DT))) {
2064+
isKnownNonZero(II, /*Depth=*/0,
2065+
getSimplifyQuery().getWithInstruction(II)))) {
20652066
CI.addRetAttr(Attribute::NonNull);
20662067
Changed = true;
20672068
}
@@ -3648,7 +3649,8 @@ Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) {
36483649
for (Value *V : Call.args()) {
36493650
if (V->getType()->isPointerTy() &&
36503651
!Call.paramHasAttr(ArgNo, Attribute::NonNull) &&
3651-
isKnownNonZero(V, DL, 0, &AC, &Call, &DT))
3652+
isKnownNonZero(V, /*Depth=*/0,
3653+
getSimplifyQuery().getWithInstruction(&Call)))
36523654
ArgNos.push_back(ArgNo);
36533655
ArgNo++;
36543656
}
@@ -3828,7 +3830,8 @@ Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) {
38283830

38293831
// isKnownNonNull -> nonnull attribute
38303832
if (!GCR.hasRetAttr(Attribute::NonNull) &&
3831-
isKnownNonZero(DerivedPtr, DL, 0, &AC, &Call, &DT)) {
3833+
isKnownNonZero(DerivedPtr, /*Depth=*/0,
3834+
getSimplifyQuery().getWithInstruction(&Call))) {
38323835
GCR.addRetAttr(Attribute::NonNull);
38333836
// We discovered new fact, re-check users.
38343837
Worklist.pushUsersToWorkList(GCR);

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,12 +1273,12 @@ Instruction *InstCombinerImpl::foldICmpWithZero(ICmpInst &Cmp) {
12731273

12741274
// if X non-zero and NoOverflow(X * Y)
12751275
// (icmp eq/ne Y)
1276-
if (!XKnown.One.isZero() || isKnownNonZero(X, DL, 0, Q.AC, Q.CxtI, Q.DT))
1276+
if (!XKnown.One.isZero() || isKnownNonZero(X, /*Depth=*/0, Q))
12771277
return new ICmpInst(Pred, Y, Cmp.getOperand(1));
12781278

12791279
// if Y non-zero and NoOverflow(X * Y)
12801280
// (icmp eq/ne X)
1281-
if (!YKnown.One.isZero() || isKnownNonZero(Y, DL, 0, Q.AC, Q.CxtI, Q.DT))
1281+
if (!YKnown.One.isZero() || isKnownNonZero(Y, /*Depth=*/0, Q))
12821282
return new ICmpInst(Pred, X, Cmp.getOperand(1));
12831283
}
12841284
// Note, we are skipping cases:
@@ -3087,7 +3087,7 @@ Instruction *InstCombinerImpl::foldICmpAddConstant(ICmpInst &Cmp,
30873087
// (X + -1) <u C --> X <=u C (if X is never null)
30883088
if (Pred == CmpInst::ICMP_ULT && C2->isAllOnes()) {
30893089
const SimplifyQuery Q = SQ.getWithInstruction(&Cmp);
3090-
if (llvm::isKnownNonZero(X, DL, 0, Q.AC, Q.CxtI, Q.DT))
3090+
if (llvm::isKnownNonZero(X, /*Depth=*/0, Q))
30913091
return new ICmpInst(ICmpInst::ICMP_ULE, X, ConstantInt::get(Ty, C));
30923092
}
30933093

@@ -4275,8 +4275,7 @@ static Value *foldICmpWithLowBitMaskedVal(ICmpInst::Predicate Pred, Value *Op0,
42754275

42764276
// Look for: x & ~Mask pred ~Mask
42774277
if (isMaskOrZero(X, /*Not=*/true, Q)) {
4278-
return !ICmpInst::isSigned(Pred) ||
4279-
isKnownNonZero(X, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT);
4278+
return !ICmpInst::isSigned(Pred) || isKnownNonZero(X, /*Depth=*/0, Q);
42804279
}
42814280
return false;
42824281
}
@@ -4780,8 +4779,7 @@ static Instruction *foldICmpXorXX(ICmpInst &I, const SimplifyQuery &Q,
47804779
// icmp (X ^ Y_NonZero) s>= X --> icmp (X ^ Y_NonZero) s> X
47814780
// icmp (X ^ Y_NonZero) s<= X --> icmp (X ^ Y_NonZero) s< X
47824781
CmpInst::Predicate PredOut = CmpInst::getStrictPredicate(Pred);
4783-
if (PredOut != Pred &&
4784-
isKnownNonZero(A, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
4782+
if (PredOut != Pred && isKnownNonZero(A, /*Depth=*/0, Q))
47854783
return new ICmpInst(PredOut, Op0, Op1);
47864784

47874785
return nullptr;
@@ -5064,11 +5062,11 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
50645062
return new ICmpInst(Pred, C, D);
50655063
// (A - B) u>=/u< A --> B u>/u<= A iff B != 0
50665064
if (A == Op1 && (Pred == ICmpInst::ICMP_UGE || Pred == ICmpInst::ICMP_ULT) &&
5067-
isKnownNonZero(B, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
5065+
isKnownNonZero(B, /*Depth=*/0, Q))
50685066
return new ICmpInst(CmpInst::getFlippedStrictnessPredicate(Pred), B, A);
50695067
// C u<=/u> (C - D) --> C u</u>= D iff B != 0
50705068
if (C == Op0 && (Pred == ICmpInst::ICMP_ULE || Pred == ICmpInst::ICMP_UGT) &&
5071-
isKnownNonZero(D, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
5069+
isKnownNonZero(D, /*Depth=*/0, Q))
50725070
return new ICmpInst(CmpInst::getFlippedStrictnessPredicate(Pred), C, D);
50735071

50745072
// icmp (A-B), (C-B) -> icmp A, C for equalities or if there is no overflow.
@@ -5110,14 +5108,13 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
51105108
// X * Z eq/ne Y * Z -> X eq/ne Y
51115109
if (ZKnown.countMaxTrailingZeros() == 0)
51125110
return new ICmpInst(Pred, X, Y);
5113-
NonZero = !ZKnown.One.isZero() ||
5114-
isKnownNonZero(Z, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT);
5111+
NonZero = !ZKnown.One.isZero() || isKnownNonZero(Z, /*Depth=*/0, Q);
51155112
// if Z != 0 and nsw(X * Z) and nsw(Y * Z)
51165113
// X * Z eq/ne Y * Z -> X eq/ne Y
51175114
if (NonZero && BO0 && BO1 && Op0HasNSW && Op1HasNSW)
51185115
return new ICmpInst(Pred, X, Y);
51195116
} else
5120-
NonZero = isKnownNonZero(Z, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT);
5117+
NonZero = isKnownNonZero(Z, /*Depth=*/0, Q);
51215118

51225119
// If Z != 0 and nuw(X * Z) and nuw(Y * Z)
51235120
// X * Z u{lt/le/gt/ge}/eq/ne Y * Z -> X u{lt/le/gt/ge}/eq/ne Y

llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,8 @@ Instruction *InstCombinerImpl::visitPHINode(PHINode &PN) {
15371537
for (unsigned I = 0, E = PN.getNumIncomingValues(); I != E; ++I) {
15381538
Instruction *CtxI = PN.getIncomingBlock(I)->getTerminator();
15391539
Value *VA = PN.getIncomingValue(I);
1540-
if (isKnownNonZero(VA, DL, 0, &AC, CtxI, &DT)) {
1540+
if (isKnownNonZero(VA, 0,
1541+
getSimplifyQuery().getWithInstruction(CtxI))) {
15411542
if (!NonZeroConst)
15421543
NonZeroConst = getAnyNonZeroConstInt(PN);
15431544
if (NonZeroConst != VA) {

0 commit comments

Comments
 (0)