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

    <tr>
        <th>Summary</th>
        <td>
            AMDGPU backend: range is set incorrectly for mbcnt instructions
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    According to the GCN / RDNA ISA documentation, the `v_mbcnt_lo` and `v_mbcnt_hi` instructions can have a source which is added to the result. The LLVM AMDGPU backend disregards this and always sets the range of these instructions as if their upper bound was the wave size, however this is incorrect when the addition is used because it can then exceed this range.

The problematic line of code is this: https://github.com/llvm/llvm-project/blob/25af3af/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp#L4601

This causes false assumptions when the instruction is used with arbitrary addition, resulting in buggy code being compiled.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVUk1v2zAM_TX2hZjh-GvJwYeswYoCaTGsW68FJTO2NkUyJDlZ9utH2WjaHAcINkXx471HCttd2q2U1nXK9BAshIHg_u4JkuIrfN89beHheQudldORTMCgrEmKuzkqafLT61FIE1615Qug6T46BxWdyvjgJhkTPUg0MOCJAMHbyUmC86DkAMoDdh11bwAc-UmHDH6wvd-_PML2cXf_7ScIlL-Ju3TKO-rRdZ7DYzL7UJ_x4sFT8EsNND2BPcSLp1sc6EHND8rBNI7kQNiJa5xxyT1HjF79pch1sGc6ccjcKR7DcjmSgcGTmeMZvIqV4_PkmYcgiVPsGmbOIQbSH0mRYiwzg8uSfJfk2-UbqY7OCk1HVlmCVmZGL21HsWxMS8otDCGM0eD58OlVGCaRSXvki9ant98nLvWLIfJVaCv4V9R4KPHwIUxF9w90PcWwReGr8fBMes_EHa9FJscxKcp91eSrW8gqjpR5ejigZrro_XQcF42v4nxQ_qrPmXEDOqGCQ3e56hflXmYft1EZEFPfXxYNBEUfMx2Vpi5Lu7bsNuUG06CCpvZ2Q6JSywKoeSXeh6YvcLAO5hW9WYp0crr9b3UVMybPRl3Xm3U6tNWhyjdNIxtc1yURCkHlZ1HLqlrndYV5qlGQ9m1Sf0mKwtAZ5hJsJ_UuVW2RF0VerzbFqiyqPFtV3bopGtHIg8RqjUmV84IonUUcmXV96toZEivl-VErH_z7Iw9E9YZobsf1cQqDde0LGTradO7czsj_AWShX3g">