feat(victory-shader): implement v_swaprel_b32, v_movrelsd_2_b32, and s_movrelsd_2_b32 lowering #627

Closed
Amit89-beep wants to merge 2 commits from upstream-pr/627 into main
Amit89-beep commented 2026-11-24 05:54:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Amit89-beep on 2026-11-24T05:54:45Z.


Summary

Implements IR register-effect tracking and DXIL lowering for three previously unhandled relative/indexed instructions in victory-shader:

  • v_swaprel_b32 (VOP1 opcode 0x068): atomically swaps v[dst + M0] ↔ v[src + M0]
  • v_movrelsd_2_b32 (VOP1 opcode 0x048): GFX10.3 dual-source indexed vector move (v[dst + M0] = v[src0 + M0] and base v[dst] = v[src1])
  • s_movrelsd_2_b32 (SOP1 opcode 0x049): scalar relative swap (sdst = s[ssrc + M0]; s[ssrc + M0] = sdst_old) across valid SGPRs 0..106

Details of Changes

  1. crates/victory-shader/src/ir.rs:

    • Added support for s_movrelsd_2_b32 under Fields::Sop to track both indexed read and write register spans (0..106) along with M0 as an implicit read dependency.
    • Added unit tests: v_swaprel_tracks_both_indexed_reads_and_writes and s_movrelsd_2_tracks_dual_indexed_sgpr_effects.
  2. crates/victory-shader/src/emit/lower.rs:

    • Added lowering arm for s_movrelsd_2_b32 in sop() using dynamic select chains while preserving untouched SGPR slots.
    • Added lowering arms for v_swaprel_b32 and v_movrelsd_2_b32 in valu_op() with proper aliasing handling when src == dst.
    • Added unit tests: v_swaprel_b32_lowers_through_select_chains, v_movrelsd_2_b32_lowers_cleanly, s_movrelsd_2_b32_lowers_cleanly, and v_movrels_and_movreld_round_trip_through_dxil.

