shader: admit proven calculated far early-outs #2956
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2956
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2956"
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?
@chadhyatt on GitHub · 2026-11-26 23:13 UTC · original
chadhyatt:backport/shader-far-early-out→main· +699 −13 · 5 files · 3 commits · merged 2026-11-27 04:20 UTCAI-assisted backport patch from x2w-microlift.
Extend the gfx1013 pixel two-exit profile with a single proven forward calculated transfer onto a pure terminating continuation. Reuse the existing calculated-PC proof, require the fresh contiguous GETPC/ADD/ADDC/SETPC chain and reject observable continuation effects. The stand-alone pixel lowering remains unchanged.
Apple Silicon macOS, revision
2615baa8b2:python3 -B tests/startup_gfx2hlsl_far_early_out_check.py: three authored variants, both selector outcomes and refusal controls passed. LLVM 15 extraction capability skipped locally.python3 -B tests/startup_gfx2hlsl_far_early_out_check.py binary /opt/homebrew/opt/llvm/bin/llvm-mc: exact assembly roundtrip passed with LLVM 23.1.6.python3 -B tests/startup_gfx2hlsl_calculated_target_check.py: passed.python3 -B tests/docs_links_check.py: passed.git diff --check: passed.Windows and LLVM 15 extraction not run on this host; existing CI lanes retain their checks and add the new fixture.
@thepatrickworld on GitHub · 2026-11-27 03:06 UTC · original
Independent Python-only audit of
2615baa8: the refusal matrix on the base, the extraction half the body left unrun, and nine clause mutantsNot a code change; measurements only. No GPU and no Windows here:
gfx2hlsl,pixel_aotand the decoder are Python, and everything below runs before any HLSL is compiled.Environment
libLLVM-15.6ee878d8(currentmain), head2615baa8, separate worktrees;git status --porcelain --untracked-files=noempty in both, the base carrying the copied fixture below as the only untracked file.Commands
The base already refuses 12 of the 15 negatives, and accepts 3
negative()raises at the first accepted program, so the fixture on the base reports one program, not the matrix. I replayed each negative as its own program against both trees:calculated_pc_proof(10): register-derived displacement, missing ADDC, wrong sign extension, signed low-word ADD, competing entry into the chain, pair clobbering, address escape, SCC escape, target off an instruction boundary, target outside the program — e.g.s_setpc_b64: unknown or ambiguous calculated target from s[20:21] at +0x48for pair clobbering, identical on both trees.buffer_store_dwordands_barrierhit the generic unsupported-instruction check on the base.exp, continuations_mov_b32 exec_lo, 0. Run alone, the head refuses all three (far early-out: the scratch pair s[20:21] is not fresh,far early-out: the continuation instruction …).The startup half admits nothing new: it removes three admissions
For the two effectful continuations the base does not drop the instruction, it emits it. From
Stage(...).body()on the base, withexp mrt0 v4, v4, v4, v4 done vmat the continuation:with
s_mov_b32 exec_lo, 0at the continuation:and with the pre-written
s21of the stale-pair program the base writess21 = 0x00000005u;in the entry block and still jumps statically to an empty terminating block — the pre-written pair changes nothing in its output, which is what the new clause refuses.So no program gains an accepted emission on the Stage side; three lose theirs. For the five programs both trees accept (short branch, short calculated, far calculated,
v_nopcontinuation, threes_endpgm) the emitted body is byte-identical:sha256[:16]of the stripped body ise422a90516e79788for the four single-exit-continuation ones and5d8d8a0eb35e5ea4for the three-s_endpgmone, on both trees. The three variants share one dispatcher because the chain is elided and the jump lands in the same block.What the extraction half adds, executed
pixel_aoton the base, same programs, same library, in themarkers == 2andllvm is not Nonebranch ofcontainer_code:short s_branch: span returned unchanged (80 bytes) — already accepted before this PR, it contains nos_getpc_b64;short calculated(92 bytes, displacement 24) andfar calculated(131168 bytes):ValueError: Unverified multi-exit control flow: s_getpc_b64.The same is true of every two-exit program with a calculated transfer that I built (short calculated, far calculated, stale pair, export continuation, EXEC continuation) — all refused that way on the base — while
short s_branch, which carries nos_getpc_b64, is returned unchanged there. So before this PR the extractor refuses a two-exit pixel program with a calculated transfer whatever its distance. On the head all three variants come back unchanged and the whole fixture passes with the extraction enabled (Far early-out: three variants, dispatcher oracle and refusal controls passed); each of the 15 negatives then refuses through the extractor as well as the Stage, with the same message on both (refused (…)instead ofrefused by the translator (…); extraction skipped). That is the capability this PR buys, and it is on thepixel_aotside.Clause coverage: 2 of 9 clause mutants are killed
One textual mutation at a time in
terminal_continuation_proof, the fixture run after each, file restored withgit checkout --and its sha256 checked back to the pre-mutant value:killed by the fixture
if False and {pair, pair + 1} & scalar_registers(asm)) →stale scratch pair: the startup translator accepted a refused program;at += _n; continue) →effectful continuation (an export): the startup translator accepted a refused program.survive the fixture (rc=0, whole file green)
for off in chain[1:]: if off in branch_targets— disabled: green. Not exercised by the fixture, and the three interior entries I built are refused upstream bycalculated_pc_proofon both trees: the fixture's own competing entry (targets the ADD), a branch to the ADDC (s_setpc_b64: missing matching low-word carry for calculated PC high-word addition at +0x40), a branch to the SETPC (s_setpc_b64: unknown or ambiguous calculated target from s[20:21] at +0x44). Redundancy is shown for those three entries only.or extension != (-1 if displacement < 0 else 0)— disabled: green. The base refuses the fixture's wrong sign extension without this clause, and the same agreement test already exists incalculated_pc_proof.len(transfers) != 1 or len(ends) != 2→< 2: green, and a three-s_endpgmvariant is accepted with an identical body by both trees, so the guard never decides on these programs.if target != chain[0] + get_n + displacement— disabled: green; I could not build a program that reaches this test separately from the arithmeticcalculated_pc_proofalready did.if target <= setpc— disabled: green, and I could not exercise it: the only backward targets I could build point back into the chain (the early export, thes_getpc_b64itself) and are refused upstream as an ambiguous loop. Unpinned, with no measurement either way.if asm != 's_endpgm' or at != ends[-1]— disabled: green, and this one is reachable (next section).raise … leaves the decoded program before ending: I could not reach it; my attempt at a continuation that walks off the end is refused earlier (s_setpc_b64: target 0x20060 outside decoded program at +0x48).One reachable clause has no case: the continuation must end at the last decoded
s_endpgmTake the fixture's own
variant(CHAIN)rows, insert ones_nop 0betweenEXP_Band the firsts_endpgm, and re-encode the ADD to land on that NOP (d = 20, target0x50, the firsts_endpgmat0x54, the last at0x5c):[(branch, '!scc', 72) at 0, (jump, 80) at 48, (end,) at 80, (end,) at 88];Unsupported: far early-out: the continuation ends at +0x54, not the program's final exit;at != ends[-1]conjunct dropped, the head accepts that same program and the whole fixture stays green.So this is the one clause that is reachable by the proof and unpinned by the fixture. A negative case in
check_negatives— one inserteds_nop 0and the ADD re-aimed, about ten lines next torows_boundary— would pin it. Note thatends[-1]is the last decodeds_endpgm, not the end of the span; the extractor has its ownexits[-1] + 4 == len(code)check, the Stage proof does not.Small things in the fixture itself
Its usage line offers
binary <llvm-mc> [llvm-objcopy] [libLLVM], butmain()rejects anything but exactly two arguments, andresolve_libllvm's docstring mentions adecodemode this file does not have — so an LLVM library cannot be passed explicitly, and the extraction half runs only whereresolve_libllvm()finds one of its four names.Limits
(x, y)pairs on uniform-lane programs.libLLVM-21, notlibLLVM-15: this host has no 15, the fixture as shipped printsextraction skipped (no LLVM 15 library found), and I drove its ownextract()with the 21 library.pixel_aotuses the LLVM C API to enumerate the instruction inventory; the accept/refuse decision then comes from the repository's decoder and this proof. A run with LLVM 15 proper would be worth having.terminal_continuation_proofis called for every stage kind (ps,vs,cs,ms), not only the pixel two-exit profile the commit describes; and when the Stage is built with arefusalslist the reason is collected and the translation continues, so the check is diagnostic on that path and refuses only the strict construction.pixel-binaryentry (binary llvm-mc-15) only reassembles the three sources and never reaches the Stage orpixel_aot; thepython-linuxjob does run this fixture without arguments, where the extraction is conditional on alibLLVM-15that the job does not install, and whether the image carries one is not provable from the repository.AI-assisted.
@chadhyatt on GitHub · 2026-11-27 03:08 UTC · original
@thepatrickworld Thank you for the exact base/head extraction comparison and clause controls. I will add the reachable earlier-continuation termination negative and correct explicit LLVM library selection in the fixture. I agree that the startup-side changes tighten admission, while the new capability is extraction. No GPU execution claim.
@chadhyatt on GitHub · 2026-11-27 03:24 UTC · original
@thepatrickworld Updated
dfd691825e. The reachable continuation ending before the final exit is now a negative control;controls <libLLVM>explicitly selects the extraction library for all positive and negative checks.Verified on Apple Silicon with LLVM 15.0.7:
python3 -B tests/startup_gfx2hlsl_far_early_out_check.py controls /opt/homebrew/opt/llvm@15/lib/libLLVM-15.dylib- three positive exact extractions and all 16 refusal cases, including the new earlier termination, passed through the Stage and extractor.python3 -B tests/startup_gfx2hlsl_far_early_out_check.py binary /opt/homebrew/opt/llvm@15/bin/llvm-mc /opt/homebrew/opt/llvm@15/lib/libLLVM-15.dylib- all three variants reassembled and extracted byte-identically. Fixture-only amendment; no GPU claim.AI-assisted backport patch from x2w-microlift.
@thepatrickworld on GitHub · 2026-11-27 03:57 UTC · original
Follow-up on
dfd691825e: the case you added does pin the distance clause, and the no-argument mode now ignores the library it findsPython-only, no Windows and no GPU. Same host as the previous audit (Linux x86-64, Python 3.11.16, one LLVM library, 21.1).
Environment
dfd691825e,git status --porcelain --untracked-files=noempty.6619ea3f…(555 lines),tools/startup/gfx2hlsl.py928817ae…(11 945 lines) — unchanged by this commit, as a fixture-only amendment should be.2615baa8:tests/…, 520 lines,e842a42a…) run in the same tree, same tools, as the control.Commands
The clause is now pinned on the refusal side
Clean head: rc=0 and 16 refusals in both modes. Under M1 the amended fixture dies exactly on your new case —
AssertionError: continuation ends before the final exit: the startup translator accepted a refused program(fixture line 352), after 13 refusals, so the two cases placed after it do not run. The
2615baa8fixture, runagainst the same mutated bytes, stays green (rc=0, 15 refusals). So the case you added is necessary and
sufficient for M1 on these programs, which was the ask. After
git checkout --,gfx2hlsl.pyis back to928817ae…,git statusempty, rc=0 again.The acceptance side is not a gain of this commit
ends[-1]→ends[0](94bce5e8…) is killed by the positiveshort calculated:Unsupported: far early-out: the continuation ends at +0x58. That mutant kills the2615baa8fixture the sameway, so the pair brackets the comparison but only the refusal half is new.
asm != 's_endpgm'is unreachable, so M2 is equivalent rather than a holeDropping only that half leaves the fixture green, and it must:
0xbf810000,0xbf810001and0xbf81ffffalldecode to
(0, 4, 's_endpgm', 's_endpgm'), so whenname == 's_endpgm'the text cannot differ. Treat it asdead on today's decoder (a guard that would matter only if the decoder ever emitted a longer text), not as a
missing case.
The no-argument mode no longer uses
resolve_libllvm()main()setslibrary = Noneand passes it explicitly intocheck_variantandcheck_negatives, so themodule-level
LIBRARY = resolve_libllvm()never reachesextract(). Measured on a directory holdinglibLLVM-15.so.1(a symlink to libLLVM-21.1) withLD_LIBRARY_PATHset and that directory as cwd:resolve_libllvm()returns'libLLVM-15.so.1'(printed from the fixture module);2615baa8fixture printsextracted exactlyfor the three variants, rc=0;dfd691825efixture, same command, same cwd, printsextraction skipped (no LLVM 15 library found), rc=0.So on a host that has the library the diagnostic is now wrong, and an extraction that used to run is skipped
silently. One line restores it while keeping
controls <lib>explicit:library = LIBRARYin the no-argumentbranch instead of
library = None.Where that lands
Read from the workflow file, not from a job log:
pixel-binaryruns this fixture asbinary llvm-mc-15(
windows.yml:149) — two arguments, socheck_binaryreceiveslibrary=Noneeven though that is the job thatinstalls llvm-15 (
:35) — andpython-linuxruns it with no arguments (:324) on ubuntu-24.04 with no LLVMpackage installed (
:195-197). No job exercises the extraction before or after this commit, so the docstringline saying a binary-mode machine covers it was already inaccurate.
Limits
controlsargument and behind thelibLLVM-15.so.1name:"LLVM 15 proper" is still not measured here.
pixel_aot.pixel_aot.native_programare the same rule re-executed (pixel_aot.py:95callsG.terminal_continuation_proof); that path's independent contribution is the LLVM-versus-repository-decoderinventory, not a second opinion on the clause.
AI-assisted.
@R0Y00 on GitHub · 2026-11-27 04:00 UTC · original · reviewed
At
dfd69182I reproduced the dispatcher and refusal controls, including the earlier termination case, plus the calculated-target and startup cache-key suites. The head CI logs still leave the new extractor path out: Python printedextraction skipped (no LLVM 15 library found), and the LLVM job only reassembled the fixtures. Please passlibLLVM-15.so.1to this fixture in the LLVM job, which already uses that library for the neighboring fixtures. That will keep extraction from silently dropping out of the test lane.@chadhyatt on GitHub · 2026-11-27 04:01 UTC · original
Acknowledged. I will wire the existing LLVM15 extractor argument explicitly into the public LLVM job and keep the portable default diagnostic accurate. The source proof is unchanged.
@chadhyatt on GitHub · 2026-11-27 04:02 UTC · original
Addressed at
537d7b923c: existing public LLVM job explicitly passeslibLLVM-15.so.1; portable mode uses its discovered library when present. Actual Apple Silicon LLVM15binary /opt/homebrew/opt/llvm@15/bin/llvm-mc /opt/homebrew/opt/llvm@15/lib/libLLVM-15.dylibpassed exact assembly and extraction for all three variants. No-argument dispatcher and 16 refusals pass, with discovery skip reported on this host. Ready for follow-up.@R0Y00 on GitHub · 2026-11-27 04:19 UTC · original · approved these changes
Reviewed
537d7b923cbd09356325ecf947e75a72b48d8a91. The LLVM job now explicitly invokesbinary llvm-mc-15 libLLVM-15.so.1; I checked the job log and it confirms byte-exact assembly and extraction for all three variants. Independently reran the far-early-out and calculated-target Python checks on the exact head: all portable controls passed, while local LLVM extraction was skipped on Windows. Required Windows CI passed.@KelboLive on GitHub · 2026-11-27 04:33 UTC · original · reviewed
PR #2956 admits proven calculated far early-outs in the gfx1013 pixel two-exit profile. The
chain-verification is thorough and the 555-line test matrix is excellent.
What works
s_getpc_b64, middle two must be exactly s_add_u32 and s_addc_u32, last two instructions must target
s[%d:%d] set from GETPC pair. Matches the documented pattern.
extension on signed displacement and zero-extension on negative displacement.
must be forward (target > setpc). A single exit or backward jumps are refused.
wrong sign extension, signed ADD instead of ADDC, competing entry into chain, pair clobbering, address/SCC
escape, stale scratch pair, effectful continuation (export/store/barrier/EXEC), wrong endpgm, off-boundary
target, out-of-range target, and non-forward target.
inventory before accepting the chain. Good invariant.
excluded from far-early-out acceptance (mesh has its own export model).
Issues
GETPC on different registers across functions, the chain form changes. The verifier picks whichever pair
the GETPC happens to use. This is correct but pairs should ideally be consistent across callers for
determinism. Otherwise, the pair choice is per-function.
explicitly refuse internal branches in the continuation. Consider adding an explicit branch-refusal check.
The proof assumes the GETPC value is read before the pair is clobbered. This matches the PR description
requiring a fresh aligned scalar pair. No bug, but worth noting for anyone reasoning about the proof.
proof. The import comment notes gfx2hlsl also imports pixel_aot lazily, so order should be stable.
Recommendations
Overall: excellent PR. The chain verification is carefully constructed and the test matrix covers edge
cases that would otherwise slip through. Enables more complex control flow in translated programs.
@thepatrickworld on GitHub · 2026-11-27 07:59 UTC · original
Post-merge receipt on
9436a181: the no-argument run now drives 19 extraction sites, the calculated early-out extraction re-runs the translator's proofs, and CI exercises three of themPython-only, no Windows, no GPU. Same host as my two earlier audits (Linux x86-64, CPython 3.11.16, one LLVM library, 21.1).
Tree measured
9436a181(squash of this PR);git status --porcelain --untracked-files=noempty before and after the runs.tests/startup_gfx2hlsl_far_early_out_check.py51a49457…and.github/workflows/windows.ymla4196088…are byte-identical to the head537d7b92I measured earlier (sha256 equal at both refs), so the fixture I ran is byte-identical to the delivered one and the workflow line I quote is the delivered one; no CI job was run here.tools/startup/gfx2hlsl.py(9d9f09fe…) differs from that head by other merges, not by this one.Commands
The cwd matters:
resolve_libllvm()testslibLLVM-15.so.1as a relative path, and LLVM 21.1 sits behind that name in the directory used below.From the repository root instead, the same first command prints
extraction skipped×19, andcontrols libLLVM-15.so.1exits 1 on the docstring (Path(argv[2]).is_file()).Observed
extracted exactly×3,extraction skipped×0, 16 refusal lines carrying the translator's diagnostics with no skip suffix; rc=0.controls libLLVM-15.so.1gives the same three exact extractions and the same 16 refusals.dfd69182,6619ea3f…, written totests/_panam_old_far.pyin the same tree and removed afterwards; its only difference from the delivered fixture inmain()islibrary = LIBRARY→library = None), same cwd and env:extraction skipped (no LLVM 15 library found)×19,extracted exactly×0; rc=0.So the one line moves 19 extraction sites, not 3: the three variants, plus the 16 refusal controls whose
stage_and_extract()returnsNonewhen no library is selected (tests/startup_gfx2hlsl_far_early_out_check.py:389).What the extraction half actually gates
extract(...) == codealone is a container round-trip:container_codereturns a slice of the FSSM image it just re-read, so every program it accepts comes back byte-identical — a validshortvariant with word 18 changed froms_nop 0tos_nop 1comes back EXACT too.The gate that can fail sits before that return, in
_check_two_exits(tools/pixel_aot.py:103): it disassembles with LLVM, requires the LLVM inventory to agree with the repository decoder, walks the CFG to both exits, and — when the program carriess_getpc_b64— replayscalculated_pc_proofandterminal_continuation_proof(tools/startup/gfx2hlsl.py:1167,:1377, the two functionsStage.translatecalls at:3571and:3578).Measured on the merged tree, on the
shortvariant (s_cbranch_scc0at pc 44,s_branchat pc 56):s_nop 0givesValueError: Unreachable code or unverified alternate exit, and the same for word 14;s_endpgmgivesUnverified multi-exit program, and a word after the last exitExpected termination followed by code padding— both raised earlier, insidecontainer_code(the marker count and_bounded_code);container_codestill returns a one-exit program but refuses these two-exit ones, soextract(..., None)raisesUnverified multi-exit programfor all three variants: theif library is not Noneincheck_binary(tests/startup_gfx2hlsl_far_early_out_check.py:544) is what keepsbinary <mc>runnable on a host without a library.Not covered by this half: HLSL emission, the dispatcher oracle, the arithmetic.
Where CI only exercises three of the 19
check_binaryasserts extraction for the three variants only, andcheck_negativesis reached only frommain()after thebinarybranch has returned. So at this shapixel-binaryexercises the extraction of the three variants and no refusal control (.github/workflows/windows.yml:149; its run at537d7b92concluded success), whilepython-linuxruns the no-argument mode on ubuntu-24.04, whose published image lists clang 16/17/18 and no clang 15 (runner-imagesUbuntu2404-Readme.md, image 20261116.376.1), and the job itself installs onlyrequirements-dev.txt— on such an imageresolve_libllvm()has nolibLLVM-15.so.1to return. I could not read the job log, so that last point is the image's package list, not a run trace.If the 16 refusal controls should go through the extractor in CI, the list at
:149can carry a second entry(["tests/startup_gfx2hlsl_far_early_out_check.py", "controls", "<absolute libLLVM-15.so.1 path>"], {}): that job installsllvm-15, butmain()requires an existing file andrun_checks_parallelkeeps the repository root as cwd, so the bare soname the neighbouring entries pass exits on the docstring.Limits
libLLVM-15.so.1(LD_LIBRARY_PATHfor the load); nollvm-mcon this host, sobinary <mc> <lib>was read, not executed.pixel-binaryat537d7b92(run 45937575194, job 140304215556, success), so what it printed is not quoted here.AI-assisted.