@@ -7571,7 +7571,7 @@ static bool programUndefinedIfUndefOrPoison(const Value *V, bool PoisonOnly);
75717571
75727572Use *llvm::canFoldFreezeIntoRecurrence (
75737573 PHINode *PN, DominatorTree *DT, bool &StartNeedsFreeze,
7574- SmallVectorImpl<Instruction *> *DropFlags) {
7574+ SmallVectorImpl<Instruction *> *DropFlags, unsigned Depth ) {
75757575 // Detect whether this is a recurrence with a start value and some number of
75767576 // backedge values. We'll check whether we can push the freeze through the
75777577 // backedge values (possibly dropping poison flags along the way) until we
@@ -7597,7 +7597,8 @@ Use *llvm::canFoldFreezeIntoRecurrence(
75977597
75987598 Value *StartV = StartU->get ();
75997599 BasicBlock *StartBB = PN->getIncomingBlock (*StartU);
7600- StartNeedsFreeze = !isGuaranteedNotToBeUndefOrPoison (StartV);
7600+ StartNeedsFreeze = !isGuaranteedNotToBeUndefOrPoison (
7601+ StartV, /* AC=*/ nullptr , /* CtxI=*/ nullptr , /* DT=*/ nullptr , Depth);
76017602 // We can't insert freeze if the start value is the result of the
76027603 // terminator (e.g. an invoke).
76037604 if (StartNeedsFreeze && StartBB->getTerminator () == StartV)
@@ -7609,11 +7610,13 @@ Use *llvm::canFoldFreezeIntoRecurrence(
76097610 if (!Visited.insert (V).second )
76107611 continue ;
76117612
7612- if (Visited.size () > 32 )
7613+ if (Visited.size () > MaxRecurrenceSearchDepth )
76137614 return nullptr ; // Limit the total number of values we inspect.
76147615
76157616 // Assume that PN is non-poison, because it will be after the transform.
7616- if (V == PN || isGuaranteedNotToBeUndefOrPoison (V))
7617+ if (V == PN ||
7618+ isGuaranteedNotToBeUndefOrPoison (V, /* AC=*/ nullptr , /* CtxI=*/ nullptr ,
7619+ /* DT=*/ nullptr , Depth))
76177620 continue ;
76187621
76197622 Instruction *I = dyn_cast<Instruction>(V);
@@ -7719,9 +7722,9 @@ static bool isGuaranteedNotToBeUndefOrPoison(
77197722 return true ;
77207723
77217724 bool StartNeedsFreeze;
7722- if (canFoldFreezeIntoRecurrence (const_cast <PHINode *>(PN),
7723- const_cast <DominatorTree *>(DT),
7724- StartNeedsFreeze ) &&
7725+ if (canFoldFreezeIntoRecurrence (
7726+ const_cast <PHINode *>(PN), const_cast <DominatorTree *>(DT),
7727+ StartNeedsFreeze, /* DropFlags= */ nullptr , Depth ) &&
77257728 !StartNeedsFreeze)
77267729 return true ;
77277730 } else if (!::canCreateUndefOrPoison (Opr, Kind,
0 commit comments