[PATCH] D28460: getLoopEstimatedTripCount should really be called getLoopEstimatedBackedgeTakeCount.
Xin Tong via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 8 12:24:50 PST 2017
trentxintong created this revision.
trentxintong added reviewers: mkuper, danielcdh, davidxl.
trentxintong added a subscriber: llvm-commits.
Herald added a subscriber: mzolotukhin.
getLoopEstimatedTripCount should really be called getLoopEstimatedBackedgeTakeCount.
https://reviews.llvm.org/D28460
Files:
include/llvm/Transforms/Utils/LoopUtils.h
lib/Transforms/Scalar/LoopUnrollPass.cpp
lib/Transforms/Utils/LoopUnrollPeel.cpp
lib/Transforms/Utils/LoopUtils.cpp
Index: lib/Transforms/Utils/LoopUtils.cpp
===================================================================
--- lib/Transforms/Utils/LoopUtils.cpp
+++ lib/Transforms/Utils/LoopUtils.cpp
@@ -1068,7 +1068,7 @@
return true;
}
-Optional<unsigned> llvm::getLoopEstimatedTripCount(Loop *L) {
+Optional<unsigned> llvm::getLoopEstimatedBackedgeTakenCount(Loop *L) {
// Only support loops with a unique exiting block, and a latch.
if (!L->getExitingBlock())
return None;
Index: lib/Transforms/Utils/LoopUnrollPeel.cpp
===================================================================
--- lib/Transforms/Utils/LoopUnrollPeel.cpp
+++ lib/Transforms/Utils/LoopUnrollPeel.cpp
@@ -84,7 +84,9 @@
// We only do this in the presence of profile information, since otherwise
// our estimates of the trip count are not reliable enough.
if (UP.AllowPeeling && L->getHeader()->getParent()->getEntryCount()) {
- Optional<unsigned> PeelCount = getLoopEstimatedTripCount(L);
+ // We only peel backedge taken count # of times as the original loop
+ // body will become the last iteration.
+ Optional<unsigned> PeelCount = getLoopEstimatedBackedgeTakenCount(L);
if (!PeelCount)
return;
Index: lib/Transforms/Scalar/LoopUnrollPass.cpp
===================================================================
--- lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -850,8 +850,10 @@
// Check if the runtime trip count is too small when profile is available.
if (L->getHeader()->getParent()->getEntryCount()) {
- if (auto ProfileTripCount = getLoopEstimatedTripCount(L)) {
- if (*ProfileTripCount < FlatLoopTripCountThreshold)
+ auto ProfileBETakenCount = getLoopEstimatedBackedgeTakenCount(L);
+ if (ProfileBETakenCount) {
+ // Trip count == BE taken count + 1.
+ if (*ProfileBETakenCount + 1 < FlatLoopTripCountThreshold)
return false;
else
UP.AllowExpensiveTripCount = true;
Index: include/llvm/Transforms/Utils/LoopUtils.h
===================================================================
--- include/llvm/Transforms/Utils/LoopUtils.h
+++ include/llvm/Transforms/Utils/LoopUtils.h
@@ -461,10 +461,10 @@
void addStringMetadataToLoop(Loop *TheLoop, const char *MDString,
unsigned V = 0);
-/// \brief Get a loop's estimated trip count based on branch weight metadata.
-/// Returns 0 when the count is estimated to be 0, or None when a meaningful
-/// estimate can not be made.
-Optional<unsigned> getLoopEstimatedTripCount(Loop *L);
+/// \brief Get a loop's estimated BE taken count based on branch weight
+/// metadata. Returns 0 when the count is estimated to be 0, or None when a
+/// meaningful estimate can not be made.
+Optional<unsigned> getLoopEstimatedBackedgeTakenCount(Loop *L);
/// Helper to consistently add the set of standard passes to a loop pass's \c
/// AnalysisUsage.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28460.83571.patch
Type: text/x-patch
Size: 2945 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170108/3355cc32/attachment.bin>
More information about the llvm-commits
mailing list