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

Closed
b3IKK wants to merge 1 commit from upstream-pr/1726 into main
b3IKK commented 2026-11-24 19:56:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T19:56:51Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:6590217456 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1726). Originally posted by [b3IKK](https://github.com/b3IKK) on 2026-11-24T19:56:51Z. --- 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.
upipibi commented 2026-11-24 21:09:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T20:06:01Z.


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).

<!-- greyfinch-sync:ivall/xcl:comment:7143040314 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1726#issuecomment-7143040314). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T20:06:01Z. --- 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).
b3IKK commented 2026-11-24 22:06:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T21:47:00Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7145381205 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1726#issuecomment-7145381205). Originally posted by [b3IKK](https://github.com/b3IKK) on 2026-11-24T21:47:00Z. --- Rebased onto 1d027e5 and re-ran both with the current scripts/smoke.ps1 (#677's hashed itle: line): 960 passed, 0 failed, 43 ignored.
DavidM1911 commented 2026-11-24 23:08:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T22:37:41Z.


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

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

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7146456501 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1726#issuecomment-7146456501). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T22:37:41Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~23 ignored. Thanks!
upstream-sync closed this pull request 2026-11-25 00:07:36 +00:00
b3IKK commented 2026-11-25 00:08:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T23:25:12Z.


@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.

<!-- greyfinch-sync:ivall/xcl:comment:7147377936 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1726#issuecomment-7147377936). Originally posted by [b3IKK](https://github.com/b3IKK) on 2026-11-24T23:25:12Z. --- @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.
upipibi commented 2026-11-25 00:09:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T23:42:15Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7147701108 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1726#issuecomment-7147701108). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T23:42:15Z. --- 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.
b3IKK commented 2026-11-25 00:09:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-25T00:03:53Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7148097667 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1726#issuecomment-7148097667). Originally posted by [b3IKK](https://github.com/b3IKK) on 2026-11-25T00:03:53Z. --- 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.
DavidM1911 commented 2026-11-26 07:03:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T06:17:10Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7184278454 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1726#issuecomment-7184278454). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T06:17:10Z. --- 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

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
xcl-dev/xcl!1716
No description provided.