fix(recompiler): give an early-return selection that joins its parent's merge a merge of its own #413

Merged
oneandonlydean merged 1 commit from upstream-pr/413 into main 2026-10-03 22:30:06 +00:00
oneandonlydean commented 2026-10-02 22:06:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T22:06:10Z.


What

A selection whose one arm only returns (a kill or s_endpgm tail) and whose other arm branches straight to the merge of an enclosing selection got no structured merge. The returning arm has no join, and the other target belongs to the parent construct, so findSelectionMerge finds nothing, no existing split applies, and the shader fails to structurize, which skips the draw. PPSA21564's BotEye G-buffer pixel shaders (eight variants) have this shape; the crowd robots and the mothership lose their visors and eyes.

splitSharedMergeBlocks now has a last split, splitOneReturnJoin, tried after the loop and selection merge splits. For a conditional branch outside any loop with no selection merge, where:

  • one target is dominated by the header and runs linearly to a terminal block (the return arm), and
  • the other target is not dominated by the header and every predecessor of it is either dominated by the header or dominates it (the enclosing construct's join),

the edge from the header's region to that join is split into an empty block (splitSharedMergeBlock), which becomes the header's own merge. The enclosing selection keeps the original join as its merge.

This is the selection counterpart of #275 (exit-tail branches inside loops): splitOneReturnJoin skips blocks inside a loop, so the two do not overlap.

Tests:

  • agc_structurizer_tests: the bare graph (an early return inside a selection that joins its parent's merge) structurizes, and every header dominates its merge.
  • agc_shader_control_flow_tests: an RDNA program with that shape recompiles with neither cloning nor route variables (a new Split::None expectation).

Tested

  • Linux (CachyOS, GCC 16), RTX 4090: ctest 125/125 pass. With Structurizer.cpp reverted to main, agc_structurizer_tests fails with "conditional block 1 has no structured merge" and agc_shader_control_flow_tests fails on the new program.
  • PPSA21564: of 6087 shader requests captured from the title, 10 failed to structurize before this change and none after (CPU sweep on my integration branch). The crowd robots' visors and eyes in the intro render again, and the change has been on my integration branch through repeated passes of my visual regression check (intro, title, menu and a level).

Checklist

  • Based on current main; no other open PR implements the same functions
  • 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 (attach them to this PR)
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4721968777 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/413). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-02T22:06:10Z. --- ### What A selection whose one arm only returns (a kill or `s_endpgm` tail) and whose other arm branches straight to the merge of an enclosing selection got no structured merge. The returning arm has no join, and the other target belongs to the parent construct, so `findSelectionMerge` finds nothing, no existing split applies, and the shader fails to structurize, which skips the draw. PPSA21564's BotEye G-buffer pixel shaders (eight variants) have this shape; the crowd robots and the mothership lose their visors and eyes. `splitSharedMergeBlocks` now has a last split, `splitOneReturnJoin`, tried after the loop and selection merge splits. For a conditional branch outside any loop with no selection merge, where: - one target is dominated by the header and runs linearly to a terminal block (the return arm), and - the other target is not dominated by the header and every predecessor of it is either dominated by the header or dominates it (the enclosing construct's join), the edge from the header's region to that join is split into an empty block (`splitSharedMergeBlock`), which becomes the header's own merge. The enclosing selection keeps the original join as its merge. This is the selection counterpart of #275 (exit-tail branches inside loops): `splitOneReturnJoin` skips blocks inside a loop, so the two do not overlap. Tests: - `agc_structurizer_tests`: the bare graph (an early return inside a selection that joins its parent's merge) structurizes, and every header dominates its merge. - `agc_shader_control_flow_tests`: an RDNA program with that shape recompiles with neither cloning nor route variables (a new `Split::None` expectation). ### Tested - Linux (CachyOS, GCC 16), RTX 4090: `ctest` 125/125 pass. With `Structurizer.cpp` reverted to `main`, `agc_structurizer_tests` fails with "conditional block 1 has no structured merge" and `agc_shader_control_flow_tests` fails on the new program. - PPSA21564: of 6087 shader requests captured from the title, 10 failed to structurize before this change and none after (CPU sweep on my integration branch). The crowd robots' visors and eyes in the intro render again, and the change has been on my integration branch through repeated passes of my visual regression check (intro, title, menu and a level). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [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 (attach them to this PR) - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
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!413
No description provided.