Skip to content

Recompiler: classify wave64 VS / PS by whether a 32-lane cut changes them (#336) - #517

Merged
raylitebull merged 2 commits into
xcl-dev:mainfrom
emirduran707:wave64-partition
Nov 25, 2026
Merged

raylitebull merged 2 commits into
xcl-dev:mainfrom
emirduran707:wave64-partition

Conversation

@emirduran707

@emirduran707 emirduran707 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #341; only the top commit (dfc5578) belongs here. Part of #336. Reworked after the reviews below (QemmHD, CuteBooty, upipibi); #528 (stale scalars) is folded in.

A GPU that runs a console wave64 VS / PS in 32-lane waves runs each half of the console wave on its own. upper_lanes (#133) follows what lanes ≥ 32 hold when they are read; this classifies the other ways the cut shows: wave-wide votes are taken per half, and lane counts, ranks, first-lane indices, masks used as numbers and other lanes' values differ in a half. Classification only – nothing translates by it yet, so there is no behaviour change.

What is in it

  • gpu/recomp/partition.rs (new), partition::classify: a forward data-flow pass over the program's blocks (cfg, Recompiler: basic blocks, post-dominators and control dependence (#336) #341) with taint bits per register, run twice (the second with stale scalars), reporting Tier::Exact / Tier::MayDiffer and the reasons:
    • a tainted value reaching an export, a store (LDS / GDS included), a branch or EXEC; one word of EXEC, or a number, written to EXEC (lane-count, rank, first-lane, lane-id, mask-data, cross-lane, tainted-exec); DPP16 row / bank masks and v_writelane are lane-id, row_bcast is cross-lane, a number combined with a mask is mask-data;
    • a vote (vccz/vccnz, execz/execnz, scc on a mask) unless the side taken with the mask empty is the join or ends the program writing nothing, the other side starts by narrowing EXEC to the mask (for a mask other than EXEC) and does not widen it again before the join (a forward flow of the registers that are zero in a half that skipped the side, and of those that hold the EXEC it had at the vote: EXEC may be written only from the first, and must reach the join as the second) – or the mask is all or none of the active lanes (under a narrowed EXEC only if neither side widens EXEC before the join) (vote-branch, unsafe-execz-branch);
    • a scalar written in the blocks a vote decides (control dependence) and read after the join (stale-scalar); masks that only accumulate behind the vote (s_andn2_b64 / s_or_b64 of themselves with a mask zero in that half) are not stale.
    • Values every lane has: written under the launch EXEC by plain VALU ops of such values, through all-or-none selectors, or loaded at such addresses (whole-quad mode drops the ones written before it).
  • Register uses from x64_masks::uses (read-modify-write destinations, SDWA scalar sources, SMEM offsets, src_vccz / src_execz) plus src_scc, NSA addresses, and image loads by their DMASK (upper_lanes::vgpr_writes, now pub(super)).
  • 43 tests: the reviews' counter-examples (each was Exact and exported something else when cut), one per reason, and the exact cases (if that narrows EXEC, uniform votes, the discard early-out, a load at a uniform address, nested restores).

Not yet (the next parts of #336): exact idioms (waterfall loops, spill slots, wave-aggregated atomics). Unknown counts as MayDiffer.

Size: 860 lines of code and 572 of tests. The review showed that leaving the stale-scalar rule to a later PR makes this one report Exact for programs that differ, so it is in here; what is left (idioms) only turns MayDiffer into Exact and comes separately.

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 dfc5578: 726 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): no panic, at most 173 ms for one program. 6 057 Exact: 3 954 of 10 974 PS, 2 103 of 2 236 VS. Reasons among the others: vote-branch 6 375, cross-lane 3 824, unsafe-execz-branch 2 858, tainted-exec 2 966, stale-scalar 1 418, mask-data 815, lane-count 432, lane-id 420, first-lane 353. (Before the first review: 9 424 Exact; at ad4add0: 7 208; at c5e0ded: 6 043; at 223065f: 6 121; some of each wrong.)

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: 64b3f35599bb7102f55d640e1a791e7d6dd3b175
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1576 (PresentX 1576)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14774 MB

PR:

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

Not tested

  • Whether MayDiffer programs actually differ on a 32-lane GPU (no 64-lane reference on the GPU yet; the review's interpreter checked the counter-examples).
  • 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. The counter-example tests come from QemmHD's, CuteBooty's and upipibi's reviews.

🤖 Generated with Claude Code

…ll#336)

Preparation for classifying wave64 VS / PS by whether their result depends
on how a 32-lane GPU cuts their waves: that needs to know which blocks run
because of a wave-wide vote. No behaviour change: nothing calls it yet.

cfg::Cfg builds a program's basic blocks from upper_lanes::successors (now
shared), and gives each block's immediate post-dominator (Cooper, Harvey
and Kennedy's iteration on the reversed graph, with one exit after every
block that ends the program) and the branches it is control-dependent on
(Ferrante, Ottenstein and Warren). A program with an indirect jump has no
graph; a block from which no path ends the program has no post-dominator.

Measured over all 26 698 programs of a retail shader pack (release, one
thread): no panic, 195 with an indirect jump, at most 15 995 blocks in one
program, at most 15 ms for one program's graph, post-dominators and
control dependence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PHeitor1

Copy link
Copy Markdown

Tested ed04b05 (with #341 under it) merged onto main 508a0c7, on a GPU that runs wave64 VS / PS as two 32-lane halves, the case this classifies.

RTX 5060 Ti 8 GB (Blackwell, 32-lane waves), NVIDIA 621.24, Ryzen 5 5600X, Windows 11 Pro 26300 (native, Graphics Tools + XGameRuntime installed), rustc 1.100.0 MSVC, debug, cargo test --workspace --no-fail-fast -- --test-threads=4, no XCL_SAMPLE_*.

Pass: 702 passed, 0 failed, 41 ignored. SKIPPED: only the 2 no wave64 tests. All 15 gpu::recomp::partition::tests pass. The cfg tests from #341 pass too.

No behaviour change to check on the GPU yet, since nothing translates by the tier. Once a part of #336 acts on MayDiffer, I can run it here.

Run and written with Claude Code (Claude Opus 5.5).

@QemmHD

QemmHD commented Nov 24, 2026

Copy link
Copy Markdown

Thanks for this. The structure (a forward pass over the #341 blocks, with reasons per sink) reads well, and the fixed point is fine: taint only grows, flags only fall, and a tainted VCC / SCC / EXEC reaches its branch, also across a back edge. Your 10 Exact test programs also hold up under 5 000 random cuts in a small reference interpreter I wrote for this review.

The problem is in the direction that matters for NVIDIA: I found programs that get Tier::Exact but export something else when the wave is cut. Each one below was run as one 64-lane wave and as two 32-lane halves (your half model: lanes keep their position mod 32, upper mask word 0), except 2 and 6, which are argued from the operand tables. The snippets are in your test style, and all of them currently return [].

1. uniform is not "every lane has it" (partition.rs:261, :283-289). A write under a narrowed EXEC and a v_cndmask with a per-lane selector both leave the VGPR uniform, so v_readfirstlane is not cross-lane, and a compare of it becomes a "uniform" vote.

// idx = s5; if (v4 > v5) idx = s6; s0 = first lane's idx; export it
let p: &[I] = &[("V_MOV_B32", "ENC_VOP1", &[("VDST", 6), ("SRC0", 5)], None), CMP, NARROW,
    ("S_CBRANCH_EXECZ", "ENC_SOPP", &[("SIMM16", 1)], None),
    ("V_MOV_B32", "ENC_VOP1", &[("VDST", 6), ("SRC0", 6)], None), RESTORE,
    ("V_READFIRSTLANE_B32", "ENC_VOP1", &[("VDST", 0), ("SRC0", V + 6)], None),
    ("V_MOV_B32", "ENC_VOP1", &[("VDST", 0), ("SRC0", 0)], None), EXP];
assert_eq!(reasons(p), vec!["cross-lane"]);   // actual: []

With only lane 32 passing, the wave exports s5 everywhere, while the upper half exports s6. The same holds for v_cndmask_b32 v6, 0, v7, vcc (VCC is never looked at by all_uniform), for DPP results (and row_mask, which names rows of the wave), and for v_readlane of a lane the half did not launch.

2. Image loads (:135, :287). rdna2::vgpr_uses gives four data registers whatever DMASK says, so a DMASK=1 sample "overwrites" v1..v3 and clears their taint; upper_lanes::vgpr_writes already handles this. NSA address registers are not read at all, and the "ENC_MIMG_NSA1" | "ENC_MIMG_NSA2" arms never match, because the decoder keeps ENC_MIMG.

3. A scalar written behind an exempted vote is Exact (:429-436). The description lists this as not followed yet, but then it should count as MayDiffer; as it stands, "unknown counts as MayDiffer" and "a lower bound for exact programs" do not hold.

// s20 = s5; if (any lane: v4 > v5) { s20 = s6 }; export s20
let p: &[I] = &[("S_MOV_B32", "ENC_SOP1", &[("SDST", 20), ("SSRC0", 5)], None), CMP, NARROW,
    ("S_CBRANCH_EXECZ", "ENC_SOPP", &[("SIMM16", 1)], None),
    ("S_MOV_B32", "ENC_SOP1", &[("SDST", 20), ("SSRC0", 6)], None), RESTORE,
    ("V_MOV_B32", "ENC_VOP1", &[("VDST", 0), ("SRC0", 20)], None), EXP];
assert!(!reasons(p).is_empty());              // actual: []

A loop's trip count read after the loop behaves the same way. Cfg::control_dependence from #341 looks like the tool for this, and it is unused here.

4. The vote exemptions check less than they assume (:266, :297-304, :329-340, :429).

  • Only the first instruction of the run side is checked: vccz → join; exec &= vcc; …; exec = saved; v1 = 1.0; join is Exact.
  • The "ends the program writing nothing" exit has the same gap: execz → null export, while the run side restores EXEC and exports.
  • vcmp_uniform does not check exec_launch, although the comment at :75 says "under the launch EXEC".
  • scc_vote goes stale when EXEC or the mask register is rewritten before the branch (e.g. s_and_saveexec; s_mov_b64 exec, s10; s_cbranch_scc0).

5. A vote read as data is not tainted (:295-305, :170-172, :279).

// scc = (vcc != 0); s20 = scc ? s6 : s5; export s20
let p: &[I] = &[CMP, ("S_CMP_LG_U64", "ENC_SOPC", &[("SSRC0", VCC as u64), ("SSRC1", 128)], None),
    ("S_CSELECT_B32", "ENC_SOP2", &[("SDST", 20), ("SSRC0", 6), ("SSRC1", 5)], None),
    ("V_MOV_B32", "ENC_VOP1", &[("VDST", 0), ("SRC0", 20)], None), EXP];
assert!(!reasons(p).is_empty());              // actual: []

Your a_scalar_condition_selected_into_a_mask… test with this SCC as its condition is also Exact. So are src_vccz / src_execz / src_scc operands, and 32-bit operations on mask words: s_mov_b32 s20, exec_lo; v_mov_b32 v0, s20 loses mask-data, and s_or_b32 s20, vcc_lo, vcc_hi; s_cbranch_scc0 is not a vote. Carry masks (v_add_co_u32) are not flagged as masks either.

6. Register uses (:133-158, :256, :278). x64_masks::uses already models what regs() misses:

  • writes that keep the old value (s_cmov*, s_addk, s_mulk, s_bitset*) clear the taint: s_bcnt1 s20, exec; s_addk_i32 s20, 1 exports clean;
  • SMEM offset registers and SDWA scalar sources are not read.

Separately, writes_exec only looks at s126, so s_mov_b32 exec_hi, 0 is neither a sink nor the end of exec_launch; and a number written to EXEC (s_mov_b64 exec, 1) is not a reason.

7. Precision. An all-discarded early-out inside an if makes the enclosing execz post-dominator Exit, so the if becomes unsafe-execz-branch although it is exact (no difference over 500 random cuts); that may be part of the 1 443. Spill slots (v_writelane / v_readlane of the same lane) are cross-lane, although upper_lanes resolves them.

8. Small things. is_store misses the other DS_* writes. first-lane, tainted-exec, unsafe-execz-branch and no-graph have no test. The commit subject is 80 characters. Time is fine: 40 000 instructions in 78 ms in release.

The 29 counter-examples (all failing on ed04b05) and the interpreter are on a local branch; I can share them as a patch if useful.

Reviewed on an RTX 4070 SUPER machine (CPU unit tests only for this PR). Points 1, 5 and the counter-example runs were checked by hand against the code before posting.
AI-assisted review (Claude Code; Claude Opus 5.5 and Claude Fable 5.2).
Discord: bigpeppa.

@emirduran707

Copy link
Copy Markdown
Contributor Author

Thank you – this is exactly the review this needed, and you're right on every point I've checked so far; an Exact that is wrong is the failure that matters here. Yes please, the patch with the 29 counter-examples (and the interpreter, if you're happy to share it) would be very useful: I'd like every one of them in the tests.

What I'll do on this PR:

  • 3: fold Recompiler: scalars written behind a vote and read after it are partition-dependent (#336) #528 (scalars written behind a vote, read after the join) into this one, so nothing is left "not followed but Exact"; I'll close Recompiler: scalars written behind a vote and read after it are partition-dependent (#336) #528.
  • 1: a VGPR stays "every lane has it" only when written under the launch EXEC from such values: not under a narrowed EXEC, not through a per-lane selector (v_cndmask/carry-in on a mask that isn't all-or-none), not from DPP/SDWA/permlane or a v_readlane of a lane the half may not have.
  • 2: image loads by DMASK (as upper_lanes::vgpr_writes does) and NSA address registers read; the dead ENC_MIMG_NSA* arms go.
  • 4: an exemption holds only if no block the run side reaches before the join (or, for the "ends the program" exit, at all) widens EXEC; scc_vote is dropped when EXEC or the mask register is rewritten before the branch; the vcmp_uniform comment fixed to what it checks.
  • 5 / 6: a vote's SCC, src_vccz / src_execz / src_scc and mask words read as numbers are tainted; 32-bit ops on mask words and carry masks kept as masks; read-modify-write destinations read (reusing x64_masks::uses where it fits); SMEM offset / SDWA scalar sources read; EXEC's high word and numbers written to EXEC handled.
  • 8: the other DS_* writes, tests for every reason, and a shorter subject.
  • 7 (precision) after the soundness fixes, measured on the pack again.

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

@4MDomo

4MDomo commented Nov 24, 2026

Copy link
Copy Markdown

NVIDIA test report for ed04b05 (this PR's head, stack 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 ed04b05: 698 passed, 0 failed, 41 ignored.
  • 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 classification counts (no retail shader pack here). Classification only, so this run does not show how a 32-lane GPU renders the programs it marks.

AI use

  • Claude Code (Claude Opus 5.5) ran the suite and wrote this report; checked by me.

@tugasky

tugasky commented Nov 24, 2026 •

Copy link
Copy Markdown

A second machine ran the census with the PR's own code, unmodified and without writing a
test into the tree. Nothing here needed the title: the carved shader containers are in a
folder, so the same partition::classify can be driven directly. The counts came out
identical to yours, reason for reason, which is the useful part.

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.

How: a throwaway src/bin (not committed, deleted afterwards) walked the 26 503
carved containers, took each program's code, decoded it the way wave_lane_reads does –
rdna2::decode in a loop, then rdna2::resolve_far_jumps – and called
partition::classify(&insts). The stage comes from recomp::interface, the wave size
from recomp::detect_wave64.

stage wave64 programs Exact MayDiffer slowest program
PS 10 974 7 248 (66.0 %) 3 726 (34.0 %) 28.7 ms
VS 2 236 2 176 (97.3 %) 60 (2.7 %) 17.2 ms
total 13 210 9 424 (71.3 %) 3 786 (28.7 %) 28.7 ms

13 034 distinct programs, 9 255 distinct Exact (71.0 %). Every program decoded and every
one formed a graph: 0 undecoded dwords, 0 no-graph, no panic. 26.8 s of classify time
over the 13 210 programs (mean 2.0 ms); two runs, 127.1 s and 50.6 s wall (the first was
the cold file cache), identical counts.

The distinct-program numbers and the reason counts match yours exactly – cross-lane
2 473, tainted-exec 2 215, vote-branch 1 817, unsafe-execz-branch 1 443,
mask-data 619, lane-count 432, first-lane 353, lane-id 186 – so the pass is
deterministic and machine-independent, as a pure software pass should be.

Two numbers the PR body does not have, which change how much the cut matters:

  • 13 210 of the title's 14 337 graphics programs are wave64 (92.1 %): all 2 236 VS
    and 10 974 of 12 101 PS. Almost every graphics program of this title is exposed to the
    32-lane cut, so the 71 % Exact rate is a rate over the whole graphics corpus, not over
    an unusual corner of it.
  • 1 317 of the 3 786 MayDiffer programs (34.8 %) differ for exactly one reason, which
    makes the order of the next parts of Recompiler: wave64 VS / PS on 32-lane waves – votes are taken per half (not only lane reads) #336 measurable: unsafe-execz-branch 861 PS + 1
    VS, vote-branch 248 PS + 2 VS, cross-lane 155 PS + 4 VS, lane-count 40 PS,
    mask-data 6 VS. The commonest shapes are those singletons plus
    cross-lane+tainted-exec+vote-branch 719, cross-lane+tainted-exec 501 and
    cross-lane+mask-data+tainted-exec+vote-branch 410.

Suite: the branch head is three commits behind main (base a6f5f7a; #486 came after),
so I tested the merge with 7ebf1b8, which is what the merge check builds:
cargo build --workspace --release (the e2e tests need xcl_testtitle.exe), then
cargo test --workspace --release -- --test-threads=4 → 699 passed, 0 failed, 41
ignored
, no test skipped. That is your 698 plus the one test #486 adds. The 15
partition::tests all pass on their own as well.

Not tested (same as you): whether a MayDiffer program actually differs on a 32-lane
GPU (needs a 64-lane reference), 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.

QemmHD added a commit to QemmHD/xcl that referenced this pull request Nov 24, 2026
29 programs partition::classify reports as Exact although a 32-lane cut
changes what they export, plus 7 passing checks (fixed point, the PR's
own Exact programs under 5 000 random cuts, precision cases, timing).

Each unsound case is run by a small reference interpreter (run / cut /
must_differ, ~30 instructions, DPP as in emit.rs) as one 64-lane wave
and as two 32-lane halves, then asserted not Exact. a5, a6, both d2 and
g are classifier-only, argued from the operand tables.

On ed04b05: 22 passed, 29 failed (the counter-examples), by design.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
@QemmHD

QemmHD commented Nov 24, 2026

Copy link
Copy Markdown

Glad it helps. The tests and the interpreter are one commit on top of ed04b05:

Everything is in mod review_517 at the end of the tests module in partition.rs (lines 607-1470): the interpreter (run / cut / must_differ) at 678-955, then 36 review_517_* tests. On ed04b05 that's 22 passed, 29 failed. The failing ones are the counter-examples; each first asserts that a launched lane exports something different between the 64-lane run and the two halves, then that the classifier isn't Exact. The interpreter covers only the ~30 instructions these tests use (DPP follows emit.rs:2509-2533), so treat it as test scaffolding, not a reference model. Feel free to rename, trim or restructure anything.

AI-assisted (Claude Code, Claude Opus 5.5).
Discord: bigpeppa.

@emirduran707

Copy link
Copy Markdown
Contributor Author

Updated to ad4add0 (one commit on #341; #528 folded in and closed). Each of your points as I handled it:

  1. A VGPR is "every lane's" only when written under the launch EXEC by a plain VALU op (no DPP / SDWA / permlane) of such values, with any per-lane selector (v_cndmask, carry-in) all-or-none; v_readlane is always cross-lane.
  2. Image writes by DMASK (upper_lanes::vgpr_writes, now shared), NSA addresses read, the dead ENC_MIMG_NSA* arms gone.
  3. Stale scalars are part of this PR now (control dependence from Recompiler: basic blocks, post-dominators and control dependence (#336) #341, nested branches included; loops' trip counts fall under it).
  4. The run side must not widen EXEC again before the join (or to the end, for the all-discarded way out). Not widening: ANDs with EXEC / a mask saved inside / the vote's mask, v_cmpx, whole-quad mode, a nested if's restore, an if/else flip (s_or_saveexec + s_xor exec), and a restore right before the join with no lane work after it. scc_vote is dropped when EXEC or its mask register is rewritten; the vcmp_uniform comment says what it checks.
  5. A vote's SCC read as a number is mask-data; src_vccz / src_execz / src_scc; 32-bit ops on mask words keep them masks (and vote through SCC); carry-outs are masks.
  6. Uses from x64_masks::uses (read-modify-write destinations read, SDWA / SMEM offset sources); EXEC's high word, a single word of EXEC, and numbers written to EXEC are reasons.
  7. All DS_* writes; a test per reason; subject shortened.

Your snippets are tests (some tightened: the exec_hi one now has no divergent compare after it, so it only passes for the right reason); all 31 tests pass, suite 714 / 0 / 41. Over the pack: 7 208 Exact (was 9 424 before, which included wrong ones). 7 (precision: early-out inside an if, spill slots) is next, once the soundness side is settled – your patch with the 29 cases would let me check every one of them too.

AI use: Claude Code with Claude Opus 5.5 made the changes, ran the tests and wrote this reply.

@QemmHD

QemmHD commented Nov 24, 2026

Copy link
Copy Markdown

Ran all 29 counter-examples against ad4add0 (the test module applies unchanged): 26 fixed, 3 still Exact.

  • review_517_a4_a_dpp_row_mask_names_rows_of_the_wave: v_mov_b32_dpp v0, v6 quad_perm:[0,1,2,3] row_mask:0xc, then export. source_taint (partition.rs:243-273) has no rule for DPP row / bank masks; DPP only drops uniform (:362-367), and a 32-lane wave has no rows 2–3.
  • review_517_c3_a_uniform_compare_under_a_narrowed_exec: v7 = s3; vcc = v4 > v5; s_and_saveexec s10, vcc; v_cmp_gt_u32 s2, v7; s_cbranch_vccz join; exec |= s10; v0 = 1.0; join: exec |= s10; exp. vcmp_uniform / uniform_mask are set without exec_launch (:342, :357), and vote() accepts uniform_mask without it (:718-719, unlike is_vote at :631). A half with no lanes left sees VCC = 0 and skips the body.
  • review_517_h_writelane_then_a_per_lane_read: v_writelane_b32 v0, s5, 5, then a per-lane export. It only clears uniform (:367); it needs lane-id taint, since lane 5 of each half is console lanes 5 and 37.

Separately, P3 lost precision: the plain if (no early-out) was Exact on ed04b05 and is now stale-scalar, tainted-exec. stale_at_joins (:670-678) marks the mask s88 stale although the region only changes it in lanes that are in EXEC, so a half that skipped the region still holds the right bits. Not a correctness bug.

Your 31 tests and the cfg tests pass, and the random-cut check of your Exact programs finds no difference (5 000 cuts).

Branch with the module on top of ad4add0: https://github.com/QemmHD/xcl/tree/review/517-recheck (git fetch https://github.com/QemmHD/xcl review/517-recheck).

AI-assisted (Claude Code, Claude Opus 5.5).
Discord: bigpeppa.

@emirduran707

Copy link
Copy Markdown
Contributor Author

Thanks. Updated to c5e0ded (still one commit on #341). All three are fixed, and P3 is back to Exact:

  • DPP row / bank masks (a4): a DPP16 row or bank mask other than 0xF is lane-id (a 32-lane wave has rows 0 and 1 only); row_bcast15 / row_bcast31 (DPP_CTRL 0x142 / 0x143) are cross-lane.
  • Uniform compare under a narrowed EXEC (c3): a mask that is all or none of the active lanes counts as uniform only under the launch EXEC, as in is_vote. Under a narrowed EXEC a half may have no lanes left and take the other side, so the vote is accepted only if neither side turns lanes on again before the join.
  • v_writelane (h): lane-id, since lane k of each half is a different console lane.
  • P3 (plain if): a mask that only accumulates behind the vote (s_andn2_b64 / s_or_b64 of itself with VCC or EXEC) is not marked stale, since a half with no active lanes leaves its bits as they were. stale_at_joins also follows both operands of an s_and_b64 into EXEC now.

All four are tests in the PR now, so it has 35 tests. Your module on c5e0ded: 35 of its 36 tests pass. The one that fails, review_517_p1_an_sgpr_spill_slot_is_exact_but_reported, expects ["cross-lane"] and now gets ["cross-lane", "lane-id"], because the spill goes through v_writelane. It is still MayDiffer; the spill-slot idiom that would make it Exact is the next part of #336.

Cost over the same shader pack: 6 043 Exact instead of 7 208 (3 953 of 10 974 PS; VS unchanged at 2 090 of 2 236). The reasons that grew are vote-branch (3 973 → 5 979, the c3 rule) and lane-id (186 → 420, the DPP masks and v_writelane).

@QemmHD

QemmHD commented Nov 24, 2026

Copy link
Copy Markdown

Confirmed on c5e0ded: with our module applied, 70 passed and 1 failed (your 35, plus 35 of our 36). All 29 counter-examples are now not-Exact, and P3 is Exact again. The one failure is our p1_an_sgpr_spill_slot_is_exact_but_reported, as you said: it pinned the exact reason list (["cross-lane"]). ["cross-lane", "lane-id"] is still MayDiffer, so our test was too strict, not your code. Fine to relax it to "not Exact", or drop it until the spill-slot idiom lands.

No further soundness findings from our side. The Exact count going from 7 208 to 6 043 looks like the right trade until the precision idioms come back.

AI-assisted (Claude Code, Claude Opus 5.5).
Discord: bigpeppa.

@CuteBooty

Copy link
Copy Markdown

Five more ways c5e0ded says Exact for a program that differs when the wave is cut. Each was run with QemmHD's interpreter (review/517-recheck applied to c5e0ded, plus S_XOR_B64 and the S_OR / S_ANDN2_SAVEEXEC / S_ANDN2_WREXEC arms): with lane 3 alone passing CMP, lanes 32..63 export something else, and classify gives no reason. A to D are in ad4add0 too.

In all of them SAVE20 is s_mov_b64 s[20:21], exec at the start; CMP, NARROW, BODY, RESTORE, EXP are yours; BODY1 is v_mov_b32 v1, 1.0; execz +n skips n dwords.

  • A. The first instruction of an EXEC vote's side is not looked at. The last widens_after call in vote passes skip_first = true with mask None too, where the first instruction is not a checked narrowing.
    CMP, SAVE20, NARROW, execz +2, s_mov_b64 exec, s20, BODY, RESTORE, EXP (the same with s_andn2_saveexec_b64 s14, s20 or s_andn2_wrexec_b64 s14, s20 first and s_mov_b64 exec, s20 at the join). With BODY in front of the write all three are reported. The skip also keeps a save in that position out of saved (a bounded restore is then unsafe-execz-branch: precision only).
  • B. The vote's mask register rewritten in its side. saved.extend(mask) is never taken back.
    CMP, vccz +5, NARROW, s_mov_b64 vcc, s10, s_mov_b64 exec, vcc, BODY, RESTORE, EXP
  • C. saved has no order and is not invalidated. Both of these, with BODY first so that A plays no part:
    CMP, SAVE20, NARROW, execz +5, BODY, s_mov_b64 s12, exec, s_mov_b64 s12, s20, s_mov_b64 exec, s12, BODY, RESTORE, EXP
    CMP, SAVE20, NARROW, execz +4, BODY, s_mov_b64 exec, s20, BODY, SAVE20, RESTORE, EXP
    Without the rewrite the first is Exact, and is exact.
  • D. An else flip inside the skipped side. s_or_saveexec_b64 s10, s10 puts s10 in saved by its own destination, and else_flip excuses it as well; here s10 is the EXEC from before the vote, so the flip turns on the lanes the vote left out.
    CMP, SAVE20, NARROW, execz +4, BODY, s_or_saveexec_b64 s10, s10, s_xor_b64 exec, exec, s10, BODY1, s_mov_b64 exec, s20, EXP
    With execz +1 (the flip at the join, as compilers emit it) the halves match the wave.
  • E. (new in c5e0ded) Accumulating with a VCC wider than EXEC. The accumulates exemption needs VCC to have no lane outside EXEC.
    CMP, SAVE20, s_mov_b64 s88, exec, NARROW, s_mov_b64 vcc, s20, execz +2, BODY, s_andn2_b64 s88, s88, vcc, s_mov_b64 exec, s20, s_and_b64 exec, exec, s88, BODY1, s_mov_b64 exec, s20, EXP
    With a compare under the narrowed EXEC instead of the move it is Exact, and is exact.

Possible fixes: A, skip only when narrows_exec_by checked that instruction; B and C, accept a restore only if a save made inside the side reaches it unchanged on every path; D, no exemption unless the OR's source is bounded by this vote; E, exempt VCC only when it was last written by a compare under the current EXEC.

I can post the tests as a branch or a patch if you want them.

Tested: cargo test -p xcl --lib -- partition::tests (CPU only, debug, rustc 1.100.0 MSVC, Windows 11 Pro 26200) on c5e0ded + QemmHD's module + these: 77 passed, 11 failed. The 11: 9 witnesses for A to E, the precision case under A, and review_517_p1 (its known strict reason list).

Not tested: whether any retail program has these shapes (B to E look unusual for compiler output); nothing ran on a GPU.

AI use: Claude Code (Claude Opus 5.5) found the cases and wrote the tests and this comment; Codex (GPT-6.2 Astra) reviewed them by reading the code, without running anything.

@emirduran707

Copy link
Copy Markdown
Contributor Author

Thanks, all five confirmed and fixed in 223065f. A to D come from the same flaw: the side's "saved" masks were an unordered set. So I replaced the set with an ordered data flow rather than patching each case.

  • What changed: widens_after now runs a forward data flow over the side's blocks. It tracks which scalar registers (EXEC and VCC included) are zero in a half that skipped the side, intersected over every way into a block. A write to EXEC of a value not known to be zero there widens EXEC.
    • At entry: the vote's mask, plus what the vote's own block writes from it after its last write.
    • Kept zero: AND with a zero operand, OR / XOR / MOV of zero operands, saveexec by its real semantics, and compares under a zero EXEC (inactive lanes write 0).
    • Everything else written is dropped.
  • A: the side's first instruction is no longer skipped. The narrowing passes because it writes m & exec.
  • B: VCC overwritten from s10 is no longer zero.
  • C: a save counts only after it is made and until it is overwritten.
  • D: no else-flip exemption any more. A flip inside the side keeps EXEC zero only if s10 is, which it is when s10 comes from a saveexec in the side, and not when it is the EXEC from before the vote.
  • E: stale_at_joins uses the same flow for the side the wave runs. An accumulation s &= ~m / s |= m is exempt only when m is zero in that half at that point.

Each case is a test now (five tests, 40 in all), with the exact variants you gave as Exact checks: C without the rewrite, D with the flip at the join, and E with a compare under the narrowed EXEC. All five fail on c5e0ded and pass on 223065f. QemmHD's module on 223065f gives the same result as before: 35 of 36, with only p1's strict reason list failing.

Over the same shader pack: 6 121 Exact (4 017 of 10 974 PS, 2 104 of 2 236 VS), up from 6 043 (unsafe-execz-branch 3 211 → 2 858, vote-branch 5 979 → 6 011). The slowest program takes 169 ms (one thread, release).

No need for the branch, thanks; the description of each case was enough to write the tests.

@upipibi upipibi mentioned this pull request Nov 24, 2026
@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Three more programs that classify returns as Exact (no reasons) on 223065f, though a 32-lane cut changes what they export. None is among the 34 counter-examples above. I ran classify from a scratch test in partition.rs's mod tests, using the PR's own helpers and constants. Whether each one diverges is argued by hand under the same half model the earlier reviews used (I had no interpreter), so please run them through QemmHD's interpreter.

A. A vote on VCC whose taken side narrows EXEC and never restores it (partition.rs:688-690, :788-791)
Your test a_vcc_vote_that_narrows_exec_first_is_exact with RESTORE removed:
CMP; s_cbranch_vccz join; s_and_saveexec_b64 s10, vcc; v0 = 1.0; join: exp.
If only lane 3 passes, the wave leaves EXEC = {3}, so lanes 32..63 export nothing. The upper half alone has VCC = 0, jumps to the join with its whole EXEC, and all its lanes export.
stale_at_joins leaves EXEC out ("which the join restores"), and vote only checks that the side doesn't widen EXEC. Possible fix: for a non-EXEC mask, require EXEC to be the pre-vote EXEC on every path into the join, or mark EXEC stale at the join when the side writes it without restoring it.

B. A write under the launch mask, then s_wqm_b64, then a compare (:364, :380-384, early return at :773)
v_mov_b32 v4, s3; s_wqm_b64 exec, exec; v_cmp_gt_u32 vcc, s2, v4; s_cbranch_vccz +1; v0 = 1.0; exp.
The helper lanes that WQM turns on never got the write to v4, so the compare isn't all-or-none. A helper lane in the lower half can make the wave's VCC non-zero while the upper half alone sees VCC = 0. whole_quad_mode_at_the_start_keeps_the_launch_mask covers only the other order (WQM first, then the write). Possible fix: clear uniform / uniform_mask when EXEC moves between L and wqm(L).

C. A number combined into a mask (:347-351, :363)
s_and_b64 exec, exec, 1; v0 = 1.0; exp: the wave exports lane 0, while the two halves export lanes 0 and 32. The same AND applied to a uniform VCC before a vote is also Exact. Only s_mov into EXEC is checked for "a number written to EXEC", and mask_uniform accepts any operand that isn't a mask. Possible fix: a bitwise mask op whose other operand is neither a mask nor 0 / -1 gets mask-data and loses uniform_mask.

All three classify outputs, with the scratch test's input programs:

T1  vcc vote, side narrows by saveexec, no restore: []
T1b same, narrowing by s_and_b64 exec,exec,vcc:     []
T2  uniform write, then wqm, then compare:          []
T3  s_and_b64 exec,exec,1 (also via s20=1,s21=0):   []
T4  uniform vcc &= 1, then vote:                    []
control: vote with whole exec:                      ["vote-branch"]

Nothing calls classify yet, so these matter for the later parts of #336. A is one instruction away from your own test; B and C are unusual for compiler output.

AI-assisted (Claude Code), read-only review plus one scratch test run of classify.

…them

Part of xcl-dev#336. A GPU that runs a console wave64 VS / PS in 32-lane waves runs
each half of the console wave on its own. upper_lanes follows what lanes >= 32
hold when they are read; this follows the other ways the cut shows: wave-wide
votes are taken per half, and lane counts, ranks, first-lane indices, masks
used as numbers and other lanes' values differ in a half. Classification
only: nothing translates by it yet.

partition::classify runs a forward data-flow pass over the program's blocks
(cfg) with taint bits per register and reports Exact / MayDiffer with the
reasons:
- a tainted value reaching an export, a store (LDS / GDS ones included), a
  branch or EXEC; one word of EXEC or a number written to EXEC;
- a vote (vccz/vccnz, execz/execnz, scc on a mask) unless the side taken
  with the mask empty is the join or ends the program writing nothing, and
  the other side starts by narrowing EXEC to the mask (for a mask other
  than EXEC) and does not widen it again before the join (a restore of a
  mask saved inside, an if/else flip, a restore right before the join are
  fine) – or the mask is all or none of the active lanes;
- a scalar written in the blocks a vote decides and read after the join
  (a half that took the other side never wrote it).
Values every lane has are followed (written under the launch EXEC by plain
VALU ops of such values, through all-or-none selectors, or loaded at such
addresses), so reading one from the first lane is exact. Register uses
come from x64_masks::uses (read-modify-write destinations, SDWA scalar
sources, SMEM offsets, src_vccz / src_execz) plus src_scc, NSA addresses
and image loads by their DMASK (upper_lanes::vgpr_writes, now shared).

Tests include the review's counter-examples (values written under a
narrowed EXEC or selected per lane, a vote read as a number, mask words
moved, read-modify-write taint, a side that widens EXEC again, an SCC vote
whose mask is rewritten, EXEC's high word, image DMASK, DS writes) and one
for every reason.

Over the 13 210 wave64 VS / PS of a retail shader pack (local run): 7 208
Exact (5 118 of 10 974 PS, 2 090 of 2 236 VS), at most 159 ms a program.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@emirduran707

Copy link
Copy Markdown
Contributor Author

Thanks, all three hold, and all are fixed in dfc5578:

  • A (EXEC not restored at the join): the side's data flow now also tracks which registers hold the EXEC the half had at the vote (copies, saveexec destinations, x | 0, x | x, x & x, …). On every edge into the join the side must hand over that EXEC, or, for an EXEC vote (where the skipping half had no lanes), an EXEC that is zero there. Both of your T1 forms are now vote-branch. This also closes a hole in the old trailing-restore exemption: a restore into the join is accepted only if what it restores is the vote's EXEC.
  • B (WQM after a write): s_wqm_b64 into EXEC now drops "every lane's value" for VGPRs and "all or none" for masks written before it, since the helper lanes it turns on never got those writes. WQM first, then the write (your existing control case), stays Exact.
  • C (a number in a mask): a bitwise op that reads a mask and has an operand that is neither a set of lanes nor 0 / -1 is mask-data. A new per-SGPR flag says the register holds a set of lanes: a mask, or a scalar condition selected as -1 / 0. s_and_b64 exec, exec, 1, the same through s[20:21] = 1, and a uniform vcc &= 1 before a vote are all reported now. An s_cselect_b64 -1, 0 mask ANDed with EXEC stays Exact.

Each is a test (three tests, 43 in all). All three fail on 223065f and pass on dfc5578. QemmHD's module gives the same result as before: 35 of 36, with only p1's strict reason list failing.

Same shader pack: 6 057 Exact (3 954 of 10 974 PS, 2 103 of 2 236 VS), down from 6 121 (mask-data 635 → 815, vote-branch 6 011 → 6 375). The slowest program takes 173 ms.

@thiagocalile

Copy link
Copy Markdown

Independent AMD RDNA2 (native wave64) test report on exact head dfc557881b9d608bb6f38f0d77497bf759ed2a73 (without rebasing or edits).

Tested

  • Hardware: AMD Radeon RX 6600 (8146 MiB VRAM, driver 32.0.21045.29003; XCL_ADAPTER=radeon, native wave64 + mesh shaders), AMD Ryzen 7 5700X3D, 47.9 GB RAM, Windows 11 (26200), Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.8.2502.11, debug build.
  • XCL_ADAPTER=radeon cargo test -p xcl --lib gpu::recomp -- --test-threads=4: 232 passed, 0 failed, 18 ignored (0 GPU skips).
  • XCL_ADAPTER=radeon cargo test --workspace --no-fail-fast -- --test-threads=4: 723 passed, 3 failed, 41 ignored. The 3 failures are pre-existing on this RX 6600 on main (placed_title_textures_share_vram_and_preserve_pixels: 3D 64x64x64 4 mips subresource 2 mismatch, plus 2 mutex-poison cascades; covered by D3D12.X: map and unmap 3D texture mips separately #1028).

Not tested

  • Retail title / scripts/smoke.ps1 (no retail executable here), D3D12 debug layer (no d3d12SDKLayers.dll), NVIDIA / Intel / WARP, Linux / Wine.

AI use

  • Antigravity (Gemini 4 Neon) checked out dfc5578, ran the tests on my RX 6600, and drafted this report; I checked the output before posting.

@PHeitor1

Copy link
Copy Markdown

NVIDIA report on the exact head dfc5578, and on it merged onto main 1d027e5 (clean). My earlier report was for ed04b05.

Tested

  • RTX 5060 Ti 8 GB (Blackwell, 32-lane waves), NVIDIA 621.24, Ryzen 5 5600X, Windows 11 Pro 26300, rustc 1.100.0 MSVC, DXC 1.9.2602.17, debug, no XCL_* set. cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4.
  • dfc5578 as it is: 726 passed, 0 failed, 41 ignored. SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64).
  • dfc5578 merged onto 1d027e5: 1009 passed, 0 failed, 43 ignored. Plain 1d027e5: 959 passed, 0 failed, 43 ignored (2 runs). The SKIPPED lines are the same in both.
  • All 43 gpu::recomp::partition tests pass in both trees. No nvlddmkm event in any run.

Not tested: whether a MayDiffer program differs when run on this GPU (nothing translates by the tier yet), a shader pack, release, a title.

Run and written with Claude Code (Claude Opus 5.5).

CalvyPZ pushed a commit to CalvyPZ/xcl that referenced this pull request Nov 24, 2026
…cl-dev#336)

The partition classifier accepted a mask vote only if the side the wave
runs starts with an instruction that narrows EXEC by the vote's mask. The
console compiler's pixel-shader discard early-out narrows it one step
later: `s_wqm_b64 s, live; s_and_b64 exec, exec, s`, often with scalar
loads in between. Such votes were reported as `vote-branch`.

The side now only has to turn EXEC off, in a half whose mask is empty,
before its first lane instruction. The zero flow of the vote's side checks
it: wqm(0) and x & 0 are zero there. Before that only scalar ALU ops, scalar
loads, s_waitcnt and s_nop are allowed; their writes are the wave's and are
followed as stale where the sides join. s_setreg, s_sendmsg, PC writes and
any lane instruction end the search. Every shape the old first-instruction
check accepted passes the new one.

Over the 13 210 wave64 VS / PS of a retail shader pack: 7 015 Exact
instead of 6 057 (PS 4 912 of 10 974, from 3 954), `vote-branch` 5 186
programs instead of 6 375. A reference interpreter of a 64-lane wave and
its two 32-lane halves (from the review of xcl-dev#517) shows no difference for
the new exact form over 5 000 random cuts, and differs for an export
placed before the narrowing, which stays `vote-branch`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@raylitebull
raylitebull merged commit 5796cc4 into xcl-dev:main Nov 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants