llvm.org GIT mirror llvm / 7fa6b25
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316986 91177308-0d34-0410-b5e6-96231b3b80d8 David Green 1 year, 11 months ago
4 changed file(s) with 59 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
6666 LoopInfo *LI,
6767 ScalarEvolution *SE, DominatorTree *DT,
6868 AssumptionCache *AC,
69 OptimizationRemarkEmitter *ORE,
7069 bool PreserveLCSSA);
7170
7271 void computePeelCount(Loop *L, unsigned LoopSize,
426426
427427 if (RuntimeTripCount && TripMultiple % Count != 0 &&
428428 !UnrollRuntimeLoopRemainder(L, Count, AllowExpensiveTripCount,
429 EpilogProfitability, UnrollRemainder,
430 LI, SE, DT, AC, ORE,
431 PreserveLCSSA)) {
429 EpilogProfitability, UnrollRemainder, LI, SE,
430 DT, AC, PreserveLCSSA)) {
432431 if (Force)
433432 RuntimeTripCount = false;
434433 else {
460459 if (CompletelyUnroll) {
461460 DEBUG(dbgs() << "COMPLETELY UNROLLING loop %" << Header->getName()
462461 << " with trip count " << TripCount << "!\n");
463 ORE->emit([&]() {
464 return OptimizationRemark(DEBUG_TYPE, "FullyUnrolled", L->getStartLoc(),
465 L->getHeader())
466 << "completely unrolled loop with " << NV("UnrollCount", TripCount)
467 << " iterations";
468 });
462 if (ORE)
463 ORE->emit([&]() {
464 return OptimizationRemark(DEBUG_TYPE, "FullyUnrolled", L->getStartLoc(),
465 L->getHeader())
466 << "completely unrolled loop with "
467 << NV("UnrollCount", TripCount) << " iterations";
468 });
469469 } else if (PeelCount) {
470470 DEBUG(dbgs() << "PEELING loop %" << Header->getName()
471471 << " with iteration count " << PeelCount << "!\n");
472 ORE->emit([&]() {
473 return OptimizationRemark(DEBUG_TYPE, "Peeled", L->getStartLoc(),
474 L->getHeader())
475 << " peeled loop by " << NV("PeelCount", PeelCount)
476 << " iterations";
477 });
472 if (ORE)
473 ORE->emit([&]() {
474 return OptimizationRemark(DEBUG_TYPE, "Peeled", L->getStartLoc(),
475 L->getHeader())
476 << " peeled loop by " << NV("PeelCount", PeelCount)
477 << " iterations";
478 });
478479 } else {
479480 auto DiagBuilder = [&]() {
480481 OptimizationRemark Diag(DEBUG_TYPE, "PartialUnrolled", L->getStartLoc(),
487488 << " by " << Count);
488489 if (TripMultiple == 0 || BreakoutTrip != TripMultiple) {
489490 DEBUG(dbgs() << " with a breakout at trip " << BreakoutTrip);
490 ORE->emit([&]() {
491 return DiagBuilder() << " with a breakout at trip "
492 << NV("BreakoutTrip", BreakoutTrip);
493 });
491 if (ORE)
492 ORE->emit([&]() {
493 return DiagBuilder() << " with a breakout at trip "
494 << NV("BreakoutTrip", BreakoutTrip);
495 });
494496 } else if (TripMultiple != 1) {
495497 DEBUG(dbgs() << " with " << TripMultiple << " trips per branch");
496 ORE->emit([&]() {
497 return DiagBuilder() << " with " << NV("TripMultiple", TripMultiple)
498 << " trips per branch";
499 });
498 if (ORE)
499 ORE->emit([&]() {
500 return DiagBuilder() << " with " << NV("TripMultiple", TripMultiple)
501 << " trips per branch";
502 });
500503 } else if (RuntimeTripCount) {
501504 DEBUG(dbgs() << " with run-time trip count");
502 ORE->emit([&]() { return DiagBuilder() << " with run-time trip count"; });
505 if (ORE)
506 ORE->emit(
507 [&]() { return DiagBuilder() << " with run-time trip count"; });
503508 }
504509 DEBUG(dbgs() << "!\n");
505510 }
539539 bool UnrollRemainder,
540540 LoopInfo *LI, ScalarEvolution *SE,
541541 DominatorTree *DT, AssumptionCache *AC,
542 OptimizationRemarkEmitter *ORE,
543542 bool PreserveLCSSA) {
544543 DEBUG(dbgs() << "Trying runtime unrolling on Loop: \n");
545544 DEBUG(L->dump());
906905
907906 if (remainderLoop && UnrollRemainder) {
908907 DEBUG(dbgs() << "Unrolling remainder loop\n");
909 UnrollLoop(remainderLoop, /*Count*/Count - 1, /*TripCount*/Count - 1,
910 /*Force*/false, /*AllowRuntime*/false,
911 /*AllowExpensiveTripCount*/false, /*PreserveCondBr*/true,
912 /*PreserveOnlyFirst*/false, /*TripMultiple*/1,
913 /*PeelCount*/0, /*UnrollRemainder*/false, LI, SE, DT, AC, ORE,
914 PreserveLCSSA);
908 UnrollLoop(remainderLoop, /*Count*/ Count - 1, /*TripCount*/ Count - 1,
909 /*Force*/ false, /*AllowRuntime*/ false,
910 /*AllowExpensiveTripCount*/ false, /*PreserveCondBr*/ true,
911 /*PreserveOnlyFirst*/ false, /*TripMultiple*/ 1,
912 /*PeelCount*/ 0, /*UnrollRemainder*/ false, LI, SE, DT, AC,
913 /*ORE*/ nullptr, PreserveLCSSA);
915914 }
916915
917916 NumRuntimeUnrolled++;
0 ; RUN: opt < %s -S -loop-unroll -pass-remarks=loop-unroll -unroll-count=16 2>&1 | FileCheck -check-prefix=COMPLETE-UNROLL %s
11 ; RUN: opt < %s -S -loop-unroll -pass-remarks=loop-unroll -unroll-count=4 2>&1 | FileCheck -check-prefix=PARTIAL-UNROLL %s
2 ; 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
23
34 ; COMPLETE-UNROLL: remark: {{.*}}: completely unrolled loop with 16 iterations
45 ; PARTIAL-UNROLL: remark: {{.*}}: unrolled loop by a factor of 4
6 ; RUNTIME-UNROLL: remark: {{.*}}: unrolled loop by a factor of 4
57
68 define i32 @sum() {
79 entry:
2123 ret i32 %add1
2224 }
2325
24 declare i32 @baz(i32)
26 ; RUNTIME-UNROLL-NOT: remark: {{.*}}: completely unrolled loop with 3 iterations
27 ; RUNTIME-UNROLL: remark: {{.*}}: unrolled loop by a factor of 4
28
29 define i32 @runtime(i32 %n) {
30 entry:
31 br label %for.body
32
33 for.body: ; preds = %for.body, %entry
34 %s.06 = phi i32 [ 0, %entry ], [ %add1, %for.body ]
35 %i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
36 %add = add nsw i32 %i.05, 4
37 %call = tail call i32 @baz(i32 %add) #2
38 %add1 = add nsw i32 %call, %s.06
39 %inc = add nsw i32 %i.05, 1
40 %exitcond = icmp eq i32 %inc, %n
41 br i1 %exitcond, label %for.end, label %for.body
42
43 for.end: ; preds = %for.body
44 ret i32 %add1
45 }
46
47 declare i32 @baz(i32)