diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -1392,11 +1392,11 @@ } NumReplaced++; - Instruction *Inst = cast(PN->getIncomingValue(Phi.Ith)); PN->setIncomingValue(Phi.Ith, ExitVal); // If this instruction is dead now, delete it. Don't do it now to avoid // invalidating iterators. + Instruction *Inst = Phi.ExpansionPoint; if (isInstructionTriviallyDead(Inst, TLI)) DeadInsts.push_back(Inst);