Skip to content

wave64_halves: a lane mask accumulated by lane-local defs is not stale (SHADER-821) - #4656

Open
sperm wants to merge 7 commits into
ItsNotRexed:mainfrom
sperm:shader-821-break-loop-lane-mask
Open

sperm wants to merge 7 commits into
ItsNotRexed:mainfrom
sperm:shader-821-break-loop-lane-mask

Conversation

@sperm

@sperm sperm commented Nov 23, 2026

Copy link
Copy Markdown

Claim: SHADER-821 (#4571 (comment)), from @shdann's finding.

What and why

stale_uses() treats a 64-bit lane mask in an SGPR pair as a scalar. In a compiler's break loop, the pair collects the lanes that left:

s_mov_b64 s[16:17], 0
loop:
  v_add_nc_u32_e32 v9, 1, v9
  v_cmp_ge_u32_e32 vcc, v9, v10        ; v10 differs per lane
  s_or_b64 s[16:17], vcc, s[16:17]
  s_andn2_b64 exec, exec, s[16:17]
  s_cbranch_execnz loop
s_or_b64 exec, exec, s[16:17]

The pair's in-loop def is control dependent on the loop's EXEC vote, so its reads were stale and the two EXEC writes tainted-exec: tier C. Each bit belongs to one lane, though. A v_cmp writes 0 for the lanes that are off, so OR-ing it in can't change an off lane's bit. A half that leaves the loop early therefore has the same bits for its lanes as the wave.

The rule (narrow on purpose)

  • Lane-local def (Analysis.lane_local_defs): s_or_b64 D, M, D (either order) or s_andn2_b64 D, D, M, where D is an SGPR pair and M is VCC or a pair that a v_cmp (not v_cmpx) wrote earlier in the same block, with no EXEC write in between.
  • Not stale: in stale_uses(), a read of D is not stale when every vote-dependent def that reaches it is lane-local and the read only uses D as a lane mask, either as an EXEC write or as the next lane-local def.
  • Unchanged: scalar uses of the same pair (s_bcnt1, s_cmp, data) are still stale. So is an OR with anything that isn't a fresh v_cmp result.

Tests (tests/semantic/test_wave64_halves.py)

  • test_a_break_loop_lane_mask: the loop above as a PS is tier A (tier C tainted-exec on main).
  • test_a_break_loop_lane_mask_runs_the_same: as a VS through the CPU wave interpreter, one 64-lane wave and two 32-lane waves write the same outputs (trip counts 1 to 4 per lane), and the tier is A.
  • Near misses that stay tier C:
    • test_c_break_loop_mask_read_as_scalar: s_bcnt1_i32_b64 of the pair is exported.
    • test_c_break_loop_or_with_a_non_compare_mask: OR-ing a copy of EXEC instead of a v_cmp result.

Corpus census (asked for by the item)

On my own 1.0.2.1 copy I translated the whole corpus at main (d0835dd) and with this change, then ran wave64_halves.py --census. Counts only.

main this PR
A / B / C (13,401 wave64 VS/PS/GS) 4,033 / 85 / 9,283 4,033 / 85 / 9,283
tainted-exec / stale-scalar 5,188 / 3,414 5,188 / 3,414

No shader changes tier. The shape doesn't occur in this corpus: none of the 25,734 listings narrows EXEC with s_andn2_b64 exec, …. The game's compiler narrows with s_and_b64 exec, exec, s[pair] (15,971 times) and loops with s_andn2_wrexec_b64 waterfalls. So this PR fixes the classifier for the LLVM-style loop in the finding, but it has no effect on 1.0.2.1's tiers. I'm reporting that plainly so the maintainer can decide whether the rule is worth keeping. If not, the census still answers the item's open question, and I'm happy to close this.

Tested

Touches tools/wave64_halves.py alongside #4619/#4620 (SHADER-819/820), but in stale_uses() and a new helper, not in put()/narrows.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@justr4mzi

Copy link
Copy Markdown
Contributor

Reviewed and tested at b4279edb on Windows 11 with AMD Radeon RX 6700 XT (RDNA2, gfx1031), LLVM_MC, SPIRV-Tools, and LEONIDA_VK_VALIDATION=1.

Tests Run

  • python -I tests/semantic/test_wave64_halves.py: 77/77 OK (2.495s).
  • python -I tests/semantic/test_wave64_halves_soundness.py: 30/30 OK (2.305s).
  • python -I tests/semantic/test_wave64_emulate_opt.py: 22/22 OK (6.603s).
  • python -I tests/test_shader_checks.py: 75/75 OK (1.621s).
  • python -I scripts/run_gpu_tests.py --build build --filter cs_w64 --require-pass (LEONIDA_VK_VALIDATION=1, RX 6700 XT):
    • Native wave64: 21 shaders: 21 translated, 21 pass spirv-val, 21/21 passed (0 validation errors).
    • Emulated wave64 (LEONIDA_W64_EMULATE=1): 21 shaders: 21 translated, 21 pass spirv-val, 21/21 passed (0 validation errors).
  • py_compile, scripts/check_no_game_data.py, and git diff --check: exited 0.
  • Note: tests/test_wave64_halves_fixtures.py was not run (pytest is not installed in this environment).

Code Review (tools/wave64_halves.py)

  • The tracking in lane_local_defs() and gating in stale_uses() look sound: zero_off is populated only from non-v_cmpx v_cmp* results, cleared on any exec write or overwritten pair member, and stale_uses() still catches scalar reads (s_bcnt1_i32_b64) or non-compare masks even when the accumulator is consumed by exec or another lane-local def.
  • Non-blocking nit: LANE_LOCAL_OPS at tools/wave64_halves.py:1025 is unused (lane_local_defs() checks op in ("s_or_b64", "s_andn2_b64") after base_op, which strips _e32).

AI-assisted (Gemini, Antigravity).

@sperm

sperm commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks @justr4mzi, good catch. LANE_LOCAL_OPS was left over from a first draft: lane_local_defs() checks the two opcodes after base_op strips the suffix. Removed in 682d144. test_wave64_halves.py and test_wave64_halves_soundness.py still pass (107 run, OK), and git diff --check is clean. AI-assisted.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 682d14421 on Windows 11: tests/semantic/test_wave64_halves.py -> 77 tests, OK; tests/semantic/test_wave64_halves_soundness.py -> 30 tests, OK; git diff --check clean.

The lane mask accumulated by lane-local definitions is no longer treated as stale when a later read consumes it (SHADER-821), and the unused LANE_LOCAL_OPS list is dropped; the added cases cover the accumulated-mask and the rewritten-mask forms. Merge check: clean with #4619, #4620, #4624 and #4630; conflicts only with #4655 in tools/wave64_halves.py. No blocking issue.

Jacob and others added 2 commits November 23, 2026 18:02
…e (SHADER-821)

A compiler's break loop ORs a v_cmp result into an SGPR pair and narrows EXEC
with it. stale_uses() treated the pair as a scalar, so the loop was tier C
tainted-exec although each bit belongs to one lane. A def that ORs (or
AND-NOTs) a same-block v_cmp result into the pair leaves the off lanes' bits
alone; a read that only uses the pair as a lane mask (an EXEC write, or the next
such def) is no longer stale. Scalar uses (s_bcnt1, s_cmp) still are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…DER-821)

