[PATCH] D18782: Reduce unroll of constant bounds loop with TripCount that is not modulo of unroll factor.

Evgeny Stupachenko via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 4 18:23:44 PDT 2016


evstupac created this revision.
evstupac added reviewers: mzolotukhin, resistor, escha.
evstupac added a subscriber: llvm-commits.
evstupac set the repository for this revision to rL LLVM.
Herald added a subscriber: mzolotukhin.

Allow the type of unroll only when AllowRuntime is true. 
Limit Count to DefaultRuntimeCount.

Repository:
  rL LLVM

http://reviews.llvm.org/D18782

Files:
  lib/Transforms/Scalar/LoopUnrollPass.cpp
  test/Transforms/LoopUnroll/partial-unroll-const-bounds.ll

Index: lib/Transforms/Scalar/LoopUnrollPass.cpp
===================================================================
--- lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -639,10 +639,12 @@
       Count = (std::max(UP.PartialThreshold, 3u) - 2) / (LoopSize - 2);
       while (Count != 0 && TripCount % Count != 0)
         Count--;
-      if (Count <= 1) {
+      if (AllowRuntime && Count <= 1) {
         // If there is no Count that is modulo of TripCount, set Count to
         // largest power-of-two factor that satisfies the threshold limit.
-        Count = (std::max(UP.PartialThreshold, 3u) - 2) / (LoopSize - 2);
+        // As we'll create fixup loop, do the type of unrolling only if
+        // runtime unrolling is allowed.
+        Count = DefaultUnrollRuntimeCount;
         UnrolledSize = (LoopSize - 2) * Count + 2;
         while (Count != 0 && UnrolledSize > UP.PartialThreshold) {
           Count >>= 1;
Index: test/Transforms/LoopUnroll/partial-unroll-const-bounds.ll
===================================================================
--- test/Transforms/LoopUnroll/partial-unroll-const-bounds.ll
+++ test/Transforms/LoopUnroll/partial-unroll-const-bounds.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -S -unroll-threshold=20 -loop-unroll -unroll-allow-partial | FileCheck %s
+; RUN: opt < %s -S -unroll-threshold=20 -loop-unroll -unroll-allow-partial -unroll-runtime | FileCheck %s
 
 ; The Loop TripCount is 9. However unroll factors 3 or 9 exceed given threshold.
 ; The test checks that we choose a smaller, power-of-two, unroll count and do not give up on unrolling.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18782.52651.patch
Type: text/x-patch
Size: 1626 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160405/8fa7e998/attachment.bin>


More information about the llvm-commits mailing list