diff options
| author | Dehao Chen <dehao@google.com> | 2016-11-17 01:17:02 +0000 |
|---|---|---|
| committer | Dehao Chen <dehao@google.com> | 2016-11-17 01:17:02 +0000 |
| commit | 41d72a8632605ad9366b9bfcd12fe80a177b80ca (patch) | |
| tree | 8c52313d46859c2c91ec359ae6d57836f7e70379 /llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp | |
| parent | 9103036f5ffadf7a881e8dca42ff862570d1e79f (diff) | |
| download | bcm5719-llvm-41d72a8632605ad9366b9bfcd12fe80a177b80ca.tar.gz bcm5719-llvm-41d72a8632605ad9366b9bfcd12fe80a177b80ca.zip | |
Use profile info to adjust loop unroll threshold.
Summary:
For flat loop, even if it is hot, it is not a good idea to unroll in runtime, thus we set a lower partial unroll threshold.
For hot loop, we set a higher unroll threshold and allows expensive tripcount computation to allow more aggressive unrolling.
Reviewers: davidxl, mzolotukhin
Subscribers: sanjoy, mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D26527
llvm-svn: 287186
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp index d28cbb61803..7b154be8c5b 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -102,6 +102,12 @@ static cl::opt<unsigned> PragmaUnrollThreshold( cl::desc("Unrolled size limit for loops with an unroll(full) or " "unroll_count pragma.")); +static cl::opt<unsigned> FlatLoopTripCountThreshold( + "flat-loop-tripcount-threshold", cl::init(5), cl::Hidden, + cl::desc("If the runtime tripcount for the loop is lower than the " + "threshold, the loop is considered as flat and will be less " + "aggressively unrolled.")); + /// A magic value for use with the Threshold parameter to indicate /// that the loop unroll should be performed regardless of how much /// code expansion would result. @@ -748,6 +754,16 @@ static bool computeUnrollCount( bool ExplicitUnroll = PragmaCount > 0 || PragmaFullUnroll || PragmaEnableUnroll || UserUnrollCount; + // Check if the runtime trip count is too small when profile is available. + if (L->getHeader()->getParent()->getEntryCount() && TripCount == 0) { + if (auto ProfileTripCount = getLoopEstimatedTripCount(L)) { + if (*ProfileTripCount < FlatLoopTripCountThreshold) + return false; + else + UP.AllowExpensiveTripCount = true; + } + } + if (ExplicitUnroll && TripCount != 0) { // If the loop has an unrolling pragma, we want to be more aggressive with // unrolling limits. Set thresholds to at least the PragmaThreshold value |

