[PATCH] D23388: [LoopUnroll] By default disable unrolling when optimizing for size.

Michael Zolotukhin via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 10 17:30:28 PDT 2016


mzolotukhin created this revision.
mzolotukhin added reviewers: hfinkel, chandlerc.
mzolotukhin added a subscriber: llvm-commits.
Herald added a subscriber: mzolotukhin.

In clang commit r268509 we started to invoke loop-unroll pass from the
driver even under -Os. However, we happen to not initialize optsize
thresholds properly, which si fixed with this change.

r268509 led to some big compile time regressions, because we started to
unroll some loops that we didn't unroll before. With this change I hope
to recover most of the regressions. We still are slightly slower than
before, because we do some checks here and there in loop-unrolling
before we bail out, but at least the slowdown is not that huge now.

https://reviews.llvm.org/D23388

Files:
  include/llvm/CodeGen/BasicTTIImpl.h
  lib/Transforms/Scalar/LoopUnrollPass.cpp

Index: lib/Transforms/Scalar/LoopUnrollPass.cpp
===================================================================
--- lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -948,6 +948,10 @@
       L, TTI, ProvidedThreshold, ProvidedCount, ProvidedAllowPartial,
       ProvidedRuntime);
 
+  // Exit early if unrolling is disabled.
+  if (UP.Threshold == 0 && UP.PartialThreshold == 0)
+    return false;
+
   // If the loop contains a convergent operation, the prelude we'd add
   // to do the first few instructions before we hit the unrolled loop
   // is unsafe -- it adds a control-flow dependency to the convergent
Index: include/llvm/CodeGen/BasicTTIImpl.h
===================================================================
--- include/llvm/CodeGen/BasicTTIImpl.h
+++ include/llvm/CodeGen/BasicTTIImpl.h
@@ -281,7 +281,11 @@
 
     // Enable runtime and partial unrolling up to the specified size.
     UP.Partial = UP.Runtime = true;
-    UP.PartialThreshold = UP.PartialOptSizeThreshold = MaxOps;
+    UP.PartialThreshold = MaxOps;
+
+    // Avoid unrolling when optimizing for size.
+    UP.OptSizeThreshold = 0;
+    UP.PartialOptSizeThreshold = 0;
   }
 
   /// @}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23388.67639.patch
Type: text/x-patch
Size: 1214 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160811/18d0dd1e/attachment.bin>


More information about the llvm-commits mailing list