diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index ed5aca372ab..763854ee0b1 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -26,6 +26,7 @@ #include "Support/Debug.h" #include "Support/Statistic.h" #include "Support/STLExtras.h" +#include using namespace llvm; namespace { @@ -206,6 +207,14 @@ static bool TransformLoop(LoopInfo *Loops, Loop *Loop) { PHIOps.insert(PHIOps.end(), MaybeDead->op_begin(), MaybeDead->op_end()); MaybeDead->getParent()->getInstList().erase(MaybeDead); + + // Erase any duplicates entries in the PHIOps list. + std::vector::iterator It = + std::find(PHIOps.begin(), PHIOps.end(), MaybeDead); + while (It != PHIOps.end()) { + PHIOps.erase(It); + It = std::find(PHIOps.begin(), PHIOps.end(), MaybeDead); + } // Erasing the instruction could invalidate the AfterPHI iterator! AfterPHIIt = Header->begin();