[llvm] [AArch64] [CostModel] Improve costs for scalar inserts into fixed-length SVE constant vector (PR #223638)
Utpal Bora via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 23 01:51:43 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())
----------------
utpalbora wrote:
I’ll add a test for this.
https://github.com/llvm/llvm-project/pull/223638
More information about the llvm-commits
mailing list