[PATCH] D45334: [LoopUnroll] Make LoopPeeling respect the AllowPeeling preference.

Chad Rosier via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 6 07:00:23 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL329395: [LoopUnroll] Make LoopPeeling respect the AllowPeeling preference. (authored by mcrosier, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45334?vs=141215&id=141339#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45334

Files:
  llvm/trunk/lib/Transforms/Utils/LoopUnrollPeel.cpp
  llvm/trunk/test/Transforms/LoopUnroll/peel-loop-not-forced.ll


Index: llvm/trunk/lib/Transforms/Utils/LoopUnrollPeel.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopUnrollPeel.cpp
+++ llvm/trunk/lib/Transforms/Utils/LoopUnrollPeel.cpp
@@ -232,6 +232,19 @@
   if (!L->empty())
     return;
 
+  // If the user provided a peel count, use that.
+  bool UserPeelCount = UnrollForcePeelCount.getNumOccurrences() > 0;
+  if (UserPeelCount) {
+    DEBUG(dbgs() << "Force-peeling first " << UnrollForcePeelCount
+                 << " iterations.\n");
+    UP.PeelCount = UnrollForcePeelCount;
+    return;
+  }
+
+  // Skip peeling if it's disabled.
+  if (!UP.AllowPeeling)
+    return;
+
   // Here we try to get rid of Phis which become invariants after 1, 2, ..., N
   // iterations of the loop. For this we compute the number for iterations after
   // which every Phi is guaranteed to become an invariant, and try to peel the
@@ -279,21 +292,12 @@
   if (TripCount)
     return;
 
-  // If the user provided a peel count, use that.
-  bool UserPeelCount = UnrollForcePeelCount.getNumOccurrences() > 0;
-  if (UserPeelCount) {
-    DEBUG(dbgs() << "Force-peeling first " << UnrollForcePeelCount
-                 << " iterations.\n");
-    UP.PeelCount = UnrollForcePeelCount;
-    return;
-  }
-
   // If we don't know the trip count, but have reason to believe the average
   // trip count is low, peeling should be beneficial, since we will usually
   // hit the peeled section.
   // We only do this in the presence of profile information, since otherwise
   // our estimates of the trip count are not reliable enough.
-  if (UP.AllowPeeling && L->getHeader()->getParent()->hasProfileData()) {
+  if (L->getHeader()->getParent()->hasProfileData()) {
     Optional<unsigned> PeelCount = getLoopEstimatedTripCount(L);
     if (!PeelCount)
       return;
Index: llvm/trunk/test/Transforms/LoopUnroll/peel-loop-not-forced.ll
===================================================================
--- llvm/trunk/test/Transforms/LoopUnroll/peel-loop-not-forced.ll
+++ llvm/trunk/test/Transforms/LoopUnroll/peel-loop-not-forced.ll
@@ -1,12 +1,15 @@
 ; RUN: opt < %s -S -loop-unroll -unroll-threshold=30 | FileCheck %s
+; RUN: opt < %s -S -loop-unroll -unroll-threshold=30 -unroll-allow-peeling=false | FileCheck %s --check-prefix=DISABLE
 
 define i32 @invariant_backedge_1(i32 %a, i32 %b) {
 ; CHECK-LABEL: @invariant_backedge_1
 ; CHECK-NOT:     %plus = phi
 ; CHECK:       loop.peel:
 ; CHECK:       loop:
 ; CHECK:         %i = phi
 ; CHECK:         %sum = phi
+; DISABLE-LABEL: @invariant_backedge_1
+; DISABLE-NOT: loop.peel:
 entry:
   br label %loop
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45334.141339.patch
Type: text/x-patch
Size: 2653 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180406/b7292ef4/attachment.bin>


More information about the llvm-commits mailing list