[llvm] [AArch64] Increase fixed-length SVE scalarization costs (PR #226120)
Utpal Bora via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 29 05:22:12 PDT 2026
================
@@ -4891,12 +4891,26 @@ 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);
- unsigned VecInstCost =
- CostKind == TTI::TCK_CodeSize ? 1 : ST->getVectorInsertExtractBaseCost();
- return DemandedElts.popcount() * (Insert + Extract) * VecInstCost;
+
+ std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty);
+ if (!ST->useSVEForFixedLengthVectors(LT.second)) {
+ if (Ty->getElementType()->isFloatingPointTy())
+ return BaseT::getScalarizationOverhead(Ty, DemandedElts, Insert, Extract,
+ CostKind);
+
+ unsigned VecInstCost = CostKind == TTI::TCK_CodeSize
+ ? 1
+ : ST->getVectorInsertExtractBaseCost();
+ return DemandedElts.popcount() * (Insert + Extract) * VecInstCost;
+ }
+
+ // Scalarizing fixed-length SVE vectors is expensive. Add an extra cost to
+ // prevent the SLP vectorizer from selecting unprofitable trees.
+ // TODO: Model the scalarization overhead of wide fixed-length SVE vectors
+ // accurately.
+ return BaseT::getScalarizationOverhead(Ty, DemandedElts, Insert, Extract,
+ CostKind) +
+ 5;
----------------
utpalbora wrote:
Our experiments with SPEC CPU 2017 and 2026 using a scalarization overhead of 500 did not show any additional benefit over overhead of 5. So 5 appears to be sufficient for this heuristic without unnecessarily inflating the cost.
Longer term, this should be superseded by a more accurate cost model for constant vector materialization.
https://github.com/llvm/llvm-project/pull/226120
More information about the llvm-commits
mailing list