Skip to content

Commit 0175cd0

Browse files
committed
[AArch64] Add vector saturating add intrinsic costs
This adds sadd.sat, uadd.sat, ssub.sat and usub.sat costs for AArch64, similar to how they were recently added for ARM. Differential Revision: https://reviews.llvm.org/D95292
1 parent 9a75a80 commit 0175cd0

File tree

3 files changed

+164
-144
lines changed

3 files changed

+164
-144
lines changed

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,22 @@ AArch64TTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
235235
return LT.first;
236236
break;
237237
}
238+
case Intrinsic::sadd_sat:
239+
case Intrinsic::ssub_sat:
240+
case Intrinsic::uadd_sat:
241+
case Intrinsic::usub_sat: {
242+
static const auto ValidSatTys = {MVT::v8i8, MVT::v16i8, MVT::v4i16,
243+
MVT::v8i16, MVT::v2i32, MVT::v4i32,
244+
MVT::v2i64};
245+
auto LT = TLI->getTypeLegalizationCost(DL, RetTy);
246+
// This is a base cost of 1 for the vadd, plus 3 extract shifts if we
247+
// need to extend the type, as it uses shr(qadd(shl, shl)).
248+
unsigned Instrs =
249+
LT.second.getScalarSizeInBits() == RetTy->getScalarSizeInBits() ? 1 : 4;
250+
if (any_of(ValidSatTys, [&LT](MVT M) { return M == LT.second; }))
251+
return LT.first * Instrs;
252+
break;
253+
}
238254
default:
239255
break;
240256
}

0 commit comments

Comments
 (0)