SPU optimizer#18141
Draft
RipleyTom wants to merge 1 commit into
Draft
Conversation
b531aaa to
a88ca73
Compare
Megamouse
reviewed
Feb 2, 2026
| <property name="title"> | ||
| <string>Additional Settings</string> | ||
| </property> | ||
| <layout class="QVBoxLayout" name="checkboxes_layout"> |
Contributor
There was a problem hiding this comment.
Why change the name? Is it duplicated?
Megamouse
reviewed
Feb 2, 2026
| std::vector<u32> m_optimized_data; | ||
|
|
||
| public: | ||
| const std::vector<u32>& get_data() const noexcept { return m_data; } |
Contributor
There was a problem hiding this comment.
Why not just call this data() as well?
elad335
reviewed
Feb 3, 2026
| // Encoding: rt4 (bits 21-27) = dest, rb (bits 14-20) = src2, ra (bits 7-13) = src1, rc (bits 0-6) = variant | ||
| static constexpr u32 make_optimizer_opcode_2src(u32 variant, u32 src1, u32 src2, u32 dest) | ||
| { | ||
| return (0xa << 28) | ((dest & 0x7f) << 21) | ((src2 & 0x7f) << 14) | ((src1 & 0x7f) << 7) | (variant & 0x7f); |
Contributor
There was a problem hiding this comment.
spu_opcode_t fields allow to insert values as well.
| { | ||
| // Creates history | ||
| for (const auto& op : program.get_data()) | ||
| { |
Contributor
There was a problem hiding this comment.
Does it check if there are branches that interfere with the patterns? Like:
- Conditional Branch to 2st instruction.
- 1st instruction of pattern.
- 2nd instruction of pattern.
"Pattern matched" - but if the branch is taken, 1st instruction won't execute and the pattern would be incomplete.
It only appears so in first glance, because it iterates through all instructions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Aims to remove the most dubious optimization patterns from the SPULLVMRecompiler and treat them as a separate option(SPU Optimizer in CPU tab) and hopefully with better detection/behaviour.
This takes a spu_program and builds a history going through the instructions one by one, tracking what function result each register is currently tracking(the first 128 history_index values are the registers before the start of execution and can't be part of a pattern as they are out of scope). Then we built a referential history, increasing the ref_count of all the instructions whose results are used. The final instruction of the pattern is replaced by a RPCS3_OPTIMIZER pseudo instruction which has various variants depending on the patterns.
Finally we try to detect the pattern and if we do we eliminate all the instructions which results are no longer used in the current program(hence the ref_count earlier).