[llvm] [RISCV][TTI] Model the cost of insert/extractelt when the vector split into multiple register group and idx exceed single group. (PR #118401)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 10 09:10:42 PST 2024


================
@@ -1922,6 +1922,33 @@ InstructionCost RISCVTTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val,
       SlideCost = 1; // With a constant index, we do not need to use addi.
   }
 
+  // When the vector needs to split into multiple register groups and the index
+  // exceeds single vector register group, we need to insert/extract the element
+  // via stack.
+  if (LT.first > 1 &&
+      ((Index == -1U) || (Index >= LT.second.getVectorMinNumElements() &&
+                          LT.second.isScalableVector()))) {
+    Type *ScalarType = Val->getScalarType();
+    Align VecAlign = DL.getPrefTypeAlign(Val);
+    Align SclAlign = DL.getPrefTypeAlign(ScalarType);
+
+    // Store all split vectors into stack and load the target element.
+    if (Opcode == Instruction::ExtractElement)
+      return LT.first * getMemoryOpCost(Instruction::Store, Val, VecAlign, 0,
----------------
preames wrote:

You shouldn't need to multiply by LT.first here.  getMemoryOpCost does that internally.  Or, at least, it should.  If it's not doing so in the split case, we should fix that in getMemoryOpCost instead.

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


More information about the llvm-commits mailing list