startup: accept compute execz blocks whose scalar results are dead #2306
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2314"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T11:57:54Z.
Change
Replaces the blanket refusal (#2182) of scalar instructions in a compute block that
s_cbranch_execzskips witha liveness rule, and accepts exec writes that cannot reactivate an inactive lane. Refs #2274 (item: execz exec
write and scalar handling).
The wave runs the block when any lane is active, so its scalar results (SGPRs,
vcc,m0, SCC) are the same forevery lane; the one-lane model skips it for an inactive lane. The two differ only if the lane reads, after the
join, scalar state the block defines. So the block is translated unchanged when everything it may define is dead
where it joins. Loads in the block run only for active lanes; nothing is hoisted.
Exec writes inside the block are accepted only in a straight-line block, and only if they cannot set the exec bit
of a lane whose bit is clear:
s_and_saveexec,v_cmpx,s_and/s_andn2that keep exec, and a 32-bits_or/s_xor/move from a register that only holds an exec copy made earlier in the block. A 64-bit restore fromsuch copies is refused: the tracked set names registers, not which exec half was copied, so two
s_mov_b32copiesrestored by
s_mov_b64 execwould have setexec_hifromexec_lo.Liveness is a backward pass over the decoded instructions and their successors (branches and proven calculated
s_setpc_b64jumps). Reads are over-approximated (any scalar instruction may write SCC;m0always live); killscount only printed destinations.
Still refused: a definition live at the join; any other exec write or an exec write in a block with a branch;
effects outside scalar registers (scalar stores/atomics, barriers,
s_endpgm,v_writelane,s_movrel*,s_setpcinside the block); a branch out of the block; a backwards_cbranch_execz.Behavior narrowing against main, deliberate: a proven
s_setpc_b64inside a skipped block, and av_cmp/v_cmpxvccdefinition that is live at the join, are refused where main accepted them (main's blanket refusal exemptedthem).
AI-assisted (Claude Code).
Base and overlaps
3cd1c08c(one commit), base4ea0c770(origin/main). Upstream compute cases E (saveexec) and F (LDS exchange)stay as they are; this change's cases are G, H and K. Upstream's
translate()retry loop is kept;execz_refusals()is computed once before it and refuses by offset inside it. No upstream refusal was removed, and no upstream test
was weakened or deleted. Neither the saveexec change nor the LDS exchange covers the execz liveness rule, so
nothing of ours was dropped as a duplicate.
ea468f30conflicted inCMakeLists.txt, the compute check andgfx2hlsl.py; the final move to4ea0c770was clean.Verification
Windows 11 build 26300, Python 3.13.
python -B tests/startup_gfx2hlsl_*_check.py(57 files),tests/startup_translator_check.py,tests/docs_links_check.py,tests/bidi_controls_check.py: all pass.git diff --check origin/main...HEAD: clean.ctest --preset release --no-tests=error -R "^startup_gfx2hlsl|^startup_translator|^startup_tools_lint|^startup_compute"after a rebuild of the release tree: 141 passed, 0 skipped, 0 failed (run on the rebase onto
ea468f30; the lastmove to
4ea0c770was clean and not retested). Adapters, from the test output: WARP 10.0.26100.10068(debug layer on, 0 errors, 0 warnings) and NVIDIA GeForce RTX 5090, driver 32.0.16.2135 (debug layer on, 0 errors,
0 warnings).
g-scalar-droppedrejecteds_and_saveexec/s_orif inside the blockh-inner-unpredicatedrejectedk-block-enteredrejectedPinned refusals in
tests/startup_gfx2hlsl_compute_check.py: 64-bit exec restore from two 32-bit copies, branch outof the block,
vccdefinition read bys_cbranch_vcczafter the join, provens_setpc_b64(GETPC/ADD/ADDC/SETPC)inside the block, and a calculated jump that lands on the restore and bypasses
s_mov_b32 s21, exec_lo(with thedirect-branch control next to it). Both are refused as "exec write".
Calculated-target fix (review of
6f4033eb): the incoming-target set that decides whether a block is straight-lineonly held direct branches, so a proven
s_setpc_b64into the block bypassed a copy the restore assumed. It now holdsthe proven calculated targets too, built in the same loop as the liveness successors.
Negative controls: with the 32-bit restriction removed, the 64-bit restore assertion fails ("accepted, expected a
refusal"); with the calculated targets left out of the incoming set, the calculated-jump assertion fails the same way
(rechecked after the rebase); with main's
gfx2hlsl.pythe check fails at the first accepted-case assertion.Limits
llvm-mclocally).Checklist
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:00:07Z.
Review: COMMENTED
Review of head
6f4033eb00c7d26ad319b3a527d34ca745fcd79a(comment only, no approval).Scope read:
tools/startup/gfx2hlsl.py(newscalar_effects,exec_stays_clear,exec_copies_after,Stage.execz_refusals, call site in the block loop),tests/startup_gfx2hlsl_compute_check.py,CMakeLists.txt,docs/experiments.md. Title is neutral, no clean-room concerns seen.Commands run locally (worktree at the head SHA):
git diff --stat origin/main...HEAD: 4 files, +391/-32python3 tests/startup_gfx2hlsl_compute_check.py:Self-test passed.python3 tests/docs_links_check.py:Checked 18 Markdown files and 448 links.python3 tests/bidi_controls_check.py:Checked 1609 tracked ... files: no bidirectional controls.git diff --check origin/main...HEAD: cleanbase.endswith('32')condition inexec_stays_clear(the 64-bit restore refusal). The test fails withaccepted, expected a refusal naming 's_mov_b64 ... exec write'. Killed.{'m0'}only, ignoringlive_in[t]. The test fails withaccepted, expected a refusal naming 's_add_u32 ... definition of s20'. Killed.Findings
exec_copies_aftertracks register names and not which exec half was copied. The 32-bit-only restore rule covers this and is tested. A one-line comment at thesavedinitialisation, saying whys_mov_b32 exec_hi, sNis refused (tokens are{exec_hi}, whichis_execrejects), would help the next reader.int(parse(asm)[1][0].split('_')[1], 16)now appears four times inexecz_refusals. A small helper would cut the repetition.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T12:28:46Z.
Review: CHANGES_REQUESTED
I reproduced a gap in the straight-line proof on
6f4033eb. The liveness successor set includes a provens_setpc_b64edge, but the incoming-target set used to validate EXEC copies only includes direct branches. That lets a calculated entry bypass a copy that the restore assumes ran.A source-built decoded test with GETPC/ADD 20/ADDC/SETPC resolves the edge from 0x14 directly to the restore at 0x20, bypassing
s_mov_b32 s21, exec_loat 0x1c. The execz scan accepts it. Replacing that edge with a direct branch to 0x20 correctly produces the exec-write refusal. Please include proven calculated targets in the incoming-edge check and pin this as a refusal alongside the existing direct-branch control.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:52:43Z.
@NiiRoZz could you rebase this branch onto current
mainand force-push?GitHub reports head
6f4033ebas conflicting withmain, so it cannot be merged as is.Files that conflict with current
main(4aaea119):CMakeLists.txttests/startup_gfx2hlsl_compute_check.pytools/startup/gfx2hlsl.pyCommands run locally:
Once it is rebased and CI is green it will be re-checked right away.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:55:40Z.
@NiiRoZz could you rebase this branch onto current
mainand force-push?GitHub reports head
3b51b327as conflicting withmain, so it cannot be merged as is.Files that conflict with current
main(ea468f30):CMakeLists.txttests/startup_gfx2hlsl_compute_check.pytools/startup/gfx2hlsl.pyCommands run locally:
Once it is rebased and CI is green it will be re-checked right away.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:11:40Z.
Review: COMMENTED
Review of head
3cd1c08c45696579c5ef52fdf8213e0bbd41957b(Linux only; no Windows run, so the new WARP control cases are not independently verified here).Checks: title neutral, mergeable, Linux CI jobs pass, the Windows build was still pending when I looked.
Commands run locally in a clean worktree of the PR head:
python3 tests/startup_gfx2hlsl_compute_check.py: pass.python3 tests/docs_links_check.py: pass (19 files, 453 links).python3 tests/bidi_controls_check.py: pass (1637 files).git diff --check origin/main...HEAD: clean.Logic read (
execz_refusals,exec_stays_clear,exec_copies_after,scalar_effects): the backward liveness pass, the over-approximated reads, the under-approximated kills, the straight-line rule for exec writes and the 32-bit-only restore all look correct to me. I found no semantic error. The old backward-branch case is now refused throught <= b, which is the safe direction.Mutations (each applied, test script run, then
git checkout -- .):base.endswith('32')restore rule: killed.straightfor exec writes: killed.s_andn2with exec as the kept operand accepted for any operand (return True): SURVIVED.m0live entry: SURVIVED.Findings:
tools/startup/gfx2hlsl.pyexec_stays_clear,s_andn2branch: no test refusess_andn2 exec, x, exec-style forms, where exec is not the kept first source. Add one refusal fixture so the check cannot loosen unnoticed.tools/startup/gfx2hlsl.py,live = live_in[t] | {'m0'}: no fixture depends on them0rule. Add a block that definesm0where nothing else reads it, and expect a refusal.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T13:29:51Z.
Review: APPROVED
Rechecked
3cd1c08c. The incoming-edge proof now includes every proven calculated target. The regression reproduces the GETPC/ADD/ADDC/SETPC edge that skips the EXEC copy, and both the calculated and direct versions are refused. The host checks and generated compute dispatches passed independently on WARP and RTX 4060 Laptop with the debug layer enabled. This clears my earlier blocking finding.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:39:59Z.
Review: COMMENTED
Review of head
66e64b334f9da0812c587976ee0b5a5863ba7449(comment only, no approval).Scope:
tools/startup/gfx2hlsl.py,tests/startup_gfx2hlsl_compute_check.py,CMakeLists.txt,docs/experiments.md. Title is neutral and the change is mergeable. Linux, gfx1013 fixtures and Windows CI checks are green. The /O2 and chart jobs were skipped.Commands run locally on this head:
git diff --stat origin/main...HEAD: 4 files, +400/-30.python3 tests/startup_gfx2hlsl_compute_check.py: passes (execz refusals included).python3 tests/docs_links_check.py: 457 links OK.python3 tests/bidi_controls_check.py: OK.git diff --check origin/main...HEAD: clean.Mutations (each reverted with
git checkout -- .):(may - EXEC_KEYS) & live). Killed: the test expected thedefinition of s20refusal.exec_stays_clearalways return True. Killed: the test expected theexec writerefusal.saveexec/wrexecSCC must-write inscalar_effects. SURVIVED: no test depends on that line.Findings
tools/startup/gfx2hlsl.py,scalar_effects, the'saveexec' in base or 'wrexec' in baseSCC write): mutation 3 survived. Add one case where ans_*_saveexecin a skipped block is followed by an SCC read after the join, or drop the redundant clause.exec_stays_clearandexec_copies_aftertrack copies by register name only. The comment says only 32-bit restores are trusted, which is conservative and only adds refusals. A short test for a 64-bit restore refusal would pin that.Reasoning on the dead-scalar analysis: reads are over-approximated and must-writes under-approximated, so any error only adds refusals. m0 is treated as always live. Backward
s_cbranch_execzand branches out of the block are refused. I found no unsound acceptance.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T13:13:12Z.
Fixed in
3cd1c08cand rebased onto main. The incoming-target set that decides whether a skipped block is straight-line now includes proven calculateds_setpc_b64targets; it is built in the same loop as the liveness successors. Your GETPC / ADD 20 / ADDC / SETPC shape landing on the restore is pinned as an "exec write" refusal next to the direct-branch control; with the fix removed, the new assertion fails ("accepted"). On the release preset, 141 startup_gfx2hlsl, startup_translator and startup_compute tests passed (0 skipped, 0 failed) on WARP and an RTX 5090, debug layer on with 0 errors, run on baseea468f30; the last move to4ea0c770was a clean rebase and only the Python compute check was rerun. Our compute cases are now G, H and K, because main took E and F.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:34:17Z.
@NiiRoZz could you rebase this branch onto current
mainand force-push?GitHub reports head
3cd1c08cas conflicting withmain, so it cannot be merged as is.Files that conflict with current
main(43608f2e):CMakeLists.txttests/startup_gfx2hlsl_compute_check.pyCommands run locally:
Once it is rebased and CI is green it will be re-checked right away.
AI-assisted; commands listed were executed locally.