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 @@ -5722,11 +5722,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) { @@ -5740,9 +5735,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 Value *Op : I.operands()) { + if (YieldsPoison.count(Op)) { + YieldsPoison.insert(&I); + break; + } + } + } } BB = BB->getSingleSuccessor();