Recompiler: fix NULL dest, B32 SAVEEXEC, and MIMG TFE/LWE in upper_lanes #2136

Open
github-bot wants to merge 1 commit from github-bot/gh-2136 into main AGit
Owner

@⁠Decodere on GitHub · 2026-11-25 05:48 UTC · original
Decodere:fix-336-upper-lanes-soundness → main · +124 −10 · 1 files · 1 commits · open

What is in it

Fixes three soundness bugs in wave64-on-wave32 upper-lane analysis (crates/xcl/src/gpu/recomp/upper_lanes.rs):

  1. SDST == 125 (NULL) on 64-bit / multi-dword SGPR writes clobbered EXEC_LO (s126) and EXEC_HI (s127):
    • In step(), 64-bit SAVEEXEC/WREXEC writes and 64-bit ENC_SOP1/ENC_SOP2 writes called st.set(dst + 1, ...) even when dst == 125 (NULL), overwriting st.s[126] (EXEC_LO) — for example, S_OR_SAVEEXEC_B64 null, -1 overwrote EXEC_LO with saved EXEC_HI (Word::Zero). Guarded both paths with dst != 125 and avoided reading dst + 1 in CMOV when dst == 125.
    • In sgpr_outputs(), generic SGPR outputs (v < 128) and SDWA V_CMP_* outputs (SD == 1) pushed NULL (125) with multi-dword sizes, causing VOP3/SDWA V_CMP_* null, ... to clobber s126 (EXEC_LO) and S_LOAD_DWORDX4 null, ... to clobber both s126 and s127 (EXEC_HI). Skipped 125 in both output paths.
  2. 32-bit SAVEEXEC/WREXEC read SSRC0 via st.src64() instead of st.src32():
    • st.src64() maps 124 (M0) and 127 (EXEC_HI) to Word::Any, losing tracked Word state on instructions such as S_AND_SAVEEXEC_B32 s0, exec_hi and S_OR_SAVEEXEC_B32 s0, m0. Now uses st.src32(d, fv("SSRC0")) when !b64, matching the ENC_SOP1/ENC_SOP2 path below it.
  3. vgpr_writes() missed the 5th VGPR (vdata + 4) on MIMG loads/samples/gathers with TFE = 1 or LWE = 1:
    • The operand table lists 4 VGPRs for VDATA, so when DMASK = 0xF (or IMAGE_GATHER4) with D16 = 0 and TFE = 1 or LWE = 1 gave n = 5, w.truncate(5) still returned only 4 registers and left vdata + 4 untracked (allowing stale constants in vdata + 4 to survive an image load under WWM). Rebuilds w as (base..(base + n).min(256)).collect().

Adds three deterministic CPU unit tests in gpu::recomp::upper_lanes::tests covering all three bugs.

Part of #336

Tested

Hardware/toolchain: Windows 11 (26200), NVIDIA GeForce RTX 4060 (32-lane waves, driver 621.14), DXC 1.9.2609.5 (01b62ad4), Rust 1.100.0.

  • Verified pre-fix failures on the 3 new regression tests before applying the fixes (null_dst_multi_dword_writes_preserve_exec: Const(0) instead of Const(u32::MAX); saveexec_b32_reads_32bit_special_sources: Unknown instead of Const(0); mimg_tfe_and_lwe_write_fifth_vgpr: [4, 5, 6, 7] instead of [4, 5, 6, 7, 8]).
  • cargo test --release -p xcl --lib gpu::recomp::upper_lanes::tests::: 12 passed, 0 failed, 0 ignored (pure CPU, CI WARP-safe).
  • cargo test --release -p xcl --lib gpu::recomp::partition::tests::: 44 passed, 0 failed, 0 ignored (pure CPU).
  • cargo build --release --workspace: exit 0.
  • cargo test --release --workspace -- --test-threads=4: 1157 passed, 0 failed, 46 ignored across 21 test suites, with 25 pre-existing runtime SKIPPED lines (23 native wave64 / unsupported per-lane lowering skips on 32-lane RTX 4060, 1 Windows driver-cache skip, 1 heap-window skip; 0 new skips).

Regression run

