<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/136276>136276</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [BOLT] Inaccurate profile data check
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            BOLT
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          WangJee
      </td>
    </tr>
</table>

<pre>
    I was tring to use llvm-bolt to optimize MySQL on RISCV64, get the following warning:
BOLT-WARNING: 4411 (38.5% of all profiled) functions have invalid (possibly stale) profile. Use -report-stale to see the list.
BOLT-WARNING: 2811567572 out of 5787240884 samples in the binary (48.6%) belong to functions with invalid (possibly stale) profile.

The profile data:
1 _ZL18fsp_fill_free_listbP11fil_space_tPhP5mtr_t/1  326  1 _Z23fsp_is_system_temporaryj 0 0 11

The basic block:
.Ltmp531:
    00000322:   lw      a0, 0x18(s4)
    00000326:   auipc   ra, _Z23fsp_is_system_temporaryj
    0000032a:   jalr    -0x160(ra) # handler: 0; action: 0 # Offset: 810
    0000032e:   bnez    a0, .Ltmp530 # Offset: 814

The error is caused by the fact that when acquiring the profile data, the instruction at offset 0x326 is PseudoCALL, but when performing profile verification, PseudoCALL is converted to AUIPC and jalr instructions, and the offset obtained is 0x32a; therefore, the profile data is considered invalid.

<img width="547" alt="Image" src="https://github.com/user-attachments/assets/d7dea31d-904a-4860-9308-e87a021ada96" />
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVEuv2zYT_TX0ZmCDDz0XXtzrxB_8wU1u82iAboyRNLKYUKJKUnacX19QcnBv0iKoNjaHcw7PPNF7fR6Itix9ZOmrFU6hs277CYfz_4lWlW1u2wNc0UNwejhDsDB5AmMu_bqyJkSDHYPu9TeC327vfz-CHeDd4f3ujyxhcgdnChA6gtYaY6-R4opu0MOZqQfGHx7fHj-sPz28e3N48z-mHiBJhAAmC1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