Repository navigation
[AMDGPU] Keep soft waitcnts unchanged until SIInsertWaitcnts converges - #244689
Conversation
|
@llvm/pr-subscribers-backend-amdgpu @llvm/pr-subscribers-llvm-globalisel Author: Pablo Reble (reble) ChangesOn the first visit to a loop header, a soft waitcnt whose gfx950 runtime reproducer: 20/20 launches read stale LDS before, 0/20 after. Other test changes: in 14 tests the wait moves past meta instructions (emitted code unchanged), and Depends on #244686. Fixes: LCOMPILER-3291 Patch is 100.39 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/244689.diff 17 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
index 754a0e10a7ce68..197d9fb184e90d 100644
--- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
@@ -1782,16 +1782,17 @@ bool WaitcntGeneratorPreGFX12::applyPreexistingWaitcnt(
}
Wait = Wait.combined(OldWait);
- // Merge consecutive waitcnt of the same type by erasing multiples.
- if (WaitcntInstr) {
+ if (TrySimplify) {
+ // What a soft wait needs depends on the incoming state, which can
+ // still grow through a loop back edge. Keep it unchanged so later
+ // visits see the original request, let a hard wait carry what is
+ // needed now, and erase the soft wait once the fixpoint is reached.
+ DeferredErasures.insert(&II);
+ } else if (WaitcntInstr) {
+ // Merge consecutive waitcnt of the same type by erasing multiples.
DeferredErasures.erase(&II);
II.eraseFromParent();
Modified = true;
- } else if (!Wait.hasWaitExceptStoreCnt() && TrySimplify) {
- // Might or might not be redundant, depending on if there's a loop
- // carried dependency. Stash it away so we can erase it if nothing saves
- // it.
- DeferredErasures.insert(&II);
} else {
WaitcntInstr = ⅈ
DeferredErasures.erase(&II);
@@ -1828,13 +1829,13 @@ bool WaitcntGeneratorPreGFX12::applyPreexistingWaitcnt(
Wait.set(AMDGPU::STORE_CNT,
std::min(Wait.get(AMDGPU::STORE_CNT), OldVSCnt));
- if (WaitcntVsCntInstr) {
+ if (TrySimplify) {
+ // See the S_WAITCNT case above.
+ DeferredErasures.insert(&II);
+ } else if (WaitcntVsCntInstr) {
DeferredErasures.erase(&II);
II.eraseFromParent();
Modified = true;
- } else if (!Wait.hasWaitStoreCnt() && TrySimplify) {
- // Loop-carried dependencies guard, see S_WAITCNT case above.
- DeferredErasures.insert(&II);
} else {
WaitcntVsCntInstr = ⅈ
DeferredErasures.erase(&II);
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/flat-scratch.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/flat-scratch.ll
index c728f0c80515e2..31ace364c4a9f2 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/flat-scratch.ll
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/flat-scratch.ll
@@ -871,8 +871,8 @@ define amdgpu_kernel void @store_load_vindex_small_offset_kernel(i32 %n) {
; GFX10-NEXT: v_lshlrev_b32_e32 v1, 2, v1
; GFX10-NEXT: v_add_nc_u32_e32 v0, 0x100, v0
; GFX10-NEXT: scratch_store_dword v0, v2, off offset:128
-; GFX10-NEXT: s_waitcnt_vscnt null, 0x0
; GFX10-NEXT: s_waitcnt lgkmcnt(0)
+; GFX10-NEXT: s_waitcnt_vscnt null, 0x0
; GFX10-NEXT: s_lshl_b32 s0, s0, 7
; GFX10-NEXT: s_add_u32 s0, 0x100, s0
; GFX10-NEXT: v_add_nc_u32_e32 v1, s0, v1
@@ -912,8 +912,8 @@ define amdgpu_kernel void @store_load_vindex_small_offset_kernel(i32 %n) {
; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_4) | instid1(SALU_CYCLE_1)
; GFX11-NEXT: v_lshlrev_b32_e32 v1, 2, v1
; GFX11-NEXT: scratch_store_b32 v0, v2, off offset:384 dlc
-; GFX11-NEXT: s_waitcnt_vscnt null, 0x0
; GFX11-NEXT: s_waitcnt lgkmcnt(0)
+; GFX11-NEXT: s_waitcnt_vscnt null, 0x0
; GFX11-NEXT: s_lshl_b32 s0, s0, 7
; GFX11-NEXT: s_add_u32 s0, 0x100, s0
; GFX11-NEXT: s_delay_alu instid0(SALU_CYCLE_1)
@@ -980,8 +980,8 @@ define amdgpu_kernel void @store_load_vindex_small_offset_kernel(i32 %n) {
; UNALIGNED_GFX10-NEXT: v_lshlrev_b32_e32 v1, 2, v1
; UNALIGNED_GFX10-NEXT: v_add_nc_u32_e32 v0, 0x100, v0
; UNALIGNED_GFX10-NEXT: scratch_store_dword v0, v2, off offset:128
-; UNALIGNED_GFX10-NEXT: s_waitcnt_vscnt null, 0x0
; UNALIGNED_GFX10-NEXT: s_waitcnt lgkmcnt(0)
+; UNALIGNED_GFX10-NEXT: s_waitcnt_vscnt null, 0x0
; UNALIGNED_GFX10-NEXT: s_lshl_b32 s0, s0, 7
; UNALIGNED_GFX10-NEXT: s_add_u32 s0, 0x100, s0
; UNALIGNED_GFX10-NEXT: v_add_nc_u32_e32 v1, s0, v1
@@ -1021,8 +1021,8 @@ define amdgpu_kernel void @store_load_vindex_small_offset_kernel(i32 %n) {
; UNALIGNED_GFX11-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_4) | instid1(SALU_CYCLE_1)
; UNALIGNED_GFX11-NEXT: v_lshlrev_b32_e32 v1, 2, v1
; UNALIGNED_GFX11-NEXT: scratch_store_b32 v0, v2, off offset:384 dlc
-; UNALIGNED_GFX11-NEXT: s_waitcnt_vscnt null, 0x0
; UNALIGNED_GFX11-NEXT: s_waitcnt lgkmcnt(0)
+; UNALIGNED_GFX11-NEXT: s_waitcnt_vscnt null, 0x0
; UNALIGNED_GFX11-NEXT: s_lshl_b32 s0, s0, 7
; UNALIGNED_GFX11-NEXT: s_add_u32 s0, 0x100, s0
; UNALIGNED_GFX11-NEXT: s_delay_alu instid0(SALU_CYCLE_1)
@@ -1507,8 +1507,8 @@ define amdgpu_kernel void @store_load_vindex_large_offset_kernel(i32 %n) {
; GFX10-NEXT: v_lshlrev_b32_e32 v1, 2, v1
; GFX10-NEXT: v_add_nc_u32_e32 v0, 0x4004, v0
; GFX10-NEXT: scratch_store_dword v0, v2, off offset:128
-; GFX10-NEXT: s_waitcnt_vscnt null, 0x0
; GFX10-NEXT: s_waitcnt lgkmcnt(0)
+; GFX10-NEXT: s_waitcnt_vscnt null, 0x0
; GFX10-NEXT: s_lshl_b32 s0, s0, 7
; GFX10-NEXT: s_add_u32 s0, 0x4004, s0
; GFX10-NEXT: v_add_nc_u32_e32 v1, s0, v1
@@ -1618,8 +1618,8 @@ define amdgpu_kernel void @store_load_vindex_large_offset_kernel(i32 %n) {
; UNALIGNED_GFX10-NEXT: v_lshlrev_b32_e32 v1, 2, v1
; UNALIGNED_GFX10-NEXT: v_add_nc_u32_e32 v0, 0x4004, v0
; UNALIGNED_GFX10-NEXT: scratch_store_dword v0, v2, off offset:128
-; UNALIGNED_GFX10-NEXT: s_waitcnt_vscnt null, 0x0
; UNALIGNED_GFX10-NEXT: s_waitcnt lgkmcnt(0)
+; UNALIGNED_GFX10-NEXT: s_waitcnt_vscnt null, 0x0
; UNALIGNED_GFX10-NEXT: s_lshl_b32 s0, s0, 7
; UNALIGNED_GFX10-NEXT: s_add_u32 s0, 0x4004, s0
; UNALIGNED_GFX10-NEXT: v_add_nc_u32_e32 v1, s0, v1
@@ -2588,8 +2588,8 @@ define void @store_load_i64_unaligned(ptr addrspace(5) nocapture %arg) {
; UNALIGNED_GFX9-NEXT: scratch_store_byte v0, v1, off offset:7
; UNALIGNED_GFX9-NEXT: s_waitcnt vmcnt(0)
; UNALIGNED_GFX9-NEXT: scratch_load_ubyte v1, v0, off glc
-; UNALIGNED_GFX9-NEXT: s_waitcnt vmcnt(0)
; UNALIGNED_GFX9-NEXT: ; kill: killed $vgpr0
+; UNALIGNED_GFX9-NEXT: s_waitcnt vmcnt(0)
; UNALIGNED_GFX9-NEXT: scratch_load_ubyte v1, v0, off offset:1 glc
; UNALIGNED_GFX9-NEXT: s_waitcnt vmcnt(0)
; UNALIGNED_GFX9-NEXT: scratch_load_ubyte v1, v0, off offset:2 glc
@@ -2667,8 +2667,8 @@ define void @store_load_i64_unaligned(ptr addrspace(5) nocapture %arg) {
; UNALIGNED_GFX942-NEXT: scratch_store_byte v0, v1, off offset:7 sc0 sc1
; UNALIGNED_GFX942-NEXT: s_waitcnt vmcnt(0)
; UNALIGNED_GFX942-NEXT: scratch_load_ubyte v1, v0, off sc0 sc1
-; UNALIGNED_GFX942-NEXT: s_waitcnt vmcnt(0)
; UNALIGNED_GFX942-NEXT: ; kill: killed $vgpr0
+; UNALIGNED_GFX942-NEXT: s_waitcnt vmcnt(0)
; UNALIGNED_GFX942-NEXT: scratch_load_ubyte v1, v0, off offset:1 sc0 sc1
; UNALIGNED_GFX942-NEXT: s_waitcnt vmcnt(0)
; UNALIGNED_GFX942-NEXT: scratch_load_ubyte v1, v0, off offset:2 sc0 sc1
@@ -2882,8 +2882,8 @@ define void @store_load_v3i32_unaligned(ptr addrspace(5) nocapture %arg) {
; UNALIGNED_GFX9-NEXT: scratch_store_byte v0, v1, off offset:11
; UNALIGNED_GFX9-NEXT: s_waitcnt vmcnt(0)
; UNALIGNED_GFX9-NEXT: scratch_load_ubyte v1, v0, off glc
-; UNALIGNED_GFX9-NEXT: s_waitcnt vmcnt(0)
; UNALIGNED_GFX9-NEXT: ; kill: killed $vgpr0
+; UNALIGNED_GFX9-NEXT: s_waitcnt vmcnt(0)
; UNALIGNED_GFX9-NEXT: scratch_load_ubyte v1, v0, off offset:1 glc
; UNALIGNED_GFX9-NEXT: s_waitcnt vmcnt(0)
; UNALIGNED_GFX9-NEXT: scratch_load_ubyte v1, v0, off offset:2 glc
@@ -2997,8 +2997,8 @@ define void @store_load_v3i32_unaligned(ptr addrspace(5) nocapture %arg) {
; UNALIGNED_GFX942-NEXT: scratch_store_byte v0, v1, off offset:11 sc0 sc1
; UNALIGNED_GFX942-NEXT: s_waitcnt vmcnt(0)
; UNALIGNED_GFX942-NEXT: scratch_load_ubyte v1, v0, off sc0 sc1
-; UNALIGNED_GFX942-NEXT: s_waitcnt vmcnt(0)
; UNALIGNED_GFX942-NEXT: ; kill: killed $vgpr0
+; UNALIGNED_GFX942-NEXT: s_waitcnt vmcnt(0)
; UNALIGNED_GFX942-NEXT: scratch_load_ubyte v1, v0, off offset:1 sc0 sc1
; UNALIGNED_GFX942-NEXT: s_waitcnt vmcnt(0)
; UNALIGNED_GFX942-NEXT: scratch_load_ubyte v1, v0, off offset:2 sc0 sc1
diff --git a/llvm/test/CodeGen/AMDGPU/a-v-flat-atomicrmw.ll b/llvm/test/CodeGen/AMDGPU/a-v-flat-atomicrmw.ll
index 6525309e8d42fd..e9650aceb5f547 100644
--- a/llvm/test/CodeGen/AMDGPU/a-v-flat-atomicrmw.ll
+++ b/llvm/test/CodeGen/AMDGPU/a-v-flat-atomicrmw.ll
@@ -6437,8 +6437,8 @@ define void @flat_atomic_add_i64_ret_a_a(ptr %ptr) #0 {
; GFX90A-NEXT: s_cbranch_execz .LBB89_2
; GFX90A-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX90A-NEXT: flat_atomic_add_x2 v[0:1], v[0:1], v[2:3] glc
-; GFX90A-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX90A-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX90A-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX90A-NEXT: v_accvgpr_write_b32 a0, v0
; GFX90A-NEXT: v_accvgpr_write_b32 a1, v1
; GFX90A-NEXT: ; implicit-def: $vgpr0_vgpr1
@@ -6484,8 +6484,8 @@ define void @flat_atomic_add_i64_ret_a_a(ptr %ptr) #0 {
; GFX950-NEXT: s_cbranch_execz .LBB89_2
; GFX950-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX950-NEXT: flat_atomic_add_x2 v[0:1], v[0:1], v[2:3] sc0
-; GFX950-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX950-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX950-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX950-NEXT: v_accvgpr_write_b32 a0, v0
; GFX950-NEXT: v_accvgpr_write_b32 a1, v1
; GFX950-NEXT: ; implicit-def: $vgpr0_vgpr1
@@ -6533,9 +6533,9 @@ define void @flat_atomic_add_i64_ret_av_av(ptr %ptr) #0 {
; GFX90A-NEXT: s_cbranch_execz .LBB90_2
; GFX90A-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX90A-NEXT: flat_atomic_add_x2 v[0:1], v[4:5], v[2:3] glc
-; GFX90A-NEXT: s_waitcnt lgkmcnt(0)
; GFX90A-NEXT: ; implicit-def: $vgpr4_vgpr5
; GFX90A-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX90A-NEXT: s_waitcnt lgkmcnt(0)
; GFX90A-NEXT: .LBB90_2: ; %Flow
; GFX90A-NEXT: s_andn2_saveexec_b64 s[4:5], s[4:5]
; GFX90A-NEXT: s_cbranch_execz .LBB90_4
@@ -6573,9 +6573,9 @@ define void @flat_atomic_add_i64_ret_av_av(ptr %ptr) #0 {
; GFX950-NEXT: s_cbranch_execz .LBB90_2
; GFX950-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX950-NEXT: flat_atomic_add_x2 v[0:1], v[2:3], v[4:5] sc0
-; GFX950-NEXT: s_waitcnt lgkmcnt(0)
; GFX950-NEXT: ; implicit-def: $vgpr2_vgpr3
; GFX950-NEXT: ; implicit-def: $vgpr4_vgpr5
+; GFX950-NEXT: s_waitcnt lgkmcnt(0)
; GFX950-NEXT: .LBB90_2: ; %Flow
; GFX950-NEXT: s_andn2_saveexec_b64 s[0:1], s[0:1]
; GFX950-NEXT: s_cbranch_execz .LBB90_4
@@ -6620,8 +6620,8 @@ define void @flat_atomic_sub_i64_ret_a_a(ptr %ptr) #0 {
; GFX90A-NEXT: s_cbranch_execz .LBB91_2
; GFX90A-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX90A-NEXT: flat_atomic_sub_x2 v[0:1], v[0:1], v[2:3] glc
-; GFX90A-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX90A-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX90A-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX90A-NEXT: v_accvgpr_write_b32 a0, v0
; GFX90A-NEXT: v_accvgpr_write_b32 a1, v1
; GFX90A-NEXT: ; implicit-def: $vgpr0_vgpr1
@@ -6667,8 +6667,8 @@ define void @flat_atomic_sub_i64_ret_a_a(ptr %ptr) #0 {
; GFX950-NEXT: s_cbranch_execz .LBB91_2
; GFX950-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX950-NEXT: flat_atomic_sub_x2 v[0:1], v[0:1], v[2:3] sc0
-; GFX950-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX950-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX950-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX950-NEXT: v_accvgpr_write_b32 a0, v0
; GFX950-NEXT: v_accvgpr_write_b32 a1, v1
; GFX950-NEXT: ; implicit-def: $vgpr0_vgpr1
@@ -6718,9 +6718,9 @@ define void @flat_atomic_sub_i64_ret_av_av(ptr %ptr) #0 {
; GFX90A-NEXT: s_cbranch_execz .LBB92_2
; GFX90A-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX90A-NEXT: flat_atomic_sub_x2 v[0:1], v[4:5], v[2:3] glc
-; GFX90A-NEXT: s_waitcnt lgkmcnt(0)
; GFX90A-NEXT: ; implicit-def: $vgpr4_vgpr5
; GFX90A-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX90A-NEXT: s_waitcnt lgkmcnt(0)
; GFX90A-NEXT: .LBB92_2: ; %Flow
; GFX90A-NEXT: s_andn2_saveexec_b64 s[4:5], s[4:5]
; GFX90A-NEXT: s_cbranch_execz .LBB92_4
@@ -6758,9 +6758,9 @@ define void @flat_atomic_sub_i64_ret_av_av(ptr %ptr) #0 {
; GFX950-NEXT: s_cbranch_execz .LBB92_2
; GFX950-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX950-NEXT: flat_atomic_sub_x2 v[0:1], v[4:5], v[2:3] sc0
-; GFX950-NEXT: s_waitcnt lgkmcnt(0)
; GFX950-NEXT: ; implicit-def: $vgpr4_vgpr5
; GFX950-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX950-NEXT: s_waitcnt lgkmcnt(0)
; GFX950-NEXT: .LBB92_2: ; %Flow
; GFX950-NEXT: s_andn2_saveexec_b64 s[0:1], s[0:1]
; GFX950-NEXT: s_cbranch_execz .LBB92_4
@@ -6807,8 +6807,8 @@ define void @flat_atomic_and_i64_ret_a_a(ptr %ptr) #0 {
; GFX90A-NEXT: s_cbranch_execz .LBB93_2
; GFX90A-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX90A-NEXT: flat_atomic_and_x2 v[0:1], v[0:1], v[2:3] glc
-; GFX90A-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX90A-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX90A-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX90A-NEXT: v_accvgpr_write_b32 a0, v0
; GFX90A-NEXT: v_accvgpr_write_b32 a1, v1
; GFX90A-NEXT: ; implicit-def: $vgpr0_vgpr1
@@ -6854,8 +6854,8 @@ define void @flat_atomic_and_i64_ret_a_a(ptr %ptr) #0 {
; GFX950-NEXT: s_cbranch_execz .LBB93_2
; GFX950-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX950-NEXT: flat_atomic_and_x2 v[0:1], v[0:1], v[2:3] sc0
-; GFX950-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX950-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX950-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX950-NEXT: v_accvgpr_write_b32 a0, v0
; GFX950-NEXT: v_accvgpr_write_b32 a1, v1
; GFX950-NEXT: ; implicit-def: $vgpr0_vgpr1
@@ -6904,9 +6904,9 @@ define void @flat_atomic_and_i64_ret_av_av(ptr %ptr) #0 {
; GFX90A-NEXT: s_cbranch_execz .LBB94_2
; GFX90A-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX90A-NEXT: flat_atomic_and_x2 v[0:1], v[4:5], v[2:3] glc
-; GFX90A-NEXT: s_waitcnt lgkmcnt(0)
; GFX90A-NEXT: ; implicit-def: $vgpr4_vgpr5
; GFX90A-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX90A-NEXT: s_waitcnt lgkmcnt(0)
; GFX90A-NEXT: .LBB94_2: ; %Flow
; GFX90A-NEXT: s_andn2_saveexec_b64 s[4:5], s[4:5]
; GFX90A-NEXT: s_cbranch_execz .LBB94_4
@@ -6944,9 +6944,9 @@ define void @flat_atomic_and_i64_ret_av_av(ptr %ptr) #0 {
; GFX950-NEXT: s_cbranch_execz .LBB94_2
; GFX950-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX950-NEXT: flat_atomic_and_x2 v[0:1], v[4:5], v[2:3] sc0
-; GFX950-NEXT: s_waitcnt lgkmcnt(0)
; GFX950-NEXT: ; implicit-def: $vgpr4_vgpr5
; GFX950-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX950-NEXT: s_waitcnt lgkmcnt(0)
; GFX950-NEXT: .LBB94_2: ; %Flow
; GFX950-NEXT: s_andn2_saveexec_b64 s[0:1], s[0:1]
; GFX950-NEXT: s_cbranch_execz .LBB94_4
@@ -7252,8 +7252,8 @@ define void @flat_atomic_or_i64_ret_a_a(ptr %ptr) #0 {
; GFX90A-NEXT: s_cbranch_execz .LBB97_2
; GFX90A-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX90A-NEXT: flat_atomic_or_x2 v[0:1], v[0:1], v[2:3] glc
-; GFX90A-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX90A-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX90A-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX90A-NEXT: v_accvgpr_write_b32 a0, v0
; GFX90A-NEXT: v_accvgpr_write_b32 a1, v1
; GFX90A-NEXT: ; implicit-def: $vgpr0_vgpr1
@@ -7299,8 +7299,8 @@ define void @flat_atomic_or_i64_ret_a_a(ptr %ptr) #0 {
; GFX950-NEXT: s_cbranch_execz .LBB97_2
; GFX950-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX950-NEXT: flat_atomic_or_x2 v[0:1], v[0:1], v[2:3] sc0
-; GFX950-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX950-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX950-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX950-NEXT: v_accvgpr_write_b32 a0, v0
; GFX950-NEXT: v_accvgpr_write_b32 a1, v1
; GFX950-NEXT: ; implicit-def: $vgpr0_vgpr1
@@ -7349,9 +7349,9 @@ define void @flat_atomic_or_i64_ret_av_av(ptr %ptr) #0 {
; GFX90A-NEXT: s_cbranch_execz .LBB98_2
; GFX90A-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX90A-NEXT: flat_atomic_or_x2 v[0:1], v[4:5], v[2:3] glc
-; GFX90A-NEXT: s_waitcnt lgkmcnt(0)
; GFX90A-NEXT: ; implicit-def: $vgpr4_vgpr5
; GFX90A-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX90A-NEXT: s_waitcnt lgkmcnt(0)
; GFX90A-NEXT: .LBB98_2: ; %Flow
; GFX90A-NEXT: s_andn2_saveexec_b64 s[4:5], s[4:5]
; GFX90A-NEXT: s_cbranch_execz .LBB98_4
@@ -7389,9 +7389,9 @@ define void @flat_atomic_or_i64_ret_av_av(ptr %ptr) #0 {
; GFX950-NEXT: s_cbranch_execz .LBB98_2
; GFX950-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX950-NEXT: flat_atomic_or_x2 v[0:1], v[4:5], v[2:3] sc0
-; GFX950-NEXT: s_waitcnt lgkmcnt(0)
; GFX950-NEXT: ; implicit-def: $vgpr4_vgpr5
; GFX950-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX950-NEXT: s_waitcnt lgkmcnt(0)
; GFX950-NEXT: .LBB98_2: ; %Flow
; GFX950-NEXT: s_andn2_saveexec_b64 s[0:1], s[0:1]
; GFX950-NEXT: s_cbranch_execz .LBB98_4
@@ -7437,8 +7437,8 @@ define void @flat_atomic_max_i64_ret_a_a(ptr %ptr) #0 {
; GFX90A-NEXT: s_cbranch_execz .LBB99_2
; GFX90A-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX90A-NEXT: flat_atomic_smax_x2 v[0:1], v[2:3], v[0:1] glc
-; GFX90A-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX90A-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX90A-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX90A-NEXT: v_accvgpr_write_b32 a0, v0
; GFX90A-NEXT: v_accvgpr_write_b32 a1, v1
; GFX90A-NEXT: ; implicit-def: $vgpr0_vgpr1
@@ -7484,8 +7484,8 @@ define void @flat_atomic_max_i64_ret_a_a(ptr %ptr) #0 {
; GFX950-NEXT: s_cbranch_execz .LBB99_2
; GFX950-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX950-NEXT: flat_atomic_smax_x2 v[0:1], v[2:3], v[0:1] sc0
-; GFX950-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX950-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX950-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX950-NEXT: v_accvgpr_write_b32 a0, v0
; GFX950-NEXT: v_accvgpr_write_b32 a1, v1
; GFX950-NEXT: ; implicit-def: $vgpr0_vgpr1
@@ -7535,9 +7535,9 @@ define void @flat_atomic_max_i64_ret_av_av(ptr %ptr) #0 {
; GFX90A-NEXT: s_cbranch_execz .LBB100_2
; GFX90A-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX90A-NEXT: flat_atomic_smax_x2 v[0:1], v[4:5], v[2:3] glc
-; GFX90A-NEXT: s_waitcnt lgkmcnt(0)
; GFX90A-NEXT: ; implicit-def: $vgpr4_vgpr5
; GFX90A-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX90A-NEXT: s_waitcnt lgkmcnt(0)
; GFX90A-NEXT: .LBB100_2: ; %Flow
; GFX90A-NEXT: s_andn2_saveexec_b64 s[4:5], s[4:5]
; GFX90A-NEXT: s_cbranch_execz .LBB100_4
@@ -7576,9 +7576,9 @@ define void @flat_atomic_max_i64_ret_av_av(ptr %ptr) #0 {
; GFX950-NEXT: s_cbranch_execz .LBB100_2
; GFX950-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX950-NEXT: flat_atomic_smax_x2 v[0:1], v[4:5], v[2:3] sc0
-; GFX950-NEXT: s_waitcnt lgkmcnt(0)
; GFX950-NEXT: ; implicit-def: $vgpr4_vgpr5
; GFX950-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX950-NEXT: s_waitcnt lgkmcnt(0)
; GFX950-NEXT: .LBB100_2: ; %Flow
; GFX950-NEXT: s_andn2_saveexec_b64 s[0:1], s[0:1]
; GFX950-NEXT: s_cbranch_execz .LBB100_4
@@ -7626,8 +7626,8 @@ define void @flat_atomic_min_i64_ret_a_a(ptr %ptr) #0 {
; GFX90A-NEXT: s_cbranch_execz .LBB101_2
; GFX90A-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX90A-NEXT: flat_atomic_smin_x2 v[0:1], v[2:3], v[0:1] glc
-; GFX90A-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX90A-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX90A-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX90A-NEXT: v_accvgpr_write_b32 a0, v0
; GFX90A-NEXT: v_accvgpr_write_b32 a1, v1
; GFX90A-NEXT: ; implicit-def: $vgpr0_vgpr1
@@ -7673,8 +7673,8 @@ define void @flat_atomic_min_i64_ret_a_a(ptr %ptr) #0 {
; GFX950-NEXT: s_cbranch_execz .LBB101_2
; GFX950-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX950-NEXT: flat_atomic_smin_x2 v[0:1], v[2:3], v[0:1] sc0
-; GFX950-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX950-NEXT: ; implicit-def: $vgpr2_vgpr3
+; GFX950-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
; GFX950-NEXT: v_accvgpr_write_b32 a0, v0
; GFX950-NEXT: v_accvgpr_write_b32 a1, v1
; GFX950-NEXT: ; implicit-def: $vgpr0_vgpr1
@@ -7724,9 +7724,9 @@ define void @flat_atomic_min_i64_ret_av_av(ptr %ptr) #0 {
; GFX90A-NEXT: s_cbranch_execz .LBB102_2
; GFX90A-NEXT: ; %bb.1: ; %atomicrmw.global
; GFX90A-NEXT: flat_atomic_smin_x2 v[0:1], v[4:5], v[2:3] glc...
[truncated]
|
205d469 to
c2cef5b
Compare
krzysz00
left a comment
There was a problem hiding this comment.
Looks overall fine to me, just a few questions
| ; GFX11-NEXT: scratch_store_b32 v0, v2, off offset:384 dlc | ||
| ; GFX11-NEXT: s_waitcnt_vscnt null, 0x0 | ||
| ; GFX11-NEXT: s_waitcnt lgkmcnt(0) | ||
| ; GFX11-NEXT: s_waitcnt_vscnt null, 0x0 |
There was a problem hiding this comment.
Do we care about this ordering change?
There was a problem hiding this comment.
Good point, I don't think so. The two waits are adjacent before and after, so only their order changes.
The soft vscnt wait is now deferred, and both waits are created together before the s_lshl_b32. Other test changes have the same cause, waits move past meta instructions and no change to the emitted instructions.
| ; GFX11-EXPAND-NEXT: global_store_b32 v0, v2, s[0:1] offset:256 | ||
| ; GFX11-EXPAND-NEXT: global_store_b32 v0, v3, s[0:1] offset:512 | ||
| ; GFX11-EXPAND-NEXT: s_waitcnt_vscnt null, 0x2 | ||
| ; GFX11-EXPAND-NEXT: s_waitcnt_vscnt null, 0x1 |
There was a problem hiding this comment.
... shouldn't these merge?
There was a problem hiding this comment.
IIUC, no that's intended. In profiling mode each outstanding op gets its own wait (2, 1, 0), same as the other -EXPAND checks in this file.
Before, the fence wait was the soft wait promoted in place, which never got expanded. Now it's a newly created wait, so it gets expanded like the others.
c2cef5b to
3fe8b13
Compare
3fe8b13 to
c515e16
Compare
On the first visit to a loop header only the preheader state is known. A soft waitcnt there (e.g. from a release fence) can have some of its counters simplified away while another counter keeps the instruction alive: the fence's own vmcnt(0), a preceding wait.asyncmark, or an explicit s_waitcnt. The soft waitcnt was then rewritten with the simplified value and promoted to a hard waitcnt, or merged into a preceding hard one. When the back edge later brought a pending LDS store, the original lgkmcnt(0) request was gone, and the s_barrier after the release fence no longer waited for it. Treat soft waitcnts as requests that depend on the incoming state: never merge, promote or rewrite them while the analysis iterates. They are kept unchanged in DeferredErasures, a hard waitcnt (existing or new) carries what is needed on each visit, and the soft waitcnts are erased once the analysis converges. This extends #220357, which did the same only for soft waitcnts that were simplified away entirely. Test changes: - waitcnt-loop-carried-fence-drain.mir: the two pre-committed cases now wait for lgkmcnt(0) before the S_BARRIER. - 15 tests: the waitcnt now sits directly before the instruction that needs it, i.e. after meta instructions such as KILL/IMPLICIT_DEF or after an adjacent s_waitcnt_vscnt. No change in emitted instructions. - expand-waitcnt-profiling.ll: with amdgpu-expand-waitcnt-profiling, the wait for a release fence on gfx9-gfx11 is now expanded like other newly created waits. Co-Authored-By: Claude Opus 5.5 <[email protected]>
c515e16 to
8bf10a1
Compare
# Conflicts: # llvm/test/CodeGen/AMDGPU/stack-realign.ll
Pierre-vh
left a comment
There was a problem hiding this comment.
Can you add a dedicated MIR test case that clearly documents what the expected behavior is?
…tcnts The checks show the current behavior: two loop-header cases miss the lgkmcnt(0) for a DS write that reaches the header through the back edge. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e/amdgpu-soft-waitcnt-loop-header
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Added a dedicated MIR test in #247313. |
…-waitcnt-loop-header
On the first visit to a loop header, a soft waitcnt whose
lgkmcntsimplifies away but whosevmcntis still needed was rewritten and promoted (or merged into a preceding hard wait). The revisit through the back edge then lost thelgkmcnt(0), so thes_barrierafter a release fence no longer waited for the loop's LDS store. Like #220357, keep soft waitcnts unchanged until the pass converges, and let a hard waitcnt carry what each visit needs.gfx950 runtime reproducer: 20/20 launches read stale LDS before, 0/20 after. Other test changes: in 14 tests the wait moves past meta instructions (emitted code unchanged), and
expand-waitcnt-profiling.llnow expands the release-fence wait on gfx9-gfx11.Depends on #244686.
Fixes: LCOMPILER-3291
Assisted-by: Claude Opus 5.5