Verification

  • cargo fmt --package victory-shader --check (clean)
  • cargo clippy -p victory-shader --all-targets (0 warnings, 0 errors)
  • cargo test -p victory-shader (all 75 unit tests pass)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6575617304 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/627). Originally posted by [Amit89-beep](https://github.com/Amit89-beep) on 2026-11-24T05:54:45Z. --- ## Summary Implements IR register-effect tracking and DXIL lowering for three previously unhandled relative/indexed instructions in `victory-shader`: - `v_swaprel_b32` (VOP1 opcode `0x068`): atomically swaps `v[dst + M0] ↔ v[src + M0]` - `v_movrelsd_2_b32` (VOP1 opcode `0x048`): GFX10.3 dual-source indexed vector move (`v[dst + M0] = v[src0 + M0]` and base `v[dst] = v[src1]`) - `s_movrelsd_2_b32` (SOP1 opcode `0x049`): scalar relative swap (`sdst = s[ssrc + M0]; s[ssrc + M0] = sdst_old`) across valid SGPRs `0..106` ## Details of Changes 1. **`crates/victory-shader/src/ir.rs`**: - Added support for `s_movrelsd_2_b32` under `Fields::Sop` to track both indexed read and write register spans (`0..106`) along with `M0` as an implicit read dependency. - Added unit tests: `v_swaprel_tracks_both_indexed_reads_and_writes` and `s_movrelsd_2_tracks_dual_indexed_sgpr_effects`. 2. **`crates/victory-shader/src/emit/lower.rs`**: - Added lowering arm for `s_movrelsd_2_b32` in `sop()` using dynamic `select` chains while preserving untouched SGPR slots. - Added lowering arms for `v_swaprel_b32` and `v_movrelsd_2_b32` in `valu_op()` with proper aliasing handling when `src == dst`. - Added unit tests: `v_swaprel_b32_lowers_through_select_chains`, `v_movrelsd_2_b32_lowers_cleanly`, `s_movrelsd_2_b32_lowers_cleanly`, and `v_movrels_and_movreld_round_trip_through_dxil`. ## Verification - `cargo fmt --package victory-shader --check` (clean) - `cargo clippy -p victory-shader --all-targets` (0 warnings, 0 errors) - `cargo test -p victory-shader` (all 75 unit tests pass)
LAKSHYA-cmd-tech commented 2026-11-24 06:54:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T05:58:43Z.

Review: APPROVED


Tested on Windows 11 with Rust 1.98.1 (x86_64-pc-windows-msvc).

  • cargo test -p victory-shader: all 75 unit tests passed cleanly (including _swaprel_tracks_both_indexed_reads_and_writes, s_movrelsd_2_tracks_dual_indexed_sgpr_effects, s_movrelsd_2_b32_lowers_cleanly, _movrelsd_2_b32_lowers_cleanly, and _swaprel_b32_lowers_through_select_chains).
  • cargo xtask policy: passed (151 files ok).
  • Verified IR register tracking and DXIL select-chain lowering for dual indexed moves and relative swaps.
<!-- greyfinch-sync:Marvisak/VIctory:review:6034405105 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/627#pullrequestreview-6034405105). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T05:58:43Z. **Review:** APPROVED --- Tested on Windows 11 with Rust 1.98.1 (x86_64-pc-windows-msvc). - cargo test -p victory-shader: all 75 unit tests passed cleanly (including _swaprel_tracks_both_indexed_reads_and_writes, s_movrelsd_2_tracks_dual_indexed_sgpr_effects, s_movrelsd_2_b32_lowers_cleanly, _movrelsd_2_b32_lowers_cleanly, and _swaprel_b32_lowers_through_select_chains). - cargo xtask policy: passed (151 files ok). - Verified IR register tracking and DXIL select-chain lowering for dual indexed moves and relative swaps.
Lyrnc commented 2026-11-24 06:56:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-24T06:02:13Z.


RDNA2 hardware measurement of the three opcodes: on gfx1036 none of the three behaves as described here. All three split M0 into two fields, and none of them is a swap with a shared offset or a second move.

Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (GFX10.3 / RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. A HIP kernel (assembled by the AMD driver's amd_comgr) fills 16 VGPRs (v10..v25) or 16 SGPRs (s20..s35) with distinct values, sets M0, runs one instruction, and reads every register back. RDNA2 desktop silicon, not the console's. No game data.

Instruction M0 Registers that changed
v_swaprel_b32 v12, v11 0x00010000 v11 <-> v13
v_swaprel_b32 v12, v11 0x00030002 v13 <-> v15
v_movrelsd_2_b32 v12, v11 0x00010000 v13 = v11, nothing else
v_movrelsd_2_b32 v12, v11 0x00050003 v17 = v14, nothing else
s_movrelsd_2_b32 s22, s21 0x00010000 s23 = s21, nothing else
s_movrelsd_2_b32 s22, s21 0x00020001 s24 = s22, nothing else
s_movrelsd_2_b32 s22, s21 0x00030002 s25 = s23, nothing else
s_movrelsd_2_b32 s22, s21 0x04000003 s22 = s24 (bit 26 ignored)

For all three:

  • The source register is src + M0[9:0] and the destination dst + M0[25:16]. Bits 10-15 and 26-31 are ignored. 11 M0 values for the vector forms (listed on #498, which lowers them this way), 10 for s_movrelsd_2_b32.
  • v_swaprel_b32 swaps v[dst + M0[25:16]] with v[src + M0[9:0]], not v[dst + M0] with v[src + M0]. With M0 = 0x00010000 the description's form would index 65536 registers out.
  • v_movrelsd_2_b32 makes one move. v[dst] is not also written from another source.
  • s_movrelsd_2_b32 is a move with the same split, not a swap: the source SGPR keeps its value in every run.

s_movrels_b32 and s_movreld_b32 (as in #608) use the whole M0, as their descriptions say.

AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123511680 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/627#issuecomment-7123511680). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-24T06:02:13Z. --- RDNA2 hardware measurement of the three opcodes: **on gfx1036 none of the three behaves as described here.** All three split M0 into two fields, and none of them is a swap with a shared offset or a second move. **Setup.** AMD Radeon iGPU of a Ryzen 7 9800X3D, **gfx1036 (GFX10.3 / RDNA2)**, AMD driver 32.0.21042.62, Windows 11 Pro 26200. A HIP kernel (assembled by the AMD driver's amd_comgr) fills 16 VGPRs (`v10..v25`) or 16 SGPRs (`s20..s35`) with distinct values, sets M0, runs one instruction, and reads every register back. RDNA2 desktop silicon, not the console's. No game data. | Instruction | M0 | Registers that changed | |---|---|---| | `v_swaprel_b32 v12, v11` | `0x00010000` | v11 <-> v13 | | `v_swaprel_b32 v12, v11` | `0x00030002` | v13 <-> v15 | | `v_movrelsd_2_b32 v12, v11` | `0x00010000` | v13 = v11, nothing else | | `v_movrelsd_2_b32 v12, v11` | `0x00050003` | v17 = v14, nothing else | | `s_movrelsd_2_b32 s22, s21` | `0x00010000` | s23 = s21, nothing else | | `s_movrelsd_2_b32 s22, s21` | `0x00020001` | s24 = s22, nothing else | | `s_movrelsd_2_b32 s22, s21` | `0x00030002` | s25 = s23, nothing else | | `s_movrelsd_2_b32 s22, s21` | `0x04000003` | s22 = s24 (bit 26 ignored) | For all three: - The source register is `src + M0[9:0]` and the destination `dst + M0[25:16]`. Bits 10-15 and 26-31 are ignored. 11 M0 values for the vector forms (listed on #498, which lowers them this way), 10 for `s_movrelsd_2_b32`. - `v_swaprel_b32` swaps `v[dst + M0[25:16]]` with `v[src + M0[9:0]]`, not `v[dst + M0]` with `v[src + M0]`. With `M0 = 0x00010000` the description's form would index 65536 registers out. - `v_movrelsd_2_b32` makes one move. `v[dst]` is not also written from another source. - `s_movrelsd_2_b32` is a move with the same split, not a swap: the source SGPR keeps its value in every run. `s_movrels_b32` and `s_movreld_b32` (as in #608) use the whole M0, as their descriptions say. AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.
catminou4 commented 2026-11-24 11:03:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T10:19:50Z.

Review: COMMENTED


Conflicts with current main (ffe310e) in lower.rs — needs a rebase.

Static review: three M0-relative lowerings (v_swaprel_b32, v_movrelsd_2_b32, s_movrelsd_2_b32) built on select chains over the IR-tracked indexed span. The swap semantics are the tricky part and the comments get them right: simultaneous swap (dst receives old s/v[src+M0], src+M0 receives old dst), sreg==dreg as no-op, aliasing slots skipped because the dst scatter already wrote them. v_movrels_and_movreld_round_trip_through_dxil goes through DXIL, which is good. Same gap as #608: the value-level tests are lowering/round-trip smoke tests, not host execution — a valu-suite test with concrete VGPR/SGPR values would confirm the scatter order (dst range written before src range is skipped correctly when ranges overlap partially, e.g. dreg=100, sreg=105).

Rebase and I'll re-run.

<!-- greyfinch-sync:Marvisak/VIctory:review:6037425353 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/627#pullrequestreview-6037425353). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T10:19:50Z. **Review:** COMMENTED --- Conflicts with current main (`ffe310e`) in `lower.rs` — needs a rebase. Static review: three M0-relative lowerings (v_swaprel_b32, v_movrelsd_2_b32, s_movrelsd_2_b32) built on select chains over the IR-tracked indexed span. The swap semantics are the tricky part and the comments get them right: simultaneous swap (dst receives old s/v[src+M0], src+M0 receives old dst), sreg==dreg as no-op, aliasing slots skipped because the dst scatter already wrote them. `v_movrels_and_movreld_round_trip_through_dxil` goes through DXIL, which is good. Same gap as #608: the value-level tests are lowering/round-trip smoke tests, not host execution — a valu-suite test with concrete VGPR/SGPR values would confirm the scatter order (dst range written before src range is skipped correctly when ranges overlap partially, e.g. dreg=100, sreg=105). Rebase and I'll re-run.
mercuryVM commented 2026-11-24 12:04:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T11:16:00Z.

Review: CHANGES_REQUESTED


Tested e8ea7d9 on Windows 11, RTX 5070, MSVC: cargo test -p victory-shader -- --test-threads=1 75 passed, and cargo clippy -p victory-shader --all-targets is clean. The tests pass, but they encode the semantics this PR assumes, and as I read the RDNA2 ISA reference those semantics don't match the hardware for any of the three instructions:

  • v_movrelsd_2_b32: the ISA gives VGPR[D.addr + M0[25:16]] = VGPR[S0.addr + M0[9:0]]. That is one move with separate source and destination offsets taken from two M0 fields. There is no second source and no write to the base v[dst]. The PR lowers it as a dual move with the whole of M0 as both offsets.
  • v_swaprel_b32: tmp = VGPR[D.addr + M0[25:16]]; VGPR[D.addr + M0[25:16]] = VGPR[S0.addr + M0[9:0]]; VGPR[S0.addr + M0[9:0]] = tmp. The swap is right, but lower.rs and ir.rs index both sides with the full M0 (cmp(m0, k)), not with the two 10-bit fields.
  • s_movrelsd_2_b32: SGPR[D.addr + M0[25:16]] = SGPR[S0.addr + M0[9:0]], again one move with two offsets. It isn't a swap, so s[ssrc + M0] = sdst_old (lower.rs, the s_movrelsd_2_b32 block, and the matching write set in ir.rs:695) would write a register the hardware leaves alone.

Fix: decode src_off = m0 & 0x3FF and dst_off = (m0 >> 16) & 0x3FF. Build the read select chain over src_off and the write scatter over dst_off. Drop the second write for s_movrelsd_2_b32 and v_movrelsd_2_b32, and keep it, with the field offsets, for v_swaprel_b32. In ir.rs, the write sets should range from dst and the read sets from src. If you have a source showing the full-M0 or swap behaviour on GFX10.3, please link it and I'll re-check.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6038226275 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/627#pullrequestreview-6038226275). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T11:16:00Z. **Review:** CHANGES_REQUESTED --- Tested e8ea7d9 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-shader -- --test-threads=1` 75 passed, and `cargo clippy -p victory-shader --all-targets` is clean. The tests pass, but they encode the semantics this PR assumes, and as I read the RDNA2 ISA reference those semantics don't match the hardware for any of the three instructions: - `v_movrelsd_2_b32`: the ISA gives `VGPR[D.addr + M0[25:16]] = VGPR[S0.addr + M0[9:0]]`. That is one move with *separate* source and destination offsets taken from two M0 fields. There is no second source and no write to the base `v[dst]`. The PR lowers it as a dual move with the whole of M0 as both offsets. - `v_swaprel_b32`: `tmp = VGPR[D.addr + M0[25:16]]; VGPR[D.addr + M0[25:16]] = VGPR[S0.addr + M0[9:0]]; VGPR[S0.addr + M0[9:0]] = tmp`. The swap is right, but `lower.rs` and `ir.rs` index both sides with the full M0 (`cmp(m0, k)`), not with the two 10-bit fields. - `s_movrelsd_2_b32`: `SGPR[D.addr + M0[25:16]] = SGPR[S0.addr + M0[9:0]]`, again one move with two offsets. It isn't a swap, so `s[ssrc + M0] = sdst_old` (`lower.rs`, the `s_movrelsd_2_b32` block, and the matching write set in `ir.rs:695`) would write a register the hardware leaves alone. Fix: decode `src_off = m0 & 0x3FF` and `dst_off = (m0 >> 16) & 0x3FF`. Build the read select chain over `src_off` and the write scatter over `dst_off`. Drop the second write for `s_movrelsd_2_b32` and `v_movrelsd_2_b32`, and keep it, with the field offsets, for `v_swaprel_b32`. In `ir.rs`, the write sets should range from `dst` and the read sets from `src`. If you have a source showing the full-M0 or swap behaviour on GFX10.3, please link it and I'll re-check. AI-assisted (Claude Code).
mercuryVM commented 2026-11-24 13:01:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T12:08:16Z.

Review: APPROVED


Re-tested 66a3ec5 on Windows 11, RTX 5070, MSVC: cargo test -p victory-shader -- --test-threads=1 126 passed, and cargo clippy -p victory-shader --all-targets is clean.

This addresses my earlier review. All three instructions now use the M0 fields from the ISA: the source at M0[9:0] and the destination at M0[25:16].

  • s_movrelsd_2_b32 and v_movrelsd_2_b32 are single moves with no second write.

  • v_swaprel_b32 keeps the swap with the split offsets.

  • ir.rs read and write sets range from src and dst respectively.

  • Overlap: the commit "shader: lower v_movrelsd_2_b32 and v_swaprel_b32", stacked under #499/#576, lowers the same two VOP1 forms with the same field split. Only one should land. This PR additionally covers s_movrelsd_2_b32, so it's the more complete of the two.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6038913162 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/627#pullrequestreview-6038913162). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T12:08:16Z. **Review:** APPROVED --- Re-tested 66a3ec5 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-shader -- --test-threads=1` 126 passed, and `cargo clippy -p victory-shader --all-targets` is clean. This addresses my earlier review. All three instructions now use the M0 fields from the ISA: the source at `M0[9:0]` and the destination at `M0[25:16]`. - `s_movrelsd_2_b32` and `v_movrelsd_2_b32` are single moves with no second write. - `v_swaprel_b32` keeps the swap with the split offsets. - `ir.rs` read and write sets range from `src` and `dst` respectively. - Overlap: the commit "shader: lower v_movrelsd_2_b32 and v_swaprel_b32", stacked under #499/#576, lowers the same two VOP1 forms with the same field split. Only one should land. This PR additionally covers `s_movrelsd_2_b32`, so it's the more complete of the two. AI-assisted (Claude Code).
CaravelaLabs commented 2026-11-24 14:04:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by CaravelaLabs on 2026-11-24T13:05:18Z.


Thanks @Amit89-beep — this merges cleanly onto main ffe310e. cargo test -p victory-shader --lib is 102 passed / 0 failed / 1 ignored (Linux, rustc 1.98.1). Main on the same commit is 96 / 0 / 1.

The M0 split matches what @Lyrnc measured and what @mercuryVM asked for. One swap on 66a3ec5 is still wrong when the two index ranges overlap, which they do whenever the source base is at or below the destination address.

With v1=17, v2=34, v3=51, constant-folding the select chains this lowerer builds:

  • v_swaprel_b32 v2, v1, M0=0, should swap v1 and v2. v2 stays 34 (both end as 34).
  • v_swaprel_b32 v2, v1, M0=0x00010000, should swap v1 and v3. v3 stays 51 (both end as 51).

The source side is written. The destination side is written first, then the source-range scatter puts the original value back, because that register is in the source range and is not the source target. v_swaprel_b32 v1, v3 with M0=0 (destination outside the source range) and v_swaprel_b32 v2, v2 come out right, so this is only the different-base arm.

@catminou4's note about aliasing slots was on the previous head. The new lower tests only check that emit returns Ok, and those two VOP tests also pass on main without this lowering, so they do not catch this. s_movrelsd_2_b32 does fail on main (Unsupported). The 0xBE80_0380 word in those tests is s_mov_b32 s0, 0, not s_mov_b32 m0, 0 (0xBEFC0380), so they never set M0 either.

AI-assisted; tests run on this machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7132331034 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/627#issuecomment-7132331034). Originally posted by [CaravelaLabs](https://github.com/CaravelaLabs) on 2026-11-24T13:05:18Z. --- Thanks @Amit89-beep — this merges cleanly onto main `ffe310e`. `cargo test -p victory-shader --lib` is 102 passed / 0 failed / 1 ignored (Linux, rustc 1.98.1). Main on the same commit is 96 / 0 / 1. The M0 split matches what @Lyrnc measured and what @mercuryVM asked for. One swap on `66a3ec5` is still wrong when the two index ranges overlap, which they do whenever the source base is at or below the destination address. With v1=17, v2=34, v3=51, constant-folding the select chains this lowerer builds: - `v_swaprel_b32 v2, v1`, M0=0, should swap v1 and v2. v2 stays 34 (both end as 34). - `v_swaprel_b32 v2, v1`, M0=0x00010000, should swap v1 and v3. v3 stays 51 (both end as 51). The source side is written. The destination side is written first, then the source-range scatter puts the original value back, because that register is in the source range and is not the source target. `v_swaprel_b32 v1, v3` with M0=0 (destination outside the source range) and `v_swaprel_b32 v2, v2` come out right, so this is only the different-base arm. @catminou4's note about aliasing slots was on the previous head. The new lower tests only check that emit returns Ok, and those two VOP tests also pass on main without this lowering, so they do not catch this. `s_movrelsd_2_b32` does fail on main (`Unsupported`). The `0xBE80_0380` word in those tests is `s_mov_b32 s0, 0`, not `s_mov_b32 m0, 0` (`0xBEFC0380`), so they never set M0 either. AI-assisted; tests run on this machine.
Amit89-beep commented 2026-11-24 14:04:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Amit89-beep on 2026-11-24T13:36:37Z.


Great catch — thank you for the detailed trace.

Fixed in 7dac1ae:

  • Unified scatter for v_swaprel_b32: Replaced the two separate loops with a single pass over min(sreg, dreg)..=255, evaluating destination and source matches independently per register. This prevents the source loop from restoring old values when the spans overlap (sreg <= dreg).
  • IR effect deduplication: Ensured reads and writes in ir::build deduplicate registers so overlapping ranges don't allocate duplicate SSA values.
  • M0 test word: Fixed the setup instruction from 0xBE80_0380 (s0) to 0xBEFC_0380 (m0).
  • Host execution test: Added v_swaprel_and_movrelsd_match_rdna2_on_host in valu_tests.rs running on the host GPU/WARP runner, covering both M0=0 (swapping v1 ↔ v2) and M0=0x00010000 (swapping v1 ↔ v3, preserving v2), as well as v_movrelsd_2_b32.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7133076676 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/627#issuecomment-7133076676). Originally posted by [Amit89-beep](https://github.com/Amit89-beep) on 2026-11-24T13:36:37Z. --- Great catch — thank you for the detailed trace. Fixed in 7dac1ae: - **Unified scatter for `v_swaprel_b32`**: Replaced the two separate loops with a single pass over `min(sreg, dreg)..=255`, evaluating destination and source matches independently per register. This prevents the source loop from restoring old values when the spans overlap (`sreg <= dreg`). - **IR effect deduplication**: Ensured `reads` and `writes` in `ir::build` deduplicate registers so overlapping ranges don't allocate duplicate SSA values. - **M0 test word**: Fixed the setup instruction from `0xBE80_0380` (`s0`) to `0xBEFC_0380` (`m0`). - **Host execution test**: Added `v_swaprel_and_movrelsd_match_rdna2_on_host` in `valu_tests.rs` running on the host GPU/WARP runner, covering both `M0=0` (swapping `v1` ↔ `v2`) and `M0=0x00010000` (swapping `v1` ↔ `v3`, preserving `v2`), as well as `v_movrelsd_2_b32`.
catminou4 commented 2026-11-24 15:03:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T14:58:42Z.

Review: COMMENTED


The three M0-relative moves are a valuable addition and the VGPR sides look right (the vector rule in ir.rs already adds every VGPR write to the reads, so v_swaprel_b32's union pass and v_movrelsd_2_b32's scatter both see the old values; the overlap-span fix in the head commit and the dedup in build are the right shape). One concern I can't execute-verify from macOS — the SGPR form:

s_movrelsd_2_b32: non-target SGPRs in the destination range can be zeroed when dst_base < src_base.

  • ir.rs effects() for this SOP instruction adds the source range to reads and the destination range to writes, plus M0 to reads — but nothing adds the destination range to reads (the "Lanes disabled in EXEC keep the old value" rule only applies to Fields::Valu).
  • The lowering's scatter then does inst.read(Reg::S(dst_base + k)) and falls back to self.s.m.i32(0) when absent, writing select(is_target, val, old) for every slot in [dst_base, 106).

Concretely: s_movrelsd_2_b32 s0, s2 (exactly what your lowering test encodes) with m0 = 0 targets s0; the loop also "writes" s1, and since s1 is in neither the source range [s2..105] nor the reads, old_slot is the constant 0 — so s1 is overwritten with 0 instead of keeping its value. Hardware writes only the single target SGPR. The reverse direction (dst_base > src_base, as in your IR test s4, s2) is safe only because the ranges then overlap.

Cheapest fix: in effects() also add the destination range to reads for this instruction (scalar ops don't need EXEC preservation, but the lowering needs the old values — same reason the vector rule exists). Then a hardware test in the style of v_swaprel_and_movrelsd_match_rdna2_on_host with dst_base < src_base and a sentinel SGPR would pin it. Until that's confirmed on the Windows lane, I'd hold off approving — the VGPR forms are fine to land independently if you'd rather split them.

Verified locally: test-merge with current main (ffe310e) clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 102 passed / 0 failed / 1 ignored (lowering/IR unit tests only — execution is Windows-gated).

<!-- greyfinch-sync:Marvisak/VIctory:review:6041648880 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/627#pullrequestreview-6041648880). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T14:58:42Z. **Review:** COMMENTED --- The three M0-relative moves are a valuable addition and the VGPR sides look right (the `vector` rule in `ir.rs` already adds every VGPR write to the reads, so `v_swaprel_b32`'s union pass and `v_movrelsd_2_b32`'s scatter both see the old values; the overlap-span fix in the head commit and the dedup in `build` are the right shape). One concern I can't execute-verify from macOS — the SGPR form: **`s_movrelsd_2_b32`: non-target SGPRs in the destination range can be zeroed when `dst_base < src_base`.** - `ir.rs` `effects()` for this SOP instruction adds the *source* range to reads and the *destination* range to writes, plus M0 to reads — but nothing adds the destination range to reads (the "Lanes disabled in EXEC keep the old value" rule only applies to `Fields::Valu`). - The lowering's scatter then does `inst.read(Reg::S(dst_base + k))` and falls back to `self.s.m.i32(0)` when absent, writing `select(is_target, val, old)` for **every** slot in `[dst_base, 106)`. Concretely: `s_movrelsd_2_b32 s0, s2` (exactly what your lowering test encodes) with `m0 = 0` targets `s0`; the loop also "writes" `s1`, and since `s1` is in neither the source range `[s2..105]` nor the reads, `old_slot` is the constant 0 — so `s1` is overwritten with 0 instead of keeping its value. Hardware writes only the single target SGPR. The reverse direction (`dst_base > src_base`, as in your IR test `s4, s2`) is safe only because the ranges then overlap. Cheapest fix: in `effects()` also add the destination range to reads for this instruction (scalar ops don't need EXEC preservation, but the lowering needs the old values — same reason the vector rule exists). Then a hardware test in the style of `v_swaprel_and_movrelsd_match_rdna2_on_host` with `dst_base < src_base` and a sentinel SGPR would pin it. Until that's confirmed on the Windows lane, I'd hold off approving — the VGPR forms are fine to land independently if you'd rather split them. Verified locally: test-merge with current main (`ffe310e`) clean; `cargo test -p victory-shader --locked` (macOS arm64, rustc 1.98.1) → **102 passed / 0 failed / 1 ignored** (lowering/IR unit tests only — execution is Windows-gated).
CaravelaLabs commented 2026-11-24 15:03:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by CaravelaLabs on 2026-11-24T14:10:59Z.


Thanks @Amit89-beep — re-folded the two overlap cases on 7dac1ae.

With v1=17, v2=34, v3=51, the select chains now come out right:

  • v_swaprel_b32 v2, v1, M0=0: v1=34, v2=17 (v3 stays 51)
  • v_swaprel_b32 v2, v1, M0=0x10000: v1=51, v3=17 (v2 stays 34)

The no-overlap case (v1, v3, M0=0) and the same-base case (v2, v2, M0=0x10000) still match too. This is a constant-fold of the chains this lowerer builds, not a GPU run.

AI-assisted; tests run on this machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7133967845 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/627#issuecomment-7133967845). Originally posted by [CaravelaLabs](https://github.com/CaravelaLabs) on 2026-11-24T14:10:59Z. --- Thanks @Amit89-beep — re-folded the two overlap cases on `7dac1ae`. With v1=17, v2=34, v3=51, the select chains now come out right: - `v_swaprel_b32 v2, v1`, M0=0: v1=34, v2=17 (v3 stays 51) - `v_swaprel_b32 v2, v1`, M0=0x10000: v1=51, v3=17 (v2 stays 34) The no-overlap case (`v1, v3`, M0=0) and the same-base case (`v2, v2`, M0=0x10000) still match too. This is a constant-fold of the chains this lowerer builds, not a GPU run. AI-assisted; tests run on this machine.
upstream-sync closed this pull request 2026-11-25 01:04:32 +00:00
Marvisak commented 2026-11-25 01:07:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:26:26Z.


Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #498. Same two VALU instructions as #498 with the same M0 split, plus s_movrelsd_2_b32 and register tracking in ir.rs that main's range.rs has since reworked (e0034c2a). Its description of the semantics does not match its own code. No title use.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148511869 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/627#issuecomment-7148511869). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:26:26Z. --- Automated triage for the maintainers. Closing because another open pull request covers the same change. See #498. Same two VALU instructions as #498 with the same M0 split, plus s_movrelsd_2_b32 and register tracking in ir.rs that main's range.rs has since reworked (e0034c2a). Its description of the semantics does not match its own code. No title use. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!627
No description provided.