[llvm-commits] [llvm] r53265 - in /llvm/trunk: lib/Transforms/Scalar/LoopIndexSplit.cpp test/Transforms/LoopIndexSplit/2008-05-19-IndVar.ll test/Transforms/LoopIndexSplit/2008-07-08-MisCompilation.ll

Devang Patel dpatel at apple.com
Tue Jul 8 17:12:01 PDT 2008


Author: dpatel
Date: Tue Jul  8 19:12:01 2008
New Revision: 53265

URL: http://llvm.org/viewvc/llvm-project?rev=53265&view=rev
Log:
If loop induction variable's start value is less then its exit value then do not split the loop.

Added:
    llvm/trunk/test/Transforms/LoopIndexSplit/2008-07-08-MisCompilation.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp
    llvm/trunk/test/Transforms/LoopIndexSplit/2008-05-19-IndVar.ll

Modified: llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp?rev=53265&r1=53264&r2=53265&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp Tue Jul  8 19:12:01 2008
@@ -384,6 +384,19 @@
     BasicBlock *Preheader = L->getLoopPreheader();
     StartValue = IndVar->getIncomingValueForBlock(Preheader);
   }
+
+  // If start value is more then exit value where induction variable
+  // increments by 1 then we are potentially dealing with an infinite loop.
+  // Do not index split this loop.
+  if (ExitCondition) {
+    ConstantInt *SV = dyn_cast<ConstantInt>(StartValue);
+    ConstantInt *EV = 
+      dyn_cast<ConstantInt>(ExitCondition->getOperand(ExitValueNum));
+    if (SV && EV && SV->getSExtValue() > EV->getSExtValue())
+      ExitCondition = NULL;
+    else if (EV && EV->isZero())
+      ExitCondition = NULL;
+  }
 }
 
 /// Find condition inside a loop that is suitable candidate for index split.

Modified: llvm/trunk/test/Transforms/LoopIndexSplit/2008-05-19-IndVar.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopIndexSplit/2008-05-19-IndVar.ll?rev=53265&r1=53264&r2=53265&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/LoopIndexSplit/2008-05-19-IndVar.ll (original)
+++ llvm/trunk/test/Transforms/LoopIndexSplit/2008-05-19-IndVar.ll Tue Jul  8 19:12:01 2008
@@ -24,7 +24,7 @@
 	br label %bb6.i
 bb6.i:		; preds = %bb4.i, %bb.i
 	%tmp8.i = add i16 %g_2.tmp.0.i, 1		; <i16> [#uses=3]
-	%tmp11.i = icmp sgt i16 %tmp8.i, 0		; <i1> [#uses=1]
+	%tmp11.i = icmp sgt i16 %tmp8.i, 42		; <i1> [#uses=1]
 	br i1 %tmp11.i, label %bb.i, label %return.loopexit.i
 return.loopexit.i:		; preds = %bb6.i
 	%tmp8.i.lcssa = phi i16 [ %tmp8.i, %bb6.i ]		; <i16> [#uses=1]

Added: llvm/trunk/test/Transforms/LoopIndexSplit/2008-07-08-MisCompilation.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopIndexSplit/2008-07-08-MisCompilation.ll?rev=53265&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/LoopIndexSplit/2008-07-08-MisCompilation.ll (added)
+++ llvm/trunk/test/Transforms/LoopIndexSplit/2008-07-08-MisCompilation.ll Tue Jul  8 19:12:01 2008
@@ -0,0 +1,25 @@
+; RUN: llvm-as < %s | opt -loop-index-split -stats -disable-output | not grep "1 loop-index-split"
+; PR 2487
+ at g_6 = external global i32		; <i32*> [#uses=1]
+
+define void @func_1() nounwind  {
+entry:
+	br label %bb
+
+bb:		; preds = %bb4, %entry
+	%l_3.0 = phi i8 [ 0, %entry ], [ %tmp6, %bb4 ]		; <i8> [#uses=2]
+	%tmp1 = icmp eq i8 %l_3.0, 0		; <i1> [#uses=1]
+	br i1 %tmp1, label %bb3, label %bb4
+
+bb3:		; preds = %bb
+	store i32 1, i32* @g_6, align 4
+	br label %bb4
+
+bb4:		; preds = %bb3, %bb
+	%tmp6 = add i8 %l_3.0, 1		; <i8> [#uses=2]
+	%tmp9 = icmp sgt i8 %tmp6, -1		; <i1> [#uses=1]
+	br i1 %tmp9, label %bb, label %return
+
+return:		; preds = %bb4
+	ret void
+}





More information about the llvm-commits mailing list