From 6bba6068be0d884c15ff78ecf803197f5d84a5e2 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Thu, 18 May 2017 10:42:34 +0000 Subject: [PATCH] [X86][AVX512] Add 512-bit vector ctpop costs + tests llvm-svn: 303342 --- llvm/lib/Target/X86/X86TargetTransformInfo.cpp | 6 +++ llvm/test/Analysis/CostModel/X86/ctpop.ll | 63 ++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp index 057e874..fe94079 100644 --- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp +++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp @@ -1415,6 +1415,10 @@ int X86TTIImpl::getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, { ISD::CTLZ, MVT::v16i32, 22 }, { ISD::CTLZ, MVT::v32i16, 18 }, { ISD::CTLZ, MVT::v64i8, 17 }, + { ISD::CTPOP, MVT::v8i64, 7 }, + { ISD::CTPOP, MVT::v16i32, 11 }, + { ISD::CTPOP, MVT::v32i16, 9 }, + { ISD::CTPOP, MVT::v64i8, 6 }, { ISD::CTTZ, MVT::v8i64, 10 }, { ISD::CTTZ, MVT::v16i32, 14 }, { ISD::CTTZ, MVT::v32i16, 12 }, @@ -1425,6 +1429,8 @@ int X86TTIImpl::getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, { ISD::BITREVERSE, MVT::v16i32, 24 }, { ISD::CTLZ, MVT::v8i64, 29 }, { ISD::CTLZ, MVT::v16i32, 35 }, + { ISD::CTPOP, MVT::v8i64, 16 }, + { ISD::CTPOP, MVT::v16i32, 24 }, { ISD::CTTZ, MVT::v8i64, 20 }, { ISD::CTTZ, MVT::v16i32, 28 }, }; diff --git a/llvm/test/Analysis/CostModel/X86/ctpop.ll b/llvm/test/Analysis/CostModel/X86/ctpop.ll index f072cba..f5dc2dd 100644 --- a/llvm/test/Analysis/CostModel/X86/ctpop.ll +++ b/llvm/test/Analysis/CostModel/X86/ctpop.ll @@ -4,6 +4,8 @@ ; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=core-avx2 -cost-model -analyze | FileCheck %s -check-prefix=CHECK -check-prefix=AVX -check-prefix=AVX2 -check-prefix=POPCNT ; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=bdver2 -cost-model -analyze | FileCheck %s -check-prefix=CHECK -check-prefix=AVX -check-prefix=AVX1 -check-prefix=POPCNT ; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=bdver4 -cost-model -analyze | FileCheck %s -check-prefix=CHECK -check-prefix=AVX -check-prefix=AVX2 -check-prefix=POPCNT +; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=knl -cost-model -analyze | FileCheck %s -check-prefix=CHECK -check-prefix=AVX512 -check-prefix=AVX512F -check-prefix=POPCNT +; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=skx -cost-model -analyze | FileCheck %s -check-prefix=CHECK -check-prefix=AVX512 -check-prefix=AVX512BW -check-prefix=POPCNT ; Verify the cost of scalar population count instructions. @@ -56,11 +58,17 @@ declare <8 x i32> @llvm.ctpop.v8i32(<8 x i32>) declare <16 x i16> @llvm.ctpop.v16i16(<16 x i16>) declare <32 x i8> @llvm.ctpop.v32i8(<32 x i8>) +declare <8 x i64> @llvm.ctpop.v8i64(<8 x i64>) +declare <16 x i32> @llvm.ctpop.v16i32(<16 x i32>) +declare <32 x i16> @llvm.ctpop.v32i16(<32 x i16>) +declare <64 x i8> @llvm.ctpop.v64i8(<64 x i8>) + define <2 x i64> @var_ctpop_v2i64(<2 x i64> %a) { ; CHECK: 'Cost Model Analysis' for function 'var_ctpop_v2i64': ; SSE2: Found an estimated cost of 12 for instruction: %ctpop ; SSE42: Found an estimated cost of 7 for instruction: %ctpop ; AVX: Found an estimated cost of 7 for instruction: %ctpop +; AVX512: Found an estimated cost of 7 for instruction: %ctpop %ctpop = call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %a) ret <2 x i64> %ctpop } @@ -71,15 +79,29 @@ define <4 x i64> @var_ctpop_v4i64(<4 x i64> %a) { ; SSE42: Found an estimated cost of 14 for instruction: %ctpop ; AVX1: Found an estimated cost of 16 for instruction: %ctpop ; AVX2: Found an estimated cost of 7 for instruction: %ctpop +; AVX512: Found an estimated cost of 7 for instruction: %ctpop %ctpop = call <4 x i64> @llvm.ctpop.v4i64(<4 x i64> %a) ret <4 x i64> %ctpop } +define <8 x i64> @var_ctpop_v8i64(<8 x i64> %a) { +; CHECK: 'Cost Model Analysis' for function 'var_ctpop_v8i64': +; SSE2: Found an estimated cost of 48 for instruction: %ctpop +; SSE42: Found an estimated cost of 28 for instruction: %ctpop +; AVX1: Found an estimated cost of 32 for instruction: %ctpop +; AVX2: Found an estimated cost of 14 for instruction: %ctpop +; AVX512F: Found an estimated cost of 16 for instruction: %ctpop +; AVX512BW: Found an estimated cost of 7 for instruction: %ctpop + %ctpop = call <8 x i64> @llvm.ctpop.v8i64(<8 x i64> %a) + ret <8 x i64> %ctpop +} + define <4 x i32> @var_ctpop_v4i32(<4 x i32> %a) { ; CHECK: 'Cost Model Analysis' for function 'var_ctpop_v4i32': ; SSE2: Found an estimated cost of 15 for instruction: %ctpop ; SSE42: Found an estimated cost of 11 for instruction: %ctpop ; AVX: Found an estimated cost of 11 for instruction: %ctpop +; AVX512: Found an estimated cost of 11 for instruction: %ctpop %ctpop = call <4 x i32> @llvm.ctpop.v4i32(<4 x i32> %a) ret <4 x i32> %ctpop } @@ -90,15 +112,29 @@ define <8 x i32> @var_ctpop_v8i32(<8 x i32> %a) { ; SSE42: Found an estimated cost of 22 for instruction: %ctpop ; AVX1: Found an estimated cost of 24 for instruction: %ctpop ; AVX2: Found an estimated cost of 11 for instruction: %ctpop +; AVX512: Found an estimated cost of 11 for instruction: %ctpop %ctpop = call <8 x i32> @llvm.ctpop.v8i32(<8 x i32> %a) ret <8 x i32> %ctpop } +define <16 x i32> @var_ctpop_v16i32(<16 x i32> %a) { +; CHECK: 'Cost Model Analysis' for function 'var_ctpop_v16i32': +; SSE2: Found an estimated cost of 60 for instruction: %ctpop +; SSE42: Found an estimated cost of 44 for instruction: %ctpop +; AVX1: Found an estimated cost of 48 for instruction: %ctpop +; AVX2: Found an estimated cost of 22 for instruction: %ctpop +; AVX512F: Found an estimated cost of 24 for instruction: %ctpop +; AVX512BW: Found an estimated cost of 11 for instruction: %ctpop + %ctpop = call <16 x i32> @llvm.ctpop.v16i32(<16 x i32> %a) + ret <16 x i32> %ctpop +} + define <8 x i16> @var_ctpop_v8i16(<8 x i16> %a) { ; CHECK: 'Cost Model Analysis' for function 'var_ctpop_v8i16': ; SSE2: Found an estimated cost of 13 for instruction: %ctpop ; SSE42: Found an estimated cost of 9 for instruction: %ctpop ; AVX: Found an estimated cost of 9 for instruction: %ctpop +; AVX512: Found an estimated cost of 9 for instruction: %ctpop %ctpop = call <8 x i16> @llvm.ctpop.v8i16(<8 x i16> %a) ret <8 x i16> %ctpop } @@ -109,15 +145,29 @@ define <16 x i16> @var_ctpop_v16i16(<16 x i16> %a) { ; SSE42: Found an estimated cost of 18 for instruction: %ctpop ; AVX1: Found an estimated cost of 20 for instruction: %ctpop ; AVX2: Found an estimated cost of 9 for instruction: %ctpop +; AVX512: Found an estimated cost of 9 for instruction: %ctpop %ctpop = call <16 x i16> @llvm.ctpop.v16i16(<16 x i16> %a) ret <16 x i16> %ctpop } +define <32 x i16> @var_ctpop_v32i16(<32 x i16> %a) { +; CHECK: 'Cost Model Analysis' for function 'var_ctpop_v32i16': +; SSE2: Found an estimated cost of 52 for instruction: %ctpop +; SSE42: Found an estimated cost of 36 for instruction: %ctpop +; AVX1: Found an estimated cost of 40 for instruction: %ctpop +; AVX2: Found an estimated cost of 18 for instruction: %ctpop +; AVX512F: Found an estimated cost of 18 for instruction: %ctpop +; AVX512BW: Found an estimated cost of 9 for instruction: %ctpop + %ctpop = call <32 x i16> @llvm.ctpop.v32i16(<32 x i16> %a) + ret <32 x i16> %ctpop +} + define <16 x i8> @var_ctpop_v16i8(<16 x i8> %a) { ; CHECK: 'Cost Model Analysis' for function 'var_ctpop_v16i8': ; SSE2: Found an estimated cost of 10 for instruction: %ctpop ; SSE42: Found an estimated cost of 6 for instruction: %ctpop ; AVX: Found an estimated cost of 6 for instruction: %ctpop +; AVX512: Found an estimated cost of 6 for instruction: %ctpop %ctpop = call <16 x i8> @llvm.ctpop.v16i8(<16 x i8> %a) ret <16 x i8> %ctpop } @@ -128,6 +178,19 @@ define <32 x i8> @var_ctpop_v32i8(<32 x i8> %a) { ; SSE42: Found an estimated cost of 12 for instruction: %ctpop ; AVX1: Found an estimated cost of 14 for instruction: %ctpop ; AVX2: Found an estimated cost of 6 for instruction: %ctpop +; AVX512: Found an estimated cost of 6 for instruction: %ctpop %ctpop = call <32 x i8> @llvm.ctpop.v32i8(<32 x i8> %a) ret <32 x i8> %ctpop } + +define <64 x i8> @var_ctpop_v64i8(<64 x i8> %a) { +; CHECK: 'Cost Model Analysis' for function 'var_ctpop_v64i8': +; SSE2: Found an estimated cost of 40 for instruction: %ctpop +; SSE42: Found an estimated cost of 24 for instruction: %ctpop +; AVX1: Found an estimated cost of 28 for instruction: %ctpop +; AVX2: Found an estimated cost of 12 for instruction: %ctpop +; AVX512F: Found an estimated cost of 12 for instruction: %ctpop +; AVX512BW: Found an estimated cost of 6 for instruction: %ctpop + %ctpop = call <64 x i8> @llvm.ctpop.v64i8(<64 x i8> %a) + ret <64 x i8> %ctpop +} -- 2.7.4