Don't grab the condition of unconditional branches!
authorChris Lattner <sabre@nondot.org>
Tue, 8 Jun 2004 21:50:30 +0000 (21:50 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 8 Jun 2004 21:50:30 +0000 (21:50 +0000)
This fixes PR363

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14076 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/LoopInfo.cpp

index c4b2bf681461b4264a6bd2db8f6ae66f545ea444..8619984f3df726a245e4edde9b7640424804cf92 100644 (file)
@@ -442,14 +442,15 @@ Value *Loop::getTripCount() const {
     IV->getIncomingBlock(contains(IV->getIncomingBlock(1)));
 
   if (BranchInst *BI = dyn_cast<BranchInst>(BackedgeBlock->getTerminator()))
-    if (SetCondInst *SCI = dyn_cast<SetCondInst>(BI->getCondition()))
-      if (SCI->getOperand(0) == Inc)
-        if (BI->getSuccessor(0) == getHeader()) {
-          if (SCI->getOpcode() == Instruction::SetNE)
+    if (BI->isConditional())
+      if (SetCondInst *SCI = dyn_cast<SetCondInst>(BI->getCondition()))
+        if (SCI->getOperand(0) == Inc)
+          if (BI->getSuccessor(0) == getHeader()) {
+            if (SCI->getOpcode() == Instruction::SetNE)
+              return SCI->getOperand(1);
+          } else if (SCI->getOpcode() == Instruction::SetEQ) {
             return SCI->getOperand(1);
-        } else if (SCI->getOpcode() == Instruction::SetEQ) {
-          return SCI->getOperand(1);
-        }
+          }
   
   return 0;
 }