# RUN: %stinkytofu-opt --arch gfx1250 %s --StinkyBuildImplicitDependencyPass --StinkyWaitCntInsertionPass --print-output # # StinkyWaitCntInsertionPass (gfx1250): insert s_wait_dscnt before each WMMA # that consumes outstanding ds_load results. The pass inserts an actual # s_wait_dscnt instruction whose immediate is the number of ds_load results # that should still be OUTSTANDING after the wait. The inserted instruction # also carries an `mod.swaitcnt` modifier exposing the semantic fields # (vlcnt / vscnt / dlcnt / dscnt / kmcnt) that downstream emitters consume. # # Pattern (single-block): # ds_load_b64 v[20:21], v0 (ds_load 0) # ds_load_b64 v[30:31], v0 (ds_load 1) # ds_load_b64 v[40:41], v0 (ds_load 2) # ds_load_b64 v[50:51], v0 (ds_load 3) # v_wmma_f32_16x16x32_bf16 (uses v[20:27], v[30:37] -> needs ds_load 0,1) # v_wmma_f32_16x16x32_bf16 (uses v[40:47], v[50:57] -> needs ds_load 2,3) # # Expected waits inserted by the pass: # s_wait_dscnt 2 before WMMA1 (wait for ds_load 0,1 ; leave 2,3 outstanding) # s_wait_dscnt 0 before WMMA2 (wait for the remaining ds_load 2,3) # # CHECK-LABEL: @waitcnt_insertion_wmma_dsread # CHECK: ds_load_b64 # CHECK-NEXT: ds_load_b64 # CHECK-NEXT: ds_load_b64 # CHECK-NEXT: ds_load_b64 # CHECK-NEXT: s_wait_dscnt # CHECK-SAME: dlcnt = 2 # CHECK-NEXT: v_wmma_f32_16x16x32_bf16 # CHECK-NEXT: s_wait_dscnt # CHECK-SAME: dlcnt = 0 # CHECK-NEXT: v_wmma_f32_16x16x32_bf16 # Only two waitcnt inserts should exist, and no tensor waitcnt should appear # (no tensor loads are present in this block, so the tensor-wait heuristic is a no-op). # CHECK-NOT: s_wait_tensorcnt # CHECK-NOT: s_wait_loadcnt st.func @waitcnt_insertion_wmma_dsread() { ^entry: v[20:21] = "st.ds_load_b64"(v0) { mod.ds = { na = 1, offset = 0, gds = false }, mod.memtoken = { tokens = [0] } } v[30:31] = "st.ds_load_b64"(v0) { mod.ds = { na = 1, offset = 16, gds = false }, mod.memtoken = { tokens = [0] } } v[40:41] = "st.ds_load_b64"(v0) { mod.ds = { na = 1, offset = 32, gds = false }, mod.memtoken = { tokens = [0] } } v[50:51] = "st.ds_load_b64"(v0) { mod.ds = { na = 1, offset = 48, gds = false }, mod.memtoken = { tokens = [0] } } a[10:17] = "st.v_wmma_f32_16x16x32_bf16"(v[20:27], v[30:37], a[10:17]) { mod.mfma = { reuseA = false, reuseB = false } } a[10:17] = "st.v_wmma_f32_16x16x32_bf16"(v[40:47], v[50:57], a[10:17]) { mod.mfma = { reuseA = false, reuseB = false } } }