After the rebase onto main, the kill-exit test from cc4231d that expected a
conservative tier C for an exit whose live mask two kills define now gets A:
both definitions are `s_andn2_b64 D, D, vcc` after a v_cmp, so the mask is
lane-local. Run it on the emulator (64 lanes against two halves of 32, with
the halves leaving at different votes) and the words match. Keep a C control
where the second definition ORs in a scalar register.

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

Copy link
Copy Markdown
Contributor

Tested 649260f merged with main 98fa503 on WSL Ubuntu, Python 3.12.16: pass

  • tests/semantic/test_wave64_halves.py: 107 tests, OK (CPU only; the Execution tests run on the wave interpreter).
  • Negative control, tools/wave64_halves.py checked out from main with the PR's tests: 4 fail (test_a_break_loop_lane_mask, test_a_break_loop_lane_mask_runs_the_same, test_kill_exit_shared_by_two_kills_invariant, test_shared_exit_of_two_kills_is_a), so the new tests need the fix. The two _stays_c / _c_ guard tests pass on both, as expected for conservative cases.
  • Read the diff; also ran the break loop with the accumulator initialised to 0, to a copy of EXEC (s[10:11]) and to -1: tier A and whole-wave vs halves outputs identical in all three. No issues found.
  • Not run on Windows: pure Python with no path or subprocess use.

@CuteBooty

Copy link
Copy Markdown

Tested 649260f0 on NVIDIA GeForce RTX 3070 (32-wide subgroups), driver 617.14, Windows 11 25H2; llvm-mc 23.1.5; test programs built from the base 98fa503f (the PR does not touch runtime/).

GPU suite (build.py + check.py), head against base 98fa503f:

  • native: 153/188 pass, 35 skipped (wave64 on a 32-wide device)
  • LEONIDA_W64_EMULATE=1: 184/188 pass, 4 skipped (3 mesh fixtures, ps_w64x_readlane)
  • same result for every test, all 242 translated modules byte-identical, graphics tiers A/B/C 10/7/13 on both

So no regression on a 32-wide GPU. It also means none of the 242 fixtures build.py translates reaches the new rule: the C→A move for a break-loop lane mask has CPU coverage only (the 107/107 and the 4-fail negative control kapitche reported above reproduce on Windows), and nothing yet runs such a shader as tier A on 32-wide hardware.

AI-assisted (Claude Code).

@sperm

sperm commented Nov 23, 2026

Copy link
Copy Markdown
Author

Rebased onto main (98fa503), now at 649260f. AI-assisted (Claude Code).

Conflict: stale_uses() in tools/wave64_halves.py. main added the lane-spill read (v_readlane_b32 from a pure spill VGPR). I kept that and this PR's mask_use line next to each other. Both are independent reads, and neither changes the other.

One test on main changed with this rule: test_shared_exit_of_two_kills_stays_c (from cc4231d). Two lane-local kills share one exit. Each kill's s_andn2_b64 s[pair], s[pair], vcc is one of the lane-local defs this PR treats as not stale, so the shape is now tier A. I checked that it's sound before changing the expectation:

  • Through the CPU wave interpreter, one 64-lane wave and two 32-lane halves write the same outputs, with the second kill's limit at 20, 50 and 63.
  • The test is now test_shared_exit_of_two_kills_is_a, and test_kill_exit_shared_by_two_kills_invariant checks it end to end. Whole-quad mode keeps lanes 48 and 49 on, as expected.
  • A near miss still stays tier C (tainted-exec): in test_shared_exit_after_a_scalar_mask_stays_c, the second kill ORs in a scalar pair instead of a compare.

Census after the rebase: I translated my own 1.0.2.1 copy at main 98fa503 and at this branch, then ran wave64_halves.py --census. Counts only.

main this PR
translated / spirv-val valid 26,503 / 26,503 26,503 / 26,503
tier A / B / C 5,054 / 106 / 8,245 5,054 / 106 / 8,245
shaders whose index entry differs 0

As before, no shader in this corpus changes tier, so the rule only matters for the LLVM-style loop in the finding.

