[llvm] r316986 - [LoopUnroll] Clean up remarks for unroll remainder
David Green via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 31 03:47:46 PDT 2017
Author: dmgreen
Date: Tue Oct 31 03:47:46 2017
New Revision: 316986
URL: http://llvm.org/viewvc/llvm-project?rev=316986&view=rev
Log:
[LoopUnroll] Clean up remarks for unroll remainder
The optimisation remarks for loop unrolling with an unrolled remainder looks something like:
test.c:7:18: remark: completely unrolled loop with 3 iterations [-Rpass=loop-unroll]
C[i] += A[i*N+j];
^
test.c:6:9: remark: unrolled loop by a factor of 4 with run-time trip count [-Rpass=loop-unroll]
for(int j = 0; j < N; j++)
^
This removes the first of the two messages.
Differential revision: https://reviews.llvm.org/D38725
Modified:
llvm/trunk/include/llvm/Transforms/Utils/UnrollLoop.h
llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp
llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp
llvm/trunk/test/Transforms/LoopUnroll/loop-remarks.ll
Modified: llvm/trunk/include/llvm/Transforms/Utils/UnrollLoop.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/UnrollLoop.h?rev=316986&r1=316985&r2=316986&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/UnrollLoop.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/UnrollLoop.h Tue Oct 31 03:47:46 2017
@@ -67,7 +67,6 @@ bool UnrollRuntimeLoopRemainder(Loop *L,
LoopInfo *LI,
ScalarEvolution *SE, DominatorTree *DT,
AssumptionCache *AC,
- OptimizationRemarkEmitter *ORE,
bool PreserveLCSSA);
void computePeelCount(Loop *L, unsigned LoopSize,
Modified: llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp?rev=316986&r1=316985&r2=316986&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp Tue Oct 31 03:47:46 2017
@@ -427,9 +427,8 @@ LoopUnrollResult llvm::UnrollLoop(
if (RuntimeTripCount && TripMultiple % Count != 0 &&
!UnrollRuntimeLoopRemainder(L, Count, AllowExpensiveTripCount,
- EpilogProfitability, UnrollRemainder,
- LI, SE, DT, AC, ORE,
- PreserveLCSSA)) {
+ EpilogProfitability, UnrollRemainder, LI, SE,
+ DT, AC, PreserveLCSSA)) {
if (Force)
RuntimeTripCount = false;
else {
@@ -461,21 +460,23 @@ LoopUnrollResult llvm::UnrollLoop(
if (CompletelyUnroll) {
DEBUG(dbgs() << "COMPLETELY UNROLLING loop %" << Header->getName()
<< " with trip count " << TripCount << "!\n");
- ORE->emit([&]() {
- return OptimizationRemark(DEBUG_TYPE, "FullyUnrolled", L->getStartLoc(),
- L->getHeader())
- << "completely unrolled loop with " << NV("UnrollCount", TripCount)
- << " iterations";
- });
+ if (ORE)
+ ORE->emit([&]() {
+ return OptimizationRemark(DEBUG_TYPE, "FullyUnrolled", L->getStartLoc(),
+ L->getHeader())
+ << "completely unrolled loop with "
+ << NV("UnrollCount", TripCount) << " iterations";
+ });
} else if (PeelCount) {
DEBUG(dbgs() << "PEELING loop %" << Header->getName()
<< " with iteration count " << PeelCount << "!\n");
- ORE->emit([&]() {
- return OptimizationRemark(DEBUG_TYPE, "Peeled", L->getStartLoc(),
- L->getHeader())
- << " peeled loop by " << NV("PeelCount", PeelCount)
- << " iterations";
- });
+ if (ORE)
+ ORE->emit([&]() {
+ return OptimizationRemark(DEBUG_TYPE, "Peeled", L->getStartLoc(),
+ L->getHeader())
+ << " peeled loop by " << NV("PeelCount", PeelCount)
+ << " iterations";
+ });
} else {
auto DiagBuilder = [&]() {
OptimizationRemark Diag(DEBUG_TYPE, "PartialUnrolled", L->getStartLoc(),
@@ -488,19 +489,23 @@ LoopUnrollResult llvm::UnrollLoop(
<< " by " << Count);
if (TripMultiple == 0 || BreakoutTrip != TripMultiple) {
DEBUG(dbgs() << " with a breakout at trip " << BreakoutTrip);
- ORE->emit([&]() {
- return DiagBuilder() << " with a breakout at trip "
- << NV("BreakoutTrip", BreakoutTrip);
- });
+ if (ORE)
+ ORE->emit([&]() {
+ return DiagBuilder() << " with a breakout at trip "
+ << NV("BreakoutTrip", BreakoutTrip);
+ });
} else if (TripMultiple != 1) {
DEBUG(dbgs() << " with " << TripMultiple << " trips per branch");
- ORE->emit([&]() {
- return DiagBuilder() << " with " << NV("TripMultiple", TripMultiple)
- << " trips per branch";
- });
+ if (ORE)
+ ORE->emit([&]() {
+ return DiagBuilder() << " with " << NV("TripMultiple", TripMultiple)
+ << " trips per branch";
+ });
} else if (RuntimeTripCount) {
DEBUG(dbgs() << " with run-time trip count");
- ORE->emit([&]() { return DiagBuilder() << " with run-time trip count"; });
+ if (ORE)
+ ORE->emit(
+ [&]() { return DiagBuilder() << " with run-time trip count"; });
}
DEBUG(dbgs() << "!\n");
}
Modified: llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp?rev=316986&r1=316985&r2=316986&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp Tue Oct 31 03:47:46 2017
@@ -540,7 +540,6 @@ bool llvm::UnrollRuntimeLoopRemainder(Lo
bool UnrollRemainder,
LoopInfo *LI, ScalarEvolution *SE,
DominatorTree *DT, AssumptionCache *AC,
- OptimizationRemarkEmitter *ORE,
bool PreserveLCSSA) {
DEBUG(dbgs() << "Trying runtime unrolling on Loop: \n");
DEBUG(L->dump());
@@ -907,12 +906,12 @@ bool llvm::UnrollRuntimeLoopRemainder(Lo
if (remainderLoop && UnrollRemainder) {
DEBUG(dbgs() << "Unrolling remainder loop\n");
- UnrollLoop(remainderLoop, /*Count*/Count - 1, /*TripCount*/Count - 1,
- /*Force*/false, /*AllowRuntime*/false,
- /*AllowExpensiveTripCount*/false, /*PreserveCondBr*/true,
- /*PreserveOnlyFirst*/false, /*TripMultiple*/1,
- /*PeelCount*/0, /*UnrollRemainder*/false, LI, SE, DT, AC, ORE,
- PreserveLCSSA);
+ UnrollLoop(remainderLoop, /*Count*/ Count - 1, /*TripCount*/ Count - 1,
+ /*Force*/ false, /*AllowRuntime*/ false,
+ /*AllowExpensiveTripCount*/ false, /*PreserveCondBr*/ true,
+ /*PreserveOnlyFirst*/ false, /*TripMultiple*/ 1,
+ /*PeelCount*/ 0, /*UnrollRemainder*/ false, LI, SE, DT, AC,
+ /*ORE*/ nullptr, PreserveLCSSA);
}
NumRuntimeUnrolled++;
Modified: llvm/trunk/test/Transforms/LoopUnroll/loop-remarks.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopUnroll/loop-remarks.ll?rev=316986&r1=316985&r2=316986&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopUnroll/loop-remarks.ll (original)
+++ llvm/trunk/test/Transforms/LoopUnroll/loop-remarks.ll Tue Oct 31 03:47:46 2017
@@ -1,8 +1,10 @@
; RUN: opt < %s -S -loop-unroll -pass-remarks=loop-unroll -unroll-count=16 2>&1 | FileCheck -check-prefix=COMPLETE-UNROLL %s
; RUN: opt < %s -S -loop-unroll -pass-remarks=loop-unroll -unroll-count=4 2>&1 | FileCheck -check-prefix=PARTIAL-UNROLL %s
+; RUN: opt < %s -S -loop-unroll -pass-remarks=loop-unroll -unroll-count=4 -unroll-runtime=true -unroll-remainder 2>&1 | FileCheck %s --check-prefix=RUNTIME-UNROLL
; COMPLETE-UNROLL: remark: {{.*}}: completely unrolled loop with 16 iterations
; PARTIAL-UNROLL: remark: {{.*}}: unrolled loop by a factor of 4
+; RUNTIME-UNROLL: remark: {{.*}}: unrolled loop by a factor of 4
define i32 @sum() {
entry:
@@ -22,4 +24,25 @@ for.end:
ret i32 %add1
}
-declare i32 @baz(i32)
+; RUNTIME-UNROLL-NOT: remark: {{.*}}: completely unrolled loop with 3 iterations
+; RUNTIME-UNROLL: remark: {{.*}}: unrolled loop by a factor of 4
+
+define i32 @runtime(i32 %n) {
+entry:
+ br label %for.body
+
+for.body: ; preds = %for.body, %entry
+ %s.06 = phi i32 [ 0, %entry ], [ %add1, %for.body ]
+ %i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ %add = add nsw i32 %i.05, 4
+ %call = tail call i32 @baz(i32 %add) #2
+ %add1 = add nsw i32 %call, %s.06
+ %inc = add nsw i32 %i.05, 1
+ %exitcond = icmp eq i32 %inc, %n
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body
+ ret i32 %add1
+}
+
+declare i32 @baz(i32)
\ No newline at end of file
More information about the llvm-commits
mailing list