-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[TTI][RISCV]Improve costs for whole vector reg extract/insert. #80164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
alexey-bataev
wants to merge
14
commits into
main
from
users/alexey-bataev/spr/ttiriscvimprove-costs-for-fixed-vector-whole-reg-extractinsert
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cfd0dcf
[𝘀𝗽𝗿] initial version
alexey-bataev 1689f41
Rebase, address comments
alexey-bataev e909200
Address comments
alexey-bataev 2dd7afa
Rebase
alexey-bataev 382d5b3
Rebase, Address comments
alexey-bataev de3be41
Rebase, Address comments
alexey-bataev 51da92f
Rebase, add scalable vectors
alexey-bataev 0ac7359
Rebase, address comments
alexey-bataev 7afc02a
Rebase, address comments
alexey-bataev 93c0d1c
Rebase, address comments
alexey-bataev f17263c
Rebase, address comments
alexey-bataev 07713b8
Rebase
alexey-bataev 4647802
Rebase
alexey-bataev a0d744b
Rebase, Address comments
alexey-bataev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -457,12 +457,28 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind, | |
// vslidedown.vi v8, v9, 2 | ||
return LT.first * | ||
getRISCVInstructionCost(RISCV::VSLIDEDOWN_VI, LT.second, CostKind); | ||
case TTI::SK_InsertSubvector: | ||
case TTI::SK_InsertSubvector: { | ||
if (Index == 0 && !Args.empty() && any_of(Args, UndefValue::classof)) | ||
return TTI::TCC_Free; | ||
const unsigned MinVLen = ST->getRealMinVLen(); | ||
const unsigned MaxVLen = ST->getRealMaxVLen(); | ||
Comment on lines
+463
to
+464
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use |
||
// Whole vector insert - just the vector itself. | ||
if (auto *FSubTy = dyn_cast<FixedVectorType>(SubTp); | ||
FSubTy && Index == 0 && MinVLen == MaxVLen) { | ||
unsigned TpRegs = getRegUsageForType(Tp); | ||
unsigned SubTpRegs = getRegUsageForType(SubTp); | ||
unsigned NextSubTpRegs = getRegUsageForType(FixedVectorType::get( | ||
Tp->getElementType(), FSubTy->getNumElements() + 1)); | ||
if (SubTpRegs != 0 && SubTpRegs != NextSubTpRegs && TpRegs >= SubTpRegs) | ||
Comment on lines
+468
to
+472
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible for |
||
return TTI::TCC_Free; | ||
} | ||
|
||
// Example sequence: | ||
// vsetivli zero, 4, e8, mf2, tu, ma (ignored) | ||
// vslideup.vi v8, v9, 2 | ||
return LT.first * | ||
getRISCVInstructionCost(RISCV::VSLIDEUP_VI, LT.second, CostKind); | ||
} | ||
case TTI::SK_Select: { | ||
// Example sequence: | ||
// li a0, 90 | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to split off this piece - or more accurately something vaguely related - and stumbled into something interesting.
The InsertSubvector w/Index=0 is unreachable from everywhere except SLP. TTI::getInstructionCost contains a check for the identity shuffle and always returns 0. improveShuffleKindFromMask will recognize the insert into passthru case as a select (correctly), and thus it doesn't hit this case either. Put together, this means that the index=0 case never makes it from the backend, and thus we have no test coverage via cost model tests.
SLP hits a slightly different codepath here and directly calls getShuffleCost with a possible identity mask. It still can't hit the select case, but it can hit the insert into poison case. SLP appears to have a bunch of guards for this already in various cases.
I'm not really a fan of having untestable logic here. Anyone have any ideas how we can rework this API to ensure SLP can't reach a case which is untestable via costmodel tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not tests for llvm.vector.insert intrinsics check this?