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

    <tr>
        <th>Summary</th>
        <td>
            AMDGPU should try to shrink 64-bit defs to 32-bit when rematerializing
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AMDGPU,
            llvm:regalloc,
            missed-optimization
      </td>
    </tr>

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

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

<pre>
     If we are rematerializing a wide instruction, we should try harder to rewrite it to set the minimal set of required lanes at the use point. In the most basic case, this means folding a use of s_mov_b64:
```
  %0:sreg_64 = S_MOV_B64 0
   
  // Should rematerialize here to undef %0.sub0 = S_MOV_B32 0
  S_NOP 0, implicit %0.sub0
```

[0001-WIP-AMDGPU-Fold-64-bit-moves-into-32-bit-when-materi.patch](https://github.com/user-attachments/files/18965526/0001-WIP-AMDGPU-Fold-64-bit-moves-into-32-bit-when-materi.patch)


Attaching WIP patch to start investigation. I'm not sure the starting point is useful, we try something similar already for scalar loads but I don't think the reMaterialize hook has enough context to see the uses here.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyklM1u5DYMx59GvhA2bPljMgcfnA2mmEO6AYJ2jwPZom02sjQV5UmzT1_InnaDPfRSwIAgmhTJP3-SYqbJIraifhT1U6LWMDvfKs9ol6R3-qOF8wjvCMojeFxUQE_K0HeyEyh4J41AloNfh0DOCvklOvPsVqMh-A-YldfoITjw-O4pIFCIO8YAYUZYyNKizLZ3I3j8cyWPGoyyyKB2p5URro5syOBs9zDHAXrFNMCgGGPeMBPDgsoyjM7ovcAY6Ubgy-Jul76pRNmJvBNNfv_yDkDIOhdlxx6nS1OBKJ_g9fL89ffLY1PB7gJ3x5OQJ3jdu_usBsKMHmNfq9U4bkdmvPb559NKeT_t9fLr1xfIY9G0XA0NFH5E_FRe_OrHPM-L9Nv5Je2en355-S09OaPTpkp7Cunibsgp2eDSUm6W9xltuheXXVUYZlE_Cfkwh3DlKMDWxkRhXvtscIuQp5XRpyoENcwL2sBCnkYyGNfi4djUtWyEPP3fKuTx3lDedVuuOKNv5xfYfm9UBOUDkL0hB5pURCqDs5CHBawLwGsUecbdL0ZvVABxHPS4mjt_ETx2C4YtA9NCRnlQxqPSHzA6DzyoaDJOaYZ-DXAGHfE9RODIvm1ZPD5_nrBzbzArBrRunWYYnA341x1m_IdT3kjIEt2W-lgeVYJtcajy6lg0dZPMrSwOY4EVaq11UR4K-aCrQj5U46E69LLOE2plLutcyroo66poMiyPKHU9SNXIXKIWVY6LIpMZc1sy56eEmFdsC_lwKJrEqB4Nbxdayl4Nb2i1KLt9ZEJKIb8IKWOsKDuPkzLGDf_aF2JGnbproIW-q_1Oy_g0-DbGpP06sahyQxz4RwWBgsF2z_H59kdtZh_13DEBjSNH684IREZ-flaS1Zv2P1jdSt-X9OrdHzgEIU-bBhuvuwy3Vv4dAAD__5qkk-s">