startup: prove v_readfirstlane_b32 sources in the entry block of branched programs #2175
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2183"
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-25T03:16:49Z.
Change
Part of #1723. Follows #1931 and #2153.
v_readfirstlane_b32is lowered to a copy (sD = vS) only whenvSis proven uniform. Until now, a branch anywhere in the program refused every read. The uniformity tracking (knownexec, scalar uniformity, VGPR proofs) is kept in program order, and program order is not the execution order after a join.Before the first branch target and before the first terminator, every path has executed exactly the instructions above. Program-order tracking is therefore exact there, as in straight-line code. This change accepts proofs and reads in that entry block:
past_entrybecomes true at the first block boundary thattranslate()already makes, which is a branch target or the instruction after a terminator.s_endpgmin a branch-free program also counts as past the entry block. Otherwise branch-free programs are unchanged.exec, source and overwrite rules.has_brancheskeeps its other use, the depth-export check.Relation to other work:
v_cvt_f32_u32, the first step of the unsigned-division reciprocal chain. With both changes, that chain is proven in the entry block of branched programs, where most of the measured sites are.tainted_s), and it applies only when no instruction writesexec.docs/experiments.mdsentence.tainted_scheck inuniform_sourcewould also apply inside the entry block unless it is limited to code past it. Whichever lands second needs a small integration.execsomewhere.Verification
Run on
e3e39c43plus7a3037fband0068cde4.origin/main(a2010c91) merges without conflict.python -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py:Readfirstlane uniformity checks: 0 failed.python -B tests/startup_uniform_lane_check.py:fixed scalar buffer value translated; five unproven reads rejected.python -B tests/startup_gfx2hlsl_op_refusals_check.py:gfx2hlsl op refusals: 3 cases passed.python -B tests/docs_links_check.py: passes.git diff --check origin/main...HEAD: clean. The changed files are LF in the index.Mutants of the rule, each applied alone to a copy of
gfx2hlsl.pyand run against the check:0 in targets)len(blocks) > 1)s_endpgmcounts as inside a branch-free programhas_branchesLocal measurement, not reproducible from the repository: 266 graphics pipelines used by indirect draws in one captured frame, plus 117 cached requests from other local runs (383 in all), translated offline with
translate_requestagainste3e39c43.v_readfirstlane_b32 requires a proven uniform source.s_mul_hi_u32.s_mul_hi_u32and 1 ats_pack_ll_b32_b16.Evidence and follow-up
The fixture is hand-written disassembly text in the existing check's style. It is not taken from any title.
Two existing refusals become accepted cases, which is the intended change: "branch after read" (#1931) and #2153's "chain in a program with branches". In both, the read sits in the entry block.
Accepted cases:
Refused cases:
execwrite in the entry blocks_endpgmin a branch-free programFollow-up, outside this change:
s_mov_b32 exec_hi, s2raises aTypeErrorinscalar()instead of a refusal. That is older than this change.docs/experiments.md(uniform sources ofv_readfirstlane_b32) states the entry-block rule. Reproduce with:Checklist
AI-assisted (Claude Code). All commands above were run locally.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T03:21:41Z.
Review: COMMENTED
Review of head
0068cde4fbabd601f33a73fc041835110be7155c(comment only, no approval).Result: no P1, no P2 findings.
What I checked:
past_entryis set intranslate()(tools/startup/gfx2hlsl.py:708) after the block-boundary split, so it is true exactly at a branch target (off in targets and off != start), after any terminator (self.blocksnon-empty), or when a branch targets offset 0 (loop re-entering the entry block). That matches the claim: before those points every path has run the same instructions, so program-order tracking is exact.UNIFORM_VALUproof at line 759,op_v_readfirstlane_b32at line 1737) switched fromhas_branchestopast_entry. Missing-state probes still default to refuse (getattr(..., True)).has_branchesis kept for the depth-export checks (lines 880, 2065).targets, so the read at or after it is past the entry. Covered by testsread in a loop whose header is in the entry blockandread at a backward branch target.s_endpgmcases are refused.Commands executed locally in a worktree at that head:
python3 -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py->Readfirstlane uniformity checks: 0 failedpython3 -B tests/startup_uniform_lane_check.py->fixed scalar buffer value translated; five unproven reads rejectedpython3 -B tests/startup_translator_check.py->startup translator checks: 0 failedpython3 -B tests/startup_gfx2hlsl_scalar_m0_check.py->startup scalar m0 controls passedpython3 -B tests/startup_gfx2hlsl_refusals_check.py-> ran to the end, last linenormalization of unexpected value N in source: okpython3 tests/docs_links_check.py->Checked 18 Markdown files and 401 links.python3 tests/bidi_controls_check.py->no bidirectional controls.git diff --check origin/main...HEAD-> cleanMutations (reverted with
git checkout -- .):past_entry = bool(self.blocks)(drop the loop-to-0 case):1 failed, killed.past_entry = 0 in targets(drop the terminator/target boundary):6 failed, killed.Notes (not blocking):
refusalslist set), an instruction whose handler raises is skipped before the terminator bookkeeping. If a refused terminator ever occurred, the block would not close at that point. It does not affect the translated output on the normal path and is not reachable for the terminators now modelled.tainted_sshould be limited to code past the entry block once both land). Agreed, whichever lands second needs it.AI-assisted; commands listed were executed locally.