[llvm] Change how branch weight is annotated for direct call (PR #90315)

William Junda Huang via llvm-commits llvm-commits at lists.llvm.org
Thu May 2 15:07:47 PDT 2024


huangjd wrote:

Currently this patch conflicts with 3 existing test cases, because how branch_weight is calculated for direct call was changed. In these test case inputs (and probably other test cases as well) there are several sample entries like the following:

```
 2: 123 callee:10
```
Where there's a single call target and its count is different from sample count. Some examples the call target count is even greater than the sample count, which I think should be invalid data.  Most test inputs seem to be arbitrarily written by hand without validating the data (and if running llvm-profdata on the input itself, then the output would be normalized to different contents.)


There are 3 ways to reconcile the test cases, and I would need some comment on which one makes the most sense.

1.  Apply the patch attached below, which I modified the reference values for these test cases. I am not able to manually calculate the correct value using new branch_weight calculation, but I did verify the new reference values by setting the sample count equal to call target count in the input, and the other way around, which gives the original correct output. This proves the change in output is an expected result of the change in branch_weight calculation.
2. Fix the test inputs so that call target count is equal to sample count. 
3. Further modify the way of determining branch_weight by adding a threshold, only if the sample count value differ from the call target count by more than the threshold percentage, the compiler will consider that sample count is invalid, and override with call target count instead. The threshold here is arbitrary, or it could be tied to an existing parameter in Sample Profile Loader.

[diff.txt](https://github.com/llvm/llvm-project/files/15194433/diff.txt)


https://github.com/llvm/llvm-project/pull/90315


More information about the llvm-commits mailing list