Recompiler: upper lanes drop the scalar state past s_movrelsd_2_b32 #1726

Closed
github-bot wants to merge 1 commit from gh-pr/1726/head into gh-pr/1726/base
Owner

@⁠b3IKK on GitHub · 2026-11-24 19:56 UTC · original
b3IKK:recomp/upper-lanes-movrelsd → main · +29 −2 · 1 files · 1 commits · closed without merging

Addresses XCL-BT-037 from #1488.

upper_lanes::step treats s_movreld_b32 as writing any SGPR, because its destination is s[dst + m0], but not s_movrelsd_2_b32, whose destination is s[dst + m0[25:16]] (and its source s[src + m0[9:0]]). The scalar state it knew for a register the instruction may have written therefore survived: with a destination offset other than 0, the actual destination kept its constant, and an upper lane that read that register resolved to a wrong Read::Const.

This takes s_movrelsd_2_b32 with the s_movreld forms (the emitter and x64_masks already handle it that way).

Since the review (@⁠upipibi): the first version's test used m0 = 1, which is the source offset. That program writes s10 from s21 and leaves s11 alone, so main's Const(0) for s11 was the right answer and the test only passed because the fix forgets every SGPR. The description's "fails on main" was true and proved nothing about the bug. The test now uses m0 = 0x10000 (destination offset 1): s_movrelsd_2_b32 s10, s20 writes s11 from s20, and main answers Const(0) where the register is unknown.

What is in it

  • crates/xcl/src/gpu/recomp/upper_lanes.rs: s_movrelsd_2_b32 invalidates the scalar state like s_movreld; test movrelsd_writes_a_register_its_dst_field_does_not_name (m0 = 0x10000, a constant in s11, s_movrelsd_2_b32 s10, s20 → the read must be Unknown), and the same shape with s_movreld_b32 and m0 = 1 asserting the existing behaviour.

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 976 passed, 0 failed, 45 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, no heap windows, and cannot disable the driver cache (Windows Developer Mode is required))
  • cargo test -p xcl --lib -- movrelsd_writes_a_register: 1 passed, 0 failed; with the one-line change reverted: 0 passed, 1 failed — left: [Const(0)], right: [Unknown]

Regression run

main (20cf130, clean tree, no local changes):

xcl-smoke v1
commit: 20cf13022f764208384c610c2ae6a3f4eed201a2
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1556 (PresentX 1556)
presents per 2 s (last 3): 24 21 54
device removals: 0
crashes: 0
peak commit: 19607 MB

PR (beb5438, clean tree, no local changes):

xcl-smoke v1
commit: beb5438898d5803c9db5c6e138e91cf541b7a83c
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1640 (PresentX 1640)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18412 MB

