Fix PR3913, patch by Jakub Staszak!
authorChris Lattner <sabre@nondot.org>
Fri, 28 Aug 2009 00:43:14 +0000 (00:43 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 28 Aug 2009 00:43:14 +0000 (00:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80327 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopIndexSplit.cpp
test/Transforms/LoopIndexSplit/PR3913.ll [new file with mode: 0644]

index 792b7537e522c892b45b1b46c2e3c4c6c845b2f4..259427e99bc3dcb477c204ae522f0d47aa2e44d1 100644 (file)
@@ -435,7 +435,7 @@ bool LoopIndexSplit::processOneIterationLoop() {
 
   CmpInst::Predicate C2P  = ExitCondition->getPredicate();
   BranchInst *LatchBR = cast<BranchInst>(Latch->getTerminator());
-  if (LatchBR->getOperand(0) != Header)
+  if (LatchBR->getOperand(1) != Header)
     C2P = CmpInst::getInversePredicate(C2P);
   Instruction *C2 = new ICmpInst(BR, C2P, SplitValue, ExitValue, "lisplit");
   Instruction *NSplitCond = BinaryOperator::CreateAnd(C1, C2, "lisplit", BR);
diff --git a/test/Transforms/LoopIndexSplit/PR3913.ll b/test/Transforms/LoopIndexSplit/PR3913.ll
new file mode 100644 (file)
index 0000000..c4fc0d1
--- /dev/null
@@ -0,0 +1,24 @@
+; RUN: llvm-as < %s | opt -loop-index-split | llvm-dis | not grep "icmp ne"
+
+define i32 @main() {
+entry:
+       br label %header
+
+header:
+       %r = phi i32 [ 0, %entry ], [ %r3, %skip ]
+       %i = phi i32 [ 0, %entry ], [ %i1, %skip ]
+       %cond = icmp eq i32 %i, 99
+       br i1 %cond, label %body, label %skip
+
+body:
+       br label %skip
+
+skip:
+       %r3 = phi i32 [ %r, %header ], [ 3, %body ]
+       %i1 = add i32 %i, 1
+       %exitcond = icmp eq i32 %i1, 10
+       br i1 %exitcond, label %exit, label %header
+
+exit:
+       ret i32 %r3
+}