<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/74563>74563</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Something wrong in PGOInstrumentationGen pass
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hungryzzz
</td>
</tr>
</table>
<pre>
## Description
Hi, I set the `-fprofile-generate` option to enable the `PGOInstrumentationGen` pass and collect the function counts when execution.
But I find that a function whose profiling count is zero will be invoked during execution, I think maybe there is something wrong in `PGOInstrumentationGen` pass.
## Steps to reproduce
```bash
clang++ -fprofile-generate -O2 bubble_sort.cpp -o bubble
LLVM_PROFILE_FILE=default.profraw ./bubble
llvm-profdata merge -output=default.profdata *.profraw
llvm-profdata show --counts --function=_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1Ev ./default.profdata
```
The result of `llvm-profdata show` is as follows, it shows that the total counts is zero which indicates that the function `_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1Ev` will not be executed.
```
Counters:
_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1Ev:
Hash: 0x07df0bf914dbeae5
Counters: 4
Block counts: [0, 0, 0, 0]
Instrumentation level: IR entry_first = 0
Functions shown: 1
Total functions: 9
Maximum function count: 795760
Maximum internal block count: 31829604240
```
Then I use `gdb` to debug it, and find that the function `_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1Ev ` will be entered.
```bash
bash-4.4$ gdb -q ./bubble
Reading symbols from ./bubble...(no debugging symbols found)...done.
(gdb) r _ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1Ev
Starting program: /export/users/zengruiy/xmain/test-input/mbfi/bubble _ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1Ev
Missing separate debuginfos, use: yum debuginfo-install glibc-2.28-151.el8.x86_64
iteration = 0
Bubble sorting array of 40000 elements
duration= 2.000000 ms
[Inferior 1 (process 3713690) exited normally]
Missing separate debuginfos, use: yum debuginfo-install libgcc-8.4.1-1.el8.x86_64 libstdc++-8.4.1-1.el8.x86_64
(gdb) quit
bash-4.4$ gdb -q ./bubble
Reading symbols from ./bubble...(no debugging symbols found)...done.
(gdb) b _ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1Ev
Breakpoint 1 at 0x18e0
(gdb) r
Starting program: /export/users/zengruiy/xmain/test-input/mbfi/bubble
Missing separate debuginfos, use: yum debuginfo-install glibc-2.28-151.el8.x86_64
/export/users/zengruiy/xmain/test-input/mbfi/bubble iteration(ex. 20). Will use default iteration(20)
iteration = 20
Bubble sorting array of 40000 elements
Breakpoint 1, 0x00007ffff7b34fb0 in std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream() () from /lib64/libstdc++.so.6
Missing separate debuginfos, use: yum debuginfo-install libgcc-8.4.1-1.el8.x86_64 libstdc++-8.4.1-1.el8.x86_64
```
## Environment
- llvm version: 06c5c27e44757e4917f7d7c995720ae8a2d3b1f9 (release)
- kernel version: 4.18.0-305.el8.x86_64
The test case is attached here.
[case.zip](https://github.com/llvm/llvm-project/files/13577063/case.zip)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMV0tv4zgS_jX0pSCBop4--BB34hkD3duDzmIX2EtAiSWJG4r0kFRi59cvKPmVx2LQ3Rigg0BKVF8V6_FVkeTOyU4jrki-Jvntgo--N3bVj7qzh5eXl0VtxGFFWEpYCrfoGit3XhpN6C2hN_Pzd0nYJ9iCQw--RyAFjdqdNa1UGHWo0XKPpKBgJlXwBlDzWuEJ_cdvX7faeTsOqD0PmN9QB4Uddw64FtAYpbCZzbejbiY7jRm1d_DcowbcYzOGr_G1Z-vRwxZaqQX4nnvgF-Xn3jiE2Uupu9kYSAcvaA08S6WgRpD6yTyiADHaADqvMgfse6kfYeCHegrFYtB3ZsAg6ODZGt2B1H8Z4iufj7m-97hzIVUWd9aIscGjuKDzb81dP39qFNcdYWvC1vA-8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