shader: resolve setpc dword jump tables whose load overwrites the selector #1485

Closed
github-bot wants to merge 1 commit from gh-pr/1485/head into gh-pr/1485/base
Owner

@⁠overlordxrz-source on GitHub · 2026-10-13 19:53 UTC · original
overlordxrz-source:nhl-setpc-dword-aliased-selector → main · +55 −1 · 2 files · 1 commits · closed without merging

Fixes the NHL 27 (PPSA34063, #1101) stop in compute shader 0xad738baf31b6e28b:

shader CFG build failed: unsupported dynamic S_SETPC_B64 at pc 0x00000774

The shader jumps through a dword offset table, and the table load writes back into its own index register:

0x00000474: S_MIN_U32 s19, vcc_lo, 22
0x00000518: S_LSHL_B32 s19, s19, 2
0x0000053c: s_getpc_b64 s22
0x00000540: S_ADD_U32 s22, 0x00000bd0, s22
0x00000558: S_LOAD_DWORD s19, s22, s19
0x0000076c: S_SUB_U32 s22, s22, s19
0x00000774: s_setpc_b64 s22

ResolveSetpcDwordJumpTable rejected this because the selector and the loaded offset are the same register (selector_code == offset_code). That check isn't needed. A resolved table load goes into code_table_load_pcs and isn't translated (IsCodeTableLoad), so at the s_setpc_b64 the register still holds the selector. ScalarCodeWrittenInRange still rejects any write between the load and the setpc. The qword resolver (ResolveSetpcJumpTable) never had this check.

fozter found this and wrote the fix while investigating NHL 27 (shader dump: https://github.com/user-attachments/files/33356991/shader_0xad738baf31b6e28b_pr1446.txt). It's his patch, used with his permission (#1101), so he's the commit author. I turned it into a commit on current main and checked it.

Adds TestNewShaderRecompilerSetpcDwordJumpTableAliasedSelector.

Testing:

  • I ran a small native harness of the decoder plus CFG::BuildGraph. The cases were the new test's shader words, the existing dword-table test shape, and a skeleton of the NHL shader's scalar code (same registers, the add with the literal first, a 23-entry table).
    • On main, the aliased shapes exit with unsupported dynamic S_SETPC_B64.
    • With this change they resolve: selector s6 or s19, cases 0->0x30 4->0x38 8->0x30, and 23 cases for the NHL skeleton. The existing dword test is unchanged.
    • The same shape with the selector overwritten between the load and the setpc is still rejected.
  • x86_64-linux compile of ShaderCFG.cpp with -Wall -Wextra: no new warnings. tests/shaderCfgTests.cpp builds with -fsyntax-only.
  • I couldn't link or run the full shader_cfg_tests binary here, so the IR/SPIR-V checks in the new test (dispatcher mode, no SLoadDword, OpSwitch, spirv-val) haven't been run locally.
  • fozter offered to test NHL 27 builds and I've asked him to on #1101.

AI-assisted: yes. fozter's investigation and patch were done with Claude. I used AI to review it, write the harness and draft this text. I reviewed the change and ran the checks above.

**@⁠overlordxrz-source** on GitHub · 2026-10-13 19:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1485) `overlordxrz-source:nhl-setpc-dword-aliased-selector` → `main` · +55 −1 · 2 files · 1 commits · closed without merging Fixes the NHL 27 (PPSA34063, #1101) stop in compute shader `0xad738baf31b6e28b`: ``` shader CFG build failed: unsupported dynamic S_SETPC_B64 at pc 0x00000774 ``` The shader jumps through a dword offset table, and the table load writes back into its own index register: ``` 0x00000474: S_MIN_U32 s19, vcc_lo, 22 0x00000518: S_LSHL_B32 s19, s19, 2 0x0000053c: s_getpc_b64 s22 0x00000540: S_ADD_U32 s22, 0x00000bd0, s22 0x00000558: S_LOAD_DWORD s19, s22, s19 0x0000076c: S_SUB_U32 s22, s22, s19 0x00000774: s_setpc_b64 s22 ``` `ResolveSetpcDwordJumpTable` rejected this because the selector and the loaded offset are the same register (`selector_code == offset_code`). That check isn't needed. A resolved table load goes into `code_table_load_pcs` and isn't translated (`IsCodeTableLoad`), so at the `s_setpc_b64` the register still holds the selector. `ScalarCodeWrittenInRange` still rejects any write between the load and the setpc. The qword resolver (`ResolveSetpcJumpTable`) never had this check. fozter found this and wrote the fix while investigating NHL 27 (shader dump: https://github.com/user-attachments/files/33356991/shader_0xad738baf31b6e28b_pr1446.txt). It's his patch, used with his permission (https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/1101), so he's the commit author. I turned it into a commit on current main and checked it. Adds `TestNewShaderRecompilerSetpcDwordJumpTableAliasedSelector`. Testing: - I ran a small native harness of the decoder plus `CFG::BuildGraph`. The cases were the new test's shader words, the existing dword-table test shape, and a skeleton of the NHL shader's scalar code (same registers, the add with the literal first, a 23-entry table). - On main, the aliased shapes exit with `unsupported dynamic S_SETPC_B64`. - With this change they resolve: selector s6 or s19, cases `0->0x30 4->0x38 8->0x30`, and 23 cases for the NHL skeleton. The existing dword test is unchanged. - The same shape with the selector overwritten between the load and the setpc is still rejected. - x86_64-linux compile of ShaderCFG.cpp with `-Wall -Wextra`: no new warnings. `tests/shaderCfgTests.cpp` builds with `-fsyntax-only`. - I couldn't link or run the full `shader_cfg_tests` binary here, so the IR/SPIR-V checks in the new test (dispatcher mode, no `SLoadDword`, `OpSwitch`, spirv-val) haven't been run locally. - fozter offered to test NHL 27 builds and I've asked him to on #1101. AI-assisted: yes. fozter's investigation and patch were done with Claude. I used AI to review it, write the harness and draft this text. I reviewed the change and ran the checks above.
NHL 27 (PPSA34063, #1101) stops in compute shader 0xad738baf31b6e28b with
"shader CFG build failed: unsupported dynamic S_SETPC_B64 at pc 0x00000774".
The shader dispatches through a dword offset table whose load reuses its
index register as the destination:

    s_getpc_b64     s[22:23]           ; 0x53c
    s_load_dword    s19, s[22:23], s19 ; 0x558
    ...
    s_setpc_b64     s[22:23]           ; 0x774

ResolveSetpcDwordJumpTable rejected this shape because the selector and the
loaded offset share a register. The check is not needed: resolved table
loads are recorded as code-table loads and are not translated, so at the
S_SETPC_B64 the register still holds the selector, and writes between the
load and the setpc are still rejected by ScalarCodeWrittenInRange. The qword
resolver (ResolveSetpcJumpTable) has no such check either.

Add a regression test with the aliased shape.

Co-authored-by: overlordxrz-source <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:57:51 +00:00
github-bot closed this pull request 2026-11-26 09:57:51 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-13 19:59 UTC · original

Review in Change Stack →

📝 Walkthrough

ResolveSetpcDwordJumpTable now accepts a scalar selector that uses the same register as the jump-table load’s byte offset. It continues to reject non-scalar selectors and selectors overwritten between the load and S_SETPC_B64. A regression test checks dispatcher lowering, target mappings, IR output, and SPIR-V validity.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: 🟡 Moderate · up to 2dfab

Shaders whose jump-table load overwrites its own selector register now compile. If a branch target later reads that register, it could see the selector instead of the loaded word. The risk is narrow, but it should be resolved or explicitly accepted before merge.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: resolving dword jump tables when the load overwrites the selector.
Description check Passed The description directly explains the NHL 27 failure, the code change, the regression test, and the reported validation results.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 too large.)

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-13 19:59 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1485#issuecomment-6154029095) <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1485?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> `ResolveSetpcDwordJumpTable` now accepts a scalar selector that uses the same register as the jump-table load’s byte offset. It continues to reject non-scalar selectors and selectors overwritten between the load and `S_SETPC_B64`. A regression test checks dispatcher lowering, target mappings, IR output, and SPIR-V validity. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"2dfab0d50bc1bf975aac38de6f6d211be04b7b96" --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>🟡 Moderate</strong> · up to <code>2dfab</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🟡 Moderate** · up to `2dfab` --> <!-- final_review_risk_coverage:{"sourceCommitId":"2dfab0d50bc1bf975aac38de6f6d211be04b7b96","coveredCommitId":"2dfab0d50bc1bf975aac38de6f6d211be04b7b96","kind":"reviewed"} --> Shaders whose jump-table load overwrites its own selector register now compile. If a branch target later reads that register, it could see the selector instead of the loaded word. The risk is narrow, but it should be resolved or explicitly accepted before merge. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-inconclusive-14-v2.svg" width="14" height="14" align="middle" alt="Inconclusive" title="Inconclusive"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 inconclusive</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :--------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Inconclusive](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-inconclusive.svg) | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 … | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the main change: resolving dword jump tables when the load overwrites the selector. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the NHL 27 failure, the code change, the regression test, and the reported validation results. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 too large.) </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1485)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-13 19:59 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c7119d66-cd8e-4004-b1ae-91d3b3809dae
📥 Commits

Reviewing files that changed from the base of the PR and between df5b9b92be and 2dfab0d50b.

📒 Files selected for processing: 2
  • src/graphics/shader/recompiler/frontend/cfg/ShaderCFG.cpp
  • tests/shaderCfgTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-13 19:59 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1485#pullrequestreview-5509217381) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `c7119d66-cd8e-4004-b1ae-91d3b3809dae` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between df5b9b92be7dfd463b47756b707d6d356a9f0550 and 2dfab0d50bc1bf975aac38de6f6d211be04b7b96. </details> <details> <summary>📒 Files selected for processing: 2</summary> * `src/graphics/shader/recompiler/frontend/cfg/ShaderCFG.cpp` * `tests/shaderCfgTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=aa6e10b5-96a4-49b7-8566-bd80e39cc1a4 attempt=4f069d8b-28d1-4001-b41d-e3ae9ce8adf5 batch=1/1 -->
@ -469,2 +469,4 @@
return false;
}
// The load may overwrite its own index register (s_load_dword s19, s[22:23], s19): code-table
// loads are not translated, so the register still holds the selector at the S_SETPC_B64.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-13 19:59 UTC · original

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect code-table load suppression and indirect selector lowering.
rg -n -C 8 'code_table_load_pcs|indirect_selector_code|indirect_selector_values' \
  src/graphics/shader/recompiler/frontend

Repository: KytyPS5/KytyPS5

Length of output: 20140


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- ReadScalarCode and callers ---'
rg -n -C 18 -F -- 'ReadScalarCode' src/graphics/shader/recompiler/frontend/translate
printf '%s\n' '--- code-table load handling ---'
rg -n -C 20 -e 'IsCodeTableLoad' -e 'code_table_load_pcs' -e 'CodeTable' src/graphics/shader/recompiler/frontend/translate
printf '%s\n' '--- scalar register writes/reads in the relevant translator ---'
rg -n -C 10 -e 'GetScalarReg' -e 'SetScalarReg' -e 'S_LOAD_DWORD' -e 'SLoadDword' src/graphics/shader/recompiler/frontend/translate

Repository: KytyPS5/KytyPS5

Length of output: 41496


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- CFG block translation loop ---'
sed -n '1398,1440p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp
printf '%s\n' '--- S_LOAD implementation and scalar writes ---'
rg -n -C 35 -F -- 'void Translator::S_LOAD' src/graphics/shader/recompiler/frontend/translate/Memory.cpp
printf '%s\n' '--- scalar operand read/write helpers ---'
rg -n -C 18 -e 'IR::U32 Translator::ReadU32' -e 'void Translator::WriteOperand' -e 'GetScalarReg' -e 'SetScalarReg' src/graphics/shader/recompiler/frontend/translate/Translate.cpp src/graphics/shader/recompiler/frontend/translate/Translator.cpp src/graphics/shader/recompiler/frontend/translate

Repository: KytyPS5/KytyPS5

Length of output: 41873


Preserve the loaded value when the aliased register remains live.

Translate.cpp skips every code-table load before calling Translator::TranslateInstruction. A normal SGPR read and ReadScalarCode both return the current ir.GetScalarReg value. Therefore, a target that reads the aliased register can observe its pre-load selector value instead of the table word.

Reconstruct the loaded word for later reads, or reject this shape when the aliased register remains live.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-13 19:59 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1485#discussion_r4263379052) **🎯 Functional Correctness** | **🟠 Major** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash #!/bin/bash # Inspect code-table load suppression and indirect selector lowering. rg -n -C 8 'code_table_load_pcs|indirect_selector_code|indirect_selector_values' \ src/graphics/shader/recompiler/frontend ``` Repository: KytyPS5/KytyPS5 Length of output: 20140 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- ReadScalarCode and callers ---' rg -n -C 18 -F -- 'ReadScalarCode' src/graphics/shader/recompiler/frontend/translate printf '%s\n' '--- code-table load handling ---' rg -n -C 20 -e 'IsCodeTableLoad' -e 'code_table_load_pcs' -e 'CodeTable' src/graphics/shader/recompiler/frontend/translate printf '%s\n' '--- scalar register writes/reads in the relevant translator ---' rg -n -C 10 -e 'GetScalarReg' -e 'SetScalarReg' -e 'S_LOAD_DWORD' -e 'SLoadDword' src/graphics/shader/recompiler/frontend/translate ``` Repository: KytyPS5/KytyPS5 Length of output: 41496 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- CFG block translation loop ---' sed -n '1398,1440p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp printf '%s\n' '--- S_LOAD implementation and scalar writes ---' rg -n -C 35 -F -- 'void Translator::S_LOAD' src/graphics/shader/recompiler/frontend/translate/Memory.cpp printf '%s\n' '--- scalar operand read/write helpers ---' rg -n -C 18 -e 'IR::U32 Translator::ReadU32' -e 'void Translator::WriteOperand' -e 'GetScalarReg' -e 'SetScalarReg' src/graphics/shader/recompiler/frontend/translate/Translate.cpp src/graphics/shader/recompiler/frontend/translate/Translator.cpp src/graphics/shader/recompiler/frontend/translate ``` Repository: KytyPS5/KytyPS5 Length of output: 41873 --- </details> **Preserve the loaded value when the aliased register remains live.** `Translate.cpp` skips every code-table load before calling `Translator::TranslateInstruction`. A normal SGPR read and `ReadScalarCode` both return the current `ir.GetScalarReg` value. Therefore, a target that reads the aliased register can observe its pre-load selector value instead of the table word. Reconstruct the loaded word for later reads, or reject this shape when the aliased register remains live. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:384e23c5aa6843a2c777a046 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠overlordxrz-source on GitHub · 2026-10-14 19:34 UTC · original

@⁠coderabbitai This isn't new to the aliased case. On main, every resolved dword table load is skipped the same way (IsCodeTableLoad in Translate.cpp), so in the non-aliased shape the offset register is never written either and a target that read it would see whatever was there before. The patch only drops the selector_code == offset_code rejection; it doesn't change what the targets see. Neither the NHL 27 shader nor the existing tests read the loaded word after the s_setpc_b64 (it's only used for the address). If a title turns up that does, the fix is to write each case's table word into that register at the start of its target, for every dword table, as a separate change.

AI-assisted: yes

**@⁠overlordxrz-source** on GitHub · 2026-10-14 19:34 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1485#issuecomment-6176685592) @⁠coderabbitai This isn't new to the aliased case. On main, every resolved dword table load is skipped the same way (`IsCodeTableLoad` in Translate.cpp), so in the non-aliased shape the offset register is never written either and a target that read it would see whatever was there before. The patch only drops the `selector_code == offset_code` rejection; it doesn't change what the targets see. Neither the NHL 27 shader nor the existing tests read the loaded word after the `s_setpc_b64` (it's only used for the address). If a title turns up that does, the fix is to write each case's table word into that register at the start of its target, for every dword table, as a separate change. AI-assisted: yes
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-14 19:35 UTC · original

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
fd -t f '^(Translate\.cpp|ShaderCFG\.cpp|shaderCfgTests\.cpp)$'
fd -t f '^Translate\.cpp$' --exec ast-grep outline {} --match 'Translate|Emit|Block'
ast-grep outline src/graphics/shader/recompiler/frontend/cfg/ShaderCFG.cpp --match ResolveSetpcDwordJumpTable
ast-grep outline tests/shaderCfgTests.cpp --match 'TestNewShaderRecompilerSetpcDwordJumpTable'
rg -n -C 12 'IsCodeTableLoad' .
rg -n -C 22 'selector_code == offset_code|ScalarCodeWrittenInRange\(.*selector|load overwrites|selector_code =' src/graphics/shader/recompiler/frontend/cfg/ShaderCFG.cpp
rg -n -A 65 'void TestNewShaderRecompilerSetpcDwordJumpTableAliasedSelector\(' tests/shaderCfgTests.cpp
git diff origin/main...HEAD -- src/graphics/shader/recompiler/frontend/cfg/ShaderCFG.cpp

Length of output: 22062


@overlordxrz-source You’re right. Translate.cpp skips code-table loads without an alias-specific condition. The diff only removes the alias rejection and retains ScalarCodeWrittenInRange. The new test’s targets do not read the load destination.

The missing loaded-word value is an existing limitation, not an alias-specific regression. I withdraw this concern for #1485. Thanks for the clarification.

If a shader needs the loaded word after the jump, that needs a separate fix for all resolved dword tables. Would you like a follow-up issue for that limitation?


✏️ Learnings added
Learnt from: overlordxrz-source
URL: https://github.com/KytyPS5/KytyPS5/pull/1485

Timestamp: 2026-10-14T19:35:23.098Z
Learning: In KytyPS5/KytyPS5, src/graphics/shader/recompiler/frontend/translate/Translate.cpp skips resolved code-table loads through IsCodeTableLoad for both aliased and non-aliased dword jump tables. Consequently, preserving the loaded table word for target-block reads is an existing limitation, not a regression introduced by removing selector_code == offset_code in ResolveSetpcDwordJumpTable in src/graphics/shader/recompiler/frontend/cfg/ShaderCFG.cpp. The author reports that the NHL 27 shader and existing tests use the loaded word only for the jump address. If target blocks need that word, a separate change must materialize the appropriate table word in the load destination on each case path for all resolved dword tables.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-14 19:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1485#issuecomment-6176699619) <!-- This is an auto-generated reply by CodeRabbit --> > [!TIP] > For best results, initiate chat on the files or code changes. <details> <summary>🧩 Analysis chain</summary> 🏁 Script executed: ```shell #!/bin/bash fd -t f '^(Translate\.cpp|ShaderCFG\.cpp|shaderCfgTests\.cpp)$' fd -t f '^Translate\.cpp$' --exec ast-grep outline {} --match 'Translate|Emit|Block' ast-grep outline src/graphics/shader/recompiler/frontend/cfg/ShaderCFG.cpp --match ResolveSetpcDwordJumpTable ast-grep outline tests/shaderCfgTests.cpp --match 'TestNewShaderRecompilerSetpcDwordJumpTable' rg -n -C 12 'IsCodeTableLoad' . rg -n -C 22 'selector_code == offset_code|ScalarCodeWrittenInRange\(.*selector|load overwrites|selector_code =' src/graphics/shader/recompiler/frontend/cfg/ShaderCFG.cpp rg -n -A 65 'void TestNewShaderRecompilerSetpcDwordJumpTableAliasedSelector\(' tests/shaderCfgTests.cpp git diff origin/main...HEAD -- src/graphics/shader/recompiler/frontend/cfg/ShaderCFG.cpp ``` Length of output: 22062 --- </details> `@overlordxrz-source` You’re right. `Translate.cpp` skips code-table loads without an alias-specific condition. The diff only removes the alias rejection and retains `ScalarCodeWrittenInRange`. The new test’s targets do not read the load destination. The missing loaded-word value is an existing limitation, not an alias-specific regression. I withdraw this concern for `#1485`. Thanks for the clarification. If a shader needs the loaded word after the jump, that needs a separate fix for all resolved dword tables. Would you like a follow-up issue for that limitation? --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: overlordxrz-source URL: https://github.com/KytyPS5/KytyPS5/pull/1485 Timestamp: 2026-10-14T19:35:23.098Z Learning: In KytyPS5/KytyPS5, src/graphics/shader/recompiler/frontend/translate/Translate.cpp skips resolved code-table loads through IsCodeTableLoad for both aliased and non-aliased dword jump tables. Consequently, preserving the loaded table word for target-block reads is an existing limitation, not a regression introduced by removing selector_code == offset_code in ResolveSetpcDwordJumpTable in src/graphics/shader/recompiler/frontend/cfg/ShaderCFG.cpp. The author reports that the NHL 27 shader and existing tests use the loaded word only for the jump address. If target blocks need that word, a separate change must materialize the appropriate table word in the load destination on each case path for all resolved dword tables. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings). </details> _You are interacting with an AI system._

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.