[PATCH] D153797: [CSSPGO][Preinliner] Bump up the threshold to favor previous compiler inline decision.

Hongtao Yu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 26 11:51:35 PDT 2023


hoy created this revision.
Herald added subscribers: wlei, modimo, wenlei.
Herald added a project: All.
hoy requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The compiler has more insight and knowledge about functions based on their IR and attribures and should make a better inline decision than the offline preinliner does which is purely based on callsites hotness and code size.  Therefore I'm making changes to favor previous compiler inline decision by bumping up the callsite allowance.

This should improve the performance by more than 1% according to testing on Meta services.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153797

Files:
  llvm/tools/llvm-profgen/CSPreInliner.cpp


Index: llvm/tools/llvm-profgen/CSPreInliner.cpp
===================================================================
--- llvm/tools/llvm-profgen/CSPreInliner.cpp
+++ llvm/tools/llvm-profgen/CSPreInliner.cpp
@@ -153,11 +153,12 @@
 }
 
 bool CSPreInliner::shouldInline(ProfiledInlineCandidate &Candidate) {
+  bool WasInlined =
+      Candidate.CalleeSamples->getContext().hasAttribute(ContextWasInlined);
   // If replay inline is requested, simply follow the inline decision of the
   // profiled binary.
   if (SamplePreInlineReplay)
-    return Candidate.CalleeSamples->getContext().hasAttribute(
-        ContextWasInlined);
+    return WasInlined;
 
   unsigned int SampleThreshold = SampleColdCallSiteThreshold;
   uint64_t ColdCountThreshold = ProfileSummaryBuilder::getColdCountThreshold(
@@ -184,6 +185,9 @@
     // want any inlining for cold callsites.
     SampleThreshold = SampleHotCallSiteThreshold * NormalizedHotness * 100 +
                       SampleColdCallSiteThreshold + 1;
+    // Bump up the threshold to favor previous compiler inline decision.
+    if (WasInlined)
+      SampleThreshold *= 100;
   }
 
   return (Candidate.SizeCost < SampleThreshold);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153797.534681.patch
Type: text/x-patch
Size: 1178 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230626/29108eb2/attachment.bin>


More information about the llvm-commits mailing list