summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2019-04-17 15:57:43 +0000
committerFlorian Hahn <flo@fhahn.com>2019-04-17 15:57:43 +0000
commit893aea58ea5ead1433658f181fd5bd749fe21a92 (patch)
tree4966a824bbd39f546d974211369d4351a67191ea /llvm/lib/Transforms
parente7fe6dd5edb828e702d02c7cdc6565ace4c84f5b (diff)
downloadbcm5719-llvm-893aea58ea5ead1433658f181fd5bd749fe21a92.tar.gz
bcm5719-llvm-893aea58ea5ead1433658f181fd5bd749fe21a92.zip
[LoopUnroll] Allow unrolling if the unrolled size does not exceed loop size.
Summary: In the following cases, unrolling can be beneficial, even when optimizing for code size: 1) very low trip counts 2) potential to constant fold most instructions after fully unrolling. We can unroll in those cases, by setting the unrolling threshold to the loop size. This might highlight some cost modeling issues and fixing them will have a positive impact in general. Reviewers: vsk, efriedma, dmgreen, paquette Reviewed By: paquette Differential Revision: https://reviews.llvm.org/D60265 llvm-svn: 358586
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
index c113e4d3166..53015d25842 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -207,6 +207,7 @@ TargetTransformInfo::UnrollingPreferences llvm::gatherUnrollingPreferences(
if (OptForSize) {
UP.Threshold = UP.OptSizeThreshold;
UP.PartialThreshold = UP.PartialOptSizeThreshold;
+ UP.MaxPercentThresholdBoost = 100;
}
// Apply any user values specified by cl::opt
@@ -993,6 +994,7 @@ static LoopUnrollResult tryToUnrollLoop(
if (OnlyWhenForced && !(TM & TM_Enable))
return LoopUnrollResult::Unmodified;
+ bool OptForSize = L->getHeader()->getParent()->hasOptSize();
unsigned NumInlineCandidates;
bool NotDuplicatable;
bool Convergent;
@@ -1000,8 +1002,11 @@ static LoopUnrollResult tryToUnrollLoop(
L, SE, TTI, BFI, PSI, OptLevel, ProvidedThreshold, ProvidedCount,
ProvidedAllowPartial, ProvidedRuntime, ProvidedUpperBound,
ProvidedAllowPeeling);
- // Exit early if unrolling is disabled.
- if (UP.Threshold == 0 && (!UP.Partial || UP.PartialThreshold == 0))
+
+ // Exit early if unrolling is disabled. For OptForSize, we pick the loop size
+ // as threshold later on.
+ if (UP.Threshold == 0 && (!UP.Partial || UP.PartialThreshold == 0) &&
+ !OptForSize)
return LoopUnrollResult::Unmodified;
SmallPtrSet<const Value *, 32> EphValues;
@@ -1016,6 +1021,12 @@ static LoopUnrollResult tryToUnrollLoop(
<< " instructions.\n");
return LoopUnrollResult::Unmodified;
}
+
+ // When optimizing for size, use LoopSize as threshold, to (fully) unroll
+ // loops, if it does not increase code size.
+ if (OptForSize)
+ UP.Threshold = std::max(UP.Threshold, LoopSize);
+
if (NumInlineCandidates != 0) {
LLVM_DEBUG(dbgs() << " Not unrolling loop with inlinable calls.\n");
return LoopUnrollResult::Unmodified;
OpenPOWER on IntegriCloud