[llvm] r364579 - Update -analyze -scalar-evolution output for multiple exit loops w/computable exit values

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 27 12:22:43 PDT 2019


Author: reames
Date: Thu Jun 27 12:22:43 2019
New Revision: 364579

URL: http://llvm.org/viewvc/llvm-project?rev=364579&view=rev
Log:
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.


Modified:
    llvm/trunk/lib/Analysis/ScalarEvolution.cpp
    llvm/trunk/test/Analysis/ScalarEvolution/trip-count14.ll

Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=364579&r1=364578&r2=364579&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Thu Jun 27 12:22:43 2019
@@ -11417,19 +11417,23 @@ static void PrintLoopInfo(raw_ostream &O
   L->getHeader()->printAsOperand(OS, /*PrintType=*/false);
   OS << ": ";
 
-  SmallVector<BasicBlock *, 8> ExitBlocks;
-  L->getExitBlocks(ExitBlocks);
-  if (ExitBlocks.size() != 1)
+  SmallVector<BasicBlock *, 8> ExitingBlocks;
+  L->getExitingBlocks(ExitingBlocks);
+  if (ExitingBlocks.size() != 1)
     OS << "<multiple exits> ";
 
-  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 << ": ";
 

Modified: llvm/trunk/test/Analysis/ScalarEvolution/trip-count14.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/trip-count14.ll?rev=364579&r1=364578&r2=364579&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/trip-count14.ll (original)
+++ llvm/trunk/test/Analysis/ScalarEvolution/trip-count14.ll Thu Jun 27 12:22:43 2019
@@ -82,6 +82,8 @@ if.end:
 
 ; CHECK-LABEL: Determining loop execution counts for: @s32_max2_unpredictable_exit
 ; CHECK-NEXT: Loop %do.body: <multiple exits> 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: <multiple exits> 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:




More information about the llvm-commits mailing list