[llvm-commits] [llvm] r150642 - in /llvm/trunk: lib/Transforms/Scalar/LoopRotation.cpp test/Transforms/LoopRotate/alloca.ll

Eli Friedman eli.friedman at gmail.com
Wed Feb 15 16:41:11 PST 2012


Author: efriedma
Date: Wed Feb 15 18:41:10 2012
New Revision: 150642

URL: http://llvm.org/viewvc/llvm-project?rev=150642&view=rev
Log:
loop-rotate shouldn't hoist alloca instructions out of a loop.  Patch by Patrik Hägglund, with slightly modified test.  Issue reported by Patrik Hägglund on llvmdev.


Added:
    llvm/trunk/test/Transforms/LoopRotate/alloca.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp?rev=150642&r1=150641&r2=150642&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp Wed Feb 15 18:41:10 2012
@@ -339,7 +339,8 @@
     // memory (without proving that the loop doesn't write).
     if (L->hasLoopInvariantOperands(Inst) &&
         !Inst->mayReadFromMemory() && !Inst->mayWriteToMemory() &&
-        !isa<TerminatorInst>(Inst) && !isa<DbgInfoIntrinsic>(Inst)) {
+        !isa<TerminatorInst>(Inst) && !isa<DbgInfoIntrinsic>(Inst) &&
+        !isa<AllocaInst>(Inst)) {
       Inst->moveBefore(LoopEntryBranch);
       continue;
     }

Added: llvm/trunk/test/Transforms/LoopRotate/alloca.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopRotate/alloca.ll?rev=150642&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/LoopRotate/alloca.ll (added)
+++ llvm/trunk/test/Transforms/LoopRotate/alloca.ll Wed Feb 15 18:41:10 2012
@@ -0,0 +1,33 @@
+; RUN: opt < %s -loop-rotate -S | FileCheck %s
+
+; Test alloca in -loop-rotate.
+
+; We expect a different value for %ptr each iteration (according to the
+; definition of alloca). I.e. each @use must be paired with an alloca.
+
+; CHECK: call void @use(i8* %
+; CHECK: %ptr = alloca i8
+
+ at e = global i16 10
+
+declare void @use(i8*)
+
+define void @test() {
+entry:
+  %end = load i16* @e
+  br label %loop
+
+loop:
+  %n.phi = phi i16 [ %n, %loop.fin ], [ 0, %entry ]
+  %ptr = alloca i8
+  %cond = icmp eq i16 %n.phi, %end
+  br i1 %cond, label %exit, label %loop.fin
+
+loop.fin:
+  %n = add i16 %n.phi, 1
+  call void @use(i8* %ptr)
+  br label %loop
+
+exit:
+  ret void
+}





More information about the llvm-commits mailing list