[llvm] c000b8b - [CSSPGO] Use preinliner decision by default when available

Wenlei He via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 1 23:55:59 PDT 2021


Author: Wenlei He
Date: 2021-09-01T23:45:38-07:00
New Revision: c000b8bd5c1ba981b61d7ec19bd3b02277ce03ec

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

LOG: [CSSPGO] Use preinliner decision by default when available

For CSSPGO, turn on `sample-profile-use-preinliner` by default. This simplifies the use of llvm-profgen preinliner as it's now simply driven by ContextShouldBeInlined flag for each context profile without needing extra compiler switch.

Note that llvm-profgen's preinliner is still off by default, under switch `csspgo-preinliner`.

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

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/SampleProfile.cpp
    llvm/test/Transforms/SampleProfile/csspgo-use-preinliner.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index bb6c15b56a166..2b54c5981d5da 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -1297,13 +1297,12 @@ SampleProfileLoader::shouldInlineCandidate(InlineCandidate &Candidate) {
   // aiming at better context-sensitive post-inline profile quality, assuming
   // all inline decision estimates are going to be honored by compiler. Here
   // we replay that inline decision under `sample-profile-use-preinliner`.
-  if (UsePreInlinerDecision) {
-    if (Candidate.CalleeSamples->getContext().hasAttribute(
-            ContextShouldBeInlined))
-      return InlineCost::getAlways("preinliner");
-    else
-      return InlineCost::getNever("preinliner");
-  }
+  // Note that we don't need to handle negative decision from preinliner as
+  // context profile for not inlined calls are merged by preinliner already.
+  if (UsePreInlinerDecision &&
+      Candidate.CalleeSamples->getContext().hasAttribute(
+          ContextShouldBeInlined))
+    return InlineCost::getAlways("preinliner");
 
   // For old FDO inliner, we inline the call site as long as cost is not
   // "Never". The cost-benefit check is done earlier.
@@ -1827,6 +1826,10 @@ bool SampleProfileLoader::doInitialization(Module &M,
     if (!CallsitePrioritizedInline.getNumOccurrences())
       CallsitePrioritizedInline = true;
 
+    // For CSSPGO, use preinliner decision by default when available.
+    if (!UsePreInlinerDecision.getNumOccurrences())
+      UsePreInlinerDecision = true;
+
     // Enable iterative-BFI by default for CSSPGO.
     if (!UseIterativeBFIInference.getNumOccurrences())
       UseIterativeBFIInference = true;

diff  --git a/llvm/test/Transforms/SampleProfile/csspgo-use-preinliner.ll b/llvm/test/Transforms/SampleProfile/csspgo-use-preinliner.ll
index 180fd8a02c9b4..af3c70111ed05 100644
--- a/llvm/test/Transforms/SampleProfile/csspgo-use-preinliner.ll
+++ b/llvm/test/Transforms/SampleProfile/csspgo-use-preinliner.ll
@@ -8,8 +8,9 @@
 ; DEFAULT-NOT: inlined into
 
 ; PREINLINE-NOT: inlined into
+; PREINLINE: '_Z5funcAi' inlined into 'main'
+; PREINLINE: '_Z8funcLeafi' inlined into 'main'
 ; PREINLINE: '_Z8funcLeafi' inlined into '_Z5funcBi'
-; PREINLINE: '_Z8funcLeafi' inlined into '_Z5funcAi'
 ; PREINLINE-NOT: inlined into
 
 @factor = dso_local global i32 3, align 4, !dbg !0


        


More information about the llvm-commits mailing list