[llvm] b219a9c - [CostModel][AArch64] Fix ctpop intrinsic cost when NEON is disabled.
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 2 15:18:40 PDT 2022
Author: Eli Friedman
Date: 2022-09-02T15:17:55-07:00
New Revision: b219a9c0a29ef91d4738266a755a76577f5ab031
URL: https://github.com/llvm/llvm-project/commit/b219a9c0a29ef91d4738266a755a76577f5ab031
DIFF: https://github.com/llvm/llvm-project/commit/b219a9c0a29ef91d4738266a755a76577f5ab031.diff
LOG: [CostModel][AArch64] Fix ctpop intrinsic cost when NEON is disabled.
If we don't have NEON, we use the generic fallback, which takes 12
instructions. Make sure the costs reflect that.
(On a related note, we could optimize the generic fallback a bit. It
currently uses sequences like lsr+and+add; if we use and+lsr+add
instead, we can fold the lsr into the add.)
Differential Revision: https://reviews.llvm.org/D133154
Added:
Modified:
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
llvm/test/Analysis/CostModel/AArch64/ctpop.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index ce3c34b785913..6bdd89d7fa8b6 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -383,6 +383,10 @@ AArch64TTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
break;
}
case Intrinsic::ctpop: {
+ if (!ST->hasNEON()) {
+ // 32-bit or 64-bit ctpop without NEON is 12 instructions.
+ return getTypeLegalizationCost(RetTy).first * 12;
+ }
static const CostTblEntry CtpopCostTbl[] = {
{ISD::CTPOP, MVT::v2i64, 4},
{ISD::CTPOP, MVT::v4i32, 3},
diff --git a/llvm/test/Analysis/CostModel/AArch64/ctpop.ll b/llvm/test/Analysis/CostModel/AArch64/ctpop.ll
index e34ce1f04c9d3..03e719fa7eeee 100644
--- a/llvm/test/Analysis/CostModel/AArch64/ctpop.ll
+++ b/llvm/test/Analysis/CostModel/AArch64/ctpop.ll
@@ -156,6 +156,22 @@ define <32 x i8> @test_ctpop_v32i8(<32 x i8> %a) {
ret <32 x i8> %ctpop
}
+define i64 @test_ctpop_noneon_i64(i64 %a) "target-features"="-fp-armv8,-neon" {
+; CHECK-LABEL: 'test_ctpop_noneon_i64'
+; CHECK-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %ctpop = call i64 @llvm.ctpop.i64(i64 %a)
+; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i64 %ctpop
+ %ctpop = call i64 @llvm.ctpop.i64(i64 %a)
+ ret i64 %ctpop
+}
+
+define <2 x i64> @test_ctpop_noneon_v2i64(<2 x i64> %a) "target-features"="-fp-armv8,-neon" {
+; CHECK-LABEL: 'test_ctpop_noneon_v2i64'
+; CHECK-NEXT: Cost Model: Found an estimated cost of 24 for instruction: %ctpop = call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %a)
+; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i64> %ctpop
+ %ctpop = call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %a)
+ ret <2 x i64> %ctpop
+}
+
declare <2 x i64> @llvm.ctpop.v2i64(<2 x i64>)
declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32>)
declare <4 x i32> @llvm.ctpop.v4i32(<4 x i32>)
More information about the llvm-commits
mailing list