[PATCH] D154637: [SamplePGO] Fix ICE that callee samples returns null while finding import functions

Wenlei He via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 7 10:41:36 PDT 2023


wenlei added inline comments.


================
Comment at: llvm/lib/Transforms/IPO/SampleProfile.cpp:1085-1086
     if (!Samples) {
       InlinedGUIDs.insert(
           FunctionSamples::getGUID(CB->getCalledFunction()->getName()));
       return;
----------------
hoy wrote:
> wenlei wrote:
> > hoy wrote:
> > > wenlei wrote:
> > > > wlei wrote:
> > > > > wlei wrote:
> > > > > > wenlei wrote:
> > > > > > > If it's not beneficial to inline/import (i.e. `getExternalInlineAdvisorShouldInline` returns false), should we just return without adding the callee to import candidate GUID set?
> > > > > > Good question.
> > > > > > I'm just reading the code of `getExternalInlineAdvisorShouldInline `, it looks to me `getExternalInlineAdvisorShouldInline ` return false doesn't mean `it's not beneficial to inlining/import`, it's only for replay, which is an uncommon situation, so most of time it return false, we still continue the importing.
> > > > > > Say if we ignore the branch(line 1078), the question becomes : should we import a callee whose samples is null?
> > > > > > 
> > > > > > This actually didn't happen before, that's why there is an assertion. OK. but as this is an assertion, it seems it just means we shouldn't import it.
> > > > > > 
> > > > > > so the change can be simplified to change the assertion to a return, WDYT?
> > > > > > 
> > > > > > @hoy  I remember we discussed offline, you suggested to import it, otherwise it would miss the inlining opportunity for this call in post-link.
> > > > > > 
> > > > > > Also the below logic for non-null samples is to import the hot callee, since this is exposed by stale profile, so if the new function is hot, we have to import it.. but we don't know if the new function is hot or not...
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > Say `bar` is just renamed to `baz`, we actually need to analyze `bar`'s samples to decide the import lists, but it's a function renaming matching which is a big topic.
> > > > Lei, I think you're right. Before replay inline was added (D112033), there was only this assertion. I think it makes sense to just return when Samples is null instead of assert non-null, with the explanation of the case we ran into. This should be really rare, so perf wise it probably won't matter import or not. 
> > > Importing it is probably not that beneficial but it matches the behavior of in-module inlining.
> > > it matches the behavior of in-module inlining. 
> > 
> > Being in the inline candidate queue doesn't mean it will be inlined if it's not external. It only means it will be evaluated. The actual inline decision is in tryInlineCandidate->shouldInlineCandidate (for direct call), and at this point there is no guarantee that it would be inlined if it's not external.
> Right, importing just offers an opportunity for it to be inlined. Both in-module and external inlining have to go through the inliner's cost model once the IR is ready.
I was just confused by what you meant "matches the behavior of in-module inlining".

For local functions, it's available, and we evaluate every function calls. For external functions, we can't possibly make all functions available like local functions, so we have to choose to import those that are likely to be inlined based on hotness. 

If we import everything regardless of hotness, that would "matches the behavior of in-module inlining", but that's not practical, and not what we do today. 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154637/new/

https://reviews.llvm.org/D154637



More information about the llvm-commits mailing list