Recompiler: close four wave64-on-wave32 partition classifier soundness holes #2112

Open
Decodere wants to merge 1 commit from upstream-pr/2122 into main
Decodere commented 2026-11-25 05:13:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Decodere on 2026-11-25T05:13:42Z.


What is in it
Closes four soundness holes in the wave64-on-wave32 partition classifier (crates/xcl/src/gpu/recomp/partition.rs) where cut-dependent shaders were misclassified as Tier::Exact:

  • Per-lane mask taint & SRC2 handling (uses(), source_taint(), step()):
    • Propagates taint bits from u.lane_mask in step() so V_CNDMASK_B32 / V_ADD_CO_CI_U32 / V_SUB_CO_CI_U32 / V_SUBREV_CO_CI_U32 no longer drop LANE_ID / mask taint from their mask operand.
    • Distinguishes VOP3 SRC2 presence in uses(): decodes valid SGPR pairs including EXEC (126), excludes M0 (124) / NULL (125) / constants instead of mis-mapping them to VCC, and falls back to [VCC, VCC + 1] only for VOP2 forms without SRC2.
    • Flags non-lane selectors/carries on those four ops with MASK_DATA in source_taint() unless SRC2 is 0 / -1 / null (125 | 128 | 193) or a tracked st.lanes SGPR pair (or tracked VCC for VOP2).
  • WREXEC lane-set check (source_taint()): Includes n.contains("WREXEC") alongside SAVEEXEC in the bitwise lane-set check (and treats 125 null as a zero lane set), catching S_ANDN1_WREXEC_B64 / S_ANDN2_WREXEC_B64 with non-lane operands as mask-data.
  • Non-lane EXEC writes (step()): Computes lane_src / lanes_made (including checking SDST for S_CMOV_B*) before the writes_exec sink check, flagging any non-lane write to EXEC (e.g. S_MOV_B64 exec, s[0:1] where s[0:1] holds a number, S_CSELECT_B64 exec, 1, 0, S_CMOV_B64 exec, 1, S_NOT_B64 exec, 1) and single-word EXEC writes with MASK_DATA (both recording "mask-data" and tainting EXEC).
  • Complement SAVEEXEC & non-mask S_ANDN2* uniformity (step()): Replaces || n.contains("SAVEEXEC") in keeps_uniform with an explicit allowlist of non-complement ops (excluding S_NOR/S_NAND/S_XNOR/S_ORN1/S_ORN2/S_XOR_SAVEEXEC_B64), and requires S_ANDN2_* SSRC0 to be zero (125 | 128) or a tracked mask SGPR pair (st.mask[s] && st.mask[s + 1]) rather than -1 or a non-mask SGPR.
  • Adds 4 unit tests (with counter-examples and positive controls) in gpu::recomp::partition::tests.

Part of #336

Tested
Environment: Windows 11 Home 26200, Intel Core i5-11400F, 32 GB RAM, NVIDIA GeForce RTX 4060 8 GB (driver 621.14, wave32), Rust 1.100.0, DXC 1.9.2609.5 (01b62ad4).

  • Failing-first pre-fix check (cargo test -j 4 -p xcl --lib gpu::recomp::partition::tests -- --nocapture): 44 passed, 4 failed — all 4 new counter-example tests (lane_mask_taint_and_non_lane_selectors_are_caught, wrexec_with_non_lane_operand_is_mask_data, non_lane_exec_writes_are_mask_data, complement_saveexec_and_andn2_with_non_mask_are_not_uniform) returned [] (Tier::Exact) pre-fix.
  • Post-fix targeted tests (cargo test --release -p xcl --lib gpu::recomp::partition::tests -- --nocapture): 48 passed, 0 failed (pure CPU unit tests, CI WARP-safe).
  • Full release workspace build & test (cargo build --release --workspace and cargo test --release --workspace -- --test-threads=4 --nocapture): 1,158 passed, 0 failed, 46 ignored across 21 test binaries (1102 in xcl lib, 56 across the remaining 20 binaries), with 27 SKIPPED lines on this RTX 4060:
    • 20 no wave64 (RTX 4060 is wave32-only)
    • 3 per-lane form: refused (wave32 f16 arithmetic, f16 packed, f32 conversions)
    • 2 no d3d12SDKLayers.dll / no D3D12 debug layer
    • 1 cannot disable the driver cache (Windows Developer Mode not enabled)
    • 1 no heap windows

Regression run
Paired 60 s runs via scripts/smoke.ps1 on clean origin/main (f5c5bdf0) and clean PR head (ddcda018):

