From a19edc4d15b0dae0210b90615775edd76f021008 Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Wed, 8 Jun 2016 17:48:31 +0000 Subject: Fix a bug in SCEV's poison value propagation The worklist algorithm introduced in rL271151 didn't check to see if the direct users of the post-inc add recurrence propagates poison. This change fixes the problem and makes the code structure more obvious. Note for release managers: correctness wise, this bug wasn't a regression introduced by rL271151 -- the behavior of SCEV around post-inc add recurrences was strictly improved (in terms of correctness) in rL271151. llvm-svn: 272179 --- llvm/lib/Analysis/ScalarEvolution.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp') diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index d76b0f3..111b9b6 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -4880,22 +4880,23 @@ bool ScalarEvolution::isAddRecNeverPoison(const Instruction *I, const Loop *L) { return false; SmallPtrSet Pushed; - SmallVector Stack; + SmallVector PoisonStack; + // We start by assuming \c I, the post-inc add recurrence, is poison. Only + // things that are known to be fully poison under that assumption go on the + // PoisonStack. Pushed.insert(I); - for (auto *U : I->users()) - if (Pushed.insert(cast(U)).second) - Stack.push_back(cast(U)); + PoisonStack.push_back(I); bool LatchControlDependentOnPoison = false; - while (!Stack.empty()) { - const Instruction *I = Stack.pop_back_val(); - - for (auto *U : I->users()) { - if (propagatesFullPoison(cast(U))) { - if (Pushed.insert(cast(U)).second) - Stack.push_back(cast(U)); - } else if (auto *BI = dyn_cast(U)) { + while (!PoisonStack.empty()) { + const Instruction *Poison = PoisonStack.pop_back_val(); + + for (auto *PoisonUser : Poison->users()) { + if (propagatesFullPoison(cast(PoisonUser))) { + if (Pushed.insert(cast(PoisonUser)).second) + PoisonStack.push_back(cast(PoisonUser)); + } else if (auto *BI = dyn_cast(PoisonUser)) { assert(BI->isConditional() && "Only possibility!"); if (BI->getParent() == LatchBB) { LatchControlDependentOnPoison = true; -- cgit v1.1