Bail out early, before modifying anything.
authorDevang Patel <dpatel@apple.com>
Wed, 19 Sep 2007 00:11:01 +0000 (00:11 +0000)
committerDevang Patel <dpatel@apple.com>
Wed, 19 Sep 2007 00:11:01 +0000 (00:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42120 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopIndexSplit.cpp

index c2e9d500a93d8d030b638fa63bd7052e0e371593..92a6058b5a64b569b53372dea9de749a84f0e34c 100644 (file)
@@ -542,6 +542,11 @@ bool LoopIndexSplit::processOneIterationLoop(SplitInfo &SD) {
   if (!safeSplitCondition(SD))
     return false;
 
+  BasicBlock *Latch = L->getLoopLatch();
+  BranchInst *BR = dyn_cast<BranchInst>(Latch->getTerminator());
+  if (!BR)
+    return false;
+
   // Update CFG.
 
   // Replace index variable with split value in loop body. Loop body is executed
@@ -549,11 +554,7 @@ bool LoopIndexSplit::processOneIterationLoop(SplitInfo &SD) {
   IndVar->replaceAllUsesWith(SD.SplitValue);
 
   // Remove Latch to Header edge.
-  BasicBlock *Latch = L->getLoopLatch();
   BasicBlock *LatchSucc = NULL;
-  BranchInst *BR = dyn_cast<BranchInst>(Latch->getTerminator());
-  if (!BR)
-    return false;
   Header->removePredecessor(Latch);
   for (succ_iterator SI = succ_begin(Latch), E = succ_end(Latch);
        SI != E; ++SI) {