Fix PR284: [indvars] Induction variable analysis violates LLVM invariants
authorChris Lattner <sabre@nondot.org>
Wed, 10 Mar 2004 21:42:19 +0000 (21:42 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 10 Mar 2004 21:42:19 +0000 (21:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12275 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/InductionVariable.cpp

index b602529494809f3fb0034203496f7cbdef89df83..8f622973f96bcd54678da4e410a51b049bd8b43e 100644 (file)
@@ -136,10 +136,14 @@ InductionVariable::InductionVariable(PHINode *P, LoopInfo *LoopInfo): End(0) {
         if (Constant *CV = dyn_cast<Constant>(V))
           Step = ConstantExpr::get(Instruction::Sub, Zero, CV);
         else if (Instruction *I = dyn_cast<Instruction>(V)) {
+          BasicBlock::iterator InsertPt = I;
+          for (++InsertPt; isa<PHINode>(InsertPt); ++InsertPt)
+            /*empty*/;
           Step = BinaryOperator::create(Instruction::Sub, Zero, V,
-                                        V->getName()+".neg", I->getNext());
+                                        V->getName()+".neg", InsertPt);
 
         } else {
+          // Must be loop invariant
           Step = BinaryOperator::create(Instruction::Sub, Zero, V,
                                         V->getName()+".neg", 
                               Phi->getParent()->getParent()->begin()->begin());