[llvm] 5cbcaf1 - [CSSPGO][Preinliner] Bump up the threshold to favor previous compiler inline decision.

Hongtao Yu via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 26 17:21:29 PDT 2023


Author: Hongtao Yu
Date: 2023-06-26T17:21:22-07:00
New Revision: 5cbcaf1678709e4da8b32f075a5c9a3cab028965

URL: https://github.com/llvm/llvm-project/commit/5cbcaf1678709e4da8b32f075a5c9a3cab028965
DIFF: https://github.com/llvm/llvm-project/commit/5cbcaf1678709e4da8b32f075a5c9a3cab028965.diff

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

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.

Reviewed By: wenlei

Differential Revision: https://reviews.llvm.org/D153797

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-profgen/CSPreInliner.cpp b/llvm/tools/llvm-profgen/CSPreInliner.cpp
index f0433865da449..ae0fd6d0b0692 100644
--- a/llvm/tools/llvm-profgen/CSPreInliner.cpp
+++ b/llvm/tools/llvm-profgen/CSPreInliner.cpp
@@ -57,6 +57,12 @@ static cl::opt<bool> SamplePreInlineReplay(
     cl::desc(
         "Replay previous inlining and adjust context profile accordingly"));
 
+static cl::opt<int> CSPreinlMultiplierForPrevInl(
+    "csspgo-preinliner-multiplier-for-previous-inlining", cl::Hidden,
+    cl::init(100),
+    cl::desc(
+        "Multiplier to bump up callsite threshold for previous inlining."));
+
 CSPreInliner::CSPreInliner(SampleContextTracker &Tracker,
                            ProfiledBinary &Binary, ProfileSummary *Summary)
     : UseContextCost(UseContextCostForPreInliner),
@@ -153,11 +159,12 @@ uint32_t CSPreInliner::getFuncSize(const ContextTrieNode *ContextNode) {
 }
 
 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 +191,12 @@ bool CSPreInliner::shouldInline(ProfiledInlineCandidate &Candidate) {
     // want any inlining for cold callsites.
     SampleThreshold = SampleHotCallSiteThreshold * NormalizedHotness * 100 +
                       SampleColdCallSiteThreshold + 1;
+    // Bump up the threshold to favor previous compiler inline decision. The
+    // compiler has more insight and knowledge about functions based on their IR
+    // and attribures and should be able to make a more reasonable inline
+    // decision.
+    if (WasInlined)
+      SampleThreshold *= CSPreinlMultiplierForPrevInl;
   }
 
   return (Candidate.SizeCost < SampleThreshold);


        


More information about the llvm-commits mailing list