<div dir="ltr">Hi everyone,<div><br></div><div>As probably most people know already, there are intrinsics that one can use</div><div>to influence the weight of a branch, like __builtin_expect() [1]. I assumed that using</div><div>such intrinsics "just works" in LLVM. For example, let's say that a branch surrounds a function</div><div>call. If the branch is cold, I assumed the inliner would probably not inline that. OTOH, if it's</div><div>hot, it probably will.</div><div><br></div><div>However, by looking at the code, it seems that at least for "canonical" cases, these</div><div>weights do not impact at all the inliner. When I say "canonical" case, I mean e.g.,</div><div>a branch surrounding a function call and we put a __builtin_expect() in its condition.</div><div><br></div><div>More specifically, the place that I think such an intrinsic would impact the</div><div>inliner is here [2]. If we look at the code of isColdSite() [3],</div><div>we'll see that it either needs ProfileSummaryInfo (PSI) or BlockFrequencyInfo</div><div>(BFI). PSI is not available because we don't have any profile (i.e. when __builtin_expect()</div><div>is lowered, it just puts a "branch_weights" MD in the branch, it doesn't create any kind of</div><div>artificial profile).</div><div><br></div><div>What is weirder is that we don't have BFI either, which, when I put it myself, solved the problem.</div><div>We don't have it because of here [4]. GetBFI is just passed as nullptr and I'm not sure why. It</div><div>seems to me it'd help.</div><div><br></div><div>Does anybody have any idea about any of that ? Do I use __builtin_expect() incorrectly ?</div><div>Is GetBFI supposed to be passed as nullptr?</div><div><br></div><div>Thanks,</div><div>Stefanos</div><div><br></div><div>[1] <a href="https://llvm.org/docs/BranchWeightMetadata.html">https://llvm.org/docs/BranchWeightMetadata.html</a></div><div>[2] <a href="https://github.com/llvm/llvm-project/blob/42652c1d6e21345173f5dd971cd453520aa5a7ef/llvm/lib/Analysis/InlineCost.cpp#L1550">https://github.com/llvm/llvm-project/blob/42652c1d6e21345173f5dd971cd453520aa5a7ef/llvm/lib/Analysis/InlineCost.cpp#L1550</a></div><div>[3] <a href="https://github.com/llvm/llvm-project/blob/42652c1d6e21345173f5dd971cd453520aa5a7ef/llvm/lib/Analysis/InlineCost.cpp#L1422">https://github.com/llvm/llvm-project/blob/42652c1d6e21345173f5dd971cd453520aa5a7ef/llvm/lib/Analysis/InlineCost.cpp#L1422</a></div><div>[4] <a href="https://github.com/llvm/llvm-project/blob/42652c1d6e21345173f5dd971cd453520aa5a7ef/llvm/lib/Transforms/IPO/InlineSimple.cpp#L71">https://github.com/llvm/llvm-project/blob/42652c1d6e21345173f5dd971cd453520aa5a7ef/llvm/lib/Transforms/IPO/InlineSimple.cpp#L71</a><br></div></div>