Fix PR312 and IndVarsSimplify/2004-04-05-InvokeCastCrash.llx


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12668 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index e75229c..8e6ee53 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -2478,6 +2478,8 @@
   else if (Instruction *I = dyn_cast<Instruction>(V)) {
     // FIXME: check to see if there is already a cast!
     BasicBlock::iterator IP = I; ++IP;
+    if (InvokeInst *II = dyn_cast<InvokeInst>(I))
+      IP = II->getNormalDest()->begin();
     while (isa<PHINode>(IP)) ++IP;
     return new CastInst(V, Ty, V->getName(), IP);
   } else {