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

    <tr>
        <th>Summary</th>
        <td>
            [RISCV] Missed macrofusion due to bad register allocation
        </td>
    </tr>

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

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

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

<pre>
    LUI+ADDI macrofusion depends on the LUI instruction and the ADDI instruction writing to the same register. But register allocation may not guarantee this. The LUI may get assigned a register from allocation order while the ADDI gets assigned a register based on a constraint from a later instruction. Or the ADDI could have to pick a register to avoid the LUI register being clobbered before the ADDI result is used.

Here's a simple example where fusion fails https://godbolt.org/z/5bxz5W73T

cc: @preames @wangpc-pp 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsUk1vnDwQ_jXmMgoCA8ty4LB5V6t3pVSV2qQ9j-1ZcGsw8phskl9fQbfZbZULBsbzfMw8yGy7kagV1b2o9gnOsfehjX6aKOhEefPaPjwdhbzf7fdHGFAHf5rZ-hEMTTQaBj9C7Akeno5gR45h1nEp42jW_2vfbeEcbLRjB9GvdcaBIFBnOVJI4X6O71-AznmNa9eArzD6CN2MAcdIBLG3nMLjhXqpdxThYsgAXmFOwQ-3WD4YCnDuraOrxI4if9itkMksLhG0X3ygHeMFExwuV27spfA5XEG1n52BHp9psTtZ_fMWOXrAZ2_N-_yunLRMSDuvFAUyoOjkw43YQDy7CJZhZjKpyPYi2_1-_k-BhKwZENgOkyOgF1zPc0-B4LK9E1rH0Mc4sSh2Qh6EPHTeKO9i6kMn5OFNyEOlXt6q73XxeMugtSh2IMpsCoQD8fJ6xrGb9N00QWLawjRFgwm1eZ2Vstrm2zLpW0VlKXNqirzATWNy3Ui1yXW-VcVpaxqZ2FZmsszyrMiqrMjKtKzzfCOprqhoyo0iUWY0oHWpc8_DojKxzDO19aaum8ShIsd_ghza5dKdmjsWZeYsR762RRvdGvkvx6__fRPVHj5ZXrb8V77ndWkKzUeBTObg2n_GZ2M_q1T7QcjDwnU57qbgf5COQh5WvSzkYZX8KwAA__93lS1T">