This is an archive of the discontinued LLVM Phabricator instance.

[InlineCost] Simplify the cold attribute handling in inline-cost.
AcceptedPublic

Authored by chandlerc on Aug 14 2017, 5:07 PM.

Details

Reviewers
eraman
davidxl
Summary

The inline cost analysis used the cold attribute but only when
ProfileSummaryInfo was available even though that attribute isn't part
of the profile info for the module and is independently available.

This patch lifts the check up into the generic cold callsite detection
logic as for *cold* functions, we routinely treat *all* call sites as
cold. In fact, we shape the probabilities and frequencies this way if
there is any CFG, but sometimes (such as single-basic-block functions)
there isn't any CFG that can exhibit this. Moreover, it seems much
simpler and direct to just query for the cold attribute and be done with
it, skipping all of the probability queries.

This also simplifies what is necessary to write a test using the cold
attribute as now you don't have to remember to run the
profile-summary-info analysis in the new PM. I spent quite some time
confused because I didn't have that analysis around.

Also remove the redundant thresholds between the two ways of detecting
cold calls. Originally there was some concern that we would want to tune
these thresholds independently but so far no such need has arisen and it
is easy enough to add back in. I'd rather have the simpler system in the
interim that is also easier to understand and reason about.

This should be essentially a no-op for most users of LLVM, but will
result in an API simplification and a test simplification.

Event Timeline

chandlerc created this revision.Aug 14 2017, 5:07 PM
davidxl added inline comments.Aug 14 2017, 5:30 PM
lib/Analysis/InlineCost.cpp
659

IIRC, static branch prediction already handles this case. Do you see missing cases?

chandlerc added inline comments.Aug 14 2017, 5:35 PM
lib/Analysis/InlineCost.cpp
659

Sorry, I tried to explain in my top-level description -- there are cases where despite being cold, the call site won't be cold relative to the function entry. For example, when the call site is *in* the function entry block.

Maybe this still isn't making sense? I can add an example bit of code.

davidxl added inline comments.Aug 14 2017, 6:14 PM
lib/Analysis/InlineCost.cpp
659

There is an inconsistency between cold callsite relative freq and the cold branch probability --- it is 6% vs 2%. I think we should fix one of them -- IMO, it is more reasonable to fix the static branch prediction.

chandlerc added inline comments.Aug 14 2017, 6:19 PM
lib/Analysis/InlineCost.cpp
659

Sure? I don't have strong feelings about that. But it seems like that is orthogonal? (Or am I missing something?)

Before this patch, if the branch probability check below failed, we would continue onward and ask PSI and it would still say the call is cold based on this attribute. (I think...)

davidxl added inline comments.Aug 14 2017, 6:26 PM
lib/Analysis/InlineCost.cpp
659

See my comment to the other patch. My point is what we should not rely this special hand shaking to do this. The generic attribute propagation should already kick in to mark certain callers of a cold callee as cold, and the BFI of the caller's caller should be already good enough to detect this.

chandlerc added inline comments.Aug 14 2017, 6:29 PM
lib/Analysis/InlineCost.cpp
659

Ok, let's discuss that on that patch.

This patch is *just* trying to cleanup the APIs to make them easier to understand and write tests against. It's just simplifying things and doesn't introduce any significant changes to behavior (that I'm aware of).... Regardless of what we do with the other patch I think this makes the code better?

davidxl added inline comments.Aug 14 2017, 6:35 PM
lib/Analysis/InlineCost.cpp
659

What you said makes sense in some way. However it feels wrong. If we allow the special handling of cold attribute here, what prevents other special logics from being duplicated here as well --- for instance, EH code, unreachable code, etc .. ?

chandlerc added inline comments.Aug 14 2017, 6:42 PM
lib/Analysis/InlineCost.cpp
659

All of those have control flow around them which would exhibit the coldness in the BFI analysis, so I don't know why would need them...

The key to me is that it may be useful to change inlining behavior of a cold call even if there is no control flow guarding that callsite.

But all of this seems a discussion around reconsidering the *original* introduction of the logic to check the cold attribute in the ProfileSummaryInfo analysis that was added in r271728 which you reviewed in D20648. I'm fine if you want to revisit the decision to check this attribute, but this patch just moves it around, so I don't know why we should block a cleanup on that...

eraman edited edge metadata.Aug 14 2017, 7:17 PM

LGTM. Not handling the cold attribute was an oversight and when the callee is marked cold, it makes sense to treat all its callsites as cold (therefore reasonable to handle in isColdCallsite). I also agree with collapsing the two similar params with the same value until we see a need to have different default values for them.

davidxl accepted this revision.Aug 14 2017, 8:26 PM

convinced.

lgtm

This revision is now accepted and ready to land.Aug 14 2017, 8:26 PM