test(shader): use structural dominance in CFG checks #2974

Merged
MarcZX10 merged 2 commits from upstream-pr/2974 into main 2026-10-10 23:42:14 +00:00
MarcZX10 commented 2026-10-10 19:09:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T19:09:05Z.


What

Fixes #2960. The control-flow test helper derived structured construct membership from ordinary CFG dominators, which can misclassify a loop merge as part of a nested selection. Compute structural dominators for the helper by including each construct's declared merge edge and each loop's declared continue edge, and use those dominators throughout the structured-branch checks.

The regression builds the six-block #2960 input, runs it through the real Structurizer, then checks the resulting eight-block graph. The test passes with this helper and fails with the old plain-dominator helper at block 6 branching to block 7 outside the selection.

Two open structurizer PRs (#2471 and #2941) also extend ControlFlow.cpp; they add separate fixtures and changes in Structurizer.cpp. This PR changes only the test helper and its focused regression case.

Tested

Linux, GCC 12.2.0, Release: built agc_shader_control_flow_tests; CTest agc_shader_control_flow passed (1/1). Replacing the structural-dominator queries with plain graph.Dominates made the new regression fail with the expected diagnostic. python3 tools/check_conventions.py --base upstream/main and git diff --check passed.

Checklist

  • Based on current main; no other open PR implements the same function
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4813738084 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2974). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T19:09:05Z. --- ### What Fixes #2960. The control-flow test helper derived structured construct membership from ordinary CFG dominators, which can misclassify a loop merge as part of a nested selection. Compute structural dominators for the helper by including each construct's declared merge edge and each loop's declared continue edge, and use those dominators throughout the structured-branch checks. The regression builds the six-block #2960 input, runs it through the real `Structurizer`, then checks the resulting eight-block graph. The test passes with this helper and fails with the old plain-dominator helper at block 6 branching to block 7 outside the selection. Two open structurizer PRs (#2471 and #2941) also extend `ControlFlow.cpp`; they add separate fixtures and changes in `Structurizer.cpp`. This PR changes only the test helper and its focused regression case. ### Tested Linux, GCC 12.2.0, Release: built `agc_shader_control_flow_tests`; CTest `agc_shader_control_flow` passed (1/1). Replacing the structural-dominator queries with plain `graph.Dominates` made the new regression fail with the expected diagnostic. `python3 tools/check_conventions.py --base upstream/main` and `git diff --check` passed. ### Checklist - [x] Based on current `main`; no other open PR implements the same function - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
orishamir commented 2026-10-10 19:30:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-10T19:30:54Z.


Measured on c6d9f9cb (main 4a747c48 + this commit), Linux, GCC, Release, SPIRV-Tools on.

The regression does not pin the helper change. main's verifyStructured (plain graph.Dominates) plus only verifyLoopMergeDoesNotEnterNestedSelection and its main hook: the test passes. The hand-built graph never gets BasicBlock::dominators filled (only the structurizer's private computeDominatorTree fills it), so graph.Dominates is false for every pair, constructBlocks returns no members for any header, and the old per-member checks never run on it. The shape itself is right: with StructuralDominators minus its two merge/continue edges (plain dominance, actually computed) the same graph fails with block 3 of the selection at block 2 branches to block 4 outside the construct.

