mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-04-02 07:41:38 +00:00
[LoopUnrolling] Re-prioritize Peeling and Partial unrolling
Summary: In current implementation the loop peeling happens after trip-count based partial unrolling and may sometimes not happen at all due to it (for example, if trip count is known, but UP.Partial = false). This is generally bad, the more than there are some situations where peeling is profitable even if the partial unrolling is disabled. This patch is a NFC which reorders peeling and partial unrolling application and prepares the code for implementation of the said optimizations. Patch by Max Kazantsev! Reviewers: sanjoy, anna, reames, apilipenko, igor-laevsky, mkuper Reviewed By: mkuper Subscribers: mkuper, llvm-commits, mzolotukhin Differential Revision: https://reviews.llvm.org/D30243 llvm-svn: 296897
This commit is contained in:
parent
1ba7dfb74b
commit
f07ac23c21
@ -53,7 +53,8 @@ bool UnrollRuntimeLoopRemainder(Loop *L, unsigned Count,
|
|||||||
bool PreserveLCSSA);
|
bool PreserveLCSSA);
|
||||||
|
|
||||||
void computePeelCount(Loop *L, unsigned LoopSize,
|
void computePeelCount(Loop *L, unsigned LoopSize,
|
||||||
TargetTransformInfo::UnrollingPreferences &UP);
|
TargetTransformInfo::UnrollingPreferences &UP,
|
||||||
|
unsigned &TripCount);
|
||||||
|
|
||||||
bool peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI, ScalarEvolution *SE,
|
bool peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI, ScalarEvolution *SE,
|
||||||
DominatorTree *DT, AssumptionCache *AC, bool PreserveLCSSA);
|
DominatorTree *DT, AssumptionCache *AC, bool PreserveLCSSA);
|
||||||
|
@ -784,7 +784,15 @@ static bool computeUnrollCount(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4rd priority is partial unrolling.
|
// 4th priority is loop peeling
|
||||||
|
computePeelCount(L, LoopSize, UP, TripCount);
|
||||||
|
if (UP.PeelCount) {
|
||||||
|
UP.Runtime = false;
|
||||||
|
UP.Count = 1;
|
||||||
|
return ExplicitUnroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5th priority is partial unrolling.
|
||||||
// Try partial unroll only when TripCount could be staticaly calculated.
|
// Try partial unroll only when TripCount could be staticaly calculated.
|
||||||
if (TripCount) {
|
if (TripCount) {
|
||||||
UP.Partial |= ExplicitUnroll;
|
UP.Partial |= ExplicitUnroll;
|
||||||
@ -847,14 +855,6 @@ static bool computeUnrollCount(
|
|||||||
<< "Unable to fully unroll loop as directed by unroll(full) pragma "
|
<< "Unable to fully unroll loop as directed by unroll(full) pragma "
|
||||||
"because loop has a runtime trip count.");
|
"because loop has a runtime trip count.");
|
||||||
|
|
||||||
// 5th priority is loop peeling
|
|
||||||
computePeelCount(L, LoopSize, UP);
|
|
||||||
if (UP.PeelCount) {
|
|
||||||
UP.Runtime = false;
|
|
||||||
UP.Count = 1;
|
|
||||||
return ExplicitUnroll;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6th priority is runtime unrolling.
|
// 6th priority is runtime unrolling.
|
||||||
// Don't unroll a runtime trip count loop when it is disabled.
|
// Don't unroll a runtime trip count loop when it is disabled.
|
||||||
if (HasRuntimeUnrollDisablePragma(L)) {
|
if (HasRuntimeUnrollDisablePragma(L)) {
|
||||||
|
@ -61,7 +61,8 @@ static bool canPeel(Loop *L) {
|
|||||||
|
|
||||||
// Return the number of iterations we want to peel off.
|
// Return the number of iterations we want to peel off.
|
||||||
void llvm::computePeelCount(Loop *L, unsigned LoopSize,
|
void llvm::computePeelCount(Loop *L, unsigned LoopSize,
|
||||||
TargetTransformInfo::UnrollingPreferences &UP) {
|
TargetTransformInfo::UnrollingPreferences &UP,
|
||||||
|
unsigned &TripCount) {
|
||||||
UP.PeelCount = 0;
|
UP.PeelCount = 0;
|
||||||
if (!canPeel(L))
|
if (!canPeel(L))
|
||||||
return;
|
return;
|
||||||
@ -70,6 +71,11 @@ void llvm::computePeelCount(Loop *L, unsigned LoopSize,
|
|||||||
if (!L->empty())
|
if (!L->empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Bail if we know the statically calculated trip count.
|
||||||
|
// In this case we rather prefer partial unrolling.
|
||||||
|
if (TripCount)
|
||||||
|
return;
|
||||||
|
|
||||||
// If the user provided a peel count, use that.
|
// If the user provided a peel count, use that.
|
||||||
bool UserPeelCount = UnrollForcePeelCount.getNumOccurrences() > 0;
|
bool UserPeelCount = UnrollForcePeelCount.getNumOccurrences() > 0;
|
||||||
if (UserPeelCount) {
|
if (UserPeelCount) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user