[llvm] [AArch64] [CostModel] Improve costs for scalar inserts into fixed-length SVE constant vector (PR #223638)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 02:58:28 PDT 2026


================
@@ -4866,9 +4866,57 @@ InstructionCost AArch64TTIImpl::getScalarizationOverhead(
     TTI::VectorInstrContext VIC) const {
   if (isa<ScalableVectorType>(Ty))
     return InstructionCost::getInvalid();
-  if (Ty->getElementType()->isFloatingPointTy())
-    return BaseT::getScalarizationOverhead(Ty, DemandedElts, Insert, Extract,
-                                           CostKind);
+  if (Ty->getElementType()->isFloatingPointTy()) {
+    InstructionCost Cost = BaseT::getScalarizationOverhead(
+        Ty, DemandedElts, Insert, Extract, CostKind);
+
+    if (!Insert || VL.empty())
+      return Cost;
+
+    auto LT = getTypeLegalizationCost(Ty);
+    if (!ST->isNeonAvailable() || !LT.second.isFixedLengthVector() ||
+        LT.second.getFixedSizeInBits() <= 128)
+      return Cost;
+
+    auto HasNonUniformConstants = [&VL]() -> bool {
+      Value *FirstConst = nullptr;
+      for (Value *V : VL) {
+        if (isa<UndefValue>(V) || !isa<Constant>(V) ||
+            isa<ConstantExpr, GlobalValue>(V))
+          continue;
+        if (!FirstConst)
+          FirstConst = V;
+        else if (V != FirstConst)
+          return true;
+      }
+      return false;
+    };
+
+    if (!HasNonUniformConstants())
----------------
sdesmalen-arm wrote:

When I comment this out, no tests fail, so this code is untested.

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


More information about the llvm-commits mailing list