[PATCH] D129397: [BOLT] Do not merge cold and hot chains of basic blocks

Sergey Pupyrev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 11 06:55:04 PDT 2022


spupyrev updated this revision to Diff 443625.
spupyrev edited the summary of this revision.
spupyrev added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129397/new/

https://reviews.llvm.org/D129397

Files:
  bolt/lib/Passes/ExtTSPReorderAlgorithm.cpp


Index: bolt/lib/Passes/ExtTSPReorderAlgorithm.cpp
===================================================================
--- bolt/lib/Passes/ExtTSPReorderAlgorithm.cpp
+++ bolt/lib/Passes/ExtTSPReorderAlgorithm.cpp
@@ -642,20 +642,25 @@
     }
   }
 
-  /// Merge cold blocks to reduce code size
+  /// Merge remaining blocks into chains w/o taking jump counts into
+  /// consideration. This allows to maintain the original block order in the
+  /// absense of profile data
   void mergeColdChains() {
     for (BinaryBasicBlock *SrcBB : BF.layout()) {
       // Iterating in reverse order to make sure original fallthrough jumps are
-      // merged first
+      // merged first; this might be beneficial for code size.
       for (auto Itr = SrcBB->succ_rbegin(); Itr != SrcBB->succ_rend(); ++Itr) {
         BinaryBasicBlock *DstBB = *Itr;
         size_t SrcIndex = SrcBB->getLayoutIndex();
         size_t DstIndex = DstBB->getLayoutIndex();
         Chain *SrcChain = AllBlocks[SrcIndex].CurChain;
         Chain *DstChain = AllBlocks[DstIndex].CurChain;
+        bool IsColdSrc = SrcChain->executionCount() == 0;
+        bool IsColdDst = DstChain->executionCount() == 0;
         if (SrcChain != DstChain && !DstChain->isEntryPoint() &&
             SrcChain->blocks().back()->Index == SrcIndex &&
-            DstChain->blocks().front()->Index == DstIndex)
+            DstChain->blocks().front()->Index == DstIndex &&
+            IsColdSrc == IsColdDst)
           mergeChains(SrcChain, DstChain, 0, MergeTypeTy::X_Y);
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129397.443625.patch
Type: text/x-patch
Size: 1544 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220711/5b4aabc0/attachment.bin>


More information about the llvm-commits mailing list