aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/LoopUnroll.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-06-17 21:03:50 +0200
committerNikita Popov <nikita.ppv@gmail.com>2021-06-18 23:47:03 +0200
commit3308205ae9dd3b42e19b377157c642a04312f7fd (patch)
tree8e30f2d7777b2fa192000a3b5092fcf3fa6df38c /llvm/lib/Transforms/Utils/LoopUnroll.cpp
parentfb19aa0c74fdb864ddbd677a7b3585661966a098 (diff)
downloadllvm-3308205ae9dd3b42e19b377157c642a04312f7fd.zip
llvm-3308205ae9dd3b42e19b377157c642a04312f7fd.tar.gz
llvm-3308205ae9dd3b42e19b377157c642a04312f7fd.tar.bz2
[LoopUnroll] Simplify optimization remarks
Remove dependence on ULO.TripCount/ULO.TripMultiple from ORE and debug code. For debug code, print information about all exits. For optimization remarks, only include the unroll count and the type of unroll (complete, partial or runtime), but omit detailed information about exit folding, now that more than one exit may be folded. Differential Revision: https://reviews.llvm.org/D104482
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUnroll.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/LoopUnroll.cpp69
1 files changed, 20 insertions, 49 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
index 4d61127..17e4f09 100644
--- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
@@ -296,11 +296,6 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
return LoopUnrollResult::Unmodified;
}
- if (ULO.TripCount != 0)
- LLVM_DEBUG(dbgs() << " Trip Count = " << ULO.TripCount << "\n");
- if (ULO.TripMultiple != 1)
- LLVM_DEBUG(dbgs() << " Trip Multiple = " << ULO.TripMultiple << "\n");
-
// Don't enter the unroll code if there is nothing to do.
if (ULO.TripCount == 0 && ULO.Count < 2) {
LLVM_DEBUG(dbgs() << "Won't unroll; almost nothing to do\n");
@@ -357,6 +352,10 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
}
Info.ExitOnTrue = !L->contains(BI->getSuccessor(0));
Info.ExitingBlocks.push_back(ExitingBlock);
+ LLVM_DEBUG(dbgs() << " Exiting block %" << ExitingBlock->getName()
+ << ": TripCount=" << Info.TripCount
+ << ", TripMultiple=" << Info.TripMultiple
+ << ", BreakoutTrip=" << Info.BreakoutTrip << "\n");
}
// Are we eliminating the loop control altogether? Note that we can know
@@ -369,8 +368,8 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
// We assume a run-time trip count if the compiler cannot
// figure out the loop trip count and the unroll-runtime
// flag is specified.
- bool RuntimeTripCount =
- !CompletelyUnroll && ULO.TripCount == 0 && ULO.AllowRuntime;
+ bool RuntimeTripCount = !CompletelyUnroll && ULO.TripCount == 0 &&
+ ULO.TripMultiple % ULO.Count != 0 && ULO.AllowRuntime;
// Go through all exits of L and see if there are any phi-nodes there. We just
// conservatively assume that they're inserted to preserve LCSSA form, which
@@ -418,7 +417,7 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
UnrollRuntimeEpilog.getNumOccurrences() ? UnrollRuntimeEpilog
: isEpilogProfitable(L);
- if (RuntimeTripCount && ULO.TripMultiple % ULO.Count != 0 &&
+ if (RuntimeTripCount &&
!UnrollRuntimeLoopRemainder(L, ULO.Count, ULO.AllowExpensiveTripCount,
EpilogProfitability, ULO.UnrollRemainder,
ULO.ForgetAllSCEV, LI, SE, DT, AC, TTI,
@@ -432,62 +431,34 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
}
}
- // If we know the trip count, we know the multiple...
- // TODO: This is only used for the ORE code, remove it.
- unsigned BreakoutTrip = 0;
- if (ULO.TripCount != 0) {
- BreakoutTrip = ULO.TripCount % ULO.Count;
- ULO.TripMultiple = 0;
- } else {
- // Figure out what multiple to use.
- BreakoutTrip = ULO.TripMultiple =
- (unsigned)GreatestCommonDivisor64(ULO.Count, ULO.TripMultiple);
- }
-
using namespace ore;
// Report the unrolling decision.
if (CompletelyUnroll) {
LLVM_DEBUG(dbgs() << "COMPLETELY UNROLLING loop %" << Header->getName()
- << " with trip count " << ULO.TripCount << "!\n");
+ << " with trip count " << ULO.Count << "!\n");
if (ORE)
ORE->emit([&]() {
return OptimizationRemark(DEBUG_TYPE, "FullyUnrolled", L->getStartLoc(),
L->getHeader())
<< "completely unrolled loop with "
- << NV("UnrollCount", ULO.TripCount) << " iterations";
+ << NV("UnrollCount", ULO.Count) << " iterations";
});
} else {
- auto DiagBuilder = [&]() {
- OptimizationRemark Diag(DEBUG_TYPE, "PartialUnrolled", L->getStartLoc(),
- L->getHeader());
- return Diag << "unrolled loop by a factor of "
- << NV("UnrollCount", ULO.Count);
- };
-
LLVM_DEBUG(dbgs() << "UNROLLING loop %" << Header->getName() << " by "
<< ULO.Count);
- if (ULO.TripMultiple == 0 || BreakoutTrip != ULO.TripMultiple) {
- LLVM_DEBUG(dbgs() << " with a breakout at trip " << BreakoutTrip);
- if (ORE)
- ORE->emit([&]() {
- return DiagBuilder() << " with a breakout at trip "
- << NV("BreakoutTrip", BreakoutTrip);
- });
- } else if (ULO.TripMultiple != 1) {
- LLVM_DEBUG(dbgs() << " with " << ULO.TripMultiple << " trips per branch");
- if (ORE)
- ORE->emit([&]() {
- return DiagBuilder()
- << " with " << NV("TripMultiple", ULO.TripMultiple)
- << " trips per branch";
- });
- } else if (RuntimeTripCount) {
+ if (RuntimeTripCount)
LLVM_DEBUG(dbgs() << " with run-time trip count");
- if (ORE)
- ORE->emit(
- [&]() { return DiagBuilder() << " with run-time trip count"; });
- }
LLVM_DEBUG(dbgs() << "!\n");
+
+ if (ORE)
+ ORE->emit([&]() {
+ OptimizationRemark Diag(DEBUG_TYPE, "PartialUnrolled", L->getStartLoc(),
+ L->getHeader());
+ Diag << "unrolled loop by a factor of " << NV("UnrollCount", ULO.Count);
+ if (RuntimeTripCount)
+ Diag << " with run-time trip count";
+ return Diag;
+ });
}
// We are going to make changes to this loop. SCEV may be keeping cached info