llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

AMDGPU should try to shrink 64-bit defs to 32-bit when rematerializing

Open arsenm opened this issue 1 year ago • 3 comments

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

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.

arsenm avatar Feb 25 '25 13:02 arsenm

@llvm/issue-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

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.
</details>

llvmbot avatar Feb 25 '25 13:02 llvmbot

I don't think the reMaterialize hook has enough context to see the uses here.

@arsenm do you recall what you meant by this, in particular the uses?

bababuck avatar Apr 21 '25 22:04 bababuck

I don't think the reMaterialize hook has enough context to see the uses here.

@arsenm do you recall what you meant by this, in particular the uses?

Like the context use instruction. TargetInstrInfo::reMaterialize sees the register and a subregister and where to insert the instruction, but it doesn't know what instruction(s) are reading the rematerialized value

arsenm avatar Apr 23 '25 11:04 arsenm