From 89f75c4c26a42ac41f6781aa08586e3955a962f7 Mon Sep 17 00:00:00 2001 From: Lino Emmenegger Date: Thu, 26 Nov 2026 15:01:42 +0100 Subject: [PATCH] Recompiler: a VOPC SDWA compare's SDST ends the loads it addresses reload::changes read SDST only from the base encoding. For a VOPC SDWA compare with SD set, SDST lives in the extension dword, so the s[x:x+1] pair it writes was not marked and a later s_load_dword* whose address was made of that pair was elided as a repeat, returning stale data. lower_valu.rs already writes that pair; reload now marks it too (SDST 125 is the null destination and writes nothing). Part of #2464 (part 1). Assisted-by: Claude Code (Claude Sonnet 5.5) Co-Authored-By: Claude Sonnet 5.5 --- crates/xcl/src/gpu/dxil/reload.rs | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/crates/xcl/src/gpu/dxil/reload.rs b/crates/xcl/src/gpu/dxil/reload.rs index 47beaa5103..aab83f8970 100644 --- a/crates/xcl/src/gpu/dxil/reload.rs +++ b/crates/xcl/src/gpu/dxil/reload.rs @@ -123,6 +123,14 @@ fn changes(d: &Decoded) -> (u128, bool) { regs |= pair(r, dwords); } } + // an SDWA compare with SD set writes the pair in the extension dword's SDST (125: none) + if d.variant == rdna2::Variant::Sdwa { + if let Some(e) = super::lower::ext_encoding(d).filter(|e| rdna2::field_value(e, &d.words, "SD") == Some(1)) { + if let Some(r) = rdna2::field_value(e, &d.words, "SDST").filter(|&r| r < 125) { + regs |= pair(r, 2); + } + } + } } let writes = name.contains("_STORE") || name.contains("_ATOMIC"); let memory = match d.enc.name { @@ -312,6 +320,37 @@ mod tests { } } + #[test] + fn an_sdwa_compare_into_an_sgpr_pair_ends_it() { + // v_cmp_lt_f32_sdwa s[x:x+1], v1, v2 (SD = 1): the SDST is in the extension dword, not in + // the base words + let code = |sdst: u32| -> Vec { + let mut v = Vec::new(); + for i in [LOAD] { + v.extend(rdna2::encode(i.0, i.1, i.2, None).unwrap()); + } + for w in [0x7c02_04f9u32, 0x0606_8001 | sdst << 8] { + v.extend(w.to_le_bytes()); + } + for i in [LOAD, END] { + v.extend(rdna2::encode(i.0, i.1, i.2, None).unwrap()); + } + v + }; + let avail = |sdst: u32| { + let c = Cfg::build(&code(sdst)).unwrap(); + let mut v: Vec<(usize, bool)> = analyze(&c).at.iter().map(|(&(_, i), l)| (i, l.available)).collect(); + v.sort(); + v + }; + // the base is s[4:5]: a write of s4 or of s[3:4] reaches it, one of s[6:7] does not + assert_eq!(avail(4), [(0, false), (2, false)]); + assert_eq!(avail(5), [(0, false), (2, false)]); + assert_eq!(avail(6), [(0, false), (2, true)]); + // SDST = 125 (null) writes nothing + assert_eq!(avail(125), [(0, false), (2, true)]); + } + #[test] fn loads_that_cannot_be_followed_are_left_alone() { // a coherent load, and one that overwrites its own base