-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[ValueTracking] Make Depth last default arg (NFC) #142384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-vectorizers @llvm/pr-subscribers-llvm-analysis Author: Ramkumar Ramachandra (artagnon) ChangesHaving a finite Depth (or recursion limit) for computeKnownBits is very limiting, but is currently a load-bearing necessity, as all KnownBits are recomputed on each call and there is no caching. As a prerequisite for an effort to remove the recursion limit altogether, either using a clever caching technique, or writing a easily-invalidable KnownBits analysis, make the Depth argument in APIs in ValueTracking uniformly the last argument with a default value. This would aid in removing the argument when the time comes, as many callers that currently pass 0 explicitly are now updated to omit the argument altogether. Patch is 272.00 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/142384.diff 40 Files Affected:
diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h
index feb7a1fa2cb35..b05b8f349b8d5 100644
--- a/llvm/include/llvm/Analysis/ValueTracking.h
+++ b/llvm/include/llvm/Analysis/ValueTracking.h
@@ -54,36 +54,37 @@ constexpr unsigned MaxAnalysisRecursionDepth = 6;
/// same width as the vector element, and the bit is set only if it is true
/// for all of the elements in the vector.
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known,
- const DataLayout &DL, unsigned Depth = 0,
+ const DataLayout &DL,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true, unsigned Depth = 0);
/// Returns the known bits rather than passing by reference.
LLVM_ABI KnownBits computeKnownBits(const Value *V, const DataLayout &DL,
- unsigned Depth = 0,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true,
+ unsigned Depth = 0);
/// Returns the known bits rather than passing by reference.
LLVM_ABI KnownBits computeKnownBits(const Value *V, const APInt &DemandedElts,
- const DataLayout &DL, unsigned Depth = 0,
+ const DataLayout &DL,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true,
+ unsigned Depth = 0);
LLVM_ABI KnownBits computeKnownBits(const Value *V, const APInt &DemandedElts,
- unsigned Depth, const SimplifyQuery &Q);
+ const SimplifyQuery &Q, unsigned Depth = 0);
-LLVM_ABI KnownBits computeKnownBits(const Value *V, unsigned Depth,
- const SimplifyQuery &Q);
+LLVM_ABI KnownBits computeKnownBits(const Value *V, const SimplifyQuery &Q,
+ unsigned Depth = 0);
-LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth,
- const SimplifyQuery &Q);
+LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known,
+ const SimplifyQuery &Q, unsigned Depth = 0);
/// Compute known bits from the range metadata.
/// \p KnownZero the set of bits that are known to be zero
@@ -93,22 +94,22 @@ LLVM_ABI void computeKnownBitsFromRangeMetadata(const MDNode &Ranges,
/// Merge bits known from context-dependent facts into Known.
LLVM_ABI void computeKnownBitsFromContext(const Value *V, KnownBits &Known,
- unsigned Depth,
- const SimplifyQuery &Q);
+ const SimplifyQuery &Q,
+ unsigned Depth = 0);
/// Using KnownBits LHS/RHS produce the known bits for logic op (and/xor/or).
LLVM_ABI KnownBits analyzeKnownBitsFromAndXorOr(const Operator *I,
const KnownBits &KnownLHS,
const KnownBits &KnownRHS,
- unsigned Depth,
- const SimplifyQuery &SQ);
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Adjust \p Known for the given select \p Arm to include information from the
/// select \p Cond.
LLVM_ABI void adjustKnownBitsForSelectArm(KnownBits &Known, Value *Cond,
Value *Arm, bool Invert,
- unsigned Depth,
- const SimplifyQuery &Q);
+ const SimplifyQuery &Q,
+ unsigned Depth = 0);
/// Return true if LHS and RHS have no common bits set.
LLVM_ABI bool haveNoCommonBitsSet(const WithCache<const Value *> &LHSCache,
@@ -121,14 +122,16 @@ LLVM_ABI bool haveNoCommonBitsSet(const WithCache<const Value *> &LHSCache,
/// vectors of integers. If 'OrZero' is set, then return true if the given
/// value is either a power of two or zero.
LLVM_ABI bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL,
- bool OrZero = false, unsigned Depth = 0,
+ bool OrZero = false,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true,
+ unsigned Depth = 0);
LLVM_ABI bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero,
- unsigned Depth, const SimplifyQuery &Q);
+ const SimplifyQuery &Q,
+ unsigned Depth = 0);
LLVM_ABI bool isOnlyUsedInZeroComparison(const Instruction *CxtI);
@@ -196,21 +199,21 @@ LLVM_ABI bool MaskedValueIsZero(const Value *V, const APInt &Mask,
/// sign bits for the vector element with the mininum number of known sign
/// bits.
LLVM_ABI unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL,
- unsigned Depth = 0,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true,
+ unsigned Depth = 0);
/// Get the upper bound on bit size for this Value \p Op as a signed integer.
/// i.e. x == sext(trunc(x to MaxSignificantBits) to bitwidth(x)).
/// Similar to the APInt::getSignificantBits function.
LLVM_ABI unsigned ComputeMaxSignificantBits(const Value *Op,
const DataLayout &DL,
- unsigned Depth = 0,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
- const DominatorTree *DT = nullptr);
+ const DominatorTree *DT = nullptr,
+ unsigned Depth = 0);
/// Map a call instruction to an intrinsic ID. Libcalls which have equivalent
/// intrinsics are treated as-if they were intrinsics.
@@ -236,36 +239,36 @@ LLVM_ABI bool isSignBitCheck(ICmpInst::Predicate Pred, const APInt &RHS,
LLVM_ABI KnownFPClass computeKnownFPClass(const Value *V,
const APInt &DemandedElts,
FPClassTest InterestedClasses,
- unsigned Depth,
- const SimplifyQuery &SQ);
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
LLVM_ABI KnownFPClass computeKnownFPClass(const Value *V,
FPClassTest InterestedClasses,
- unsigned Depth,
- const SimplifyQuery &SQ);
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
LLVM_ABI KnownFPClass computeKnownFPClass(
const Value *V, const DataLayout &DL,
- FPClassTest InterestedClasses = fcAllFlags, unsigned Depth = 0,
+ FPClassTest InterestedClasses = fcAllFlags,
const TargetLibraryInfo *TLI = nullptr, AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr, const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true, unsigned Depth = 0);
/// Wrapper to account for known fast math flags at the use instruction.
LLVM_ABI KnownFPClass computeKnownFPClass(
const Value *V, const APInt &DemandedElts, FastMathFlags FMF,
- FPClassTest InterestedClasses, unsigned Depth, const SimplifyQuery &SQ);
+ FPClassTest InterestedClasses, const SimplifyQuery &SQ, unsigned Depth = 0);
LLVM_ABI KnownFPClass computeKnownFPClass(const Value *V, FastMathFlags FMF,
FPClassTest InterestedClasses,
- unsigned Depth,
- const SimplifyQuery &SQ);
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if we can prove that the specified FP value is never equal to
/// -0.0. Users should use caution when considering PreserveSign
/// denormal-fp-math.
-LLVM_ABI bool cannotBeNegativeZero(const Value *V, unsigned Depth,
- const SimplifyQuery &SQ);
+LLVM_ABI bool cannotBeNegativeZero(const Value *V, const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if we can prove that the specified FP value is either NaN or
/// never less than -0.0.
@@ -275,30 +278,32 @@ LLVM_ABI bool cannotBeNegativeZero(const Value *V, unsigned Depth,
/// -0 --> true
/// x > +0 --> true
/// x < -0 --> false
-LLVM_ABI bool cannotBeOrderedLessThanZero(const Value *V, unsigned Depth,
- const SimplifyQuery &SQ);
+LLVM_ABI bool cannotBeOrderedLessThanZero(const Value *V,
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if the floating-point scalar value is not an infinity or if
/// the floating-point vector value has no infinities. Return false if a value
/// could ever be infinity.
-LLVM_ABI bool isKnownNeverInfinity(const Value *V, unsigned Depth,
- const SimplifyQuery &SQ);
+LLVM_ABI bool isKnownNeverInfinity(const Value *V, const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if the floating-point value can never contain a NaN or infinity.
-LLVM_ABI bool isKnownNeverInfOrNaN(const Value *V, unsigned Depth,
- const SimplifyQuery &SQ);
+LLVM_ABI bool isKnownNeverInfOrNaN(const Value *V, const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if the floating-point scalar value is not a NaN or if the
/// floating-point vector value has no NaN elements. Return false if a value
/// could ever be NaN.
-LLVM_ABI bool isKnownNeverNaN(const Value *V, unsigned Depth,
- const SimplifyQuery &SQ);
+LLVM_ABI bool isKnownNeverNaN(const Value *V, const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return false if we can prove that the specified FP value's sign bit is 0.
/// Return true if we can prove that the specified FP value's sign bit is 1.
/// Otherwise return std::nullopt.
-LLVM_ABI std::optional<bool>
-computeKnownFPSignBit(const Value *V, unsigned Depth, const SimplifyQuery &SQ);
+LLVM_ABI std::optional<bool> computeKnownFPSignBit(const Value *V,
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if the sign bit of the FP value can be ignored by the user when
/// the value is zero.
diff --git a/llvm/include/llvm/Analysis/WithCache.h b/llvm/include/llvm/Analysis/WithCache.h
index 82c230a32297c..3bf35a889bbf2 100644
--- a/llvm/include/llvm/Analysis/WithCache.h
+++ b/llvm/include/llvm/Analysis/WithCache.h
@@ -22,8 +22,8 @@
namespace llvm {
struct SimplifyQuery;
-LLVM_ABI KnownBits computeKnownBits(const Value *V, unsigned Depth,
- const SimplifyQuery &Q);
+LLVM_ABI KnownBits computeKnownBits(const Value *V, const SimplifyQuery &Q,
+ unsigned Depth);
template <typename Arg> class WithCache {
static_assert(std::is_pointer_v<Arg>, "WithCache requires a pointer type!");
@@ -45,7 +45,7 @@ template <typename Arg> class WithCache {
mutable KnownBits Known;
void calculateKnownBits(const SimplifyQuery &Q) const {
- Known = computeKnownBits(Pointer.getPointer(), 0, Q);
+ Known = computeKnownBits(Pointer.getPointer(), Q, 0);
Pointer.setInt(true);
}
diff --git a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
index fa6b60cba15aa..fa313f5290773 100644
--- a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
+++ b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
@@ -430,36 +430,39 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
/// methods should return the value returned by this function.
virtual Instruction *eraseInstFromFunction(Instruction &I) = 0;
- void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth,
- const Instruction *CxtI) const {
- llvm::computeKnownBits(V, Known, Depth, SQ.getWithInstruction(CxtI));
+ void computeKnownBits(const Value *V, KnownBits &Known,
+ const Instruction *CxtI, unsigned Depth = 0) const {
+ llvm::computeKnownBits(V, Known, SQ.getWithInstruction(CxtI), Depth);
}
- KnownBits computeKnownBits(const Value *V, unsigned Depth,
- const Instruction *CxtI) const {
- return llvm::computeKnownBits(V, Depth, SQ.getWithInstruction(CxtI));
+ KnownBits computeKnownBits(const Value *V, const Instruction *CxtI,
+ unsigned Depth = 0) const {
+ return llvm::computeKnownBits(V, SQ.getWithInstruction(CxtI), Depth);
}
bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero = false,
- unsigned Depth = 0,
- const Instruction *CxtI = nullptr) {
- return llvm::isKnownToBeAPowerOfTwo(V, OrZero, Depth,
- SQ.getWithInstruction(CxtI));
+ const Instruction *CxtI = nullptr,
+ unsigned Depth = 0) {
+ return llvm::isKnownToBeAPowerOfTwo(V, OrZero, SQ.getWithInstruction(CxtI),
+ Depth);
}
- bool MaskedValueIsZero(const Value *V, const APInt &Mask, unsigned Depth = 0,
- const Instruction *CxtI = nullptr) const {
+ bool MaskedValueIsZero(const Value *V, const APInt &Mask,
+ const Instruction *CxtI = nullptr,
+ unsigned Depth = 0) const {
return llvm::MaskedValueIsZero(V, Mask, SQ.getWithInstruction(CxtI), Depth);
}
- unsigned ComputeNumSignBits(const Value *Op, unsigned Depth = 0,
- const Instruction *CxtI = nullptr) const {
- return llvm::ComputeNumSignBits(Op, DL, Depth, &AC, CxtI, &DT);
+ unsigned ComputeNumSignBits(const Value *Op,
+ const Instruction *CxtI = nullptr,
+ unsigned Depth = 0) const {
+ return llvm::ComputeNumSignBits(Op, DL, &AC, CxtI, &DT, Depth);
}
- unsigned ComputeMaxSignificantBits(const Value *Op, unsigned Depth = 0,
- const Instruction *CxtI = nullptr) const {
- return llvm::ComputeMaxSignificantBits(Op, DL, Depth, &AC, CxtI, &DT);
+ unsigned ComputeMaxSignificantBits(const Value *Op,
+ const Instruction *CxtI = nullptr,
+ unsigned Depth = 0) const {
+ return llvm::ComputeMaxSignificantBits(Op, DL, &AC, CxtI, &DT, Depth);
}
OverflowResult computeOverflowForUnsignedMul(const Value *LHS,
@@ -507,12 +510,13 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
virtual bool SimplifyDemandedBits(Instruction *I, unsigned OpNo,
const APInt &DemandedMask, KnownBits &Known,
- unsigned Depth, const SimplifyQuery &Q) = 0;
+ const SimplifyQuery &Q,
+ unsigned Depth = 0) = 0;
bool SimplifyDemandedBits(Instruction *I, unsigned OpNo,
const APInt &DemandedMask, KnownBits &Known) {
return SimplifyDemandedBits(I, OpNo, DemandedMask, Known,
- /*Depth=*/0, SQ.getWithInstruction(I));
+ SQ.getWithInstruction(I));
}
virtual Value *
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index bcc9a71917aaf..b110c2017b9eb 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1261,8 +1261,7 @@ AliasResult BasicAAResult::aliasGEP(
ConstantRange CR = computeConstantRange(Index.Val.V, /* ForSigned */ false,
true, &AC, Index.CxtI);
- KnownBits Known =
- computeKnownBits(Index.Val.V, DL, 0, &AC, Index.CxtI, DT);
+ KnownBits Known = computeKnownBits(Index.Val.V, DL, &AC, Index.CxtI, DT);
CR = CR.intersectWith(
ConstantRange::fromKnownBits(Known, /* Signed */ true),
ConstantRange::Signed);
diff --git a/llvm/lib/Analysis/DemandedBits.cpp b/llvm/lib/Analysis/DemandedBits.cpp
index b538e16f25859..d7e2a3fa4fc59 100644
--- a/llvm/lib/Analysis/DemandedBits.cpp
+++ b/llvm/lib/Analysis/DemandedBits.cpp
@@ -70,11 +70,11 @@ void DemandedBits::determineLiveOperandBits(
const DataLayout &DL = UserI->getDataLayout();
Known = KnownBits(BitWidth);
- computeKnownBits(V1, Known, DL, 0, &AC, UserI, &DT);
+ computeKnownBits(V1, Known, DL, &AC, UserI, &DT);
if (V2) {
Known2 = KnownBits(BitWidth);
- computeKnownBits(V2, Known2, DL, 0, &AC, UserI, &DT);
+ computeKnownBits(V2, Known2, DL, &AC, UserI, &DT);
}
};
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index b7c7bcab168cc..d13f2e139ee4a 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -111,7 +111,7 @@ static std::pair<Type *, bool> computeRecurrenceType(Instruction *Exit,
// If demanded bits wasn't able to limit the bit width, we can try to use
// value tracking instead. This can be the case, for example, if the value
// may be negative.
- auto NumSignBits = ComputeNumSignBits(Exit, DL, 0, AC, nullptr, DT);
+ auto NumSignBits = ComputeNumSignBits(Exit, DL, AC, nullptr, DT);
auto NumTypeBits = DL.getTypeSizeInBits(Exit->getType());
MaxBitWidth = NumTypeBits - NumSignBits;
KnownBits Bits = computeKnownBits(Exit, DL);
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 12c84c718d4fd..e397a228afee0 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -770,7 +770,7 @@ static Value *simplifySubInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
if (IsNUW)
return Constant::getNullValue(Op0->getType());
- KnownBit...
[truncated]
|
@llvm/pr-subscribers-backend-x86 Author: Ramkumar Ramachandra (artagnon) ChangesHaving a finite Depth (or recursion limit) for computeKnownBits is very limiting, but is currently a load-bearing necessity, as all KnownBits are recomputed on each call and there is no caching. As a prerequisite for an effort to remove the recursion limit altogether, either using a clever caching technique, or writing a easily-invalidable KnownBits analysis, make the Depth argument in APIs in ValueTracking uniformly the last argument with a default value. This would aid in removing the argument when the time comes, as many callers that currently pass 0 explicitly are now updated to omit the argument altogether. Patch is 272.00 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/142384.diff 40 Files Affected:
diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h
index feb7a1fa2cb35..b05b8f349b8d5 100644
--- a/llvm/include/llvm/Analysis/ValueTracking.h
+++ b/llvm/include/llvm/Analysis/ValueTracking.h
@@ -54,36 +54,37 @@ constexpr unsigned MaxAnalysisRecursionDepth = 6;
/// same width as the vector element, and the bit is set only if it is true
/// for all of the elements in the vector.
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known,
- const DataLayout &DL, unsigned Depth = 0,
+ const DataLayout &DL,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true, unsigned Depth = 0);
/// Returns the known bits rather than passing by reference.
LLVM_ABI KnownBits computeKnownBits(const Value *V, const DataLayout &DL,
- unsigned Depth = 0,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true,
+ unsigned Depth = 0);
/// Returns the known bits rather than passing by reference.
LLVM_ABI KnownBits computeKnownBits(const Value *V, const APInt &DemandedElts,
- const DataLayout &DL, unsigned Depth = 0,
+ const DataLayout &DL,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true,
+ unsigned Depth = 0);
LLVM_ABI KnownBits computeKnownBits(const Value *V, const APInt &DemandedElts,
- unsigned Depth, const SimplifyQuery &Q);
+ const SimplifyQuery &Q, unsigned Depth = 0);
-LLVM_ABI KnownBits computeKnownBits(const Value *V, unsigned Depth,
- const SimplifyQuery &Q);
+LLVM_ABI KnownBits computeKnownBits(const Value *V, const SimplifyQuery &Q,
+ unsigned Depth = 0);
-LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth,
- const SimplifyQuery &Q);
+LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known,
+ const SimplifyQuery &Q, unsigned Depth = 0);
/// Compute known bits from the range metadata.
/// \p KnownZero the set of bits that are known to be zero
@@ -93,22 +94,22 @@ LLVM_ABI void computeKnownBitsFromRangeMetadata(const MDNode &Ranges,
/// Merge bits known from context-dependent facts into Known.
LLVM_ABI void computeKnownBitsFromContext(const Value *V, KnownBits &Known,
- unsigned Depth,
- const SimplifyQuery &Q);
+ const SimplifyQuery &Q,
+ unsigned Depth = 0);
/// Using KnownBits LHS/RHS produce the known bits for logic op (and/xor/or).
LLVM_ABI KnownBits analyzeKnownBitsFromAndXorOr(const Operator *I,
const KnownBits &KnownLHS,
const KnownBits &KnownRHS,
- unsigned Depth,
- const SimplifyQuery &SQ);
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Adjust \p Known for the given select \p Arm to include information from the
/// select \p Cond.
LLVM_ABI void adjustKnownBitsForSelectArm(KnownBits &Known, Value *Cond,
Value *Arm, bool Invert,
- unsigned Depth,
- const SimplifyQuery &Q);
+ const SimplifyQuery &Q,
+ unsigned Depth = 0);
/// Return true if LHS and RHS have no common bits set.
LLVM_ABI bool haveNoCommonBitsSet(const WithCache<const Value *> &LHSCache,
@@ -121,14 +122,16 @@ LLVM_ABI bool haveNoCommonBitsSet(const WithCache<const Value *> &LHSCache,
/// vectors of integers. If 'OrZero' is set, then return true if the given
/// value is either a power of two or zero.
LLVM_ABI bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL,
- bool OrZero = false, unsigned Depth = 0,
+ bool OrZero = false,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true,
+ unsigned Depth = 0);
LLVM_ABI bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero,
- unsigned Depth, const SimplifyQuery &Q);
+ const SimplifyQuery &Q,
+ unsigned Depth = 0);
LLVM_ABI bool isOnlyUsedInZeroComparison(const Instruction *CxtI);
@@ -196,21 +199,21 @@ LLVM_ABI bool MaskedValueIsZero(const Value *V, const APInt &Mask,
/// sign bits for the vector element with the mininum number of known sign
/// bits.
LLVM_ABI unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL,
- unsigned Depth = 0,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true,
+ unsigned Depth = 0);
/// Get the upper bound on bit size for this Value \p Op as a signed integer.
/// i.e. x == sext(trunc(x to MaxSignificantBits) to bitwidth(x)).
/// Similar to the APInt::getSignificantBits function.
LLVM_ABI unsigned ComputeMaxSignificantBits(const Value *Op,
const DataLayout &DL,
- unsigned Depth = 0,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
- const DominatorTree *DT = nullptr);
+ const DominatorTree *DT = nullptr,
+ unsigned Depth = 0);
/// Map a call instruction to an intrinsic ID. Libcalls which have equivalent
/// intrinsics are treated as-if they were intrinsics.
@@ -236,36 +239,36 @@ LLVM_ABI bool isSignBitCheck(ICmpInst::Predicate Pred, const APInt &RHS,
LLVM_ABI KnownFPClass computeKnownFPClass(const Value *V,
const APInt &DemandedElts,
FPClassTest InterestedClasses,
- unsigned Depth,
- const SimplifyQuery &SQ);
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
LLVM_ABI KnownFPClass computeKnownFPClass(const Value *V,
FPClassTest InterestedClasses,
- unsigned Depth,
- const SimplifyQuery &SQ);
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
LLVM_ABI KnownFPClass computeKnownFPClass(
const Value *V, const DataLayout &DL,
- FPClassTest InterestedClasses = fcAllFlags, unsigned Depth = 0,
+ FPClassTest InterestedClasses = fcAllFlags,
const TargetLibraryInfo *TLI = nullptr, AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr, const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true, unsigned Depth = 0);
/// Wrapper to account for known fast math flags at the use instruction.
LLVM_ABI KnownFPClass computeKnownFPClass(
const Value *V, const APInt &DemandedElts, FastMathFlags FMF,
- FPClassTest InterestedClasses, unsigned Depth, const SimplifyQuery &SQ);
+ FPClassTest InterestedClasses, const SimplifyQuery &SQ, unsigned Depth = 0);
LLVM_ABI KnownFPClass computeKnownFPClass(const Value *V, FastMathFlags FMF,
FPClassTest InterestedClasses,
- unsigned Depth,
- const SimplifyQuery &SQ);
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if we can prove that the specified FP value is never equal to
/// -0.0. Users should use caution when considering PreserveSign
/// denormal-fp-math.
-LLVM_ABI bool cannotBeNegativeZero(const Value *V, unsigned Depth,
- const SimplifyQuery &SQ);
+LLVM_ABI bool cannotBeNegativeZero(const Value *V, const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if we can prove that the specified FP value is either NaN or
/// never less than -0.0.
@@ -275,30 +278,32 @@ LLVM_ABI bool cannotBeNegativeZero(const Value *V, unsigned Depth,
/// -0 --> true
/// x > +0 --> true
/// x < -0 --> false
-LLVM_ABI bool cannotBeOrderedLessThanZero(const Value *V, unsigned Depth,
- const SimplifyQuery &SQ);
+LLVM_ABI bool cannotBeOrderedLessThanZero(const Value *V,
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if the floating-point scalar value is not an infinity or if
/// the floating-point vector value has no infinities. Return false if a value
/// could ever be infinity.
-LLVM_ABI bool isKnownNeverInfinity(const Value *V, unsigned Depth,
- const SimplifyQuery &SQ);
+LLVM_ABI bool isKnownNeverInfinity(const Value *V, const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if the floating-point value can never contain a NaN or infinity.
-LLVM_ABI bool isKnownNeverInfOrNaN(const Value *V, unsigned Depth,
- const SimplifyQuery &SQ);
+LLVM_ABI bool isKnownNeverInfOrNaN(const Value *V, const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if the floating-point scalar value is not a NaN or if the
/// floating-point vector value has no NaN elements. Return false if a value
/// could ever be NaN.
-LLVM_ABI bool isKnownNeverNaN(const Value *V, unsigned Depth,
- const SimplifyQuery &SQ);
+LLVM_ABI bool isKnownNeverNaN(const Value *V, const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return false if we can prove that the specified FP value's sign bit is 0.
/// Return true if we can prove that the specified FP value's sign bit is 1.
/// Otherwise return std::nullopt.
-LLVM_ABI std::optional<bool>
-computeKnownFPSignBit(const Value *V, unsigned Depth, const SimplifyQuery &SQ);
+LLVM_ABI std::optional<bool> computeKnownFPSignBit(const Value *V,
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if the sign bit of the FP value can be ignored by the user when
/// the value is zero.
diff --git a/llvm/include/llvm/Analysis/WithCache.h b/llvm/include/llvm/Analysis/WithCache.h
index 82c230a32297c..3bf35a889bbf2 100644
--- a/llvm/include/llvm/Analysis/WithCache.h
+++ b/llvm/include/llvm/Analysis/WithCache.h
@@ -22,8 +22,8 @@
namespace llvm {
struct SimplifyQuery;
-LLVM_ABI KnownBits computeKnownBits(const Value *V, unsigned Depth,
- const SimplifyQuery &Q);
+LLVM_ABI KnownBits computeKnownBits(const Value *V, const SimplifyQuery &Q,
+ unsigned Depth);
template <typename Arg> class WithCache {
static_assert(std::is_pointer_v<Arg>, "WithCache requires a pointer type!");
@@ -45,7 +45,7 @@ template <typename Arg> class WithCache {
mutable KnownBits Known;
void calculateKnownBits(const SimplifyQuery &Q) const {
- Known = computeKnownBits(Pointer.getPointer(), 0, Q);
+ Known = computeKnownBits(Pointer.getPointer(), Q, 0);
Pointer.setInt(true);
}
diff --git a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
index fa6b60cba15aa..fa313f5290773 100644
--- a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
+++ b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
@@ -430,36 +430,39 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
/// methods should return the value returned by this function.
virtual Instruction *eraseInstFromFunction(Instruction &I) = 0;
- void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth,
- const Instruction *CxtI) const {
- llvm::computeKnownBits(V, Known, Depth, SQ.getWithInstruction(CxtI));
+ void computeKnownBits(const Value *V, KnownBits &Known,
+ const Instruction *CxtI, unsigned Depth = 0) const {
+ llvm::computeKnownBits(V, Known, SQ.getWithInstruction(CxtI), Depth);
}
- KnownBits computeKnownBits(const Value *V, unsigned Depth,
- const Instruction *CxtI) const {
- return llvm::computeKnownBits(V, Depth, SQ.getWithInstruction(CxtI));
+ KnownBits computeKnownBits(const Value *V, const Instruction *CxtI,
+ unsigned Depth = 0) const {
+ return llvm::computeKnownBits(V, SQ.getWithInstruction(CxtI), Depth);
}
bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero = false,
- unsigned Depth = 0,
- const Instruction *CxtI = nullptr) {
- return llvm::isKnownToBeAPowerOfTwo(V, OrZero, Depth,
- SQ.getWithInstruction(CxtI));
+ const Instruction *CxtI = nullptr,
+ unsigned Depth = 0) {
+ return llvm::isKnownToBeAPowerOfTwo(V, OrZero, SQ.getWithInstruction(CxtI),
+ Depth);
}
- bool MaskedValueIsZero(const Value *V, const APInt &Mask, unsigned Depth = 0,
- const Instruction *CxtI = nullptr) const {
+ bool MaskedValueIsZero(const Value *V, const APInt &Mask,
+ const Instruction *CxtI = nullptr,
+ unsigned Depth = 0) const {
return llvm::MaskedValueIsZero(V, Mask, SQ.getWithInstruction(CxtI), Depth);
}
- unsigned ComputeNumSignBits(const Value *Op, unsigned Depth = 0,
- const Instruction *CxtI = nullptr) const {
- return llvm::ComputeNumSignBits(Op, DL, Depth, &AC, CxtI, &DT);
+ unsigned ComputeNumSignBits(const Value *Op,
+ const Instruction *CxtI = nullptr,
+ unsigned Depth = 0) const {
+ return llvm::ComputeNumSignBits(Op, DL, &AC, CxtI, &DT, Depth);
}
- unsigned ComputeMaxSignificantBits(const Value *Op, unsigned Depth = 0,
- const Instruction *CxtI = nullptr) const {
- return llvm::ComputeMaxSignificantBits(Op, DL, Depth, &AC, CxtI, &DT);
+ unsigned ComputeMaxSignificantBits(const Value *Op,
+ const Instruction *CxtI = nullptr,
+ unsigned Depth = 0) const {
+ return llvm::ComputeMaxSignificantBits(Op, DL, &AC, CxtI, &DT, Depth);
}
OverflowResult computeOverflowForUnsignedMul(const Value *LHS,
@@ -507,12 +510,13 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
virtual bool SimplifyDemandedBits(Instruction *I, unsigned OpNo,
const APInt &DemandedMask, KnownBits &Known,
- unsigned Depth, const SimplifyQuery &Q) = 0;
+ const SimplifyQuery &Q,
+ unsigned Depth = 0) = 0;
bool SimplifyDemandedBits(Instruction *I, unsigned OpNo,
const APInt &DemandedMask, KnownBits &Known) {
return SimplifyDemandedBits(I, OpNo, DemandedMask, Known,
- /*Depth=*/0, SQ.getWithInstruction(I));
+ SQ.getWithInstruction(I));
}
virtual Value *
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index bcc9a71917aaf..b110c2017b9eb 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1261,8 +1261,7 @@ AliasResult BasicAAResult::aliasGEP(
ConstantRange CR = computeConstantRange(Index.Val.V, /* ForSigned */ false,
true, &AC, Index.CxtI);
- KnownBits Known =
- computeKnownBits(Index.Val.V, DL, 0, &AC, Index.CxtI, DT);
+ KnownBits Known = computeKnownBits(Index.Val.V, DL, &AC, Index.CxtI, DT);
CR = CR.intersectWith(
ConstantRange::fromKnownBits(Known, /* Signed */ true),
ConstantRange::Signed);
diff --git a/llvm/lib/Analysis/DemandedBits.cpp b/llvm/lib/Analysis/DemandedBits.cpp
index b538e16f25859..d7e2a3fa4fc59 100644
--- a/llvm/lib/Analysis/DemandedBits.cpp
+++ b/llvm/lib/Analysis/DemandedBits.cpp
@@ -70,11 +70,11 @@ void DemandedBits::determineLiveOperandBits(
const DataLayout &DL = UserI->getDataLayout();
Known = KnownBits(BitWidth);
- computeKnownBits(V1, Known, DL, 0, &AC, UserI, &DT);
+ computeKnownBits(V1, Known, DL, &AC, UserI, &DT);
if (V2) {
Known2 = KnownBits(BitWidth);
- computeKnownBits(V2, Known2, DL, 0, &AC, UserI, &DT);
+ computeKnownBits(V2, Known2, DL, &AC, UserI, &DT);
}
};
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index b7c7bcab168cc..d13f2e139ee4a 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -111,7 +111,7 @@ static std::pair<Type *, bool> computeRecurrenceType(Instruction *Exit,
// If demanded bits wasn't able to limit the bit width, we can try to use
// value tracking instead. This can be the case, for example, if the value
// may be negative.
- auto NumSignBits = ComputeNumSignBits(Exit, DL, 0, AC, nullptr, DT);
+ auto NumSignBits = ComputeNumSignBits(Exit, DL, AC, nullptr, DT);
auto NumTypeBits = DL.getTypeSizeInBits(Exit->getType());
MaxBitWidth = NumTypeBits - NumSignBits;
KnownBits Bits = computeKnownBits(Exit, DL);
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 12c84c718d4fd..e397a228afee0 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -770,7 +770,7 @@ static Value *simplifySubInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
if (IsNUW)
return Constant::getNullValue(Op0->getType());
- KnownBit...
[truncated]
|
@llvm/pr-subscribers-backend-hexagon Author: Ramkumar Ramachandra (artagnon) ChangesHaving a finite Depth (or recursion limit) for computeKnownBits is very limiting, but is currently a load-bearing necessity, as all KnownBits are recomputed on each call and there is no caching. As a prerequisite for an effort to remove the recursion limit altogether, either using a clever caching technique, or writing a easily-invalidable KnownBits analysis, make the Depth argument in APIs in ValueTracking uniformly the last argument with a default value. This would aid in removing the argument when the time comes, as many callers that currently pass 0 explicitly are now updated to omit the argument altogether. Patch is 272.00 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/142384.diff 40 Files Affected:
diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h
index feb7a1fa2cb35..b05b8f349b8d5 100644
--- a/llvm/include/llvm/Analysis/ValueTracking.h
+++ b/llvm/include/llvm/Analysis/ValueTracking.h
@@ -54,36 +54,37 @@ constexpr unsigned MaxAnalysisRecursionDepth = 6;
/// same width as the vector element, and the bit is set only if it is true
/// for all of the elements in the vector.
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known,
- const DataLayout &DL, unsigned Depth = 0,
+ const DataLayout &DL,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true, unsigned Depth = 0);
/// Returns the known bits rather than passing by reference.
LLVM_ABI KnownBits computeKnownBits(const Value *V, const DataLayout &DL,
- unsigned Depth = 0,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true,
+ unsigned Depth = 0);
/// Returns the known bits rather than passing by reference.
LLVM_ABI KnownBits computeKnownBits(const Value *V, const APInt &DemandedElts,
- const DataLayout &DL, unsigned Depth = 0,
+ const DataLayout &DL,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true,
+ unsigned Depth = 0);
LLVM_ABI KnownBits computeKnownBits(const Value *V, const APInt &DemandedElts,
- unsigned Depth, const SimplifyQuery &Q);
+ const SimplifyQuery &Q, unsigned Depth = 0);
-LLVM_ABI KnownBits computeKnownBits(const Value *V, unsigned Depth,
- const SimplifyQuery &Q);
+LLVM_ABI KnownBits computeKnownBits(const Value *V, const SimplifyQuery &Q,
+ unsigned Depth = 0);
-LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth,
- const SimplifyQuery &Q);
+LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known,
+ const SimplifyQuery &Q, unsigned Depth = 0);
/// Compute known bits from the range metadata.
/// \p KnownZero the set of bits that are known to be zero
@@ -93,22 +94,22 @@ LLVM_ABI void computeKnownBitsFromRangeMetadata(const MDNode &Ranges,
/// Merge bits known from context-dependent facts into Known.
LLVM_ABI void computeKnownBitsFromContext(const Value *V, KnownBits &Known,
- unsigned Depth,
- const SimplifyQuery &Q);
+ const SimplifyQuery &Q,
+ unsigned Depth = 0);
/// Using KnownBits LHS/RHS produce the known bits for logic op (and/xor/or).
LLVM_ABI KnownBits analyzeKnownBitsFromAndXorOr(const Operator *I,
const KnownBits &KnownLHS,
const KnownBits &KnownRHS,
- unsigned Depth,
- const SimplifyQuery &SQ);
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Adjust \p Known for the given select \p Arm to include information from the
/// select \p Cond.
LLVM_ABI void adjustKnownBitsForSelectArm(KnownBits &Known, Value *Cond,
Value *Arm, bool Invert,
- unsigned Depth,
- const SimplifyQuery &Q);
+ const SimplifyQuery &Q,
+ unsigned Depth = 0);
/// Return true if LHS and RHS have no common bits set.
LLVM_ABI bool haveNoCommonBitsSet(const WithCache<const Value *> &LHSCache,
@@ -121,14 +122,16 @@ LLVM_ABI bool haveNoCommonBitsSet(const WithCache<const Value *> &LHSCache,
/// vectors of integers. If 'OrZero' is set, then return true if the given
/// value is either a power of two or zero.
LLVM_ABI bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL,
- bool OrZero = false, unsigned Depth = 0,
+ bool OrZero = false,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true,
+ unsigned Depth = 0);
LLVM_ABI bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero,
- unsigned Depth, const SimplifyQuery &Q);
+ const SimplifyQuery &Q,
+ unsigned Depth = 0);
LLVM_ABI bool isOnlyUsedInZeroComparison(const Instruction *CxtI);
@@ -196,21 +199,21 @@ LLVM_ABI bool MaskedValueIsZero(const Value *V, const APInt &Mask,
/// sign bits for the vector element with the mininum number of known sign
/// bits.
LLVM_ABI unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL,
- unsigned Depth = 0,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true,
+ unsigned Depth = 0);
/// Get the upper bound on bit size for this Value \p Op as a signed integer.
/// i.e. x == sext(trunc(x to MaxSignificantBits) to bitwidth(x)).
/// Similar to the APInt::getSignificantBits function.
LLVM_ABI unsigned ComputeMaxSignificantBits(const Value *Op,
const DataLayout &DL,
- unsigned Depth = 0,
AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr,
- const DominatorTree *DT = nullptr);
+ const DominatorTree *DT = nullptr,
+ unsigned Depth = 0);
/// Map a call instruction to an intrinsic ID. Libcalls which have equivalent
/// intrinsics are treated as-if they were intrinsics.
@@ -236,36 +239,36 @@ LLVM_ABI bool isSignBitCheck(ICmpInst::Predicate Pred, const APInt &RHS,
LLVM_ABI KnownFPClass computeKnownFPClass(const Value *V,
const APInt &DemandedElts,
FPClassTest InterestedClasses,
- unsigned Depth,
- const SimplifyQuery &SQ);
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
LLVM_ABI KnownFPClass computeKnownFPClass(const Value *V,
FPClassTest InterestedClasses,
- unsigned Depth,
- const SimplifyQuery &SQ);
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
LLVM_ABI KnownFPClass computeKnownFPClass(
const Value *V, const DataLayout &DL,
- FPClassTest InterestedClasses = fcAllFlags, unsigned Depth = 0,
+ FPClassTest InterestedClasses = fcAllFlags,
const TargetLibraryInfo *TLI = nullptr, AssumptionCache *AC = nullptr,
const Instruction *CxtI = nullptr, const DominatorTree *DT = nullptr,
- bool UseInstrInfo = true);
+ bool UseInstrInfo = true, unsigned Depth = 0);
/// Wrapper to account for known fast math flags at the use instruction.
LLVM_ABI KnownFPClass computeKnownFPClass(
const Value *V, const APInt &DemandedElts, FastMathFlags FMF,
- FPClassTest InterestedClasses, unsigned Depth, const SimplifyQuery &SQ);
+ FPClassTest InterestedClasses, const SimplifyQuery &SQ, unsigned Depth = 0);
LLVM_ABI KnownFPClass computeKnownFPClass(const Value *V, FastMathFlags FMF,
FPClassTest InterestedClasses,
- unsigned Depth,
- const SimplifyQuery &SQ);
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if we can prove that the specified FP value is never equal to
/// -0.0. Users should use caution when considering PreserveSign
/// denormal-fp-math.
-LLVM_ABI bool cannotBeNegativeZero(const Value *V, unsigned Depth,
- const SimplifyQuery &SQ);
+LLVM_ABI bool cannotBeNegativeZero(const Value *V, const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if we can prove that the specified FP value is either NaN or
/// never less than -0.0.
@@ -275,30 +278,32 @@ LLVM_ABI bool cannotBeNegativeZero(const Value *V, unsigned Depth,
/// -0 --> true
/// x > +0 --> true
/// x < -0 --> false
-LLVM_ABI bool cannotBeOrderedLessThanZero(const Value *V, unsigned Depth,
- const SimplifyQuery &SQ);
+LLVM_ABI bool cannotBeOrderedLessThanZero(const Value *V,
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if the floating-point scalar value is not an infinity or if
/// the floating-point vector value has no infinities. Return false if a value
/// could ever be infinity.
-LLVM_ABI bool isKnownNeverInfinity(const Value *V, unsigned Depth,
- const SimplifyQuery &SQ);
+LLVM_ABI bool isKnownNeverInfinity(const Value *V, const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if the floating-point value can never contain a NaN or infinity.
-LLVM_ABI bool isKnownNeverInfOrNaN(const Value *V, unsigned Depth,
- const SimplifyQuery &SQ);
+LLVM_ABI bool isKnownNeverInfOrNaN(const Value *V, const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if the floating-point scalar value is not a NaN or if the
/// floating-point vector value has no NaN elements. Return false if a value
/// could ever be NaN.
-LLVM_ABI bool isKnownNeverNaN(const Value *V, unsigned Depth,
- const SimplifyQuery &SQ);
+LLVM_ABI bool isKnownNeverNaN(const Value *V, const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return false if we can prove that the specified FP value's sign bit is 0.
/// Return true if we can prove that the specified FP value's sign bit is 1.
/// Otherwise return std::nullopt.
-LLVM_ABI std::optional<bool>
-computeKnownFPSignBit(const Value *V, unsigned Depth, const SimplifyQuery &SQ);
+LLVM_ABI std::optional<bool> computeKnownFPSignBit(const Value *V,
+ const SimplifyQuery &SQ,
+ unsigned Depth = 0);
/// Return true if the sign bit of the FP value can be ignored by the user when
/// the value is zero.
diff --git a/llvm/include/llvm/Analysis/WithCache.h b/llvm/include/llvm/Analysis/WithCache.h
index 82c230a32297c..3bf35a889bbf2 100644
--- a/llvm/include/llvm/Analysis/WithCache.h
+++ b/llvm/include/llvm/Analysis/WithCache.h
@@ -22,8 +22,8 @@
namespace llvm {
struct SimplifyQuery;
-LLVM_ABI KnownBits computeKnownBits(const Value *V, unsigned Depth,
- const SimplifyQuery &Q);
+LLVM_ABI KnownBits computeKnownBits(const Value *V, const SimplifyQuery &Q,
+ unsigned Depth);
template <typename Arg> class WithCache {
static_assert(std::is_pointer_v<Arg>, "WithCache requires a pointer type!");
@@ -45,7 +45,7 @@ template <typename Arg> class WithCache {
mutable KnownBits Known;
void calculateKnownBits(const SimplifyQuery &Q) const {
- Known = computeKnownBits(Pointer.getPointer(), 0, Q);
+ Known = computeKnownBits(Pointer.getPointer(), Q, 0);
Pointer.setInt(true);
}
diff --git a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
index fa6b60cba15aa..fa313f5290773 100644
--- a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
+++ b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
@@ -430,36 +430,39 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
/// methods should return the value returned by this function.
virtual Instruction *eraseInstFromFunction(Instruction &I) = 0;
- void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth,
- const Instruction *CxtI) const {
- llvm::computeKnownBits(V, Known, Depth, SQ.getWithInstruction(CxtI));
+ void computeKnownBits(const Value *V, KnownBits &Known,
+ const Instruction *CxtI, unsigned Depth = 0) const {
+ llvm::computeKnownBits(V, Known, SQ.getWithInstruction(CxtI), Depth);
}
- KnownBits computeKnownBits(const Value *V, unsigned Depth,
- const Instruction *CxtI) const {
- return llvm::computeKnownBits(V, Depth, SQ.getWithInstruction(CxtI));
+ KnownBits computeKnownBits(const Value *V, const Instruction *CxtI,
+ unsigned Depth = 0) const {
+ return llvm::computeKnownBits(V, SQ.getWithInstruction(CxtI), Depth);
}
bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero = false,
- unsigned Depth = 0,
- const Instruction *CxtI = nullptr) {
- return llvm::isKnownToBeAPowerOfTwo(V, OrZero, Depth,
- SQ.getWithInstruction(CxtI));
+ const Instruction *CxtI = nullptr,
+ unsigned Depth = 0) {
+ return llvm::isKnownToBeAPowerOfTwo(V, OrZero, SQ.getWithInstruction(CxtI),
+ Depth);
}
- bool MaskedValueIsZero(const Value *V, const APInt &Mask, unsigned Depth = 0,
- const Instruction *CxtI = nullptr) const {
+ bool MaskedValueIsZero(const Value *V, const APInt &Mask,
+ const Instruction *CxtI = nullptr,
+ unsigned Depth = 0) const {
return llvm::MaskedValueIsZero(V, Mask, SQ.getWithInstruction(CxtI), Depth);
}
- unsigned ComputeNumSignBits(const Value *Op, unsigned Depth = 0,
- const Instruction *CxtI = nullptr) const {
- return llvm::ComputeNumSignBits(Op, DL, Depth, &AC, CxtI, &DT);
+ unsigned ComputeNumSignBits(const Value *Op,
+ const Instruction *CxtI = nullptr,
+ unsigned Depth = 0) const {
+ return llvm::ComputeNumSignBits(Op, DL, &AC, CxtI, &DT, Depth);
}
- unsigned ComputeMaxSignificantBits(const Value *Op, unsigned Depth = 0,
- const Instruction *CxtI = nullptr) const {
- return llvm::ComputeMaxSignificantBits(Op, DL, Depth, &AC, CxtI, &DT);
+ unsigned ComputeMaxSignificantBits(const Value *Op,
+ const Instruction *CxtI = nullptr,
+ unsigned Depth = 0) const {
+ return llvm::ComputeMaxSignificantBits(Op, DL, &AC, CxtI, &DT, Depth);
}
OverflowResult computeOverflowForUnsignedMul(const Value *LHS,
@@ -507,12 +510,13 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
virtual bool SimplifyDemandedBits(Instruction *I, unsigned OpNo,
const APInt &DemandedMask, KnownBits &Known,
- unsigned Depth, const SimplifyQuery &Q) = 0;
+ const SimplifyQuery &Q,
+ unsigned Depth = 0) = 0;
bool SimplifyDemandedBits(Instruction *I, unsigned OpNo,
const APInt &DemandedMask, KnownBits &Known) {
return SimplifyDemandedBits(I, OpNo, DemandedMask, Known,
- /*Depth=*/0, SQ.getWithInstruction(I));
+ SQ.getWithInstruction(I));
}
virtual Value *
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index bcc9a71917aaf..b110c2017b9eb 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1261,8 +1261,7 @@ AliasResult BasicAAResult::aliasGEP(
ConstantRange CR = computeConstantRange(Index.Val.V, /* ForSigned */ false,
true, &AC, Index.CxtI);
- KnownBits Known =
- computeKnownBits(Index.Val.V, DL, 0, &AC, Index.CxtI, DT);
+ KnownBits Known = computeKnownBits(Index.Val.V, DL, &AC, Index.CxtI, DT);
CR = CR.intersectWith(
ConstantRange::fromKnownBits(Known, /* Signed */ true),
ConstantRange::Signed);
diff --git a/llvm/lib/Analysis/DemandedBits.cpp b/llvm/lib/Analysis/DemandedBits.cpp
index b538e16f25859..d7e2a3fa4fc59 100644
--- a/llvm/lib/Analysis/DemandedBits.cpp
+++ b/llvm/lib/Analysis/DemandedBits.cpp
@@ -70,11 +70,11 @@ void DemandedBits::determineLiveOperandBits(
const DataLayout &DL = UserI->getDataLayout();
Known = KnownBits(BitWidth);
- computeKnownBits(V1, Known, DL, 0, &AC, UserI, &DT);
+ computeKnownBits(V1, Known, DL, &AC, UserI, &DT);
if (V2) {
Known2 = KnownBits(BitWidth);
- computeKnownBits(V2, Known2, DL, 0, &AC, UserI, &DT);
+ computeKnownBits(V2, Known2, DL, &AC, UserI, &DT);
}
};
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index b7c7bcab168cc..d13f2e139ee4a 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -111,7 +111,7 @@ static std::pair<Type *, bool> computeRecurrenceType(Instruction *Exit,
// If demanded bits wasn't able to limit the bit width, we can try to use
// value tracking instead. This can be the case, for example, if the value
// may be negative.
- auto NumSignBits = ComputeNumSignBits(Exit, DL, 0, AC, nullptr, DT);
+ auto NumSignBits = ComputeNumSignBits(Exit, DL, AC, nullptr, DT);
auto NumTypeBits = DL.getTypeSizeInBits(Exit->getType());
MaxBitWidth = NumTypeBits - NumSignBits;
KnownBits Bits = computeKnownBits(Exit, DL);
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 12c84c718d4fd..e397a228afee0 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -770,7 +770,7 @@ static Value *simplifySubInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
if (IsNUW)
return Constant::getNullValue(Op0->getType());
- KnownBit...
[truncated]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are build failures in CI.
I think the original idea was that making Depth required avoids mistakes during recursive calls inside ValueTracking. But I agree that from the perspective of an external user, having to always specify Depth=0 doesn't make a lot of sense.
Not sure what's going on with the CI: I just re-verified locally, and the line it points to in ValueTracking.cpp seems to be outdated? I'll try a dummy force-push to re-kick the CI. EDIT: The buildkite Windows CI seems to have passed, and there's a Flang test failure in the buildkite Linux CI (which is spurious, I assume?). The GitHub CI is the one that seems to be broken. |
e75c2a2
to
f2d3329
Compare
Having a finite Depth (or recursion limit) for computeKnownBits is very limiting, but is currently a load-bearing necessity, as all KnownBits are recomputed on each call and there is no caching. As a prerequisite for an effort to remove the recursion limit altogether, either using a clever caching technique, or writing a easily-invalidable KnownBits analysis, make the Depth argument in APIs in ValueTracking uniformly the last argument with a default value. This would aid in removing the argument when the time comes, as many callers that currently pass 0 explicitly are now updated to omit the argument altogether.
f2d3329
to
6e002cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but please wait on a second opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This never made sense
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/162/builds/23770 Here is the relevant piece of the build log for the reference
|
Having a finite Depth (or recursion limit) for computeKnownBits is very limiting, but is currently a load-bearing necessity, as all KnownBits are recomputed on each call and there is no caching. As a prerequisite for an effort to remove the recursion limit altogether, either using a clever caching technique, or writing a easily-invalidable KnownBits analysis, make the Depth argument in APIs in ValueTracking uniformly the last argument with a default value. This would aid in removing the argument when the time comes, as many callers that currently pass 0 explicitly are now updated to omit the argument altogether.