recompiler: ReadLaneEliminator rewrites a spilled lane read to a value stored inside a branch, which does not dominate the read; fix branch ready #8050

Closed
opened 2026-10-19 18:49:53 +00:00 by TheSovietWaffle · 1 comment
TheSovietWaffle commented 2026-10-19 18:49:53 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-19T18:49:53Z.


ReadLaneEliminator replaces a v_readlane of a spill slot with the one value ever stored to that lane (uniqueLaneValue, through the per-lane SelectU32s and phis of collectLaneValues). When the v_writelane that stores it sits inside a branch, that value is defined in the branch and does not dominate the read after the merge, so the program later fails validation:

ShaderRecompiler::Recompile: value IR instruction definition does not dominate its use

Seen on Onimusha: Way of the Sword (PPSA27836, base 01.000.001), a 9,944-instruction wave64 pixel shader, about 6 minutes into the first scene load on an RTX 3080. Validating after every front-end pass (local diagnostic) shows the program valid after SSA, folding and control-flow identities, and broken right after readLaneEliminator.Eliminate; with only the unique-value rewrite disabled it prepares (780,890 SPIR-V words).

Fix branch: https://github.com/TheSovietWaffle/AnyPS5/tree/fix/recompiler-readlane-unique-dominance (one commit on main 8c9161eac; Optimization/src/ReadLaneEliminator.cpp, the new test tests/ReadLaneElimination.cpp registered in the libSceAgcDriver CMakeLists.txt). Where the stored value does not dominate the read, the read now takes it through phis built from the control flow: the stored value in the blocks it dominates, and an UndefU32 on paths that never store the lane, which the eliminator already treats as never read back. A read the value dominates is rewritten as before.

Checks:

  • The new test fails on main (a lane stored inside a branch is read through a value that does not dominate it) and passes with the change; the case where the value is computed before the branch is rewritten as before.
  • The retained Onimusha request prepares with the change (780,895 SPIR-V words).
  • With both fix branches merged on main 8c9161eac, all 806 agc tests on an RTX 3080 (617.42) and an AMD Radeon RDNA 2 iGPU (1002:164e, 32.0.21045.5002): 805 pass on each. The one failure on each (agc_driver_pass_input_hazard on the RTX 3080, agc_trimmed_import on the Radeon) fails the same way on unchanged main.
  • check_conventions.py passes.

Not verified: the undefined value is only ever read on paths the eliminator already assumes never read the slot back; that assumption is unchanged.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5929610157 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8050). Originally posted by [TheSovietWaffle](https://github.com/TheSovietWaffle) on 2026-10-19T18:49:53Z. --- `ReadLaneEliminator` replaces a `v_readlane` of a spill slot with the one value ever stored to that lane (`uniqueLaneValue`, through the per-lane `SelectU32`s and phis of `collectLaneValues`). When the `v_writelane` that stores it sits inside a branch, that value is defined in the branch and does not dominate the read after the merge, so the program later fails validation: ``` ShaderRecompiler::Recompile: value IR instruction definition does not dominate its use ``` Seen on Onimusha: Way of the Sword (PPSA27836, base 01.000.001), a 9,944-instruction wave64 pixel shader, about 6 minutes into the first scene load on an RTX 3080. Validating after every front-end pass (local diagnostic) shows the program valid after SSA, folding and control-flow identities, and broken right after `readLaneEliminator.Eliminate`; with only the unique-value rewrite disabled it prepares (780,890 SPIR-V words). Fix branch: https://github.com/TheSovietWaffle/AnyPS5/tree/fix/recompiler-readlane-unique-dominance (one commit on main `8c9161eac`; `Optimization/src/ReadLaneEliminator.cpp`, the new test `tests/ReadLaneElimination.cpp` registered in the libSceAgcDriver `CMakeLists.txt`). Where the stored value does not dominate the read, the read now takes it through phis built from the control flow: the stored value in the blocks it dominates, and an `UndefU32` on paths that never store the lane, which the eliminator already treats as never read back. A read the value dominates is rewritten as before. Checks: - The new test fails on main (a lane stored inside a branch is read through a value that does not dominate it) and passes with the change; the case where the value is computed before the branch is rewritten as before. - The retained Onimusha request prepares with the change (780,895 SPIR-V words). - With both fix branches merged on main `8c9161eac`, all 806 `agc` tests on an RTX 3080 (617.42) and an AMD Radeon RDNA 2 iGPU (`1002:164e`, 32.0.21045.5002): 805 pass on each. The one failure on each (`agc_driver_pass_input_hazard` on the RTX 3080, `agc_trimmed_import` on the Radeon) fails the same way on unchanged main. - `check_conventions.py` passes. Not verified: the undefined value is only ever read on paths the eliminator already assumes never read the slot back; that assumption is unchanged. AI-assisted: yes (Claude Code).
MarcZX10 commented 2026-10-19 20:57:35 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T20:57:35Z.


I opened PR #8089 from your reported fix, rebased onto current main (9127ea36). The two commits separate the failing regression from the dominance fix and preserve the original commit author.

On the current main base, the new test fails on the branch-local store case; with the fix, agc_read_lane_elimination passes (1/1). The implementation patch is byte-for-byte equivalent to the one in your linked branch. The PR carries your reported retained-shader and GPU results with their original baseline and OS limits stated explicitly.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6277163479 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8050#issuecomment-6277163479). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T20:57:35Z. --- I opened [PR #8089](https://github.com/boykopovar/AnyPS5/pull/8089) from your reported fix, rebased onto current `main` (`9127ea36`). The two commits separate the failing regression from the dominance fix and preserve the original commit author. On the current main base, the new test fails on the branch-local store case; with the fix, `agc_read_lane_elimination` passes (1/1). The implementation patch is byte-for-byte equivalent to the one in your linked branch. The PR carries your reported retained-shader and GPU results with their original baseline and OS limits stated explicitly.
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#8050
No description provided.