Skip to content

Commit 6e4cea5

Browse files
author
Zain Jaffal
committed
[AArch64] Fix cost model for udiv instruction when one of the operands is a uniform constant
Currently the model over estimates the cost of a udiv instruction with one constant. The correct cost for a udiv instruction is insert_cost * extract_cost * num_elements Reviewed By: dmgreen Differential Revision: https://reviews.llvm.org/D135991
1 parent f5dd9dd commit 6e4cea5

File tree

2 files changed

+57
-45
lines changed

2 files changed

+57
-45
lines changed

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,6 +2171,18 @@ InstructionCost AArch64TTIImpl::getArithmeticInstrCost(
21712171
Cost *= 4;
21722172
return Cost;
21732173
} else {
2174+
// If one of the operands is a uniform constant then the cost for each
2175+
// element is Cost for insertion, extraction and division.
2176+
// Insertion cost = 2, Extraction Cost = 2, Division = cost for the
2177+
// operation with scalar type
2178+
if ((Op1Info.isConstant() && Op1Info.isUniform()) ||
2179+
(Op2Info.isConstant() && Op2Info.isUniform())) {
2180+
if (auto *VTy = dyn_cast<FixedVectorType>(Ty)) {
2181+
InstructionCost DivCost = BaseT::getArithmeticInstrCost(
2182+
Opcode, Ty->getScalarType(), CostKind, Op1Info, Op2Info);
2183+
return (4 + DivCost) * VTy->getNumElements();
2184+
}
2185+
}
21742186
// On AArch64, without SVE, vector divisions are expanded
21752187
// into scalar divisions of each pair of elements.
21762188
Cost += getArithmeticInstrCost(Instruction::ExtractElement, Ty,

0 commit comments

Comments
 (0)