tooling: add a loop census for mesh-stage programs (Part of #1998) #2276
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2284"
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-25T10:06:58Z.
Change
Part of #1998 (item I, the census half). No lowering change.
tools/mesh_loop_census.pyreads a directory of DXBC containers, keeps themesh-stage programs that
tools/mesh_entry_aot.pydecodes, and printsaggregate Markdown tables only. No file name, digest, offset or instruction of
an input reaches the output; lowerer messages are printed with registers and
numbers replaced by
N.back-edge, with the body from the branch target to the branch. Per back-edge:
group barrier in the body, LDS access in the body, EXEC written in the body
(an upper bound on a loop-carried EXEC, since a save/restore pair counts
too), a latch that tests EXEC, a scalar read before the body writes it, the
trip count as a pattern (constant start, step and bound, no second exit; not
a proof; anything else is reported as
otherwith nothing claimed), nestingand the body length.
mesh_entry_aot.lowerandmesh_dynamic_aot.enumerate_variantsrun once per program. Each program is counted once by its first refusal,
placed at a latch, in a loop body, before the first loop or after one. The
run is repeated with the two flat-scratch setup writes replaced by
s_nop,because both lowerers refuse
s_setreg_imm32_b32and that refusal hideswhat follows.
s_branch 65535). Thecensus reads it signed.
tests/mesh_loop_census_check.pyis registered asmesh_loop_censusin CMake,in the platform-independent Python job and in
AGENTS.md;docs/experiments.mdhas the commands.Verification
Branch
tools/mesh-loop-census, one commit onmain19509ee4.Mesh loop census classified 14 source-built programs; 14 mutants changed category.binaryused LLVM 15llvm-mcandllvm-objcopy:each source reassembles to the embedded bytes and the
llvm-mclisting equalsthe Python decode once the branch offsets are read signed.
docs_links_check: 18 Markdown files, 435 links.bidi_controls_check: 1,578files, clean.
git diff --check: clean.Not run:
--llvm(no LLVM C library on this machine; only--llvm-mcwasexercised), CMake/ctest, and the Ubuntu job.
Evidence and follow-up
with LLVM 15 for
amdgcn--amdpal,-mcpu=gfx1013, wave64. Sources and bytesare in the check; MIT like the rest of the repository. They carry a loop and
nothing else and are not complete mesh programs.
header instead of inside the body changes the barrier column; a back-edge
turned into a forward branch removes the loop. The other mutants each move
one loop across one boundary: bound, start or step not constant, counter not
stepped by add/sub, latch not testing the compare, a second exit, EXEC write
removed, latch no longer testing EXEC, unconditional latch made conditional,
LDS access removed, scalar no longer carried, inner start unknown.
placement of a first refusal relative to a loop, the signed reading of branch
offsets, de-duplication and stage filtering of a directory, and that the
rendered tables hold no operand or encoding. They do not verify any count
from a private corpus; those are in the #1998 comment.
flow graph; "loop-carried scalar" uses body order, not a data-flow fixed
point; the LLVM C library prints the same branch spelling as
llvm-mc.request. A latch that is
s_cbranch_execnzors_cbranch_vcczraisesKeyErrorin both lowerers; the check pins that as the current behavior soa later named refusal shows up as a deliberate change. It also pins the
s_setreg_imm32_b32refusal of the flat-scratch setup, so a change thataccepts the setup has to update
check_lowerers.Checklist
AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:10:59Z.
Review: COMMENTED
Review of head
fd57054027ed8498ac56641e2e1ec42ad3ae913b(tooling only, no lowering change).Commands run locally (Linux)
git diff --stat origin/main...HEAD: 6 files, +625 (census tool, its check, CMake/CI/AGENTS/docs wiring)python3 tests/mesh_loop_census_check.py:classified 14 source-built programs; 14 mutants changed category,Self-test passed.python3 tests/docs_links_check.py: 18 files, 435 links, passedpython3 tests/bidi_controls_check.py: 1578 files, no bidi controlsgit diff --check origin/main...HEAD: cleangit merge-tree --write-tree origin/main HEAD:CONFLICT (content): Merge conflict in CMakeLists.txtgh pr checks: no checks reported on the branchMutations
s_cbranch_scc0/scc1latch set reduced toscc0only intrip(): the check fails (AssertionError ... 'other'). Killed.>= 0x8000changed to>= 0x8001insigned_branches()(tools/mesh_loop_census.py:93): the check still passes. Survived.Findings
CONFLICTINGwith main. The conflict is inCMakeLists.txt, near the newadd_test(NAME mesh_loop_census ...)in the mesh test block (~line 7441). Rebase before it can go in.s_branch 32768is -32768). Add one fixture at the boundary, or say it is out of scope.trip()excludes bystartswithprefix (s_mov,s_mul,s_cselect, ...). A laters_mul_*ors_cselect_*that writes SCC would be skipped when picking the last SCC writer, so the pattern could be claimed too generously. The docs say it is "not a proof", so this is acceptable, but a one-line note would help.I did not run Win2025: no shader or C++ change, Python-only tooling.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:29:50Z.
Review: COMMENTED
Re-review of head
dc3af5382086e52eeadd64fccac5b08c1cbe1853(tooling only, no lowering change). Previous review was onfd57054.Commands run locally (Linux)
git diff --stat origin/main...HEAD: 6 files, +634 (census tool, its check, CMake/CI/AGENTS/docs wiring)python3 tests/mesh_loop_census_check.py:classified 14 source-built programs; 14 mutants changed categorypython3 tests/docs_links_check.py: 18 files, 436 links, passedpython3 tests/bidi_controls_check.py: 1585 files, no bidi controlsgit diff --check origin/main...HEAD: cleangit merge-tree --write-tree origin/main HEAD: clean tree (no conflict)gh pr checks: Linux Python checks pass; Windows jobs were still pending when I lookedPrevious P2 items
CMakeLists.txt: RESOLVED. The merge is clean and the PR isMERGEABLE.>= 0x8000to>= 0x8001at tools/mesh_loop_census.py:93 and the check still passes (14 mutants line unchanged). No fixture coverss_branch 32768(= -32768). Add one boundary fixture, or state that it is out of scope.Findings
s_mov,s_mul,s_cselect, ...). A laters_mul_*/s_cselect_*variant that writes SCC would be skipped. A one-line note in docs/experiments.md would help.I did not run Win2025: Python-only tooling, no shader or C++ change.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:58:06Z.
Review: COMMENTED
Re-review of head
620439f4db563b0ba3f5935b536ff15f41e6ac62(tooling only, no lowering change). Previous review was ondc3af53.Commands run locally (Linux)
git diff dc3af53 HEAD --stat: 2 files, +4 (one boundary assert in the check, two doc lines)python3 tests/mesh_loop_census_check.py:classified 14 source-built programs; 14 mutants changed categorypython3 tests/docs_links_check.py: 18 files, 436 links, passedpython3 tests/bidi_controls_check.py: 1585 files, no bidi controlsgit diff --check origin/main...HEAD: cleangh pr checks: Linux Python checks, gfx1013 fixtures and Windows build/test pass; the rest are skipped jobsMutations on tools/mesh_loop_census.py:93 (each reverted with
git checkout -- .)>= 0x8000->>= 0x8001: now killed (AssertionError at tests/mesh_loop_census_check.py:138,s_branch 32768)>= 0x8000->> 0x8000: killed>= 0x8000->>= 0x7fff: killedPrevious items
s_branch 32768->-32768, and both off-by-one directions fail.MERGEABLE.Findings
I did not run Win2025: Python-only tooling, no shader or C++ change.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T10:19:08Z.
I checked the LLVM C library path on Windows x64 at
fd570540, using LLVM 15.0.7'sLLVM-C.dll. The disassembler printed unsigned branch operands, and aftersigned_branchesall 14 source-built fixtures matched the Python reference instruction-for-instruction, including byte offsets.I also ran the public CLI with the 14 synthetic mesh containers, one duplicate, one synthetic compute-stage container and a text file:
The complete Markdown matched the census from the fixture decoder (LF SHA-256
c27708083389c15d2d3884fb6e8b60af67009134e415d490174f967151654ae7). It counted 14 back-edges, 13 outermost and one nested, and classified each of the three extra inputs separately. The boundary test from the review also works against the real library: the four branch operands 32767, 32768, 32769 and 65535 normalize to 32767, −32768, −32767 and −1. That last check was external to the committed regression suite.To build the corpus, use
mesh_loop_census_check.mesh_container(bytes.fromhex(code))for each(_, code, _)inFIXTURES.values(), repeat the counted fixture once, then add the counted fixture withstage=5and one plain text file. All inputs came from this PR's tests.Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T10:53:35Z.
Addressed in
620439f4.check_branch_spellingnow readss_branch 32768as -32768 ands_branch 32767as 32767. The mutant>= 0x8001at line 93 now fails the check; the restored file passes (14 programs, 14 mutants).docs/experiments.mdnotes that the SCC-writer filter excludes by mnemonic prefix, so a laters_mul_*ors_cselect_*variant that writes SCC would be skipped.Commands:
python -B tests/mesh_loop_census_check.py,python -B tests/docs_links_check.py,git diff --check origin/main...HEAD(clean).