Skip to content

Commit f8fa042

Browse files
committed
[CostModel][X86] Add CostKinds handling for vector integer comparisons
These were based off a mixture of vector integer add/sub costs and the numbers from the 'cost-tables vs llvm-mca' script from D103695 - the extra costs for different predicates are still proving tricky to implement, but I've gotten most costs to within +/1 now - the AVX512 are tricky as we still don't handle predicate results properly, so most of these were done by hand.
1 parent 292cb11 commit f8fa042

File tree

13 files changed

+5552
-846
lines changed

13 files changed

+5552
-846
lines changed

llvm/lib/Target/X86/X86TargetTransformInfo.cpp

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,8 +3104,10 @@ InstructionCost X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
31043104
};
31053105

31063106
static const CostKindTblEntry AVX512BWCostTbl[] = {
3107-
{ ISD::SETCC, MVT::v32i16, { 1 } },
3108-
{ ISD::SETCC, MVT::v64i8, { 1 } },
3107+
{ ISD::SETCC, MVT::v32i16, { 1, 1, 1, 1 } },
3108+
{ ISD::SETCC, MVT::v16i16, { 1, 1, 1, 1 } },
3109+
{ ISD::SETCC, MVT::v64i8, { 1, 1, 1, 1 } },
3110+
{ ISD::SETCC, MVT::v32i8, { 1, 1, 1, 1 } },
31093111

31103112
{ ISD::SELECT, MVT::v32i16, { 1, 1, 1, 1 } },
31113113
{ ISD::SELECT, MVT::v64i8, { 1, 1, 1, 1 } },
@@ -3117,8 +3119,13 @@ InstructionCost X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
31173119
{ ISD::SETCC, MVT::v16f32, { 1, 4, 1, 1 } },
31183120
{ ISD::SETCC, MVT::v8f32, { 1, 4, 1, 1 } },
31193121

3120-
{ ISD::SETCC, MVT::v8i64, { 1 } },
3121-
{ ISD::SETCC, MVT::v16i32, { 1 } },
3122+
{ ISD::SETCC, MVT::v8i64, { 1, 1, 1, 1 } },
3123+
{ ISD::SETCC, MVT::v4i64, { 1, 1, 1, 1 } },
3124+
{ ISD::SETCC, MVT::v2i64, { 1, 1, 1, 1 } },
3125+
{ ISD::SETCC, MVT::v16i32, { 1, 1, 1, 1 } },
3126+
{ ISD::SETCC, MVT::v8i32, { 1, 1, 1, 1 } },
3127+
{ ISD::SETCC, MVT::v32i16, { 3, 7, 5, 5 } },
3128+
{ ISD::SETCC, MVT::v64i8, { 3, 7, 5, 5 } },
31223129

31233130
{ ISD::SELECT, MVT::v8i64, { 1, 1, 1, 1 } },
31243131
{ ISD::SELECT, MVT::v4i64, { 1, 1, 1, 1 } },
@@ -3135,9 +3142,6 @@ InstructionCost X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
31353142
{ ISD::SELECT, MVT::v4f32, { 1, 1, 1, 1 } },
31363143
{ ISD::SELECT, MVT::f32 , { 1, 1, 1, 1 } },
31373144

3138-
{ ISD::SETCC, MVT::v32i16, { 2 } }, // FIXME: should probably be 4
3139-
{ ISD::SETCC, MVT::v64i8, { 2 } }, // FIXME: should probably be 4
3140-
31413145
{ ISD::SELECT, MVT::v32i16, { 2, 2, 4, 4 } },
31423146
{ ISD::SELECT, MVT::v16i16, { 1, 1, 1, 1 } },
31433147
{ ISD::SELECT, MVT::v8i16, { 1, 1, 1, 1 } },
@@ -3154,10 +3158,10 @@ InstructionCost X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
31543158
{ ISD::SETCC, MVT::v4f32, { 1, 4, 1, 1 } },
31553159
{ ISD::SETCC, MVT::f32, { 1, 4, 1, 1 } },
31563160

3157-
{ ISD::SETCC, MVT::v4i64, { 1 } },
3158-
{ ISD::SETCC, MVT::v8i32, { 1 } },
3159-
{ ISD::SETCC, MVT::v16i16, { 1 } },
3160-
{ ISD::SETCC, MVT::v32i8, { 1 } },
3161+
{ ISD::SETCC, MVT::v4i64, { 1, 1, 1, 2 } },
3162+
{ ISD::SETCC, MVT::v8i32, { 1, 1, 1, 2 } },
3163+
{ ISD::SETCC, MVT::v16i16, { 1, 1, 1, 2 } },
3164+
{ ISD::SETCC, MVT::v32i8, { 1, 1, 1, 2 } },
31613165

31623166
{ ISD::SELECT, MVT::v4f64, { 2, 2, 1, 2 } }, // vblendvpd
31633167
{ ISD::SELECT, MVT::v8f32, { 2, 2, 1, 2 } }, // vblendvps
@@ -3167,6 +3171,11 @@ InstructionCost X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
31673171
{ ISD::SELECT, MVT::v32i8, { 2, 2, 1, 2 } }, // pblendvb
31683172
};
31693173

