diff options
author | Michael Kuperstein <mkuper@google.com> | 2016-11-30 21:13:57 +0000 |
---|---|---|
committer | Michael Kuperstein <mkuper@google.com> | 2016-11-30 21:13:57 +0000 |
commit | b151a641aa8fe3c1bbb2ed78279ede5f1ecc0e7e (patch) | |
tree | 1109eab7fac4364f34aa2da7f93ecdc8d31d16bd /llvm/lib/Transforms/Utils/LoopUtils.cpp | |
parent | aa8b28e50901045476faca1b1047123d4f43d7ce (diff) | |
download | llvm-b151a641aa8fe3c1bbb2ed78279ede5f1ecc0e7e.zip llvm-b151a641aa8fe3c1bbb2ed78279ede5f1ecc0e7e.tar.gz llvm-b151a641aa8fe3c1bbb2ed78279ede5f1ecc0e7e.tar.bz2 |
[LoopUnroll] Implement profile-based loop peeling
This implements PGO-driven loop peeling.
The basic idea is that when the average dynamic trip-count of a loop is known,
based on PGO, to be low, we can expect a performance win by peeling off the
first several iterations of that loop.
Unlike unrolling based on a known trip count, or a trip count multiple, this
doesn't save us the conditional check and branch on each iteration. However,
it does allow us to simplify the straight-line code we get (constant-folding,
etc.). This is important given that we know that we will usually only hit this
code, and not the actual loop.
This is currently disabled by default.
Differential Revision: https://reviews.llvm.org/D25963
llvm-svn: 288274
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUtils.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index d3817ee..fd35cd0 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -1090,16 +1090,16 @@ Optional<unsigned> llvm::getLoopEstimatedTripCount(Loop *L) { // from the raw counts to provide a better probability estimate. Remove // the adjustment by subtracting 1 from both weights. uint64_t TrueVal, FalseVal; - if (!LatchBR->extractProfMetadata(TrueVal, FalseVal) || (TrueVal <= 1) || - (FalseVal <= 1)) + if (!LatchBR->extractProfMetadata(TrueVal, FalseVal)) return None; - TrueVal -= 1; - FalseVal -= 1; + if (!TrueVal || !FalseVal) + return 0; - // Divide the count of the backedge by the count of the edge exiting the loop. + // Divide the count of the backedge by the count of the edge exiting the loop, + // rounding to nearest. if (LatchBR->getSuccessor(0) == L->getHeader()) - return TrueVal / FalseVal; + return (TrueVal + (FalseVal / 2)) / FalseVal; else - return FalseVal / TrueVal; + return (FalseVal + (TrueVal / 2)) / TrueVal; } |