shader: drop the duplicate-use scan from Inst::AddUse #1679
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1679
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1679/head"
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?
@Nawid3333 on GitHub · 2026-10-19 00:39 UTC · original
Nawid3333:shader/adduse-no-duplicate-scan→main· +0 −3 · 1 files · 1 commits · closed without mergingInst::AddUsescanned the used instruction's whole use list on every call, only toEXIT_IFon a duplicate(user, operand)entry.KYTY_FINAL, which turnsEXIT_IFoff, is never defined, so every build pays this scan. Each call scans the list built so far, so a value that ends up with U uses costs about U²/2 scanned entries; counted with an instrumented build, one compilation pass over the 692 harness shaders makes 1.30 MAddUsecalls that scan 220 M use entries.A duplicate cannot happen. Each
usesentry(u, i)exists only while slotiofuholds that value:SetArgremoves the entry of the slot's old value (if it is an instruction) before it adds the new one.AddPhiOperandadds the new indexphi_args.size(), andphi_argsnever shrinks beforeClearArgs, which first removes all of the instruction's uses.SetArgandAddPhiOperand, the argument storage (fixed_args,large_args,phi_args) is written only by the constructor (no arguments yet) and byClearArgs, which first removes the use of every argument; no other file refers to these members.useschanges only inAddUseandRemoveUse, andnum_argsis set only inClearArgsandReplaceUsesWith.ReplaceUsesWith(..., preserve)callsInvalidate(), which callsClearArgs()and removes every use this instruction holds, before it setsnum_argsand callsSetArg(0, ...).Instcannot be copied or moved, and a newInststarts with no arguments and no uses.Measurements
Windows, AMD Ryzen 5 7600X, RX 9070 XT, Release. One timing build with an environment switch that selects the old or the new
AddUse; two alternating rounds, each value the mean of 3 repetitions of a pass over the 692 compute harness shaders:TranslateProgramms/passCompileProgramms/passThat is about 0.09 ms less translation per shader on average on the harness; it was not measured in a game. Games compile shaders while they run: a tester's Demon's Souls run (#821, report #1660) showed
Shaders: VS 199 | PS 325 | CS 799.Tests
No test can be written that fails without this change: it removes a check that never fires and leaves the output byte-identical, so the evidence is the argument above and the timing. Same machine:
shader_cfgandresource_trackingpass,shader_recompiler_compute_tests --wave64-onlypasses, and the full run gives the same result as main here (59 cases ok, then it stops atIndirectBufferStore, as main does on this GPU).If you want the invariant still checked, I can add a test-side verifier that walks all instructions after compiling the harness shaders and requires unique
(user, operand)entries. Or feel free to close this and say what you would prefer.AI use
I used Claude Code (AI agent) to profile the recompiler, find this cost, write the change and run the checks; I reviewed the diff and the results.
@coderabbitai[bot] on GitHub · 2026-10-19 00:41 UTC · original
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
0791aa45-e488-406e-a96a-9abcf3881580📥 Commits
Reviewing files that changed from the base of the PR and between
099de8dea6and8d9c9c832a.📒 Files selected for processing: 1
src/graphics/shader/recompiler/ir/Value.cpp💤 Files with no reviewable changes: 1
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
📝 Walkthrough
Inst::AddUseno longer checks for a matching user and operand in the use list or exits when it finds one. It now appends the use directly.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Refactor
Merge Risk: ⚪ Minimal · up to
8d9c9No actionable issue remains with the use-list change; it is ready to merge after normal checks.
Pre-merge checks:
5
Full details: Docstring Coverage
Explanation
No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files.
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 helpto get the list of available commands.@Nawid3333 on GitHub · 2026-10-27 16:22 UTC · original
Closing:
mainhas this since7eb8abb2("shader: drop the duplicate-use scan from Inst::AddUse"), which removes the same scan.Pull request closed