Bail out early, before modifying anything.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42120 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp
index c2e9d50..92a6058 100644
--- a/lib/Transforms/Scalar/LoopIndexSplit.cpp
+++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp
@@ -542,6 +542,11 @@
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 @@
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) {