<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/133912>133912</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
fdebug-info-for-profiling flag unexpectedly affects code generation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
debuginfo
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jmorse
</td>
</tr>
</table>
<pre>
Here's a godbolt link showing a difference in codegen produced by `-fdebug-info-for-profiling`: https://godbolt.org/z/sx8TEdPcb . An extra/spurious `xor` appears with the flag, and the identity of one of the functions changes. As far as I'm aware, `-fdebug-info-for-profiling` is intended to affect only the production of debugging information, not the generation of code to make it more amenable to debugging or profiling, which would make this a bug.
The (heavily reduced sorry) reproducer, for completeness:
```
struct str {
str(char *);
};
using str2 = str;
struct foo {
foo(str2);
};
struct bar {
struct fail : foo {
char msg;
fail() : foo(&msg) {}
};
void clear() { fail(); }
};
struct baz : bar {
void set(bool) { clear(); }
};
baz operator<<(baz _a, char) { _a.set(0); }
```
I dug into why this happens, and it comes in three stages:
* The Inliner has an [`EnableDeferral` flag](https://github.com/llvm/llvm-project/blob/08dda4dcbf6427e357830d9c7f7ac3b422fc75f6/llvm/lib/Analysis/InlineAdvisor.cpp#L422) that makes the inliner less aggressive for certain static functions, so that they're small enough to be entirely inlined and eliminated from a file,
* This flag is enabled during pass-construction [if PGO options are enabled](https://github.com/llvm/llvm-project/blob/2044dd07da99714bbeb801bafe6dd5179493fd48/llvm/lib/Passes/PassBuilderPipelines.cpp#L939)
* PGO options are enabled if `-fdebug-info-for-profiling` [is enabled](https://github.com/llvm/llvm-project/blob/f137c3d592e96330e450a8fd63ef7e8877fc1908/clang/lib/CodeGen/BackendUtil.cpp#L870)
Thus, through a chain of decisions, we end up with different inlining choices because of debugging information. The most suspicious to me is the last, enabling PGO options if profiling debug-info is desired. This was added in c76a27e3257c54948df7fa969042d to ensure that the add-discriminator pass was enabled with the `-fdebug-info-for-profiling`. I would imagine that we need to directly write that logic somewhere, rather than using PGOOptions as a proxy.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVs2O4zgOfhrlQlTgyE5sH3JIVU16G1ig6zB7HtASZWtakQxJrlTm6Re0na7q7W00FjtAgNgW-VEkP_5gSrb3REexfxT75w1OeQjx-OclxESbLujb8R8UScg6AUIfdBdcBmf9V0hDuFrfA4K2xlAkrwisBxU09eRhjEFPijR0NxCH4sFo6qb-wXoTHkyID2MMxjrre3EoRHmCIecxifIk5FnI82pqG2Iv5PkvIc_prfn9N_2iOtjCyQO95Yj8eZyiDVNiG28hikMBOI6EMcHV5gHyQGAc9kI-AXo9v1tNPtt8g2AgeOK_WWzyKtvgE6gBfU9pC3BKYDACJvgsZH0BvCKH4-mXLoFNYH0mr0lDDoDGkMoQvLvNxpbwsDk2PwP1HE4GixfkAzbjQ57Fe_IU8S7OMWbQC34lsBkuIRLghTx2bj54xwsR3q8ln-A6WDXANUxOL-p5sJzbbuq3ojiJ4vT7QCBkMxC-WneDSEsaU4jxJmQLkdbURsYzIYIKl9FRJk9pzuAMw2ldfsUp5TipDClHEPWjKE7Az0I2asAIQp6EbEXJB6J-Xh6mxLdPOUoQ5fMsPn9foUwI36BMCEI2LPojzCre4XeWZwS0Dph4H6Dm61xSv-gCwCwlZMN-r7Lz24GF-Fv9yKZY9ptJgNdgNShHGO-q9eMHJFE-wqL14zX_ms18vO4MligL2XQhuDvcB_j_gsdAYWTGhCjKJ_7Jhj_-gZw09vMO9AduF_Tie6gP6RPF6TPoicmZA1yH20KagQvNp3tl2cxEIKY95CESQcrY08oIzjIwtT57Zz1FGDABeuDGcyh-m5n7TIZiRMflM9fs_pmJ-H1jsHmYuq0KFyHPzr3e_7j4_iSVhTx3LnRCnotGa6y06syhkjWV-7opC92q2tSoyq6S0qh6bw4fcCzrnTy6W7JJyPNy15N-tSnErRpHIct_VpJ5BnnAPFdQWnrK6pajlAD7PlJK9pWW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