Tests: I ran the whole tests/semantic suite on Linux, CPU only (no GPU used): 6,251 tests. 3 failures and 2 errors, all in test_loop_ballot_barrier (the divergent-loop emulate tests). Exactly the same ones fail on main 98fa503, so this branch didn't cause them. test_wave64_halves passes.

@memorypressure

Copy link
Copy Markdown

Verified at the PR head: tests/semantic/test_wave64_halves.py passes 107/107 under python -I, and the translator-use guard, soundness and fixtures suites are clean. The lane-local-def rule reads correctly (v_cmp's zeroed inactive bits make the accumulated mask half-invariant). The head merges cleanly with current main; sequencing note: #4655 edits the same tool and semantic test — land in some order and re-run after each. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@cxchhh

cxchhh commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 649260f0 on Tesla V100-SXM2-32GB (Volta, subgroup 32..32), NVIDIA 580.95.05, Ubuntu 24.04 (kernel 6.14.11), Python 3.12: pass.

Scope: the 32-wide half only (NVIDIA Volta). The AMD / 64-wide half still needs someone with an AMD GPU. (The change is in tools/wave64_halves.py, a CPU analysis. The GPU suite only confirms that nothing else moved.)

Setup: the PR diff applied to main 98fa503f (applies cleanly), Linux Vulkan test programs built from that tree, compared against untouched main 98fa503f built the same way. llvm-mc 23.1.6, SPIRV-Tools 2026.4.

  • scripts/run_gpu_tests.py: native 161/217 passed, 56 skipped; emulated + barycentric fallback 194/217 passed, 23 skipped; the same as main.
  • tests/semantic/test_wave64_halves.py: 107 OK (main: 101). This PR's test file against main's tools/ gives 4 failures, which are the new tier-A cases.
  • python -m unittest discover -s tests/semantic: 6251 tests; the only failures are the five test_loop_ballot_barrier cases that also fail on main here.

No game files. AI-assisted (Claude Code); I ran the commands above and checked the numbers against the logs.

@465d6a0eac

Copy link
Copy Markdown
Contributor

Census (TEST-1006) of 649260f0, from my own 1.0.2.1 copy, counts only: no change on the corpus.

Setup. I merged the PR onto main d974c88a (clean merge) and compared it with my 0db7fed5 run. tools/ differs between the two only in exe_checklist.py, gdk_runtime_calls.py and saves.py. Native mode, the 13,405 wave64 VS/PS/GS (picked by the FSSM wave-size flag and the carve-index stage), WSL Ubuntu, Python 3.14.4, llvm-mc 21.1.8, SPIRV-Tools v2026.1, CPU only.

Result. Both sides translate all 13,405, and all 13,405 pass spirv-val. The .spv files are byte-identical. The tiers are A 5,054 / B 106 / C 8,245 on both sides (VS 1,455 / 79 / 702, PS 3,404 / 27 / 7,543, GS 195 A), and no shader's reason set changes. Tier C stale-scalar stays at 3,487.

So no wave64 VS/PS/GS in the game has a stale-scalar finding that comes only from a lane mask built up by lane-local defs. The compiler break loops that this rule frees, if the corpus has any, carry other tier C reasons as well.

AI-assisted (Claude Code). Part of TEST-1006 on the coordination issue.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

AI-assisted review (Claude Code). No game files; hand-written listings; CPU wave interpreter only (Windows 11, Python 3.14.7).

Head 649260f0, and the same head merged with main 561b65a8 (the merge is clean). I ran 15 hand-written vertex listings as one 64-lane wave and as two 32-lane waves, with the analyser of this head and of main.

One defect: a pattern moves from tier C to tier A, and the two runs differ.

The rule says that a v_cmp writes 0 for the lanes that are off, so the accumulating definition cannot change the bit of a lane of a half that left. That is true only if these lanes are off at the v_cmp. The rule does not check it: lane_local_defs() clears zero_off at an EXEC write after the compare, but an EXEC write before the compare can switch the lanes on again.

v_cmp_gt_u32_e64 s[16:17], 0, v0          ; the pair starts as the empty mask
v_cmp_eq_u32_e32 vcc, 2, v0               ; v0 = lane number: only lane 2
s_and_saveexec_b64 s[12:13], vcc
s_cbranch_execz 3                         ; the second half has no lane and skips
s_mov_b64 exec, s[10:11]                  ; the run side restores the launch mask
v_cmp_gt_u32_e32 vcc, 64, v0              ; true in all 64 lanes of the wave
s_or_b64 s[16:17], vcc, s[16:17]          ; "lane-local" for the rule
s_mov_b64 exec, s[10:11]                  ; the join
s_and_b64 exec, exec, s[16:17]
v_add_nc_u32_e32 v6, 1, v6
s_mov_b64 exec, s[10:11]
  • main 561b65a8: tier C tainted-exec.
  • This head: tier A, no reasons.
  • One 64-lane wave exports v6 = 1 in lanes 32 to 63. Two 32-lane waves export 0 there (32 lanes differ).

The s_andn2_b64 spelling does the same (s_mov_b64 s[16:17], exec at the start and s_andn2_b64 s[16:17], s[16:17], vcc as the definition: 0 against 1 in lanes 32 to 63). The controls without the s_mov_b64 exec, s[10:11] in the run side are tier A with equal results, so the rule is correct when EXEC stays narrowed.

To reproduce, from the repository root at this head:

# python -I repro.py
import sys
sys.path.insert(0, "tests/semantic")
from test_wave64_halves import meta_of, vs, run_cut, out_param
body = ["v_cmp_gt_u32_e64 s[16:17], 0, v0", "v_cmp_eq_u32_e32 vcc, 2, v0", "s_and_saveexec_b64 s[12:13], vcc",
        "s_cbranch_execz 3", "s_mov_b64 exec, s[10:11]", "v_cmp_gt_u32_e32 vcc, 64, v0",
        "s_or_b64 s[16:17], vcc, s[16:17]", "s_mov_b64 exec, s[10:11]", "s_and_b64 exec, exec, s[16:17]",
        "v_add_nc_u32_e32 v6, 1, v6", "s_mov_b64 exec, s[10:11]"]
(tier, reasons, _), asm = meta_of("vs_lane_local_widened", vs(body))
whole, halves = out_param(run_cut(asm, 64)), out_param(run_cut(asm, 32))
print(tier, reasons, whole[32][:1], halves[32][:1])      # this head: A [] (1,) (0,)

Proposal: accept the definition only when EXEC at the compare is inside the EXEC of the vote that the block depends on. The dataflow has the facts: the EXEC token at the instruction (st["x"]) and ancestor(). A simpler condition that is sufficient for the loop of this pull request: between the vote and the compare, on each path, the only EXEC writes are narrowings (s_and_b64 exec, exec, ..., s_andn2_b64 exec, exec, ..., s_and_saveexec_b64, v_cmpx).

What passed. Tier A here with equal results: the break loop of the description; the same definition (s_or_b64 and s_andn2_b64) in a skip region that stays narrowed; a loop whose body restores the launch mask before the compare (equal for this input). Tier C here, as on main: an OR with a copy of EXEC, and s_bcnt1_i32_b64 of the pair (the two runs differ).

…te (SHADER-821)

@shdann on ItsNotRexed#4656: an EXEC write between the vote and the v_cmp (the run side
restoring the launch mask) switches the lanes of a half that skipped back on,
so the compare sets their bits and the wave and the halves differ in lanes
32..63. lane_local_defs only cleared at an EXEC write after the compare.

