Skip to content

Commit 60de56c

Browse files
authored
[ValueTracking] Restore isKnownNonZero parameter order. (#88873)
Prior to #85863, the required parameters of llvm::isKnownNonZero were Value and DataLayout. After, they are Value, Depth, and SimplifyQuery, where SimplifyQuery is implicitly constructible from DataLayout. The change to move Depth before SimplifyQuery needed callers to be updated unnecessarily, and as commented in #85863, we actually want Depth to be after SimplifyQuery anyway so that it can be defaulted and the caller does not need to specify it.
1 parent 3d118f9 commit 60de56c

22 files changed

+113
-124
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4124,8 +4124,7 @@ static bool isProvablyNull(llvm::Value *addr) {
41244124
}
41254125

41264126
static bool isProvablyNonNull(Address Addr, CodeGenFunction &CGF) {
4127-
return llvm::isKnownNonZero(Addr.getBasePointer(), /*Depth=*/0,
4128-
CGF.CGM.getDataLayout());
4127+
return llvm::isKnownNonZero(Addr.getBasePointer(), CGF.CGM.getDataLayout());
41294128
}
41304129

41314130
/// Emit the actual writing-back of a writeback.

llvm/include/llvm/Analysis/ValueTracking.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +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, unsigned Depth, const SimplifyQuery &Q);
127+
bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth = 0);
128128

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

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,8 +1283,7 @@ 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, /*Depth=*/0,
1287-
SimplifyQuery(DL, DT, &AC, Var.CxtI))) {
1286+
isKnownNonZero(Var.Val.V, SimplifyQuery(DL, DT, &AC, Var.CxtI))) {
12881287
// Check if abs(V*Scale) >= abs(Scale) holds in the presence of
12891288
// potentially wrapping math.
12901289
auto MultiplyByScaleNoWrap = [](const VariableGEPIndex &Var) {

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,10 +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 && isKnownNonZero(B, /*Depth=*/0, Q))
1589+
EqPred == ICmpInst::ICMP_NE && isKnownNonZero(B, Q))
15901590
return UnsignedICmp;
15911591
if (UnsignedPred == ICmpInst::ICMP_ULT && !IsAnd &&
1592-
EqPred == ICmpInst::ICMP_EQ && isKnownNonZero(B, /*Depth=*/0, Q))
1592+
EqPred == ICmpInst::ICMP_EQ && isKnownNonZero(B, Q))
15931593
return UnsignedICmp;
15941594
}
15951595
}
@@ -1607,13 +1607,13 @@ static Value *simplifyUnsignedRangeCheck(ICmpInst *ZeroICmp,
16071607
// X > Y && Y == 0 --> Y == 0 iff X != 0
16081608
// X > Y || Y == 0 --> X > Y iff X != 0
16091609
if (UnsignedPred == ICmpInst::ICMP_UGT && EqPred == ICmpInst::ICMP_EQ &&
1610-
isKnownNonZero(X, /*Depth=*/0, Q))
1610+
isKnownNonZero(X, Q))
16111611
return IsAnd ? ZeroICmp : UnsignedICmp;
16121612

16131613
// X <= Y && Y != 0 --> X <= Y iff X != 0
16141614
// X <= Y || Y != 0 --> Y != 0 iff X != 0
16151615
if (UnsignedPred == ICmpInst::ICMP_ULE && EqPred == ICmpInst::ICMP_NE &&
1616-
isKnownNonZero(X, /*Depth=*/0, Q))
1616+
isKnownNonZero(X, Q))
16171617
return IsAnd ? UnsignedICmp : ZeroICmp;
16181618

