Add a check if the initial value of the induction variable is 0 (the method comment...
authorWojciech Matyjewicz <wmatyjewicz@fastmail.fm>
Sat, 9 Feb 2008 18:06:58 +0000 (18:06 +0000)
committerWojciech Matyjewicz <wmatyjewicz@fastmail.fm>
Sat, 9 Feb 2008 18:06:58 +0000 (18:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46907 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/LoopInfo.h

index 93c36e47d8b8f31971665d0addaac81e00a6eabb..4cb03fbd8e71c6dfb7d461243c85b635e3cda908 100644 (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;
   }