widened_after_vote() is a forward dataflow: once a vote has run on a path, an
EXEC write other than a narrowing (EXEC AND/AND-NOT a mask, the and-saveexec
family, v_cmpx, or the run side's s_mov_b64 exec, <vote mask>) stops later
v_cmp results from counting as zero for the off lanes. Regression tests: both
of @shdann's listings (tier C, and the wave and halves differ), and the
narrowed control (tier A, equal).

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

sperm commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks @shdann, that's a real hole, and the repro made it easy. lane_local_defs cleared its "zero for off lanes" fact only at an EXEC write after the v_cmp. The s_mov_b64 exec, s[10:11] before it, in the same block, switched the skipped half's lanes back on.

Fixed in b3933dc with the sufficient condition you proposed. widened_after_vote() is a forward dataflow over the CFG. Once a vote has run on a path, any EXEC write that isn't a narrowing stops later v_cmp results from counting as lane-local. The narrowings are:

  • EXEC AND or AND-NOT a mask;
  • the and-saveexec family;
  • v_cmpx;
  • the run side's s_mov_b64 exec, <vote mask>, which vote() already requires to be inside EXEC.

The rule now rejects a join's restore inside a loop as well. That's conservative, and the EXEC-token / ancestor() refinement you mention could win those back later if the corpus ever needs them.

  • Your listings: both spellings (s_or_b64 and s_andn2_b64) are now tier C tainted-exec, as on main. They're added as regression tests: Classification.test_c_lane_local_def_after_exec_widens_again, and Execution.test_lane_local_def_after_exec_widens_differs_and_is_c, which checks that the wave and the halves really differ. Your narrowed control is test_lane_local_def_while_exec_stays_narrowed_is_a (tier A, equal).
  • Negative control: with the old tools/wave64_halves.py, those three tests fail (3 failures). With the fix, test_wave64_halves passes 110/110, test_wave64_halves_soundness 30/30, and test_valu_trig_f32, test_valu_fma_f64 and test_valu_permlane16 pass.
  • Census (my own 1.0.2.1 copy, counts only): b3933dc gives 26,503 translated, and 0 index entries differ from main 98fa503 or from this PR's earlier head. A/B/C stays 5,054 / 106 / 8,245. No shader in the corpus uses the widened shape, so this closes the soundness gap without moving anything.

AI-assisted (Claude Code). Linux, CPU only; no game files posted.

@sperm

sperm commented Nov 23, 2026

Copy link
Copy Markdown
Author

@CuteBooty thanks, the two-loop case is back at 45d61118, so #4870 can keep its fixture as it is.

Change: b3933dc counted any non-narrowing EXEC write after the first vote against the rest of the shader. A vote now stays open only until the path enters a block that post-dominates it, where the halves are together again, and only a widening while a vote is open counts against it.

  • A break loop's restore at its exit block is past its own vote's region, so the next loop's v_cmp counts again.
  • @shdann's counterexample (a restore inside the vote's region, before the back edge) is still tier C.

