[llvm] [AArch64] [CostModel] Fix cost modelling for saturating arithmetic intrinsics (PR #152333)
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 21 09:20:32 PDT 2025
================
@@ -643,6 +643,13 @@ AArch64TTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
LT.second.getScalarSizeInBits() == RetTy->getScalarSizeInBits() ? 1 : 4;
if (any_of(ValidSatTys, [<](MVT M) { return M == LT.second; }))
return LT.first * Instrs;
+
+ TypeSize TS = getDataLayout().getTypeSizeInBits(RetTy);
+ uint64_t VectorSize = TS.getKnownMinValue();
+
+ if (ST->isSVEAvailable() && VectorSize >= 128 && isPowerOf2_64(VectorSize))
----------------
sdesmalen-arm wrote:
There's nothing wrong with the change, but I just want to leave a few observations;
(1) `getTypeLegalizationCost` will return a legal type, which must be a power of 2. So `isPowerOf2_64(VectorSize)` must be true.
(2) The existing code checks if the legal type is any of the legal NEON types, but I think the SVE and NEON case can be merged by changing it to look up the _element_ type in a list of "supported element types" and as long as the vector size of the legalised type is >= 64 bits, it can return `LT.first * Instrs`.
(3) just an observation that this could be rolled out for other intrinsics as well, such as the min/max above which are currently also limited to only (vscale x )128 types.
https://github.com/llvm/llvm-project/pull/152333
More information about the llvm-commits
mailing list