[llvm] [AArch64][CostModel] Updated inserelement/extractelement costs (PR #220627)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 3 08:54:30 PDT 2026


================
@@ -4611,6 +4599,28 @@ InstructionCost AArch64TTIImpl::getVectorInstrCostHelper(
     if (Index == 0 && !Ty->getScalarType()->isIntegerTy())
       return 0;
 
+    // SVE has no scalar move to an arbitrary lane above the low 128-bit portion
+    // of a Z register, e.g. there is no equivalent of "mov z0.d[9], d0".
+    // Fixed-length vectors wider than 128 bits therefore need
+    // [splice]/index/pred/splat/cmp/pred-mov when scalarizing inserts for those
+    // lanes, so model them as more expensive than ordinary NEON lane accesses.
+    // Extracts to integer types require extra mov from FPR -> GPR.
+    if (ST->useSVEForFixedLengthVectors() && isa<FixedVectorType>(Ty) &&
+        !Ty->isBFloatTy()) {
+      InstructionCost Cost = CostKind == TTI::TCK_CodeSize
+                                 ? 1
+                                 : ST->getVectorInsertExtractBaseCost();
+      unsigned LowElts = AArch64::SVEBitsPerBlock / Ty->getScalarSizeInBits();
+      if (Index >= LowElts) {
+        if (Opcode == Instruction::InsertElement)
+          Cost += 3;
+        else if (Opcode == Instruction::ExtractElement &&
----------------
sdesmalen-arm wrote:

For extract element, the 'LowElts' is different as it can use `dup` (which has a wider immediate range)

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


More information about the llvm-commits mailing list