Paired 60-second scripts/smoke.ps1 runs on the same retail title build (29640639) from clean origin/main (6e1e2be) and this branch (f1e281b):

Base (origin/main):

xcl-smoke v1
commit: 6e1e2befc7430126b1e7b98b5c3fe93813c866b6
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1616 (PresentX 1617)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14507 MB

PR (fix-336-upper-lanes-soundness):

xcl-smoke v1
commit: f1e281b2e13cd9fc4efe5ba87410049b38e25f7a
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1562 (PresentX 1562)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14519 MB

Not tested

  • Native 64-lane wave64 GPU hardware (the test GPU is a 32-lane NVIDIA RTX 4060; upper_lanes is specifically the wave64-on-wave32 forward analysis and all new tests are deterministic CPU unit tests).
  • Non-Windows host platforms.

AI use

Drafted with Google Antigravity (Gemini 4 Neon) and verified locally by reproducing all three failures before the fix, verifying upper_lanes::tests and partition::tests, running the full release workspace test suite, and completing the paired 60-second smoke run above.

**@⁠Decodere** on GitHub · 2026-11-25 05:48 UTC · [original](https://github.com/xcl-dev/xcl/pull/2136) `Decodere:fix-336-upper-lanes-soundness` → `main` · +124 −10 · 1 files · 1 commits · open **What is in it** Fixes three soundness bugs in wave64-on-wave32 upper-lane analysis (`crates/xcl/src/gpu/recomp/upper_lanes.rs`): 1. **`SDST == 125` (`NULL`) on 64-bit / multi-dword SGPR writes clobbered `EXEC_LO` (`s126`) and `EXEC_HI` (`s127`)**: - In `step()`, 64-bit `SAVEEXEC`/`WREXEC` writes and 64-bit `ENC_SOP1`/`ENC_SOP2` writes called `st.set(dst + 1, ...)` even when `dst == 125` (`NULL`), overwriting `st.s[126]` (`EXEC_LO`) — for example, `S_OR_SAVEEXEC_B64 null, -1` overwrote `EXEC_LO` with saved `EXEC_HI` (`Word::Zero`). Guarded both paths with `dst != 125` and avoided reading `dst + 1` in `CMOV` when `dst == 125`. - In `sgpr_outputs()`, generic SGPR outputs (`v < 128`) and SDWA `V_CMP_*` outputs (`SD == 1`) pushed `NULL` (`125`) with multi-dword sizes, causing VOP3/SDWA `V_CMP_* null, ...` to clobber `s126` (`EXEC_LO`) and `S_LOAD_DWORDX4 null, ...` to clobber both `s126` and `s127` (`EXEC_HI`). Skipped `125` in both output paths. 2. **32-bit `SAVEEXEC`/`WREXEC` read `SSRC0` via `st.src64()` instead of `st.src32()`**: - `st.src64()` maps `124` (`M0`) and `127` (`EXEC_HI`) to `Word::Any`, losing tracked `Word` state on instructions such as `S_AND_SAVEEXEC_B32 s0, exec_hi` and `S_OR_SAVEEXEC_B32 s0, m0`. Now uses `st.src32(d, fv("SSRC0"))` when `!b64`, matching the `ENC_SOP1`/`ENC_SOP2` path below it. 3. **`vgpr_writes()` missed the 5th VGPR (`vdata + 4`) on `MIMG` loads/samples/gathers with `TFE = 1` or `LWE = 1`**: - The operand table lists 4 VGPRs for `VDATA`, so when `DMASK = 0xF` (or `IMAGE_GATHER4`) with `D16 = 0` and `TFE = 1` or `LWE = 1` gave `n = 5`, `w.truncate(5)` still returned only 4 registers and left `vdata + 4` untracked (allowing stale constants in `vdata + 4` to survive an image load under `WWM`). Rebuilds `w` as `(base..(base + n).min(256)).collect()`. Adds three deterministic CPU unit tests in `gpu::recomp::upper_lanes::tests` covering all three bugs. Part of #336 **Tested** Hardware/toolchain: Windows 11 (26200), NVIDIA GeForce RTX 4060 (32-lane waves, driver 621.14), DXC `1.9.2609.5 (01b62ad4)`, Rust `1.100.0`. - Verified pre-fix failures on the 3 new regression tests before applying the fixes (`null_dst_multi_dword_writes_preserve_exec`: `Const(0)` instead of `Const(u32::MAX)`; `saveexec_b32_reads_32bit_special_sources`: `Unknown` instead of `Const(0)`; `mimg_tfe_and_lwe_write_fifth_vgpr`: `[4, 5, 6, 7]` instead of `[4, 5, 6, 7, 8]`). - `cargo test --release -p xcl --lib gpu::recomp::upper_lanes::tests::`: **12 passed, 0 failed, 0 ignored** (pure CPU, CI WARP-safe). - `cargo test --release -p xcl --lib gpu::recomp::partition::tests::`: **44 passed, 0 failed, 0 ignored** (pure CPU). - `cargo build --release --workspace`: exit 0. - `cargo test --release --workspace -- --test-threads=4`: **1157 passed, 0 failed, 46 ignored** across 21 test suites, with 25 pre-existing runtime `SKIPPED` lines (23 native wave64 / unsupported per-lane lowering skips on 32-lane RTX 4060, 1 Windows driver-cache skip, 1 heap-window skip; 0 new skips). **Regression run** Paired 60-second `scripts/smoke.ps1` runs on the same retail title build (`29640639`) from clean `origin/main` (`6e1e2be`) and this branch (`f1e281b`): Base (`origin/main`): ``` xcl-smoke v1 commit: 6e1e2befc7430126b1e7b98b5c3fe93813c866b6 gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1616 (PresentX 1617) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14507 MB ``` PR (`fix-336-upper-lanes-soundness`): ``` xcl-smoke v1 commit: f1e281b2e13cd9fc4efe5ba87410049b38e25f7a gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1562 (PresentX 1562) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14519 MB ``` **Not tested** - Native 64-lane wave64 GPU hardware (the test GPU is a 32-lane NVIDIA RTX 4060; `upper_lanes` is specifically the wave64-on-wave32 forward analysis and all new tests are deterministic CPU unit tests). - Non-Windows host platforms. **AI use** Drafted with Google Antigravity (Gemini 4 Neon) and verified locally by reproducing all three failures before the fix, verifying `upper_lanes::tests` and `partition::tests`, running the full release workspace test suite, and completing the paired 60-second smoke run above.
Fix three soundness bugs in wave64-on-wave32 upper-lane analysis
(crates/xcl/src/gpu/recomp/upper_lanes.rs):

- NULL (125) multi-dword SGPR writes: guard dst != 125 for 64-bit
  SAVEEXEC/WREXEC and SOP1/SOP2 writes (and avoid reading dst+1 in CMOV),
  and skip v == 125 / SDST == 125 in sgpr_outputs() so writes to NULL
  (such as S_OR_SAVEEXEC_B64 null, S_MOV_B64 null, V_CMP null, and
  S_LOAD_DWORDX4 null) do not clobber EXEC_LO (s126) or EXEC_HI (s127).
- 32-bit SAVEEXEC/WREXEC sources: read SSRC0 through st.src32() instead of
  st.src64() when !b64 so M0 (124) and EXEC_HI (127) retain their tracked
  Word state.
- MIMG TFE/LWE 5th VGPR: rebuild vgpr_writes() over base..(base + n).min(256)
  instead of truncating the 4-register table entry, so IMAGE_SAMPLE /
  IMAGE_LOAD / IMAGE_GATHER4 with DMASK=0xF (D16=0) and TFE=1 or LWE=1
  report the 5th VGPR (vdata + 4).

Part of #336

Assisted-by: Google Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:20:13 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 06:49 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 06:49 UTC · [original](https://github.com/xcl-dev/xcl/pull/2136#issuecomment-7155192760) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2136/head:github-bot/gh-2136'
git switch 'github-bot/gh-2136'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2136'
git switch 'github-bot/gh-2136'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2136'
git switch 'github-bot/gh-2136'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2136'
git switch 'main'
git merge --squash 'github-bot/gh-2136'
git switch 'main'
git merge --ff-only 'github-bot/gh-2136'
git switch 'main'
git merge 'github-bot/gh-2136'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.