Tests (Linux, Python 3.14; no GPU involved, the execution tests run the tool's own wave/halves emulator):

  • tests/semantic/test_wave64_halves*.py: 144/144. New:
    • two break loops in a row are tier A, and the wave and the halves give the same words;
    • a widening behind a later vote, after a closed loop, is still tier C, and the wave and the halves really differ there.
  • Negative control: on b3933dcc's tool exactly the two new tier A tests fail.
  • ps_w64_a_break.asm from GPU fixture ps_w64_a_break: a break loop's lane mask in an SGPR pair is tier A (SHADER-821) #4870 (05ee55e6, with its w64_graphics.py entry), tests/test_wave64_halves_fixtures.py: 9 passed here, 1 failed (tainted-exec) on b3933dcc, as you saw.
  • Full tests/semantic: same 5 failures as without the change, all in test_loop_ballot_barrier.
  • Corpus: a full rdna2spirv.py --no-asm run (14 shards, merged) against main: all 26,503 entries have the same tier, reasons and idioms. A/B/C stays 5054/106/8245, so no corpus shader has this shape. Counts only.

AI-assisted (Claude Code).

@SlopTart

Copy link
Copy Markdown

GPU + semantic re-verification at head 45d61118 — RX 7900 XT (RADV NAVI31), Mesa 26.2.5, Arch/Omarchy, fresh full build:

Verdict from this machine: clean on both GPU lanes + semantics modulo rebase. No game files - repo tests only, bare hardware. Posted by Hermes (agent) on my machine (also the boxb/GTX 1070 reporter in #6296).

@lunarminus

Copy link
Copy Markdown

Tested 45d61118 merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: fail. The GPU runs are unchanged, but on this head shdann's s_andn2_saveexec_b64 / s_andn2_wrexec_b64 counterexample is still tier A, and the wave and the halves give different results.

The merge onto d0835dd9 is a fast-forward: the branch sits on main 98fa503f, and the PR's diff alone does not apply to d0835dd9. So the tree I tested is 45d61118, and I compared it per test with untouched 98fa503f, using the same runtime build (llvm-mc 23.1.5).

  • scripts/run_gpu_tests.py, native and LEONIDA_W64_EMULATE=1: 202/217 passed, 15 skipped, 0 failed in both modes.
    • Every test has the same result as 98fa503f. The SPIR-V is byte-identical (221 translated, 221 pass spirv-val).
    • Against my earlier d0835dd9 run (196/210, 14 skipped), nothing changed. There are 7 more tests: 6 PASS and ps_m2_literal SKIP. They come from main, and 98fa503f has them too.
  • runtime/test/shaders/w64_graphics.py, where RADV runs each fixture at 64 and at 32 lanes: 27/27 ok, the same as 98fa503f.
    • The translated fixtures are byte-identical, with tiers A/B/C at 10/7/13 on both.
    • So, as on the RTX 3070, no GPU fixture reaches the new rule.
  • tests/semantic/test_wave64_halves*.py: 144 OK. tests/test_wave64_halves_fixtures.py: 9 passed.
    • With 98fa503f's tools/wave64_halves.py, 7 of the PR's tests fail: the tier-A and same-result cases.
  • Still open from @shdann's second review, on the CPU wave interpreter, using his listing with the fifth line replaced:
    • s_andn2_saveexec_b64 s[14:15], s[12:13]: tier A, no reasons. One 64-lane wave and two 32-lane waves differ in 32 lanes. 98fa503f says tier C tainted-exec.
    • s_andn2_wrexec_b64 s[14:15], s[12:13]: the same result.
    • s_mov_b64 exec, s[10:11]: tier C on this head, as fixed in b3933dcc.
    • s_and_b64 exec, exec, vcc: tier A with equal results.
    • Cause: narrowing_exec_write() (tools/wave64_halves.py:1424) still lists s_andn2_saveexec_b64 and s_andn2_wrexec_b64 as narrowings. They set EXEC to S & ~EXEC, which switches to the else lanes. His proposal fixes this: only s_and_/s_andn1_ saveexec and wrexec, the narrowing list in exec_write().

No game files. AI-assisted (Claude Code).

@TG0000

TG0000 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 45d6111 on AMD Radeon RX 6800 (RDNA2 gfx1030, AMD 26.11.2, Windows 11): pass

I trial-merged it onto main 924b1465 (clean merge). It changes only Python, so the runtime was not rebuilt.

python -I scripts/run_gpu_tests.py --build build --work <scratch> --llvm-mc <llvm-mc.exe>
python -m pytest -q tests/semantic/test_wave64_halves.py
  • compileall: ok
  • GPU suite: 222/239 passed, 17 skipped, 0 failed. ms_wave_info_s3 passed in this full run, but it then failed 3 out of 3 reruns on the same merge (--filter ms_wave_info), the same as on main. This PR does not fix it; that one pass was a flake.
  • tests/semantic/test_wave64_halves.py: 138 passed, 22 subtests passed, 0 failed (12.2 s)

Setup: Vulkan test targets built once from main 924b1465 with llvm-mingw 20261117 (clang++), Ninja, -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF. llvm-mc and spirv-val from MSYS2 ucrt64, Python 3.12.10. No Vulkan validation layer was loaded. Repo tests only, no game files.

Pre-existing on main, not from this PR: ms_wave_info_s3 fails on this card with at (0,0): got (-1.0000,-1.0000,-1.0000,-1.0000), want (0.0078,0.0078,0.5,1.0). It failed 3 out of 3 times on bare main 924b1465 (--filter ms_wave_info). host_adapter_test also does not compile on main with this toolchain (d3d12_com.h:395: unknown type name 'ID3D12GraphicsCommandList8'), and the GPU runner does not use it.

AI-assisted (Claude Code).

CuteBooty added a commit to CuteBooty/Leonida that referenced this pull request Nov 23, 2026
…is tier A (SHADER-821)

A wave64 pixel shader with two compiler-style break loops: the lanes that
left are collected by s_or_b64 D, vcc, D after a v_cmp, the pair narrows
EXEC inside the loop and widens it again behind it. w64_graphics.py runs it
as tier A; every word is a function of the pixel's (x, y).

With tools/wave64_halves.py from main the fixture is tier C (tainted-exec);
with ItsNotRexed#4656 it is tier A. On an RTX 3070 (32-wide only, driver 617.14) all
4096 pixels give the derived words.

Depends on: ItsNotRexed#4656

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Spggety

Spggety commented Nov 23, 2026

Copy link
Copy Markdown

Tested 45d61118 on AMD Radeon RX 6600 XT (Navi 23, gfx1032, RDNA2, discrete), AMD proprietary driver 24.10.1 (32.0.12019.1028, Vulkan 1.3.292), subgroup 32..64, Windows 11 (build 22631). Toolchain: MSVC 14.44, Vulkan SDK 1.4.363.1, llvm-mc from rocm-sdk-core 10.0.0, Python 3.11.9. Pass on this hardware; the review point below is still open.

  • tests/semantic/test_wave64_halves.py on the head: 114 tests, OK. Merged onto main 9f669b36 (clean merge): test_wave64*.py 248 tests, OK.
  • scripts/run_gpu_tests.py (native wave64, PR merged onto main 1cc6e3c1, the runtime build's commit): 213/235 passed, 20 skipped, the same results as main itself (213/235, 20 skipped). The two failures, ms_clip and ms_wave_info_s3, are the same on main 1cc6e3c1 without this PR (3/3 reruns): on this driver vk_harness exits with 0xC0000005 before any readback, so the FAIL line has only the device line. They are not from this PR.

The head is unchanged since @lunarminus's report, so @shdann's s_andn2_saveexec_b64 / s_andn2_wrexec_b64 counterexample (tier A while the wave and the halves differ) should still apply. I did not rerun that listing; it is a CPU-side analysis question, not a hardware one.

Synthetic inputs only, no game files. AI-assisted (Claude Code).

…narrowing; andn1 is one (SHADER-821)

s_andn2_saveexec_b64 and s_andn2_wrexec_b64 set EXEC to S & ~EXEC, the lanes
that were off, so a lane-local def after them was wrongly tier A (@shdann's
listing: the wave and the halves differ in 32 lanes). The narrowing forms are
the and/andn1 ones, as exec_write() already lists.

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

sperm commented Nov 23, 2026

Copy link
Copy Markdown
Author

@shdann @lunarminus thanks, you were right. narrowing_exec_write() still listed s_andn2_saveexec_b64 and s_andn2_wrexec_b64. Fixed in 71eab82, which uses the and/andn1 forms that exec_write() already lists as narrowing.

  • New test: shdann's listing with the fifth line set to each andn2 form. Both are tier C, and the 64-lane wave and the two 32-lane waves differ.
  • Control: the andn1 forms in the same place (~S & EXEC). Both are tier A, and the two runs are equal. The old head called these tier C, because andn1 wasn't on its list.
  • Negative check: with the old tools/wave64_halves.py, all 4 new subtests fail.
  • Suites: test_wave64*.py 213 tests OK. tests/test_wave64_halves_fixtures.py 9 passed.

Only the CPU wave interpreter was used: Linux, Python 3.14, no GPU run and no game files. @CuteBooty, the two-break-loop case from 45d6111 is unchanged.

AI-assisted (Claude Code).

@paratustra

Copy link
Copy Markdown
Contributor

Unsound case at 71eab820, merged onto main dde82f27. Checked on the wave interpreter: 64 lanes against two waves of 32 (run_cut), vs() listing, empty push.

s_mov_b64 s[10:11], exec
v_mov_b32_e32 v6, 0
v_mov_b32_e32 v7, 0
v_cmp_gt_u32_e64 s[16:17], 0, v0        ; D starts empty
v_cmp_eq_u32_e32 vcc, 2, v0
s_and_saveexec_b64 s[12:13], vcc
s_cbranch_execz 3                       ; the half without lane 2 skips the next three
s_not_b64 s[16:17], s[16:17]            ; not lane-local: sets the bits of off lanes too
v_cmp_gt_u32_e32 vcc, 64, v0
s_or_b64 s[16:17], vcc, s[16:17]        ; lane-local def
s_mov_b64 exec, s[10:11]
s_and_b64 exec, exec, s[16:17]
v_add_nc_u32_e32 v6, 1, v6
s_mov_b64 exec, s[10:11]
  • With this PR the listing is tier A, and the whole wave and the halves differ in lanes 32..63.
  • On main it is tier C (tainted-exec), which is right.
  • s_or_b64 s[16:17], s[16:17], s[10:11] in place of the s_not_b64 gives the same result.
  • The control with s_mov_b64 s[16:17], 0 there stays C and equal.

The rule checks that the last def has the lane-local shape, but not that D reached it lane-locally. A non-lane-local def earlier in the same vote region sets off-lane bits, and the s_or_b64 keeps them. A def could count as lane-local only when every vote-dependent def reaching its read of D is lane-local too.

AI-assisted.

@DaviTostes

DaviTostes commented Nov 23, 2026 •

Copy link
Copy Markdown

Tested 71eab820f merged onto main dde82f27e (clean merge) on AMD Radeon RX 9060 XT (RDNA4, gfx1200), RADV Mesa 26.3.1-arch1.3, Vulkan 1.4.363, Linux 7.3.5-arch1-1: pass on the suites below. The earlier GPU checks here are on 45d61118; this run does not cover @paratustra's unsound case posted at 18:25, which is a hand-written vs() listing outside the suite, so it neither confirms nor refutes it.

Hardware / environment: RX 9060 XT (subgroup 32..64), llvm-mc 23.1.5 (AMDGPU), spirv-val from Vulkan SDK 1.4.363, Python 3.14.10.

The new andn2/andn1 rule is exercised, not vacuous (independent negative control): tests/semantic/test_wave64_halves.py = 140 OK at the head; with LEONIDA_TOOLS_DIR pointed at main dde82f27e's tools/, the same file gives 9 failures.

Full translator suite (scripts/run_semantic_tests.py tests/semantic, 12 jobs): 447 files, 5,971 tests, 2 files failed in 120 s. The two are test_image_atomics_guard (47 failures: OpImageTexelPointer in unguarded block) and test_image_store_d16 (1), and both fail with the same counts on main dde82f27e without this PR, so neither is from this branch. The other test_wave64*.py files are OK (cross_half, subgroup_ops, emulate_opt, saveexec_b32, scmp_masks, vcc_data_branch, vcc_half_write, halves_readlane_uniform, halves_soundness).

GPU suite, full scripts/run_gpu_tests.py:

mode result vs main dde82f27e
native wave64 224/241 passed, 16 skipped line-for-line identical
LEONIDA_W64_EMULATE=1 224/241 passed, 16 skipped line-for-line identical

Both runs have the one known ms_wave_info_s3 failure (got (-1.0000,...) at (0,0)), which flakes 3/8 runs on main too; every other PASS/SKIP line matches main exactly. 247/247 fixtures translated and pass spirv-val.

Wave64 graphics tiers on both subgroup widths (runtime/test/shaders/w64_graphics.py, RADV at wave64 and with RADV_PERFTEST=gewave32): 29 fixtures ok, 0 SKIP, 0 differ, and the build's classification is unchanged from main: tier A 11, tier B 8, tier C 13. For transparency: all 270 translated w64 modules are byte-identical to main's, i.e. these hand-written fixtures don't contain the loop-accumulated-mask pattern this PR changes — the new rule is covered by the semantic tests above, and this run is the no-regression check for the tiers.

Counts and pass/fail only; no game files, no game data. AI-assisted (DeepSeek V4.1 Flash coding agent); the runs were repeated and reviewed before posting.

One scope note: my run exercises the suite's own fixtures and the class of pattern the PR fixes, not arbitrary hand-written shaders, so the unsound listing above stays open as far as this check goes.

@DaviTostes

Copy link
Copy Markdown

Reproduced @paratustra's unsound case independently at 71eab820 merged onto main dde82f27e, on the wave interpreter (run_cut, 64 lanes against two waves of 32, vs() with an empty push). Their listing is right, and so is the diagnosis; two extra data points:

  • It is not new in 71eab820: the same listing is also tier A with tools/ from 45d61118, so the gap is in the original lane-local rule, not in the andn2/andn1 change this head made.
  • It is not specific to s_not_b64: the s_or_b64 s[16:17], s[16:17], s[10:11] variant is tier A as well. Both give 32 differing lanes, 32..63; the s_mov_b64 s[16:17], 0 control is tier C and gives 0 differing lanes. With main dde82f27e's tools/, both are tier C (tainted-exec), which is correct.
listing main tools 71eab820 waves differ
s_not_b64 s[16:17], s[16:17] C A 32 (lanes 32..63)
s_or_b64 s[16:17], s[16:17], s[10:11] C A 32 (lanes 32..63)
control: s_mov_b64 s[16:17], 0 C C 0

Why the existing check does not catch it, concretely: lane_local_defs() (tools/wave64_halves.py:1549) validates the shape of s_or_b64 D, M, D and that M is a v_cmp result with no widening since (zero_off[m]), but never looks at the value of D the instruction accumulates into. In stale_uses() the read at s_and_b64 exec, exec, s[16:17] (:1739-1790) then sees only the s_or def — it is in the join block, so it kills the other reaching defs — and all(r in lane_local.get(d, ()) ...) is satisfied by that one def.

Direction that I think keeps the intended case: a def should count as lane-local only when every value of D reaching it is itself lane-local or lane-uniform, i.e. identical bits in every lane of a half and of the wave. The s_mov_b64 D, 0 init of a break loop is lane-uniform, and an in-loop s_or_b64 D, M, D reaching the next iteration is lane-local by recursion, so BREAK_LOOP should stay A; s_not_b64/s_or … , exec are neither, so the case above becomes C. I have not implemented that, so treat it as a suggestion, not a tested patch.

My earlier comment on this PR is about the suites only (140/140 semantic, GPU suite at both subgroup widths, tiers unchanged); it does not cover this hand-written listing and does not contradict it.

Counts and pass/fail only; no game files. AI-assisted (DeepSeek V4.1 Flash coding agent); the runs were repeated and the diagnosis checked against the code paths named above.

… def reaching it is lane-local (SHADER-821)

The OR of a v_cmp result keeps the bits D already had, so a def that is not
lane-local earlier in the vote's region (s_not_b64 D, D, or an OR with the
launch mask) leaves the bits of off lanes set, and the wave and the halves
differ (@paratustra's listing on ItsNotRexed#4656). Prune lane-local defs to a fixed
point over the reaching definitions; defs outside every vote region, like the
s_mov_b64 D, 0 before a break loop, still count.

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

sperm commented Nov 23, 2026

Copy link
Copy Markdown
Author

@paratustra @DaviTostes thanks, both of you were right. The rule only checked the shape of the last def. It never looked at the value of D that def adds to. Fixed in ea9dfe8.

  • The change: after the reaching-definitions pass, stale_uses() now trims the lane-local defs until nothing changes. A def counts only when every vote-dependent def of D that reaches it is lane-local too. A def outside every vote region still counts, such as the s_mov_b64 D, 0 before a break loop. This is DaviTostes's suggestion.
  • Your listing: s_not_b64 s[16:17], s[16:17] and s_or_b64 s[16:17], s[16:17], s[10:11] are both tier C (tainted-exec), with 32 lanes differing. The s_mov_b64 s[16:17], 0 control is C, with 0 lanes differing, the same as you reported.
  • New test: test_lane_local_def_after_a_def_that_is_not_differs_and_is_c. Its 2 subtests fail with 71eab82's tools/wave64_halves.py.
  • Still tier A: the break loop, two break loops, and the andn1 controls.
  • Suites: test_wave64*.py 214 OK. tests/test_wave64_halves_fixtures.py 9 passed.

Only the CPU wave interpreter was used: Linux, Python 3.14, no GPU run and no game files.

AI-assisted (Claude Code).

@paratustra

Copy link
Copy Markdown
Contributor

Re-checked ea9dfe8c merged onto main: fixed. My listing and three variants of the earlier def (s_not_b64, s_or_b64 D, D, exec-copy, s_mov_b64 D, exec-copy, s_xor_b64 D, D, exec-copy) are now tier C tainted-exec; on the wave interpreter all four differ between 64 lanes and 2×32 (lanes 32..63). The s_mov_b64 D, 0 control stays C and equal. test_wave64_halves.py, _readlane_uniform and _soundness pass.

AI-assisted.

@DaviTostes

Copy link
Copy Markdown

Re-checked the fix at ea9dfe8c3 merged onto main dde82f27e (clean merge) on AMD Radeon RX 9060 XT (RDNA4, gfx1200), RADV Mesa 26.3.1-arch1.3, Vulkan 1.4.363, Linux 7.3.5-arch1-1: pass. My reproduction of @paratustra's listing (the one I confirmed at 71eab820) is now classified correctly.

The unsound case, same wave-interpreter check (run_cut, 64 lanes against two waves of 32):

listing 71eab820 ea9dfe8c3 waves differ
s_not_b64 s[16:17], s[16:17] then s_or_b64 s[16:17], vcc, s[16:17] A C (tainted-exec) 32 (lanes 32..63)
s_or_b64 s[16:17], s[16:17], s[10:11] variant A C (tainted-exec) 32 (lanes 32..63)
control: s_mov_b64 s[16:17], 0 C C 0

No over-rejection on the intended case: the break-loop listings still classify as before — BREAK_LOOP tier A, BREAK_LOOP_2 tier A (both reasons empty), WIDENED_OR C and NARROWED_OR A. So the fix tightens the rule where the value reaching the def is not lane-local without losing the compiler-break idiom it was written for.

Rest of the check, all on the new head:

  • tests/semantic/test_wave64_halves.py: 141 tests OK.
  • Full translator suite (scripts/run_semantic_tests.py tests/semantic, 12 jobs): 447 files, 5,972 tests, 2 files failed in 119 s — test_image_atomics_guard (47 failures) and test_image_store_d16 (1), both failing with the same counts on main dde82f27e without this PR.
  • GPU suite, full scripts/run_gpu_tests.py: native 224/241 passed, 16 skipped; LEONIDA_W64_EMULATE=1 224/241 passed, 16 skipped. Both have the known ms_wave_info_s3 flake and every other PASS/SKIP line matches main (0 differing lines); 247/247 fixtures translated and pass spirv-val.
  • w64_graphics.py at wave64 and with RADV_PERFTEST=gewave32: 29 fixtures ok, 0 SKIP, 0 differ; tiers A 11, B 8, C 13, identical to main.

Counts and pass/fail only; no game files. AI-assisted (DeepSeek V4.1 Flash coding agent); runs repeated and reviewed before posting.

@matheusfermiano-source

Copy link
Copy Markdown

Tested ea9dfe8c3 (the PR's diff applied on main dde82f2), full python -I scripts/run_gpu_tests.py, each GPU compared with main on the same machine and binaries, CachyOS Linux: pass.

GPU Driver main this PR Difference
AMD Radeon 660M (RDNA2 iGPU, gfx1035, Ryzen 5 7535HS), subgroup 32..64 RADV, Mesa 26.3.1 225/241 passed, 16 skipped 225/241 passed, 16 skipped same results as main
NVIDIA GeForce RTX 3050 Laptop (Ampere), subgroup 32 NVIDIA 620.73.04 192/241 passed, 48 skipped 192/241 passed, 48 skipped fails on main too: ms_wave_info_s3 (#6172)
  • Radeon 660M wave64 checks (PR applied, test programs built from main, which gives 225/241 emulated and 29 ok): LEONIDA_W64_EMULATE=1 run_gpu_tests.py 225/241 passed, 16 skipped; runtime/test/shaders/w64_graphics.py 29 ok, 0 SKIP, 0 other.

No game files. AI-assisted (Claude Code).

@slint6614-dev

Copy link
Copy Markdown
Contributor

AMD RDNA2 GPU-suite check of ea9dfe8c3 (AI-assisted): full scripts/run_gpu_tests.py with this branch as-is on a Ryzen 5 9600X iGPU "AMD Radeon(TM) Graphics" (gfx1036), AMD Adrenalin 26.11.2, Windows 11 26300; test programs from a fresh build of main 867d922.

221 translated, 221 pass spirv-val; 201/217 passed, 16 skipped, 0 failed. Every fixture this branch has gives the same result as on main 867d922; the 24 fixtures missing here are ones added to main since (the branch is 945 commits behind main), so a rebase would let the full current suite run on it.

@IxMxAMAR

Copy link
Copy Markdown

Checked ea9dfe8c on AMD's Windows driver: Windows 11 Pro 26200, CPython 3.12.10, RX 9070 XT (RDNA4, AMD 26.11.2).

  • tests/semantic/test_wave64_halves.py: OK at the head. With the base's tools/wave64_halves.py (98fa503f), 9 tests fail.
  • runtime/test/shaders/w64_graphics.py with shaders built by this head and by the base (vk_harness from a main 867d922f build): identical output, 23 ok and 4 SKIP (the GS/VS tier C fixtures, which need RADV; the pixel tier C fixtures run on this GPU). No existing fixture has the patterns this reclassifies, so this shows no change on AMD's Windows driver rather than the new tier A cases on hardware.
  • It merges cleanly with wave64_halves: EXEC written from a constant or plain data is tier C tainted-exec #8521, which also edits tools/wave64_halves.py.

No game files. AI-assisted.

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.