(The head is on 689f2db; main moved to 20cf130 while the suite ran, and the main block is that commit, run right after the PR's. Both peak higher than the blocks this PR had before, 14.5 GB: several long runs of the title on this machine in between filled its caches, and its runs now commit 17–20 GB in the first minute whatever the build. I have not isolated why.)

Not tested

  • a real console shader whose upper lanes read a register s_movrelsd_2_b32 re-targeted (the unit test builds the sequence directly)
  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Claude Fable 5.2: checked XCL-BT-037 against upper_lanes, the emitter and x64_masks, wrote the fix and test, corrected the test's offset after the review (and confirmed it then fails without the fix for the stated reason), rebased onto 689f2db, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.
**@⁠b3IKK** on GitHub · 2026-11-24 19:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/1726) `b3IKK:recomp/upper-lanes-movrelsd` → `main` · +29 −2 · 1 files · 1 commits · closed without merging Addresses `XCL-BT-037` from #1488. `upper_lanes::step` treats `s_movreld_b32` as writing any SGPR, because its destination is `s[dst + m0]`, but not `s_movrelsd_2_b32`, whose destination is `s[dst + m0[25:16]]` (and its source `s[src + m0[9:0]]`). The scalar state it knew for a register the instruction may have written therefore survived: with a destination offset other than 0, the actual destination kept its constant, and an upper lane that read that register resolved to a wrong `Read::Const`. This takes `s_movrelsd_2_b32` with the `s_movreld` forms (the emitter and `x64_masks` already handle it that way). **Since the review** (@⁠upipibi): the first version's test used `m0 = 1`, which is the *source* offset. That program writes `s10` from `s21` and leaves `s11` alone, so `main`'s `Const(0)` for `s11` was the right answer and the test only passed because the fix forgets every SGPR. The description's "fails on `main`" was true and proved nothing about the bug. The test now uses `m0 = 0x10000` (destination offset 1): `s_movrelsd_2_b32 s10, s20` writes `s11` from `s20`, and `main` answers `Const(0)` where the register is unknown. **What is in it** - `crates/xcl/src/gpu/recomp/upper_lanes.rs`: `s_movrelsd_2_b32` invalidates the scalar state like `s_movreld`; test `movrelsd_writes_a_register_its_dst_field_does_not_name` (`m0 = 0x10000`, a constant in `s11`, `s_movrelsd_2_b32 s10, s20` → the read must be `Unknown`), and the same shape with `s_movreld_b32` and `m0 = 1` asserting the existing behaviour. **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2609.5, debug (`scripts/test.ps1`) and release (`scripts/smoke.ps1`) - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 976 passed, 0 failed, 45 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, `no heap windows`, and `cannot disable the driver cache (Windows Developer Mode is required)`) - `cargo test -p xcl --lib -- movrelsd_writes_a_register`: 1 passed, 0 failed; with the one-line change reverted: 0 passed, 1 failed — `left: [Const(0)], right: [Unknown]` **Regression run** main (`20cf130`, clean tree, no local changes): ``` xcl-smoke v1 commit: 20cf13022f764208384c610c2ae6a3f4eed201a2 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1556 (PresentX 1556) presents per 2 s (last 3): 24 21 54 device removals: 0 crashes: 0 peak commit: 19607 MB ``` PR (`beb5438`, clean tree, no local changes): ``` xcl-smoke v1 commit: beb5438898d5803c9db5c6e138e91cf541b7a83c gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1640 (PresentX 1640) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 18412 MB ``` (The head is on `689f2db`; `main` moved to `20cf130` while the suite ran, and the main block is that commit, run right after the PR's. Both peak higher than the blocks this PR had before, 14.5 GB: several long runs of the title on this machine in between filled its caches, and its runs now commit 17–20 GB in the first minute whatever the build. I have not isolated why.) **Not tested** - a real console shader whose upper lanes read a register `s_movrelsd_2_b32` re-targeted (the unit test builds the sequence directly) - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Claude Fable 5.2: checked `XCL-BT-037` against `upper_lanes`, the emitter and `x64_masks`, wrote the fix and test, corrected the test's offset after the review (and confirmed it then fails without the fix for the stated reason), rebased onto `689f2db`, ran the test suite and `scripts/smoke.ps1` regression runs, and drafted this PR description.
upper_lanes::step treats s_movreld_b32 as writing any SGPR (its destination
is s[dst + m0]), but not s_movrelsd_2_b32, whose destination is
s[dst + m0[25:16]]. The analysis then kept a word it knew for a register
the instruction may have written (with m0 = 0x10000 the write lands on
s[dst + 1], not on the SDST field), and an upper lane that read it took a
wrong constant.