16191619
// The transforms below here are expected to be handled more generally with
@@ -2817,10 +2817,9 @@ static Constant *computePointerICmp(CmpInst::Predicate Pred, Value *LHS,
28172817
// the other operand can not be based on the alloc - if it were, then
28182818
// the cmp itself would be a capture.
28192819
Value *MI = nullptr;
2820-
if (isAllocLikeFn(LHS, TLI) && llvm::isKnownNonZero(RHS, /*Depth=*/0, Q))
2820+
if (isAllocLikeFn(LHS, TLI) && llvm::isKnownNonZero(RHS, Q))
28212821
MI = LHS;
2822-
else if (isAllocLikeFn(RHS, TLI) &&
2823-
llvm::isKnownNonZero(LHS, /*Depth=*/0, Q))
2822+
else if (isAllocLikeFn(RHS, TLI) && llvm::isKnownNonZero(LHS, Q))
28242823
MI = RHS;
28252824
if (MI) {
28262825
// FIXME: This is incorrect, see PR54002. While we can assume that the
@@ -2976,12 +2975,12 @@ static Value *simplifyICmpWithZero(CmpInst::Predicate Pred, Value *LHS,
29762975
return getTrue(ITy);
29772976
case ICmpInst::ICMP_EQ:
29782977
case ICmpInst::ICMP_ULE:
2979-
if (isKnownNonZero(LHS, /*Depth=*/0, Q))
2978+
if (isKnownNonZero(LHS, Q))
29802979
return getFalse(ITy);
29812980
break;
29822981
case ICmpInst::ICMP_NE:
29832982
case ICmpInst::ICMP_UGT:
2984-
if (isKnownNonZero(LHS, /*Depth=*/0, Q))
2983+
if (isKnownNonZero(LHS, Q))
29852984
return getTrue(ITy);
29862985
break;
29872986
case ICmpInst::ICMP_SLT: {
@@ -2996,7 +2995,7 @@ static Value *simplifyICmpWithZero(CmpInst::Predicate Pred, Value *LHS,
29962995
KnownBits LHSKnown = computeKnownBits(LHS, /* Depth */ 0, Q);
29972996
if (LHSKnown.isNegative())
29982997
return getTrue(ITy);
2999-
if (LHSKnown.isNonNegative() && isKnownNonZero(LHS, /*Depth=*/0, Q))
2998+
if (LHSKnown.isNonNegative() && isKnownNonZero(LHS, Q))
30002999
return getFalse(ITy);
30013000
break;
30023001
}
@@ -3012,7 +3011,7 @@ static Value *simplifyICmpWithZero(CmpInst::Predicate Pred, Value *LHS,
30123011
KnownBits LHSKnown = computeKnownBits(LHS, /* Depth */ 0, Q);
30133012
if (LHSKnown.isNegative())
30143013
return getFalse(ITy);
3015-
if (LHSKnown.isNonNegative() && isKnownNonZero(LHS, /*Depth=*/0, Q))
3014+
if (LHSKnown.isNonNegative() && isKnownNonZero(LHS, Q))
30163015
return getTrue(ITy);
30173016
break;
30183017
}
@@ -3165,7 +3164,7 @@ static Value *simplifyICmpWithBinOpOnLHS(CmpInst::Predicate Pred,
31653164
const APInt *C;
31663165
if ((match(LBO, m_LShr(m_Specific(RHS), m_APInt(C))) && *C != 0) ||
31673166
(match(LBO, m_UDiv(m_Specific(RHS), m_APInt(C))) && *C != 1)) {
3168-
if (isKnownNonZero(RHS, /*Depth=*/0, Q)) {
3167+
if (isKnownNonZero(RHS, Q)) {
31693168
switch (Pred) {
31703169
default:
31713170
break;
@@ -3398,7 +3397,7 @@ static Value *simplifyICmpWithBinOp(CmpInst::Predicate Pred, Value *LHS,
33983397
bool NUW = Q.IIQ.hasNoUnsignedWrap(LBO) && Q.IIQ.hasNoUnsignedWrap(RBO);
33993398
bool NSW = Q.IIQ.hasNoSignedWrap(LBO) && Q.IIQ.hasNoSignedWrap(RBO);
34003399
if (!NUW || (ICmpInst::isSigned(Pred) && !NSW) ||
3401-
!isKnownNonZero(LBO->getOperand(0), /*Depth=*/0, Q))
3400+
!isKnownNonZero(LBO->getOperand(0), Q))
34023401
break;
34033402
if (Value *V = simplifyICmpInst(Pred, LBO->getOperand(1),
34043403
RBO->getOperand(1), Q, MaxRecurse - 1))

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 2 additions & 3 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, /*Depth=*/0, DL))
648+
if (PT && isKnownNonZero(BBI, DL))
649649
return ValueLatticeElement::getNot(ConstantPointerNull::get(PT));
650650

651651
if (BBI->getType()->isIntegerTy()) {
@@ -1863,8 +1863,7 @@ 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(), /*Depth=*/0,
1867-
DL)) {
1866+
isKnownNonZero(V->stripPointerCastsSameRepresentation(), DL)) {
18681867
if (Pred == ICmpInst::ICMP_EQ)
18691868
return LazyValueInfo::False;
18701869
else if (Pred == ICmpInst::ICMP_NE)

llvm/lib/Analysis/Loads.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static bool isDereferenceableAndAlignedPointer(
100100
if (KnownDerefBytes.getBoolValue() && KnownDerefBytes.uge(Size) &&
101101
!CheckForFreed)
102102
if (!CheckForNonNull ||
103-
isKnownNonZero(V, /*Depth=*/0, SimplifyQuery(DL, DT, AC, CtxI))) {
103+
isKnownNonZero(V, SimplifyQuery(DL, DT, AC, CtxI))) {
104104
// As we recursed through GEPs to get here, we've incrementally checked
105105
// that each step advanced by a multiple of the alignment. If our base is
106106
// properly aligned, then the original offset accessed must also be.
@@ -134,7 +134,7 @@ static bool isDereferenceableAndAlignedPointer(
134134
if (getObjectSize(V, ObjSize, DL, TLI, Opts)) {
135135
APInt KnownDerefBytes(Size.getBitWidth(), ObjSize);
136136
if (KnownDerefBytes.getBoolValue() && KnownDerefBytes.uge(Size) &&
137-
isKnownNonZero(V, /*Depth=*/0, SimplifyQuery(DL, DT, AC, CtxI)) &&
137+
isKnownNonZero(V, SimplifyQuery(DL, DT, AC, CtxI)) &&
138138
!V->canBeFreed()) {
139139
// As we recursed through GEPs to get here, we've incrementally
140140
// checked that each step advanced by a multiple of the alignment. If

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6900,7 +6900,7 @@ const ConstantRange &ScalarEvolution::getRangeRef(
69006900
uint64_t Rem = MaxVal.urem(Align);
69016901
MaxVal -= APInt(BitWidth, Rem);
69026902
APInt MinVal = APInt::getZero(BitWidth);
6903-
if (llvm::isKnownNonZero(V, /*Depth=*/0, DL))
6903+
if (llvm::isKnownNonZero(V, DL))
69046904
MinVal = Align;
69056905
ConservativeResult = ConservativeResult.intersectWith(
69066906
ConstantRange::getNonEmpty(MinVal, MaxVal + 1), RangeType);

0 commit comments

Comments
 (0)