3174+
static const CostKindTblEntry XOPCostTbl[] = {
3175+
{ ISD::SETCC, MVT::v4i64, { 4, 2, 5, 6 } },
3176+
{ ISD::SETCC, MVT::v2i64, { 1, 1, 1, 1 } },
3177+
};
3178+
31703179
static const CostKindTblEntry AVX1CostTbl[] = {
31713180
{ ISD::SETCC, MVT::v4f64, { 2, 3, 1, 2 } },
31723181
{ ISD::SETCC, MVT::v2f64, { 1, 3, 1, 1 } },
@@ -3176,10 +3185,10 @@ InstructionCost X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
31763185
{ ISD::SETCC, MVT::f32, { 1, 3, 1, 1 } },
31773186

31783187
// AVX1 does not support 8-wide integer compare.
3179-
{ ISD::SETCC, MVT::v4i64, { 4 } },
3180-
{ ISD::SETCC, MVT::v8i32, { 4 } },
3181-
{ ISD::SETCC, MVT::v16i16, { 4 } },
3182-
{ ISD::SETCC, MVT::v32i8, { 4 } },
3188+
{ ISD::SETCC, MVT::v4i64, { 4, 2, 5, 6 } },
3189+
{ ISD::SETCC, MVT::v8i32, { 4, 2, 5, 6 } },
3190+
{ ISD::SETCC, MVT::v16i16, { 4, 2, 5, 6 } },
3191+
{ ISD::SETCC, MVT::v32i8, { 4, 2, 5, 6 } },
31833192

31843193
{ ISD::SELECT, MVT::v4f64, { 3, 3, 1, 2 } }, // vblendvpd
31853194
{ ISD::SELECT, MVT::v8f32, { 3, 3, 1, 2 } }, // vblendvps
@@ -3190,7 +3199,7 @@ InstructionCost X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
31903199
};
31913200

31923201
static const CostKindTblEntry SSE42CostTbl[] = {
3193-
{ ISD::SETCC, MVT::v2i64, { 1 } },
3202+
{ ISD::SETCC, MVT::v2i64, { 1, 2, 1, 2 } },
31943203
};
31953204

31963205
static const CostKindTblEntry SSE41CostTbl[] = {
@@ -3211,10 +3220,10 @@ InstructionCost X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
32113220
{ ISD::SETCC, MVT::v2f64, { 2, 5, 1, 1 } },
32123221
{ ISD::SETCC, MVT::f64, { 1, 5, 1, 1 } },
32133222

3214-
{ ISD::SETCC, MVT::v2i64, { 5 } }, // pcmpeqd/pcmpgtd expansion
3215-
{ ISD::SETCC, MVT::v4i32, { 1 } },
3216-
{ ISD::SETCC, MVT::v8i16, { 1 } },
3217-
{ ISD::SETCC, MVT::v16i8, { 1 } },
3223+
{ ISD::SETCC, MVT::v2i64, { 5, 4, 5, 5 } }, // pcmpeqd/pcmpgtd expansion
3224+
{ ISD::SETCC, MVT::v4i32, { 1, 1, 1, 1 } },
3225+
{ ISD::SETCC, MVT::v8i16, { 1, 1, 1, 1 } },
3226+
{ ISD::SETCC, MVT::v16i8, { 1, 1, 1, 1 } },
32183227

32193228
{ ISD::SELECT, MVT::v2f64, { 2, 2, 3, 3 } }, // andpd + andnpd + orpd
32203229
{ ISD::SELECT, MVT::f64, { 2, 2, 3, 3 } }, // andpd + andnpd + orpd
@@ -3252,6 +3261,11 @@ InstructionCost X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
32523261
if (auto KindCost = Entry->Cost[CostKind])
32533262
return LT.first * (ExtraCost + KindCost.value());
32543263

3264+
if (ST->hasXOP())
3265+
if (const auto *Entry = CostTableLookup(XOPCostTbl, ISD, MTy))
3266+
if (auto KindCost = Entry->Cost[CostKind])
3267+
return LT.first * (ExtraCost + KindCost.value());
3268+
32553269
if (ST->hasAVX())
32563270
if (const auto *Entry = CostTableLookup(AVX1CostTbl, ISD, MTy))
32573271
if (auto KindCost = Entry->Cost[CostKind])

0 commit comments

Comments
 (0)