[llvm] [InstrProf] Support conditional counter updates for integer counters (PR #109222)

Alan Zhao via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 19 13:00:30 PDT 2024


alanzhao1 wrote:

I'm going to close this as I just realized this won't work.

Say for example we have

```cpp
foo() // counter 0

if (...)
  bar(); // counter 1
else;
  baz(); // counter 0 - 1
```

Clang doesn't insert counters for each branch of an `if` statement - it only inserts a counter for one branch (in this case, `bar()`) and infers the coverage of the second branch by subtracting the counter for the first branch from the counter of the preceding basic block. Therefore, if we apply any cap to the counter values, and `foo()`, `bar()`, and `baz()` are all called, the coverage report will incorrectly report that `baz()` was never called because counter 0 (with a value of 1) - counter 1 (also with a value of 1) = 0.

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


More information about the llvm-commits mailing list