Structurizer test helper rejects structured output: constructBlocks uses dominance where SPIR-V uses structural dominance #2960
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 orishamir on 2026-10-10T18:56:05Z.
verifyStructuredincore/libs/prx/libSceAgcDriver/tests/ControlFlow.cpptakes a construct's blocks as those the header dominates and the merge does not (constructBlocks,graph.Dominates). SPIR-V 2.11.2 defines them by structural dominance, where a header's merge and continue declarations are edges (2.2.5). The two differ whenever a loop's merge declaration reaches a block that, in the plain CFG, is only reachable through an inner selection.Reproducer on
main57f96fd2(ControlFlow unchanged sincea29ef592), structurizer input as amakeGraphliteral:{{1, 5}, {2, 3}, {5}, {5, 4}, {1}, {}}.Structurizeoutput (cfgfuzz_main dump, from the harness in #2762):requireStructuredBranchespasses, and the compute shader built from this graph passes spirv-val (the bundled SPIRV-Tools,3rdparty/SPIRV-Toolsat 7f2d9ee9; @AlxcBTW saw the same with v2026.4 on #2642).verifyStructuredrejects it: block 3, the loop's merge, counts as a member of the selection at 2 because 2 dominates 3 in the plain CFG (the loop body is entered only through 2) and 2's merge 6 does not dominate it, so 3 -> 4 is reported as leaving the selection (block 7 of the selection at block 3 branches to block 8 outside the constructin the shader's numbering, which has an extra entry block). With the loop's merge declaration 1 -> 3 taken as an edge, 2 no longer dominates 3, 3 belongs to the outer selection at 0, and 3 -> 4 is that selection leaving to its own merge, which 2.11.3 allows.Effect: a structurizer change can fail
agc_shader_control_flow_testson output that is valid, and fuzz oracles built on the helper over-report. Five of the shapes I reported against AlxcBTW/AnyPS5#24 on #2642 are this; @AlxcBTW found the cause there and left the fix out of #24 because the test needs structural dominators (dominance over branch + merge + continue edges). This is a test-helper fix, not a structurizer change.AI-assisted: yes (Claude Code Fable 5.1 xhigh)
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-10T22:04:05Z.
I wrote the structural-dominance version of the helper:
Silverash-i8/AnyPS5-fork:fix/control-flow-test-structural-dominance, one commit148a28caonmaindc105f8a, test file only.verifyStructurednow works on a copy of the graph whose dominators are recomputed with each header's merge declaration, and a loop header's continue declaration, added as predecessor edges (2.2.5). Successors are untouched, so every check in the helper keeps its meaning and only the membership test changes. The rest of the function is as it was.I added your reproducer as a case:
{{1, 5}, {2, 3}, {5}, {5, 4}, {1}, {}}built with the same block layout asmakeGraph, run throughStructurize, thenverifyStructured.Tested on Windows 11, WinLibs GCC 15.2.0 r7, Release:
a loop merge reached only through an inner selection: block 6 of the selection at block 2 branches to block 7 outside the construct. With the fix it passes.ctest -R "control_flow|structuriz|agc_shader_": 11/11 pass, so none of the existing programs changed verdict.tools/check_conventions.pypasses.One caveat: I haven't run your fuzz harness from #2762 against it, so I can't say whether all five shapes you saw on #2642 now pass. If you get a chance, that would be the real check.
AI-assisted (Claude Code); I ran everything above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-10T22:23:11Z.
Thanks for writing it, and for the Windows run with the negative control. One thing first, in case you missed it: @MarcZX100's PR #2974 (head
71ced938, rebased on currentmain, no review yet) makes the same change, aStructuralDominatorsclass that computes dominators over branch, merge and continue edges and replaces everygraph.DominatesinsideverifyStructured, with the same six-block input as amakeGraph-style regression. So there are two implementations of the same helper fix now, and which one lands is the maintainers' call. Numbers for yours below; they are the same as #2974's.Measured on
148a28ca(maindc105f8a), Linux, GCC 15.2, Release, SPIRV-Tools on, yourControlFlow.cppcompiled againstmain's recompiler.Test binary: passes. With the helper switched back to plain dominance (
const auto& graph = structured;in place of thewithStructuralDominatorscall) it fails with exactly your diagnostic,a loop merge reached only through an inner selection: block 6 of the selection at block 2 branches to block 7 outside the construct, so the new case pins the change here as well.Harness (#2762): your helper spliced into the end-to-end oracle (decoder -> GraphBuilder -> Structurizer ->
verifyStructured-> Recompile with validation) in place of the test's old copy, 903-shader sample incl. 199 invalid-SPIR-V outputs:main's structurizer: the #2960 shader goes VALID_BUT_VERIFY_FAILED -> DONE, and the 12 helper rejections of validator-accepted outputs (all... outside the construct) become DONE. Nothing the old helper accepted is rejected; DONE/STRUCTURIZE/INVALID counts unchanged.predecessors, #2974 rebuilds predecessors fromsuccessors. On the 1,031 structurized outputs here the stored predecessors equal the successor-derived ones and block ids are their indices, so both compute the same dominators.verifyStructuredflags 0/199 of them now, and only the validator catches that class.Merges: clean with #2471 (a396b019) and #2941 (
54b30588); the mergedControlFlow.cppcompiles in both cases.AI-assisted: yes (Claude Code Fable 5.1 xhigh)
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-10T22:23:56Z.
@orishamir thanks, I did miss #2974, sorry for the noise. It was opened hours before my branch and makes the same change, so it should be the one that lands. I'll leave
fix/control-flow-test-structural-dominanceas it is and won't push it further.Your run is still useful for #2974: it shows the two compute the same dominators on every structurized output you have, so the result doesn't depend on whether predecessors are rebuilt from successors or reused.
AI-assisted (Claude Code).