Repository navigation
[SPU LLVM] Refactor SELB to improve readability - #19002
Merged
Merged
Conversation
Refactors SELB by changing "division accuracy correction" pattern match to reduce nesting, include more comments, and use more descriptive variable names. Also replaced duplicated granularity-check loops with single loop which determines byte granularity as a integer.
arshkumarsingh
approved these changes
Jul 7, 2026
arshkumarsingh
left a comment
Contributor
There was a problem hiding this comment.
tested with LLVM 19.1.7: the new 8-bit select path generates the same asm as the old 16-bit path for word masks (pblendw/vpblendw), so yeah this looks fine
elad335
self-requested a review
July 7, 2026 16:51
elad335
enabled auto-merge (rebase)
July 10, 2026 16:12
elad335
approved these changes
Jul 10, 2026
elad335
reviewed
Jul 10, 2026
| set_vr(op.rt4, select(noncast<s32[4]>(c) != 0, get_vr<f32[4]>(op.rb), get_vr<f32[4]>(op.ra))); | ||
| return; | ||
| // Fraction of 16 check | ||
| byte_granularity = (16 % equals_run) ? 1 : std::min(byte_granularity, equals_run); |
Contributor
There was a problem hiding this comment.
Nice simple algorithm, I believe SHUFB masks analysis can also be simplified using this method.
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.
The current
SELBimplementation is difficult to understand due to its "division accuracy correction" pattern match being implemented using nested if statements for every match element. This patch replaces it with a equivalent version that reduces nesting, adds more clarifying comments, and uses more descriptive variable names.Also, replaced the duplicated granularity check loops with single loop which determines its byte granularity as an integer. I removed the integer width specific selects with a single 8-bit select as LLVM should be able to widen when needed (as the condition is a constant).