fix(recompiler): merge a loop selection whose arm leaves the iteration where its arms rejoin #2941
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2941"
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 CnRJay on 2026-10-10T18:40:37Z.
What
PPSA28416 (STAR WARS: Galactic Racer, UE5) stops on
mainwith:Four of its compute shaders fail this way (135, 161, 162 and 272 blocks), each with exactly five times its original block count at the throw. A trace of the 161-block shader shows the same selection taking every split. Its header H sits inside a loop, and both arms rejoin at an empty block J that leads to a block X. X is also the merge of the enclosing selection, whose header branches to X directly, so H does not dominate X. Each arm can also leave the iteration through its own block that reaches the loop's continue. Those paths go round the loop and reach X through the enclosing header. So X stays the arms' nearest common post-dominator,
findSelectionMergekeeps returning it, andsplitSharedMergeBlockinserts one more empty block between J and X on every pass until the budget throws.findSelectionMergenow handles that case within the iteration. The case: inside a loop, both arms reach the global merge within the iteration, the header does not dominate it, and an arm can reach the loop's continue or merge block without passing it. The merge is then the nearest block that post-dominates both arms over the paths that reach the global merge without leaving the iteration, accepted only when the header dominates it and it lies in the loop construct. Leaving through the continue or the loop's merge from inside a selection is a structured continue or break. In every other case the merge choice is unchanged, and when no such block exists the existing fallback runs.This differs from #2471, where both arms reach the same loop exit and the merge chosen is that exit. Here the shared block is inside the loop body, and the arms' escapes go to the continue. #2471 alone does not fix these shaders.
Tested
Windows 11, WinLibs GCC 15.2.0 r7, Release, RTX 4080.
agc_shader_control_flowgains a 12-block fixture with this shape. Onmainit fails withCFG shared merge splitting exceeded budget: originalBlocks=12 currentBlocks=60 splitBudget=48. With the change, the existing harness structures it without cloning or route variables and compares every reachable original and rewritten branch and guest instruction range, for 32- and 64-lane subgroups.agc_structurizer,agc_spirv_*andagc_driver_scalar_program_flowpass. Full suite: 712/712 pass (5 VideoOut tests skipped, as onmain).agc_shader_replaypast structurization.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:35:29Z.
Checked on current main:
agc_shader_control_flow(new 12-block fixture, wave32/64),agc_structurizer,agc_structurizer_intersection_off,agc_spirv_moduleandagc_driver_scalar_program_flowpass. The new fixture fails without theStructurizer.cppchange (negative check). The merge choice is unchanged outside the case described, and the new one requires the header to dominate the merge inside the loop construct. Merging.Note for #2471: it conflicts with this one in
Structurizer.cpp; it will need a rebase on top of this change.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-11T07:49:27Z.
@CnRJay a follow-up on #2941. Since it landed, the structurizer emits invalid output for some graphs: a conditional in a loop gets no merge and neither breaks nor continues its loop. On the cfgfuzz corpus (30,000 graphs, seed 3), #2941 structurizes 2,032 graphs at 0 words per block that were refused before, and 1,919 of them are invalid. Smallest case:
{{1}, {2, 3}, {4, 5}, {}, {3, 6}, {7, 3}, {1}, {1}}("block 6 branches without a merge"). Before #2941 it was refused.iterationSelectionMergestops its backward walk only at the loop's continue and merge blocks. So the arms' nearest common post-dominator can be a block on the exit path in front of the loop merge, such as the one merge splitting inserts there, and the arms then leave the loop body without a merge.Fix: AlxcBTW/AnyPS5#40, 8 lines plus a regression test. Blocks outside the loop body end the analysis, so the merge is a block of the loop body, or there is none and the selection keeps its pre-#2941 merge.
mainbecomes invalid.The table and the remaining older invalid classes are in the PR description. @oneandonlydean, it's carry-ready if you want it.
AI-assisted: yes (Claude Code)