[BasicAA][ValueTracking] Use MaxLookupSearchDepth constant (NFC)

Use MaxLookupSearchDepth in all places limiting an underlying
object walk, instead of hardcoding 6 in various places.
This commit is contained in:
Nikita Popov
2025-06-11 14:47:47 +02:00
parent b3db0c6a1d
commit 4e441665cc
2 changed files with 9 additions and 8 deletions

View File

@@ -45,6 +45,10 @@ template <typename T> class ArrayRef;
constexpr unsigned MaxAnalysisRecursionDepth = 6;
/// The max limit of the search depth in DecomposeGEPExpression() and
/// getUnderlyingObject().
constexpr unsigned MaxLookupSearchDepth = 6;
/// Determine which bits of V are known to be either zero or one and return
/// them in the KnownZero/KnownOne bit sets.
///
@@ -432,9 +436,10 @@ LLVM_ABI bool isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(
/// original object being addressed. Note that the returned value has pointer
/// type if the specified value does. If the \p MaxLookup value is non-zero, it
/// limits the number of instructions to be stripped off.
LLVM_ABI const Value *getUnderlyingObject(const Value *V,
unsigned MaxLookup = 6);
inline Value *getUnderlyingObject(Value *V, unsigned MaxLookup = 6) {
LLVM_ABI const Value *
getUnderlyingObject(const Value *V, unsigned MaxLookup = MaxLookupSearchDepth);
inline Value *getUnderlyingObject(Value *V,
unsigned MaxLookup = MaxLookupSearchDepth) {
// Force const to avoid infinite recursion.
const Value *VConst = V;
return const_cast<Value *>(getUnderlyingObject(VConst, MaxLookup));
@@ -475,7 +480,7 @@ LLVM_ABI const Value *getUnderlyingObjectAggressive(const Value *V);
LLVM_ABI void getUnderlyingObjects(const Value *V,
SmallVectorImpl<const Value *> &Objects,
const LoopInfo *LI = nullptr,
unsigned MaxLookup = 6);
unsigned MaxLookup = MaxLookupSearchDepth);
/// This is a wrapper around getUnderlyingObjects and adds support for basic
/// ptrtoint+arithmetic+inttoptr sequences.

View File

@@ -79,10 +79,6 @@ STATISTIC(SearchLimitReached, "Number of times the limit to "
"decompose GEPs is reached");
STATISTIC(SearchTimes, "Number of times a GEP is decomposed");
// The max limit of the search depth in DecomposeGEPExpression() and
// getUnderlyingObject().
static const unsigned MaxLookupSearchDepth = 6;
bool BasicAAResult::invalidate(Function &Fn, const PreservedAnalyses &PA,
FunctionAnalysisManager::Invalidator &Inv) {
// We don't care if this analysis itself is preserved, it has no state. But