Skip to content

startup: accept compute execz blocks whose scalar results are dead - #2314

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
NiiRoZz:startup/gfx2hlsl-compute-execz-scalars
Nov 25, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
NiiRoZz:startup/gfx2hlsl-compute-execz-scalars

Conversation

@NiiRoZz

@NiiRoZz NiiRoZz commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Change

Replaces the blanket refusal (#2182) of scalar instructions in a compute block that s_cbranch_execz skips with
a 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 for
every 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_andn2 that keep exec, and a 32-bit
s_or/s_xor/move from a register that only holds an exec copy made earlier in the block. A 64-bit restore from
such copies is refused: the tracked set names registers, not which exec half was copied, so two s_mov_b32 copies
restored by s_mov_b64 exec would have set exec_hi from exec_lo.

Liveness is a backward pass over the decoded instructions and their successors (branches and proven calculated
s_setpc_b64 jumps). Reads are over-approximated (any scalar instruction may write SCC; m0 always live); kills
count 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_setpc inside the block); a branch out of the block; a backward s_cbranch_execz.

Behavior narrowing against main, deliberate: a proven s_setpc_b64 inside a skipped block, and a v_cmp/v_cmpx
vcc definition that is live at the join, are refused where main accepted them (main's blanket refusal exempted
them).

AI-assisted (Claude Code).

Base and overlaps

  • Head 3cd1c08c (one commit), base 4ea0c770 (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.
  • The head is one commit: the earlier three were squashed to replay the rebase once. The rebase onto
    ea468f30 conflicted in CMakeLists.txt, the compute check and gfx2hlsl.py; the final move to 4ea0c770 was 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 last
    move to 4ea0c770 was 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).
Case What it checks Control
G three of eight lanes active; the block loads a descriptor and computes a dead scalar g-scalar-dropped rejected
H nested s_and_saveexec/s_or if inside the block h-inner-unpredicated rejected
K only group 1 enters the block; other groups skip it as a wave k-block-entered rejected

Pinned refusals in tests/startup_gfx2hlsl_compute_check.py: 64-bit exec restore from two 32-bit copies, branch out
of the block, vcc definition read by s_cbranch_vccz after the join, proven s_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 the
direct-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-line
only held direct branches, so a proven s_setpc_b64 into the block bypassed a copy the restore assumed. It now holds
the 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.py the check fails at the first accepted-case assertion.

Limits

  • Exec writes in blocks with branches stay refused (needs a must-analysis of in-block exec copies).
  • New pinned words are hand-encoded (no llvm-mc locally).
  • Graphics stages are unchanged; they still skip execz blocks per lane.
  • Fixtures are source-built gfx1013 programs; no game bytes. This does not show full-title startup.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

🤖 Generated with Claude Code

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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/-32
  • python3 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 in exec_stays_clear (the 64-bit restore refusal). The test fails with accepted, expected a refusal naming 's_mov_b64 ... exec write'. Killed.
  • Mutation 2: made the join liveness {'m0'} only, ignoring live_in[t]. The test fails with accepted, expected a refusal naming 's_add_u32 ... definition of s20'. Killed.
  • Both mutations reverted.

Findings

  • P1: none.
  • P2: none.
  • Nit: exec_copies_after tracks 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 the saved initialisation, saying why s_mov_b32 exec_hi, sN is refused (tokens are {exec_hi}, which is_exec rejects), would help the next reader.
  • Nit: the branch-target parse int(parse(asm)[1][0].split('_')[1], 16) now appears four times in execz_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 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

@NiiRoZz could you rebase this branch onto current main and force-push?

GitHub reports head 6f4033eb as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (4aaea119):

  • CMakeLists.txt
  • tests/startup_gfx2hlsl_compute_check.py
  • tools/startup/gfx2hlsl.py

Commands run locally:

git fetch origin main pull/2314/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 2314 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

@NiiRoZz could you rebase this branch onto current main and force-push?

GitHub reports head 3b51b327 as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (ea468f30):

  • CMakeLists.txt
  • tests/startup_gfx2hlsl_compute_check.py
  • tools/startup/gfx2hlsl.py

Commands run locally:

git fetch origin main pull/2314/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 2314 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

@NiiRoZz
NiiRoZz force-pushed the startup/gfx2hlsl-compute-execz-scalars branch from 3b51b32 to edb1638 Compare November 25, 2026 13:06
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>
@NiiRoZz
NiiRoZz force-pushed the startup/gfx2hlsl-compute-execz-scalars branch from edb1638 to 3cd1c08 Compare November 25, 2026 13:07

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 straight for exec writes: killed.
  • s_andn2 with exec as the kept operand accepted for any operand (return True): SURVIVED.
  • Remove the unconditional m0 live entry: SURVIVED.

Findings:

  • P1: none.
  • P2: none.
  • Nit 1, tools/startup/gfx2hlsl.py exec_stays_clear, s_andn2 branch: no test refuses s_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 the m0 rule. Add a block that defines m0 where nothing else reads it, and expect a refusal.

AI-assisted; commands listed were executed locally.

@NiiRoZz

NiiRoZz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in 3cd1c08 and rebased onto main. The incoming-target set that decides whether a skipped block is straight-line now includes proven calculated s_setpc_b64 targets; 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 base ea468f3; the last move to 4ea0c77 was 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).

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

@NiiRoZz could you rebase this branch onto current main and force-push?

GitHub reports head 3cd1c08c as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (43608f2e):

  • CMakeLists.txt
  • tests/startup_gfx2hlsl_compute_check.py

Commands run locally:

git fetch origin main pull/2314/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 2314 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 -- .):

  1. Disabled the "live definition at the join" refusal ((may - EXEC_KEYS) & live). Killed: the test expected the definition of s20 refusal.
  2. Made exec_stays_clear always return True. Killed: the test expected the exec write refusal.
  3. Removed the saveexec/wrexec SCC must-write in scalar_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 base SCC write): mutation 3 survived. Add one case where an s_*_saveexec in a skipped block is followed by an SCC read after the join, or drop the redundant clause.
  • nit: exec_stays_clear and exec_copies_after track 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.

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.

3 participants