Skip to content

startup: accept compute execz live definitions whose reads are proven - #2557

Merged
R0Y00 merged 15 commits into
R0Y00:mainfrom
NiiRoZz:startup/gfx2hlsl-compute-execz-live-mask
Nov 26, 2026
Merged

R0Y00 merged 15 commits into
R0Y00:mainfrom
NiiRoZz:startup/gfx2hlsl-compute-execz-live-mask

Conversation

@NiiRoZz

@NiiRoZz NiiRoZz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Refs #2274

Builds on #2509 (exec writes proven over every path of a compute s_cbranch_execz block) and sits beside #2505
(the i1-phi lane mask) and #2535 (the exec-write dataflow speed-up). All three are merged; the branch has main
merged in, so the diff is this change only: two rules, a follow-up that refuses a second write of the narrowed
mask, and a commit that makes the read search cheap and narrows rule 1 to a straight run from the join.

What changes

The compute translator models one lane. A block that s_cbranch_execz skips is run by the wave whenever any lane
is active, while the model skips it for an inactive lane. Until now such a block was refused as soon as a scalar
it defines was live at the join. Two read shapes after the join are now proven instead:

  1. Absorbed read (startup: accept execz live definitions whose reads exec absorbs).
    • The exec writes inside the block are proven (startup: prove exec writes over every path of a compute execz block #2509), so a lane that skipped the block has its exec bit clear
      at the join, in the wave and in the model.
    • Suppose the read lies in a straight run that starts at the join, that only the block enters (no other
      branch targets the join or any instruction up to the read), and that no instruction in that run writes
      exec before the read. Then W & exec and exec & W
      (s_and) give that lane 0, and ~(W & exec) (s_nand) and W | ~exec (s_orn2 with exec second) give it
      1, whatever the block left in W. (s_nand on a lane mask is still refused later by the lane-mask lowering,
      so no accept test uses it.)
    • The search follows every path from the join until W is written again. A read that overwrites W ends W's
      definition.
    • Typical shape: v_cmp_* vcc inside the block, with s_and_b32 S, vcc_lo, exec_lo at the join.
  2. Narrowed mask (startup: accept execz live masks the block only narrows by clear lanes).
    • Every write of W in the block is s_andn2 W, W, X.
    • The exec-write pass proves X clear for a skipped lane at that instruction, on every path from the branch.
    • So that lane keeps its bit of W, and at the join W holds the model's bit.
    • The reads accepted are bitwise mask operations that take bit n of the result from bit n of W, in the same
      wave half, and write it to that half's exec word or back to W. Typical shape: s_andn2_b32 R, R, exec_lo in
      the block, then s_mov_b32 exec_lo, R at the join.

Every other read keeps the refusal, and the reason now names the first read that is not proven
(...: read by s_mov_b32 after the join). Still refused:

  • a copy into another register, a data read, or a vccz branch;
  • an absorbed form once exec has changed since the join, after a branch target, or at a join a loop
    re-enters;
  • an s_orn2 with exec first, or exec of the other half;
  • another write form of the narrowed mask, or an X that is not known clear;
  • a block that a branch from outside enters;
  • m0 and SCC, which have implicit readers.

The i1-phi rule from #2505 is unchanged. A live word is accepted when that rule holds or when every one of its
reads is proven. Its accepted reads (v_cndmask select, carry-in, s_and_saveexec, and s_and with exec after
the exec restore) all come after exec has been restored. With the phi rule stubbed out, none of its eight accept
cases in the compute check is taken by the new rules, so the two do not overlap.

Tests (measured)

Measured at 12b6617d, before main was merged in. At the merged head e131e319 the first and third rows were run again and pass. Python 3.13, pure Python, no GPU, no ctest.

Command Result
python -B tests/startup_gfx2hlsl_compute_check.py passes (... execz and sample refusals pass)
python -B tests/startup_gfx2hlsl_compute_check.py binary <llvm-mc 15> fixture words match llvm-mc
python -B tests/startup_translator_check.py 0 failed
every no-argument tests/startup_gfx2hlsl_*_check.py (66 files) all exit 0

New in tests/startup_gfx2hlsl_compute_check.py:

  • Case N (absorbed read). The block sets vcc from a compare, and the join ANDs it with exec before restoring
    exec. vcc is all ones before the branch, so lanes 6-7, which skip the block, carry a stale vcc. Expected:
    lanes tid.x < 3 store one word each and every other word keeps the sentinel. The exact HLSL is asserted.
    Control n-unmasked drops the & exec.
  • Case O (narrowed mask). The block narrows exec to lanes 0-2 and removes them from the saved mask with
    s_andn2_b32 s0, s0, exec_lo, and the join moves s0 into exec. Expected: lanes 3-7 store, and lanes 6-7 skip
    the block and keep their bit. The exact HLSL is asserted. Control o-mask-kept drops the narrowing.
  • Accepted splices: s_and with exec in both operand orders, s_orn2 with exec second, and an s_and that
    overwrites vcc and is followed by a vccz branch. For rule 2, the narrowed restore.
  • Negative controls, one per refusal shape, each asserting the reason and the named read:
    • rule 1: a read after the exec restore, a copy, exec | ~vcc, exec_hi in a 32-bit op, a vccz branch
      after an absorbed read, and a loop that branches back to the join;
    • rule 2: X not clear, a non-andn2 write, a second write after the narrowing, a copy and a data read after the
      join, and a block entered from outside.
  • Unit asserts for exec_absorbs, kept_halves and lane_read, including the 64-bit and cross-half forms.
  • Both controls are registered in the CMake control list next to m-else-unswitched. Like M's, their first
    mismatch is not pinned.

Translator mutations that turn the check red (run in-process at fcc249bb, not committed; the only later
commit changes docs only):

  • rule 1: s_orn2 accepted in either operand order; exec writes after the join ignored; re-entry of the
    join ignored; every read accepted;
  • rule 2: kept_halves ignoring the clear facts; lane_read accepting any destination; the entered-block guard
    dropped; kept halves joined by union instead of intersection.

All eight fail the check. A sanity mutation that lets s_or absorb is caught only by the unit asserts.

Cost: on the six largest local compute requests, the time spent in the execz check went from about 0.9 s on
the base to about 1.2 s per request (one machine, single run each). The search is memoized per live word and
stops at the first unproven read.

Rule 1 first proved "exec unchanged since the join" with a per-join dataflow map over every path. That was
the main cost, so fcc249bb replaced it with the straight-run check above. The narrower check accepts fewer
reads: on the 359 requests below, 2,366 more v_cmp sites stay refused than with the map (50,324 against
47,958). First refusals are the same. The map version also passes every negative control in this PR,
including the loop that re-enters the join, so it was not shown to be wrong; it was dropped for cost and
for a simpler argument.

Effect on local compute requests (measured)

This was measured on the local compute requests whose recorded failure names a v_cmp* or s_andn2* live
definition at an execz join: 359 requests, 4 workers. The base is the merged branch before these commits, and
both runs used fresh copies.

First refusal:

  • 334 of the 359 stop earlier, at operand 'src_scc' in s_mov_bN, on both base and head.
  • 19 requests change their first refusal:
Before After Requests
s_andn2_bN live definition (two words) s_cbranch_sccN inside the block: branch out of the block 13
s_andn2_bN live definition (one word) s_cbranch_sccN inside the block: branch out of the block 1
s_lshr_bN live definition v_cmp_lt_uN_eN live definition of vcc 2
v_cmp_lt_fN_eN live definition of vcc s_bcntN_iN_bN 1
v_cmp_eq_fN_eN live definition s_load through sN holding ('descnum',) 1
v_cmp_class_fN_eN live definition compute image_store requires dN 1

Refusal sites inside these 359 requests (every execz block, not only the first refusal), at 12b6617d's
translator, with rule 1 alone and with both rules:

Kind of live definition Base: requests / sites Rule 1: requests / sites Both: requests / sites
any execz refusal (requests) 359 357 357
v_cmp* 351 / 61,607 347 / 50,324 347 / 50,324
s_andn2_bN 352 / 30,594 352 / 29,959 345 / 28,184
other forms 356 / 800,079 352 / 761,904 352 / 761,904

Most of what remains is read by something the rules do not cover. Among v_cmp sites, the most common first
unproven reads are s_mov_bN (12,972, a copy) and an s_and_bN that is not absorbed (6,192: exec changed
since the join, a branch target in between, or no exec operand).

No request translates fully because of this change alone. The next refusal for the narrowed-mask shape is the
whole-wave s_cbranch_scc* exit that follows the s_andn2 inside the block.

Not checked (hypotheses)

  • No dispatch was run. The expected words of cases N and O, and the claim that their controls mismatch, follow
    from the ISA semantics; WARP and hardware runs have not observed them.
  • The decoder prints a 32-bit spelling for some wave64 VOPC destinations, so a high-word write can be missing
    from the may-writes. This is pre-existing. An absorbed low-word vcc read could now let an unchecked vcc_hi
    read through where the low-word refusal used to hide it.
  • The absorbing s_and sets SCC. SCC is whole-wave on hardware and per-lane in the model; that is the existing
    SCC model, unchanged here.
  • The absorbed-read rule keys on the reads, not on the defining instruction, so it also accepts live definitions
    from other forms (for example s_lshr) when every read is absorbed.

🤖 Generated with Claude Code

NiiRoZz and others added 12 commits November 25, 2026 19:50
A block that s_cbranch_execz skips per lane kept every exec write refused
unless the block was straight-line. The check now runs a forward pass over
the block: for each instruction the wave can reach from the branch it keeps
the scalar words in which a skipped lane's bit is known clear on every path,
branches and loops inside the block included, with the wave half each fact
holds for. An exec write is accepted when it leaves exec among them.

That accepts an if/else whose arms have their own s_cbranch_execz, the
s_or_saveexec/s_xor switch, s_andn2_wrexec, loops, and masks built from a
zero literal, when every restore reads a mask saved inside the block. A
block entered by a branch from outside, a mask from before the block or
from only some paths, the forms the pass does not follow and a copy of the
other exec half stay refused.

Case M runs an if/else block on a D3D12 device; a control that drops the
switch to the else arm must mismatch.

Refs R0Y00#2274

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A compute block that s_cbranch_execz skips was refused when a definition
in it was live at the join. With the block's exec writes proven, a lane
that skipped the block has its exec bit clear at the join, in the wave
and in the one-lane model. While exec is unchanged since the join on
every path, W & exec, exec & W, ~(W & exec) and W | ~exec give that lane
a result independent of W. Accept the definition when every read of it
from the join on, until W is written again, is such a read; otherwise
keep the refusal and name the first read that is not proven.

Case N runs the join form `s_and_b32 S, vcc_lo, exec_lo` on the GPU
path, with control n-unmasked dropping the AND.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The exec-write pass parsed the same instruction text once per visit and
join_writes rescanned every instruction for every branch. Cache the parse
and the clear shape per text, and compute the written registers once.
Three large compute requests: 19.1 s -> 8.4 s, same refusals.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A mask W defined in a compute execz block and read after the join was
refused. When every write of W in the block is `s_andn2 W, W, X` and the
exec-write pass proves X clear, at that instruction and on every path
from the branch, for a lane that skipped the block, the lane keeps its
bit of W, so W at the join holds the model's bit. Accept reads after the
join that take bit n of the result from bit n of W in the same wave half
and write it to that half's exec word or back to W. Copies, data reads,
other writes of W and blocks entered from outside stay refused.

Case O narrows the saved mask in the block and restores exec from it at
the join, with control o-mask-kept dropping the narrowing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sk branch

Conflicts with the i1-phi lane-mask rule from upstream: both acceptances
are kept; a live word is accepted when phi_mask_ok holds or every read
after the join is proven.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the negative control that turns red when the narrowed-mask rule
joins the kept halves of a word's writes by union instead of
intersection, and leave the new device controls unpinned like case M's
until a dispatch records their first mismatch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The live-read proof walked the whole program for every live word and
recomputed the exec-unchanged map for every join, which more than
doubled the time spent in execz_refusals on large compute programs.
Compute each word's verdict only when an instruction needs it, stop the
search at the first read that is not proven, skip kept_halves for
writes that are not s_andn2, and replace the exec-unchanged map with a
check that the read ends a straight run from the join, which only the
block enters, with no exec write in it. That check is narrower than the
map; the measured join shapes all read at or right after the join.

A loop that re-enters the join after the exec restore is a new negative
control.

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

R0Y00 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

31f63dc5 fixes the failing join fixture. The first guard can now prove lane absorption, but the joined descriptor/number is still refused at the numeric use. The fixture pins that refusal instead of the old diagnostic. The seven focused Release CTests passed on WARP and RTX 4060 Laptop, including the N/O dispatches and both mutation controls. Before merging, please resolve the wave64 case noted in the PR: prove the decoded compare's high-half write is tracked, or conservatively refuse a high-half consumer where the relaxed low-half rule would otherwise let it through. A source-built high-half read after the join should distinguish that from the accepted low-half case.

@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 31f63dc5 (comment only, no merge from this side).

Code and fixtures read against main (5 files, +332/-23). The two new rules (absorbed read, narrowed mask) are scoped tightly and the refusal list in the body matches the code (exec_absorbs, kept_halves, lane_read in tools/startup/gfx2hlsl.py).

Open item, not fixed in this head: the wave64 case that @R0Y00 asked to be resolved before merging. The body itself lists it under "Not checked": the decoder can print a 32-bit spelling for a wave64 VOPC destination, so a vcc_hi write may be missing from the may-writes, and an absorbed low-half vcc read could let an unchecked vcc_hi read through. No test or code change in this head covers it. Suggested fix, as @R0Y00 said: either prove the compare's high-half write is tracked, or refuse a high-half consumer when only the low-half rule would let it through. Add a source-built fixture with a high-half read after the join.

Startup claim: this touches the startup translator path (#2274). I only reviewed code and fixture tests. Nothing here was run on the game, so any startup result stays with the maintainers. The merge is left to @R0Y00 or MasterDomino.

Commands run locally (Linux, Python, no GPU):

  • python3 -B tests/startup_gfx2hlsl_compute_check.py: passes
  • python3 -B tests/startup_gfx2hlsl_join_symbols_check.py: passes
  • python3 tests/docs_links_check.py: 19 files, 486 links ok
  • python3 tests/bidi_controls_check.py: ok
  • git diff --check origin/main...HEAD: clean
  • Mutation 1: allow or in exec_absorbs and drop the exec check: the compute check fails (assertion on the join refusal). Reverted.

Not run: Win2025 WARP dispatch of cases N and O (R0Y00 reports those passed on WARP and RTX 4060 for this head).

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Pushed 4f9974da on top of 31f63dc5 (main merged, no force, no rebase). Three commits:

  1. Merge of main. Conflicts kept both sides in CMakeLists.txt (control list) and tools/startup/gfx2hlsl.py (waterfall read pre-pass + the execz live-read search).
  2. Test fixture rename: this PR's compute case N clashed with main's waterfall case N (the later dict entry silently replaced the first), so this PR's is now NM.
  3. Wave64 point from the review (the open item before merge): scalar_effects now counts vcc_hi as a may-write of a compare / carry-out whose decoded text names only vcc_lo, and exec_absorbs / lane_read refuse a 32-bit form that reads vcc_hi (its bit n is lane 32+n, not lane n of exec_lo). New check in tests/startup_gfx2hlsl_compute_check.py: s_and_b32 s23, vcc_hi, exec_lo after the join is refused ("definition of vcc_hi, live where the block joins"), while the low-half read stays accepted. Removing either change makes this check fail.

Verification:

  • Linux: python3 -B tests/startup_gfx2hlsl_*_check.py all pass, tests/docs_links_check.py, tests/bidi_controls_check.py, git diff --check origin/main...HEAD clean.
  • Win2025 (default 5-slot pool, --patch of the merged content, --targets offscreen_check, --regex 'startup_gfx2hlsl_(compute|join_symbols).*(_warp|_controls)$'): dev 21/21 and release 21/21 passed on WARP, including the N/NM and O dispatches and all mutation controls. The two python checks passed too.
  • Not run: the *_hardware tests (the VM has WARP only). tests/startup_run_ps1_check.py fails on Win2025 both times I ran it (launcher stub exit 7, unrelated to these files), so I left it out of the python-check list for this run.

This touches the startup translator path; I reviewed code and fixtures only, nothing was run on the game. The merge stays with @R0Y00 or MasterDomino.

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 4f9974d (comment only, no approval).

Result: no blocking findings.

What I checked

  • execz_live_read and the helpers (exec_absorbs, kept_halves, lane_read, high_half_of_b32): the rule is conservative. A live definition is accepted only when every read after the join is proven, and the first unproven read is named in the refusal text.
  • Wave64 vcc_hi: scalar_effects now adds vcc_hi as a may-write for v_cmp, v_add_co, v_sub_co, v_subrev_co and v_div_scale. A 32-bit read of vcc_hi after the join is refused and does not count as absorbed by exec (high_half_of_b32). Both are covered by the test around tests/startup_gfx2hlsl_compute_check.py:1507-1512.
  • Duplicates: no other open PR covers this slice. Prior merged work (#2314, #2466, #2505, #2509) is the base this extends.
  • Tests: new GPU cases NM (vcc & exec) and O (kept mask via s_andn2) run through the existing WARP/hardware readback against a CPU reference, and are registered in CMakeLists.txt as n-unmasked and o-mask-kept next to the sibling controls. The refusal and acceptance matrix is checked in the Python test as well.

Commands run (Linux)

  • git diff --check origin/main...HEAD: clean
  • python3 -B tests/startup_gfx2hlsl_compute_check.py: pass
  • python3 -B tests/startup_gfx2hlsl_join_symbols_check.py: pass
  • python3 tests/docs_links_check.py: pass
  • python3 tests/bidi_controls_check.py: pass
  • Mutation 1: disabled the vcc_hi may-write in scalar_effects. The compute check fails.
  • Mutation 2: added or to the operations accepted by exec_absorbs. The compute check fails.
  • Both mutations reverted afterwards.

Not run here: Win2025 WARP (a separate run reported dev 21/21 and release 21/21 on this head) and nothing on the game. This is a gfx2hlsl lowering; any claim about startup progress stays with the maintainers.

Small note, not blocking: the join_symbols check does not fail under mutation 1 or 2; the compute check is the one that guards them, which is fine.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

FYI, no overlap: Draft #2723 extends phi_mask_ok for the compiler's i1-phi blend (s_andn2 M, M, exec_lo + exec-masked compare + s_or), plus a v_cmp into a zeroed M and s_orn2 into an all-ones M, each with a partial-wave readback. It does not touch the two rules in this PR (reads absorbed by exec, and a mask the block only narrows). Expect a small textual conflict in phi_mask_ok whichever lands second.

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.

The wording and source-built rejection now pin the wave64 high-half case: a compare may write vcc_hi, but ANDing that half with exec_lo cannot prove absorption. The low-half NM and mask-narrowing O cases still pass. I verified both Python checks on this head, then ran the Release offscreen_check CTests with the current main composition: 12/12, no skips, on WARP and RTX 4060 Laptop, including the live-def controls and the existing waterfall broadcast mutation. This resolves my prior review point.

@R0Y00
R0Y00 merged commit 1226f02 into R0Y00:main Nov 26, 2026
5 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.

3 participants