[PATCH] D129551: [SimplifyCFG] Collect non-contiguous block hoist statistics

Momchil Velikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 12 02:54:53 PDT 2022


chill created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
chill requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Count how many times, when hoisting instructions by
`HoistThenElseCodeToIf`, they did not belong to a single
contiguous block.


https://reviews.llvm.org/D129551

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


Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -196,6 +196,9 @@
     "Number of common instruction 'blocks' hoisted up to the begin block");
 STATISTIC(NumHoistCommonInstrs,
           "Number of common instructions hoisted up to the begin block");
+STATISTIC(
+    NumHoistCommonCodeNonContiguous,
+    "Number of non-contiguous common instruction 'blocks' hoisted up to the begin block");
 STATISTIC(NumSinkCommonCode,
           "Number of common instruction 'blocks' sunk down to the end block");
 STATISTIC(NumSinkCommonInstrs,
@@ -1505,12 +1508,6 @@
 
   BasicBlock *BIParent = BI->getParent();
 
-  bool Changed = false;
-
-  auto _ = make_scope_exit([&]() {
-    if (Changed)
-      ++NumHoistCommonCode;
-  });
 
   // Check if only hoisting terminators is allowed. This does not add new
   // instructions to the hoist location.
@@ -1530,7 +1527,11 @@
   // many instructions we skip, serving as a compilation time control as well as
   // preventing excessive increase of life ranges.
   unsigned NumSkipped = 0;
-  
+
+  // Count how many instructions were reordered over other instructions, for
+  // statistics.
+  unsigned NumReordered = 0;
+
   // Record if any non-hoisted instruction contains side-effects, as it could
   // make it illegal to reorder some instructions across.
   bool ForceNoReadMemOrSideEffectsBB1 = false;
@@ -1542,6 +1543,16 @@
   bool ForceNoSpeculationBB1 = false;
   bool ForceNoSpeculationBB2 = false;
 
+  bool Changed = false;
+
+  auto _ = make_scope_exit([&]() {
+    if (Changed) {
+      ++NumHoistCommonCode;
+      if (NumReordered)
+        ++NumHoistCommonCodeNonContiguous;
+    }
+  });
+
   for (;;) {
     // If we are hoisting the terminator instruction, don't move one (making a
     // broken BB), instead clone it, and remove BI.
@@ -1627,6 +1638,8 @@
       }
       Changed = true;
       ++NumHoistCommonInstrs;
+      if (NumSkipped)
+        ++NumReordered;
     } else {
       if (NumSkipped >= HoistCommonSkipLimit)
         return Changed;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129551.443891.patch
Type: text/x-patch
Size: 2175 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220712/200d69e6/attachment.bin>


More information about the llvm-commits mailing list