-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[InlineCost] Enable the cost benefit analysis for Sample PGO #66457
Conversation
Enables the cost-benefit-analysis-based inliner by default if we have sample profile.
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-llvm-analysis ChangesEnables the cost-benefit-analysis-based inliner by default if we have sample profile. -- Full diff: https://github.com//pull/66457.diff1 Files Affected:
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index 84dc412a3ab6e18..12c7cb62e799f29 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -787,7 +787,7 @@ class InlineCostCallAnalyzer final : public CallAnalyzer { return false; } else { // Otherwise, require instrumentation profile. - if (!PSI->hasInstrumentationProfile()) + if (!(PSI->hasInstrumentationProfile() || PSI->hasSampleProfile())) return false; } |
Thank you for the patch. Do you have any details you can share? Performance numbers? With sample profiling, a lot of inlining is done in the sample profile loader. Do you you see meaningful inlining opportunities left for |
Given this simple example sample profile file, callee was not inlined when we collected profile file. |
I'll merge it tomorrow if no objection. |
I can't reproduce it on my machine. Let's revert it first.
|
…66457) Enables the cost-benefit-analysis-based inliner by default if we have sample profile. No extra fix is required.
We see a ~1.5% increase in a binary size after this patch. This can push some of our large binaries over certain limits. While I appreciate the potential performance improvements, I also wonder, if we have a way to revert to the old behavior should this be necessary in some cases? |
cost-benefit-analysis should be on for SPGO. Otherwise, the profile file is meaningless for InlinerPass. |
Do you see any perf win on benchmarks and/or real applications? If so, can you share more details? We see some perf regression on our workloads. |
We've seen improvement for our internal workloads. |
I don't fully understand this statement. IIUC, this patch changes how the inlining decisions are made (e.g. use cost-benefit instead of cost-threshold). The profile data is used both in cost-benefit and cost-threshold. Can you share more about the numbers on your internal workloads? such as how much win do you see? and what workloads do you test? |
When we test cost-benefit on our internal workloads, we see 0.4-0.5% regressions on several workloads (e.g. ads services). Even after we tune the related flags (e.g.-inline-savings-multiplier), we still see some gap between cost-benefit vs cost-threshold. While cost-benefit seems reasonable, the effectiveness also depends on other factors such as profile quality. |
It's long time ago. I think its about ~1% gain. |
Yes, profile data is used to update the threshold, which can impact the inlining decision.
It's nice that inliners have different options (e.g. all the inlining flags, and cost-benefit v.s. cost-threshold) to try out. However, the impact of one option depends on many factors. In this particular case, those factors may include profile quality, and implementation details such as |
@HaohaiWen Cost-benefit analysis generally is a better heuristic. but not turning it on by default for sample PGO was intentional. See discussions in https://reviews.llvm.org/D98213
So the conclusion was additional work would be required before we can enable it for sample PGO. But I'm not aware of any progress on these work, so the reasons that led to not enable it by default for sample PGO probably still holds.
Changing default has a high bar. Usually we need performance testing with multiple high confidence positive data before doing it. It doesn't sound like that's the case here. |
If I recall correctly, SampleProfileLoader only try to inline functions which were inlined before SPGO.
SampleProfileLoader will only try to inline B, C to A based on profile data. It will never try to inline D to A. Otherwise we don't need Inliner Pass when enable Sample Profile Loader. As long as prof data of SPGO has similar quality as IPGO, I think it's safe to enable it by default. |
With CSSPGO, SampleProfileLoader can be more than a reply inliner.
Not really. Sample loader inlining has its limitation as it's early in the pipeline so a lot of simplification hasn't happened yet, for that reason sample loader inlining may not be complete. A later inliner (CGSCC or ModuleInliner) helps clean things up more.
This needs to be backed by data. Also it is known that sample PGO has inferior profile quality than IRPGO, so the assumption isn't true.
Yes, the regression is not specific to one service. See comments above from @helloguo There is also concern about code size increase as mentioned by another comment. We'll revert this patch. In general, changing default like this needs to be backed by more data and vetted by stakeholders. |
…le PGO (llvm#66457)" This reverts commit 954979d.
Enables the cost-benefit-analysis-based inliner by default if we have sample profile.