Skip to content

Commit d7eae33

Browse files
committed
address comments
1 parent 2e21b63 commit d7eae33

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

llvm/include/llvm/Analysis/ValueTracking.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ constexpr unsigned MaxAnalysisRecursionDepth = 6;
5050
/// getUnderlyingObject().
5151
constexpr unsigned MaxLookupSearchDepth = 10;
5252

53+
/// The max limit of the search depth in canFoldFreezeIntoRecurrence().
54+
constexpr unsigned MaxRecurrenceSearchDepth = 32;
55+
5356
/// Determine which bits of V are known to be either zero or one and return
5457
/// them in the KnownZero/KnownOne bit sets.
5558
///
@@ -779,7 +782,7 @@ LLVM_ABI bool impliesPoison(const Value *ValAssumedPoison, const Value *V);
779782
/// phi again. In that case, we can move the freeze to the start value.
780783
LLVM_ABI Use *canFoldFreezeIntoRecurrence(
781784
PHINode *PN, DominatorTree *DT, bool &StartNeedsFreeze,
782-
SmallVectorImpl<Instruction *> *DropFlags = nullptr);
785+
SmallVectorImpl<Instruction *> *DropFlags = nullptr, unsigned Depth = 0);
783786

784787
/// Return true if this function can prove that V does not have undef bits
785788
/// and is never poison. If V is an aggregate value or vector, check whether

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7571,7 +7571,7 @@ static bool programUndefinedIfUndefOrPoison(const Value *V, bool PoisonOnly);
75717571

75727572
Use *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

Comments
 (0)