diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -5729,11 +5729,6 @@ SmallSet Visited; YieldsPoison.insert(V); - auto Propagate = [&](const User *User) { - if (propagatesPoison(cast(User))) - YieldsPoison.insert(User); - }; - for_each(V->users(), Propagate); Visited.insert(BB); while (true) { @@ -5747,9 +5742,16 @@ if (!isGuaranteedToTransferExecutionToSuccessor(&I)) return false; - // Mark poison that propagates from I through uses of I. - if (YieldsPoison.count(&I)) - for_each(I.users(), Propagate); + // If this instruction propagates poison, mark it as poison if any of + // its operands are poison + if (propagatesPoison(cast(&I))) { + for (const Use &U : I.operands()) { + if (YieldsPoison.count(U.get())) { + YieldsPoison.insert(&I); + break; + } + } + } } BB = BB->getSingleSuccessor();