Main (f5c5bdf0e91035f8f1404f46f4f2f7aedc259e7f):

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

PR (ddcda0184c4fb347a1546f9c61be127c70795713):

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

Not tested

  • Native wave64 GPU execution (20 no wave64 skips on RTX 4060), D3D12 debug layer tests (2 skips without d3d12SDKLayers.dll), driver cache disable toggle (1 skip without Windows Developer Mode), and heap-window OOM fallback (1 skip without XCL_HEAP_WINDOWS).
  • Retail titles other than title: 29640639, and partition::classify is classification-only (not yet wired into runtime translation).

AI use
Google Antigravity (Gemini 4 Neon) wrote the partition.rs soundness fixes, unit tests, and this PR description. All pre-fix/post-fix unit tests, full release workspace tests, paired 60 s smoke runs, and scripts/pr_check.py --local validation were run locally on this machine.

<!-- greyfinch-sync:ivall/xcl:issue:5485592862 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2122). Originally posted by [Decodere](https://github.com/Decodere) on 2026-11-25T05:13:42Z. --- **What is in it** Closes four soundness holes in the wave64-on-wave32 partition classifier (`crates/xcl/src/gpu/recomp/partition.rs`) where cut-dependent shaders were misclassified as `Tier::Exact`: - **Per-lane mask taint & `SRC2` handling (`uses()`, `source_taint()`, `step()`):** - Propagates taint bits from `u.lane_mask` in `step()` so `V_CNDMASK_B32` / `V_ADD_CO_CI_U32` / `V_SUB_CO_CI_U32` / `V_SUBREV_CO_CI_U32` no longer drop `LANE_ID` / mask taint from their mask operand. - Distinguishes VOP3 `SRC2` presence in `uses()`: decodes valid SGPR pairs including `EXEC` (`126`), excludes `M0` (`124`) / `NULL` (`125`) / constants instead of mis-mapping them to `VCC`, and falls back to `[VCC, VCC + 1]` only for VOP2 forms without `SRC2`. - Flags non-lane selectors/carries on those four ops with `MASK_DATA` in `source_taint()` unless `SRC2` is `0` / `-1` / `null` (`125 | 128 | 193`) or a tracked `st.lanes` SGPR pair (or tracked `VCC` for VOP2). - **`WREXEC` lane-set check (`source_taint()`):** Includes `n.contains("WREXEC")` alongside `SAVEEXEC` in the bitwise lane-set check (and treats `125` `null` as a zero lane set), catching `S_ANDN1_WREXEC_B64` / `S_ANDN2_WREXEC_B64` with non-lane operands as `mask-data`. - **Non-lane `EXEC` writes (`step()`):** Computes `lane_src` / `lanes_made` (including checking `SDST` for `S_CMOV_B*`) before the `writes_exec` sink check, flagging any non-lane write to `EXEC` (e.g. `S_MOV_B64 exec, s[0:1]` where `s[0:1]` holds a number, `S_CSELECT_B64 exec, 1, 0`, `S_CMOV_B64 exec, 1`, `S_NOT_B64 exec, 1`) and single-word `EXEC` writes with `MASK_DATA` (both recording `"mask-data"` and tainting `EXEC`). - **Complement `SAVEEXEC` & non-mask `S_ANDN2*` uniformity (`step()`):** Replaces `|| n.contains("SAVEEXEC")` in `keeps_uniform` with an explicit allowlist of non-complement ops (excluding `S_NOR`/`S_NAND`/`S_XNOR`/`S_ORN1`/`S_ORN2`/`S_XOR_SAVEEXEC_B64`), and requires `S_ANDN2_*` `SSRC0` to be zero (`125 | 128`) or a tracked mask SGPR pair (`st.mask[s] && st.mask[s + 1]`) rather than `-1` or a non-mask SGPR. - Adds 4 unit tests (with counter-examples and positive controls) in `gpu::recomp::partition::tests`. Part of #336 **Tested** Environment: Windows 11 Home 26200, Intel Core i5-11400F, 32 GB RAM, NVIDIA GeForce RTX 4060 8 GB (driver 621.14, wave32), Rust 1.100.0, DXC `1.9.2609.5` (`01b62ad4`). - Failing-first pre-fix check (`cargo test -j 4 -p xcl --lib gpu::recomp::partition::tests -- --nocapture`): 44 passed, 4 failed — all 4 new counter-example tests (`lane_mask_taint_and_non_lane_selectors_are_caught`, `wrexec_with_non_lane_operand_is_mask_data`, `non_lane_exec_writes_are_mask_data`, `complement_saveexec_and_andn2_with_non_mask_are_not_uniform`) returned `[]` (`Tier::Exact`) pre-fix. - Post-fix targeted tests (`cargo test --release -p xcl --lib gpu::recomp::partition::tests -- --nocapture`): 48 passed, 0 failed (pure CPU unit tests, CI WARP-safe). - Full release workspace build & test (`cargo build --release --workspace` and `cargo test --release --workspace -- --test-threads=4 --nocapture`): 1,158 passed, 0 failed, 46 ignored across 21 test binaries (`1102` in `xcl` lib, `56` across the remaining 20 binaries), with 27 `SKIPPED` lines on this RTX 4060: - 20 `no wave64` (RTX 4060 is wave32-only) - 3 `per-lane form: refused` (wave32 f16 arithmetic, f16 packed, f32 conversions) - 2 `no d3d12SDKLayers.dll` / `no D3D12 debug layer` - 1 `cannot disable the driver cache` (Windows Developer Mode not enabled) - 1 `no heap windows` **Regression run** Paired 60 s runs via `scripts/smoke.ps1` on clean `origin/main` (`f5c5bdf0`) and clean PR head (`ddcda018`): Main (`f5c5bdf0e91035f8f1404f46f4f2f7aedc259e7f`): ``` xcl-smoke v1 commit: f5c5bdf0e91035f8f1404f46f4f2f7aedc259e7f gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1536 (PresentX 1536) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14486 MB ``` PR (`ddcda0184c4fb347a1546f9c61be127c70795713`): ``` xcl-smoke v1 commit: ddcda0184c4fb347a1546f9c61be127c70795713 gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1586 (PresentX 1586) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14522 MB ``` **Not tested** - Native wave64 GPU execution (20 `no wave64` skips on RTX 4060), D3D12 debug layer tests (2 skips without `d3d12SDKLayers.dll`), driver cache disable toggle (1 skip without Windows Developer Mode), and heap-window OOM fallback (1 skip without `XCL_HEAP_WINDOWS`). - Retail titles other than `title: 29640639`, and `partition::classify` is classification-only (not yet wired into runtime translation). **AI use** Google Antigravity (Gemini 4 Neon) wrote the `partition.rs` soundness fixes, unit tests, and this PR description. All pre-fix/post-fix unit tests, full release workspace tests, paired 60 s smoke runs, and `scripts/pr_check.py --local` validation were run locally on this machine.
DavidM1911 commented 2026-11-25 07:05:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T06:18:47Z.


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

  • cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7154661293 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2122#issuecomment-7154661293). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T06:18:47Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun. Thanks!
github-actions[bot] commented 2026-11-28 20:18:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-28T20:18:46Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7245193634 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2122#issuecomment-7245193634). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T20:18:46Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 07:25:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:25:19Z.


Triage (#1607) – head ddcda01

No other open PR changes partition.rs, and main has not touched the file since this PR's base (f5c5bdf), so none of the four fixes are on main yet.
No correctness problems found. The change makes the classifier more conservative: any EXEC write that is not a lane set (lanes_made), and any v_cndmask/carry-in selector that is not a lane set, is now mask-data, and complement SAVEEXEC forms no longer keep uniformity. More programs may leave the Exact tier, so a before/after tier count on a shader pack would show what this costs.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7304035618 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2122#issuecomment-7304035618). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T07:25:19Z. --- **Triage (#1607)** – head ddcda01 No other open PR changes `partition.rs`, and main has not touched the file since this PR's base (`f5c5bdf`), so none of the four fixes are on main yet. No correctness problems found. The change makes the classifier more conservative: any EXEC write that is not a lane set (`lanes_made`), and any v_cndmask/carry-in selector that is not a lane set, is now `mask-data`, and complement SAVEEXEC forms no longer keep uniformity. More programs may leave the Exact tier, so a before/after tier count on a shader pack would show what this costs. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Decodere commented 2026-12-02 07:47:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T07:47:09Z.


Keeping open: still fixes the four wave64-on-wave32 partition classifier soundness holes in crates/xcl/src/gpu/recomp/partition.rs; MERGEABLE/CLEAN with green CI and waiting for review / merge-checks. (AI note: checked with Antigravity, Gemini 4 Neon.)

<!-- greyfinch-sync:ivall/xcl:comment:7338606193 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2122#issuecomment-7338606193). Originally posted by [Decodere](https://github.com/Decodere) on 2026-12-02T07:47:09Z. --- Keeping open: still fixes the four wave64-on-wave32 partition classifier soundness holes in `crates/xcl/src/gpu/recomp/partition.rs`; `MERGEABLE`/`CLEAN` with green CI and waiting for review / merge-checks. (AI note: checked with Antigravity, Gemini 4 Neon.)
fromthemoonx commented 2026-12-02 21:01:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-02T21:01:46Z.


merge-check
base: 5ad98adbc3
head: ddcda0184c
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3009 passed, 0 failed, 52 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing: none
review: read the whole diff (1 file, +215 -23). No problem found in it. Two older gaps stay, see below.

  • The four new tests fail with main's code and pass with the PR's.
  • Extra check: I wrote a small CPU simulator (not pushed) that runs random programs as one 64-lane wave and as two 32-lane halves and compares each lane's export. 320,000 programs of 3 to 9 instructions (mask ops, saveexec / wrexec, compares, v_cndmask, forward branches; no loops, memory, WQM or DPP), 24 random inputs each:
    • called Exact although the result differs: main 49,863, this PR 90;
    • called Exact in total: main 173,269, this PR 108,386. For 20,555 programs that main calls Exact and this PR does not, I saw no difference (24 inputs do not prove there is none). Random programs are not typical shaders, so this says little about a real shader pack, which I do not have.
  • The 90 that are left come from two lines that main has too. Not blockers, and fine as a follow-up:
    • st.lanes[s] = st.mask[s] || lanes_made: a mask that s_cmov_b64 / s_cselect_b64 may have replaced by a number still counts as a set of lanes. With is_vcmp(d) || (is_valu(d) && n.contains("_CO_")) || lanes_made 6 of the 90 are left.
    • st.v[v] = t: a VGPR write under a narrowed EXEC drops the taint of the lanes that are off, which keep their old value. Example, Exact on main and here: v0 = v_mbcnt_lo(-1, 0), s_and_saveexec on a compare, v0 = 1.0, restore EXEC, export v0. With if st.exec_launch { t } else { t | st.v[v] } as well, 0 of 320,000 are left and the 48 partition tests pass.
  • No title was run here. Nothing calls partition::classify outside its tests yet.
    performance: none at run time, the classifier is not called yet.
    verdict: safe to merge
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
<!-- greyfinch-sync:ivall/xcl:comment:7358685253 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2122#issuecomment-7358685253). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-12-02T21:01:46Z. --- merge-check base: 5ad98adbc360225ac8a57ad9661e16fe8df9d8dd head: ddcda0184c4fb347a1546f9c61be127c70795713 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3009 passed, 0 failed, 52 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing: none review: read the whole diff (1 file, +215 -23). No problem found in it. Two older gaps stay, see below. - The four new tests fail with main's code and pass with the PR's. - Extra check: I wrote a small CPU simulator (not pushed) that runs random programs as one 64-lane wave and as two 32-lane halves and compares each lane's export. 320,000 programs of 3 to 9 instructions (mask ops, saveexec / wrexec, compares, v_cndmask, forward branches; no loops, memory, WQM or DPP), 24 random inputs each: - called Exact although the result differs: main 49,863, this PR 90; - called Exact in total: main 173,269, this PR 108,386. For 20,555 programs that main calls Exact and this PR does not, I saw no difference (24 inputs do not prove there is none). Random programs are not typical shaders, so this says little about a real shader pack, which I do not have. - The 90 that are left come from two lines that main has too. Not blockers, and fine as a follow-up: - `st.lanes[s] = st.mask[s] || lanes_made`: a mask that `s_cmov_b64` / `s_cselect_b64` may have replaced by a number still counts as a set of lanes. With `is_vcmp(d) || (is_valu(d) && n.contains("_CO_")) || lanes_made` 6 of the 90 are left. - `st.v[v] = t`: a VGPR write under a narrowed EXEC drops the taint of the lanes that are off, which keep their old value. Example, Exact on main and here: v0 = `v_mbcnt_lo(-1, 0)`, `s_and_saveexec` on a compare, v0 = 1.0, restore EXEC, export v0. With `if st.exec_launch { t } else { t | st.v[v] }` as well, 0 of 320,000 are left and the 48 `partition` tests pass. - No title was run here. Nothing calls `partition::classify` outside its tests yet. performance: none at run time, the classifier is not called yet. verdict: safe to merge hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2122:upstream-pr/2122'
git switch 'upstream-pr/2122'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2122'
git switch 'upstream-pr/2122'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2122'
git switch 'upstream-pr/2122'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2122'
git switch 'main'
git merge --squash 'upstream-pr/2122'
git switch 'main'
git merge --ff-only 'upstream-pr/2122'
git switch 'main'
git merge 'upstream-pr/2122'
git push origin 'main'
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!2112
No description provided.