[llvm] [RISCV][TTI] Cost a subvector extract at a register boundary with exact vlen (PR #82405)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 20 20:14:02 PST 2024
================
@@ -436,6 +436,22 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
if (Index == 0)
return TTI::TCC_Free;
+ // If we're extracting a subvector of at most m1 size at a sub-register
+ // boundary - which unfortunately we need exact vlen to identity - this is
+ // a subregister extract at worst and thus won't require a vslidedown.
+ // TODO: Extend for aligned m2, m4 subvector extracts
+ // TODO: Extend for misalgined (but contained) extracts
+ // TODO: Extend for scalable subvector types
+ if (std::pair<InstructionCost, MVT> SubLT = getTypeLegalizationCost(SubTp);
+ SubLT.second.isValid() && SubLT.second.isFixedLengthVector()) {
+ const unsigned MinVLen = ST->getRealMinVLen();
+ const unsigned MaxVLen = ST->getRealMaxVLen();
+ if (MinVLen == MaxVLen &&
+ SubLT.second.getScalarSizeInBits() * Index % MinVLen == 0 &&
+ SubLT.second.getSizeInBits() <= MinVLen)
----------------
lukel97 wrote:
For extending it to m2+, checking that the extract is LMUL aligned is the same as checking that the index is a multiple of the number of elements, so you could do something like:
```suggestion
SubLT.second.getVectorNumElements() % Index == 0)
```
https://github.com/llvm/llvm-project/pull/82405
More information about the llvm-commits
mailing list