[llvm-commits] [llvm] r75584 - in /llvm/trunk: lib/Transforms/Scalar/LoopUnswitch.cpp lib/Transforms/Utils/LoopSimplify.cpp test/Transforms/IndVarSimplify/loop_evaluate9.ll

Dan Gohman gohman at apple.com
Mon Jul 13 18:37:59 PDT 2009


Author: djg
Date: Mon Jul 13 20:37:59 2009
New Revision: 75584

URL: http://llvm.org/viewvc/llvm-project?rev=75584&view=rev
Log:
Update LoopSimplify and LoopUnswitch to use the new makeLoopInvariant
function.

Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp
    llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp
    llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate9.ll

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

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp Mon Jul 13 20:37:59 2009
@@ -168,9 +168,14 @@
   if (isa<Constant>(Cond)) return 0;
 
   // TODO: Handle: br (VARIANT|INVARIANT).
-  // TODO: Hoist simple expressions out of loops.
   if (L->isLoopInvariant(Cond)) return Cond;
 
+  // Hoist simple values out.
+  if (L->makeLoopInvariant(Cond)) {
+    Changed = true;
+    return Cond;
+  }
+
   if (BinaryOperator *BO = dyn_cast<BinaryOperator>(Cond))
     if (BO->getOpcode() == Instruction::And ||
         BO->getOpcode() == Instruction::Or) {

Modified: llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp?rev=75584&r1=75583&r2=75584&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp Mon Jul 13 20:37:59 2009
@@ -91,7 +91,7 @@
   private:
     bool ProcessLoop(Loop *L);
     BasicBlock *RewriteLoopExitBlock(Loop *L, BasicBlock *Exit);
-    void InsertPreheaderForLoop(Loop *L);
+    BasicBlock *InsertPreheaderForLoop(Loop *L);
     Loop *SeparateNestedLoop(Loop *L);
     void InsertUniqueBackedgeBlock(Loop *L);
     void PlaceSplitBlockCarefully(BasicBlock *NewBB,
@@ -193,8 +193,9 @@
          "Header isn't first block in loop?");
 
   // Does the loop already have a preheader?  If so, don't insert one.
-  if (L->getLoopPreheader() == 0) {
-    InsertPreheaderForLoop(L);
+  BasicBlock *Preheader = L->getLoopPreheader();
+  if (!Preheader) {
+    Preheader = InsertPreheaderForLoop(L);
     NumInserted++;
     Changed = true;
   }
@@ -287,19 +288,11 @@
         Instruction *Inst = I++;
         if (Inst == CI)
           continue;
-        if (Inst->isTrapping()) {
+        if (!L->makeLoopInvariant(Inst, Preheader->getTerminator())) {
           AllInvariant = false;
+          Changed = true;
           break;
         }
-        for (unsigned j = 0, f = Inst->getNumOperands(); j != f; ++j)
-          if (!L->isLoopInvariant(Inst->getOperand(j))) {
-            AllInvariant = false;
-            break;
-          }
-        if (!AllInvariant)
-          break;
-        // Hoist.
-        Inst->moveBefore(L->getLoopPreheader()->getTerminator());
       }
       if (!AllInvariant) continue;
 
@@ -340,7 +333,7 @@
 /// preheader, this method is called to insert one.  This method has two phases:
 /// preheader insertion and analysis updating.
 ///
-void LoopSimplify::InsertPreheaderForLoop(Loop *L) {
+BasicBlock *LoopSimplify::InsertPreheaderForLoop(Loop *L) {
   BasicBlock *Header = L->getHeader();
 
   // Compute the set of predecessors of the loop that are not in the loop.
@@ -367,6 +360,8 @@
   // Make sure that NewBB is put someplace intelligent, which doesn't mess up
   // code layout too horribly.
   PlaceSplitBlockCarefully(NewBB, OutsideBlocks, L);
+
+  return NewBB;
 }
 
 /// RewriteLoopExitBlock - Ensure that the loop preheader dominates all exit

Modified: llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate9.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate9.ll?rev=75584&r1=75583&r2=75584&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate9.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/loop_evaluate9.ll Mon Jul 13 20:37:59 2009
@@ -1,6 +1,6 @@
 ; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t
-; RUN: grep {\[%\]tmp5.lcssa = phi i8 \\\[ 63, \[%\]cc70a02__complex_integers__Oadd.153.exit.i \\\]} %t
-; RUN: grep {\[%\]tmp4.lcssa = phi i8 \\\[ -28, \[%\]cc70a02__complex_integers__Oadd.153.exit.i \\\]} %t
+; RUN: grep {\[%\]tmp7 = icmp eq i8 -28, -28} %t
+; RUN: grep {\[%\]tmp8 = icmp eq i8 63, 63} %t
 ; PR4477
 
 ; Indvars should compute the exit values in loop.





More information about the llvm-commits mailing list