Skip to content

Commit f3c73ba

Browse files
committed
[ValueTracking] Convert isKnownNonZero to use SimplifyQuery
1 parent f9f363e commit f3c73ba

22 files changed

+85
-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
@@ -1585,12 +1585,10 @@ static Value *simplifyUnsignedRangeCheck(ICmpInst *ZeroICmp,
15851585
if (match(UnsignedICmp,
15861586
m_c_ICmp(UnsignedPred, m_Specific(Y), m_Specific(A)))) {
15871587
if (UnsignedPred == ICmpInst::ICMP_UGE && IsAnd &&
1588-
EqPred == ICmpInst::ICMP_NE &&
1589-
isKnownNonZero(B, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
1588+
EqPred == ICmpInst::ICMP_NE && isKnownNonZero(B, /*Depth=*/0, Q))
15901589
return UnsignedICmp;
15911590
if (UnsignedPred == ICmpInst::ICMP_ULT && !IsAnd &&
1592-
EqPred == ICmpInst::ICMP_EQ &&
1593-
isKnownNonZero(B, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
1591+
EqPred == ICmpInst::ICMP_EQ && isKnownNonZero(B, /*Depth=*/0, Q))
15941592
return UnsignedICmp;
15951593
}
15961594
}
@@ -1608,13 +1606,13 @@ static Value *simplifyUnsignedRangeCheck(ICmpInst *ZeroICmp,
16081606
// X > Y && Y == 0 --> Y == 0 iff X != 0
16091607
// X > Y || Y == 0 --> X > Y iff X != 0
16101608
if (UnsignedPred == ICmpInst::ICMP_UGT && EqPred == ICmpInst::ICMP_EQ &&
1611-
isKnownNonZero(X, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
1609+
isKnownNonZero(X, /*Depth=*/0, Q))
16121610
return IsAnd ? ZeroICmp : UnsignedICmp;
16131611

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

16201618
// The transforms below here are expected to be handled more generally with
@@ -2820,11 +2818,10 @@ static Constant *computePointerICmp(CmpInst::Predicate Pred, Value *LHS,
28202818
// the other operand can not be based on the alloc - if it were, then
28212819
// the cmp itself would be a capture.
28222820
Value *MI = nullptr;
2823-
if (isAllocLikeFn(LHS, TLI) &&
2824-
llvm::isKnownNonZero(RHS, DL, 0, nullptr, CxtI, DT))
2821+
if (isAllocLikeFn(LHS, TLI) && llvm::isKnownNonZero(RHS, /*Depth=*/0, Q))
28252822
MI = LHS;
28262823
else if (isAllocLikeFn(RHS, TLI) &&
2827-
llvm::isKnownNonZero(LHS, DL, 0, nullptr, CxtI, DT))
2824+
llvm::isKnownNonZero(LHS, /*Depth=*/0, Q))
28282825
MI = RHS;
28292826
if (MI) {
28302827
// FIXME: This is incorrect, see PR54002. While we can assume that the
@@ -2980,12 +2977,12 @@ static Value *simplifyICmpWithZero(CmpInst::Predicate Pred, Value *LHS,
29802977
return getTrue(ITy);
29812978
case ICmpInst::ICMP_EQ:
29822979
case ICmpInst::ICMP_ULE:
2983-
if (isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT, Q.IIQ.UseInstrInfo))
2980+
if (isKnownNonZero(LHS, /*Depth=*/0, Q))
29842981
return getFalse(ITy);
29852982
break;
29862983
case ICmpInst::ICMP_NE:
29872984
case ICmpInst::ICMP_UGT:
2988-
if (isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT, Q.IIQ.UseInstrInfo))
2985+
if (isKnownNonZero(LHS, /*Depth=*/0, Q))
29892986
return getTrue(ITy);
29902987
break;
29912988
case ICmpInst::ICMP_SLT: {
@@ -3000,8 +2997,7 @@ static Value *simplifyICmpWithZero(CmpInst::Predicate Pred, Value *LHS,
30002997
KnownBits LHSKnown = computeKnownBits(LHS, /* Depth */ 0, Q);
30012998
if (LHSKnown.isNegative())
30022999
return getTrue(ITy);
3003-
if (LHSKnown.isNonNegative() &&
3004-
isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
3000+
if (LHSKnown.isNonNegative() && isKnownNonZero(LHS, /*Depth=*/0, Q))
30053001
return getFalse(ITy);
30063002
break;
30073003
}
@@ -3017,8 +3013,7 @@ static Value *simplifyICmpWithZero(CmpInst::Predicate Pred, Value *LHS,
30173013
KnownBits LHSKnown = computeKnownBits(LHS, /* Depth */ 0, Q);
30183014
if (LHSKnown.isNegative())
30193015
return getFalse(ITy);
3020-
if (LHSKnown.isNonNegative() &&
3021-
isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
3016+
if (LHSKnown.isNonNegative() && isKnownNonZero(LHS, /*Depth=*/0, Q))
30223017
return getTrue(ITy);
30233018
break;
30243019
}
@@ -3171,7 +3166,7 @@ static Value *simplifyICmpWithBinOpOnLHS(CmpInst::Predicate Pred,
31713166
const APInt *C;
31723167
if ((match(LBO, m_LShr(m_Specific(RHS), m_APInt(C))) && *C != 0) ||
31733168
(match(LBO, m_UDiv(m_Specific(RHS), m_APInt(C))) && *C != 1)) {
3174-
if (isKnownNonZero(RHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT)) {
3169+
if (isKnownNonZero(RHS, /*Depth=*/0, Q)) {
31753170
switch (Pred) {
31763171
default:
31773172
break;
@@ -3404,7 +3399,7 @@ static Value *simplifyICmpWithBinOp(CmpInst::Predicate Pred, Value *LHS,
34043399
bool NUW = Q.IIQ.hasNoUnsignedWrap(LBO) && Q.IIQ.hasNoUnsignedWrap(RBO);
34053400
bool NSW = Q.IIQ.hasNoSignedWrap(LBO) && Q.IIQ.hasNoSignedWrap(RBO);
34063401
if (!NUW || (ICmpInst::isSigned(Pred) && !NSW) ||
3407-
!isKnownNonZero(LBO->getOperand(0), Q.DL))
3402+
!isKnownNonZero(LBO->getOperand(0), /*Depth=*/0, Q))
34083403
break;
34093404
if (Value *V = simplifyICmpInst(Pred, LBO->getOperand(1),
34103405
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
@@ -641,7 +641,7 @@ LazyValueInfoImpl::solveBlockValueImpl(Value *Val, BasicBlock *BB) {
641641
// instruction is placed, even if it could legally be hoisted much higher.
642642
// That is unfortunate.
643643
PointerType *PT = dyn_cast<PointerType>(BBI->getType());
644-
if (PT && isKnownNonZero(BBI, DL))
644+
if (PT && isKnownNonZero(BBI, /*Depth=*/0, SimplifyQuery(DL)))
645645
return ValueLatticeElement::getNot(ConstantPointerNull::get(PT));
646646

647647
if (BBI->getType()->isIntegerTy()) {
@@ -1858,7 +1858,8 @@ LazyValueInfo::getPredicateAt(unsigned Pred, Value *V, Constant *C,
18581858
Module *M = CxtI->getModule();
18591859
const DataLayout &DL = M->getDataLayout();
18601860
if (V->getType()->isPointerTy() && C->isNullValue() &&
1861-
isKnownNonZero(V->stripPointerCastsSameRepresentation(), DL)) {
1861+
isKnownNonZero(V->stripPointerCastsSameRepresentation(), /*Depth=*/0,
1862+
SimplifyQuery(DL))) {
18621863
if (Pred == ICmpInst::ICMP_EQ)
18631864
return LazyValueInfo::False;
18641865
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
@@ -6898,7 +6898,7 @@ const ConstantRange &ScalarEvolution::getRangeRef(
68986898
uint64_t Rem = MaxVal.urem(Align);
68996899
MaxVal -= APInt(BitWidth, Rem);
69006900
APInt MinVal = APInt::getZero(BitWidth);
6901-
if (llvm::isKnownNonZero(V, DL))
6901+
if (llvm::isKnownNonZero(V, /*Depth=*/0, SimplifyQuery(DL)))
69026902
MinVal = Align;
69036903
ConservativeResult = ConservativeResult.intersectWith(
69046904
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,
@@ -2975,11 +2965,12 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
29752965
return false;
29762966
}
29772967

2978-
bool isKnownNonZero(const Value *V, unsigned Depth, const SimplifyQuery &Q) {
2968+
bool llvm::isKnownNonZero(const Value *V, unsigned Depth,
2969+
const SimplifyQuery &Q) {
29792970
auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
29802971
APInt DemandedElts =
29812972
FVTy ? APInt::getAllOnes(FVTy->getNumElements()) : APInt(1, 1);
2982-
return isKnownNonZero(V, DemandedElts, Depth, Q);
2973+
return ::isKnownNonZero(V, DemandedElts, Depth, Q);
29832974
}
29842975

29852976
/// 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, SimplifyQuery(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
@@ -986,7 +986,7 @@ Instruction *InstCombinerImpl::foldAddWithConstant(BinaryOperator &Add) {
986986
if (C->isOne()) {
987987
if (match(Op0, m_ZExt(m_Add(m_Value(X), m_AllOnes())))) {
988988
const SimplifyQuery Q = SQ.getWithInstruction(&Add);
989-
if (llvm::isKnownNonZero(X, DL, 0, Q.AC, Q.CxtI, Q.DT))
989+
if (llvm::isKnownNonZero(X, /*Depth=*/0, Q))
990990
return new ZExtInst(X, Ty);
991991
}
992992
}

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
}
@@ -3647,7 +3648,8 @@ Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) {
36473648
for (Value *V : Call.args()) {
36483649
if (V->getType()->isPointerTy() &&
36493650
!Call.paramHasAttr(ArgNo, Attribute::NonNull) &&
3650-
isKnownNonZero(V, DL, 0, &AC, &Call, &DT))
3651+
isKnownNonZero(V, /*Depth=*/0,
3652+
getSimplifyQuery().getWithInstruction(&Call)))
36513653
ArgNos.push_back(ArgNo);
36523654
ArgNo++;
36533655
}
@@ -3827,7 +3829,8 @@ Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) {
38273829

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

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

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

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

12781278
// if Y non-zero and NoOverflow(X * Y)
12791279
// (icmp eq/ne X)
1280-
if (!YKnown.One.isZero() || isKnownNonZero(Y, DL, 0, Q.AC, Q.CxtI, Q.DT))
1280+
if (!YKnown.One.isZero() || isKnownNonZero(Y, /*Depth=*/0, Q))
12811281
return new ICmpInst(Pred, X, Cmp.getOperand(1));
12821282
}
12831283
// Note, we are skipping cases:
@@ -3076,7 +3076,7 @@ Instruction *InstCombinerImpl::foldICmpAddConstant(ICmpInst &Cmp,
30763076
// (X + -1) <u C --> X <=u C (if X is never null)
30773077
if (Pred == CmpInst::ICMP_ULT && C2->isAllOnes()) {
30783078
const SimplifyQuery Q = SQ.getWithInstruction(&Cmp);
3079-
if (llvm::isKnownNonZero(X, DL, 0, Q.AC, Q.CxtI, Q.DT))
3079+
if (llvm::isKnownNonZero(X, /*Depth=*/0, Q))
30803080
return new ICmpInst(ICmpInst::ICMP_ULE, X, ConstantInt::get(Ty, C));
30813081
}
30823082

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

42604260
// Look for: x & ~Mask pred ~Mask
42614261
if (isMaskOrZero(X, /*Not=*/true, Q)) {
4262-
return !ICmpInst::isSigned(Pred) ||
4263-
isKnownNonZero(X, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT);
4262+
return !ICmpInst::isSigned(Pred) || isKnownNonZero(X, /*Depth=*/0, Q);
42644263
}
42654264
return false;
42664265
}
@@ -4764,8 +4763,7 @@ static Instruction *foldICmpXorXX(ICmpInst &I, const SimplifyQuery &Q,
47644763
// icmp (X ^ Y_NonZero) s>= X --> icmp (X ^ Y_NonZero) s> X
47654764
// icmp (X ^ Y_NonZero) s<= X --> icmp (X ^ Y_NonZero) s< X
47664765
CmpInst::Predicate PredOut = CmpInst::getStrictPredicate(Pred);
4767-
if (PredOut != Pred &&
4768-
isKnownNonZero(A, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
4766+
if (PredOut != Pred && isKnownNonZero(A, /*Depth=*/0, Q))
47694767
return new ICmpInst(PredOut, Op0, Op1);
47704768

47714769
return nullptr;
@@ -5048,11 +5046,11 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
50485046
return new ICmpInst(Pred, C, D);
50495047
// (A - B) u>=/u< A --> B u>/u<= A iff B != 0
50505048
if (A == Op1 && (Pred == ICmpInst::ICMP_UGE || Pred == ICmpInst::ICMP_ULT) &&
5051-
isKnownNonZero(B, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
5049+
isKnownNonZero(B, /*Depth=*/0, Q))
50525050
return new ICmpInst(CmpInst::getFlippedStrictnessPredicate(Pred), B, A);
50535051
// C u<=/u> (C - D) --> C u</u>= D iff B != 0
50545052
if (C == Op0 && (Pred == ICmpInst::ICMP_ULE || Pred == ICmpInst::ICMP_UGT) &&
5055-
isKnownNonZero(D, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
5053+
isKnownNonZero(D, /*Depth=*/0, Q))
50565054
return new ICmpInst(CmpInst::getFlippedStrictnessPredicate(Pred), C, D);
50575055

50585056
// icmp (A-B), (C-B) -> icmp A, C for equalities or if there is no overflow.
@@ -5094,14 +5092,13 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
50945092
// X * Z eq/ne Y * Z -> X eq/ne Y
50955093
if (ZKnown.countMaxTrailingZeros() == 0)
50965094
return new ICmpInst(Pred, X, Y);
5097-
NonZero = !ZKnown.One.isZero() ||
5098-
isKnownNonZero(Z, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT);
5095+
NonZero = !ZKnown.One.isZero() || isKnownNonZero(Z, /*Depth=*/0, Q);
50995096
// if Z != 0 and nsw(X * Z) and nsw(Y * Z)
51005097
// X * Z eq/ne Y * Z -> X eq/ne Y
51015098
if (NonZero && BO0 && BO1 && Op0HasNSW && Op1HasNSW)
51025099
return new ICmpInst(Pred, X, Y);
51035100
} else
5104-
NonZero = isKnownNonZero(Z, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT);
5101+
NonZero = isKnownNonZero(Z, /*Depth=*/0, Q);
51055102

51065103
// If Z != 0 and nuw(X * Z) and nuw(Y * Z)
51075104
// 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)