Recompiler: scalars written behind a vote and read after it are partition-dependent (#336) #523

Closed
emirduran707 wants to merge 2 commits from upstream-pr/528 into main
emirduran707 commented 2026-11-24 01:23:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-24T01:23:38Z.


Stacked on #517 (which is stacked on #341); only the top commit (741efd7) belongs here. Part of #336.

A half whose mask is empty takes the other side of a vote (or skips its lane-masked side), so it never runs the scalar code the wave runs there. A scalar that code writes and that is read after the sides join holds something else in that half – one of the ways #517 left to follow. Classification only: nothing translates by it yet.

What is in it

  • gpu/recomp/partition.rs: classify runs its data-flow pass twice. The first finds the votes – branches on a mask, unless every half has lanes and votes as the wave does (the launch EXEC, or a mask that is all or none of its lanes) – and the scalars written in the blocks each one decides (SGPRs, VCC, M0, SCC; not EXEC, which the join restores), from cfg's control dependence with nested branches' blocks included. The second marks those scalars stale where the vote's sides join; a stale value reaching an export, a store, a branch or EXEC is the new reason stale-scalar.
  • Tests: a scalar written behind an EXEC vote and read after the join (and the same not read: exact); a scalar behind a vote every half takes as the wave.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.31044.16; Ryzen 5 5600, 32 GB; Windows 11 Pro 26300; rustc 1.100.0 x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug for the suite, release for the runs.
  • cargo test --workspace -- --test-threads=4 at 741efd7: 700 passed, 0 failed, 41 ignored; no SKIPPED lines.
  • Over the 13 210 wave64 VS / PS of a retail shader pack (a local test, not committed; release, one thread): 8 767 Exact (was 9 424 with #517 alone: 6 620 of 10 974 PS, 2 147 of 2 236 VS); stale-scalar in 2 468 programs; no panic; at most 99 ms for one program (two passes; nothing calls this on a title's path yet).

Regression run

Nothing in the runtime calls the new code, so this only shows the build is unchanged in use. The gpu: line names a virtual display adapter of this machine (what #281 / #282 / #285 fix); XCL's log names backend 'real' – AMD Radeon RX 9060 XT (16188 MiB VRAM).

main:

xcl-smoke v1
commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1382 (PresentX 1382)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14751 MB

PR:

xcl-smoke v1
commit: 741efd798a50b3d75e011c54e9e5790b1fd3894f
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1401 (PresentX 1401)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14736 MB

Not tested

  • Whether the flagged programs actually differ on a 32-lane GPU (no 64-lane reference yet).
  • NVIDIA (nothing here runs on the GPU).

AI use

  • Claude Code with Claude Opus 5.5: wrote the code, the tests and this description; the runs above were made on my machine.
<!-- greyfinch-sync:ivall/xcl:issue:6572461642 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/528). Originally posted by [emirduran707](https://github.com/emirduran707) on 2026-11-24T01:23:38Z. --- Stacked on #517 (which is stacked on #341); only the top commit (741efd7) belongs here. Part of #336. A half whose mask is empty takes the other side of a vote (or skips its lane-masked side), so it never runs the scalar code the wave runs there. A scalar that code writes and that is read after the sides join holds something else in that half – one of the ways #517 left to follow. Classification only: nothing translates by it yet. **What is in it** - `gpu/recomp/partition.rs`: `classify` runs its data-flow pass twice. The first finds the votes – branches on a mask, unless every half has lanes and votes as the wave does (the launch EXEC, or a mask that is all or none of its lanes) – and the scalars written in the blocks each one decides (SGPRs, VCC, M0, SCC; not EXEC, which the join restores), from `cfg`'s control dependence with nested branches' blocks included. The second marks those scalars stale where the vote's sides join; a stale value reaching an export, a store, a branch or EXEC is the new reason `stale-scalar`. - Tests: a scalar written behind an EXEC vote and read after the join (and the same not read: exact); a scalar behind a vote every half takes as the wave. **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.31044.16; Ryzen 5 5600, 32 GB; Windows 11 Pro 26300; rustc 1.100.0 `x86_64-pc-windows-msvc`; DXC 1.9.2602.17; debug for the suite, release for the runs. - `cargo test --workspace -- --test-threads=4` at 741efd7: 700 passed, 0 failed, 41 ignored; no `SKIPPED` lines. - Over the 13 210 wave64 VS / PS of a retail shader pack (a local test, not committed; release, one thread): 8 767 Exact (was 9 424 with #517 alone: 6 620 of 10 974 PS, 2 147 of 2 236 VS); `stale-scalar` in 2 468 programs; no panic; at most 99 ms for one program (two passes; nothing calls this on a title's path yet). **Regression run** Nothing in the runtime calls the new code, so this only shows the build is unchanged in use. The `gpu:` line names a virtual display adapter of this machine (what #281 / #282 / #285 fix); XCL's log names `backend 'real' – AMD Radeon RX 9060 XT (16188 MiB VRAM)`. main: ``` xcl-smoke v1 commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212 gpu: AMD Radeon RX 9060 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1382 (PresentX 1382) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14751 MB ``` PR: ``` xcl-smoke v1 commit: 741efd798a50b3d75e011c54e9e5790b1fd3894f gpu: AMD Radeon RX 9060 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1401 (PresentX 1401) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14736 MB ``` **Not tested** - Whether the flagged programs actually differ on a 32-lane GPU (no 64-lane reference yet). - NVIDIA (nothing here runs on the GPU). **AI use** - Claude Code with Claude Opus 5.5: wrote the code, the tests and this description; the runs above were made on my machine.
upstream-sync closed this pull request 2026-11-24 06:58:47 +00:00
towiice commented 2026-11-24 06:58:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by towiice on 2026-11-24T01:32:42Z.

Review: COMMENTED


Tested PR head 741efd7 on NVIDIA GeForce GTX 1650 SUPER (Turing / TU116, wave32, driver 610.88), Windows 11 build 10.0.26300 (26H2), Rust 1.100.0 (stable-x86_64-pc-windows-gnullvm), DXC v1.9.2609:

  • cargo test -p xcl --lib a_scalar_ -- --test-threads=4: 5 passed, 0 failed (0.01 s), including gpu::recomp::partition::tests::a_scalar_written_behind_a_vote_and_read_after_the_join_may_differ and a_scalar_behind_a_vote_every_half_takes_as_the_wave_is_exact.

Builds and passes cleanly on gnullvm.

<!-- greyfinch-sync:ivall/xcl:review:6032290348 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/528#pullrequestreview-6032290348). Originally posted by [towiice](https://github.com/towiice) on 2026-11-24T01:32:42Z. **Review:** COMMENTED --- Tested PR head `741efd7` on **NVIDIA GeForce GTX 1650 SUPER** (Turing / TU116, wave32, driver 610.88), Windows 11 build 10.0.26300 (26H2), Rust 1.100.0 (`stable-x86_64-pc-windows-gnullvm`), DXC `v1.9.2609`: - `cargo test -p xcl --lib a_scalar_ -- --test-threads=4`: **5 passed, 0 failed** (0.01 s), including `gpu::recomp::partition::tests::a_scalar_written_behind_a_vote_and_read_after_the_join_may_differ` and `a_scalar_behind_a_vote_every_half_takes_as_the_wave_is_exact`. Builds and passes cleanly on `gnullvm`.
4MDomo commented 2026-11-24 07:05:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by 4MDomo on 2026-11-24T01:53:35Z.


NVIDIA test report for 741efd7 (this PR's head, #517 and #341 included).

Tested

  • NVIDIA GeForce RTX 3070 (32-lane waves only), driver 32.0.16.1742; Intel i9-9900K, 32 GB; Windows 11 Home 10.0.26300; rustc 1.98.1 stable-x86_64-pc-windows-msvc; DXC 1.8.2502.11 (Windows SDK 10.0.26100.0); debug.
  • cargo test --workspace -- --test-threads=4 at 741efd7: 700 passed, 0 failed, 41 ignored (the same 700 as on the RX 9060 XT).
  • SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware. Same as main 508a0c7.

Not tested

  • The shader-pack counts (no retail shader pack here).

AI use

  • Claude Code (Claude Opus 5.5) ran the suite and wrote this report; checked by me.
<!-- greyfinch-sync:ivall/xcl:comment:7119553437 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/528#issuecomment-7119553437). Originally posted by [4MDomo](https://github.com/4MDomo) on 2026-11-24T01:53:35Z. --- NVIDIA test report for 741efd7 (this PR's head, #517 and #341 included). **Tested** - NVIDIA GeForce RTX 3070 (32-lane waves only), driver 32.0.16.1742; Intel i9-9900K, 32 GB; Windows 11 Home 10.0.26300; rustc 1.98.1 `stable-x86_64-pc-windows-msvc`; DXC 1.8.2502.11 (Windows SDK 10.0.26100.0); debug. - `cargo test --workspace -- --test-threads=4` at 741efd7: 700 passed, 0 failed, 41 ignored (the same 700 as on the RX 9060 XT). - SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. Same as `main` 508a0c7. **Not tested** - The shader-pack counts (no retail shader pack here). **AI use** - Claude Code (Claude Opus 5.5) ran the suite and wrote this report; checked by me.
tugasky commented 2026-11-24 07:05:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by tugasky on 2026-11-24T02:12:42Z.


Same harness as the #517 census, run again on this stack, so the numbers below are a
delta over the same 13 210 programs of the same retail pack, not a separate sample.

Machine: Windows 11 Pro 26300, Ryzen 7 9700X (8C/16T), Rust 1.98.0
x86_64-pc-windows-msvc, DXC 1.9.2602.17, Radeon RX 9070 XT (RDNA4, 16 GB), driver
32.0.32029.2010. Release build, 741efd7 merged into 7ebf1b8 (the stack's base is
a6f5f7a, three commits behind main; the merge touches only README and
title_textures.rs, so partition.rs is the PR's).

stage Exact with #517 Exact with #528 MayDiffer stale-scalar slowest program
PS 7 248 6 620 (60.3 %) 4 354 2 416 82.2 ms
VS 2 176 2 147 (96.0 %) 89 52 48.7 ms
total 9 424 8 767 (66.4 %) 4 443 2 468 82.2 ms

Your 8 767 / 6 620 / 2 147 and stale-scalar in 2 468 programs come out here exactly.
13 034 distinct programs still, 8 598 distinct Exact (was 9 255), so the 657 newly gated
programs are 657 distinct ones – no program is counted twice in that drop. No panic,
0 undecoded dwords, 0 no-graph.

What the 657 cost, attributed. 447 of them (68.0 %) are gated by stale-scalar alone
(442 PS + 5 VS). The other 210 carry stale-scalar+tainted-exec and nothing else
(186 PS + 24 VS), which is the rule doing what it should: the stale scalar also reaches
EXEC or a branch, so control is tainted too. That accounts for the second finding –
tainted-exec is the only other reason that moves, 2 215 → 2 612 (+397): 210 are those
newly gated programs, the remaining 187 are programs that were already MayDiffer and
whose stale scalar now also taints control. Every other reason is unchanged to the
program: cross-lane 2 473, vote-branch 1 817, unsafe-execz-branch 1 443,
mask-data 619, lane-count 432, first-lane 353, lane-id 186. So the rule is
purely additive on this corpus, and its cost is 657 programs, not 2 468 – the other
2 011 already differed for another reason.

Order of the remaining parts of #336 is now measurable the same way (programs whose
only reason is this one): unsafe-execz-branch 744, then stale-scalar 447 (the ones
this PR adds), vote-branch 206, cross-lane 150, lane-count 40, mask-data 6. The
EXECZ/EXECNZ rule is still first.

Cost: 65.2 s of classify time over the 13 210 programs, against 24.6 s and 26.8 s in
two runs of #517 alone on this machine (mean 4.9 ms, slowest program 82.2 ms; your machine
reports 99 ms). Fine for a census, and worth knowing before anything calls this on a
title's path.

Suite: cargo build --workspace --release, then
cargo test --workspace --release -- --test-threads=4 → 701 passed, 0 failed, 41
ignored
, no test skipped (your 700 plus the one test #486 adds on main). The 17
partition::tests pass on their own as well.

Not tested (same as you): whether the flagged programs actually differ on a 32-lane
GPU, and NVIDIA.

No game data in this comment – only counts printed by the tool.

AI use: written with Cline; the runs are from my machine.

<!-- greyfinch-sync:ivall/xcl:comment:7119871196 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/528#issuecomment-7119871196). Originally posted by [tugasky](https://github.com/tugasky) on 2026-11-24T02:12:42Z. --- Same harness as the #517 census, run again on this stack, so the numbers below are a delta over the same 13 210 programs of the same retail pack, not a separate sample. **Machine:** Windows 11 Pro 26300, Ryzen 7 9700X (8C/16T), Rust 1.98.0 `x86_64-pc-windows-msvc`, DXC 1.9.2602.17, Radeon RX 9070 XT (RDNA4, 16 GB), driver 32.0.32029.2010. Release build, `741efd7` merged into `7ebf1b8` (the stack's base is a6f5f7a, three commits behind `main`; the merge touches only README and `title_textures.rs`, so `partition.rs` is the PR's). | stage | Exact with #517 | Exact with #528 | MayDiffer | `stale-scalar` | slowest program | |:--|--:|--:|--:|--:|--:| | PS | 7 248 | **6 620** (60.3 %) | 4 354 | 2 416 | 82.2 ms | | VS | 2 176 | **2 147** (96.0 %) | 89 | 52 | 48.7 ms | | total | 9 424 | **8 767** (66.4 %) | 4 443 | 2 468 | 82.2 ms | Your 8 767 / 6 620 / 2 147 and `stale-scalar` in 2 468 programs come out here exactly. 13 034 distinct programs still, 8 598 distinct Exact (was 9 255), so the 657 newly gated programs are 657 *distinct* ones – no program is counted twice in that drop. No panic, 0 undecoded dwords, 0 `no-graph`. **What the 657 cost, attributed.** 447 of them (68.0 %) are gated by `stale-scalar` alone (442 PS + 5 VS). The other 210 carry `stale-scalar+tainted-exec` and nothing else (186 PS + 24 VS), which is the rule doing what it should: the stale scalar also reaches EXEC or a branch, so control is tainted too. That accounts for the second finding – `tainted-exec` is the only other reason that moves, 2 215 → 2 612 (+397): 210 are those newly gated programs, the remaining 187 are programs that were already MayDiffer and whose stale scalar now also taints control. Every other reason is unchanged to the program: `cross-lane` 2 473, `vote-branch` 1 817, `unsafe-execz-branch` 1 443, `mask-data` 619, `lane-count` 432, `first-lane` 353, `lane-id` 186. So the rule is purely additive on this corpus, and its cost is 657 programs, not 2 468 – the other 2 011 already differed for another reason. **Order of the remaining parts of #336** is now measurable the same way (programs whose only reason is this one): `unsafe-execz-branch` 744, then `stale-scalar` 447 (the ones this PR adds), `vote-branch` 206, `cross-lane` 150, `lane-count` 40, `mask-data` 6. The EXECZ/EXECNZ rule is still first. **Cost:** 65.2 s of classify time over the 13 210 programs, against 24.6 s and 26.8 s in two runs of #517 alone on this machine (mean 4.9 ms, slowest program 82.2 ms; your machine reports 99 ms). Fine for a census, and worth knowing before anything calls this on a title's path. **Suite:** `cargo build --workspace --release`, then `cargo test --workspace --release -- --test-threads=4` → **701 passed, 0 failed, 41 ignored**, no test skipped (your 700 plus the one test #486 adds on `main`). The 17 `partition::tests` pass on their own as well. **Not tested (same as you):** whether the flagged programs actually differ on a 32-lane GPU, and NVIDIA. No game data in this comment – only counts printed by the tool. **AI use:** written with Cline; the runs are from my machine.
emirduran707 commented 2026-11-24 07:05:34 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-24T02:26:03Z.


Folded into #517 (ad4add0) after its review: leaving the stale-scalar rule to a later PR made #517 report Exact for programs that differ.

AI use: Claude Code with Claude Opus 5.5 wrote this note.

<!-- greyfinch-sync:ivall/xcl:comment:7120137191 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/528#issuecomment-7120137191). Originally posted by [emirduran707](https://github.com/emirduran707) on 2026-11-24T02:26:03Z. --- Folded into #517 (ad4add0) after its review: leaving the stale-scalar rule to a later PR made #517 report Exact for programs that differ. AI use: Claude Code with Claude Opus 5.5 wrote this note.

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!523
No description provided.