[llvm] [AMDGPU][GlobalISel] Eliminate READANYLANE round trips in mixed build_vector/merge (PR #210449)
Anshil Gandhi via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 20 15:49:16 PDT 2026
================
@@ -3943,27 +3815,24 @@ define amdgpu_kernel void @fadd_fadd_fsub_0(<2 x float> %arg) {
; GFX90A-GISEL-NEXT: s_load_dwordx2 s[0:1], s[4:5], 0x24
; GFX90A-GISEL-NEXT: s_waitcnt lgkmcnt(0)
; GFX90A-GISEL-NEXT: v_pk_add_f32 v[0:1], s[0:1], 0
-; GFX90A-GISEL-NEXT: v_readfirstlane_b32 s2, v1
-; GFX90A-GISEL-NEXT: v_pk_add_f32 v[0:1], s[2:3], 0
-; GFX90A-GISEL-NEXT: v_readfirstlane_b32 s1, v0
-; GFX90A-GISEL-NEXT: v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
-; GFX90A-GISEL-NEXT: flat_store_dwordx2 v[0:1], v[0:1]
+; GFX90A-GISEL-NEXT: v_mov_b32_e32 v0, v1
+; GFX90A-GISEL-NEXT: v_pk_add_f32 v[0:1], v[0:1], 0
+; GFX90A-GISEL-NEXT: v_mov_b32_e32 v2, s0
+; GFX90A-GISEL-NEXT: v_mov_b32_e32 v3, v0
+; GFX90A-GISEL-NEXT: flat_store_dwordx2 v[0:1], v[2:3]
----------------
gandhi56 wrote:
I ran a quick test to determine the cost of performing this transform - VGPR count and occupancy.
I used Cursor to implement a guard which rejects applying this transform to G_Merge instructions with at least one non-VGPR-only use. That is, if one of the uses can be assigned to an SGPR, then SIFoldOperands will most likely re-introduce the ReadAnyLane removed by this transform.
<img width="768" height="113" alt="image" src="https://github.com/user-attachments/assets/336a73f1-3db7-4adf-a2b1-b5d00db58e4a" />
Baseline = commit before this patch
Unguarded = this patch without the VGPROnlyUse guard
Guarded = this patch with the VGPROnlyUse guard
The above data only discards the kernels where no VGPR count increase was observed. Also note that occupancy never changes in the kernels I have tested. On average, this transform reduces 6 instructions at an expense of allocating 1 VGPR (across both guarded and unguarded cases). Furthermore, my implementation of whether or a MachineOperand must be assigned to a VGPR was really naive - I could reimplement this function to better understand the cost, depending on your thoughts.
https://github.com/llvm/llvm-project/pull/210449
More information about the llvm-commits
mailing list