As probably most people know already, there are intrinsics that one can use
to influence the weight of a branch, like __builtin_expect() . I assumed that using
such intrinsics “just works” in LLVM. For example, let’s say that a branch surrounds a function
call. If the branch is cold, I assumed the inliner would probably not inline that. OTOH, if it’s
hot, it probably will.
However, by looking at the code, it seems that at least for “canonical” cases, these
weights do not impact at all the inliner. When I say “canonical” case, I mean e.g.,
a branch surrounding a function call and we put a __builtin_expect() in its condition.
More specifically, the place that I think such an intrinsic would impact the
inliner is here . If we look at the code of isColdSite() ,
we’ll see that it either needs ProfileSummaryInfo (PSI) or BlockFrequencyInfo
(BFI). PSI is not available because we don’t have any profile (i.e. when __builtin_expect()
is lowered, it just puts a “branch_weights” MD in the branch, it doesn’t create any kind of
What is weirder is that we don’t have BFI either, which, when I put it myself, solved the problem.
We don’t have it because of here . GetBFI is just passed as nullptr and I’m not sure why. It
seems to me it’d help.
Does anybody have any idea about any of that ? Do I use __builtin_expect() incorrectly ?
Is GetBFI supposed to be passed as nullptr?