Repository navigation
startup: accept compute execz blocks whose scalar results are dead - #2314
Conversation
tedin7
left a comment
There was a problem hiding this comment.
Review of head 6f4033eb00c7d26ad319b3a527d34ca745fcd79a (comment only, no approval).
Scope read: tools/startup/gfx2hlsl.py (new scalar_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: clean- Mutation 1: dropped the
base.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. - Mutation 2: made the join liveness
{'m0'}only, ignoringlive_in[t]. The test fails withaccepted, expected a refusal naming 's_add_u32 ... definition of s20'. Killed. - Both mutations reverted.
Findings
- P1: none.
- P2: none.
- Nit:
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. - Nit: the branch-target parse
int(parse(asm)[1][0].split('_')[1], 16)now appears four times inexecz_refusals. A small helper would cut the repetition. - Not run: Windows WARP. The change only widens what the translator accepts and refuses for scalar bookkeeping. It adds no new lowering that needs GPU readback. CI (Linux checks, fixtures, Windows build) was still pending when I looked.
AI-assisted; commands listed were executed locally.
R0Y00
left a comment
There was a problem hiding this comment.
I reproduced a gap in the straight-line proof on 6f4033eb. The liveness successor set includes a proven s_setpc_b64 edge, 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_lo at 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.
|
@NiiRoZz could you rebase this branch onto current GitHub reports head Files that conflict with current
Commands run locally: Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally. |
|
@NiiRoZz could you rebase this branch onto current GitHub reports head Files that conflict with current
Commands run locally: Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally. |
3b51b32 to
edb1638
Compare
Replace the blanket refusal of scalar instructions in a block that s_cbranch_execz skips with a liveness rule: the block is translated unchanged when every scalar register, mask and SCC it may define is dead where it joins. Exec writes that cannot reactivate an inactive lane are accepted in straight-line blocks only: no branch in the block and no branch into it, a proven calculated s_setpc_b64 jump included. Only a 32-bit restore from a 32-bit copy of exec is trusted. A v_cmpx source taken as a destination and in-block exec copies tracked across a branch are refused and pinned. Pin the branch out of the block, vcc live at the join, a proven s_setpc_b64 inside the block, and a calculated jump onto the restore that bypasses the copy. Refs R0Y00#2274 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
edb1638 to
3cd1c08
Compare
tedin7
left a comment
There was a problem hiding this comment.
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 through t <= b, which is the safe direction.
Mutations (each applied, test script run, then git checkout -- .):
- Disable the live-definition refusal: killed.
- Drop the
base.endswith('32')restore rule: killed. - Ignore
straightfor exec writes: killed. s_andn2with exec as the kept operand accepted for any operand (return True): SURVIVED.- Remove the unconditional
m0live entry: SURVIVED.
Findings:
- P1: none.
- P2: none.
- Nit 1,
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. - Nit 2,
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.
|
Fixed in 3cd1c08 and rebased onto main. The incoming-target set that decides whether a skipped block is straight-line now includes proven calculated AI-assisted (Claude Code). |
R0Y00
left a comment
There was a problem hiding this comment.
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.
|
@NiiRoZz could you rebase this branch onto current GitHub reports head Files that conflict with current
Commands run locally: Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally. |
tedin7
left a comment
There was a problem hiding this comment.
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 -- .):
- Disabled the "live definition at the join" refusal (
(may - EXEC_KEYS) & live). Killed: the test expected thedefinition of s20refusal. - Made
exec_stays_clearalways return True. Killed: the test expected theexec writerefusal. - Removed the
saveexec/wrexecSCC must-write inscalar_effects. SURVIVED: no test depends on that line.
Findings
- P1: none.
- P2: none.
- nit (
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. - nit:
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. - Windows: this is a Python-side acceptance and refusal analysis with no new HLSL lowering. I did not run Win2025. I judged it unnecessary, and Windows CI is green.
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_execz and branches out of the block are refused. I found no unsound acceptance.
AI-assisted; commands listed were executed locally.
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