[llvm] [RISCV] Model interleave2 and deinterleave2 costs with Zvzip (PR #225752)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 28 22:12:36 PDT 2026


================
@@ -733,6 +733,48 @@ InstructionCost RISCVTTIImpl::getSlideCost(FixedVectorType *Tp,
   return FirstSlideCost + SecondSlideCost + MaskCost;
 }
 
+std::optional<MVT> RISCVTTIImpl::getZvzipVZIPCostVT(MVT InterleavedVT) const {
+  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;
+}
+
+std::optional<MVT> RISCVTTIImpl::getZvzipVUNZIPCostVT(MVT InterleavedVT) const {
+  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();
+  }
----------------
renndong wrote:

Yes, this code is indeed dead. I missed the internal logic and only pick the function when splitting PR #224991. I had planned to call this function from `getShuffleCost` for fixed-length vectors, but for now it is unused.

> Is there a reason that we are not computing a Zvzip cost for fixed-length vectors?

No, we should compute the Zvzip cost for fixed-length vectors. But this PR does not implement it, and I would like to implement it in a follow-up PR to make the review easier.

> I think it would be best to remove this code and add an assertion requiring a scalable vector instead.

Agreed. I have replaced the dead code with the assertion in a new commit.

https://github.com/llvm/llvm-project/pull/225752


More information about the llvm-commits mailing list