Repository navigation
test(recompiler): check seeded structurizer outputs for exact equivalence - #4964
Closed
nikowolf123 wants to merge 3 commits into
Closed
nikowolf123 wants to merge 3 commits into
nikowolf123 wants to merge 3 commits into
Conversation
nikowolf123
force-pushed
the
test/structurizer-equivalence
branch
2 times, most recently
from
October 13, 2026 08:58
3267398 to
ff7ab88
Compare
This was referenced Oct 13, 2026
This was referenced Oct 13, 2026
nikowolf123
force-pushed
the
test/structurizer-equivalence
branch
from
October 13, 2026 15:35
ff7ab88 to
51c01e4
Compare
10 tasks done
nikowolf123
force-pushed
the
test/structurizer-equivalence
branch
from
October 13, 2026 16:21
51c01e4 to
071a735
Compare
This was referenced Oct 13, 2026
When every attempt of the structurizer ladder refuses a graph, the title aborts. Rebuild such a graph from a hierarchical decomposition into strongly connected components instead: each original block keeps one copy and runs behind a guard on its own reach flag, and each component becomes a loop with a single latch that repeats it while a back edge set its again flag. Every edge sets the reach flag of its target, so exactly one flag names the next original block and the blocks run in the input's order for every branch decision. Irreducible and non-terminating graphs are handled the same way, and no block is cloned. The ladder runs first and its output is unchanged. The fallback only runs when both attempt series refuse; if it cannot structure the graph, the ladder's error is reported as before. Blocks that start the top-level order unconditionally run unguarded, so the entry block's results reach later blocks without a stale path. APS5_FORCE_STRUCTURIZER_FALLBACK=1 uses the construction for every supported graph, for tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…zer fallback Structurize eight graphs the ladder refuses on main (a duplicate merge, a region that wraps around to its dominator, the merge-splitting budget, a conditional without a structured merge, an irreducible entry and three loops that never exit) and the boykopovar#2642 two-latch loop, which the ladder accepts. Each must give structured branches, every original block exactly once and the same executions as the input for every branch decision. Register agc_structurizer_forced_fallback and agc_shader_control_flow_forced_fallback, which run the in-tree graphs and RDNA programs, through Recompile and SPIR-V validation, with APS5_FORCE_STRUCTURIZER_FALLBACK=1. Under that switch the split-kind checks become checks that no block is cloned and a route variable is used, and the nested-selection check names blocks by their original instructions instead of their position. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ence Structure 2000 seeded graphs of 2 to 24 blocks and check every output against its input. Half are random graphs with a random entry block, loops, irreducible cycles and blocks that never return; half are laid out like compiled code, with fall-through, forward branches and back edges. Graphs have at most six conditional branches and smaller random graphs are more frequent: on denser graphs the structurizer's retries take seconds per graph. Each output must: - keep the graph contract: dense ids from entry block 0, successors and predecessors that match the branches, every block reachable and reaching a return, every block after its immediate dominator, loop headers that are empty branches with distinct merge and continue blocks and one back edge from the continue block, unique merges, conditional branches without a merge that leave their loop, and empty blocks that only forward, set or test a route variable, or one empty return; every original block keeps at least one unchanged copy; - run the same original blocks as the input for every branch decision: a search over pairs of input block, output block and the live route variable values, through the empty blocks between original blocks, compares the next original block on both sides of every conditional, loops included, and names the shortest decision sequence on a mismatch; reading an unset route variable or looping through empty blocks fails; - with SPIRV-Tools, pass validation for SPIR-V 1.3 and 1.4 as a skeleton module laid out the way SpirvFlowEmitter emits blocks, merges and branches. agc_structurizer_equivalence_forced_fallback runs the same graphs with APS5_FORCE_STRUCTURIZER_FALLBACK=1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nikowolf123
force-pushed
the
test/structurizer-equivalence
branch
from
October 13, 2026 23:07
071a735 to
f41e2d9
Compare
|
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.
|
11 tasks done
11 tasks done
This was referenced Oct 14, 2026
Contributor
Author
|
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 |
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.
What
#4926 makes
Structurizer::Structurizestructure every graph built from branch, conditional branch and return blocks: the existing ladder runs first, and a reach-flag construction takes over when the ladder refuses. The in-tree tests check hand-picked graphs (agc_structurizer) and RDNA programs (agc_shader_control_flow). The evidence that both paths keep every execution of the input came from an oracle outside the repository. This PR adds a condensed version of that oracle as a test, so every CI run checks the same properties on 2000 graphs.agc_structurizer_equivalencebuilds its graphs from fixed seeds (no clock, norandom_device). Each graph has 2 to 24 blocks:Structurizemust succeed on a copy of each graph. The output must then pass three checks, none of which reuses structurizer code:after decisions "--F-T" through original blocks 9 13 8 5 6 15: the input runs original block 15 but the structured graph runs block 32 with instructions [22, 24).ANYPS5_ENABLE_SPIRV_TOOLS, the same switch under whichRecompilevalidates the modules ofagc_shader_control_flow). The test emits a skeleton module with the blocks laid out the waySpirvFlowEmitteremits them: the two-block entry prologue,OpLoopMergeon loop headers,OpSelectionMergeon the other conditional branches that have a merge,OpBranchConditionalonOpUndefbooleans, andOpReturnfor returns. The module must validate for SPIR-V 1.3 (Vulkan 1.1) and 1.4. Since fix(shader): never branch conditionally to one label twice #4580 the emitter writesOpBranchfor a conditional branch whose two targets are the same block, and the skeleton does the same. The SPIR-V 1.6 rule against equal labels therefore cannot fire, and 1.6 is not checked separately.agc_structurizer_equivalence_forced_fallbackruns the same graphs withAPS5_FORCE_STRUCTURIZER_FALLBACK=1. Both tests are registered like the neighbouring structurizer tests:ANYPS5_NO_SHADER_CACHE=1, the source tree as working directory, andlibconPATHon Windows. SPIRV-Tools is linked only when it is enabled.The corpus has limits that keep the default run at about 2 s:
Without these limits, the ladder can spend tens of seconds on a single graph of 11 to 24 blocks before it accepts or refuses it (42 s on one 20-block graph). That is the ladder runtime limit #4926 lists, and this test does not measure it. GraphBuilder shapes (jump-table compare chains, the empty end block) stay covered by
agc_shader_control_flow.Tested
WSL2 Ubuntu 26.04 with GCC 15.2.0, configured like CI (Release, SPIRV-Tools ON, ccache), on top of #4926. Native Windows 11 with WinLibs GCC 15.2.0, SPIRV-Tools OFF as in the Windows CI job. No title.
ctest -R 'structurizer|control_flow': 10 of 10 pass in three runs.agc_structurizer_equivalencetakes 2.0 s andagc_structurizer_equivalence_forced_fallback1.0 s, with the same times under--parallel 4.tools/check_test_registration.pypasses on both build trees.tools/check_conventions.py --base origin/mainpasses, with both the branch's checker andmain's.hasStructuredConstructsrejects and SPIRV-Tools accepts.Structurizer.cppand ran both tests on it. The counts are failing graphs out of 2000. On the same outputs I also ran the contract, the equivalence search and SPIR-V validation one at a time, to show which check catches which mutant.Structurizer.cppagc_structurizer_equivalence..._forced_fallbackappendJunctionhasStructuredConstructsalways returns trueorderByDominancenever reordersorderByDominance"Self-check off" means
hasStructuredConstructsalso returns true. Without that, the structurizer rejects its own output,Structurizethrows, and the test fails on that instead.The last mutant survives because it changes nothing: the fallback already emits blocks in dominance order, and
orderByDominancereturns early on such graphs. WhenorderByDominancenever reorders, 500 outputs keep their entry at another block than block 0; the equivalence search starts at block 0, as the translator does, and catches all of them.Four outputs of the
hasStructuredConstructsmutant break construct rules that only SPIRV-Tools checks: a branch into a selection construct that bypasses its header, and a loop exit that is not a structured exit. Builds without SPIRV-Tools, such as the Windows CI job, do not check these two rules. In the other direction, the contract rejects one output that SPIRV-Tools accepts: a conditional branch without a merge that does not leave its loop.Of 21 further mutants (edge redirection, clone edges, reuse and clearing of route variables, the fallback's again flags, guards and loop heads, and single
hasStructuredConstructsrules), 17 fail the test. The other 4 change no behaviour: the oracle accepts all of their outputs too. On the outputs of 12 of these mutants and of the last six mutants in the table, the oracle rejects no output that the test accepts.main4bb2c7f and feat(recompiler): structure every control-flow graph the structurizer refuses #4926: the structurizer, control-flow and shader tests pass (20 of 20),agc_structurizer_equivalencein 2.0 s and its forced variant in 1.0 s.Rebased with #4926 onto
main30f9612. The conflicts were indocs/dev/debt/shader.md, wheremainadded entries next to #4926's, and earlier the test list incore/libs/prx/libSceAgcDriver/CMakeLists.txt; both sides are kept and the changed lines are identical. WSL2 Ubuntu 26.04, lavapipe (Mesa 26.0.8), CI configuration: the structurizer, control-flow and shader tests 20 of 20, fullctest1087 of 1087.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