Add a check if the initial value of the induction variable is 0 (the method comment says it should be).

llvm-svn: 46907
This commit is contained in:
Wojciech Matyjewicz 2008-02-09 18:06:58 +00:00
parent 4cc387212a
commit 5c252865de
1 changed files with 10 additions and 6 deletions

View File

@ -360,12 +360,16 @@ public:
// Loop over all of the PHI nodes, looking for a canonical indvar.
for (typename BlockT::iterator I = H->begin(); isa<PHINode>(I); ++I) {
PHINode *PN = cast<PHINode>(I);
if (Instruction *Inc =
dyn_cast<Instruction>(PN->getIncomingValueForBlock(Backedge)))
if (Inc->getOpcode() == Instruction::Add && Inc->getOperand(0) == PN)
if (ConstantInt *CI = dyn_cast<ConstantInt>(Inc->getOperand(1)))
if (CI->equalsInt(1))
return PN;
if (ConstantInt *CI =
dyn_cast<ConstantInt>(PN->getIncomingValueForBlock(Incoming)))
if (CI->isNullValue())
if (Instruction *Inc =
dyn_cast<Instruction>(PN->getIncomingValueForBlock(Backedge)))
if (Inc->getOpcode() == Instruction::Add &&
Inc->getOperand(0) == PN)
if (ConstantInt *CI = dyn_cast<ConstantInt>(Inc->getOperand(1)))
if (CI->equalsInt(1))
return PN;
}
return 0;
}