A regression that pins (measured: passes with this PR's helper, fails on main's with block 6 of the selection at block 2 branches to block 7 outside the construct, block 6 being the loop's merge): build the unstructured #2960 input {{1, 5}, {2, 3}, {5}, {5, 4}, {1}, {}} the way makeGraph in tests/Structurizer.cpp does (ids, program counters, instruction ranges, SccNonZero conditions, predecessors), run Structurizer{}.Structurize(graph), then verifyStructured. That also keeps the regression on real structurizer output, where #2960 was found.

End to end (harness from #2762, 903-shader sample incl. 199 invalid-SPIR-V outputs, main structurizer): the #2960 shader goes VALID_BUT_VERIFY_FAILED -> DONE; 12 of the sample's helper rejections of validator-accepted outputs (all ... outside the construct) become DONE; nothing the old helper accepted is rejected now; DONE/STRUCTURIZE/INVALID counts unchanged. With AlxcBTW#24 (0b56b7ad) as the structurizer: 17 -> DONE, the shapes I listed on #2642 among them, 0 new rejections. Side effect: 44 of the 199 invalid outputs (the #2762 class: 41 branches to the selection construct, but not to the selection header, 3 Selection must be structured) that the old helper flagged through the same plain-dominance artifact are no longer flagged, so verifyStructured now flags 0/199 of them; only the validator catches that class, and verifyRequest (recorded requests) does not run it.

Merges: clean with #2471 (470f51ce) 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:6101355197 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2974#issuecomment-6101355197). Originally posted by [orishamir](https://github.com/orishamir) on 2026-10-10T19:30:54Z. --- Measured on c6d9f9cb (main 4a747c48 + this commit), Linux, GCC, Release, SPIRV-Tools on. **The regression does not pin the helper change.** main's `verifyStructured` (plain `graph.Dominates`) plus only `verifyLoopMergeDoesNotEnterNestedSelection` and its `main` hook: the test passes. The hand-built graph never gets `BasicBlock::dominators` filled (only the structurizer's private `computeDominatorTree` fills it), so `graph.Dominates` is false for every pair, `constructBlocks` returns no members for any header, and the old per-member checks never run on it. The shape itself is right: with `StructuralDominators` minus its two merge/continue edges (plain dominance, actually computed) the same graph fails with `block 3 of the selection at block 2 branches to block 4 outside the construct`. A regression that pins (measured: passes with this PR's helper, fails on main's with `block 6 of the selection at block 2 branches to block 7 outside the construct`, block 6 being the loop's merge): build the unstructured #2960 input `{{1, 5}, {2, 3}, {5}, {5, 4}, {1}, {}}` the way `makeGraph` in tests/Structurizer.cpp does (ids, program counters, instruction ranges, `SccNonZero` conditions, predecessors), run `Structurizer{}.Structurize(graph)`, then `verifyStructured`. That also keeps the regression on real structurizer output, where #2960 was found. **End to end** (harness from #2762, 903-shader sample incl. 199 invalid-SPIR-V outputs, main structurizer): the #2960 shader goes VALID_BUT_VERIFY_FAILED -> DONE; 12 of the sample's helper rejections of validator-accepted outputs (all `... outside the construct`) become DONE; nothing the old helper accepted is rejected now; DONE/STRUCTURIZE/INVALID counts unchanged. With AlxcBTW#24 (0b56b7ad) as the structurizer: 17 -> DONE, the shapes I listed on #2642 among them, 0 new rejections. Side effect: 44 of the 199 invalid outputs (the #2762 class: 41 `branches to the selection construct, but not to the selection header`, 3 `Selection must be structured`) that the old helper flagged through the same plain-dominance artifact are no longer flagged, so `verifyStructured` now flags 0/199 of them; only the validator catches that class, and `verifyRequest` (recorded requests) does not run it. **Merges:** clean with #2471 (470f51ce) and #2941 (54b30588); the merged `ControlFlow.cpp` compiles in both cases. AI-assisted: yes (Claude Code Fable 5.1 xhigh)
MarcZX10 commented 2026-10-10 19:40:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T19:40:15Z.


Addressed in 03ed5aecb: the regression now builds the six-block #2960 input with populated block metadata, runs Structurizer, and verifies its eight-block output. It passes with the structural helper; substituting plain graph.Dominates reproduces the expected block 6 -> 7 failure. Updated the PR description and reran the focused CTest and conventions check.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101444564 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2974#issuecomment-6101444564). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T19:40:15Z. --- Addressed in 03ed5aecb: the regression now builds the six-block #2960 input with populated block metadata, runs Structurizer, and verifies its eight-block output. It passes with the structural helper; substituting plain graph.Dominates reproduces the expected block 6 -> 7 failure. Updated the PR description and reran the focused CTest and conventions check.
MarcZX10 commented 2026-10-10 20:50:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T20:50:58Z.


I rebased both commits onto current main and rechecked the regression on Linux (GCC 12.2, Release). agc_shader_control_flow passes with the structural-dominator helper. As a negative control, I temporarily replaced its dominator queries with the old graph.Dominates calls; the test then fails with the reported block 6 ... branches to block 7 outside the construct diagnostic. I restored the structural helper, rebuilt the target, and confirmed the focused test passes again. Conventions and git diff --check also pass on the rebased branch.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102045953 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2974#issuecomment-6102045953). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T20:50:58Z. --- I rebased both commits onto current `main` and rechecked the regression on Linux (GCC 12.2, Release). `agc_shader_control_flow` passes with the structural-dominator helper. As a negative control, I temporarily replaced its dominator queries with the old `graph.Dominates` calls; the test then fails with the reported `block 6 ... branches to block 7 outside the construct` diagnostic. I restored the structural helper, rebuilt the target, and confirmed the focused test passes again. Conventions and `git diff --check` also pass on the rebased branch.
adriadam10 commented 2026-10-10 23:42:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:42:11Z.


Checked on the PR merged onto current main: agc_shader_control_flow passes (344/344 in the libSceAgcDriver scope). As a negative control, dropping the merge/continue edges from StructuralDominators makes the new #2960 regression fail. The helper now follows SPIR-V structural dominance and the regression runs the real Structurizer, which addresses the earlier review. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103416600 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2974#issuecomment-6103416600). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T23:42:11Z. --- Checked on the PR merged onto current main: `agc_shader_control_flow` passes (344/344 in the libSceAgcDriver scope). As a negative control, dropping the merge/continue edges from `StructuralDominators` makes the new #2960 regression fail. The helper now follows SPIR-V structural dominance and the regression runs the real `Structurizer`, which addresses the earlier review. Merging.
Sign in to join this conversation.
No reviewers
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!2974
No description provided.