From 61f57617d771104a2929e35f5e3885a9b6f2bddd Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 10 Mar 2004 21:42:19 +0000 Subject: [PATCH] Fix PR284: [indvars] Induction variable analysis violates LLVM invariants llvm-svn: 12275 --- llvm/lib/Analysis/InductionVariable.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Analysis/InductionVariable.cpp b/llvm/lib/Analysis/InductionVariable.cpp index b60252949480..8f622973f96b 100644 --- a/llvm/lib/Analysis/InductionVariable.cpp +++ b/llvm/lib/Analysis/InductionVariable.cpp @@ -136,10 +136,14 @@ InductionVariable::InductionVariable(PHINode *P, LoopInfo *LoopInfo): End(0) { if (Constant *CV = dyn_cast(V)) Step = ConstantExpr::get(Instruction::Sub, Zero, CV); else if (Instruction *I = dyn_cast(V)) { + BasicBlock::iterator InsertPt = I; + for (++InsertPt; isa(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());