perf(recompiler): iterate structurizer fixpoints in post-order and bound shared merge splitting growth #5028
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5028"
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 boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-13T08:54:14Z.
What
The structurizer's attempts can spend seconds to minutes on a small graph before they accept or refuse it. With the oracle described under Tested, about 1,150 of 200,000 random graphs of 2 to 32 blocks take more than 10 s, on
mainand with #4926 (1,142 and 1,149; the count depends on machine load), and some take more than 300 s. One 20-block graph takes 10.3 s. In a title, that time is spent while the shader is prepared.A profile of 41 of these graphs puts 73% of the time in
computeDominatorTree, 13% initerationSelectionMerge, 6% injoinWithinIterationand 5% inmergeBesideReturns, all recomputed while shared merge splitting grows the graph. Every slow attempt ends at the split round budget (4 rounds per block at the start of splitting), in one of two ways:In production code, this PR changes only
Structurizer.cpp:mergeBesideReturns,iterationSelectionMergeandjoinWithinIterationsweep the blocks in reverse post-order from the entry (dominators) or in post-order (the others), unreachable blocks last in id order. They swept in id order, but splitting appends its blocks at the end, so a sweep carried a set only one new block further.computePostDominatorsalready used this order;analysisOrderreplaces its inline copy. Each fixpoint starts from the full set and its equations are monotone, so every sweep order reaches the same greatest fixed point and no output changes.joinWithinIterationalso tests membership with a bit vector instead of a linear search, andmergeBesideReturnsinserts into its already sorted set.splitSharedMergeBlocksrefuses the attempt once the graph has more than 16 times its block count at the start of splitting, or more than 64 blocks when that is larger (CFG shared merge splitting exceeded growth budget). The budget counts blocks, not time. A refused attempt continues exactly as after the existing round budget: the next attempt, then the reach-flag fallback of #4926. With the sweep-order changes alone, 360 of the 1,220 graphs that took more than 10 s in any run onmainor #4926 still do.The growth budget is a heuristic. Succeeding attempts grew at most 8.6 times on these 200,000 graphs, 9.4 times on 200,000 graphs of another seed and 10.6 times on 12,000 graphs of up to 128 blocks. An attempt that would succeed only beyond 16 times now gives a later attempt's output or the fallback's, which is valid and equivalent but not the same. No such graph was found, but shaders are larger than these graphs.
Splitting that adds one block per round stays under the growth budget and still runs all its rounds. On 2,000 random graphs of up to 128 blocks, 9 still take more than 10 s with this PR, at most 63.5 s; with the sweep-order changes alone, 28 take more than 10 s and 13 more than 300 s. The technical debt entry of #4926 now records the budget and this limit.
Tested
WSL2 Ubuntu 26.04, GCC 15.2.0, configured like CI (Release, SPIRV-Tools ON, lavapipe), on top of #4926. No title.
In-tree:
agc_structurizergains three cases. The 20-block graph and a 12-block loop whose 2000-word latch is too large to clone, so that splitting keeps adding junctions, must give structured branches, every original block once and the same executions as the input. The same loop with an unsupported exit, which keeps the reach-flag fallback out, must be refused at the growth budget. On #4926 alone that case fails: it reports the round budget after the graph reached 676 blocks.g++ -O2, the test takes 0.4 s with this PR. On #4926 alone it fails after 16 s (39 s withAPS5_NO_PERF_ITERATION_SELECTION=1).ctest -R "structurizer|control_flow": 8 of 8 pass in three runs.agc_structurizertakes 0.3 s, and under 1 s in each of its variants.ctestin the CI configuration: 1014 tests, 0 failed.tools/check_skips.pyflags onlyguest_video_out_high_frame_rate, which skips because the WSL display has no 120 Hz mode.tools/check_test_registration.pypasses.tools/check_conventions.py --base origin/mainpasses with both the branch's checker andmain's.maincac4e9688with #4926: fullctestin the CI configuration, 1032 tests, 0 failed. Then onto4bb2c7f39, where only the technical debt file conflicted: the structurizer, control-flow and shader tests, 18 of 18.agc_structurizertakes 0.5 s and at most 0.9 s in its variants.Out of tree, with the oracle described in #4926 (graph contract, SPIRV-Tools on a skeleton module at SPIR-V 1.3, 1.4 and 1.6, and an exact equivalence decision), on the same 200,000 graphs (seed 1, 2 to 32 blocks, 10 s per graph), built against
mainand against this branch and run on the same machine at 16 jobs:main: 81,078 graphs accepted, 117,780 refused, 1,142 past 10 s. The run took 2,235 s.mainaccepts give byte-identical outputs. Against the run made for #4926, the 198,851 graphs that #4926 finished give byte-identical outputs too.mainor with #4926 in either run give the same outputs as this PR built without the growth budget and run until it finished. That build still took more than 10 s on 360 of them, and up to 203 s (12 graphs at a time).The same code, run earlier on other graphs: on 200,000 graphs of seed 2 (2 to 32 blocks), all 199,892 graphs that a build with the sweep-order changes alone finished within 60 s give the same outputs, and the slowest graph takes 2.3 s. On 2,000 graphs of up to 128 blocks, all 1,987 that build finished within 300 s give the same outputs.
A second check on graphs of seed 7, with this branch at ebcb1068c:
mainaccepts give byte-identical outputs, and so do the 79,632 graphs #4926 finished within 10 s. None is refused or takes more than 10 s;maintakes more than 10 s on 366. Two runs of 40,000 of these graphs at different job counts give identical outputs, and an AddressSanitizer build gives the same outputs on 5,000 of them without a report.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by houcineBen on 2026-10-13T17:21:56Z.
A data point from a real shader for the case listed as remaining ("splitting that adds one block per round … still runs all its rounds").
vkQuake (LibreQuake) homebrew PPSA99010 on a RADV (Mesa 26.2) build: compute shader
0x20134f400(1602 dwords, wave32, 8x8 threads, 155 blocks when splitting starts). Header 119 splits merge 151 again in every round, each round adding one forwarder in front of the previous one, until the round budget.agc_shader_replay --cfgon its dump, Windows 11, RTX 4060 Ti, WinLibs GCC 15.2.0:main9ea71307aThe title waits 10 s for the dispatch, so 18.4 s still stops it.
The change (+15/−2 in
Structurizer.cpp):splitOneSelectionMergereports the header and merge it split, andsplitSharedMergeBlocksfails the attempt withCFG shared merge splitting repeatsafter 16 consecutive rounds that split the same header and merge and add exactly one block. I checked with the check changed to only record: every attempt it fires in, 6 inagc_structurizerand 6 in this shader, ran on toexceeded budgetanyway. So it only ends doomed attempts sooner, and the structured CFGs of all 12 vkQuake dumps we have are byte-identical to this PR's. A test case uses your 20-block forwarder graph with block 12 unsupported (to keep the reach-flag fallback out). It must be refused with the new reason, and on this PR alone it reportsexceeded budget: originalBlocks=43 currentBlocks=216 splitBudget=172. Fullcteston top of this PR: 1082 pass, 7 skipped.I'll open it as a follow-up with
Depends on: #5028once I can (I'm at the first-time author PR limit), unless you'd rather fold it in here.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T01:38:21Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/shader.mdL117docs/dev/debt/shader.mdL117docs/dev/debt/shader.mdL117docs/dev/debt/shader.mdL117Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-14T07:13:42Z.
Closing this together with #4926, which it builds on, following the request there to hold off on pull requests that do not name a title needing the change while the queue is this long. The branch stays; if a title stops on refused control flow on current
main, I will reopen with the title ID and the log line.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T07:35:52Z.
Reopened with #4926; reviewing both now.