From 971322597fd998d65e945a01b6881e5a099e4dc4 Mon Sep 17 00:00:00 2001 From: Decodere <98278826+Decodere@users.noreply.github.com> Date: Wed, 25 Nov 2026 13:54:37 +0300 Subject: [PATCH] Tests: add split_wave64_spin_exchange_updates_block_tails regression test Both `self.tails[self.cur] = self.lw.cur()` sync lines in `DxilIr::ballot` and `DxilIr::read_lane` landed on `main` via #2203. Rebase #1928 onto `main` to keep only the standalone `[128, 1, 1]` split-wave64 (`Partner::Spin`) regression test covering: - whole-wave ballot (`s_bcnt1_i32_b64`) in a uniform branch arm feeding a join PHI, - cross-half `v_readlane_b32` (lane 37) in a uniform branch arm feeding a join PHI, - `v_readfirstlane_b32` (ballot + read_lane) in a uniform loop feeding back-edge PHIs. Each case compiles and validates through `lower_dxil::compute_split` and, when a GPU is available, checks dispatch parity against `run_compute_waves`. Part of #1889 Assisted-by: Google Antigravity (Gemini 4 Neon) --- crates/xcl/src/gpu/recomp/lower_dxil.rs | 81 +++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/crates/xcl/src/gpu/recomp/lower_dxil.rs b/crates/xcl/src/gpu/recomp/lower_dxil.rs index a3b942da6c..a3f2769663 100644 --- a/crates/xcl/src/gpu/recomp/lower_dxil.rs +++ b/crates/xcl/src/gpu/recomp/lower_dxil.rs @@ -1165,4 +1165,85 @@ mod tests { } } } + + /// Split wave64 compute with >64 threads (`Partner::Spin`): `DxilIr::ballot` and + /// `DxilIr::read_lane` call `Lw::spin_exchange`, which creates DXIL basic blocks and advances + /// `self.lw.cur()`. `self.tails[self.cur]` must track that tail so PHIs in successor blocks + /// (diamonds and loop headers) reference the post-exchange predecessor block (#1889). + #[test] + fn split_wave64_spin_exchange_updates_block_tails() { + // 1) Whole-wave ballot (`s_bcnt1_i32_b64`) in a uniform branch arm feeding a join PHI + const BALLOT_DIAMOND: &[I] = &[ + ("S_CMP_EQ_U32", "ENC_SOPC", &[("SSRC0", 2), ("SSRC1", 128)]), + ("S_CBRANCH_SCC0", "ENC_SOPP", &[("SIMM16", 3)]), + ("V_CMP_GT_U32", "ENC_VOPC", &[("SRC0", 168), ("VSRC1", 0)]), + ("S_BCNT1_I32_B64", "ENC_SOP1", &[("SDST", 4), ("SSRC0", 106)]), + ("S_BRANCH", "ENC_SOPP", &[("SIMM16", 1)]), + ("S_MOV_B32", "ENC_SOP1", &[("SDST", 4), ("SSRC0", 135)]), + ("S_LSHL_B32", "ENC_SOP2", &[("SDST", 3), ("SSRC0", 2), ("SSRC1", 135)]), + ("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 4), ("SRC0", 3), ("VSRC1", 0)]), + ("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 8), ("SRC0", 130), ("VSRC1", 4)]), + ("V_MOV_B32", "ENC_VOP1", &[("VDST", 9), ("SRC0", 128)]), + ("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 7), ("SRC0", 4), ("VSRC1", 0)]), + ("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 8), ("DATA", 7), ("SADDR", 125), ("OFFSET", 0)]), + ENDPGM, + ]; + // 2) Cross-half `v_readlane_b32` (lane 37) in a uniform branch arm feeding a join PHI + const READLANE_DIAMOND: &[I] = &[ + ("S_CMP_EQ_U32", "ENC_SOPC", &[("SSRC0", 2), ("SSRC1", 128)]), + ("S_CBRANCH_SCC0", "ENC_SOPP", &[("SIMM16", 3)]), + ("V_READLANE_B32", "ENC_VOP3", &[("VDST", 4), ("SRC0", V), ("SRC1", 165)]), + ("S_BRANCH", "ENC_SOPP", &[("SIMM16", 1)]), + ("S_MOV_B32", "ENC_SOP1", &[("SDST", 4), ("SSRC0", 137)]), + ("S_LSHL_B32", "ENC_SOP2", &[("SDST", 3), ("SSRC0", 2), ("SSRC1", 135)]), + ("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 4), ("SRC0", 3), ("VSRC1", 0)]), + ("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 8), ("SRC0", 130), ("VSRC1", 4)]), + ("V_MOV_B32", "ENC_VOP1", &[("VDST", 9), ("SRC0", 128)]), + ("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 7), ("SRC0", 4), ("VSRC1", 0)]), + ("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 8), ("DATA", 7), ("SADDR", 125), ("OFFSET", 0)]), + ENDPGM, + ]; + // 3) `v_readfirstlane_b32` (ballot + read_lane) inside a uniform loop feeding back-edge PHIs + const READFIRSTLANE_LOOP: &[I] = &[ + ("S_MOV_B32", "ENC_SOP1", &[("SDST", 4), ("SSRC0", 128)]), + ("S_MOV_B32", "ENC_SOP1", &[("SDST", 5), ("SSRC0", 128)]), + ("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 1), ("SRC0", 5), ("VSRC1", 0)]), + ("V_READFIRSTLANE_B32", "ENC_VOP1", &[("VDST", 6), ("SRC0", V + 1)]), + ("S_ADD_U32", "ENC_SOP2", &[("SDST", 4), ("SSRC0", 4), ("SSRC1", 6)]), + ("S_ADD_U32", "ENC_SOP2", &[("SDST", 5), ("SSRC0", 5), ("SSRC1", 129)]), + ("S_CMP_LT_U32", "ENC_SOPC", &[("SSRC0", 5), ("SSRC1", 131)]), + ("S_CBRANCH_SCC1", "ENC_SOPP", &[("SIMM16", (-6i16) as u16 as u64)]), + ("S_LSHL_B32", "ENC_SOP2", &[("SDST", 3), ("SSRC0", 2), ("SSRC1", 135)]), + ("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 4), ("SRC0", 3), ("VSRC1", 0)]), + ("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 8), ("SRC0", 130), ("VSRC1", 4)]), + ("V_MOV_B32", "ENC_VOP1", &[("VDST", 9), ("SRC0", 128)]), + ("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 7), ("SRC0", 4), ("VSRC1", 0)]), + ("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 8), ("DATA", 7), ("SADDR", 125), ("OFFSET", 0)]), + ENDPGM, + ]; + + let cs = crate::gpu::recomp::CsInterface { threads: [128, 1, 1], ..compute_cs() }; + let cases: [(&str, &[I], [u32; 3]); 3] = [ + ("ballot diamond", BALLOT_DIAMOND, [40, 64, 7]), + ("readlane diamond", READLANE_DIAMOND, [37, 165, 9]), + ("readfirstlane loop", READFIRSTLANE_LOOP, [3, 259, 3]), + ]; + let compiled: Vec<(&str, &[I], [u32; 3], Vec)> = cases + .into_iter() + .map(|(name, lines, spot)| { + let dxil = super::compute_split(&decode(lines), &cs).unwrap_or_else(|e| panic!("{name}: {e}")); + (name, lines, spot, dxil) + }) + .collect(); + if !gpu() { + return; + } + let mem = vec![0u32; 256]; + for (name, lines, [w0, w1, g1], dxil) in compiled { + let gpu = runner::dispatch(&dxil, [2, 1, 1], &[100, 0], &mem).unwrap_or_else(|e| panic!("{name}: {e}")); + let cpu = run_compute_waves(lines, &cs, true, 2, &[100, 0], &mem); + assert_eq!([cpu[0], cpu[64], cpu[128]], [w0, w1, g1], "{name}: expected spot values"); + assert_eq!(&gpu[..256], &cpu[..256], "{name}"); + } + } }