[RISCV][TTI] Fix a misuse of the getShuffleCost API [NFC] (#129137)

The getShuffleCost api, in concept, expects to only deal with non-length
changing shuffles. We were failing to extend the mask appropriately
before invoking it. This came up in
https://github.com/llvm/llvm-project/pull/128537 in discussion of a
potential invariant, but is otherwise unrelated.
This commit is contained in:
Philip Reames 2025-02-27 18:53:49 -08:00 committed by GitHub
parent 1b622a43c4
commit 1bd13bceec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -482,7 +482,6 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
ArrayRef<const Value *> Args,
const Instruction *CxtI) {
Kind = improveShuffleKindFromMask(Kind, Mask, Tp, Index, SubTp);
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Tp);
// First, handle cases where having a fixed length vector enables us to
@ -890,11 +889,12 @@ InstructionCost RISCVTTIImpl::getInterleavedMemoryOpCost(
if (Opcode == Instruction::Load) {
InstructionCost Cost = MemCost;
for (unsigned Index : Indices) {
FixedVectorType *SubVecTy =
FixedVectorType *VecTy =
FixedVectorType::get(FVTy->getElementType(), VF * Factor);
auto Mask = createStrideMask(Index, Factor, VF);
Mask.resize(VF * Factor, -1);
InstructionCost ShuffleCost =
getShuffleCost(TTI::ShuffleKind::SK_PermuteSingleSrc, SubVecTy, Mask,
getShuffleCost(TTI::ShuffleKind::SK_PermuteSingleSrc, VecTy, Mask,
CostKind, 0, nullptr, {});
Cost += ShuffleCost;
}