[llvm] [RISCV][TTI] Add shuffle costing for masked slide lowering (PR #128537)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 24 11:46:07 PST 2025
================
@@ -474,6 +474,63 @@ costShuffleViaVRegSplitting(RISCVTTIImpl &TTI, MVT LegalVT,
return InstructionCost::getInvalid();
}
+InstructionCost RISCVTTIImpl::getSlideCost(FixedVectorType *Tp,
+ ArrayRef<int> Mask,
+ TTI::TargetCostKind CostKind) {
+ // Avoid missing masks
+ if (Mask.size() <= 2)
+ return InstructionCost::getInvalid();
+
+ int NumElts = Tp->getNumElements();
+ std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Tp);
+ // Avoid scalarization cases
+ if (!LT.second.isFixedLengthVector())
+ return InstructionCost::getInvalid();
+
+ // Requires moving elements between parts, which requires additional
+ // unmodeled instructions.
+ if (LT.first != 1)
+ return InstructionCost::getInvalid();
+
+ auto getSlideOpcode = [&](int SlideAmt) {
+ assert(SlideAmt != 0);
+ if (SlideAmt < 0)
+ return SlideAmt > -32 ? RISCV::VSLIDEDOWN_VI : RISCV::VSLIDEDOWN_VX;
+ return SlideAmt < 32 ? RISCV::VSLIDEUP_VI : RISCV::VSLIDEUP_VX;
----------------
alexey-bataev wrote:
Do not use magic numbers, use named constants instead
https://github.com/llvm/llvm-project/pull/128537
More information about the llvm-commits
mailing list