[llvm] r257402 - LoopUnroll: Use the optsize threshold for minsize as well

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 11 14:39:43 PST 2016


Author: bogner
Date: Mon Jan 11 16:39:43 2016
New Revision: 257402

URL: http://llvm.org/viewvc/llvm-project?rev=257402&view=rev
Log:
LoopUnroll: Use the optsize threshold for minsize as well

Currently we're unrolling loops more in minsize than in optsize, which
means -Oz will have a larger code size than -Os. That doesn't make any
sense.

This resolves the FIXME about this in LoopUnrollPass and extends the
optsize test to make sure we use the smaller threshold for minsize as
well.

Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
    llvm/trunk/test/Transforms/LoopUnroll/partial-unroll-optsize.ll

Modified: llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp?rev=257402&r1=257401&r2=257402&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp Mon Jan 11 16:39:43 2016
@@ -209,10 +209,7 @@ namespace {
                                        ? CurrentDynamicCostSavingsDiscount
                                        : UP.DynamicCostSavingsDiscount;
 
-      if (!UserThreshold &&
-          // FIXME: Use Function::optForSize().
-          L->getHeader()->getParent()->hasFnAttribute(
-              Attribute::OptimizeForSize)) {
+      if (!UserThreshold && L->getHeader()->getParent()->optForSize()) {
         Threshold = UP.OptSizeThreshold;
         PartialThreshold = UP.PartialOptSizeThreshold;
       }

Modified: llvm/trunk/test/Transforms/LoopUnroll/partial-unroll-optsize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopUnroll/partial-unroll-optsize.ll?rev=257402&r1=257401&r2=257402&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopUnroll/partial-unroll-optsize.ll (original)
+++ llvm/trunk/test/Transforms/LoopUnroll/partial-unroll-optsize.ll Mon Jan 11 16:39:43 2016
@@ -1,4 +1,6 @@
 ; RUN: opt < %s -S -loop-unroll -unroll-allow-partial | FileCheck %s
+; RUN: sed -e 's/optsize/minsize/' %s | opt -S -loop-unroll -unroll-allow-partial | FileCheck %s
+
 ; Loop size = 3, when the function has the optsize attribute, the
 ; OptSizeUnrollThreshold, i.e. 50, is used, hence the loop should be unrolled
 ; by 32 times because (1 * 32) + 2 < 50 (whereas (1 * 64 + 2) is not).
@@ -49,4 +51,3 @@ exit:
 ; CHECK-NEXT: add
 ; CHECK-NEXT: add
 ; CHECK-NEXT: icmp
-




More information about the llvm-commits mailing list