[PATCH] D145212: Only split cold blocks with more than a given number of instructions

Daniel Hoekwater via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 6 14:28:44 PST 2023


dhoekwater created this revision.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
dhoekwater retitled this revision from "Only split cold blocks with more than a given number of instructions." to "Only split cold blocks with more than a given number of instructions".
dhoekwater published this revision for review.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

On Arm, splitting a cold block may incur a thunk, a 16-byte snippet of code
that extends the range of an unconditional branch. Consequently, splitting
the block may actually inflate cold code size and hurt performance.

While thunk-aware splitting is a complex problem, only splitting cold blocks
larger than a thunk will get some wins without the risk of regression.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145212

Files:
  llvm/lib/CodeGen/MachineFunctionSplitter.cpp


Index: llvm/lib/CodeGen/MachineFunctionSplitter.cpp
===================================================================
--- llvm/lib/CodeGen/MachineFunctionSplitter.cpp
+++ llvm/lib/CodeGen/MachineFunctionSplitter.cpp
@@ -59,6 +59,12 @@
         "Minimum number of times a block must be executed to be retained."),
     cl::init(1), cl::Hidden);
 
+static cl::opt<unsigned>
+    ColdSizeThreshold("mfs-size-threshold",
+                      cl::desc("Maximum number of instructions a cold block "
+                               "may have and still be retained."),
+                      cl::init(0), cl::Hidden);
+
 static cl::opt<bool> SplitAllEHCode(
     "mfs-split-ehcode",
     cl::desc("Splits all EH code and it's descendants by default."),
@@ -97,6 +103,9 @@
 static bool isColdBlock(const MachineBasicBlock &MBB,
                         const MachineBlockFrequencyInfo *MBFI,
                         ProfileSummaryInfo *PSI) {
+  if (MBB.size() <= ColdSizeThreshold)
+    return false;
+
   std::optional<uint64_t> Count = MBFI->getBlockProfileCount(&MBB);
   if (!Count)
     return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145212.502043.patch
Type: text/x-patch
Size: 1103 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230306/c9e49ff7/attachment.bin>


More information about the llvm-commits mailing list