Skip to content

[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

Merged
merged 1 commit into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 50 additions & 45 deletions llvm/include/llvm/Analysis/ValueTracking.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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);

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/Analysis/WithCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand All @@ -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);
}

Expand Down
44 changes: 24 additions & 20 deletions llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 *
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Analysis/BasicAliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/DemandedBits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/IVDescriptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading