aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Transforms/Scalar/IndVarSimplify.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp
index 369be47..ed5aca3 100644
--- a/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -140,6 +140,8 @@ static bool TransformLoop(LoopInfo *Loops, Loop *Loop) {
DEBUG(IV->print(std::cerr));
+ while (isa<PHINode>(AfterPHIIt)) ++AfterPHIIt;
+
// Don't do math with pointers...
const Type *IVTy = IV->Phi->getType();
if (isa<PointerType>(IVTy)) IVTy = Type::ULongTy;
@@ -204,6 +206,9 @@ static bool TransformLoop(LoopInfo *Loops, Loop *Loop) {
PHIOps.insert(PHIOps.end(), MaybeDead->op_begin(),
MaybeDead->op_end());
MaybeDead->getParent()->getInstList().erase(MaybeDead);
+
+ // Erasing the instruction could invalidate the AfterPHI iterator!
+ AfterPHIIt = Header->begin();
}
}