Structurizer test helper rejects structured output: constructBlocks uses dominance where SPIR-V uses structural dominance #2960

Closed
opened 2026-10-10 18:56:05 +00:00 by orishamir · 3 comments
orishamir commented 2026-10-10 18:56:05 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-10T18:56:05Z.


verifyStructured in core/libs/prx/libSceAgcDriver/tests/ControlFlow.cpp takes 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 main 57f96fd2 (ControlFlow unchanged since a29ef592), structurizer input as a makeGraph literal: {{1, 5}, {2, 3}, {5}, {5, 4}, {1}, {}}. Structurize output (cfgfuzz_main dump, from the harness in #2762):

block 0  Cond(1, 4)  merge 4
block 1  -> 2        LOOP merge 3 continue 7
block 2  Cond(5, 6)  merge 6
block 3  -> 4
block 4  Return
block 5  -> 3
block 6  Cond(3, 7)
block 7  -> 1

requireStructuredBranches passes, and the compute shader built from this graph passes spirv-val (the bundled SPIRV-Tools, 3rdparty/SPIRV-Tools at 7f2d9ee9; @AlxcBTW saw the same with v2026.4 on #2642). verifyStructured rejects 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 construct in 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_tests on 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)

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5794297408 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2960). Originally posted by [orishamir](https://github.com/orishamir) on 2026-10-10T18:56:05Z. --- `verifyStructured` in `core/libs/prx/libSceAgcDriver/tests/ControlFlow.cpp` takes 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 `main` 57f96fd2 (ControlFlow unchanged since a29ef592), structurizer input as a `makeGraph` literal: `{{1, 5}, {2, 3}, {5}, {5, 4}, {1}, {}}`. `Structurize` output (`cfgfuzz_main dump`, from the harness in #2762): ``` block 0 Cond(1, 4) merge 4 block 1 -> 2 LOOP merge 3 continue 7 block 2 Cond(5, 6) merge 6 block 3 -> 4 block 4 Return block 5 -> 3 block 6 Cond(3, 7) block 7 -> 1 ``` `requireStructuredBranches` passes, and the compute shader built from this graph passes spirv-val (the bundled SPIRV-Tools, `3rdparty/SPIRV-Tools` at 7f2d9ee9; @AlxcBTW saw the same with v2026.4 on #2642). `verifyStructured` rejects 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 construct` in 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_tests` on 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)
Silverash-i8 commented 2026-10-10 22:04:05 +00:00 (Migrated from github.com)
Author
Contributor

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 commit 148a28ca on main dc105f8a, test file only.

verifyStructured now 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 as makeGraph, run through Structurize, then verifyStructured.

Tested on Windows 11, WinLibs GCC 15.2.0 r7, Release:

  • With the helper switched back to plain dominance, the new case fails: 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.py passes.

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102659619 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2960#issuecomment-6102659619). Originally posted by [Silverash-i8](https://github.com/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`](https://github.com/Silverash-i8/AnyPS5-fork/tree/fix/control-flow-test-structural-dominance), one commit `148a28ca` on `main` `dc105f8a`, test file only. `verifyStructured` now 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 as `makeGraph`, run through `Structurize`, then `verifyStructured`. Tested on Windows 11, WinLibs GCC 15.2.0 r7, Release: - With the helper switched back to plain dominance, the new case fails: `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.py` passes. 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.
orishamir commented 2026-10-10 22:23:11 +00:00 (Migrated from github.com)
Author
Contributor

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 current main, no review yet) makes the same change, a StructuralDominators class that computes dominators over branch, merge and continue edges and replaces every graph.Dominates inside verifyStructured, with the same six-block input as a makeGraph-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 (main dc105f8a), Linux, GCC 15.2, Release, SPIRV-Tools on, your ControlFlow.cpp compiled against main's recompiler.

Test binary: passes. With the helper switched back to plain dominance (const auto& graph = structured; in place of the withStructuralDominators call) 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.
  • AlxcBTW#24 (0b56b7ad) as the structurizer: 17 -> DONE, the five #24-only shapes from the issue text among them, 0 new rejections. Of the five #2642 shapes run separately, the three the old helper rejected under #24 pass now; the other two already did.
  • Verdict for verdict (stage and message), your helper and #2974's agree on all 903 rows with each structurizer, and on the #2642 shapes and the #2960 shader. The one way the two could differ is the edge set they start from: yours adds the declared edges to the structurizer's stored predecessors, #2974 rebuilds predecessors from successors. 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.
  • Same side effect as #2974 (noted there): 44 of the 199 invalid outputs (the #2762 class) that the old helper flagged through the same plain-dominance artifact are no longer flagged; verifyStructured flags 0/199 of them now, and only the validator catches that class.

Merges: clean with #2471 (a396b019) and #2941 (54b30588); the merged ControlFlow.cpp compiles in both cases.

AI-assisted: yes (Claude Code Fable 5.1 xhigh)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102814118 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2960#issuecomment-6102814118). Originally posted by [orishamir](https://github.com/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 current `main`, no review yet) makes the same change, a `StructuralDominators` class that computes dominators over branch, merge and continue edges and replaces every `graph.Dominates` inside `verifyStructured`, with the same six-block input as a `makeGraph`-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` (`main` dc105f8a), Linux, GCC 15.2, Release, SPIRV-Tools on, your `ControlFlow.cpp` compiled against `main`'s recompiler. **Test binary:** passes. With the helper switched back to plain dominance (`const auto& graph = structured;` in place of the `withStructuralDominators` call) 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. - AlxcBTW#24 (0b56b7ad) as the structurizer: 17 -> DONE, the five #24-only shapes from the issue text among them, 0 new rejections. Of the five #2642 shapes run separately, the three the old helper rejected under #24 pass now; the other two already did. - Verdict for verdict (stage and message), your helper and #2974's agree on all 903 rows with each structurizer, and on the #2642 shapes and the #2960 shader. The one way the two could differ is the edge set they start from: yours adds the declared edges to the structurizer's stored `predecessors`, #2974 rebuilds predecessors from `successors`. 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. - Same side effect as #2974 (noted there): 44 of the 199 invalid outputs (the #2762 class) that the old helper flagged through the same plain-dominance artifact are no longer flagged; `verifyStructured` flags 0/199 of them now, and only the validator catches that class. **Merges:** clean with #2471 (a396b019) and #2941 (54b30588); the merged `ControlFlow.cpp` compiles in both cases. AI-assisted: yes (Claude Code Fable 5.1 xhigh)
Silverash-i8 commented 2026-10-10 22:23:56 +00:00 (Migrated from github.com)
Author
Contributor

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-dominance as 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).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102820148 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2960#issuecomment-6102820148). Originally posted by [Silverash-i8](https://github.com/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-dominance` as 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).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#2960
No description provided.