diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp --- a/llvm/lib/Transforms/IPO/SampleProfile.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp @@ -1308,13 +1308,12 @@ // 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. @@ -1838,6 +1837,10 @@ 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 --- 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