[PATCH] D30243: [LoopUnrolling] Re-prioritize Peeling and Partial unrolling

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 21 22:05:49 PST 2017


mkazantsev created this revision.
Herald added a subscriber: mzolotukhin.

In current implementation partial unrolling has a higher priority than loop
peeling. As result, two negative effects may happen:

1. UP.Partial flag set to false causes non-applicability of peeling
2. UP.Partial flag set to true makes some loops partially unroll, even if just peeling could be more beneficial for them.

One of optimization opportunities we miss for this reason is peeling loops with
Phi with invariant backedge input introduced in the patch https://reviews.llvm.org/D30161

This patch gives loop peeling a higher priority than partial unrolling and also
makes is independent on UP.Partial flag.


https://reviews.llvm.org/D30243

Files:
  lib/Transforms/Scalar/LoopUnrollPass.cpp


Index: lib/Transforms/Scalar/LoopUnrollPass.cpp
===================================================================
--- lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -784,7 +784,15 @@
     }
   }
 
-  // 4rd priority is partial unrolling.
+  // 4th priority is loop peeling
+  computePeelCount(L, LoopSize, UP);
+  if (UP.PeelCount) {
+    UP.Runtime = false;
+    UP.Count = 1;
+    return ExplicitUnroll;
+  }
+
+  // 5th priority is partial unrolling.
   // Try partial unroll only when TripCount could be staticaly calculated.
   if (TripCount) {
     UP.Partial |= ExplicitUnroll;
@@ -847,14 +855,6 @@
         << "Unable to fully unroll loop as directed by unroll(full) pragma "
            "because loop has a runtime trip count.");
 
-  // 5th priority is loop peeling
-  computePeelCount(L, LoopSize, UP);
-  if (UP.PeelCount) {
-    UP.Runtime = false;
-    UP.Count = 1;
-    return ExplicitUnroll;
-  }
-
   // 6th priority is runtime unrolling.
   // Don't unroll a runtime trip count loop when it is disabled.
   if (HasRuntimeUnrollDisablePragma(L)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30243.89322.patch
Type: text/x-patch
Size: 1110 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170222/56c75e11/attachment.bin>


More information about the llvm-commits mailing list