From 2ab07ac8fe545b0f65c6981e62384572acae8378 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Mon, 11 Jan 2016 22:39:43 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257402 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopUnrollPass.cpp | 5 +---- test/Transforms/LoopUnroll/partial-unroll-optsize.ll | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/Transforms/Scalar/LoopUnrollPass.cpp b/lib/Transforms/Scalar/LoopUnrollPass.cpp index 56ae5c01041..bc0f1e9f400 100644 --- a/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -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; } diff --git a/test/Transforms/LoopUnroll/partial-unroll-optsize.ll b/test/Transforms/LoopUnroll/partial-unroll-optsize.ll index a650317f3df..e5e0151761b 100644 --- a/test/Transforms/LoopUnroll/partial-unroll-optsize.ll +++ b/test/Transforms/LoopUnroll/partial-unroll-optsize.ll @@ -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 - -- 2.34.1