[PATCH] D20181: Don't try to rotate a loop more than once - we never do this anyway.

Michael Zolotukhin via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 10 15:10:46 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL272439: Don't try to rotate a loop more than once - we never do this anyway. (authored by mzolotukhin).

Changed prior to commit:
  http://reviews.llvm.org/D20181?vs=56974&id=60415#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20181

Files:
  llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp

Index: llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp
+++ llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp
@@ -569,26 +569,22 @@
   return true;
 }
 
-/// Rotate \c L as many times as possible. Return true if the loop is rotated
-/// at least once.
-static bool iterativelyRotateLoop(Loop *L, unsigned MaxHeaderSize, LoopInfo *LI,
-                                  const TargetTransformInfo *TTI,
-                                  AssumptionCache *AC, DominatorTree *DT,
-                                  ScalarEvolution *SE) {
+/// Rotate \c L, and return true if any modification was made.
+static bool processLoop(Loop *L, unsigned MaxHeaderSize, LoopInfo *LI,
+                        const TargetTransformInfo *TTI, AssumptionCache *AC,
+                        DominatorTree *DT, ScalarEvolution *SE) {
   // Save the loop metadata.
   MDNode *LoopMD = L->getLoopID();
 
   // Simplify the loop latch before attempting to rotate the header
   // upward. Rotation may not be needed if the loop tail can be folded into the
   // loop exit.
   bool SimplifiedLatch = simplifyLoopLatch(L, LI, DT);
 
-  // One loop can be rotated multiple times.
-  bool MadeChange = false;
-  while (rotateLoop(L, MaxHeaderSize, LI, TTI, AC, DT, SE, SimplifiedLatch)) {
-    MadeChange = true;
-    SimplifiedLatch = false;
-  }
+  bool MadeChange =
+      rotateLoop(L, MaxHeaderSize, LI, TTI, AC, DT, SE, SimplifiedLatch);
+  assert((!MadeChange || L->isLoopExiting(L->getLoopLatch())) &&
+         "Loop latch should be exiting after loop-rotate.");
 
   // Restore the loop metadata.
   // NB! We presume LoopRotation DOESN'T ADD its own metadata.
@@ -613,7 +609,7 @@
   auto *DT = FAM.getCachedResult<DominatorTreeAnalysis>(*F);
   auto *SE = FAM.getCachedResult<ScalarEvolutionAnalysis>(*F);
 
-  bool Changed = iterativelyRotateLoop(&L, MaxHeaderSize, LI, TTI, AC, DT, SE);
+  bool Changed = processLoop(&L, MaxHeaderSize, LI, TTI, AC, DT, SE);
   if (!Changed)
     return PreservedAnalyses::all();
   return getLoopPassPreservedAnalyses();
@@ -654,7 +650,7 @@
     auto *SEWP = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>();
     auto *SE = SEWP ? &SEWP->getSE() : nullptr;
 
-    return iterativelyRotateLoop(L, MaxHeaderSize, LI, TTI, AC, DT, SE);
+    return processLoop(L, MaxHeaderSize, LI, TTI, AC, DT, SE);
   }
 };
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20181.60415.patch
Type: text/x-patch
Size: 2457 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160610/05f600d5/attachment.bin>


More information about the llvm-commits mailing list