[llvm] [AArch64][CostModel] Improve cost estimate of scalarizing a vector di… (PR #118055)
Sushant Gokhale via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 2 03:28:00 PST 2024
================
@@ -3472,29 +3472,41 @@ InstructionCost AArch64TTIImpl::getArithmeticInstrCost(
Cost *= 4;
return Cost;
} else {
- // If one of the operands is a uniform constant then the cost for each
- // element is Cost for insertion, extraction and division.
- // Insertion cost = 2, Extraction Cost = 2, Division = cost for the
- // operation with scalar type
- if ((Op1Info.isConstant() && Op1Info.isUniform()) ||
- (Op2Info.isConstant() && Op2Info.isUniform())) {
- if (auto *VTy = dyn_cast<FixedVectorType>(Ty)) {
+ if (auto *VTy = dyn_cast<FixedVectorType>(Ty)) {
+ if ((Op1Info.isConstant() && Op1Info.isUniform()) ||
+ (Op2Info.isConstant() && Op2Info.isUniform())) {
InstructionCost DivCost = BaseT::getArithmeticInstrCost(
Opcode, Ty->getScalarType(), CostKind, Op1Info, Op2Info);
- return (4 + DivCost) * VTy->getNumElements();
+ // If #vector_elements = n then we need
+ // n inserts + 2n extracts + n divisions.
+ InstructionCost InsertExtractCost =
+ ST->getVectorInsertExtractBaseCost();
+ Cost = (3 * InsertExtractCost + DivCost) * VTy->getNumElements();
+ } else if (!Scalars.empty()) {
----------------
sushgokh wrote:
I initially tried passing scalars through `Args` but this is crashing one of the tests. Didnt debug this.
https://github.com/llvm/llvm-project/pull/118055
More information about the llvm-commits
mailing list