Repository navigation
startup: accept compute execz live definitions whose reads are proven - #2557
Conversation
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>
|
|
tedin7
left a comment
There was a problem hiding this comment.
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: passespython3 -B tests/startup_gfx2hlsl_join_symbols_check.py: passespython3 tests/docs_links_check.py: 19 files, 486 links okpython3 tests/bidi_controls_check.py: okgit diff --check origin/main...HEAD: clean- Mutation 1: allow
orinexec_absorbsand 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.
… waterfall fixture from main)
…reads of vcc_hi in the execz lane rules
|
Pushed
Verification:
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
left a comment
There was a problem hiding this comment.
Review of head 4f9974d (comment only, no approval).
Result: no blocking findings.
What I checked
execz_live_readand 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_effectsnow addsvcc_hias a may-write for v_cmp, v_add_co, v_sub_co, v_subrev_co and v_div_scale. A 32-bit read ofvcc_hiafter 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-unmaskedando-mask-keptnext 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: cleanpython3 -B tests/startup_gfx2hlsl_compute_check.py: passpython3 -B tests/startup_gfx2hlsl_join_symbols_check.py: passpython3 tests/docs_links_check.py: passpython3 tests/bidi_controls_check.py: pass- Mutation 1: disabled the
vcc_himay-write inscalar_effects. The compute check fails. - Mutation 2: added
orto the operations accepted byexec_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.
|
FYI, no overlap: Draft #2723 extends AI-assisted; commands listed were executed locally. |
R0Y00
left a comment
There was a problem hiding this comment.
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.
Refs #2274
Builds on #2509 (exec writes proven over every path of a compute
s_cbranch_execzblock) 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_execzskips is run by the wave whenever any laneis 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:
startup: accept execz live definitions whose reads exec absorbs).at the join, in the wave and in the model.
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 & execandexec & W(
s_and) give that lane 0, and~(W & exec)(s_nand) andW | ~exec(s_orn2with exec second) give it1, whatever the block left in W. (
s_nandon a lane mask is still refused later by the lane-mask lowering,so no accept test uses it.)
definition.
v_cmp_* vccinside the block, withs_and_b32 S, vcc_lo, exec_loat the join.startup: accept execz live masks the block only narrows by clear lanes).s_andn2 W, W, X.wave half, and write it to that half's exec word or back to W. Typical shape:
s_andn2_b32 R, R, exec_lointhe block, then
s_mov_b32 exec_lo, Rat 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:vcczbranch;re-enters;
s_orn2with exec first, or exec of the other half;m0and 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_cndmaskselect, carry-in,s_and_saveexec, ands_andwith exec afterthe 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 heade131e319the first and third rows were run again and pass. Python 3.13, pure Python, no GPU, no ctest.python -B tests/startup_gfx2hlsl_compute_check.py... execz and sample refusals pass)python -B tests/startup_gfx2hlsl_compute_check.py binary <llvm-mc 15>fixture words match llvm-mcpython -B tests/startup_translator_check.py0 failedtests/startup_gfx2hlsl_*_check.py(66 files)New in
tests/startup_gfx2hlsl_compute_check.py:vccfrom a compare, and the join ANDs it with exec before restoringexec.
vccis all ones before the branch, so lanes 6-7, which skip the block, carry a stalevcc. Expected:lanes
tid.x < 3store one word each and every other word keeps the sentinel. The exact HLSL is asserted.Control
n-unmaskeddrops the& exec.s_andn2_b32 s0, s0, exec_lo, and the join moves s0 into exec. Expected: lanes 3-7 store, and lanes 6-7 skipthe block and keep their bit. The exact HLSL is asserted. Control
o-mask-keptdrops the narrowing.s_andwith exec in both operand orders,s_orn2with exec second, and ans_andthatoverwrites
vccand is followed by avcczbranch. For rule 2, the narrowed restore.exec | ~vcc,exec_hiin a 32-bit op, avcczbranchafter an absorbed read, and a loop that branches back to the join;
andn2write, a second write after the narrowing, a copy and a data read after thejoin, and a block entered from outside.
exec_absorbs,kept_halvesandlane_read, including the 64-bit and cross-half forms.m-else-unswitched. Like M's, their firstmismatch is not pinned.
Translator mutations that turn the check red (run in-process at
fcc249bb, not committed; the only latercommit changes docs only):
s_orn2accepted in either operand order; exec writes after the join ignored; re-entry of thejoin ignored; every read accepted;
kept_halvesignoring the clear facts;lane_readaccepting any destination; the entered-block guarddropped; kept halves joined by union instead of intersection.
All eight fail the check. A sanity mutation that lets
s_orabsorb 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
fcc249bbreplaced it with the straight-run check above. The narrower check accepts fewerreads: on the 359 requests below, 2,366 more
v_cmpsites stay refused than with the map (50,324 against47,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*ors_andn2*livedefinition 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:
operand 'src_scc' in s_mov_bN, on both base and head.s_andn2_bNlive definition (two words)s_cbranch_sccNinside the block: branch out of the blocks_andn2_bNlive definition (one word)s_cbranch_sccNinside the block: branch out of the blocks_lshr_bNlive definitionv_cmp_lt_uN_eNlive definition ofvccv_cmp_lt_fN_eNlive definition ofvccs_bcntN_iN_bNv_cmp_eq_fN_eNlive definitions_load through sN holding ('descnum',)v_cmp_class_fN_eNlive definitioncompute image_store requires dNRefusal sites inside these 359 requests (every execz block, not only the first refusal), at
12b6617d'stranslator, with rule 1 alone and with both rules:
v_cmp*s_andn2_bNMost of what remains is read by something the rules do not cover. Among
v_cmpsites, the most common firstunproven reads are
s_mov_bN(12,972, a copy) and ans_and_bNthat is not absorbed (6,192: exec changedsince 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 thes_andn2inside the block.Not checked (hypotheses)
from the ISA semantics; WARP and hardware runs have not observed them.
from the may-writes. This is pre-existing. An absorbed low-word
vccread could now let an uncheckedvcc_hiread through where the low-word refusal used to hide it.
s_andsets SCC. SCC is whole-wave on hardware and per-lane in the model; that is the existingSCC model, unchanged here.
from other forms (for example
s_lshr) when every read is absorbed.🤖 Generated with Claude Code