[llvm] 3fc1def - [NFC][SimplifyCFG] SinkCommonCodeFromPredecessors(): count number of instruction "blocks" actually sunk

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 15 14:22:31 PDT 2020


Author: Roman Lebedev
Date: 2020-07-16T00:21:56+03:00
New Revision: 3fc1defc0b28d9b0ac8917629716181c0ac8df07

URL: https://github.com/llvm/llvm-project/commit/3fc1defc0b28d9b0ac8917629716181c0ac8df07
DIFF: https://github.com/llvm/llvm-project/commit/3fc1defc0b28d9b0ac8917629716181c0ac8df07.diff

LOG: [NFC][SimplifyCFG] SinkCommonCodeFromPredecessors(): count number of instruction "blocks" actually sunk

Out of all the times the function was called,
how many times did we actually sink anything?

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 58995c4f3bc9..a1483537afd7 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -147,6 +147,8 @@ STATISTIC(
     NumLookupTablesHoles,
     "Number of switch instructions turned into lookup tables (holes checked)");
 STATISTIC(NumTableCmpReuses, "Number of reused switch table lookup compares");
+STATISTIC(NumSinkCommonCode,
+          "Number of common instruction 'blocks' sunk down to the end block");
 STATISTIC(NumSinkCommonInstrs,
           "Number of common instructions sunk down to the end block");
 STATISTIC(NumSpeculations, "Number of speculative executed instructions");
@@ -1880,7 +1882,8 @@ static bool SinkCommonCodeFromPredecessors(BasicBlock *BB) {
   // sink presuming a later value will also be sunk, but stop half way through
   // and never actually sink it which means we produce more PHIs than intended.
   // This is unlikely in practice though.
-  for (unsigned SinkIdx = 0; SinkIdx != ScanIdx; ++SinkIdx) {
+  unsigned SinkIdx = 0;
+  for (; SinkIdx != ScanIdx; ++SinkIdx) {
     LLVM_DEBUG(dbgs() << "SINK: Sink: "
                       << *UnconditionalPreds[0]->getTerminator()->getPrevNode()
                       << "\n");
@@ -1899,11 +1902,14 @@ static bool SinkCommonCodeFromPredecessors(BasicBlock *BB) {
       LLVM_DEBUG(
           dbgs()
           << "SINK: stopping here, failed to actually sink instruction!\n");
-      return Changed;
+      break;
     }
+
     NumSinkCommonInstrs++;
     Changed = true;
   }
+  if (SinkIdx != 0)
+    ++NumSinkCommonCode;
   return Changed;
 }
 


        


More information about the llvm-commits mailing list