From: Philip Reames Date: Thu, 27 Jun 2019 19:22:43 +0000 (+0000) Subject: Update -analyze -scalar-evolution output for multiple exit loops w/computable exit... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27daa20eac6629e2f48432c7dc3ffc5fd1a472e9;p=llvm Update -analyze -scalar-evolution output for multiple exit loops w/computable exit values The previous output was next to useless if *any* exit was not computable. If we have more than one exit, show the exit count for each so that it's easier to see what's going from with SCEV analysis when debugging. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364579 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 0a87a084644..a66e609e4ee 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -11417,19 +11417,23 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE, L->getHeader()->printAsOperand(OS, /*PrintType=*/false); OS << ": "; - SmallVector ExitBlocks; - L->getExitBlocks(ExitBlocks); - if (ExitBlocks.size() != 1) + SmallVector ExitingBlocks; + L->getExitingBlocks(ExitingBlocks); + if (ExitingBlocks.size() != 1) OS << " "; - if (SE->hasLoopInvariantBackedgeTakenCount(L)) { - OS << "backedge-taken count is " << *SE->getBackedgeTakenCount(L); - } else { - OS << "Unpredictable backedge-taken count. "; - } + if (SE->hasLoopInvariantBackedgeTakenCount(L)) + OS << "backedge-taken count is " << *SE->getBackedgeTakenCount(L) << "\n"; + else + OS << "Unpredictable backedge-taken count.\n"; - OS << "\n" - "Loop "; + if (ExitingBlocks.size() > 1) + for (BasicBlock *ExitingBlock : ExitingBlocks) { + OS << " exit count for " << ExitingBlock->getName() << ": " + << *SE->getExitCount(L, ExitingBlock) << "\n"; + } + + OS << "Loop "; L->getHeader()->printAsOperand(OS, /*PrintType=*/false); OS << ": "; diff --git a/test/Analysis/ScalarEvolution/trip-count14.ll b/test/Analysis/ScalarEvolution/trip-count14.ll index 15080613881..711939bc112 100644 --- a/test/Analysis/ScalarEvolution/trip-count14.ll +++ b/test/Analysis/ScalarEvolution/trip-count14.ll @@ -82,6 +82,8 @@ if.end: ; CHECK-LABEL: Determining loop execution counts for: @s32_max2_unpredictable_exit ; CHECK-NEXT: Loop %do.body: backedge-taken count is (((-1 * %n) + ((2 + %n) smax %n)) umin ((-1 * %n) + %x)) +; CHECK-NEXT: exit count for do.body: ((-1 * %n) + %x) +; CHECK-NEXT: exit count for if.end: ((-1 * %n) + ((2 + %n) smax %n)) ; CHECK-NEXT: Loop %do.body: max backedge-taken count is 2{{$}} do.end: @@ -170,6 +172,8 @@ if.end: ; CHECK-LABEL: Determining loop execution counts for: @u32_max2_unpredictable_exit ; CHECK-NEXT: Loop %do.body: backedge-taken count is (((-1 * %n) + ((2 + %n) umax %n)) umin ((-1 * %n) + %x)) +; CHECK-NEXT: exit count for do.body: ((-1 * %n) + %x) +; CHECK-NEXT: exit count for if.end: ((-1 * %n) + ((2 + %n) umax %n)) ; CHECK-NEXT: Loop %do.body: max backedge-taken count is 2{{$}} do.end: