[llvm] r289819 - [CostModel][X86] Updated reverse shuffle costs
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 15 06:24:08 PST 2016
Author: rksimon
Date: Thu Dec 15 08:24:07 2016
New Revision: 289819
URL: http://llvm.org/viewvc/llvm-project?rev=289819&view=rev
Log:
[CostModel][X86] Updated reverse shuffle costs
Modified:
llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp
llvm/trunk/test/Analysis/CostModel/X86/shuffle-reverse.ll
Modified: llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp?rev=289819&r1=289818&r2=289819&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp Thu Dec 15 08:24:07 2016
@@ -604,12 +604,102 @@ int X86TTIImpl::getShuffleCost(TTI::Shuf
if (Kind == TTI::SK_Reverse) {
std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Tp);
- int Cost = 1;
- if (LT.second.getSizeInBits() > 128)
- Cost = 3; // Extract + insert + copy.
- // Multiple by the number of parts.
- return Cost * LT.first;
+ static const CostTblEntry AVX512VBMIShuffleTbl[] = {
+ { ISD::VECTOR_SHUFFLE, MVT::v64i8, 1 }, // vpermb
+ { ISD::VECTOR_SHUFFLE, MVT::v32i8, 1 } // vpermb
+ };
+
+ if (ST->hasVBMI())
+ if (const auto *Entry = CostTableLookup(AVX512VBMIShuffleTbl,
+ ISD::VECTOR_SHUFFLE, LT.second))
+ return LT.first * Entry->Cost;
+
+ static const CostTblEntry AVX512BWShuffleTbl[] = {
+ { ISD::VECTOR_SHUFFLE, MVT::v32i16, 1 }, // vpermw
+ { ISD::VECTOR_SHUFFLE, MVT::v64i8, 6 } // vextracti64x4 + 2*vperm2i128
+ // + 2*pshufb + vinserti64x4
+ };
+
+ if (ST->hasBWI())
+ if (const auto *Entry = CostTableLookup(AVX512BWShuffleTbl,
+ ISD::VECTOR_SHUFFLE, LT.second))
+ return LT.first * Entry->Cost;
+
+ static const CostTblEntry AVX512ShuffleTbl[] = {
+ { ISD::VECTOR_SHUFFLE, MVT::v8f64, 1 }, // vpermpd
+ { ISD::VECTOR_SHUFFLE, MVT::v16f32, 1 }, // vpermps
+ { ISD::VECTOR_SHUFFLE, MVT::v8i64, 1 }, // vpermq
+ { ISD::VECTOR_SHUFFLE, MVT::v16i32, 1 }, // vpermd
+ };
+
+ if (ST->hasAVX512())
+ if (const auto *Entry =
+ CostTableLookup(AVX512ShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second))
+ return LT.first * Entry->Cost;
+
+ static const CostTblEntry AVX2ShuffleTbl[] = {
+ { ISD::VECTOR_SHUFFLE, MVT::v4f64, 1 }, // vpermpd
+ { ISD::VECTOR_SHUFFLE, MVT::v8f32, 1 }, // vpermps
+ { ISD::VECTOR_SHUFFLE, MVT::v4i64, 1 }, // vpermq
+ { ISD::VECTOR_SHUFFLE, MVT::v8i32, 1 }, // vpermd
+ { ISD::VECTOR_SHUFFLE, MVT::v16i16, 2 }, // vperm2i128 + pshufb
+ { ISD::VECTOR_SHUFFLE, MVT::v32i8, 2 } // vperm2i128 + pshufb
+ };
+
+ if (ST->hasAVX2())
+ if (const auto *Entry =
+ CostTableLookup(AVX2ShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second))
+ return LT.first * Entry->Cost;
+
+ static const CostTblEntry AVX1ShuffleTbl[] = {
+ { ISD::VECTOR_SHUFFLE, MVT::v4f64, 2 }, // vperm2f128 + vpermilpd
+ { ISD::VECTOR_SHUFFLE, MVT::v8f32, 2 }, // vperm2f128 + vpermilps
+ { ISD::VECTOR_SHUFFLE, MVT::v4i64, 2 }, // vperm2f128 + vpermilpd
+ { ISD::VECTOR_SHUFFLE, MVT::v8i32, 2 }, // vperm2f128 + vpermilps
+ { ISD::VECTOR_SHUFFLE, MVT::v16i16, 4 }, // vextractf128 + 2*pshufb
+ // + vinsertf128
+ { ISD::VECTOR_SHUFFLE, MVT::v32i8, 4 } // vextractf128 + 2*pshufb
+ // + vinsertf128
+ };
+
+ if (ST->hasAVX())
+ if (const auto *Entry =
+ CostTableLookup(AVX1ShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second))
+ return LT.first * Entry->Cost;
+
+ static const CostTblEntry SSSE3ShuffleTbl[] = {
+ { ISD::VECTOR_SHUFFLE, MVT::v8i16, 1 }, // pshufb
+ { ISD::VECTOR_SHUFFLE, MVT::v16i8, 1 } // pshufb
+ };
+
+ if (ST->hasSSSE3())
+ if (const auto *Entry =
+ CostTableLookup(SSSE3ShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second))
+ return LT.first * Entry->Cost;
+
+ static const CostTblEntry SSE2ShuffleTbl[] = {
+ { ISD::VECTOR_SHUFFLE, MVT::v2f64, 1 }, // shufpd
+ { ISD::VECTOR_SHUFFLE, MVT::v2i64, 1 }, // pshufd
+ { ISD::VECTOR_SHUFFLE, MVT::v4i32, 1 }, // pshufd
+ { ISD::VECTOR_SHUFFLE, MVT::v8i16, 3 }, // pshuflw + pshufhw + pshufd
+ { ISD::VECTOR_SHUFFLE, MVT::v16i8, 9 } // 2*pshuflw + 2*pshufhw
+ // + 2*pshufd + 2*unpck + packus
+ };
+
+ if (ST->hasSSE2())
+ if (const auto *Entry =
+ CostTableLookup(SSE2ShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second))
+ return LT.first * Entry->Cost;
+
+ static const CostTblEntry SSE1ShuffleTbl[] = {
+ { ISD::VECTOR_SHUFFLE, MVT::v4f32, 1 }, // shufps
+ };
+
+ if (ST->hasSSE1())
+ if (const auto *Entry =
+ CostTableLookup(SSE1ShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second))
+ return LT.first * Entry->Cost;
}
if (Kind == TTI::SK_Alternate) {
Modified: llvm/trunk/test/Analysis/CostModel/X86/shuffle-reverse.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CostModel/X86/shuffle-reverse.ll?rev=289819&r1=289818&r2=289819&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/CostModel/X86/shuffle-reverse.ll (original)
+++ llvm/trunk/test/Analysis/CostModel/X86/shuffle-reverse.ll Thu Dec 15 08:24:07 2016
@@ -18,13 +18,15 @@ define void @test_vXf64(<2 x double> %sr
%V128 = shufflevector <2 x double> %src128, <2 x double> undef, <2 x i32> <i32 1, i32 0>
; SSE: cost of 2 {{.*}} %V256 = shufflevector
- ; AVX: cost of 3 {{.*}} %V256 = shufflevector
- ; AVX512: cost of 3 {{.*}} %V256 = shufflevector
+ ; AVX1: cost of 2 {{.*}} %V256 = shufflevector
+ ; AVX2: cost of 1 {{.*}} %V256 = shufflevector
+ ; AVX512: cost of 1 {{.*}} %V256 = shufflevector
%V256 = shufflevector <4 x double> %src256, <4 x double> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
; SSE: cost of 4 {{.*}} %V512 = shufflevector
- ; AVX: cost of 6 {{.*}} %V512 = shufflevector
- ; AVX512: cost of 3 {{.*}} %V512 = shufflevector
+ ; AVX1: cost of 4 {{.*}} %V512 = shufflevector
+ ; AVX2: cost of 2 {{.*}} %V512 = shufflevector
+ ; AVX512: cost of 1 {{.*}} %V512 = shufflevector
%V512 = shufflevector <8 x double> %src512, <8 x double> undef, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
ret void
@@ -38,13 +40,15 @@ define void @test_vXi64(<2 x i64> %src12
%V128 = shufflevector <2 x i64> %src128, <2 x i64> undef, <2 x i32> <i32 1, i32 0>
; SSE: cost of 2 {{.*}} %V256 = shufflevector
- ; AVX: cost of 3 {{.*}} %V256 = shufflevector
- ; AVX512: cost of 3 {{.*}} %V256 = shufflevector
+ ; AVX1: cost of 2 {{.*}} %V256 = shufflevector
+ ; AVX2: cost of 1 {{.*}} %V256 = shufflevector
+ ; AVX512: cost of 1 {{.*}} %V256 = shufflevector
%V256 = shufflevector <4 x i64> %src256, <4 x i64> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
; SSE: cost of 4 {{.*}} %V512 = shufflevector
- ; AVX: cost of 6 {{.*}} %V512 = shufflevector
- ; AVX512: cost of 3 {{.*}} %V512 = shufflevector
+ ; AVX1: cost of 4 {{.*}} %V512 = shufflevector
+ ; AVX2: cost of 2 {{.*}} %V512 = shufflevector
+ ; AVX512: cost of 1 {{.*}} %V512 = shufflevector
%V512 = shufflevector <8 x i64> %src512, <8 x i64> undef, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
ret void
@@ -63,13 +67,15 @@ define void @test_vXf32(<2 x float> %src
%V128 = shufflevector <4 x float> %src128, <4 x float> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
; SSE: cost of 2 {{.*}} %V256 = shufflevector
- ; AVX: cost of 3 {{.*}} %V256 = shufflevector
- ; AVX512: cost of 3 {{.*}} %V256 = shufflevector
+ ; AVX1: cost of 2 {{.*}} %V256 = shufflevector
+ ; AVX2: cost of 1 {{.*}} %V256 = shufflevector
+ ; AVX512: cost of 1 {{.*}} %V256 = shufflevector
%V256 = shufflevector <8 x float> %src256, <8 x float> undef, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
; SSE: cost of 4 {{.*}} %V512 = shufflevector
- ; AVX: cost of 6 {{.*}} %V512 = shufflevector
- ; AVX512: cost of 3 {{.*}} %V512 = shufflevector
+ ; AVX1: cost of 4 {{.*}} %V512 = shufflevector
+ ; AVX2: cost of 2 {{.*}} %V512 = shufflevector
+ ; AVX512: cost of 1 {{.*}} %V512 = shufflevector
%V512 = shufflevector <16 x float> %src512, <16 x float> undef, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
ret void
@@ -88,13 +94,15 @@ define void @test_vXi32(<2 x i32> %src64
%V128 = shufflevector <4 x i32> %src128, <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
; SSE: cost of 2 {{.*}} %V256 = shufflevector
- ; AVX: cost of 3 {{.*}} %V256 = shufflevector
- ; AVX512: cost of 3 {{.*}} %V256 = shufflevector
+ ; AVX1: cost of 2 {{.*}} %V256 = shufflevector
+ ; AVX2: cost of 1 {{.*}} %V256 = shufflevector
+ ; AVX512: cost of 1 {{.*}} %V256 = shufflevector
%V256 = shufflevector <8 x i32> %src256, <8 x i32> undef, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
; SSE: cost of 4 {{.*}} %V512 = shufflevector
- ; AVX: cost of 6 {{.*}} %V512 = shufflevector
- ; AVX512: cost of 3 {{.*}} %V512 = shufflevector
+ ; AVX1: cost of 4 {{.*}} %V512 = shufflevector
+ ; AVX2: cost of 2 {{.*}} %V512 = shufflevector
+ ; AVX512: cost of 1 {{.*}} %V512 = shufflevector
%V512 = shufflevector <16 x i32> %src512, <16 x i32> undef, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
ret void
@@ -102,20 +110,28 @@ define void @test_vXi32(<2 x i32> %src64
; CHECK-LABEL: 'test_vXi16'
define void @test_vXi16(<8 x i16> %src128, <16 x i16> %src256, <32 x i16> %src512) {
- ; SSE: cost of 1 {{.*}} %V128 = shufflevector
+ ; SSE2: cost of 3 {{.*}} %V128 = shufflevector
+ ; SSSE3: cost of 1 {{.*}} %V128 = shufflevector
+ ; SSE42: cost of 1 {{.*}} %V128 = shufflevector
; AVX: cost of 1 {{.*}} %V128 = shufflevector
; AVX512: cost of 1 {{.*}} %V128 = shufflevector
%V128 = shufflevector <8 x i16> %src128, <8 x i16> undef, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
- ; SSE: cost of 2 {{.*}} %V256 = shufflevector
- ; AVX: cost of 3 {{.*}} %V256 = shufflevector
- ; AVX512: cost of 3 {{.*}} %V256 = shufflevector
+ ; SSE2: cost of 6 {{.*}} %V256 = shufflevector
+ ; SSSE3: cost of 2 {{.*}} %V256 = shufflevector
+ ; SSE42: cost of 2 {{.*}} %V256 = shufflevector
+ ; AVX1: cost of 4 {{.*}} %V256 = shufflevector
+ ; AVX2: cost of 2 {{.*}} %V256 = shufflevector
+ ; AVX512: cost of 2 {{.*}} %V256 = shufflevector
%V256 = shufflevector <16 x i16> %src256, <16 x i16> undef, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
- ; SSE: cost of 4 {{.*}} %V512 = shufflevector
- ; AVX: cost of 6 {{.*}} %V512 = shufflevector
- ; AVX512F: cost of 6 {{.*}} %V512 = shufflevector
- ; AVX512BW: cost of 3 {{.*}} %V512 = shufflevector
+ ; SSE2: cost of 12 {{.*}} %V512 = shufflevector
+ ; SSSE3: cost of 4 {{.*}} %V512 = shufflevector
+ ; SSE42: cost of 4 {{.*}} %V512 = shufflevector
+ ; AVX1: cost of 8 {{.*}} %V512 = shufflevector
+ ; AVX2: cost of 4 {{.*}} %V512 = shufflevector
+ ; AVX512F: cost of 4 {{.*}} %V512 = shufflevector
+ ; AVX512BW: cost of 1 {{.*}} %V512 = shufflevector
%V512 = shufflevector <32 x i16> %src512, <32 x i16> undef, <32 x i32> <i32 31, i32 30, i32 29, i32 28, i32 27, i32 26, i32 25, i32 24, i32 23, i32 22, i32 21, i32 20, i32 19, i32 18, i32 17, i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
ret void
@@ -123,20 +139,28 @@ define void @test_vXi16(<8 x i16> %src12
; CHECK-LABEL: 'test_vXi8'
define void @test_vXi8(<16 x i8> %src128, <32 x i8> %src256, <64 x i8> %src512) {
- ; SSE: cost of 1 {{.*}} %V128 = shufflevector
+ ; SSE2: cost of 9 {{.*}} %V128 = shufflevector
+ ; SSSE3: cost of 1 {{.*}} %V128 = shufflevector
+ ; SSE42: cost of 1 {{.*}} %V128 = shufflevector
; AVX: cost of 1 {{.*}} %V128 = shufflevector
; AVX512: cost of 1 {{.*}} %V128 = shufflevector
%V128 = shufflevector <16 x i8> %src128, <16 x i8> undef, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
- ; SSE: cost of 2 {{.*}} %V256 = shufflevector
- ; AVX: cost of 3 {{.*}} %V256 = shufflevector
- ; AVX512: cost of 3 {{.*}} %V256 = shufflevector
+ ; SSE2: cost of 18 {{.*}} %V256 = shufflevector
+ ; SSSE3: cost of 2 {{.*}} %V256 = shufflevector
+ ; SSE42: cost of 2 {{.*}} %V256 = shufflevector
+ ; AVX1: cost of 4 {{.*}} %V256 = shufflevector
+ ; AVX2: cost of 2 {{.*}} %V256 = shufflevector
+ ; AVX512: cost of 2 {{.*}} %V256 = shufflevector
%V256 = shufflevector <32 x i8> %src256, <32 x i8> undef, <32 x i32> <i32 31, i32 30, i32 29, i32 28, i32 27, i32 26, i32 25, i32 24, i32 23, i32 22, i32 21, i32 20, i32 19, i32 18, i32 17, i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
- ; SSE: cost of 4 {{.*}} %V512 = shufflevector
- ; AVX: cost of 6 {{.*}} %V512 = shufflevector
- ; AVX512F: cost of 6 {{.*}} %V512 = shufflevector
- ; AVX512BW: cost of 3 {{.*}} %V512 = shufflevector
+ ; SSE2: cost of 36 {{.*}} %V512 = shufflevector
+ ; SSSE3: cost of 4 {{.*}} %V512 = shufflevector
+ ; SSE42: cost of 4 {{.*}} %V512 = shufflevector
+ ; AVX1: cost of 8 {{.*}} %V512 = shufflevector
+ ; AVX2: cost of 4 {{.*}} %V512 = shufflevector
+ ; AVX512F: cost of 4 {{.*}} %V512 = shufflevector
+ ; AVX512BW: cost of 6 {{.*}} %V512 = shufflevector
%V512 = shufflevector <64 x i8> %src512, <64 x i8> undef, <64 x i32> <i32 63, i32 62, i32 61, i32 60, i32 59, i32 58, i32 57, i32 56, i32 55, i32 54, i32 53, i32 52, i32 51, i32 50, i32 49, i32 48, i32 47, i32 46, i32 45, i32 44, i32 43, i32 42, i32 41, i32 40, i32 39, i32 38, i32 37, i32 36, i32 35, i32 34, i32 33, i32 32, i32 31, i32 30, i32 29, i32 28, i32 27, i32 26, i32 25, i32 24, i32 23, i32 22, i32 21, i32 20, i32 19, i32 18, i32 17, i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
ret void
More information about the llvm-commits
mailing list