[llvm] [RISCV] Add cost modeling for Zvzip 0.3 (PR #224991)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 20 20:52:23 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: renndong
<details>
<summary>Changes</summary>
Teach the RISC-V TTI to recognize interleave, deinterleave, and pair-even/pair-odd shuffles that can be implemented with vzip.vv, vunzipe[o].v, or vpaire[o].v. Also add target-specific costs for llvm.vector.interleave2 and llvm.vector.deinterleave2 intrinsics.
Move the pair-even and pair-odd shuffle mask matchers to VectorUtils so they can be shared by instruction selection and the cost model, and use them to model vpaire.vv and vpairo.vv.
Assisted-By: Trae CLI (GPT-5)
---
Patch is 46.64 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/224991.diff
6 Files Affected:
- (modified) llvm/include/llvm/Analysis/VectorUtils.h (+20)
- (modified) llvm/lib/Analysis/VectorUtils.cpp (+41)
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+2-50)
- (modified) llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp (+222)
- (modified) llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h (+6)
- (added) llvm/test/Analysis/CostModel/RISCV/shuffle-zvzip.ll (+497)
``````````diff
diff --git a/llvm/include/llvm/Analysis/VectorUtils.h b/llvm/include/llvm/Analysis/VectorUtils.h
index b177d9eec2189..edd15000def14 100644
--- a/llvm/include/llvm/Analysis/VectorUtils.h
+++ b/llvm/include/llvm/Analysis/VectorUtils.h
@@ -229,6 +229,26 @@ LLVM_ABI bool getShuffleDemandedElts(int SrcWidth, ArrayRef<int> Mask,
LLVM_ABI bool isMaskedSlidePair(ArrayRef<int> Mask, int NumElts,
std::array<std::pair<int, int>, 2> &SrcInfo);
+/// Given a shuffle which can be represented as a pair of two slides, return
+/// true if it is a pair-even idiom and set \p Factor to its pairing factor.
+/// The mappings in \p SrcInfo may be in either order.
+/// Pair-even is:
+/// Input 0: a0 a1 a2 a3
+/// Input 1: b0 b1 b2 b3
+/// Result: a0 b0 a2 b2
+LLVM_ABI bool isPairEvenShuffleMask(std::array<std::pair<int, int>, 2> SrcInfo,
+ ArrayRef<int> Mask, unsigned &Factor);
+
+/// Given a shuffle which can be represented as a pair of two slides, return
+/// true if it is a pair-odd idiom and set \p Factor to its pairing factor.
+/// The mappings in \p SrcInfo may be in either order.
+/// Pair-odd is:
+/// Input 0: a0 a1 a2 a3
+/// Input 1: b0 b1 b2 b3
+/// Result: a1 b1 a3 b3
+LLVM_ABI bool isPairOddShuffleMask(std::array<std::pair<int, int>, 2> SrcInfo,
+ ArrayRef<int> Mask, unsigned &Factor);
+
/// Replace each shuffle mask index with the scaled sequential indices for an
/// equivalent mask of narrowed elements. Mask elements that are less than 0
/// (sentinel values) are repeated in the output mask.
diff --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp
index 1c105ebb772b3..f5a2f1ae6fe1c 100644
--- a/llvm/lib/Analysis/VectorUtils.cpp
+++ b/llvm/lib/Analysis/VectorUtils.cpp
@@ -513,6 +513,47 @@ bool llvm::isMaskedSlidePair(ArrayRef<int> Mask, int NumElts,
return SrcInfo[0].first != -1;
}
+static bool
+isAlternatingShuffleMask(const std::array<std::pair<int, int>, 2> &SrcInfo,
+ ArrayRef<int> Mask, unsigned Factor,
+ bool RequiredPolarity) {
+ int NumElts = Mask.size();
+ for (const auto &[Idx, M] : enumerate(Mask)) {
+ if (M < 0)
+ continue;
+ int Src = M >= NumElts;
+ int Diff = static_cast<int>(Idx) - (M % NumElts);
+ bool C = Src == SrcInfo[1].first && Diff == SrcInfo[1].second;
+ assert(C != (Src == SrcInfo[0].first && Diff == SrcInfo[0].second) &&
+ "Must match exactly one of the two slides");
+ if (RequiredPolarity != (C == (Idx / Factor) % 2))
+ return false;
+ }
+ return true;
+}
+
+bool llvm::isPairEvenShuffleMask(std::array<std::pair<int, int>, 2> SrcInfo,
+ ArrayRef<int> Mask, unsigned &Factor) {
+ if (SrcInfo[1].second == 0)
+ std::swap(SrcInfo[0], SrcInfo[1]);
+
+ Factor = SrcInfo[1].second;
+ return SrcInfo[0].second == 0 && isPowerOf2_32(Factor) &&
+ Mask.size() % Factor == 0 &&
+ isAlternatingShuffleMask(SrcInfo, Mask, Factor, true);
+}
+
+bool llvm::isPairOddShuffleMask(std::array<std::pair<int, int>, 2> SrcInfo,
+ ArrayRef<int> Mask, unsigned &Factor) {
+ if (SrcInfo[1].second == 0)
+ std::swap(SrcInfo[0], SrcInfo[1]);
+
+ Factor = -SrcInfo[1].second;
+ return SrcInfo[0].second == 0 && isPowerOf2_32(Factor) &&
+ Mask.size() % Factor == 0 &&
+ isAlternatingShuffleMask(SrcInfo, Mask, Factor, false);
+}
+
void llvm::narrowShuffleMaskElts(int Scale, ArrayRef<int> Mask,
SmallVectorImpl<int> &ScaledMask) {
assert(Scale > 0 && "Unexpected scaling factor");
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 2c05e3000c5eb..5b7a93052d65c 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -5490,54 +5490,6 @@ static bool isElementRotate(const std::array<std::pair<int, int>, 2> &SrcInfo,
SrcInfo[1].second - SrcInfo[0].second == (int)NumElts;
}
-static bool isAlternating(const std::array<std::pair<int, int>, 2> &SrcInfo,
- ArrayRef<int> Mask, unsigned Factor,
- bool RequiredPolarity) {
- int NumElts = Mask.size();
- for (const auto &[Idx, M] : enumerate(Mask)) {
- if (M < 0)
- continue;
- int Src = M >= NumElts;
- int Diff = (int)Idx - (M % NumElts);
- bool C = Src == SrcInfo[1].first && Diff == SrcInfo[1].second;
- assert(C != (Src == SrcInfo[0].first && Diff == SrcInfo[0].second) &&
- "Must match exactly one of the two slides");
- if (RequiredPolarity != (C == (Idx / Factor) % 2))
- return false;
- }
- return true;
-}
-
-/// Given a shuffle which can be represented as a pair of two slides,
-/// see if it is a pair-even idiom.
-/// Pair-even is:
-/// vs2: a0 a1 a2 a3
-/// vs1: b0 b1 b2 b3
-/// vd: a0 b0 a2 b2
-static bool isPairEven(const std::array<std::pair<int, int>, 2> &SrcInfo,
- ArrayRef<int> Mask, unsigned &Factor) {
- Factor = SrcInfo[1].second;
- return SrcInfo[0].second == 0 && isPowerOf2_32(Factor) &&
- Mask.size() % Factor == 0 &&
- isAlternating(SrcInfo, Mask, Factor, true);
-}
-
-/// Given a shuffle which can be represented as a pair of two slides,
-/// see if it is a pair-odd idiom.
-/// Pair-odd is:
-/// vs2: a0 a1 a2 a3
-/// vs1: b0 b1 b2 b3
-/// vd: a1 b1 a3 b3
-/// Note that the operand order is swapped due to the way we canonicalize
-/// the slides, so SrCInfo[0] is vs1, and SrcInfo[1] is vs2.
-static bool isPairOdd(const std::array<std::pair<int, int>, 2> &SrcInfo,
- ArrayRef<int> Mask, unsigned &Factor) {
- Factor = -SrcInfo[1].second;
- return SrcInfo[0].second == 0 && isPowerOf2_32(Factor) &&
- Mask.size() % Factor == 0 &&
- isAlternating(SrcInfo, Mask, Factor, false);
-}
-
// Lower a deinterleave shuffle to SRL and TRUNC. Factor must be
// 2, 4, 8 and the integer type Factor-times larger than VT's
// element type must be a legal element type.
@@ -7039,7 +6991,7 @@ SDValue RISCVTargetLowering::lowerVECTOR_SHUFFLE(SDValue Op,
if (Subtarget.hasStdExtZvzip()) {
bool TryWiden = false;
unsigned Factor;
- if (isPairEven(SrcInfo, Mask, Factor)) {
+ if (isPairEvenShuffleMask(SrcInfo, Mask, Factor)) {
if (Factor == 1) {
SDValue Src1 = SrcInfo[0].first == 0 ? V1 : V2;
SDValue Src2 = SrcInfo[1].first == 0 ? V1 : V2;
@@ -7048,7 +7000,7 @@ SDValue RISCVTargetLowering::lowerVECTOR_SHUFFLE(SDValue Op,
}
TryWiden = true;
}
- if (isPairOdd(SrcInfo, Mask, Factor)) {
+ if (isPairOddShuffleMask(SrcInfo, Mask, Factor)) {
if (Factor == 1) {
SDValue Src1 = SrcInfo[1].first == 0 ? V1 : V2;
SDValue Src2 = SrcInfo[0].first == 0 ? V1 : V2;
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 43b4791998d39..0bcff20e4f84b 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -708,6 +708,14 @@ InstructionCost RISCVTTIImpl::getSlideCost(FixedVectorType *Tp,
if (SrcInfo[1].second == 0)
std::swap(SrcInfo[0], SrcInfo[1]);
+ if (ST->hasStdExtZvzip() && LT.second.getScalarSizeInBits() != 1) {
+ unsigned Factor;
+ if (isPairEvenShuffleMask(SrcInfo, Mask, Factor) && Factor == 1)
+ return getRISCVInstructionCost(RISCV::VPAIRE_VV, LT.second, CostKind);
+ if (isPairOddShuffleMask(SrcInfo, Mask, Factor) && Factor == 1)
+ return getRISCVInstructionCost(RISCV::VPAIRO_VV, LT.second, CostKind);
+ }
+
InstructionCost FirstSlideCost = 0;
if (SrcInfo[0].second != 0) {
unsigned Opcode = GetSlideOpcode(SrcInfo[0].second);
@@ -733,6 +741,149 @@ InstructionCost RISCVTTIImpl::getSlideCost(FixedVectorType *Tp,
return FirstSlideCost + SecondSlideCost + MaskCost;
}
+/// Return the type used to cost vzip.vv, whose LMUL represents the
+/// interleaved destination EMUL. Return std::nullopt if illegal.
+static std::optional<MVT> getZvzipVZIPCostVT(MVT InterleavedVT,
+ const RISCVSubtarget &ST,
+ const RISCVTargetLowering &TLI) {
+ if (!InterleavedVT.getVectorElementCount().isKnownEven())
+ return std::nullopt;
+
+ MVT CostVT = InterleavedVT;
+ if (InterleavedVT.isFixedLengthVector()) {
+ MVT SourceVT = InterleavedVT.getHalfNumVectorElementsVT();
+ CostVT = TLI.getContainerForFixedLengthVector(SourceVT)
+ .getDoubleNumVectorElementsVT();
+ }
+
+ unsigned EltBits = CostVT.getScalarSizeInBits();
+ unsigned MinSize = CostVT.getSizeInBits().getKnownMinValue();
+ unsigned LMULOctuple = MinSize / (RISCV::RVVBitsPerBlock / 8);
+ // Perform the 2 * SEW <= LMUL * min(ELEN, VLEN) check.
+ if (EltBits * 16 > LMULOctuple * std::min(ST.getELen(), ST.getRealMinVLen()))
+ return std::nullopt;
+ return CostVT;
+}
+
+/// Return the type used to cost vunzipe.v/vunzipo.v, whose LMUL represents
+/// the interleaved source EMUL. Return std::nullopt if illegal.
+static std::optional<MVT> getZvzipVUNZIPCostVT(MVT InterleavedVT,
+ const RISCVTargetLowering &TLI) {
+ if (!InterleavedVT.getVectorElementCount().isKnownEven())
+ return std::nullopt;
+
+ MVT CostVT = InterleavedVT;
+ // lowerZvzipVUNZIP widens the source container if halving it would produce
+ // an illegal result type. Apply the same rule here so the cost uses the
+ // source LMUL selected by ISel.
+ if (InterleavedVT.isFixedLengthVector()) {
+ CostVT = TLI.getContainerForFixedLengthVector(InterleavedVT);
+ if (CostVT.getVectorMinNumElements() == 1 ||
+ !TLI.isTypeLegal(CostVT.getHalfNumVectorElementsVT()))
+ CostVT = CostVT.getDoubleNumVectorElementsVT();
+ }
+
+ MVT DeinterleavedVT = CostVT.getHalfNumVectorElementsVT();
+ if (RISCVTargetLowering::getLMUL(DeinterleavedVT) == RISCVVType::LMUL_8)
+ return std::nullopt;
+ return CostVT;
+}
+
+InstructionCost RISCVTTIImpl::getVZIPCost(TTI::ShuffleKind Kind,
+ VectorType *DstTy, VectorType *SrcTy,
+ ArrayRef<int> Mask,
+ TTI::TargetCostKind CostKind) const {
+ if (!ST->hasStdExtZvzip() || Mask.size() < 2 ||
+ DstTy->getScalarSizeInBits() == 1)
+ return InstructionCost::getInvalid();
+
+ unsigned NumSrcElts = SrcTy->getElementCount().getKnownMinValue();
+ unsigned NumDstElts = DstTy->getElementCount().getKnownMinValue();
+ unsigned NumInputElts;
+
+ if (Kind == TTI::SK_PermuteSingleSrc) {
+ // A single-source vzip shuffle interleaves two halves of the same vector,
+ // so its source and destination must have the same number of elements.
+ if (NumSrcElts != NumDstElts)
+ return InstructionCost::getInvalid();
+ NumInputElts = NumSrcElts;
+ } else if (Kind == TTI::SK_PermuteTwoSrc) {
+ // Accept both forms that can be lowered with vzip.vv:
+ //
+ // 1. The destination has twice as many elements as each source, e.g.
+ // %r = shufflevector <4 x i32> %a, <4 x i32> %b,
+ // <8 x i32> <0, 4, 1, 5, 2, 6, 3, 7>
+ // The two operands are already the half-sized inputs of vzip.vv.
+ //
+ // 2. Each source has the same number of elements as the destination, e.g.
+ // %r = shufflevector <4 x i32> %a, <4 x i32> %b,
+ // <4 x i32> <0, 4, 1, 5>
+ // ISel first extracts a <2 x i32> half from each source and then uses
+ // those halves as the inputs of vzip.vv.
+ if (NumSrcElts != NumDstElts && NumSrcElts * 2 != NumDstElts)
+ return InstructionCost::getInvalid();
+ NumInputElts = NumSrcElts * 2;
+ } else {
+ return InstructionCost::getInvalid();
+ }
+
+ // ISel deliberately excludes the two-element single-source identity case.
+ if (Kind == TTI::SK_PermuteSingleSrc && Mask.size() == 2 &&
+ ShuffleVectorInst::isSingleSourceMask(Mask, Mask.size()))
+ return InstructionCost::getInvalid();
+
+ // A deinterleave shuffle for an interleaved load may have a mask such as
+ // %even = shufflevector <4 x i32> %wide, <4 x i32> poison,
+ // <4 x i32> <i32 0, i32 2, i32 poison, i32 poison>
+ // Because isInterleaveMask ignores poison lanes, this mask may also satisfy
+ // the interleave matcher. Do not cost it as vzip.vv.
+ unsigned DeinterleaveIndex;
+ if (ShuffleVectorInst::isDeInterleaveMaskOfFactor(Mask, 2,
+ DeinterleaveIndex) &&
+ count_if(Mask, [](int Idx) { return Idx >= 0; }) > 1)
+ return InstructionCost::getInvalid();
+
+ // Require the two start indices found in the mask to be aligned to
+ // half-vector boundaries, with at least one equal to zero.
+ SmallVector<unsigned, 2> StartIndexes;
+ if (!ShuffleVectorInst::isInterleaveMask(Mask, 2, NumInputElts, StartIndexes))
+ return InstructionCost::getInvalid();
+
+ unsigned HalfNumElts = Mask.size() / 2;
+ if ((StartIndexes[0] != 0 && StartIndexes[1] != 0) ||
+ StartIndexes[0] % HalfNumElts != 0 || StartIndexes[1] % HalfNumElts != 0)
+ return InstructionCost::getInvalid();
+
+ std::pair<InstructionCost, MVT> DstLT = getTypeLegalizationCost(DstTy);
+ if (!DstLT.second.isFixedLengthVector())
+ return InstructionCost::getInvalid();
+
+ std::optional<MVT> CostVT = getZvzipVZIPCostVT(DstLT.second, *ST, *TLI);
+ if (!CostVT)
+ return InstructionCost::getInvalid();
+
+ InstructionCost Cost =
+ DstLT.first * getRISCVInstructionCost(RISCV::VZIP_VV, *CostVT, CostKind);
+
+ // For a shuffle such as
+ // %r = shufflevector <4 x i32> %v, <4 x i32> poison,
+ // <4 x i32> <i32 0, i32 2, i32 1, i32 3>
+ // vzip.vv needs two <2 x i32> inputs. Include the cost of extracting each
+ // upper half; extracting a low half is free.
+ if (NumSrcElts == NumDstElts) {
+ auto *HalfSrcTy = FixedVectorType::getHalfElementsVectorType(
+ cast<FixedVectorType>(SrcTy));
+ for (unsigned Start : StartIndexes) {
+ unsigned ExtractIndex = Start % NumSrcElts;
+ if (ExtractIndex != 0)
+ Cost += getShuffleCost(TTI::SK_ExtractSubvector, HalfSrcTy, SrcTy,
+ CostKind, {}, ExtractIndex, HalfSrcTy);
+ }
+ }
+
+ return Cost;
+}
+
InstructionCost
RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy,
VectorType *SrcTy, TTI::TargetCostKind CostKind,
@@ -771,6 +922,14 @@ RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy,
case TTI::SK_PermuteSingleSrc: {
if (Mask.size() >= 2) {
MVT EltTp = LT.second.getVectorElementType();
+
+ // Try the vzip.vv cost first, otherwise use the widening-interleave
+ // cost below.
+ if (InstructionCost VZipCost =
+ getVZIPCost(Kind, DstTy, SrcTy, Mask, CostKind);
+ VZipCost.isValid())
+ return VZipCost;
+
// If the size of the element is < ELEN then shuffles of interleaves and
// deinterleaves of 2 vectors can be lowered into the following
// sequences
@@ -792,6 +951,16 @@ RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy,
LT.second, CostKind);
}
}
+
+ unsigned Index;
+ if (ST->hasStdExtZvzip() && EltTp.getScalarSizeInBits() != 1 &&
+ ShuffleVectorInst::isDeInterleaveMaskOfFactor(Mask, 2, Index)) {
+ unsigned Opcode = Index == 0 ? RISCV::VUNZIPE_V : RISCV::VUNZIPO_V;
+ if (auto CostVT = getZvzipVUNZIPCostVT(LT.second, *TLI))
+ return LT.first *
+ getRISCVInstructionCost(Opcode, *CostVT, CostKind);
+ }
+
int SubVectorSize;
if (LT.second.getScalarSizeInBits() != 1 &&
isRepeatedConcatMask(Mask, SubVectorSize)) {
@@ -840,6 +1009,10 @@ RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy,
SlideCost.isValid())
return SlideCost;
+ if (InstructionCost VZipCost =
+ getVZIPCost(Kind, DstTy, SrcTy, Mask, CostKind);
+ VZipCost.isValid())
+ return VZipCost;
// 2 x (vrgather + cost of generating the mask constant) + cost of mask
// register for the second vrgather. We model this for an unknown
// (shuffle) mask.
@@ -1897,6 +2070,55 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
ValLT.second, CostKind);
return Cost;
}
+ case Intrinsic::vector_interleave2:
+ case Intrinsic::vector_deinterleave2: {
+ if (!ST->hasStdExtZvzip())
+ break;
+
+ bool IsInterleave = ICA.getID() == Intrinsic::vector_interleave2;
+ Type *InterleavedTy = IsInterleave ? RetTy : ICA.getArgTypes().front();
+ // ISel does not select vzip.vv if either interleave2 input is undef.
+ if (IsInterleave && !ICA.isTypeBasedOnly() &&
+ any_of(ICA.getArgs(),
+ [](const Value *Arg) { return isa<UndefValue>(Arg); }))
+ break;
+ if (InterleavedTy->getScalarSizeInBits() == 1)
+ break;
+
+ if (FixedVectorType *FVT = dyn_cast<FixedVectorType>(InterleavedTy)) {
+ if (IsInterleave) {
+ unsigned VF = FVT->getNumElements() / 2;
+ FixedVectorType *HalfFVT =
+ FixedVectorType::getHalfElementsVectorType(FVT);
+ return getShuffleCost(TTI::SK_PermuteTwoSrc, FVT, HalfFVT, CostKind,
+ createInterleaveMask(VF, 2), 0, nullptr);
+ }
+
+ FixedVectorType *HalfFVT =
+ FixedVectorType::getHalfElementsVectorType(FVT);
+ unsigned VF = HalfFVT->getNumElements();
+ InstructionCost Cost = 0;
+ for (unsigned Start = 0; Start != 2; ++Start)
+ Cost += getShuffleCost(TTI::SK_PermuteSingleSrc, HalfFVT, FVT, CostKind,
+ createStrideMask(Start, 2, VF), 0, nullptr);
+ return Cost;
+ }
+
+ std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(InterleavedTy);
+ if (!LT.second.isScalableVector())
+ break;
+ if (IsInterleave) {
+ if (std::optional<MVT> CostVT = getZvzipVZIPCostVT(LT.second, *ST, *TLI))
+ return LT.first *
+ getRISCVInstructionCost(RISCV::VZIP_VV, *CostVT, CostKind);
+ } else if (std::optional<MVT> CostVT =
+ getZvzipVUNZIPCostVT(LT.second, *TLI)) {
+ return LT.first *
+ getRISCVInstructionCost({RISCV::VUNZIPE_V, RISCV::VUNZIPO_V},
+ *CostVT, CostKind);
+ }
+ break;
+ }
}
if (ST->hasVInstructions() && RetTy->isVectorTy()) {
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
index 4523ebd6ae892..5f5306fc2afbf 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
@@ -72,6 +72,12 @@ class RISCVTTIImpl final : public BasicTTIImplBase<RISCVTTIImpl> {
InstructionCost getSlideCost(FixedVectorType *Tp, ArrayRef<int> Mask,
TTI::TargetCostKind CostKind) const;
+ /// If a fixed-length shuffle can be lowered to a vzip.vv instruction,
+ /// return its cost.
+ InstructionCost getVZIPCost(TTI::ShuffleKind Kind, VectorType *DstTy,
+ VectorType *SrcTy, ArrayRef<int> Mask,
+ TTI::TargetCostKind CostKind) const;
+
public:
explicit RISCVTTIImpl(const RISCVTargetMachine *TM, const Function &F)
: BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),
diff --git a/llvm/test/Analysis/CostModel/RISCV/shuffle-zvzip.ll b/llvm/test/Analysis/CostModel/RISCV/shuffle-zvzip.ll
new file mode 100644
index 0000000000000..705fa0be3161d
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/RISCV/shuffle-zvzip.ll
@@ -0,0 +1,497 @@
+; RUN: opt < %s -passes="print<cost-model>" -cost-kind=throughput 2>&1 -disable-output -mtriple=riscv64 -mattr=+v,+zvfh,+experimental-zvzip | FileCheck %s --check-prefix=ZVZIP
+; RUN: opt < %s -passes="print<cost-model>" -cost-kind=throughput 2>&1 -dis...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/224991
More information about the llvm-commits
mailing list