Take it with the s_movreld forms, and test that a constant in s11 does not
survive s_movrelsd_2_b32 s10, s20 with m0 = 0x10000 (the destination
offset; m0 = 1 is the source offset and leaves s11 alone, as the review of
#1726 pointed out).

Assisted-by: OpenCode (Claude Fable 5.2)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:02:47 +00:00
github-bot closed this pull request 2026-11-26 05:02:47 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 20:06 UTC · original

The fix is right, but the test and the description use the wrong offset. s_movrelsd_2_b32 takes the source offset from M0[9:0] and the destination offset from M0[25:16]: SGPR[SDST + M0[25:16]] = SGPR[SSRC0 + M0[9:0]]. That is how emit.rs:1308 and dxil/lower.rs smovrel on main already lower it.

With m0 = 1, s_movrelsd_2_b32 s10, s20 writes s10 from s21. s11 is untouched, so main's Const(0) for s11 was the correct answer for that program. The test passes with the fix only because the fix forgets every SGPR, which is sound but less precise.

The case the PR is about needs the destination offset, m0 = 0x10000, which writes s11 from s20. I checked it at 8b20a4d (CPU-only test, the same program with Some(0x10000) as the m0 literal):

  • with the fix: [Unknown], passes;
  • with the one-line change reverted: left: [Const(0)], right: [Unknown], fails.

Using 0x10000 in the first case (and adjusting its comment and the description) would make the test fail on main for the stated reason.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-24 20:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/1726#issuecomment-7143040314) The fix is right, but the test and the description use the wrong offset. `s_movrelsd_2_b32` takes the source offset from M0[9:0] and the destination offset from M0[25:16]: `SGPR[SDST + M0[25:16]] = SGPR[SSRC0 + M0[9:0]]`. That is how `emit.rs:1308` and `dxil/lower.rs` `smovrel` on `main` already lower it. With `m0 = 1`, `s_movrelsd_2_b32 s10, s20` writes **s10** from s21. s11 is untouched, so `main`'s `Const(0)` for s11 was the correct answer for that program. The test passes with the fix only because the fix forgets every SGPR, which is sound but less precise. The case the PR is about needs the destination offset, `m0 = 0x10000`, which writes s11 from s20. I checked it at `8b20a4d` (CPU-only test, the same program with `Some(0x10000)` as the m0 literal): - with the fix: `[Unknown]`, passes; - with the one-line change reverted: `left: [Const(0)], right: [Unknown]`, fails. Using `0x10000` in the first case (and adjusting its comment and the description) would make the test fail on `main` for the stated reason. AI-assisted (Claude Code).
Author
Owner

@⁠b3IKK on GitHub · 2026-11-24 21:47 UTC · original

Rebased onto 1d027e5 and re-ran both with the current scripts/smoke.ps1 (#677's hashed itle: line): 960 passed, 0 failed, 43 ignored.

**@⁠b3IKK** on GitHub · 2026-11-24 21:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/1726#issuecomment-7145381205) Rebased onto 1d027e5 and re-ran both with the current scripts/smoke.ps1 (#677's hashed itle: line): 960 passed, 0 failed, 43 ignored.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 22:37 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 22:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/1726#issuecomment-7146456501) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~23 ignored. Thanks!
Author
Owner

@⁠b3IKK on GitHub · 2026-11-24 23:25 UTC · original

@⁠upipibi you are right, and I checked it against emit.rs ("s_movrelsd_2_b32" => (m0 & 0x3FF, (m0 >> 16) & 0x3FF)): the source offset is M0[9:0] and the destination offset M0[25:16]. With m0 = 1 my program wrote s10 from s21, s11 was untouched, and main's Const(0) was the correct answer. The test passed with the fix only because the fix forgets every SGPR, so "fails on main" in the description was true and showed nothing about the bug.

Pushed beb5438 (rebased onto 689f2db):

  • the first case uses m0 = 0x10000, so s_movrelsd_2_b32 s10, s20 writes s11 from s20;
  • comments, commit message and description now give the two offsets separately;
  • the s_movreld_b32 case keeps m0 = 1, which is that instruction's destination offset.

Same result as yours: with the fix [Unknown], with the one-line change reverted left: [Const(0)], right: [Unknown]. Suite: 976 passed, 0 failed, 45 ignored.

The fix itself is unchanged and still coarser than it could be (it forgets every SGPR, as s_movreld does, rather than only the registers M0[25:16] can reach). I left it that way to match the existing s_movreld handling.

AI use: OpenCode, Claude Fable 5.2 made the change, ran the tests and wrote this comment.

**@⁠b3IKK** on GitHub · 2026-11-24 23:25 UTC · [original](https://github.com/xcl-dev/xcl/pull/1726#issuecomment-7147377936) @⁠upipibi you are right, and I checked it against `emit.rs` (`"s_movrelsd_2_b32" => (m0 & 0x3FF, (m0 >> 16) & 0x3FF)`): the source offset is `M0[9:0]` and the destination offset `M0[25:16]`. With `m0 = 1` my program wrote `s10` from `s21`, `s11` was untouched, and `main`'s `Const(0)` was the correct answer. The test passed with the fix only because the fix forgets every SGPR, so "fails on `main`" in the description was true and showed nothing about the bug. Pushed `beb5438` (rebased onto `689f2db`): - the first case uses `m0 = 0x10000`, so `s_movrelsd_2_b32 s10, s20` writes `s11` from `s20`; - comments, commit message and description now give the two offsets separately; - the `s_movreld_b32` case keeps `m0 = 1`, which is that instruction's destination offset. Same result as yours: with the fix `[Unknown]`, with the one-line change reverted `left: [Const(0)], right: [Unknown]`. Suite: 976 passed, 0 failed, 45 ignored. The fix itself is unchanged and still coarser than it could be (it forgets every SGPR, as `s_movreld` does, rather than only the registers `M0[25:16]` can reach). I left it that way to match the existing `s_movreld` handling. AI use: OpenCode, Claude Fable 5.2 made the change, ran the tests and wrote this comment.
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 23:42 UTC · original

Checked beb5438 merged onto main 20cf130: the first case now writes s11 from s20 through m0 = 0x10000 (destination offset M0[25:16] = 1, source offset M0[9:0] = 0), as the ISA has it. Tests matching upper_lanes / movrel: 13 passed, 0 failed, including movrelsd_writes_a_register_its_dst_field_does_not_name. Thanks for fixing it up.

**@⁠upipibi** on GitHub · 2026-11-24 23:42 UTC · [original](https://github.com/xcl-dev/xcl/pull/1726#issuecomment-7147701108) Checked `beb5438` merged onto `main` `20cf130`: the first case now writes s11 from s20 through `m0 = 0x10000` (destination offset M0[25:16] = 1, source offset M0[9:0] = 0), as the ISA has it. Tests matching `upper_lanes` / `movrel`: 13 passed, 0 failed, including `movrelsd_writes_a_register_its_dst_field_does_not_name`. Thanks for fixing it up.
Author
Owner

@⁠b3IKK on GitHub · 2026-11-25 00:03 UTC · original

Closing in favour of #1616, which came first and makes the same change (#1607, group D46): S_MOVRELSD_2_B32 joins the S_MOVRELD arm of upper_lanes::step. One thing from the review here that may be useful there: the instruction's destination offset is M0[25:16] and its source offset M0[9:0], so a test of the register it re-targets needs m0 = 0x10000, not m0 = 1. AI use: OpenCode, Claude Fable 5.2.

**@⁠b3IKK** on GitHub · 2026-11-25 00:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/1726#issuecomment-7148097667) Closing in favour of #1616, which came first and makes the same change (#1607, group D46): `S_MOVRELSD_2_B32` joins the `S_MOVRELD` arm of `upper_lanes::step`. One thing from the review here that may be useful there: the instruction's destination offset is `M0[25:16]` and its source offset `M0[9:0]`, so a test of the register it re-targets needs `m0 = 0x10000`, not `m0 = 1`. AI use: OpenCode, Claude Fable 5.2.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 06:17 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 06:17 UTC · [original](https://github.com/xcl-dev/xcl/pull/1726#issuecomment-7184278454) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.