[llvm-commits] [llvm] r72149 - in /llvm/trunk: lib/Transforms/Scalar/LoopStrengthReduce.cpp test/Transforms/LoopStrengthReduce/dont_reverse.ll

Dan Gohman gohman at apple.com
Tue May 19 17:34:08 PDT 2009


Author: djg
Date: Tue May 19 19:34:08 2009
New Revision: 72149

URL: http://llvm.org/viewvc/llvm-project?rev=72149&view=rev
Log:
Suppress the IV reversal transformation in the case that the RHS
of the comparison is defined inside the loop. This fixes a
use-before-def problem, because the transformation puts a use
of the RHS outside the loop.

Added:
    llvm/trunk/test/Transforms/LoopStrengthReduce/dont_reverse.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp

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

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Tue May 19 19:34:08 2009
@@ -2456,6 +2456,11 @@
   SCEVHandle One = SE->getIntegerSCEV(1, BackedgeTakenCount->getType());
   if (!AR || !AR->isAffine() || AR->getStepRecurrence(*SE) != One)
     return;
+  // If the RHS of the comparison is defined inside the loop, the rewrite
+  // cannot be done.
+  if (Instruction *CR = dyn_cast<Instruction>(Cond->getOperand(1)))
+    if (L->contains(CR->getParent()))
+      return;
 
   // Make sure the IV is only used for counting.  Value may be preinc or
   // postinc; 2 uses in either case.

Added: llvm/trunk/test/Transforms/LoopStrengthReduce/dont_reverse.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopStrengthReduce/dont_reverse.ll?rev=72149&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/LoopStrengthReduce/dont_reverse.ll (added)
+++ llvm/trunk/test/Transforms/LoopStrengthReduce/dont_reverse.ll Tue May 19 19:34:08 2009
@@ -0,0 +1,21 @@
+; RUN: llvm-as < %s | opt -loop-reduce | llvm-dis \
+; RUN:    | grep {icmp eq i2 %lsr.iv.next, %xmp4344}
+
+; Don't reverse the iteration if the rhs of the compare is defined
+; inside the loop.
+
+define void @Fill_Buffer() nounwind {
+entry:
+	br label %bb8
+
+bb8:
+	%indvar34 = phi i32 [ 0, %entry ], [ %indvar.next35, %bb8 ]
+	%indvar3451 = trunc i32 %indvar34 to i2
+	%xmp4344 = xor i2 0, -1
+	%xmp104 = icmp eq i2 %indvar3451, %xmp4344
+	%indvar.next35 = add i32 %indvar34, 1
+	br i1 %xmp104, label %bb10, label %bb8
+
+bb10:
+	unreachable
+}





More information about the llvm-commits mailing list