Repository navigation
startup: prove v_readfirstlane_b32 sources in the entry block of branched programs - #2183
Merged
R0Y00 merged 2 commits intoNov 25, 2026
Merged
Conversation
…ched programs A program with any branch refused every v_readfirstlane_b32. Before the first branch target and the first terminator, every path has executed exactly the instructions above, so the program-order tracking of exec, scalar uniformity and VGPR proofs is as exact as in straight-line code. Proofs and reads are now accepted there. A branch back to the first instruction keeps the whole program refused, because a loop re-enters the entry block. Branch-free programs are unchanged. The check moves "branch after read" to the accepted cases, adds the read just before the first branch target, and refuses a read at the first branch target, after the first terminator, in an entry block re-entered by a loop, after an exec write and from a lane mask. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… s_endpgm Review follow-up. A forward branch reaches its terminator before its target, so no case pinned the rule that a branch target alone ends the entry block. Two refused cases now do: a read in a loop whose header is in the entry block, and a read at a backward branch target. Code after s_endpgm in a branch-free program now also counts as past the entry block (dead code), and a refused case covers it. The test docstring and the CMake comment no longer say straight-line only. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
tedin7
reviewed
Nov 25, 2026
tedin7
left a comment
Collaborator
There was a problem hiding this comment.
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.- Both gates (
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). - Backward branch to a target inside the entry block: the target is in the precomputed
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. - Test changes only move the old branch refusals into precise accepted/refused cases. No test was weakened: the entry-block cases are accepted, and the first target, first terminator, loop-to-0, exec write, mask and dead-code-after-
s_endpgmcases are refused. - Docs sentence and CMake comment match the behavior. Mergeable, CI green (Linux Python, Windows build and test, gfx1013 fixtures), title neutral, no model or title names.
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-> clean
Mutations (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):
- Nit: in refusals-census mode (
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. - The author already notes the integration with #2060 (
tainted_sshould be limited to code past the entry block once both land). Agreed, whichever lands second needs it. - No shader output changes for branch-free programs, so I did not queue a Windows GPU run. The CI Windows job passed.
AI-assisted; commands listed were executed locally.
This was referenced Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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