llvm / llvm/llvm-project

[SPGO][DebugInfo] Incorrect profile counts for tail call

Open
#172,873 1 comment 0 reactions 0 assignees View on GitHub
debuginfo PGO
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

When using SPGO, sometimes a single instruction correlates to multiple lines of the original program, but debug information can only represent one location. For example, a tail call represents both a call and a return, so in this example:

```c
#include
#include

void func(uint64_t i) {
if (i % 2 != 0) return;

printf("Hello\n");
}
```
compiled with `-O3 -fdebug-info-for-profiling` ([Compiler Explorer link](https://godbolt.org/z/GcsoW3GE3))

the exit block at line 8 is only recorded when the early return is taken, which executes an explicit return instruction pointing to line 8. When the tail call is executed, it also implicitly returns but the instruction is associated with the printf call. This leads to the exit block being undercounted by 50% when a profile is collected and loaded.

This is similar to #172872 but more difficult to solve, since that issue can be resolved using a copy ID, but in this case there is no place to store the association at all without extending debug info or affecting codegen.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.