Skip to content

[ARM] Add scalar add_sat costs. #100988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,8 @@ ARMTTIImpl::getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty,
InstructionCost
ARMTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
TTI::TargetCostKind CostKind) {
switch (ICA.getID()) {
unsigned Opc = ICA.getID();
switch (Opc) {
case Intrinsic::get_active_lane_mask:
// Currently we make a somewhat optimistic assumption that
// active_lane_mask's are always free. In reality it may be freely folded
Expand All @@ -1904,17 +1905,38 @@ ARMTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
case Intrinsic::ssub_sat:
case Intrinsic::uadd_sat:
case Intrinsic::usub_sat: {
bool IsAdd = (Opc == Intrinsic::sadd_sat || Opc == Intrinsic::ssub_sat);
bool IsSigned = (Opc == Intrinsic::sadd_sat || Opc == Intrinsic::ssub_sat);
Type *RetTy = ICA.getReturnType();

if (auto *ITy = dyn_cast<IntegerType>(RetTy)) {
if (IsSigned && ST->hasDSP() && ITy->getBitWidth() == 32)
return 1; // qadd / qsub
if (ST->hasDSP() && (ITy->getBitWidth() == 8 || ITy->getBitWidth() == 16))
return 2; // uqadd16 / qadd16 / uqsub16 / qsub16 + possible extend.
// Otherwise return the cost of expanding the node. Generally an add +
// icmp + sel.
CmpInst::Predicate Pred = CmpInst::ICMP_SGT;
Type *CondTy = RetTy->getWithNewBitWidth(1);
return getArithmeticInstrCost(IsAdd ? Instruction::Add : Instruction::Sub,
RetTy, CostKind) +
2 * getCmpSelInstrCost(BinaryOperator::ICmp, RetTy, CondTy, Pred,
CostKind) +
2 * getCmpSelInstrCost(BinaryOperator::Select, RetTy, CondTy, Pred,
CostKind);
}

if (!ST->hasMVEIntegerOps())
break;
Type *VT = ICA.getReturnType();

std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(VT);
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(RetTy);
if (LT.second == MVT::v4i32 || LT.second == MVT::v8i16 ||
LT.second == MVT::v16i8) {
// This is a base cost of 1 for the vqadd, plus 3 extract shifts if we
// need to extend the type, as it uses shr(qadd(shl, shl)).
unsigned Instrs =
LT.second.getScalarSizeInBits() == VT->getScalarSizeInBits() ? 1 : 4;
LT.second.getScalarSizeInBits() == RetTy->getScalarSizeInBits() ? 1
: 4;
return LT.first * ST->getMVEVectorCostFactor(CostKind) * Instrs;
}
break;
Expand Down Expand Up @@ -1948,7 +1970,7 @@ ARMTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
case Intrinsic::fptoui_sat: {
if (ICA.getArgTypes().empty())
break;
bool IsSigned = ICA.getID() == Intrinsic::fptosi_sat;
bool IsSigned = Opc == Intrinsic::fptosi_sat;
auto LT = getTypeLegalizationCost(ICA.getArgTypes()[0]);
EVT MTy = TLI->getValueType(DL, ICA.getReturnType());
// Check for the legal types, with the corect subtarget features.
Expand Down
Loading
Loading