[llvm] [RISCV][TTI] Recognize CONCAT_VECTORS if a shufflevector mask is multiple insert subvector. (PR #111459)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 21:43:27 PDT 2024


================
@@ -343,6 +343,50 @@ RISCVTTIImpl::getConstantPoolLoadCost(Type *Ty,  TTI::TargetCostKind CostKind) {
                              /*AddressSpace=*/0, CostKind);
 }
 
+InstructionCost
+RISCVTTIImpl::isMultipleInsertSubvector(VectorType *Tp, ArrayRef<int> Mask,
+                                        TTI::TargetCostKind CostKind) {
+  if (!isa<FixedVectorType>(Tp))
+    return InstructionCost::getInvalid();
+  std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Tp);
+  if (LT.second.getScalarSizeInBits() == 1)
+    return InstructionCost::getInvalid();
+  unsigned Size = Mask.size();
+  if (!isPowerOf2_32(Size))
+    return InstructionCost::getInvalid();
+  // Try to guess subvector size.
+  unsigned SubVecSize;
+  for (unsigned I = 0; I != Size; ++I) {
+    if (static_cast<unsigned>(Mask[I]) == I)
+      continue;
+    if (Mask[I] == 0) {
+      SubVecSize = I;
+      break;
+    }
+    return InstructionCost::getInvalid();
+  }
+  for (unsigned I = 0; I != Size; ++I)
----------------
lukel97 wrote:

I think we now need to check SubVecSize is a power of 2

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


More information about the llvm-commits mailing list