@@ -90,6 +90,8 @@ using namespace llvm::PatternMatch;
9090static cl::opt<unsigned > DomConditionsMaxUses (" dom-conditions-max-uses" ,
9191 cl::Hidden, cl::init(20 ));
9292
93+ static cl::opt<bool > ExhaustiveRecursion (" exhaustive-analysis-recursion" ,
94+ cl::Hidden);
9395
9496// / Returns the bitwidth of the given scalar or pointer type. For vector types,
9597// / returns the element type's bitwidth.
@@ -131,6 +133,12 @@ static bool getShuffleDemandedElts(const ShuffleVectorInst *Shuf,
131133 DemandedElts, DemandedLHS, DemandedRHS);
132134}
133135
136+ unsigned llvm::getAnalysisRecursionDepthLimit () {
137+ if (!ExhaustiveRecursion.getNumOccurrences () || !ExhaustiveRecursion)
138+ return MaxAnalysisRecursionDepth;
139+ return -1 ;
140+ }
141+
134142static void computeKnownBits (const Value *V, const APInt &DemandedElts,
135143 KnownBits &Known, const SimplifyQuery &Q,
136144 unsigned Depth);
@@ -798,7 +806,7 @@ static void computeKnownBitsFromCond(const Value *V, Value *Cond,
798806 KnownBits &Known, const SimplifyQuery &SQ,
799807 bool Invert, unsigned Depth) {
800808 Value *A, *B;
801- if (Depth < MaxAnalysisRecursionDepth &&
809+ if (Depth < getAnalysisRecursionDepthLimit () &&
802810 match (Cond, m_LogicalOp (m_Value (A), m_Value (B)))) {
803811 KnownBits Known2 (Known.getBitWidth ());
804812 KnownBits Known3 (Known.getBitWidth ());
@@ -833,7 +841,8 @@ static void computeKnownBitsFromCond(const Value *V, Value *Cond,
833841 return ;
834842 }
835843
836- if (Depth < MaxAnalysisRecursionDepth && match (Cond, m_Not (m_Value (A))))
844+ if (Depth < getAnalysisRecursionDepthLimit () &&
845+ match (Cond, m_Not (m_Value (A))))
837846 computeKnownBitsFromCond (V, A, Known, SQ, !Invert, Depth + 1 );
838847}
839848
@@ -927,7 +936,7 @@ void llvm::computeKnownBitsFromContext(const Value *V, KnownBits &Known,
927936 }
928937
929938 // The remaining tests are all recursive, so bail out if we hit the limit.
930- if (Depth == MaxAnalysisRecursionDepth )
939+ if (Depth == getAnalysisRecursionDepthLimit () )
931940 continue ;
932941
933942 ICmpInst *Cmp = dyn_cast<ICmpInst>(Arg);
@@ -1696,7 +1705,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
16961705
16971706 // Otherwise take the unions of the known bit sets of the operands,
16981707 // taking conservative care to avoid excessive recursion.
1699- if (Depth < MaxAnalysisRecursionDepth - 1 && Known.isUnknown ()) {
1708+ if (Depth < getAnalysisRecursionDepthLimit () - 1 && Known.isUnknown ()) {
17001709 // Skip if every incoming value references to ourself.
17011710 if (isa_and_nonnull<UndefValue>(P->hasConstantValue ()))
17021711 break ;
@@ -1725,7 +1734,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
17251734 // TODO: See if we can base recursion limiter on number of incoming phi
17261735 // edges so we don't overly clamp analysis.
17271736 computeKnownBits (IncValue, DemandedElts, Known2, RecQ,
1728- MaxAnalysisRecursionDepth - 1 );
1737+ getAnalysisRecursionDepthLimit () - 1 );
17291738
17301739 // See if we can further use a conditional branch into the phi
17311740 // to help us determine the range of the value.
@@ -2194,7 +2203,7 @@ void computeKnownBits(const Value *V, const APInt &DemandedElts,
21942203 }
21952204
21962205 assert (V && " No Value?" );
2197- assert (Depth <= MaxAnalysisRecursionDepth && " Limit Search Depth" );
2206+ assert (Depth <= getAnalysisRecursionDepthLimit () && " Limit Search Depth" );
21982207
21992208#ifndef NDEBUG
22002209 Type *Ty = V->getType ();
@@ -2293,7 +2302,7 @@ void computeKnownBits(const Value *V, const APInt &DemandedElts,
22932302 Known = Range->toKnownBits ();
22942303
22952304 // All recursive calls that increase depth must come after this.
2296- if (Depth == MaxAnalysisRecursionDepth )
2305+ if (Depth == getAnalysisRecursionDepthLimit () )
22972306 return ;
22982307
22992308 // A weak GlobalAlias is totally unknown. A non-weak GlobalAlias has
@@ -2406,7 +2415,7 @@ static bool isImpliedToBeAPowerOfTwoFromCond(const Value *V, bool OrZero,
24062415// / types and vectors of integers.
24072416bool llvm::isKnownToBeAPowerOfTwo (const Value *V, bool OrZero,
24082417 const SimplifyQuery &Q, unsigned Depth) {
2409- assert (Depth <= MaxAnalysisRecursionDepth && " Limit Search Depth" );
2418+ assert (Depth <= getAnalysisRecursionDepthLimit () && " Limit Search Depth" );
24102419
24112420 if (isa<Constant>(V))
24122421 return OrZero ? match (V, m_Power2OrZero ()) : match (V, m_Power2 ());
@@ -2468,7 +2477,7 @@ bool llvm::isKnownToBeAPowerOfTwo(const Value *V, bool OrZero,
24682477 return true ;
24692478
24702479 // The remaining tests are all recursive, so bail out if we hit the limit.
2471- if (Depth++ == MaxAnalysisRecursionDepth )
2480+ if (Depth++ == getAnalysisRecursionDepthLimit () )
24722481 return false ;
24732482
24742483 switch (I->getOpcode ()) {
@@ -2556,7 +2565,7 @@ bool llvm::isKnownToBeAPowerOfTwo(const Value *V, bool OrZero,
25562565
25572566 // Recursively check all incoming values. Limit recursion to 2 levels, so
25582567 // that search complexity is limited to number of operands^2.
2559- unsigned NewDepth = std::max (Depth, MaxAnalysisRecursionDepth - 1 );
2568+ unsigned NewDepth = std::max (Depth, getAnalysisRecursionDepthLimit () - 1 );
25602569 return llvm::all_of (PN->operands (), [&](const Use &U) {
25612570 // Value is power of 2 if it is coming from PHI node itself by induction.
25622571 if (U.get () == PN)
@@ -2660,7 +2669,7 @@ static bool isGEPKnownNonNull(const GEPOperator *GEP, const SimplifyQuery &Q,
26602669 // to recurse 10k times just because we have 10k GEP operands. We don't
26612670 // bail completely out because we want to handle constant GEPs regardless
26622671 // of depth.
2663- if (Depth++ >= MaxAnalysisRecursionDepth )
2672+ if (Depth++ >= getAnalysisRecursionDepthLimit () )
26642673 continue ;
26652674
26662675 if (isKnownNonZero (GTI.getOperand (), Q, Depth))
@@ -3164,7 +3173,7 @@ static bool isKnownNonZeroFromOperator(const Operator *I,
31643173
31653174 // Check if all incoming values are non-zero using recursion.
31663175 SimplifyQuery RecQ = Q.getWithoutCondContext ();
3167- unsigned NewDepth = std::max (Depth, MaxAnalysisRecursionDepth - 1 );
3176+ unsigned NewDepth = std::max (Depth, getAnalysisRecursionDepthLimit () - 1 );
31683177 return llvm::all_of (PN->operands (), [&](const Use &U) {
31693178 if (U.get () == PN)
31703179 return true ;
@@ -3430,7 +3439,7 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts,
34303439 Type *Ty = V->getType ();
34313440
34323441#ifndef NDEBUG
3433- assert (Depth <= MaxAnalysisRecursionDepth && " Limit Search Depth" );
3442+ assert (Depth <= getAnalysisRecursionDepthLimit () && " Limit Search Depth" );
34343443
34353444 if (auto *FVTy = dyn_cast<FixedVectorType>(Ty)) {
34363445 assert (
@@ -3493,7 +3502,7 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts,
34933502 return true ;
34943503
34953504 // Some of the tests below are recursive, so bail out if we hit the limit.
3496- if (Depth++ >= MaxAnalysisRecursionDepth )
3505+ if (Depth++ >= getAnalysisRecursionDepthLimit () )
34973506 return false ;
34983507
34993508 // Check for pointer simplifications.
@@ -3877,7 +3886,7 @@ static bool isKnownNonEqual(const Value *V1, const Value *V2,
38773886 // We can't look through casts yet.
38783887 return false ;
38793888
3880- if (Depth >= MaxAnalysisRecursionDepth )
3889+ if (Depth >= getAnalysisRecursionDepthLimit () )
38813890 return false ;
38823891
38833892 // See if we can recurse through (exactly one of) our operands. This
@@ -3994,7 +4003,7 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
39944003 const SimplifyQuery &Q, unsigned Depth) {
39954004 Type *Ty = V->getType ();
39964005#ifndef NDEBUG
3997- assert (Depth <= MaxAnalysisRecursionDepth && " Limit Search Depth" );
4006+ assert (Depth <= getAnalysisRecursionDepthLimit () && " Limit Search Depth" );
39984007
39994008 if (auto *FVTy = dyn_cast<FixedVectorType>(Ty)) {
40004009 assert (
@@ -4021,7 +4030,7 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
40214030 // Note that ConstantInt is handled by the general computeKnownBits case
40224031 // below.
40234032
4024- if (Depth == MaxAnalysisRecursionDepth )
4033+ if (Depth == getAnalysisRecursionDepthLimit () )
40254034 return 1 ;
40264035
40274036 if (auto *U = dyn_cast<Operator>(V)) {
@@ -4555,7 +4564,7 @@ static void computeKnownFPClassFromCond(const Value *V, Value *Cond,
45554564 KnownFPClass &KnownFromContext,
45564565 unsigned Depth = 0 ) {
45574566 Value *A, *B;
4558- if (Depth < MaxAnalysisRecursionDepth &&
4567+ if (Depth < getAnalysisRecursionDepthLimit () &&
45594568 (CondIsTrue ? match (Cond, m_LogicalAnd (m_Value (A), m_Value (B)))
45604569 : match (Cond, m_LogicalOr (m_Value (A), m_Value (B))))) {
45614570 computeKnownFPClassFromCond (V, A, CondIsTrue, CxtI, KnownFromContext,
@@ -4564,7 +4573,7 @@ static void computeKnownFPClassFromCond(const Value *V, Value *Cond,
45644573 Depth + 1 );
45654574 return ;
45664575 }
4567- if (Depth < MaxAnalysisRecursionDepth && match (Cond, m_Not (m_Value (A)))) {
4576+ if (Depth < getAnalysisRecursionDepthLimit () && match (Cond, m_Not (m_Value (A)))) {
45684577 computeKnownFPClassFromCond (V, A, !CondIsTrue, CxtI, KnownFromContext,
45694578 Depth + 1 );
45704579 return ;
@@ -4696,7 +4705,7 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
46964705 return ;
46974706 }
46984707
4699- assert (Depth <= MaxAnalysisRecursionDepth && " Limit Search Depth" );
4708+ assert (Depth <= getAnalysisRecursionDepthLimit () && " Limit Search Depth" );
47004709
47014710 if (auto *CFP = dyn_cast<ConstantFP>(V)) {
47024711 Known.KnownFPClasses = CFP->getValueAPF ().classify ();
@@ -4790,7 +4799,7 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
47904799 return ;
47914800
47924801 // All recursive calls that increase depth must come after this.
4793- if (Depth == MaxAnalysisRecursionDepth )
4802+ if (Depth == getAnalysisRecursionDepthLimit () )
47944803 return ;
47954804
47964805 const unsigned Opc = Op->getOpcode ();
@@ -5744,7 +5753,7 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
57445753
57455754 // Otherwise take the unions of the known bit sets of the operands,
57465755 // taking conservative care to avoid excessive recursion.
5747- const unsigned PhiRecursionLimit = MaxAnalysisRecursionDepth - 2 ;
5756+ const unsigned PhiRecursionLimit = getAnalysisRecursionDepthLimit () - 2 ;
57485757
57495758 if (Depth < PhiRecursionLimit) {
57505759 // Skip if every incoming value references to ourself.
@@ -7559,7 +7568,7 @@ static bool programUndefinedIfUndefOrPoison(const Value *V, bool PoisonOnly);
75597568static bool isGuaranteedNotToBeUndefOrPoison (
75607569 const Value *V, AssumptionCache *AC, const Instruction *CtxI,
75617570 const DominatorTree *DT, unsigned Depth, UndefPoisonKind Kind) {
7562- if (Depth >= MaxAnalysisRecursionDepth )
7571+ if (Depth >= getAnalysisRecursionDepthLimit () )
75637572 return false ;
75647573
75657574 if (isa<MetadataAsValue>(V))
@@ -8895,7 +8904,7 @@ static Value *lookThroughCast(CmpInst *CmpI, Value *V1, Value *V2,
88958904SelectPatternResult llvm::matchSelectPattern (Value *V, Value *&LHS, Value *&RHS,
88968905 Instruction::CastOps *CastOp,
88978906 unsigned Depth) {
8898- if (Depth >= MaxAnalysisRecursionDepth )
8907+ if (Depth >= getAnalysisRecursionDepthLimit () )
88998908 return {SPF_UNKNOWN, SPNB_NA, false };
89008909
89018910 SelectInst *SI = dyn_cast<SelectInst>(V);
@@ -9314,10 +9323,10 @@ isImpliedCondICmps(CmpPredicate LPred, const Value *L0, const Value *L1,
93149323 // C1` (see discussion: D58633).
93159324 ConstantRange LCR = computeConstantRange (
93169325 L1, ICmpInst::isSigned (LPred), /* UseInstrInfo=*/ true , /* AC=*/ nullptr ,
9317- /* CxtI=*/ nullptr , /* DT=*/ nullptr , MaxAnalysisRecursionDepth - 1 );
9326+ /* CxtI=*/ nullptr , /* DT=*/ nullptr , getAnalysisRecursionDepthLimit () - 1 );
93189327 ConstantRange RCR = computeConstantRange (
93199328 R1, ICmpInst::isSigned (RPred), /* UseInstrInfo=*/ true , /* AC=*/ nullptr ,
9320- /* CxtI=*/ nullptr , /* DT=*/ nullptr , MaxAnalysisRecursionDepth - 1 );
9329+ /* CxtI=*/ nullptr , /* DT=*/ nullptr , getAnalysisRecursionDepthLimit () - 1 );
93219330 // Even if L1/R1 are not both constant, we can still sometimes deduce
93229331 // relationship from a single constant. For example X u> Y implies X != 0.
93239332 if (auto R = isImpliedCondCommonOperandWithCR (LPred, LCR, RPred, RCR))
@@ -9382,7 +9391,7 @@ isImpliedCondAndOr(const Instruction *LHS, CmpPredicate RHSPred,
93829391 LHS->getOpcode () == Instruction::Select) &&
93839392 " Expected LHS to be 'and', 'or', or 'select'." );
93849393
9385- assert (Depth <= MaxAnalysisRecursionDepth && " Hit recursion limit" );
9394+ assert (Depth <= getAnalysisRecursionDepthLimit () && " Hit recursion limit" );
93869395
93879396 // If the result of an 'or' is false, then we know both legs of the 'or' are
93889397 // false. Similarly, if the result of an 'and' is true, then we know both
@@ -9407,7 +9416,7 @@ llvm::isImpliedCondition(const Value *LHS, CmpPredicate RHSPred,
94079416 const Value *RHSOp0, const Value *RHSOp1,
94089417 const DataLayout &DL, bool LHSIsTrue, unsigned Depth) {
94099418 // Bail out when we hit the limit.
9410- if (Depth == MaxAnalysisRecursionDepth )
9419+ if (Depth == getAnalysisRecursionDepthLimit () )
94119420 return std::nullopt ;
94129421
94139422 // A mismatch occurs when we compare a scalar cmp to a vector cmp, for
@@ -9478,7 +9487,7 @@ std::optional<bool> llvm::isImpliedCondition(const Value *LHS, const Value *RHS,
94789487 return std::nullopt ;
94799488 }
94809489
9481- if (Depth == MaxAnalysisRecursionDepth )
9490+ if (Depth == getAnalysisRecursionDepthLimit () )
94829491 return std::nullopt ;
94839492
94849493 // LHS ==> (RHS1 || RHS2) if LHS ==> RHS1 or LHS ==> RHS2
@@ -9940,7 +9949,7 @@ ConstantRange llvm::computeConstantRange(const Value *V, bool ForSigned,
99409949 unsigned Depth) {
99419950 assert (V->getType ()->isIntOrIntVectorTy () && " Expected integer instruction" );
99429951
9943- if (Depth == MaxAnalysisRecursionDepth )
9952+ if (Depth == getAnalysisRecursionDepthLimit () )
99449953 return ConstantRange::getFull (V->getType ()->getScalarSizeInBits ());
99459954
99469955 if (auto *C = dyn_cast<Constant>(V))
0 commit comments