LLVM 24.0.0git
X86TargetTransformInfo.cpp
Go to the documentation of this file.
1//===-- X86TargetTransformInfo.cpp - X86 specific TTI pass ----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9/// This file implements a TargetTransformInfo analysis pass specific to the
10/// X86 target machine. It uses the target's detailed information to provide
11/// more precise answers to certain TTI queries, while letting the target
12/// independent and default TTI implementations handle the rest.
13///
14//===----------------------------------------------------------------------===//
15/// About Cost Model numbers used below it's necessary to say the following:
16/// the numbers correspond to some "generic" X86 CPU instead of usage of a
17/// specific CPU model. Usually the numbers correspond to the CPU where the
18/// feature first appeared. For example, if we do Subtarget.hasSSE42() in
19/// the lookups below the cost is based on Nehalem as that was the first CPU
20/// to support that feature level and thus has most likely the worst case cost,
21/// although we may discard an outlying worst cost from one CPU (e.g. Atom).
22///
23/// Some examples of other technologies/CPUs:
24/// SSE 3 - Pentium4 / Athlon64
25/// SSE 4.1 - Penryn
26/// SSE 4.2 - Nehalem / Silvermont
27/// AVX - Sandy Bridge / Jaguar / Bulldozer
28/// AVX2 - Haswell / Ryzen
29/// AVX-512 - Xeon Phi / Skylake
30///
31/// And some examples of instruction target dependent costs (latency)
32/// divss sqrtss rsqrtss
33/// AMD K7 11-16 19 3
34/// Piledriver 9-24 13-15 5
35/// Jaguar 14 16 2
36/// Pentium II,III 18 30 2
37/// Nehalem 7-14 7-18 3
38/// Haswell 10-13 11 5
39///
40/// Interpreting the 4 TargetCostKind types:
41/// TCK_RecipThroughput and TCK_Latency should try to match the worst case
42/// values reported by the CPU scheduler models (and llvm-mca).
43/// TCK_CodeSize should match the instruction count (e.g. divss = 1), NOT the
44/// actual encoding size of the instruction.
45/// TCK_SizeAndLatency should match the worst case micro-op counts reported by
46/// by the CPU scheduler models (and llvm-mca), to ensure that they are
47/// compatible with the MicroOpBufferSize and LoopMicroOpBufferSize values which are
48/// often used as the cost thresholds where TCK_SizeAndLatency is requested.
49//===----------------------------------------------------------------------===//
50
60#include <optional>
61
62using namespace llvm;
63
64#define DEBUG_TYPE "x86tti"
65
66//===----------------------------------------------------------------------===//
67//
68// X86 cost model.
69//
70//===----------------------------------------------------------------------===//
71
74
75std::optional<unsigned> X86TTIImpl::getCacheSize(
77 switch (Level) {
79 // - Penryn
80 // - Nehalem
81 // - Westmere
82 // - Sandy Bridge
83 // - Ivy Bridge
84 // - Haswell
85 // - Broadwell
86 // - Skylake
87 // - Kabylake
88 return 32 * 1024; // 32 KiB
90 // - Penryn
91 // - Nehalem
92 // - Westmere
93 // - Sandy Bridge
94 // - Ivy Bridge
95 // - Haswell
96 // - Broadwell
97 // - Skylake
98 // - Kabylake
99 return 256 * 1024; // 256 KiB
100 }
101
102 llvm_unreachable("Unknown TargetTransformInfo::CacheLevel");
103}
104
105std::optional<unsigned> X86TTIImpl::getCacheAssociativity(
107 // - Penryn
108 // - Nehalem
109 // - Westmere
110 // - Sandy Bridge
111 // - Ivy Bridge
112 // - Haswell
113 // - Broadwell
114 // - Skylake
115 // - Kabylake
116 switch (Level) {
118 [[fallthrough]];
120 return 8;
121 }
122
123 llvm_unreachable("Unknown TargetTransformInfo::CacheLevel");
124}
125
127
129 return Vector ? VectorClass
130 : Ty && Ty->isFloatingPointTy() ? ScalarFPClass
131 : GPRClass;
132}
133
134unsigned X86TTIImpl::getNumberOfRegisters(unsigned ClassID) const {
135 if (ClassID == VectorClass && !ST->hasSSE1())
136 return 0;
137
138 if (!ST->is64Bit())
139 return 8;
140
141 if ((ClassID == GPRClass && ST->hasEGPR()) ||
142 (ClassID != GPRClass && ST->hasAVX512()))
143 return 32;
144
145 return 16;
146}
147
149 // Conditional faulting load/store requires prefer-cf-mem-operand.
150 if (!ST->hasCF() || !ST->preferCFMemOperand())
151 return false;
152 if (!Ty)
153 return true;
154 // Conditional faulting is supported by CFCMOV, which only accepts
155 // 16/32/64-bit operands.
156 // TODO: Support f32/f64 with VMOVSS/VMOVSD with zero mask when it's
157 // profitable.
158 auto *VTy = dyn_cast<FixedVectorType>(Ty);
159 if (!Ty->isIntegerTy() && (!VTy || VTy->getNumElements() != 1))
160 return false;
161 auto *ScalarTy = Ty->getScalarType();
162 switch (cast<IntegerType>(ScalarTy)->getBitWidth()) {
163 default:
164 return false;
165 case 16:
166 case 32:
167 case 64:
168 return true;
169 }
170}
171
174 unsigned PreferVectorWidth = ST->getPreferVectorWidth();
175 switch (K) {
177 return TypeSize::getFixed(ST->is64Bit() ? 64 : 32);
179 if (ST->hasAVX512() && PreferVectorWidth >= 512)
180 return TypeSize::getFixed(512);
181 if (ST->hasAVX() && PreferVectorWidth >= 256)
182 return TypeSize::getFixed(256);
183 if (ST->hasSSE1() && PreferVectorWidth >= 128)
184 return TypeSize::getFixed(128);
185 return TypeSize::getFixed(0);
187 return TypeSize::getScalable(0);
188 }
189
190 llvm_unreachable("Unsupported register kind");
191}
192
197
199 bool HasUnorderedReductions) const {
200 // If the loop will not be vectorized, don't interleave the loop.
201 // Let regular unroll to unroll the loop, which saves the overflow
202 // check and memory check cost.
203 if (VF.isScalar())
204 return 1;
205
206 if (ST->isAtom())
207 return 1;
208
209 // Sandybridge and Haswell have multiple execution ports and pipelined
210 // vector units.
211 if (ST->hasAVX())
212 return 4;
213
214 return 2;
215}
216
218 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
220 ArrayRef<const Value *> Args, const Instruction *CtxI,
221 const TargetLibraryInfo *TLibInfo, ArrayRef<const Value *> Scalars) const {
222
223 // vXi8 multiplications are always promoted to vXi16.
224 // Sub-128-bit types can be extended/packed more efficiently.
225 if (Opcode == Instruction::Mul && Ty->isVectorTy() &&
226 Ty->getPrimitiveSizeInBits() <= 64 && Ty->getScalarSizeInBits() == 8) {
227 Type *WideVecTy =
229 return getCastInstrCost(Instruction::ZExt, WideVecTy, Ty,
231 CostKind) +
232 getCastInstrCost(Instruction::Trunc, Ty, WideVecTy,
234 CostKind) +
235 getArithmeticInstrCost(Opcode, WideVecTy, CostKind, Op1Info, Op2Info);
236 }
237
238 // Legalize the type.
239 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty);
240
241 int ISD = TLI->InstructionOpcodeToISD(Opcode);
242 assert(ISD && "Invalid opcode");
243
244 if (ISD == ISD::MUL && Args.size() == 2 && LT.second.isVector() &&
245 (LT.second.getScalarType() == MVT::i32 ||
246 LT.second.getScalarType() == MVT::i64)) {
247 // Check if the operands can be represented as a smaller datatype.
248 bool Op1Signed = false, Op2Signed = false;
249 unsigned Op1MinSize = BaseT::minRequiredElementSize(Args[0], Op1Signed);
250 unsigned Op2MinSize = BaseT::minRequiredElementSize(Args[1], Op2Signed);
251 unsigned OpMinSize = std::max(Op1MinSize, Op2MinSize);
252 bool SignedMode = Op1Signed || Op2Signed;
253
254 // If both vXi32 are representable as i15 and at least one is constant,
255 // zero-extended, or sign-extended from vXi16 (or less pre-SSE41) then we
256 // can treat this as PMADDWD which has the same costs as a vXi16 multiply.
257 if (OpMinSize <= 15 && !ST->isPMADDWDSlow() &&
258 LT.second.getScalarType() == MVT::i32) {
259 bool Op1Constant =
260 isa<ConstantDataVector>(Args[0]) || isa<ConstantVector>(Args[0]);
261 bool Op2Constant =
262 isa<ConstantDataVector>(Args[1]) || isa<ConstantVector>(Args[1]);
263 bool Op1Sext = isa<SExtInst>(Args[0]) &&
264 (Op1MinSize == 15 || (Op1MinSize < 15 && !ST->hasSSE41()));
265 bool Op2Sext = isa<SExtInst>(Args[1]) &&
266 (Op2MinSize == 15 || (Op2MinSize < 15 && !ST->hasSSE41()));
267
268 bool IsZeroExtended = !Op1Signed || !Op2Signed;
269 bool IsConstant = Op1Constant || Op2Constant;
270 bool IsSext = Op1Sext || Op2Sext;
271 if (IsConstant || IsZeroExtended || IsSext)
272 LT.second =
273 MVT::getVectorVT(MVT::i16, 2 * LT.second.getVectorNumElements());
274 }
275
276 // Check if the vXi32 operands can be shrunk into a smaller datatype.
277 // This should match the codegen from reduceVMULWidth.
278 // TODO: Make this generic (!ST->SSE41 || ST->isPMULLDSlow()).
279 if (ST->useSLMArithCosts() && LT.second == MVT::v4i32) {
280 if (OpMinSize <= 7)
281 return LT.first * 3; // pmullw/sext
282 if (!SignedMode && OpMinSize <= 8)
283 return LT.first * 3; // pmullw/zext
284 if (OpMinSize <= 15)
285 return LT.first * 5; // pmullw/pmulhw/pshuf
286 if (!SignedMode && OpMinSize <= 16)
287 return LT.first * 5; // pmullw/pmulhw/pshuf
288 }
289
290 // If both vXi64 are representable as (unsigned) i32, then we can perform
291 // the multiple with a single PMULUDQ instruction.
292 // TODO: Add (SSE41+) PMULDQ handling for signed extensions.
293 if (!SignedMode && OpMinSize <= 32 && LT.second.getScalarType() == MVT::i64)
294 ISD = X86ISD::PMULUDQ;
295 }
296
297 // Vector multiply by pow2 will be simplified to shifts.
298 // Vector multiply by -pow2 will be simplified to shifts/negates.
299 if (ISD == ISD::MUL && Op2Info.isConstant() &&
300 (Op2Info.isPowerOf2() || Op2Info.isNegatedPowerOf2())) {
302 getArithmeticInstrCost(Instruction::Shl, Ty, CostKind,
303 Op1Info.getNoProps(), Op2Info.getNoProps());
304 if (Op2Info.isNegatedPowerOf2())
305 Cost += getArithmeticInstrCost(Instruction::Sub, Ty, CostKind);
306 return Cost;
307 }
308
309 // On X86, vector signed division by constants power-of-two are
310 // normally expanded to the sequence SRA + SRL + ADD + SRA.
311 // The OperandValue properties may not be the same as that of the previous
312 // operation; conservatively assume OP_None.
313 if ((ISD == ISD::SDIV || ISD == ISD::SREM) &&
314 Op2Info.isConstant() && Op2Info.isPowerOf2()) {
316 2 * getArithmeticInstrCost(Instruction::AShr, Ty, CostKind,
317 Op1Info.getNoProps(), Op2Info.getNoProps());
318 Cost += getArithmeticInstrCost(Instruction::LShr, Ty, CostKind,
319 Op1Info.getNoProps(), Op2Info.getNoProps());
320 Cost += getArithmeticInstrCost(Instruction::Add, Ty, CostKind,
321 Op1Info.getNoProps(), Op2Info.getNoProps());
322
323 if (ISD == ISD::SREM) {
324 // For SREM: (X % C) is the equivalent of (X - (X/C)*C)
325 Cost += getArithmeticInstrCost(Instruction::Mul, Ty, CostKind, Op1Info.getNoProps(),
326 Op2Info.getNoProps());
327 Cost += getArithmeticInstrCost(Instruction::Sub, Ty, CostKind, Op1Info.getNoProps(),
328 Op2Info.getNoProps());
329 }
330
331 return Cost;
332 }
333
334 // Vector unsigned division/remainder will be simplified to shifts/masks.
335 if ((ISD == ISD::UDIV || ISD == ISD::UREM) &&
336 Op2Info.isConstant() && Op2Info.isPowerOf2()) {
337 if (ISD == ISD::UDIV)
338 return getArithmeticInstrCost(Instruction::LShr, Ty, CostKind,
339 Op1Info.getNoProps(), Op2Info.getNoProps());
340 // UREM
341 return getArithmeticInstrCost(Instruction::And, Ty, CostKind,
342 Op1Info.getNoProps(), Op2Info.getNoProps());
343 }
344
345 // A rem paired with a div on the same operands in the same block is free:
346 // the pair costs the div alone. Power-of-two divisors are handled above.
347 if ((ISD == ISD::UREM || ISD == ISD::SREM) && CostKind != TTI::TCK_Latency &&
348 CtxI && CtxI->getOpcode() == Opcode) {
349 using namespace PatternMatch;
350 // Same use limit as SLP, bounds the walk over the operand users.
351 constexpr unsigned MaxUses = 64;
352 unsigned DivOpcode =
353 ISD == ISD::SREM ? Instruction::SDiv : Instruction::UDiv;
354 const Value *X = CtxI->getOperand(0);
355 const Value *Y = CtxI->getOperand(1);
356 // Constants have context-wide use lists, walk the variable operand.
357 const Value *V = isa<Constant>(Y) ? X : Y;
358 if (!isa<Constant>(V) && !V->hasNUsesOrMore(MaxUses) &&
359 any_of(V->users(), [&](const User *U) {
360 return match(U, m_BinOp(DivOpcode, m_Specific(X), m_Specific(Y))) &&
361 cast<Instruction>(U)->getParent() == CtxI->getParent();
362 }))
363 return TTI::TCC_Free;
364 }
365
366 // A scalar integer divide/remainder by a constant is not a hardware divide;
367 // it lowers to a magic-number multiply-high plus a few fixup ops. Cost it as
368 // that sequence rather than the generic single-instruction divide, so the
369 // vectorizers do not compare against an artificially cheap scalar lane. The
370 // power-of-two cases are handled above; negated powers of two are left to the
371 // generic handling.
372 if (!Ty->isVectorTy() && Op2Info.isConstant() && !Op2Info.isNegatedPowerOf2() &&
373 (ISD == ISD::UDIV || ISD == ISD::SDIV || ISD == ISD::UREM ||
374 ISD == ISD::SREM)) {
375 unsigned Cost = ISD == ISD::UREM || ISD == ISD::SREM ? 6 : 5;
376 if (CostKind == TTI::TCK_CodeSize || CostKind == TTI::TCK_SizeAndLatency)
377 Cost += 2;
378 return LT.first * Cost;
379 }
380
381 static const CostKindTblEntry GFNIUniformConstCostTable[] = {
382 { ISD::SHL, MVT::v16i8, { 1, 6, 1, 2 } }, // gf2p8affineqb
383 { ISD::SRL, MVT::v16i8, { 1, 6, 1, 2 } }, // gf2p8affineqb
384 { ISD::SRA, MVT::v16i8, { 1, 6, 1, 2 } }, // gf2p8affineqb
385 { ISD::SHL, MVT::v32i8, { 1, 6, 1, 2 } }, // gf2p8affineqb
386 { ISD::SRL, MVT::v32i8, { 1, 6, 1, 2 } }, // gf2p8affineqb
387 { ISD::SRA, MVT::v32i8, { 1, 6, 1, 2 } }, // gf2p8affineqb
388 { ISD::SHL, MVT::v64i8, { 1, 6, 1, 2 } }, // gf2p8affineqb
389 { ISD::SRL, MVT::v64i8, { 1, 6, 1, 2 } }, // gf2p8affineqb
390 { ISD::SRA, MVT::v64i8, { 1, 6, 1, 2 } }, // gf2p8affineqb
391 };
392
393 if (Op2Info.isUniform() && Op2Info.isConstant() && ST->hasGFNI())
394 if (const auto *Entry =
395 CostTableLookup(GFNIUniformConstCostTable, ISD, LT.second))
396 if (auto KindCost = Entry->Cost[CostKind])
397 return LT.first * *KindCost;
398
399 static const CostKindTblEntry AVX512BWUniformConstCostTable[] = {
400 { ISD::SHL, MVT::v16i8, { 1, 7, 2, 3 } }, // psllw + pand.
401 { ISD::SRL, MVT::v16i8, { 1, 7, 2, 3 } }, // psrlw + pand.
402 { ISD::SRA, MVT::v16i8, { 1, 8, 4, 5 } }, // psrlw, pand, pxor, psubb.
403 { ISD::SHL, MVT::v32i8, { 1, 8, 2, 3 } }, // psllw + pand.
404 { ISD::SRL, MVT::v32i8, { 1, 8, 2, 3 } }, // psrlw + pand.
405 { ISD::SRA, MVT::v32i8, { 1, 9, 4, 5 } }, // psrlw, pand, pxor, psubb.
406 { ISD::SHL, MVT::v64i8, { 1, 8, 2, 3 } }, // psllw + pand.
407 { ISD::SRL, MVT::v64i8, { 1, 8, 2, 3 } }, // psrlw + pand.
408 { ISD::SRA, MVT::v64i8, { 1, 9, 4, 6 } }, // psrlw, pand, pxor, psubb.
409
410 { ISD::SHL, MVT::v16i16, { 1, 1, 1, 1 } }, // psllw
411 { ISD::SRL, MVT::v16i16, { 1, 1, 1, 1 } }, // psrlw
412 { ISD::SRA, MVT::v16i16, { 1, 1, 1, 1 } }, // psrlw
413 { ISD::SHL, MVT::v32i16, { 1, 1, 1, 1 } }, // psllw
414 { ISD::SRL, MVT::v32i16, { 1, 1, 1, 1 } }, // psrlw
415 { ISD::SRA, MVT::v32i16, { 1, 1, 1, 1 } }, // psrlw
416 };
417
418 if (Op2Info.isUniform() && Op2Info.isConstant() && ST->hasBWI())
419 if (const auto *Entry =
420 CostTableLookup(AVX512BWUniformConstCostTable, ISD, LT.second))
421 if (auto KindCost = Entry->Cost[CostKind])
422 return LT.first * *KindCost;
423
424 static const CostKindTblEntry AVX512DQUniformConstCostTable[] = {
425 { ISD::SDIV, MVT::v4i64, { 15 } }, // vpmullq-based MULHS sequence
426 { ISD::SREM, MVT::v4i64, { 17 } }, // vpmullq-based MULHS+mul+sub sequence
427 { ISD::SDIV, MVT::v8i64, { 15 } }, // vpmullq-based MULHS sequence
428 { ISD::SREM, MVT::v8i64, { 17 } }, // vpmullq-based MULHS+mul+sub sequence
429 // The remainder's multiply-back is a single vpmullq with DQ, just like the
430 // pmulld the vXi32 entries above rely on. Without DQ it is another
431 // vpmuludq schoolbook, so the AVX512/AVX2 tables charge more.
432 { ISD::UREM, MVT::v4i64, { 17 } }, // MULHU + vpmullq + sub sequence
433 { ISD::UREM, MVT::v8i64, { 17 } }, // MULHU + vpmullq + sub sequence
434 };
435
436 if (Op2Info.isUniform() && Op2Info.isConstant() && ST->hasDQI())
437 if (const auto *Entry =
438 CostTableLookup(AVX512DQUniformConstCostTable, ISD, LT.second))
439 if (auto KindCost = Entry->Cost[CostKind])
440 return LT.first * *KindCost;
441
442 static const CostKindTblEntry AVX512UniformConstCostTable[] = {
443 { ISD::SHL, MVT::v64i8, { 2, 12, 5, 6 } }, // psllw + pand.
444 { ISD::SRL, MVT::v64i8, { 2, 12, 5, 6 } }, // psrlw + pand.
445 { ISD::SRA, MVT::v64i8, { 3, 10, 12, 12 } }, // psrlw, pand, pxor, psubb.
446
447 { ISD::SHL, MVT::v16i16, { 2, 7, 4, 4 } }, // psllw + split.
448 { ISD::SRL, MVT::v16i16, { 2, 7, 4, 4 } }, // psrlw + split.
449 { ISD::SRA, MVT::v16i16, { 2, 7, 4, 4 } }, // psraw + split.
450
451 { ISD::SHL, MVT::v8i32, { 1, 1, 1, 1 } }, // pslld
452 { ISD::SRL, MVT::v8i32, { 1, 1, 1, 1 } }, // psrld
453 { ISD::SRA, MVT::v8i32, { 1, 1, 1, 1 } }, // psrad
454 { ISD::SHL, MVT::v16i32, { 1, 1, 1, 1 } }, // pslld
455 { ISD::SRL, MVT::v16i32, { 1, 1, 1, 1 } }, // psrld
456 { ISD::SRA, MVT::v16i32, { 1, 1, 1, 1 } }, // psrad
457
458 { ISD::SRA, MVT::v2i64, { 1, 1, 1, 1 } }, // psraq
459 { ISD::SHL, MVT::v4i64, { 1, 1, 1, 1 } }, // psllq
460 { ISD::SRL, MVT::v4i64, { 1, 1, 1, 1 } }, // psrlq
461 { ISD::SRA, MVT::v4i64, { 1, 1, 1, 1 } }, // psraq
462 { ISD::SHL, MVT::v8i64, { 1, 1, 1, 1 } }, // psllq
463 { ISD::SRL, MVT::v8i64, { 1, 1, 1, 1 } }, // psrlq
464 { ISD::SRA, MVT::v8i64, { 1, 1, 1, 1 } }, // psraq
465
466 { ISD::SDIV, MVT::v16i32, { 6 } }, // pmuludq sequence
467 { ISD::SREM, MVT::v16i32, { 8 } }, // pmuludq+mul+sub sequence
468 { ISD::UDIV, MVT::v16i32, { 5 } }, // pmuludq sequence
469 { ISD::UREM, MVT::v16i32, { 7 } }, // pmuludq+mul+sub sequence
470
471 { ISD::UDIV, MVT::v8i64, { 15 } }, // pmuludq-based MULHU sequence
472 { ISD::UREM, MVT::v8i64, { 21 } }, // pmuludq-based MULHU+mul+sub sequence
473 };
474
475 if (Op2Info.isUniform() && Op2Info.isConstant() && ST->hasAVX512())
476 if (const auto *Entry =
477 CostTableLookup(AVX512UniformConstCostTable, ISD, LT.second))
478 if (auto KindCost = Entry->Cost[CostKind])
479 return LT.first * *KindCost;
480
481 static const CostKindTblEntry AVX2UniformConstCostTable[] = {
482 { ISD::SHL, MVT::v16i8, { 1, 8, 2, 3 } }, // psllw + pand.
483 { ISD::SRL, MVT::v16i8, { 1, 8, 2, 3 } }, // psrlw + pand.
484 { ISD::SRA, MVT::v16i8, { 2, 10, 5, 6 } }, // psrlw, pand, pxor, psubb.
485 { ISD::SHL, MVT::v32i8, { 2, 8, 2, 4 } }, // psllw + pand.
486 { ISD::SRL, MVT::v32i8, { 2, 8, 2, 4 } }, // psrlw + pand.
487 { ISD::SRA, MVT::v32i8, { 3, 10, 5, 9 } }, // psrlw, pand, pxor, psubb.
488
489 { ISD::SHL, MVT::v8i16, { 1, 1, 1, 1 } }, // psllw
490 { ISD::SRL, MVT::v8i16, { 1, 1, 1, 1 } }, // psrlw
491 { ISD::SRA, MVT::v8i16, { 1, 1, 1, 1 } }, // psraw
492 { ISD::SHL, MVT::v16i16,{ 2, 2, 1, 2 } }, // psllw
493 { ISD::SRL, MVT::v16i16,{ 2, 2, 1, 2 } }, // psrlw
494 { ISD::SRA, MVT::v16i16,{ 2, 2, 1, 2 } }, // psraw
495
496 { ISD::SHL, MVT::v4i32, { 1, 1, 1, 1 } }, // pslld
497 { ISD::SRL, MVT::v4i32, { 1, 1, 1, 1 } }, // psrld
498 { ISD::SRA, MVT::v4i32, { 1, 1, 1, 1 } }, // psrad
499 { ISD::SHL, MVT::v8i32, { 2, 2, 1, 2 } }, // pslld
500 { ISD::SRL, MVT::v8i32, { 2, 2, 1, 2 } }, // psrld
501 { ISD::SRA, MVT::v8i32, { 2, 2, 1, 2 } }, // psrad
502
503 { ISD::SHL, MVT::v2i64, { 1, 1, 1, 1 } }, // psllq
504 { ISD::SRL, MVT::v2i64, { 1, 1, 1, 1 } }, // psrlq
505 { ISD::SRA, MVT::v2i64, { 2, 3, 3, 3 } }, // psrad + shuffle.
506 { ISD::SHL, MVT::v4i64, { 2, 2, 1, 2 } }, // psllq
507 { ISD::SRL, MVT::v4i64, { 2, 2, 1, 2 } }, // psrlq
508 { ISD::SRA, MVT::v4i64, { 4, 4, 3, 6 } }, // psrad + shuffle + split.
509
510 { ISD::SDIV, MVT::v8i32, { 6 } }, // pmuludq sequence
511 { ISD::SREM, MVT::v8i32, { 8 } }, // pmuludq+mul+sub sequence
512 { ISD::UDIV, MVT::v8i32, { 5 } }, // pmuludq sequence
513 { ISD::UREM, MVT::v8i32, { 7 } }, // pmuludq+mul+sub sequence
514
515 { ISD::UDIV, MVT::v4i64, { 15 } }, // pmuludq-based MULHU sequence
516 { ISD::UREM, MVT::v4i64, { 21 } }, // pmuludq-based MULHU+mul+sub sequence
517 };
518
519 if (Op2Info.isUniform() && Op2Info.isConstant() && ST->hasAVX2())
520 if (const auto *Entry =
521 CostTableLookup(AVX2UniformConstCostTable, ISD, LT.second))
522 if (auto KindCost = Entry->Cost[CostKind])
523 return LT.first * *KindCost;
524
525 static const CostKindTblEntry AVXUniformConstCostTable[] = {
526 { ISD::SHL, MVT::v16i8, { 2, 7, 2, 3 } }, // psllw + pand.
527 { ISD::SRL, MVT::v16i8, { 2, 7, 2, 3 } }, // psrlw + pand.
528 { ISD::SRA, MVT::v16i8, { 3, 9, 5, 6 } }, // psrlw, pand, pxor, psubb.
529 { ISD::SHL, MVT::v32i8, { 4, 7, 7, 8 } }, // 2*(psllw + pand) + split.
530 { ISD::SRL, MVT::v32i8, { 4, 7, 7, 8 } }, // 2*(psrlw + pand) + split.
531 { ISD::SRA, MVT::v32i8, { 7, 7, 12, 13 } }, // 2*(psrlw, pand, pxor, psubb) + split.
532
533 { ISD::SHL, MVT::v8i16, { 1, 2, 1, 1 } }, // psllw.
534 { ISD::SRL, MVT::v8i16, { 1, 2, 1, 1 } }, // psrlw.
535 { ISD::SRA, MVT::v8i16, { 1, 2, 1, 1 } }, // psraw.
536 { ISD::SHL, MVT::v16i16,{ 3, 6, 4, 5 } }, // psllw + split.
537 { ISD::SRL, MVT::v16i16,{ 3, 6, 4, 5 } }, // psrlw + split.
538 { ISD::SRA, MVT::v16i16,{ 3, 6, 4, 5 } }, // psraw + split.
539
540 { ISD::SHL, MVT::v4i32, { 1, 2, 1, 1 } }, // pslld.
541 { ISD::SRL, MVT::v4i32, { 1, 2, 1, 1 } }, // psrld.
542 { ISD::SRA, MVT::v4i32, { 1, 2, 1, 1 } }, // psrad.
543 { ISD::SHL, MVT::v8i32, { 3, 6, 4, 5 } }, // pslld + split.
544 { ISD::SRL, MVT::v8i32, { 3, 6, 4, 5 } }, // psrld + split.
545 { ISD::SRA, MVT::v8i32, { 3, 6, 4, 5 } }, // psrad + split.
546
547 { ISD::SHL, MVT::v2i64, { 1, 2, 1, 1 } }, // psllq.
548 { ISD::SRL, MVT::v2i64, { 1, 2, 1, 1 } }, // psrlq.
549 { ISD::SRA, MVT::v2i64, { 2, 3, 3, 3 } }, // psrad + shuffle.
550 { ISD::SHL, MVT::v4i64, { 3, 6, 4, 5 } }, // 2 x psllq + split.
551 { ISD::SRL, MVT::v4i64, { 3, 6, 4, 5 } }, // 2 x psllq + split.
552 { ISD::SRA, MVT::v4i64, { 5, 7, 8, 9 } }, // 2 x psrad + shuffle + split.
553
554 { ISD::SDIV, MVT::v8i32, { 14 } }, // 2*pmuludq sequence + split.
555 { ISD::SREM, MVT::v8i32, { 18 } }, // 2*pmuludq+mul+sub sequence + split.
556 { ISD::UDIV, MVT::v8i32, { 12 } }, // 2*pmuludq sequence + split.
557 { ISD::UREM, MVT::v8i32, { 16 } }, // 2*pmuludq+mul+sub sequence + split.
558 };
559
560 // XOP has faster vXi8 shifts.
561 if (Op2Info.isUniform() && Op2Info.isConstant() && ST->hasAVX() &&
562 (!ST->hasXOP() || LT.second.getScalarSizeInBits() != 8))
563 if (const auto *Entry =
564 CostTableLookup(AVXUniformConstCostTable, ISD, LT.second))
565 if (auto KindCost = Entry->Cost[CostKind])
566 return LT.first * *KindCost;
567
568 static const CostKindTblEntry SSE2UniformConstCostTable[] = {
569 { ISD::SHL, MVT::v16i8, { 1, 7, 2, 3 } }, // psllw + pand.
570 { ISD::SRL, MVT::v16i8, { 1, 7, 2, 3 } }, // psrlw + pand.
571 { ISD::SRA, MVT::v16i8, { 3, 9, 5, 6 } }, // psrlw, pand, pxor, psubb.
572
573 { ISD::SHL, MVT::v8i16, { 1, 1, 1, 1 } }, // psllw.
574 { ISD::SRL, MVT::v8i16, { 1, 1, 1, 1 } }, // psrlw.
575 { ISD::SRA, MVT::v8i16, { 1, 1, 1, 1 } }, // psraw.
576
577 { ISD::SHL, MVT::v4i32, { 1, 1, 1, 1 } }, // pslld
578 { ISD::SRL, MVT::v4i32, { 1, 1, 1, 1 } }, // psrld.
579 { ISD::SRA, MVT::v4i32, { 1, 1, 1, 1 } }, // psrad.
580
581 { ISD::SHL, MVT::v2i64, { 1, 1, 1, 1 } }, // psllq.
582 { ISD::SRL, MVT::v2i64, { 1, 1, 1, 1 } }, // psrlq.
583 { ISD::SRA, MVT::v2i64, { 3, 5, 6, 6 } }, // 2 x psrad + shuffle.
584
585 { ISD::SDIV, MVT::v4i32, { 6 } }, // pmuludq sequence
586 { ISD::SREM, MVT::v4i32, { 8 } }, // pmuludq+mul+sub sequence
587 { ISD::UDIV, MVT::v4i32, { 5 } }, // pmuludq sequence
588 { ISD::UREM, MVT::v4i32, { 7 } }, // pmuludq+mul+sub sequence
589 };
590
591 // XOP has faster vXi8 shifts.
592 if (Op2Info.isUniform() && Op2Info.isConstant() && ST->hasSSE2() &&
593 (!ST->hasXOP() || LT.second.getScalarSizeInBits() != 8))
594 if (const auto *Entry =
595 CostTableLookup(SSE2UniformConstCostTable, ISD, LT.second))
596 if (auto KindCost = Entry->Cost[CostKind])
597 return LT.first * *KindCost;
598
599 static const CostKindTblEntry AVX512BWConstCostTable[] = {
600 { ISD::SDIV, MVT::v64i8, { 14 } }, // 2*ext+2*pmulhw sequence
601 { ISD::SREM, MVT::v64i8, { 16 } }, // 2*ext+2*pmulhw+mul+sub sequence
602 { ISD::UDIV, MVT::v64i8, { 14 } }, // 2*ext+2*pmulhw sequence
603 { ISD::UREM, MVT::v64i8, { 16 } }, // 2*ext+2*pmulhw+mul+sub sequence
604
605 { ISD::SDIV, MVT::v32i16, { 6 } }, // vpmulhw sequence
606 { ISD::SREM, MVT::v32i16, { 8 } }, // vpmulhw+mul+sub sequence
607 { ISD::UDIV, MVT::v32i16, { 6 } }, // vpmulhuw sequence
608 { ISD::UREM, MVT::v32i16, { 8 } }, // vpmulhuw+mul+sub sequence
609 };
610
611 if (Op2Info.isConstant() && ST->hasBWI())
612 if (const auto *Entry =
613 CostTableLookup(AVX512BWConstCostTable, ISD, LT.second))
614 if (auto KindCost = Entry->Cost[CostKind])
615 return LT.first * *KindCost;
616
617 static const CostKindTblEntry AVX512DQConstCostTable[] = {
618 { ISD::SDIV, MVT::v4i64, { 19 } }, // vpmullq-based MULHS sequence
619 { ISD::SREM, MVT::v4i64, { 21 } }, // vpmullq-based MULHS+mul+sub sequence
620 { ISD::SDIV, MVT::v8i64, { 19 } }, // vpmullq-based MULHS sequence
621 { ISD::SREM, MVT::v8i64, { 21 } }, // vpmullq-based MULHS+mul+sub sequence
622 // The remainder's multiply-back is a single vpmullq with DQ, whereas the
623 // AVX512/AVX2 tables have to charge for another vpmuludq schoolbook.
624 { ISD::UREM, MVT::v4i64, { 24 } }, // MULHU + vpmullq + sub sequence
625 { ISD::UREM, MVT::v8i64, { 24 } }, // MULHU + vpmullq + sub sequence
626 };
627
628 if (Op2Info.isConstant() && ST->hasDQI())
629 if (const auto *Entry =
630 CostTableLookup(AVX512DQConstCostTable, ISD, LT.second))
631 if (auto KindCost = Entry->Cost[CostKind])
632 return LT.first * *KindCost;
633
634 static const CostKindTblEntry AVX512ConstCostTable[] = {
635 { ISD::SDIV, MVT::v64i8, { 28 } }, // 4*ext+4*pmulhw sequence
636 { ISD::SREM, MVT::v64i8, { 32 } }, // 4*ext+4*pmulhw+mul+sub sequence
637 { ISD::UDIV, MVT::v64i8, { 28 } }, // 4*ext+4*pmulhw sequence
638 { ISD::UREM, MVT::v64i8, { 32 } }, // 4*ext+4*pmulhw+mul+sub sequence
639
640 { ISD::SDIV, MVT::v32i16, { 12 } }, // 2*vpmulhw sequence
641 { ISD::SREM, MVT::v32i16, { 16 } }, // 2*vpmulhw+mul+sub sequence
642 { ISD::UDIV, MVT::v32i16, { 12 } }, // 2*vpmulhuw sequence
643 { ISD::UREM, MVT::v32i16, { 16 } }, // 2*vpmulhuw+mul+sub sequence
644
645 { ISD::SDIV, MVT::v16i32, { 15 } }, // vpmuldq sequence
646 { ISD::SREM, MVT::v16i32, { 17 } }, // vpmuldq+mul+sub sequence
647 { ISD::UDIV, MVT::v16i32, { 15 } }, // vpmuludq sequence
648 { ISD::UREM, MVT::v16i32, { 17 } }, // vpmuludq+mul+sub sequence
649
650 { ISD::UDIV, MVT::v8i64, { 22 } }, // vpmuludq-based MULHU sequence
651 { ISD::UREM, MVT::v8i64, { 28 } }, // vpmuludq-based MULHU+mul+sub sequence
652 };
653
654 if (Op2Info.isConstant() && ST->hasAVX512())
655 if (const auto *Entry =
656 CostTableLookup(AVX512ConstCostTable, ISD, LT.second))
657 if (auto KindCost = Entry->Cost[CostKind])
658 return LT.first * *KindCost;
659
660 static const CostKindTblEntry AVX2ConstCostTable[] = {
661 { ISD::SDIV, MVT::v32i8, { 14 } }, // 2*ext+2*pmulhw sequence
662 { ISD::SREM, MVT::v32i8, { 16 } }, // 2*ext+2*pmulhw+mul+sub sequence
663 { ISD::UDIV, MVT::v32i8, { 14 } }, // 2*ext+2*pmulhw sequence
664 { ISD::UREM, MVT::v32i8, { 16 } }, // 2*ext+2*pmulhw+mul+sub sequence
665
666 { ISD::SDIV, MVT::v16i16, { 6 } }, // vpmulhw sequence
667 { ISD::SREM, MVT::v16i16, { 8 } }, // vpmulhw+mul+sub sequence
668 { ISD::UDIV, MVT::v16i16, { 6 } }, // vpmulhuw sequence
669 { ISD::UREM, MVT::v16i16, { 8 } }, // vpmulhuw+mul+sub sequence
670
671 { ISD::SDIV, MVT::v8i32, { 15 } }, // vpmuldq sequence
672 { ISD::SREM, MVT::v8i32, { 19 } }, // vpmuldq+mul+sub sequence
673 { ISD::UDIV, MVT::v8i32, { 15 } }, // vpmuludq sequence
674 { ISD::UREM, MVT::v8i32, { 19 } }, // vpmuludq+mul+sub sequence
675
676 { ISD::UDIV, MVT::v4i64, { 22 } }, // vpmuludq-based MULHU sequence
677 { ISD::UREM, MVT::v4i64, { 28 } }, // vpmuludq-based MULHU+mul+sub sequence
678 };
679
680 if (Op2Info.isConstant() && ST->hasAVX2())
681 if (const auto *Entry = CostTableLookup(AVX2ConstCostTable, ISD, LT.second))
682 if (auto KindCost = Entry->Cost[CostKind])
683 return LT.first * *KindCost;
684
685 static const CostKindTblEntry AVXConstCostTable[] = {
686 { ISD::SDIV, MVT::v32i8, { 30 } }, // 4*ext+4*pmulhw sequence + split.
687 { ISD::SREM, MVT::v32i8, { 34 } }, // 4*ext+4*pmulhw+mul+sub sequence + split.
688 { ISD::UDIV, MVT::v32i8, { 30 } }, // 4*ext+4*pmulhw sequence + split.
689 { ISD::UREM, MVT::v32i8, { 34 } }, // 4*ext+4*pmulhw+mul+sub sequence + split.
690
691 { ISD::SDIV, MVT::v16i16, { 14 } }, // 2*pmulhw sequence + split.
692 { ISD::SREM, MVT::v16i16, { 18 } }, // 2*pmulhw+mul+sub sequence + split.
693 { ISD::UDIV, MVT::v16i16, { 14 } }, // 2*pmulhuw sequence + split.
694 { ISD::UREM, MVT::v16i16, { 18 } }, // 2*pmulhuw+mul+sub sequence + split.
695
696 { ISD::SDIV, MVT::v8i32, { 32 } }, // vpmuludq sequence
697 { ISD::SREM, MVT::v8i32, { 38 } }, // vpmuludq+mul+sub sequence
698 { ISD::UDIV, MVT::v8i32, { 32 } }, // 2*pmuludq sequence + split.
699 { ISD::UREM, MVT::v8i32, { 42 } }, // 2*pmuludq+mul+sub sequence + split.
700 };
701
702 if (Op2Info.isConstant() && ST->hasAVX())
703 if (const auto *Entry = CostTableLookup(AVXConstCostTable, ISD, LT.second))
704 if (auto KindCost = Entry->Cost[CostKind])
705 return LT.first * *KindCost;
706
707 static const CostKindTblEntry SSE41ConstCostTable[] = {
708 { ISD::SDIV, MVT::v4i32, { 15 } }, // vpmuludq sequence
709 { ISD::SREM, MVT::v4i32, { 20 } }, // vpmuludq+mul+sub sequence
710 };
711
712 if (Op2Info.isConstant() && ST->hasSSE41())
713 if (const auto *Entry =
714 CostTableLookup(SSE41ConstCostTable, ISD, LT.second))
715 if (auto KindCost = Entry->Cost[CostKind])
716 return LT.first * *KindCost;
717
718 static const CostKindTblEntry SSE2ConstCostTable[] = {
719 { ISD::SDIV, MVT::v16i8, { 14 } }, // 2*ext+2*pmulhw sequence
720 { ISD::SREM, MVT::v16i8, { 16 } }, // 2*ext+2*pmulhw+mul+sub sequence
721 { ISD::UDIV, MVT::v16i8, { 14 } }, // 2*ext+2*pmulhw sequence
722 { ISD::UREM, MVT::v16i8, { 16 } }, // 2*ext+2*pmulhw+mul+sub sequence
723
724 { ISD::SDIV, MVT::v8i16, { 6 } }, // pmulhw sequence
725 { ISD::SREM, MVT::v8i16, { 8 } }, // pmulhw+mul+sub sequence
726 { ISD::UDIV, MVT::v8i16, { 6 } }, // pmulhuw sequence
727 { ISD::UREM, MVT::v8i16, { 8 } }, // pmulhuw+mul+sub sequence
728
729 { ISD::SDIV, MVT::v4i32, { 19 } }, // pmuludq sequence
730 { ISD::SREM, MVT::v4i32, { 24 } }, // pmuludq+mul+sub sequence
731 { ISD::UDIV, MVT::v4i32, { 15 } }, // pmuludq sequence
732 { ISD::UREM, MVT::v4i32, { 20 } }, // pmuludq+mul+sub sequence
733 };
734
735 if (Op2Info.isConstant() && ST->hasSSE2())
736 if (const auto *Entry = CostTableLookup(SSE2ConstCostTable, ISD, LT.second))
737 if (auto KindCost = Entry->Cost[CostKind])
738 return LT.first * *KindCost;
739
740 // rem matches div because the divider returns the remainder for free.
741 static const CostKindTblEntry ScalarVarDivCostTable[] = {
742 { ISD::SDIV, MVT::i8, { 15, 20, 2, 4 } },
743 { ISD::UDIV, MVT::i8, { 15, 20, 2, 4 } },
744 { ISD::SREM, MVT::i8, { 15, 20, 2, 4 } },
745 { ISD::UREM, MVT::i8, { 15, 20, 2, 4 } },
746 { ISD::SDIV, MVT::i16, { 17, 20, 2, 4 } },
747 { ISD::UDIV, MVT::i16, { 17, 20, 2, 4 } },
748 { ISD::SREM, MVT::i16, { 17, 20, 2, 4 } },
749 { ISD::UREM, MVT::i16, { 17, 20, 2, 4 } },
750 { ISD::SDIV, MVT::i32, { 25, 22, 2, 4 } },
751 { ISD::UDIV, MVT::i32, { 25, 22, 2, 4 } },
752 { ISD::SREM, MVT::i32, { 25, 22, 2, 4 } },
753 { ISD::UREM, MVT::i32, { 25, 22, 2, 4 } },
754 { ISD::SDIV, MVT::i64, { 41, 24, 2, 4 } },
755 { ISD::UDIV, MVT::i64, { 41, 24, 2, 4 } },
756 { ISD::SREM, MVT::i64, { 41, 24, 2, 4 } },
757 { ISD::UREM, MVT::i64, { 41, 24, 2, 4 } },
758 };
759
760 if (!LT.second.isVector() && !Op2Info.isConstant())
761 if (const auto *Entry =
762 CostTableLookup(ScalarVarDivCostTable, ISD, LT.second))
763 if (auto KindCost = Entry->Cost[CostKind])
764 return LT.first * *KindCost;
765
766 // Variable divisors lower through a float divide. strictfp needs SAE
767 // rounding which is 512-bit only.
768 bool IsStrictFP =
769 CtxI && CtxI->getFunction()->hasFnAttribute(Attribute::StrictFP);
770 bool IsDivRem = ISD == ISD::UDIV || ISD == ISD::SDIV || ISD == ISD::UREM ||
771 ISD == ISD::SREM;
772 bool VarDivToFP = IsDivRem && !Op2Info.isConstant() &&
773 (!IsStrictFP || ST->useAVX512Regs());
774
775 // i64 needs the qq converts, which are AVX512DQ only. Two tables because the
776 // lowering picks by operand value and not by type.
777 static const CostKindTblEntry AVX512DQExactVarDivCostTable[] = {
778 { ISD::UDIV, MVT::v2i64, { 5 } }, // cvt+divpd sequence
779 { ISD::SDIV, MVT::v2i64, { 5 } },
780 { ISD::UREM, MVT::v2i64, { 5 } },
781 { ISD::SREM, MVT::v2i64, { 5 } },
782 { ISD::UDIV, MVT::v4i64, { 8 } },
783 { ISD::SDIV, MVT::v4i64, { 8 } },
784 { ISD::UREM, MVT::v4i64, { 8 } },
785 { ISD::SREM, MVT::v4i64, { 8 } },
786 { ISD::UDIV, MVT::v8i64, { 16 } },
787 { ISD::SDIV, MVT::v8i64, { 16 } },
788 { ISD::UREM, MVT::v8i64, { 16 } },
789 { ISD::SREM, MVT::v8i64, { 16 } },
790 };
791
792 static const CostKindTblEntry AVX512DQVarDivCostTable[] = {
793 { ISD::UDIV, MVT::v2i64, { 16 } },
794 { ISD::SDIV, MVT::v2i64, { 16 } },
795 { ISD::UREM, MVT::v2i64, { 16 } },
796 { ISD::SREM, MVT::v2i64, { 16 } },
797 { ISD::UDIV, MVT::v4i64, { 16 } },
798 { ISD::SDIV, MVT::v4i64, { 16 } },
799 { ISD::UREM, MVT::v4i64, { 16 } },
800 { ISD::SREM, MVT::v4i64, { 16 } },
801 { ISD::UDIV, MVT::v8i64, { 16 } },
802 { ISD::SDIV, MVT::v8i64, { 18 } },
803 { ISD::UREM, MVT::v8i64, { 16 } },
804 { ISD::SREM, MVT::v8i64, { 18 } },
805 };
806
807 // The DAG combine picks between the two sequences with these same two
808 // queries, so the cost cannot disagree with what codegen emits.
809 bool IsSignedDiv = ISD == ISD::SDIV || ISD == ISD::SREM;
810 auto OperandsFit = [&](unsigned Mantissa) {
811 if (Args.size() != 2 || !CtxI)
812 return false;
813 unsigned EltBits = LT.second.getScalarSizeInBits();
814 const DataLayout &DL = CtxI->getDataLayout();
815 auto Fits = [&](const Value *V) {
816 if (IsSignedDiv)
817 return ComputeNumSignBits(V, DL, /*AC=*/nullptr, CtxI) + Mantissa >
818 EltBits;
819 return computeKnownBits(V, DL, /*AC=*/nullptr, CtxI)
820 .countMaxActiveBits() <= Mantissa;
821 };
822 return Fits(Args[0]) && Fits(Args[1]);
823 };
824
825 // An i32 divide goes through f32 when both operands fit in 24 bits, and
826 // through f64 at twice the vector width when they do not.
827 bool ExactI32 =
828 VarDivToFP && LT.second.getScalarType() == MVT::i32 &&
830
831 if (VarDivToFP && ST->hasDQI() && ST->useAVX512Regs() &&
832 LT.second.getScalarType() == MVT::i64) {
833 bool ExactFPDiv =
835
836 // Only the reciprocal chain multiplies, so only it is vpmullq gated.
837 bool SlowMultiply =
838 !ExactFPDiv && LT.second == MVT::v2i64 && ST->isPMULLQSlow();
839
840 if (!SlowMultiply) {
842 ExactFPDiv ? AVX512DQExactVarDivCostTable : AVX512DQVarDivCostTable;
843 if (const auto *Entry = CostTableLookup(Tbl, ISD, LT.second))
844 if (auto KindCost = Entry->Cost[CostKind])
845 return LT.first * *KindCost;
846 }
847 }
848
849 static const CostKindTblEntry AVX512BWVarDivCostTable[] = {
850 { ISD::UDIV, MVT::v16i8, { 10 } }, // unpack+cvt+divps sequence
851 { ISD::SDIV, MVT::v16i8, { 10 } },
852 { ISD::UREM, MVT::v16i8, { 10 } },
853 { ISD::SREM, MVT::v16i8, { 10 } },
854 { ISD::UDIV, MVT::v32i8, { 20 } },
855 { ISD::SDIV, MVT::v32i8, { 20 } },
856 { ISD::UREM, MVT::v32i8, { 20 } },
857 { ISD::SREM, MVT::v32i8, { 20 } },
858 { ISD::UDIV, MVT::v64i8, { 40 } },
859 { ISD::SDIV, MVT::v64i8, { 40 } },
860 { ISD::UREM, MVT::v64i8, { 40 } },
861 { ISD::SREM, MVT::v64i8, { 40 } },
862 { ISD::UDIV, MVT::v8i16, { 5 } },
863 { ISD::SDIV, MVT::v8i16, { 5 } },
864 { ISD::UREM, MVT::v8i16, { 5 } },
865 { ISD::SREM, MVT::v8i16, { 5 } },
866 { ISD::UDIV, MVT::v16i16, { 10 } },
867 { ISD::SDIV, MVT::v16i16, { 10 } },
868 { ISD::UREM, MVT::v16i16, { 10 } },
869 { ISD::SREM, MVT::v16i16, { 10 } },
870 { ISD::UDIV, MVT::v32i16, { 20 } },
871 { ISD::SDIV, MVT::v32i16, { 20 } },
872 { ISD::UREM, MVT::v32i16, { 20 } },
873 { ISD::SREM, MVT::v32i16, { 20 } },
874 { ISD::UDIV, MVT::v4i32, { 8 } }, // cvt+divpd sequence
875 { ISD::SDIV, MVT::v4i32, { 8 } },
876 { ISD::UREM, MVT::v4i32, { 8 } },
877 { ISD::SREM, MVT::v4i32, { 8 } },
878 { ISD::UDIV, MVT::v8i32, { 16 } },
879 { ISD::SDIV, MVT::v8i32, { 16 } },
880 { ISD::UREM, MVT::v8i32, { 16 } },
881 { ISD::SREM, MVT::v8i32, { 16 } },
882 { ISD::UDIV, MVT::v16i32, { 32 } },
883 { ISD::SDIV, MVT::v16i32, { 32 } },
884 { ISD::UREM, MVT::v16i32, { 32 } },
885 { ISD::SREM, MVT::v16i32, { 32 } },
886 };
887
888 static const CostKindTblEntry AVX512BWExactVarDivCostTable[] = {
889 { ISD::UDIV, MVT::v4i32, { 3 } }, // cvt+divps sequence
890 { ISD::SDIV, MVT::v4i32, { 3 } },
891 { ISD::UREM, MVT::v4i32, { 3 } },
892 { ISD::SREM, MVT::v4i32, { 3 } },
893 { ISD::UDIV, MVT::v8i32, { 5 } },
894 { ISD::SDIV, MVT::v8i32, { 5 } },
895 { ISD::UREM, MVT::v8i32, { 5 } },
896 { ISD::SREM, MVT::v8i32, { 5 } },
897 { ISD::UDIV, MVT::v16i32, { 10 } },
898 { ISD::SDIV, MVT::v16i32, { 10 } },
899 { ISD::UREM, MVT::v16i32, { 10 } },
900 { ISD::SREM, MVT::v16i32, { 10 } },
901 };
902
903 if (VarDivToFP && ST->hasBWI()) {
904 ArrayRef<CostKindTblEntry> Tbl = AVX512BWVarDivCostTable;
905 if (ExactI32)
906 Tbl = AVX512BWExactVarDivCostTable;
907 if (const auto *Entry = CostTableLookup(Tbl, ISD, LT.second))
908 if (auto KindCost = Entry->Cost[CostKind])
909 return LT.first * *KindCost;
910 }
911
912 static const CostKindTblEntry AVX512VarDivCostTable[] = {
913 { ISD::UDIV, MVT::v16i8, { 14 } }, // unpack+cvt+divps sequence
914 { ISD::SDIV, MVT::v16i8, { 14 } },
915 { ISD::UREM, MVT::v16i8, { 14 } },
916 { ISD::SREM, MVT::v16i8, { 14 } },
917 { ISD::UDIV, MVT::v32i8, { 28 } },
918 { ISD::SDIV, MVT::v32i8, { 28 } },
919 { ISD::UREM, MVT::v32i8, { 28 } },
920 { ISD::SREM, MVT::v32i8, { 28 } },
921 { ISD::UDIV, MVT::v64i8, { 56 } },
922 { ISD::SDIV, MVT::v64i8, { 56 } },
923 { ISD::UREM, MVT::v64i8, { 56 } },
924 { ISD::SREM, MVT::v64i8, { 56 } },
925 { ISD::UDIV, MVT::v8i16, { 14 } },
926 { ISD::SDIV, MVT::v8i16, { 14 } },
927 { ISD::UREM, MVT::v8i16, { 14 } },
928 { ISD::SREM, MVT::v8i16, { 14 } },
929 { ISD::UDIV, MVT::v16i16, { 14 } },
930 { ISD::SDIV, MVT::v16i16, { 14 } },
931 { ISD::UREM, MVT::v16i16, { 14 } },
932 { ISD::SREM, MVT::v16i16, { 14 } },
933 { ISD::UDIV, MVT::v32i16, { 28 } },
934 { ISD::SDIV, MVT::v32i16, { 28 } },
935 { ISD::UREM, MVT::v32i16, { 28 } },
936 { ISD::SREM, MVT::v32i16, { 28 } },
937 { ISD::UDIV, MVT::v4i32, { 28 } }, // cvt+divpd sequence
938 { ISD::SDIV, MVT::v4i32, { 28 } },
939 { ISD::UREM, MVT::v4i32, { 28 } },
940 { ISD::SREM, MVT::v4i32, { 28 } },
941 { ISD::UDIV, MVT::v8i32, { 28 } },
942 { ISD::SDIV, MVT::v8i32, { 28 } },
943 { ISD::UREM, MVT::v8i32, { 28 } },
944 { ISD::SREM, MVT::v8i32, { 28 } },
945 { ISD::UDIV, MVT::v16i32, { 56 } },
946 { ISD::SDIV, MVT::v16i32, { 56 } },
947 { ISD::UREM, MVT::v16i32, { 56 } },
948 { ISD::SREM, MVT::v16i32, { 56 } },
949 };
950
951 static const CostKindTblEntry AVX512ExactVarDivCostTable[] = {
952 { ISD::UDIV, MVT::v4i32, { 7 } }, // cvt+divps sequence
953 { ISD::SDIV, MVT::v4i32, { 7 } },
954 { ISD::UREM, MVT::v4i32, { 7 } },
955 { ISD::SREM, MVT::v4i32, { 7 } },
956 { ISD::UDIV, MVT::v8i32, { 14 } },
957 { ISD::SDIV, MVT::v8i32, { 14 } },
958 { ISD::UREM, MVT::v8i32, { 14 } },
959 { ISD::SREM, MVT::v8i32, { 14 } },
960 { ISD::UDIV, MVT::v16i32, { 14 } },
961 { ISD::SDIV, MVT::v16i32, { 14 } },
962 { ISD::UREM, MVT::v16i32, { 14 } },
963 { ISD::SREM, MVT::v16i32, { 14 } },
964 };
965
966 if (VarDivToFP && ST->hasAVX512()) {
967 ArrayRef<CostKindTblEntry> Tbl = AVX512VarDivCostTable;
968 if (ExactI32)
969 Tbl = AVX512ExactVarDivCostTable;
970 if (const auto *Entry = CostTableLookup(Tbl, ISD, LT.second))
971 if (auto KindCost = Entry->Cost[CostKind])
972 return LT.first * *KindCost;
973 }
974
975 static const CostKindTblEntry AVX2VarDivCostTable[] = {
976 { ISD::UDIV, MVT::v16i8, { 28 } }, // unpack+cvt+divps sequence
977 { ISD::SDIV, MVT::v16i8, { 28 } },
978 { ISD::UREM, MVT::v16i8, { 28 } },
979 { ISD::SREM, MVT::v16i8, { 28 } },
980 { ISD::UDIV, MVT::v32i8, { 56 } },
981 { ISD::SDIV, MVT::v32i8, { 56 } },
982 { ISD::UREM, MVT::v32i8, { 56 } },
983 { ISD::SREM, MVT::v32i8, { 56 } },
984 { ISD::UDIV, MVT::v8i16, { 14 } },
985 { ISD::SDIV, MVT::v8i16, { 14 } },
986 { ISD::UREM, MVT::v8i16, { 14 } },
987 { ISD::SREM, MVT::v8i16, { 14 } },
988 { ISD::UDIV, MVT::v16i16, { 28 } },
989 { ISD::SDIV, MVT::v16i16, { 28 } },
990 { ISD::UREM, MVT::v16i16, { 28 } },
991 { ISD::SREM, MVT::v16i16, { 28 } },
992 { ISD::UDIV, MVT::v4i32, { 28 } }, // cvt+divpd sequence
993 { ISD::SDIV, MVT::v4i32, { 28 } },
994 { ISD::UREM, MVT::v4i32, { 28 } },
995 { ISD::SREM, MVT::v4i32, { 28 } },
996 { ISD::UDIV, MVT::v8i32, { 56 } },
997 { ISD::SDIV, MVT::v8i32, { 56 } },
998 { ISD::UREM, MVT::v8i32, { 56 } },
999 { ISD::SREM, MVT::v8i32, { 56 } },
1000 };
1001
1002 static const CostKindTblEntry AVX2ExactVarDivCostTable[] = {
1003 { ISD::UDIV, MVT::v4i32, { 9 } }, // cvt+divps sequence
1004 { ISD::SDIV, MVT::v4i32, { 8 } },
1005 { ISD::UREM, MVT::v4i32, { 9 } },
1006 { ISD::SREM, MVT::v4i32, { 8 } },
1007 { ISD::UDIV, MVT::v8i32, { 14 } },
1008 { ISD::SDIV, MVT::v8i32, { 14 } },
1009 { ISD::UREM, MVT::v8i32, { 14 } },
1010 { ISD::SREM, MVT::v8i32, { 14 } },
1011 };
1012
1013 if (VarDivToFP && ST->hasAVX2()) {
1014 ArrayRef<CostKindTblEntry> Tbl = AVX2VarDivCostTable;
1015 if (ExactI32)
1016 Tbl = AVX2ExactVarDivCostTable;
1017 if (const auto *Entry = CostTableLookup(Tbl, ISD, LT.second))
1018 if (auto KindCost = Entry->Cost[CostKind])
1019 return LT.first * *KindCost;
1020 }
1021
1022 // No unsigned i32 entries below AVX2, where the u32 to f64 converts are
1023 // emulated and the fold stays off.
1024 static const CostKindTblEntry AVX1VarDivCostTable[] = {
1025 { ISD::UDIV, MVT::v16i8, { 56 } }, // unpack+cvt+divps sequence
1026 { ISD::SDIV, MVT::v16i8, { 56 } },
1027 { ISD::UREM, MVT::v16i8, { 56 } },
1028 { ISD::SREM, MVT::v16i8, { 56 } },
1029 { ISD::UDIV, MVT::v32i8, { 112 } },
1030 { ISD::SDIV, MVT::v32i8, { 112 } },
1031 { ISD::UREM, MVT::v32i8, { 112 } },
1032 { ISD::SREM, MVT::v32i8, { 112 } },
1033 { ISD::UDIV, MVT::v8i16, { 28 } },
1034 { ISD::SDIV, MVT::v8i16, { 28 } },
1035 { ISD::UREM, MVT::v8i16, { 28 } },
1036 { ISD::SREM, MVT::v8i16, { 28 } },
1037 { ISD::UDIV, MVT::v16i16, { 56 } },
1038 { ISD::SDIV, MVT::v16i16, { 56 } },
1039 { ISD::UREM, MVT::v16i16, { 56 } },
1040 { ISD::SREM, MVT::v16i16, { 56 } },
1041 { ISD::SDIV, MVT::v4i32, { 44 } }, // cvt+divpd sequence
1042 { ISD::SREM, MVT::v4i32, { 44 } },
1043 { ISD::SDIV, MVT::v8i32, { 88 } },
1044 { ISD::SREM, MVT::v8i32, { 88 } },
1045 };
1046
1047 static const CostKindTblEntry AVX1ExactVarDivCostTable[] = {
1048 { ISD::SDIV, MVT::v4i32, { 14 } }, // cvt+divps sequence
1049 { ISD::SREM, MVT::v4i32, { 14 } },
1050 { ISD::SDIV, MVT::v8i32, { 28 } },
1051 { ISD::SREM, MVT::v8i32, { 28 } },
1052 };
1053
1054 if (VarDivToFP && ST->hasAVX()) {
1055 ArrayRef<CostKindTblEntry> Tbl = AVX1VarDivCostTable;
1056 if (ExactI32)
1057 Tbl = AVX1ExactVarDivCostTable;
1058 if (const auto *Entry = CostTableLookup(Tbl, ISD, LT.second))
1059 if (auto KindCost = Entry->Cost[CostKind])
1060 return LT.first * *KindCost;
1061 }
1062
1063 static const CostKindTblEntry SSE2VarDivCostTable[] = {
1064 { ISD::UDIV, MVT::v16i8, { 56 } }, // unpack+cvt+divps sequence
1065 { ISD::SDIV, MVT::v16i8, { 56 } },
1066 { ISD::UREM, MVT::v16i8, { 56 } },
1067 { ISD::SREM, MVT::v16i8, { 56 } },
1068 { ISD::UDIV, MVT::v8i16, { 28 } },
1069 { ISD::SDIV, MVT::v8i16, { 28 } },
1070 { ISD::UREM, MVT::v8i16, { 28 } },
1071 { ISD::SREM, MVT::v8i16, { 28 } },
1072 { ISD::SDIV, MVT::v4i32, { 44 } }, // cvt+divpd sequence
1073 { ISD::SREM, MVT::v4i32, { 44 } },
1074 };
1075
1076 static const CostKindTblEntry SSE2ExactVarDivCostTable[] = {
1077 { ISD::SDIV, MVT::v4i32, { 14 } }, // cvt+divps sequence
1078 { ISD::SREM, MVT::v4i32, { 14 } },
1079 };
1080
1081 if (VarDivToFP && ST->hasSSE2()) {
1082 ArrayRef<CostKindTblEntry> Tbl = SSE2VarDivCostTable;
1083 if (ExactI32)
1084 Tbl = SSE2ExactVarDivCostTable;
1085 if (const auto *Entry = CostTableLookup(Tbl, ISD, LT.second))
1086 if (auto KindCost = Entry->Cost[CostKind])
1087 return LT.first * *KindCost;
1088 }
1089
1090 static const CostKindTblEntry AVX512BWUniformCostTable[] = {
1091 { ISD::SHL, MVT::v16i8, { 3, 5, 5, 7 } }, // psllw + pand.
1092 { ISD::SRL, MVT::v16i8, { 3,10, 5, 8 } }, // psrlw + pand.
1093 { ISD::SRA, MVT::v16i8, { 4,12, 8,12 } }, // psrlw, pand, pxor, psubb.
1094 { ISD::SHL, MVT::v32i8, { 4, 7, 6, 8 } }, // psllw + pand.
1095 { ISD::SRL, MVT::v32i8, { 4, 8, 7, 9 } }, // psrlw + pand.
1096 { ISD::SRA, MVT::v32i8, { 5,10,10,13 } }, // psrlw, pand, pxor, psubb.
1097 { ISD::SHL, MVT::v64i8, { 4, 7, 6, 8 } }, // psllw + pand.
1098 { ISD::SRL, MVT::v64i8, { 4, 8, 7,10 } }, // psrlw + pand.
1099 { ISD::SRA, MVT::v64i8, { 5,10,10,15 } }, // psrlw, pand, pxor, psubb.
1100
1101 { ISD::SHL, MVT::v32i16, { 2, 4, 2, 3 } }, // psllw
1102 { ISD::SRL, MVT::v32i16, { 2, 4, 2, 3 } }, // psrlw
1103 { ISD::SRA, MVT::v32i16, { 2, 4, 2, 3 } }, // psrqw
1104 };
1105
1106 if (ST->hasBWI() && Op2Info.isUniform())
1107 if (const auto *Entry =
1108 CostTableLookup(AVX512BWUniformCostTable, ISD, LT.second))
1109 if (auto KindCost = Entry->Cost[CostKind])
1110 return LT.first * *KindCost;
1111
1112 static const CostKindTblEntry AVX512UniformCostTable[] = {
1113 { ISD::SHL, MVT::v32i16, { 5,10, 5, 7 } }, // psllw + split.
1114 { ISD::SRL, MVT::v32i16, { 5,10, 5, 7 } }, // psrlw + split.
1115 { ISD::SRA, MVT::v32i16, { 5,10, 5, 7 } }, // psraw + split.
1116
1117 { ISD::SHL, MVT::v16i32, { 2, 4, 2, 3 } }, // pslld
1118 { ISD::SRL, MVT::v16i32, { 2, 4, 2, 3 } }, // psrld
1119 { ISD::SRA, MVT::v16i32, { 2, 4, 2, 3 } }, // psrad
1120
1121 { ISD::SRA, MVT::v2i64, { 1, 2, 1, 2 } }, // psraq
1122 { ISD::SHL, MVT::v4i64, { 1, 4, 1, 2 } }, // psllq
1123 { ISD::SRL, MVT::v4i64, { 1, 4, 1, 2 } }, // psrlq
1124 { ISD::SRA, MVT::v4i64, { 1, 4, 1, 2 } }, // psraq
1125 { ISD::SHL, MVT::v8i64, { 1, 4, 1, 2 } }, // psllq
1126 { ISD::SRL, MVT::v8i64, { 1, 4, 1, 2 } }, // psrlq
1127 { ISD::SRA, MVT::v8i64, { 1, 4, 1, 2 } }, // psraq
1128 };
1129
1130 if (ST->hasAVX512() && Op2Info.isUniform())
1131 if (const auto *Entry =
1132 CostTableLookup(AVX512UniformCostTable, ISD, LT.second))
1133 if (auto KindCost = Entry->Cost[CostKind])
1134 return LT.first * *KindCost;
1135
1136 static const CostKindTblEntry AVX2UniformCostTable[] = {
1137 // Uniform splats are cheaper for the following instructions.
1138 { ISD::SHL, MVT::v16i8, { 3, 5, 5, 7 } }, // psllw + pand.
1139 { ISD::SRL, MVT::v16i8, { 3, 9, 5, 8 } }, // psrlw + pand.
1140 { ISD::SRA, MVT::v16i8, { 4, 5, 9,13 } }, // psrlw, pand, pxor, psubb.
1141 { ISD::SHL, MVT::v32i8, { 4, 7, 6, 8 } }, // psllw + pand.
1142 { ISD::SRL, MVT::v32i8, { 4, 8, 7, 9 } }, // psrlw + pand.
1143 { ISD::SRA, MVT::v32i8, { 6, 9,11,16 } }, // psrlw, pand, pxor, psubb.
1144
1145 { ISD::SHL, MVT::v8i16, { 1, 2, 1, 2 } }, // psllw.
1146 { ISD::SRL, MVT::v8i16, { 1, 2, 1, 2 } }, // psrlw.
1147 { ISD::SRA, MVT::v8i16, { 1, 2, 1, 2 } }, // psraw.
1148 { ISD::SHL, MVT::v16i16, { 2, 4, 2, 3 } }, // psllw.
1149 { ISD::SRL, MVT::v16i16, { 2, 4, 2, 3 } }, // psrlw.
1150 { ISD::SRA, MVT::v16i16, { 2, 4, 2, 3 } }, // psraw.
1151
1152 { ISD::SHL, MVT::v4i32, { 1, 2, 1, 2 } }, // pslld
1153 { ISD::SRL, MVT::v4i32, { 1, 2, 1, 2 } }, // psrld
1154 { ISD::SRA, MVT::v4i32, { 1, 2, 1, 2 } }, // psrad
1155 { ISD::SHL, MVT::v8i32, { 2, 4, 2, 3 } }, // pslld
1156 { ISD::SRL, MVT::v8i32, { 2, 4, 2, 3 } }, // psrld
1157 { ISD::SRA, MVT::v8i32, { 2, 4, 2, 3 } }, // psrad
1158
1159 { ISD::SHL, MVT::v2i64, { 1, 2, 1, 2 } }, // psllq
1160 { ISD::SRL, MVT::v2i64, { 1, 2, 1, 2 } }, // psrlq
1161 { ISD::SRA, MVT::v2i64, { 2, 4, 5, 7 } }, // 2 x psrad + shuffle.
1162 { ISD::SHL, MVT::v4i64, { 2, 4, 1, 2 } }, // psllq
1163 { ISD::SRL, MVT::v4i64, { 2, 4, 1, 2 } }, // psrlq
1164 { ISD::SRA, MVT::v4i64, { 4, 6, 5, 9 } }, // 2 x psrad + shuffle.
1165 };
1166
1167 if (ST->hasAVX2() && Op2Info.isUniform())
1168 if (const auto *Entry =
1169 CostTableLookup(AVX2UniformCostTable, ISD, LT.second))
1170 if (auto KindCost = Entry->Cost[CostKind])
1171 return LT.first * *KindCost;
1172
1173 static const CostKindTblEntry AVXUniformCostTable[] = {
1174 { ISD::SHL, MVT::v16i8, { 4, 4, 6, 8 } }, // psllw + pand.
1175 { ISD::SRL, MVT::v16i8, { 4, 8, 5, 8 } }, // psrlw + pand.
1176 { ISD::SRA, MVT::v16i8, { 6, 6, 9,13 } }, // psrlw, pand, pxor, psubb.
1177 { ISD::SHL, MVT::v32i8, { 7, 8,11,14 } }, // psllw + pand + split.
1178 { ISD::SRL, MVT::v32i8, { 7, 9,10,14 } }, // psrlw + pand + split.
1179 { ISD::SRA, MVT::v32i8, { 10,11,16,21 } }, // psrlw, pand, pxor, psubb + split.
1180
1181 { ISD::SHL, MVT::v8i16, { 1, 3, 1, 2 } }, // psllw.
1182 { ISD::SRL, MVT::v8i16, { 1, 3, 1, 2 } }, // psrlw.
1183 { ISD::SRA, MVT::v8i16, { 1, 3, 1, 2 } }, // psraw.
1184 { ISD::SHL, MVT::v16i16, { 3, 7, 5, 7 } }, // psllw + split.
1185 { ISD::SRL, MVT::v16i16, { 3, 7, 5, 7 } }, // psrlw + split.
1186 { ISD::SRA, MVT::v16i16, { 3, 7, 5, 7 } }, // psraw + split.
1187
1188 { ISD::SHL, MVT::v4i32, { 1, 3, 1, 2 } }, // pslld.
1189 { ISD::SRL, MVT::v4i32, { 1, 3, 1, 2 } }, // psrld.
1190 { ISD::SRA, MVT::v4i32, { 1, 3, 1, 2 } }, // psrad.
1191 { ISD::SHL, MVT::v8i32, { 3, 7, 5, 7 } }, // pslld + split.
1192 { ISD::SRL, MVT::v8i32, { 3, 7, 5, 7 } }, // psrld + split.
1193 { ISD::SRA, MVT::v8i32, { 3, 7, 5, 7 } }, // psrad + split.
1194
1195 { ISD::SHL, MVT::v2i64, { 1, 3, 1, 2 } }, // psllq.
1196 { ISD::SRL, MVT::v2i64, { 1, 3, 1, 2 } }, // psrlq.
1197 { ISD::SRA, MVT::v2i64, { 3, 4, 5, 7 } }, // 2 x psrad + shuffle.
1198 { ISD::SHL, MVT::v4i64, { 3, 7, 4, 6 } }, // psllq + split.
1199 { ISD::SRL, MVT::v4i64, { 3, 7, 4, 6 } }, // psrlq + split.
1200 { ISD::SRA, MVT::v4i64, { 6, 7,10,13 } }, // 2 x (2 x psrad + shuffle) + split.
1201 };
1202
1203 // XOP has faster vXi8 shifts.
1204 if (ST->hasAVX() && Op2Info.isUniform() &&
1205 (!ST->hasXOP() || LT.second.getScalarSizeInBits() != 8))
1206 if (const auto *Entry =
1207 CostTableLookup(AVXUniformCostTable, ISD, LT.second))
1208 if (auto KindCost = Entry->Cost[CostKind])
1209 return LT.first * *KindCost;
1210
1211 static const CostKindTblEntry SSE2UniformCostTable[] = {
1212 // Uniform splats are cheaper for the following instructions.
1213 { ISD::SHL, MVT::v16i8, { 9, 10, 6, 9 } }, // psllw + pand.
1214 { ISD::SRL, MVT::v16i8, { 9, 13, 5, 9 } }, // psrlw + pand.
1215 { ISD::SRA, MVT::v16i8, { 11, 15, 9,13 } }, // pcmpgtb sequence.
1216
1217 { ISD::SHL, MVT::v8i16, { 2, 2, 1, 2 } }, // psllw.
1218 { ISD::SRL, MVT::v8i16, { 2, 2, 1, 2 } }, // psrlw.
1219 { ISD::SRA, MVT::v8i16, { 2, 2, 1, 2 } }, // psraw.
1220
1221 { ISD::SHL, MVT::v4i32, { 2, 2, 1, 2 } }, // pslld
1222 { ISD::SRL, MVT::v4i32, { 2, 2, 1, 2 } }, // psrld.
1223 { ISD::SRA, MVT::v4i32, { 2, 2, 1, 2 } }, // psrad.
1224
1225 { ISD::SHL, MVT::v2i64, { 2, 2, 1, 2 } }, // psllq.
1226 { ISD::SRL, MVT::v2i64, { 2, 2, 1, 2 } }, // psrlq.
1227 { ISD::SRA, MVT::v2i64, { 5, 9, 5, 7 } }, // 2*psrlq + xor + sub.
1228 };
1229
1230 if (ST->hasSSE2() && Op2Info.isUniform() &&
1231 (!ST->hasXOP() || LT.second.getScalarSizeInBits() != 8))
1232 if (const auto *Entry =
1233 CostTableLookup(SSE2UniformCostTable, ISD, LT.second))
1234 if (auto KindCost = Entry->Cost[CostKind])
1235 return LT.first * *KindCost;
1236
1237 static const CostKindTblEntry AVX512DQCostTable[] = {
1238 { ISD::MUL, MVT::v2i64, { 2, 15, 1, 3 } }, // pmullq
1239 { ISD::MUL, MVT::v4i64, { 2, 15, 1, 3 } }, // pmullq
1240 { ISD::MUL, MVT::v8i64, { 3, 15, 1, 3 } } // pmullq
1241 };
1242
1243 // Look for AVX512DQ lowering tricks for custom cases.
1244 if (ST->hasDQI())
1245 if (const auto *Entry = CostTableLookup(AVX512DQCostTable, ISD, LT.second))
1246 if (auto KindCost = Entry->Cost[CostKind])
1247 return LT.first * *KindCost;
1248
1249 static const CostKindTblEntry AVX512BWCostTable[] = {
1250 { ISD::SHL, MVT::v16i8, { 4, 8, 4, 5 } }, // extend/vpsllvw/pack sequence.
1251 { ISD::SRL, MVT::v16i8, { 4, 8, 4, 5 } }, // extend/vpsrlvw/pack sequence.
1252 { ISD::SRA, MVT::v16i8, { 4, 8, 4, 5 } }, // extend/vpsravw/pack sequence.
1253 { ISD::SHL, MVT::v32i8, { 4, 23,11,16 } }, // extend/vpsllvw/pack sequence.
1254 { ISD::SRL, MVT::v32i8, { 4, 30,12,18 } }, // extend/vpsrlvw/pack sequence.
1255 { ISD::SRA, MVT::v32i8, { 6, 13,24,30 } }, // extend/vpsravw/pack sequence.
1256 { ISD::SHL, MVT::v64i8, { 6, 19,13,15 } }, // extend/vpsllvw/pack sequence.
1257 { ISD::SRL, MVT::v64i8, { 7, 27,15,18 } }, // extend/vpsrlvw/pack sequence.
1258 { ISD::SRA, MVT::v64i8, { 15, 15,30,30 } }, // extend/vpsravw/pack sequence.
1259
1260 { ISD::SHL, MVT::v8i16, { 1, 1, 1, 1 } }, // vpsllvw
1261 { ISD::SRL, MVT::v8i16, { 1, 1, 1, 1 } }, // vpsrlvw
1262 { ISD::SRA, MVT::v8i16, { 1, 1, 1, 1 } }, // vpsravw
1263 { ISD::SHL, MVT::v16i16, { 1, 1, 1, 1 } }, // vpsllvw
1264 { ISD::SRL, MVT::v16i16, { 1, 1, 1, 1 } }, // vpsrlvw
1265 { ISD::SRA, MVT::v16i16, { 1, 1, 1, 1 } }, // vpsravw
1266 { ISD::SHL, MVT::v32i16, { 1, 1, 1, 1 } }, // vpsllvw
1267 { ISD::SRL, MVT::v32i16, { 1, 1, 1, 1 } }, // vpsrlvw
1268 { ISD::SRA, MVT::v32i16, { 1, 1, 1, 1 } }, // vpsravw
1269
1270 { ISD::ADD, MVT::v64i8, { 1, 1, 1, 1 } }, // paddb
1271 { ISD::ADD, MVT::v32i16, { 1, 1, 1, 1 } }, // paddw
1272
1273 { ISD::ADD, MVT::v32i8, { 1, 1, 1, 1 } }, // paddb
1274 { ISD::ADD, MVT::v16i16, { 1, 1, 1, 1 } }, // paddw
1275 { ISD::ADD, MVT::v8i32, { 1, 1, 1, 1 } }, // paddd
1276 { ISD::ADD, MVT::v4i64, { 1, 1, 1, 1 } }, // paddq
1277
1278 { ISD::SUB, MVT::v64i8, { 1, 1, 1, 1 } }, // psubb
1279 { ISD::SUB, MVT::v32i16, { 1, 1, 1, 1 } }, // psubw
1280
1281 { ISD::MUL, MVT::v16i8, { 4, 12, 4, 5 } }, // extend/pmullw/trunc
1282 { ISD::MUL, MVT::v32i8, { 3, 10, 7,10 } }, // pmaddubsw
1283 { ISD::MUL, MVT::v64i8, { 3, 11, 7,10 } }, // pmaddubsw
1284 { ISD::MUL, MVT::v32i16, { 1, 5, 1, 1 } }, // pmullw
1285
1286 { ISD::SUB, MVT::v32i8, { 1, 1, 1, 1 } }, // psubb
1287 { ISD::SUB, MVT::v16i16, { 1, 1, 1, 1 } }, // psubw
1288 { ISD::SUB, MVT::v8i32, { 1, 1, 1, 1 } }, // psubd
1289 { ISD::SUB, MVT::v4i64, { 1, 1, 1, 1 } }, // psubq
1290 };
1291
1292 // Look for AVX512BW lowering tricks for custom cases.
1293 if (ST->hasBWI())
1294 if (const auto *Entry = CostTableLookup(AVX512BWCostTable, ISD, LT.second))
1295 if (auto KindCost = Entry->Cost[CostKind])
1296 return LT.first * *KindCost;
1297
1298 static const CostKindTblEntry AVX512CostTable[] = {
1299 { ISD::SHL, MVT::v64i8, { 15, 19,27,33 } }, // vpblendv+split sequence.
1300 { ISD::SRL, MVT::v64i8, { 15, 19,30,36 } }, // vpblendv+split sequence.
1301 { ISD::SRA, MVT::v64i8, { 37, 37,51,63 } }, // vpblendv+split sequence.
1302
1303 { ISD::SHL, MVT::v32i16, { 11, 16,11,15 } }, // 2*extend/vpsrlvd/pack sequence.
1304 { ISD::SRL, MVT::v32i16, { 11, 16,11,15 } }, // 2*extend/vpsrlvd/pack sequence.
1305 { ISD::SRA, MVT::v32i16, { 11, 16,11,15 } }, // 2*extend/vpsravd/pack sequence.
1306
1307 { ISD::SHL, MVT::v4i32, { 1, 1, 1, 1 } },
1308 { ISD::SRL, MVT::v4i32, { 1, 1, 1, 1 } },
1309 { ISD::SRA, MVT::v4i32, { 1, 1, 1, 1 } },
1310 { ISD::SHL, MVT::v8i32, { 1, 1, 1, 1 } },
1311 { ISD::SRL, MVT::v8i32, { 1, 1, 1, 1 } },
1312 { ISD::SRA, MVT::v8i32, { 1, 1, 1, 1 } },
1313 { ISD::SHL, MVT::v16i32, { 1, 1, 1, 1 } },
1314 { ISD::SRL, MVT::v16i32, { 1, 1, 1, 1 } },
1315 { ISD::SRA, MVT::v16i32, { 1, 1, 1, 1 } },
1316
1317 { ISD::SHL, MVT::v2i64, { 1, 1, 1, 1 } },
1318 { ISD::SRL, MVT::v2i64, { 1, 1, 1, 1 } },
1319 { ISD::SRA, MVT::v2i64, { 1, 1, 1, 1 } },
1320 { ISD::SHL, MVT::v4i64, { 1, 1, 1, 1 } },
1321 { ISD::SRL, MVT::v4i64, { 1, 1, 1, 1 } },
1322 { ISD::SRA, MVT::v4i64, { 1, 1, 1, 1 } },
1323 { ISD::SHL, MVT::v8i64, { 1, 1, 1, 1 } },
1324 { ISD::SRL, MVT::v8i64, { 1, 1, 1, 1 } },
1325 { ISD::SRA, MVT::v8i64, { 1, 1, 1, 1 } },
1326
1327 { ISD::ADD, MVT::v64i8, { 3, 7, 5, 5 } }, // 2*paddb + split
1328 { ISD::ADD, MVT::v32i16, { 3, 7, 5, 5 } }, // 2*paddw + split
1329
1330 { ISD::SUB, MVT::v64i8, { 3, 7, 5, 5 } }, // 2*psubb + split
1331 { ISD::SUB, MVT::v32i16, { 3, 7, 5, 5 } }, // 2*psubw + split
1332
1333 { ISD::AND, MVT::v32i8, { 1, 1, 1, 1 } },
1334 { ISD::AND, MVT::v16i16, { 1, 1, 1, 1 } },
1335 { ISD::AND, MVT::v8i32, { 1, 1, 1, 1 } },
1336 { ISD::AND, MVT::v4i64, { 1, 1, 1, 1 } },
1337
1338 { ISD::OR, MVT::v32i8, { 1, 1, 1, 1 } },
1339 { ISD::OR, MVT::v16i16, { 1, 1, 1, 1 } },
1340 { ISD::OR, MVT::v8i32, { 1, 1, 1, 1 } },
1341 { ISD::OR, MVT::v4i64, { 1, 1, 1, 1 } },
1342
1343 { ISD::XOR, MVT::v32i8, { 1, 1, 1, 1 } },
1344 { ISD::XOR, MVT::v16i16, { 1, 1, 1, 1 } },
1345 { ISD::XOR, MVT::v8i32, { 1, 1, 1, 1 } },
1346 { ISD::XOR, MVT::v4i64, { 1, 1, 1, 1 } },
1347
1348 { ISD::MUL, MVT::v16i32, { 1, 10, 1, 2 } }, // pmulld (Skylake from agner.org)
1349 { ISD::MUL, MVT::v8i32, { 1, 10, 1, 2 } }, // pmulld (Skylake from agner.org)
1350 { ISD::MUL, MVT::v4i32, { 1, 10, 1, 2 } }, // pmulld (Skylake from agner.org)
1351 { ISD::MUL, MVT::v8i64, { 6, 9, 8, 8 } }, // 3*pmuludq/3*shift/2*add
1352 { ISD::MUL, MVT::i64, { 1 } }, // Skylake from http://www.agner.org/
1353
1354 { X86ISD::PMULUDQ, MVT::v8i64, { 1, 5, 1, 1 } },
1355
1356 { ISD::FNEG, MVT::v8f64, { 1, 1, 1, 2 } }, // Skylake from http://www.agner.org/
1357 { ISD::FADD, MVT::v8f64, { 1, 4, 1, 1 } }, // Skylake from http://www.agner.org/
1358 { ISD::FADD, MVT::v4f64, { 1, 4, 1, 1 } }, // Skylake from http://www.agner.org/
1359 { ISD::FSUB, MVT::v8f64, { 1, 4, 1, 1 } }, // Skylake from http://www.agner.org/
1360 { ISD::FSUB, MVT::v4f64, { 1, 4, 1, 1 } }, // Skylake from http://www.agner.org/
1361 { ISD::FMUL, MVT::v8f64, { 1, 4, 1, 1 } }, // Skylake from http://www.agner.org/
1362 { ISD::FMUL, MVT::v4f64, { 1, 4, 1, 1 } }, // Skylake from http://www.agner.org/
1363 { ISD::FMUL, MVT::v2f64, { 1, 4, 1, 1 } }, // Skylake from http://www.agner.org/
1364 { ISD::FMUL, MVT::f64, { 1, 4, 1, 1 } }, // Skylake from http://www.agner.org/
1365
1366 { ISD::FDIV, MVT::f64, { 4, 14, 1, 1 } }, // Skylake from http://www.agner.org/
1367 { ISD::FDIV, MVT::v2f64, { 4, 14, 1, 1 } }, // Skylake from http://www.agner.org/
1368 { ISD::FDIV, MVT::v4f64, { 8, 14, 1, 1 } }, // Skylake from http://www.agner.org/
1369 { ISD::FDIV, MVT::v8f64, { 16, 23, 1, 3 } }, // Skylake from http://www.agner.org/
1370
1371 { ISD::FNEG, MVT::v16f32, { 1, 1, 1, 2 } }, // Skylake from http://www.agner.org/
1372 { ISD::FADD, MVT::v16f32, { 1, 4, 1, 1 } }, // Skylake from http://www.agner.org/
1373 { ISD::FADD, MVT::v8f32, { 1, 4, 1, 1 } }, // Skylake from http://www.agner.org/
1374 { ISD::FSUB, MVT::v16f32, { 1, 4, 1, 1 } }, // Skylake from http://www.agner.org/
1375 { ISD::FSUB, MVT::v8f32, { 1, 4, 1, 1 } }, // Skylake from http://www.agner.org/
1376 { ISD::FMUL, MVT::v16f32, { 1, 4, 1, 1 } }, // Skylake from http://www.agner.org/
1377 { ISD::FMUL, MVT::v8f32, { 1, 4, 1, 1 } }, // Skylake from http://www.agner.org/
1378 { ISD::FMUL, MVT::v4f32, { 1, 4, 1, 1 } }, // Skylake from http://www.agner.org/
1379 { ISD::FMUL, MVT::f32, { 1, 4, 1, 1 } }, // Skylake from http://www.agner.org/
1380
1381 { ISD::FDIV, MVT::f32, { 3, 11, 1, 1 } }, // Skylake from http://www.agner.org/
1382 { ISD::FDIV, MVT::v4f32, { 3, 11, 1, 1 } }, // Skylake from http://www.agner.org/
1383 { ISD::FDIV, MVT::v8f32, { 5, 11, 1, 1 } }, // Skylake from http://www.agner.org/
1384 { ISD::FDIV, MVT::v16f32, { 10, 18, 1, 3 } }, // Skylake from http://www.agner.org/
1385 };
1386
1387 if (ST->hasAVX512())
1388 if (const auto *Entry = CostTableLookup(AVX512CostTable, ISD, LT.second))
1389 if (auto KindCost = Entry->Cost[CostKind])
1390 return LT.first * *KindCost;
1391
1392 static const CostKindTblEntry AVX2ShiftCostTable[] = {
1393 // Shifts on vXi64/vXi32 on AVX2 is legal even though we declare to
1394 // customize them to detect the cases where shift amount is a scalar one.
1395 { ISD::SHL, MVT::v4i32, { 2, 3, 1, 3 } }, // vpsllvd (Haswell from agner.org)
1396 { ISD::SRL, MVT::v4i32, { 2, 3, 1, 3 } }, // vpsrlvd (Haswell from agner.org)
1397 { ISD::SRA, MVT::v4i32, { 2, 3, 1, 3 } }, // vpsravd (Haswell from agner.org)
1398 { ISD::SHL, MVT::v8i32, { 4, 4, 1, 3 } }, // vpsllvd (Haswell from agner.org)
1399 { ISD::SRL, MVT::v8i32, { 4, 4, 1, 3 } }, // vpsrlvd (Haswell from agner.org)
1400 { ISD::SRA, MVT::v8i32, { 4, 4, 1, 3 } }, // vpsravd (Haswell from agner.org)
1401 { ISD::SHL, MVT::v2i64, { 2, 3, 1, 1 } }, // vpsllvq (Haswell from agner.org)
1402 { ISD::SRL, MVT::v2i64, { 2, 3, 1, 1 } }, // vpsrlvq (Haswell from agner.org)
1403 { ISD::SHL, MVT::v4i64, { 4, 4, 1, 2 } }, // vpsllvq (Haswell from agner.org)
1404 { ISD::SRL, MVT::v4i64, { 4, 4, 1, 2 } }, // vpsrlvq (Haswell from agner.org)
1405 };
1406
1407 if (ST->hasAVX512()) {
1408 if (ISD == ISD::SHL && LT.second == MVT::v32i16 && Op2Info.isConstant())
1409 // On AVX512, a packed v32i16 shift left by a constant build_vector
1410 // is lowered into a vector multiply (vpmullw).
1411 return getArithmeticInstrCost(Instruction::Mul, Ty, CostKind,
1412 Op1Info.getNoProps(), Op2Info.getNoProps());
1413 }
1414
1415 // Look for AVX2 lowering tricks (XOP is always better at v4i32 shifts).
1416 if (ST->hasAVX2() && !(ST->hasXOP() && LT.second == MVT::v4i32)) {
1417 if (ISD == ISD::SHL && LT.second == MVT::v16i16 &&
1418 Op2Info.isConstant())
1419 // On AVX2, a packed v16i16 shift left by a constant build_vector
1420 // is lowered into a vector multiply (vpmullw).
1421 return getArithmeticInstrCost(Instruction::Mul, Ty, CostKind,
1422 Op1Info.getNoProps(), Op2Info.getNoProps());
1423
1424 if (const auto *Entry = CostTableLookup(AVX2ShiftCostTable, ISD, LT.second))
1425 if (auto KindCost = Entry->Cost[CostKind])
1426 return LT.first * *KindCost;
1427 }
1428
1429 static const CostKindTblEntry XOPShiftCostTable[] = {
1430 // 128bit shifts take 1cy, but right shifts require negation beforehand.
1431 { ISD::SHL, MVT::v16i8, { 1, 3, 1, 1 } },
1432 { ISD::SRL, MVT::v16i8, { 2, 3, 1, 1 } },
1433 { ISD::SRA, MVT::v16i8, { 2, 3, 1, 1 } },
1434 { ISD::SHL, MVT::v8i16, { 1, 3, 1, 1 } },
1435 { ISD::SRL, MVT::v8i16, { 2, 3, 1, 1 } },
1436 { ISD::SRA, MVT::v8i16, { 2, 3, 1, 1 } },
1437 { ISD::SHL, MVT::v4i32, { 1, 3, 1, 1 } },
1438 { ISD::SRL, MVT::v4i32, { 2, 3, 1, 1 } },
1439 { ISD::SRA, MVT::v4i32, { 2, 3, 1, 1 } },
1440 { ISD::SHL, MVT::v2i64, { 1, 3, 1, 1 } },
1441 { ISD::SRL, MVT::v2i64, { 2, 3, 1, 1 } },
1442 { ISD::SRA, MVT::v2i64, { 2, 3, 1, 1 } },
1443 // 256bit shifts require splitting if AVX2 didn't catch them above.
1444 { ISD::SHL, MVT::v32i8, { 4, 7, 5, 6 } },
1445 { ISD::SRL, MVT::v32i8, { 6, 7, 5, 6 } },
1446 { ISD::SRA, MVT::v32i8, { 6, 7, 5, 6 } },
1447 { ISD::SHL, MVT::v16i16, { 4, 7, 5, 6 } },
1448 { ISD::SRL, MVT::v16i16, { 6, 7, 5, 6 } },
1449 { ISD::SRA, MVT::v16i16, { 6, 7, 5, 6 } },
1450 { ISD::SHL, MVT::v8i32, { 4, 7, 5, 6 } },
1451 { ISD::SRL, MVT::v8i32, { 6, 7, 5, 6 } },
1452 { ISD::SRA, MVT::v8i32, { 6, 7, 5, 6 } },
1453 { ISD::SHL, MVT::v4i64, { 4, 7, 5, 6 } },
1454 { ISD::SRL, MVT::v4i64, { 6, 7, 5, 6 } },
1455 { ISD::SRA, MVT::v4i64, { 6, 7, 5, 6 } },
1456 };
1457
1458 // Look for XOP lowering tricks.
1459 if (ST->hasXOP()) {
1460 // If the right shift is constant then we'll fold the negation so
1461 // it's as cheap as a left shift.
1462 int ShiftISD = ISD;
1463 if ((ShiftISD == ISD::SRL || ShiftISD == ISD::SRA) && Op2Info.isConstant())
1464 ShiftISD = ISD::SHL;
1465 if (const auto *Entry =
1466 CostTableLookup(XOPShiftCostTable, ShiftISD, LT.second))
1467 if (auto KindCost = Entry->Cost[CostKind])
1468 return LT.first * *KindCost;
1469 }
1470
1471 if (ISD == ISD::SHL && !Op2Info.isUniform() && Op2Info.isConstant()) {
1472 MVT VT = LT.second;
1473 // Vector shift left by non uniform constant can be lowered
1474 // into vector multiply.
1475 if (((VT == MVT::v8i16 || VT == MVT::v4i32) && ST->hasSSE2()) ||
1476 ((VT == MVT::v16i16 || VT == MVT::v8i32) && ST->hasAVX()))
1477 ISD = ISD::MUL;
1478 }
1479
1480 static const CostKindTblEntry GLMCostTable[] = {
1481 { ISD::FDIV, MVT::f32, { 18, 19, 1, 1 } }, // divss
1482 { ISD::FDIV, MVT::v4f32, { 35, 36, 1, 1 } }, // divps
1483 { ISD::FDIV, MVT::f64, { 33, 34, 1, 1 } }, // divsd
1484 { ISD::FDIV, MVT::v2f64, { 65, 66, 1, 1 } }, // divpd
1485 };
1486
1487 if (ST->useGLMDivSqrtCosts())
1488 if (const auto *Entry = CostTableLookup(GLMCostTable, ISD, LT.second))
1489 if (auto KindCost = Entry->Cost[CostKind])
1490 return LT.first * *KindCost;
1491
1492 static const CostKindTblEntry SLMCostTable[] = {
1493 { ISD::MUL, MVT::v4i32, { 11, 11, 1, 7 } }, // pmulld
1494 { ISD::MUL, MVT::v8i16, { 2, 5, 1, 1 } }, // pmullw
1495 { ISD::FMUL, MVT::f64, { 2, 5, 1, 1 } }, // mulsd
1496 { ISD::FMUL, MVT::f32, { 1, 4, 1, 1 } }, // mulss
1497 { ISD::FMUL, MVT::v2f64, { 4, 7, 1, 1 } }, // mulpd
1498 { ISD::FMUL, MVT::v4f32, { 2, 5, 1, 1 } }, // mulps
1499 { ISD::FDIV, MVT::f32, { 17, 19, 1, 1 } }, // divss
1500 { ISD::FDIV, MVT::v4f32, { 39, 39, 1, 6 } }, // divps
1501 { ISD::FDIV, MVT::f64, { 32, 34, 1, 1 } }, // divsd
1502 { ISD::FDIV, MVT::v2f64, { 69, 69, 1, 6 } }, // divpd
1503 { ISD::FADD, MVT::v2f64, { 2, 4, 1, 1 } }, // addpd
1504 { ISD::FSUB, MVT::v2f64, { 2, 4, 1, 1 } }, // subpd
1505 // v2i64/v4i64 mul is custom lowered as a series of long:
1506 // multiplies(3), shifts(3) and adds(2)
1507 // slm muldq version throughput is 2 and addq throughput 4
1508 // thus: 3X2 (muldq throughput) + 3X1 (shift throughput) +
1509 // 3X4 (addq throughput) = 17
1510 { ISD::MUL, MVT::v2i64, { 17, 22, 9, 9 } },
1511 // slm addq\subq throughput is 4
1512 { ISD::ADD, MVT::v2i64, { 4, 2, 1, 2 } },
1513 { ISD::SUB, MVT::v2i64, { 4, 2, 1, 2 } },
1514 };
1515
1516 if (ST->useSLMArithCosts())
1517 if (const auto *Entry = CostTableLookup(SLMCostTable, ISD, LT.second))
1518 if (auto KindCost = Entry->Cost[CostKind])
1519 return LT.first * *KindCost;
1520
1521 static const CostKindTblEntry AVX2CostTable[] = {
1522 { ISD::SHL, MVT::v16i8, { 6, 21,11,16 } }, // vpblendvb sequence.
1523 { ISD::SHL, MVT::v32i8, { 6, 23,11,22 } }, // vpblendvb sequence.
1524 { ISD::SHL, MVT::v8i16, { 5, 18, 5,10 } }, // extend/vpsrlvd/pack sequence.
1525 { ISD::SHL, MVT::v16i16, { 8, 10,10,14 } }, // extend/vpsrlvd/pack sequence.
1526
1527 { ISD::SRL, MVT::v16i8, { 6, 27,12,18 } }, // vpblendvb sequence.
1528 { ISD::SRL, MVT::v32i8, { 8, 30,12,24 } }, // vpblendvb sequence.
1529 { ISD::SRL, MVT::v8i16, { 5, 11, 5,10 } }, // extend/vpsrlvd/pack sequence.
1530 { ISD::SRL, MVT::v16i16, { 8, 10,10,14 } }, // extend/vpsrlvd/pack sequence.
1531
1532 { ISD::SRA, MVT::v16i8, { 17, 17,24,30 } }, // vpblendvb sequence.
1533 { ISD::SRA, MVT::v32i8, { 18, 20,24,43 } }, // vpblendvb sequence.
1534 { ISD::SRA, MVT::v8i16, { 5, 11, 5,10 } }, // extend/vpsravd/pack sequence.
1535 { ISD::SRA, MVT::v16i16, { 8, 10,10,14 } }, // extend/vpsravd/pack sequence.
1536 { ISD::SRA, MVT::v2i64, { 4, 5, 5, 5 } }, // srl/xor/sub sequence.
1537 { ISD::SRA, MVT::v4i64, { 8, 8, 5, 9 } }, // srl/xor/sub sequence.
1538
1539 { ISD::SUB, MVT::v32i8, { 1, 1, 1, 2 } }, // psubb
1540 { ISD::ADD, MVT::v32i8, { 1, 1, 1, 2 } }, // paddb
1541 { ISD::SUB, MVT::v16i16, { 1, 1, 1, 2 } }, // psubw
1542 { ISD::ADD, MVT::v16i16, { 1, 1, 1, 2 } }, // paddw
1543 { ISD::SUB, MVT::v8i32, { 1, 1, 1, 2 } }, // psubd
1544 { ISD::ADD, MVT::v8i32, { 1, 1, 1, 2 } }, // paddd
1545 { ISD::SUB, MVT::v4i64, { 1, 1, 1, 2 } }, // psubq
1546 { ISD::ADD, MVT::v4i64, { 1, 1, 1, 2 } }, // paddq
1547
1548 { ISD::MUL, MVT::v16i8, { 5, 18, 6,12 } }, // extend/pmullw/pack
1549 { ISD::MUL, MVT::v32i8, { 4, 8, 8,16 } }, // pmaddubsw
1550 { ISD::MUL, MVT::v16i16, { 2, 5, 1, 2 } }, // pmullw
1551 { ISD::MUL, MVT::v8i32, { 4, 10, 1, 2 } }, // pmulld
1552 { ISD::MUL, MVT::v4i32, { 2, 10, 1, 2 } }, // pmulld
1553 { ISD::MUL, MVT::v4i64, { 6, 10, 8,13 } }, // 3*pmuludq/3*shift/2*add
1554 { ISD::MUL, MVT::v2i64, { 6, 10, 8, 8 } }, // 3*pmuludq/3*shift/2*add
1555
1556 { X86ISD::PMULUDQ, MVT::v4i64, { 1, 5, 1, 1 } },
1557
1558 { ISD::FNEG, MVT::v4f64, { 1, 1, 1, 2 } }, // vxorpd
1559 { ISD::FNEG, MVT::v8f32, { 1, 1, 1, 2 } }, // vxorps
1560
1561 { ISD::FADD, MVT::f64, { 1, 4, 1, 1 } }, // vaddsd
1562 { ISD::FADD, MVT::f32, { 1, 4, 1, 1 } }, // vaddss
1563 { ISD::FADD, MVT::v2f64, { 1, 4, 1, 1 } }, // vaddpd
1564 { ISD::FADD, MVT::v4f32, { 1, 4, 1, 1 } }, // vaddps
1565 { ISD::FADD, MVT::v4f64, { 1, 4, 1, 2 } }, // vaddpd
1566 { ISD::FADD, MVT::v8f32, { 1, 4, 1, 2 } }, // vaddps
1567
1568 { ISD::FSUB, MVT::f64, { 1, 4, 1, 1 } }, // vsubsd
1569 { ISD::FSUB, MVT::f32, { 1, 4, 1, 1 } }, // vsubss
1570 { ISD::FSUB, MVT::v2f64, { 1, 4, 1, 1 } }, // vsubpd
1571 { ISD::FSUB, MVT::v4f32, { 1, 4, 1, 1 } }, // vsubps
1572 { ISD::FSUB, MVT::v4f64, { 1, 4, 1, 2 } }, // vsubpd
1573 { ISD::FSUB, MVT::v8f32, { 1, 4, 1, 2 } }, // vsubps
1574
1575 { ISD::FMUL, MVT::f64, { 1, 5, 1, 1 } }, // vmulsd
1576 { ISD::FMUL, MVT::f32, { 1, 5, 1, 1 } }, // vmulss
1577 { ISD::FMUL, MVT::v2f64, { 1, 5, 1, 1 } }, // vmulpd
1578 { ISD::FMUL, MVT::v4f32, { 1, 5, 1, 1 } }, // vmulps
1579 { ISD::FMUL, MVT::v4f64, { 1, 5, 1, 2 } }, // vmulpd
1580 { ISD::FMUL, MVT::v8f32, { 1, 5, 1, 2 } }, // vmulps
1581
1582 { ISD::FDIV, MVT::f32, { 7, 13, 1, 1 } }, // vdivss
1583 { ISD::FDIV, MVT::v4f32, { 7, 13, 1, 1 } }, // vdivps
1584 { ISD::FDIV, MVT::v8f32, { 14, 21, 1, 3 } }, // vdivps
1585 { ISD::FDIV, MVT::f64, { 14, 20, 1, 1 } }, // vdivsd
1586 { ISD::FDIV, MVT::v2f64, { 14, 20, 1, 1 } }, // vdivpd
1587 { ISD::FDIV, MVT::v4f64, { 28, 35, 1, 3 } }, // vdivpd
1588 };
1589
1590 // Look for AVX2 lowering tricks for custom cases.
1591 if (ST->hasAVX2())
1592 if (const auto *Entry = CostTableLookup(AVX2CostTable, ISD, LT.second))
1593 if (auto KindCost = Entry->Cost[CostKind])
1594 return LT.first * *KindCost;
1595
1596 static const CostKindTblEntry AVX1CostTable[] = {
1597 // We don't have to scalarize unsupported ops. We can issue two half-sized
1598 // operations and we only need to extract the upper YMM half.
1599 // Two ops + 1 extract + 1 insert = 4.
1600 { ISD::MUL, MVT::v32i8, { 10, 11, 18, 19 } }, // pmaddubsw + split
1601 { ISD::MUL, MVT::v16i8, { 5, 6, 8, 12 } }, // 2*pmaddubsw/3*and/psllw/or
1602 { ISD::MUL, MVT::v16i16, { 4, 8, 5, 6 } }, // pmullw + split
1603 { ISD::MUL, MVT::v8i32, { 5, 8, 5, 10 } }, // pmulld + split
1604 { ISD::MUL, MVT::v4i32, { 2, 5, 1, 3 } }, // pmulld
1605 { ISD::MUL, MVT::v4i64, { 12, 15, 19, 20 } },
1606
1607 { X86ISD::PMULUDQ, MVT::v4i64, { 3, 5, 5, 6 } }, // pmuludq + split
1608
1609 { ISD::AND, MVT::v32i8, { 1, 1, 1, 2 } }, // vandps
1610 { ISD::AND, MVT::v16i16, { 1, 1, 1, 2 } }, // vandps
1611 { ISD::AND, MVT::v8i32, { 1, 1, 1, 2 } }, // vandps
1612 { ISD::AND, MVT::v4i64, { 1, 1, 1, 2 } }, // vandps
1613
1614 { ISD::OR, MVT::v32i8, { 1, 1, 1, 2 } }, // vorps
1615 { ISD::OR, MVT::v16i16, { 1, 1, 1, 2 } }, // vorps
1616 { ISD::OR, MVT::v8i32, { 1, 1, 1, 2 } }, // vorps
1617 { ISD::OR, MVT::v4i64, { 1, 1, 1, 2 } }, // vorps
1618
1619 { ISD::XOR, MVT::v32i8, { 1, 1, 1, 2 } }, // vxorps
1620 { ISD::XOR, MVT::v16i16, { 1, 1, 1, 2 } }, // vxorps
1621 { ISD::XOR, MVT::v8i32, { 1, 1, 1, 2 } }, // vxorps
1622 { ISD::XOR, MVT::v4i64, { 1, 1, 1, 2 } }, // vxorps
1623
1624 { ISD::SUB, MVT::v32i8, { 4, 2, 5, 6 } }, // psubb + split
1625 { ISD::ADD, MVT::v32i8, { 4, 2, 5, 6 } }, // paddb + split
1626 { ISD::SUB, MVT::v16i16, { 4, 2, 5, 6 } }, // psubw + split
1627 { ISD::ADD, MVT::v16i16, { 4, 2, 5, 6 } }, // paddw + split
1628 { ISD::SUB, MVT::v8i32, { 4, 2, 5, 6 } }, // psubd + split
1629 { ISD::ADD, MVT::v8i32, { 4, 2, 5, 6 } }, // paddd + split
1630 { ISD::SUB, MVT::v4i64, { 4, 2, 5, 6 } }, // psubq + split
1631 { ISD::ADD, MVT::v4i64, { 4, 2, 5, 6 } }, // paddq + split
1632 { ISD::SUB, MVT::v2i64, { 1, 1, 1, 1 } }, // psubq
1633 { ISD::ADD, MVT::v2i64, { 1, 1, 1, 1 } }, // paddq
1634
1635 { ISD::SHL, MVT::v16i8, { 10, 21,11,17 } }, // pblendvb sequence.
1636 { ISD::SHL, MVT::v32i8, { 22, 22,27,40 } }, // pblendvb sequence + split.
1637 { ISD::SHL, MVT::v8i16, { 6, 9,11,11 } }, // pblendvb sequence.
1638 { ISD::SHL, MVT::v16i16, { 13, 16,24,25 } }, // pblendvb sequence + split.
1639 { ISD::SHL, MVT::v4i32, { 3, 11, 4, 6 } }, // pslld/paddd/cvttps2dq/pmulld
1640 { ISD::SHL, MVT::v8i32, { 9, 11,12,17 } }, // pslld/paddd/cvttps2dq/pmulld + split
1641 { ISD::SHL, MVT::v2i64, { 2, 4, 4, 6 } }, // Shift each lane + blend.
1642 { ISD::SHL, MVT::v4i64, { 6, 7,11,15 } }, // Shift each lane + blend + split.
1643
1644 { ISD::SRL, MVT::v16i8, { 11, 27,12,18 } }, // pblendvb sequence.
1645 { ISD::SRL, MVT::v32i8, { 23, 23,30,43 } }, // pblendvb sequence + split.
1646 { ISD::SRL, MVT::v8i16, { 13, 16,14,22 } }, // pblendvb sequence.
1647 { ISD::SRL, MVT::v16i16, { 28, 30,31,48 } }, // pblendvb sequence + split.
1648 { ISD::SRL, MVT::v4i32, { 6, 7,12,16 } }, // Shift each lane + blend.
1649 { ISD::SRL, MVT::v8i32, { 14, 14,26,34 } }, // Shift each lane + blend + split.
1650 { ISD::SRL, MVT::v2i64, { 2, 4, 4, 6 } }, // Shift each lane + blend.
1651 { ISD::SRL, MVT::v4i64, { 6, 7,11,15 } }, // Shift each lane + blend + split.
1652
1653 { ISD::SRA, MVT::v16i8, { 21, 22,24,36 } }, // pblendvb sequence.
1654 { ISD::SRA, MVT::v32i8, { 44, 45,51,76 } }, // pblendvb sequence + split.
1655 { ISD::SRA, MVT::v8i16, { 13, 16,14,22 } }, // pblendvb sequence.
1656 { ISD::SRA, MVT::v16i16, { 28, 30,31,48 } }, // pblendvb sequence + split.
1657 { ISD::SRA, MVT::v4i32, { 6, 7,12,16 } }, // Shift each lane + blend.
1658 { ISD::SRA, MVT::v8i32, { 14, 14,26,34 } }, // Shift each lane + blend + split.
1659 { ISD::SRA, MVT::v2i64, { 5, 6,10,14 } }, // Shift each lane + blend.
1660 { ISD::SRA, MVT::v4i64, { 12, 12,22,30 } }, // Shift each lane + blend + split.
1661
1662 { ISD::FNEG, MVT::v4f64, { 2, 2, 1, 2 } }, // BTVER2 from http://www.agner.org/
1663 { ISD::FNEG, MVT::v8f32, { 2, 2, 1, 2 } }, // BTVER2 from http://www.agner.org/
1664
1665 { ISD::FADD, MVT::f64, { 1, 5, 1, 1 } }, // BDVER2 from http://www.agner.org/
1666 { ISD::FADD, MVT::f32, { 1, 5, 1, 1 } }, // BDVER2 from http://www.agner.org/
1667 { ISD::FADD, MVT::v2f64, { 1, 5, 1, 1 } }, // BDVER2 from http://www.agner.org/
1668 { ISD::FADD, MVT::v4f32, { 1, 5, 1, 1 } }, // BDVER2 from http://www.agner.org/
1669 { ISD::FADD, MVT::v4f64, { 2, 5, 1, 2 } }, // BDVER2 from http://www.agner.org/
1670 { ISD::FADD, MVT::v8f32, { 2, 5, 1, 2 } }, // BDVER2 from http://www.agner.org/
1671
1672 { ISD::FSUB, MVT::f64, { 1, 5, 1, 1 } }, // BDVER2 from http://www.agner.org/
1673 { ISD::FSUB, MVT::f32, { 1, 5, 1, 1 } }, // BDVER2 from http://www.agner.org/
1674 { ISD::FSUB, MVT::v2f64, { 1, 5, 1, 1 } }, // BDVER2 from http://www.agner.org/
1675 { ISD::FSUB, MVT::v4f32, { 1, 5, 1, 1 } }, // BDVER2 from http://www.agner.org/
1676 { ISD::FSUB, MVT::v4f64, { 2, 5, 1, 2 } }, // BDVER2 from http://www.agner.org/
1677 { ISD::FSUB, MVT::v8f32, { 2, 5, 1, 2 } }, // BDVER2 from http://www.agner.org/
1678
1679 { ISD::FMUL, MVT::f64, { 2, 5, 1, 1 } }, // BTVER2 from http://www.agner.org/
1680 { ISD::FMUL, MVT::f32, { 1, 5, 1, 1 } }, // BTVER2 from http://www.agner.org/
1681 { ISD::FMUL, MVT::v2f64, { 2, 5, 1, 1 } }, // BTVER2 from http://www.agner.org/
1682 { ISD::FMUL, MVT::v4f32, { 1, 5, 1, 1 } }, // BTVER2 from http://www.agner.org/
1683 { ISD::FMUL, MVT::v4f64, { 4, 5, 1, 2 } }, // BTVER2 from http://www.agner.org/
1684 { ISD::FMUL, MVT::v8f32, { 2, 5, 1, 2 } }, // BTVER2 from http://www.agner.org/
1685
1686 { ISD::FDIV, MVT::f32, { 14, 14, 1, 1 } }, // SNB from http://www.agner.org/
1687 { ISD::FDIV, MVT::v4f32, { 14, 14, 1, 1 } }, // SNB from http://www.agner.org/
1688 { ISD::FDIV, MVT::v8f32, { 28, 29, 1, 3 } }, // SNB from http://www.agner.org/
1689 { ISD::FDIV, MVT::f64, { 22, 22, 1, 1 } }, // SNB from http://www.agner.org/
1690 { ISD::FDIV, MVT::v2f64, { 22, 22, 1, 1 } }, // SNB from http://www.agner.org/
1691 { ISD::FDIV, MVT::v4f64, { 44, 45, 1, 3 } }, // SNB from http://www.agner.org/
1692 };
1693
1694 if (ST->hasAVX())
1695 if (const auto *Entry = CostTableLookup(AVX1CostTable, ISD, LT.second))
1696 if (auto KindCost = Entry->Cost[CostKind])
1697 return LT.first * *KindCost;
1698
1699 static const CostKindTblEntry SSE42CostTable[] = {
1700 { ISD::FADD, MVT::f64, { 1, 3, 1, 1 } }, // Nehalem from http://www.agner.org/
1701 { ISD::FADD, MVT::f32, { 1, 3, 1, 1 } }, // Nehalem from http://www.agner.org/
1702 { ISD::FADD, MVT::v2f64, { 1, 3, 1, 1 } }, // Nehalem from http://www.agner.org/
1703 { ISD::FADD, MVT::v4f32, { 1, 3, 1, 1 } }, // Nehalem from http://www.agner.org/
1704
1705 { ISD::FSUB, MVT::f64, { 1, 3, 1, 1 } }, // Nehalem from http://www.agner.org/
1706 { ISD::FSUB, MVT::f32 , { 1, 3, 1, 1 } }, // Nehalem from http://www.agner.org/
1707 { ISD::FSUB, MVT::v2f64, { 1, 3, 1, 1 } }, // Nehalem from http://www.agner.org/
1708 { ISD::FSUB, MVT::v4f32, { 1, 3, 1, 1 } }, // Nehalem from http://www.agner.org/
1709
1710 { ISD::FMUL, MVT::f64, { 1, 5, 1, 1 } }, // Nehalem from http://www.agner.org/
1711 { ISD::FMUL, MVT::f32, { 1, 5, 1, 1 } }, // Nehalem from http://www.agner.org/
1712 { ISD::FMUL, MVT::v2f64, { 1, 5, 1, 1 } }, // Nehalem from http://www.agner.org/
1713 { ISD::FMUL, MVT::v4f32, { 1, 5, 1, 1 } }, // Nehalem from http://www.agner.org/
1714
1715 { ISD::FDIV, MVT::f32, { 14, 14, 1, 1 } }, // Nehalem from http://www.agner.org/
1716 { ISD::FDIV, MVT::v4f32, { 14, 14, 1, 1 } }, // Nehalem from http://www.agner.org/
1717 { ISD::FDIV, MVT::f64, { 22, 22, 1, 1 } }, // Nehalem from http://www.agner.org/
1718 { ISD::FDIV, MVT::v2f64, { 22, 22, 1, 1 } }, // Nehalem from http://www.agner.org/
1719
1720 { ISD::MUL, MVT::v2i64, { 6, 10,10,10 } } // 3*pmuludq/3*shift/2*add
1721 };
1722
1723 if (ST->hasSSE42())
1724 if (const auto *Entry = CostTableLookup(SSE42CostTable, ISD, LT.second))
1725 if (auto KindCost = Entry->Cost[CostKind])
1726 return LT.first * *KindCost;
1727
1728 static const CostKindTblEntry SSE41CostTable[] = {
1729 { ISD::SHL, MVT::v16i8, { 15, 24,17,22 } }, // pblendvb sequence.
1730 { ISD::SHL, MVT::v8i16, { 11, 14,11,11 } }, // pblendvb sequence.
1731 { ISD::SHL, MVT::v4i32, { 14, 20, 4,10 } }, // pslld/paddd/cvttps2dq/pmulld
1732
1733 { ISD::SRL, MVT::v16i8, { 16, 27,18,24 } }, // pblendvb sequence.
1734 { ISD::SRL, MVT::v8i16, { 22, 26,23,27 } }, // pblendvb sequence.
1735 { ISD::SRL, MVT::v4i32, { 16, 17,15,19 } }, // Shift each lane + blend.
1736 { ISD::SRL, MVT::v2i64, { 4, 6, 5, 7 } }, // splat+shuffle sequence.
1737
1738 { ISD::SRA, MVT::v16i8, { 38, 41,30,36 } }, // pblendvb sequence.
1739 { ISD::SRA, MVT::v8i16, { 22, 26,23,27 } }, // pblendvb sequence.
1740 { ISD::SRA, MVT::v4i32, { 16, 17,15,19 } }, // Shift each lane + blend.
1741 { ISD::SRA, MVT::v2i64, { 8, 17, 5, 7 } }, // splat+shuffle sequence.
1742
1743 { ISD::MUL, MVT::v4i32, { 2, 11, 1, 1 } } // pmulld (Nehalem from agner.org)
1744 };
1745
1746 if (ST->hasSSE41())
1747 if (const auto *Entry = CostTableLookup(SSE41CostTable, ISD, LT.second))
1748 if (auto KindCost = Entry->Cost[CostKind])
1749 return LT.first * *KindCost;
1750
1751 static const CostKindTblEntry SSSE3CostTable[] = {
1752 { ISD::MUL, MVT::v16i8, { 5, 18,10,12 } }, // 2*pmaddubsw/3*and/psllw/or
1753 };
1754
1755 if (ST->hasSSSE3())
1756 if (const auto *Entry = CostTableLookup(SSSE3CostTable, ISD, LT.second))
1757 if (auto KindCost = Entry->Cost[CostKind])
1758 return LT.first * *KindCost;
1759
1760 static const CostKindTblEntry SSE2CostTable[] = {
1761 // We don't correctly identify costs of casts because they are marked as
1762 // custom.
1763 { ISD::SHL, MVT::v16i8, { 13, 21,26,28 } }, // cmpgtb sequence.
1764 { ISD::SHL, MVT::v8i16, { 24, 27,16,20 } }, // cmpgtw sequence.
1765 { ISD::SHL, MVT::v4i32, { 17, 19,10,12 } }, // pslld/paddd/cvttps2dq/pmuludq.
1766 { ISD::SHL, MVT::v2i64, { 4, 6, 5, 7 } }, // splat+shuffle sequence.
1767
1768 { ISD::SRL, MVT::v16i8, { 14, 28,27,30 } }, // cmpgtb sequence.
1769 { ISD::SRL, MVT::v8i16, { 16, 19,31,31 } }, // cmpgtw sequence.
1770 { ISD::SRL, MVT::v4i32, { 12, 12,15,19 } }, // Shift each lane + blend.
1771 { ISD::SRL, MVT::v2i64, { 4, 6, 5, 7 } }, // splat+shuffle sequence.
1772
1773 { ISD::SRA, MVT::v16i8, { 27, 30,54,54 } }, // unpacked cmpgtb sequence.
1774 { ISD::SRA, MVT::v8i16, { 16, 19,31,31 } }, // cmpgtw sequence.
1775 { ISD::SRA, MVT::v4i32, { 12, 12,15,19 } }, // Shift each lane + blend.
1776 { ISD::SRA, MVT::v2i64, { 8, 11,12,16 } }, // srl/xor/sub splat+shuffle sequence.
1777
1778 { ISD::AND, MVT::v16i8, { 1, 1, 1, 1 } }, // pand
1779 { ISD::AND, MVT::v8i16, { 1, 1, 1, 1 } }, // pand
1780 { ISD::AND, MVT::v4i32, { 1, 1, 1, 1 } }, // pand
1781 { ISD::AND, MVT::v2i64, { 1, 1, 1, 1 } }, // pand
1782
1783 { ISD::OR, MVT::v16i8, { 1, 1, 1, 1 } }, // por
1784 { ISD::OR, MVT::v8i16, { 1, 1, 1, 1 } }, // por
1785 { ISD::OR, MVT::v4i32, { 1, 1, 1, 1 } }, // por
1786 { ISD::OR, MVT::v2i64, { 1, 1, 1, 1 } }, // por
1787
1788 { ISD::XOR, MVT::v16i8, { 1, 1, 1, 1 } }, // pxor
1789 { ISD::XOR, MVT::v8i16, { 1, 1, 1, 1 } }, // pxor
1790 { ISD::XOR, MVT::v4i32, { 1, 1, 1, 1 } }, // pxor
1791 { ISD::XOR, MVT::v2i64, { 1, 1, 1, 1 } }, // pxor
1792
1793 { ISD::ADD, MVT::v2i64, { 1, 2, 1, 2 } }, // paddq
1794 { ISD::SUB, MVT::v2i64, { 1, 2, 1, 2 } }, // psubq
1795
1796 { ISD::MUL, MVT::v16i8, { 6, 18,12,12 } }, // 2*unpack/2*pmullw/2*and/pack
1797 { ISD::MUL, MVT::v8i16, { 1, 5, 1, 1 } }, // pmullw
1798 { ISD::MUL, MVT::v4i32, { 6, 8, 7, 7 } }, // 3*pmuludq/4*shuffle
1799 { ISD::MUL, MVT::v2i64, { 7, 10,10,10 } }, // 3*pmuludq/3*shift/2*add
1800
1801 { X86ISD::PMULUDQ, MVT::v2i64, { 1, 5, 1, 1 } },
1802
1803 { ISD::FDIV, MVT::f32, { 23, 23, 1, 1 } }, // Pentium IV from http://www.agner.org/
1804 { ISD::FDIV, MVT::v4f32, { 39, 39, 1, 1 } }, // Pentium IV from http://www.agner.org/
1805 { ISD::FDIV, MVT::f64, { 38, 38, 1, 1 } }, // Pentium IV from http://www.agner.org/
1806 { ISD::FDIV, MVT::v2f64, { 69, 69, 1, 1 } }, // Pentium IV from http://www.agner.org/
1807
1808 { ISD::FNEG, MVT::f32, { 1, 1, 1, 1 } }, // Pentium IV from http://www.agner.org/
1809 { ISD::FNEG, MVT::f64, { 1, 1, 1, 1 } }, // Pentium IV from http://www.agner.org/
1810 { ISD::FNEG, MVT::v4f32, { 1, 1, 1, 1 } }, // Pentium IV from http://www.agner.org/
1811 { ISD::FNEG, MVT::v2f64, { 1, 1, 1, 1 } }, // Pentium IV from http://www.agner.org/
1812
1813 { ISD::FADD, MVT::f32, { 2, 3, 1, 1 } }, // Pentium IV from http://www.agner.org/
1814 { ISD::FADD, MVT::f64, { 2, 3, 1, 1 } }, // Pentium IV from http://www.agner.org/
1815 { ISD::FADD, MVT::v2f64, { 2, 3, 1, 1 } }, // Pentium IV from http://www.agner.org/
1816
1817 { ISD::FSUB, MVT::f32, { 2, 3, 1, 1 } }, // Pentium IV from http://www.agner.org/
1818 { ISD::FSUB, MVT::f64, { 2, 3, 1, 1 } }, // Pentium IV from http://www.agner.org/
1819 { ISD::FSUB, MVT::v2f64, { 2, 3, 1, 1 } }, // Pentium IV from http://www.agner.org/
1820
1821 { ISD::FMUL, MVT::f64, { 2, 5, 1, 1 } }, // Pentium IV from http://www.agner.org/
1822 { ISD::FMUL, MVT::v2f64, { 2, 5, 1, 1 } }, // Pentium IV from http://www.agner.org/
1823 };
1824
1825 if (ST->hasSSE2())
1826 if (const auto *Entry = CostTableLookup(SSE2CostTable, ISD, LT.second))
1827 if (auto KindCost = Entry->Cost[CostKind])
1828 return LT.first * *KindCost;
1829
1830 static const CostKindTblEntry SSE1CostTable[] = {
1831 { ISD::FDIV, MVT::f32, { 17, 18, 1, 1 } }, // Pentium III from http://www.agner.org/
1832 { ISD::FDIV, MVT::v4f32, { 34, 48, 1, 1 } }, // Pentium III from http://www.agner.org/
1833
1834 { ISD::FNEG, MVT::f32, { 2, 2, 1, 2 } }, // Pentium III from http://www.agner.org/
1835 { ISD::FNEG, MVT::v4f32, { 2, 2, 1, 2 } }, // Pentium III from http://www.agner.org/
1836
1837 { ISD::FADD, MVT::f32, { 1, 3, 1, 1 } }, // Pentium III from http://www.agner.org/
1838 { ISD::FADD, MVT::v4f32, { 2, 3, 1, 1 } }, // Pentium III from http://www.agner.org/
1839
1840 { ISD::FSUB, MVT::f32, { 1, 3, 1, 1 } }, // Pentium III from http://www.agner.org/
1841 { ISD::FSUB, MVT::v4f32, { 2, 3, 1, 1 } }, // Pentium III from http://www.agner.org/
1842
1843 { ISD::FMUL, MVT::f32, { 2, 5, 1, 1 } }, // Pentium III from http://www.agner.org/
1844 { ISD::FMUL, MVT::v4f32, { 2, 5, 1, 1 } }, // Pentium III from http://www.agner.org/
1845 };
1846
1847 if (ST->hasSSE1())
1848 if (const auto *Entry = CostTableLookup(SSE1CostTable, ISD, LT.second))
1849 if (auto KindCost = Entry->Cost[CostKind])
1850 return LT.first * *KindCost;
1851
1852 static const CostKindTblEntry X64CostTbl[] = { // 64-bit targets
1853 { ISD::ADD, MVT::i64, { 1 } }, // Core (Merom) from http://www.agner.org/
1854 { ISD::SUB, MVT::i64, { 1 } }, // Core (Merom) from http://www.agner.org/
1855 { ISD::MUL, MVT::i64, { 2, 6, 1, 2 } },
1856 };
1857
1858 if (ST->is64Bit())
1859 if (const auto *Entry = CostTableLookup(X64CostTbl, ISD, LT.second))
1860 if (auto KindCost = Entry->Cost[CostKind])
1861 return LT.first * *KindCost;
1862
1863 static const CostKindTblEntry X86CostTbl[] = { // 32 or 64-bit targets
1864 { ISD::ADD, MVT::i8, { 1 } }, // Pentium III from http://www.agner.org/
1865 { ISD::ADD, MVT::i16, { 1 } }, // Pentium III from http://www.agner.org/
1866 { ISD::ADD, MVT::i32, { 1 } }, // Pentium III from http://www.agner.org/
1867
1868 { ISD::SUB, MVT::i8, { 1 } }, // Pentium III from http://www.agner.org/
1869 { ISD::SUB, MVT::i16, { 1 } }, // Pentium III from http://www.agner.org/
1870 { ISD::SUB, MVT::i32, { 1 } }, // Pentium III from http://www.agner.org/
1871
1872 { ISD::MUL, MVT::i8, { 3, 4, 1, 1 } },
1873 { ISD::MUL, MVT::i16, { 2, 4, 1, 1 } },
1874 { ISD::MUL, MVT::i32, { 1, 4, 1, 1 } },
1875
1876 { ISD::FNEG, MVT::f64, { 2, 2, 1, 3 } }, // (x87)
1877 { ISD::FADD, MVT::f64, { 2, 3, 1, 1 } }, // (x87)
1878 { ISD::FSUB, MVT::f64, { 2, 3, 1, 1 } }, // (x87)
1879 { ISD::FMUL, MVT::f64, { 2, 5, 1, 1 } }, // (x87)
1880 { ISD::FDIV, MVT::f64, { 38, 38, 1, 1 } }, // (x87)
1881 };
1882
1883 if (const auto *Entry = CostTableLookup(X86CostTbl, ISD, LT.second))
1884 if (auto KindCost = Entry->Cost[CostKind])
1885 return LT.first * *KindCost;
1886
1887 // It is not a good idea to vectorize division. We have to scalarize it and
1888 // in the process we will often end up having to spilling regular
1889 // registers. The overhead of division is going to dominate most kernels
1890 // anyways so try hard to prevent vectorization of division - it is
1891 // generally a bad idea. Assume somewhat arbitrarily that we have to be able
1892 // to hide "20 cycles" for each lane.
1893 if (CostKind == TTI::TCK_RecipThroughput && LT.second.isVector() &&
1894 (ISD == ISD::SDIV || ISD == ISD::SREM || ISD == ISD::UDIV ||
1895 ISD == ISD::UREM)) {
1896 InstructionCost ScalarCost =
1897 getArithmeticInstrCost(Opcode, Ty->getScalarType(), CostKind,
1898 Op1Info.getNoProps(), Op2Info.getNoProps());
1899 return 20 * LT.first * LT.second.getVectorNumElements() * ScalarCost;
1900 }
1901
1902 // Handle some basic single instruction code size cases.
1903 if (CostKind == TTI::TCK_CodeSize) {
1904 switch (ISD) {
1905 case ISD::FADD:
1906 case ISD::FSUB:
1907 case ISD::FMUL:
1908 case ISD::FDIV:
1909 case ISD::FNEG:
1910 case ISD::AND:
1911 case ISD::OR:
1912 case ISD::XOR:
1913 return LT.first;
1914 break;
1915 }
1916 }
1917
1918 // Fallback to the default implementation.
1919 return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, Op2Info,
1920 Args, CtxI, TLibInfo, Scalars);
1921}
1922
1925 unsigned Opcode1, const SmallBitVector &OpcodeMask,
1926 TTI::TargetCostKind CostKind,
1927 ArrayRef<const Value *> Scalars) const {
1928 if (isLegalAltInstr(VecTy, Opcode0, Opcode1, OpcodeMask, Scalars))
1929 return TTI::TCC_Basic;
1931}
1932
1934 TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy,
1935 TTI::TargetCostKind CostKind, ArrayRef<int> Mask, int Index,
1936 VectorType *SubTp, ArrayRef<const Value *> Args, const Instruction *CtxI,
1937 TTI::VectorInstrContext VIC) const {
1938 assert((Mask.empty() || DstTy->isScalableTy() ||
1939 Mask.size() == DstTy->getElementCount().getKnownMinValue()) &&
1940 "Expected the Mask to match the return size if given");
1941 assert(SrcTy->getScalarType() == DstTy->getScalarType() &&
1942 "Expected the same scalar types");
1943
1944 // 64-bit packed float vectors (v2f32) are widened to type v4f32.
1945 // 64-bit packed integer vectors (v2i32) are widened to type v4i32.
1946 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(SrcTy);
1947
1948 Kind = improveShuffleKindFromMask(Kind, Mask, SrcTy, Index, SubTp);
1949
1950 // If all args are constant than this will be constant folded away.
1951 if (!Args.empty() &&
1952 all_of(Args, [](const Value *Arg) { return isa<Constant>(Arg); }))
1953 return TTI::TCC_Free;
1954
1955 // Recognize a basic concat_vector shuffle.
1956 if (Kind == TTI::SK_PermuteTwoSrc &&
1957 Mask.size() == (2 * SrcTy->getElementCount().getKnownMinValue()) &&
1958 ShuffleVectorInst::isIdentityMask(Mask, Mask.size()))
1962 CostKind, Mask, Mask.size() / 2, SrcTy);
1963
1964 // Treat Transpose as 2-op shuffles - there's no difference in lowering.
1965 if (Kind == TTI::SK_Transpose)
1966 if (LT.second != MVT::v4f64 && LT.second != MVT::v4i64)
1967 Kind = TTI::SK_PermuteTwoSrc;
1968
1969 if (Kind == TTI::SK_Broadcast) {
1970 // For Broadcasts we are splatting the first element from the first input
1971 // register, so only need to reference that input and all the output
1972 // registers are the same.
1973 LT.first = 1;
1974
1975 // If we're broadcasting a load then AVX/AVX2 can do this for free.
1976 // If many-used-load whose every use is one of a small set of operations
1977 // that SLP can rewrite into a single vector lane, codegen can fold it into
1978 // the free broadcast.
1979 using namespace PatternMatch;
1980 auto IsBroadcastLoadFoldUser = [&](const User *U) {
1981 if (isa<InsertElementInst>(U) && U->getOperand(1) == Args[0])
1982 return true;
1983 if (U->getType()->isVectorTy())
1984 return false;
1985 // Terminators (return/branch/switch/indirectbr/resume/invoke EH)
1986 // and phis carry the value across control flow.
1987 if (const auto *I = dyn_cast<Instruction>(U))
1988 if (I->isTerminator() ||
1990 return false;
1991 // Only pure calls can be folded.
1992 if (const auto *CB = dyn_cast<CallBase>(U))
1993 return CB->doesNotAccessMemory() && !CB->mayHaveSideEffects();
1994 return true;
1995 };
1996 auto IsFoldableSLPBroadcastLoad = [&]() {
1997 if (!match(Args[0], m_Load(m_Value())))
1998 return false;
1999 auto *FVT = dyn_cast<FixedVectorType>(DstTy);
2000 if (!FVT)
2001 return false;
2002 // getNumUses() counts each Use, matching the per-lane broadcast
2003 // accounting (a use like `op %x, %x` consumes two broadcast lanes).
2004 if (Args[0]->getNumUses() != FVT->getNumElements())
2005 return false;
2006 return all_of(Args[0]->users(), IsBroadcastLoadFoldUser);
2007 };
2008 if (!Args.empty() &&
2009 (match(Args[0], m_OneUse(m_Load(m_Value()))) ||
2010 IsFoldableSLPBroadcastLoad()) &&
2011 (ST->hasAVX2() ||
2012 (ST->hasAVX() && LT.second.getScalarSizeInBits() >= 32)))
2013 return TTI::TCC_Free;
2014 }
2015
2016 // Attempt to detect a cheaper inlane shuffle, avoiding 128-bit subvector
2017 // permutation.
2018 // Attempt to detect a shuffle mask with a single defined element.
2019 bool IsInLaneShuffle = false;
2020 bool IsSingleElementMask = false;
2021 if (SrcTy->getPrimitiveSizeInBits() > 0 &&
2022 (SrcTy->getPrimitiveSizeInBits() % 128) == 0 &&
2023 SrcTy->getScalarSizeInBits() == LT.second.getScalarSizeInBits() &&
2024 Mask.size() == SrcTy->getElementCount().getKnownMinValue()) {
2025 unsigned NumLanes = SrcTy->getPrimitiveSizeInBits() / 128;
2026 unsigned NumEltsPerLane = Mask.size() / NumLanes;
2027 if ((Mask.size() % NumLanes) == 0) {
2028 IsInLaneShuffle = all_of(enumerate(Mask), [&](const auto &P) {
2029 return P.value() == PoisonMaskElem ||
2030 ((P.value() % Mask.size()) / NumEltsPerLane) ==
2031 (P.index() / NumEltsPerLane);
2032 });
2033 IsSingleElementMask =
2034 (Mask.size() - 1) == static_cast<unsigned>(count_if(Mask, [](int M) {
2035 return M == PoisonMaskElem;
2036 }));
2037 }
2038 }
2039
2040 // Treat <X x bfloat> shuffles as <X x half>.
2041 if (LT.second.isVectorOf(MVT::bf16))
2042 LT.second = LT.second.changeVectorElementType(MVT::f16);
2043
2044 // Subvector extractions are free if they start at the beginning of a
2045 // vector and cheap if the subvectors are aligned.
2046 if (Kind == TTI::SK_ExtractSubvector && LT.second.isVector()) {
2047 int NumElts = LT.second.getVectorNumElements();
2048 if ((Index % NumElts) == 0)
2049 return TTI::TCC_Free;
2050 std::pair<InstructionCost, MVT> SubLT = getTypeLegalizationCost(SubTp);
2051 if (SubLT.second.isVector()) {
2052 int NumSubElts = SubLT.second.getVectorNumElements();
2053 if ((Index % NumSubElts) == 0 && (NumElts % NumSubElts) == 0)
2054 return SubLT.first;
2055 // Handle some cases for widening legalization. For now we only handle
2056 // cases where the original subvector was naturally aligned and evenly
2057 // fit in its legalized subvector type.
2058 // FIXME: Remove some of the alignment restrictions.
2059 // FIXME: We can use permq for 64-bit or larger extracts from 256-bit
2060 // vectors.
2061 int OrigSubElts = cast<FixedVectorType>(SubTp)->getNumElements();
2062 if (NumSubElts > OrigSubElts && (Index % OrigSubElts) == 0 &&
2063 (NumSubElts % OrigSubElts) == 0 &&
2064 LT.second.getVectorElementType() ==
2065 SubLT.second.getVectorElementType() &&
2066 LT.second.getVectorElementType().getSizeInBits() ==
2067 SrcTy->getElementType()->getPrimitiveSizeInBits()) {
2068 assert(NumElts >= NumSubElts && NumElts > OrigSubElts &&
2069 "Unexpected number of elements!");
2070 auto *VecTy = FixedVectorType::get(SrcTy->getElementType(),
2071 LT.second.getVectorNumElements());
2072 auto *SubTy = FixedVectorType::get(SrcTy->getElementType(),
2073 SubLT.second.getVectorNumElements());
2074 int ExtractIndex = alignDown((Index % NumElts), NumSubElts);
2075 InstructionCost ExtractCost =
2076 getShuffleCost(TTI::SK_ExtractSubvector, VecTy, VecTy, CostKind, {},
2077 ExtractIndex, SubTy);
2078
2079 // If the original size is 32-bits or more, we can use pshufd. Otherwise
2080 // if we have SSSE3 we can use pshufb.
2081 if (SubTp->getPrimitiveSizeInBits() >= 32 || ST->hasSSSE3())
2082 return ExtractCost + 1; // pshufd or pshufb
2083
2084 assert(SubTp->getPrimitiveSizeInBits() == 16 &&
2085 "Unexpected vector size");
2086
2087 return ExtractCost + 2; // worst case pshufhw + pshufd
2088 }
2089 }
2090 // If the extract subvector is not optimal, treat it as single op shuffle.
2092 }
2093
2094 // Subvector insertions are cheap if the subvectors are aligned.
2095 // Note that in general, the insertion starting at the beginning of a vector
2096 // isn't free, because we need to preserve the rest of the wide vector,
2097 // but if the destination vector legalizes to the same width as the subvector
2098 // then the insertion will simplify to a (free) register copy.
2099 if (Kind == TTI::SK_InsertSubvector && LT.second.isVector()) {
2100 std::pair<InstructionCost, MVT> DstLT = getTypeLegalizationCost(DstTy);
2101 int NumElts = DstLT.second.getVectorNumElements();
2102 std::pair<InstructionCost, MVT> SubLT = getTypeLegalizationCost(SubTp);
2103 if (SubLT.second.isVector()) {
2104 int NumSubElts = SubLT.second.getVectorNumElements();
2105 bool MatchingTypes =
2106 NumElts == NumSubElts &&
2107 (SubTp->getElementCount().getKnownMinValue() % NumSubElts) == 0;
2108 if ((Index % NumSubElts) == 0 && (NumElts % NumSubElts) == 0)
2109 return MatchingTypes ? TTI::TCC_Free : SubLT.first;
2110 }
2111
2112 // Attempt to match MOVSS (Idx == 0) or INSERTPS pattern. This will have
2113 // been matched by improveShuffleKindFromMask as a SK_InsertSubvector of
2114 // v1f32 (legalised to f32) into a v4f32.
2115 if (LT.first == 1 && LT.second == MVT::v4f32 && SubLT.first == 1 &&
2116 SubLT.second == MVT::f32 && (Index == 0 || ST->hasSSE41()))
2117 return 1;
2118
2119 // If the insertion is the lowest subvector then it will be blended
2120 // otherwise treat it like a 2-op shuffle.
2121 Kind =
2122 (Index == 0 && LT.first == 1) ? TTI::SK_Select : TTI::SK_PermuteTwoSrc;
2123 }
2124
2125 // Handle some common (illegal) sub-vector types as they are often very cheap
2126 // to shuffle even on targets without PSHUFB.
2127 EVT VT = TLI->getValueType(DL, SrcTy);
2128 if (VT.isSimple() && VT.isVector() && VT.getSizeInBits() < 128 &&
2129 !ST->hasSSSE3()) {
2130 static const CostKindTblEntry SSE2SubVectorShuffleTbl[] = {
2131 {TTI::SK_Broadcast, MVT::v4i16, {1,1,1,1}}, // pshuflw
2132 {TTI::SK_Broadcast, MVT::v2i16, {1,1,1,1}}, // pshuflw
2133 {TTI::SK_Broadcast, MVT::v8i8, {2,2,2,2}}, // punpck/pshuflw
2134 {TTI::SK_Broadcast, MVT::v4i8, {2,2,2,2}}, // punpck/pshuflw
2135 {TTI::SK_Broadcast, MVT::v2i8, {1,1,1,1}}, // punpck
2136
2137 {TTI::SK_Reverse, MVT::v4i16, {1,1,1,1}}, // pshuflw
2138 {TTI::SK_Reverse, MVT::v2i16, {1,1,1,1}}, // pshuflw
2139 {TTI::SK_Reverse, MVT::v4i8, {3,3,3,3}}, // punpck/pshuflw/packus
2140 {TTI::SK_Reverse, MVT::v2i8, {1,1,1,1}}, // punpck
2141
2142 {TTI::SK_Splice, MVT::v4i16, {2,2,2,2}}, // punpck+psrldq
2143 {TTI::SK_Splice, MVT::v2i16, {2,2,2,2}}, // punpck+psrldq
2144 {TTI::SK_Splice, MVT::v4i8, {2,2,2,2}}, // punpck+psrldq
2145 {TTI::SK_Splice, MVT::v2i8, {2,2,2,2}}, // punpck+psrldq
2146
2147 {TTI::SK_PermuteTwoSrc, MVT::v4i16, {2,2,2,2}}, // punpck/pshuflw
2148 {TTI::SK_PermuteTwoSrc, MVT::v2i16, {2,2,2,2}}, // punpck/pshuflw
2149 {TTI::SK_PermuteTwoSrc, MVT::v8i8, {7,7,7,7}}, // punpck/pshuflw
2150 {TTI::SK_PermuteTwoSrc, MVT::v4i8, {4,4,4,4}}, // punpck/pshuflw
2151 {TTI::SK_PermuteTwoSrc, MVT::v2i8, {2,2,2,2}}, // punpck
2152
2153 {TTI::SK_PermuteSingleSrc, MVT::v4i16, {1,1,1,1}}, // pshuflw
2154 {TTI::SK_PermuteSingleSrc, MVT::v2i16, {1,1,1,1}}, // pshuflw
2155 {TTI::SK_PermuteSingleSrc, MVT::v8i8, {5,5,5,5}}, // punpck/pshuflw
2156 {TTI::SK_PermuteSingleSrc, MVT::v4i8, {3,3,3,3}}, // punpck/pshuflw
2157 {TTI::SK_PermuteSingleSrc, MVT::v2i8, {1,1,1,1}}, // punpck
2158 };
2159
2160 if (ST->hasSSE2())
2161 if (const auto *Entry =
2162 CostTableLookup(SSE2SubVectorShuffleTbl, Kind, VT.getSimpleVT()))
2163 if (auto KindCost = Entry->Cost[CostKind])
2164 return LT.first * *KindCost;
2165 }
2166
2167 // We are going to permute multiple sources and the result will be in multiple
2168 // destinations. Providing an accurate cost only for splits where the element
2169 // type remains the same.
2170 if (LT.first != 1) {
2171 MVT LegalVT = LT.second;
2172 if (LegalVT.isVector() &&
2173 LegalVT.getVectorElementType().getSizeInBits() ==
2174 SrcTy->getElementType()->getPrimitiveSizeInBits() &&
2175 LegalVT.getVectorNumElements() <
2176 cast<FixedVectorType>(SrcTy)->getNumElements()) {
2177 unsigned VecTySize = DL.getTypeStoreSize(SrcTy);
2178 unsigned LegalVTSize = LegalVT.getStoreSize();
2179 // Number of source vectors after legalization:
2180 unsigned NumOfSrcs = (VecTySize + LegalVTSize - 1) / LegalVTSize;
2181 // Number of destination vectors after legalization:
2182 InstructionCost NumOfDests = LT.first;
2183
2184 auto *SingleOpTy = FixedVectorType::get(SrcTy->getElementType(),
2185 LegalVT.getVectorNumElements());
2186
2187 if (!Mask.empty() && NumOfDests.isValid()) {
2188 // Try to perform better estimation of the permutation.
2189 // 1. Split the source/destination vectors into real registers.
2190 // 2. Do the mask analysis to identify which real registers are
2191 // permuted. If more than 1 source registers are used for the
2192 // destination register building, the cost for this destination register
2193 // is (Number_of_source_register - 1) * Cost_PermuteTwoSrc. If only one
2194 // source register is used, build mask and calculate the cost as a cost
2195 // of PermuteSingleSrc.
2196 // Also, for the single register permute we try to identify if the
2197 // destination register is just a copy of the source register or the
2198 // copy of the previous destination register (the cost is
2199 // TTI::TCC_Basic). If the source register is just reused, the cost for
2200 // this operation is TTI::TCC_Free.
2201 NumOfDests =
2203 FixedVectorType::get(SrcTy->getElementType(), Mask.size()))
2204 .first;
2205 unsigned E = NumOfDests.getValue();
2206 unsigned NormalizedVF =
2207 LegalVT.getVectorNumElements() * std::max(NumOfSrcs, E);
2208 unsigned NumOfSrcRegs = NormalizedVF / LegalVT.getVectorNumElements();
2209 unsigned NumOfDestRegs = NormalizedVF / LegalVT.getVectorNumElements();
2210 SmallVector<int> NormalizedMask(NormalizedVF, PoisonMaskElem);
2211 copy(Mask, NormalizedMask.begin());
2212 unsigned PrevSrcReg = 0;
2213 ArrayRef<int> PrevRegMask;
2216 NormalizedMask, NumOfSrcRegs, NumOfDestRegs, NumOfDestRegs, []() {},
2217 [this, SingleOpTy, CostKind, &PrevSrcReg, &PrevRegMask,
2218 &Cost](ArrayRef<int> RegMask, unsigned SrcReg, unsigned DestReg) {
2219 if (!ShuffleVectorInst::isIdentityMask(RegMask, RegMask.size())) {
2220 // Check if the previous register can be just copied to the next
2221 // one.
2222 if (PrevRegMask.empty() || PrevSrcReg != SrcReg ||
2223 PrevRegMask != RegMask)
2224 Cost +=
2226 SingleOpTy, CostKind, RegMask, 0, nullptr);
2227 else
2228 // Just a copy of previous destination register.
2230 return;
2231 }
2232 if (SrcReg != DestReg &&
2233 any_of(RegMask, not_equal_to(PoisonMaskElem))) {
2234 // Just a copy of the source register.
2236 }
2237 PrevSrcReg = SrcReg;
2238 PrevRegMask = RegMask;
2239 },
2240 [this, SingleOpTy, CostKind,
2241 &Cost](ArrayRef<int> RegMask, unsigned /*Unused*/,
2242 unsigned /*Unused*/, bool /*Unused*/) {
2244 SingleOpTy, CostKind, RegMask, 0, nullptr);
2245 });
2246 return Cost;
2247 }
2248
2249 InstructionCost NumOfShuffles = (NumOfSrcs - 1) * NumOfDests;
2250 return NumOfShuffles * getShuffleCost(TTI::SK_PermuteTwoSrc, SingleOpTy,
2251 SingleOpTy, CostKind, {}, 0,
2252 nullptr);
2253 }
2254
2255 return BaseT::getShuffleCost(Kind, DstTy, SrcTy, CostKind, Mask, Index,
2256 SubTp);
2257 }
2258
2259 // If we're just moving a single element around (probably as an alternative to
2260 // extracting it), we can assume this is cheap.
2261 if (LT.first == 1 && IsInLaneShuffle && IsSingleElementMask)
2262 return TTI::TCC_Basic;
2263
2264 static const CostKindTblEntry AVX512VBMIShuffleTbl[] = {
2265 { TTI::SK_Reverse, MVT::v64i8, { 1, 1, 1, 1 } }, // vpermb
2266 { TTI::SK_Reverse, MVT::v32i8, { 1, 1, 1, 1 } }, // vpermb
2267 { TTI::SK_PermuteSingleSrc, MVT::v64i8, { 1, 1, 1, 1 } }, // vpermb
2268 { TTI::SK_PermuteSingleSrc, MVT::v32i8, { 1, 1, 1, 1 } }, // vpermb
2269 { TTI::SK_PermuteTwoSrc, MVT::v64i8, { 2, 2, 2, 2 } }, // vpermt2b
2270 { TTI::SK_PermuteTwoSrc, MVT::v32i8, { 2, 2, 2, 2 } }, // vpermt2b
2271 { TTI::SK_PermuteTwoSrc, MVT::v16i8, { 2, 2, 2, 2 } } // vpermt2b
2272 };
2273
2274 if (ST->hasVBMI())
2275 if (const auto *Entry =
2276 CostTableLookup(AVX512VBMIShuffleTbl, Kind, LT.second))
2277 if (auto KindCost = Entry->Cost[CostKind])
2278 return LT.first * *KindCost;
2279
2280 static const CostKindTblEntry AVX512BWInLaneShuffleTbl[] = {
2281 {TTI::SK_PermuteTwoSrc, MVT::v64i8, {2, 2, 2, 2}}, // 2*vpshufb + vpor
2282 };
2283
2284 if (IsInLaneShuffle && ST->hasBWI())
2285 if (const auto *Entry =
2286 CostTableLookup(AVX512BWInLaneShuffleTbl, Kind, LT.second))
2287 if (auto KindCost = Entry->Cost[CostKind])
2288 return LT.first * *KindCost;
2289
2290 static const CostKindTblEntry AVX512BWShuffleTbl[] = {
2291 { TTI::SK_Broadcast, MVT::v32i16, { 1, 3, 1, 1 } }, // vpbroadcastw
2292 { TTI::SK_Broadcast, MVT::v32f16, { 1, 3, 1, 1 } }, // vpbroadcastw
2293 { TTI::SK_Broadcast, MVT::v64i8, { 1, 3, 1, 1 } }, // vpbroadcastb
2294
2295 { TTI::SK_Reverse, MVT::v32i16, { 2, 6, 2, 4 } }, // vpermw
2296 { TTI::SK_Reverse, MVT::v32f16, { 2, 6, 2, 4 } }, // vpermw
2297 { TTI::SK_Reverse, MVT::v16i16, { 2, 2, 2, 2 } }, // vpermw
2298 { TTI::SK_Reverse, MVT::v16f16, { 2, 2, 2, 2 } }, // vpermw
2299 { TTI::SK_Reverse, MVT::v64i8, { 2, 9, 2, 3 } }, // pshufb + vshufi64x2
2300
2301 { TTI::SK_PermuteSingleSrc, MVT::v32i16, { 2, 2, 2, 2 } }, // vpermw
2302 { TTI::SK_PermuteSingleSrc, MVT::v32f16, { 2, 2, 2, 2 } }, // vpermw
2303 { TTI::SK_PermuteSingleSrc, MVT::v16i16, { 2, 2, 2, 2 } }, // vpermw
2304 { TTI::SK_PermuteSingleSrc, MVT::v16f16, { 2, 2, 2, 2 } }, // vpermw
2305 { TTI::SK_PermuteSingleSrc, MVT::v64i8, { 8, 8, 8, 8 } }, // extend to v32i16
2306
2307 { TTI::SK_PermuteTwoSrc, MVT::v32i16,{ 2, 2, 2, 2 } }, // vpermt2w
2308 { TTI::SK_PermuteTwoSrc, MVT::v32f16,{ 2, 2, 2, 2 } }, // vpermt2w
2309 { TTI::SK_PermuteTwoSrc, MVT::v16i16,{ 2, 2, 2, 2 } }, // vpermt2w
2310 { TTI::SK_PermuteTwoSrc, MVT::v8i16, { 2, 2, 2, 2 } }, // vpermt2w
2311 { TTI::SK_PermuteTwoSrc, MVT::v64i8, { 19, 19, 19, 19 } }, // 6 * v32i8 + 1
2312
2313 { TTI::SK_Select, MVT::v32i16, { 1, 1, 1, 1 } }, // vblendmw
2314 { TTI::SK_Select, MVT::v64i8, { 1, 1, 1, 1 } }, // vblendmb
2315
2316 { TTI::SK_Splice, MVT::v32i16, { 2, 2, 2, 2 } }, // vshufi64x2 + palignr
2317 { TTI::SK_Splice, MVT::v32f16, { 2, 2, 2, 2 } }, // vshufi64x2 + palignr
2318 { TTI::SK_Splice, MVT::v64i8, { 2, 2, 2, 2 } }, // vshufi64x2 + palignr
2319 };
2320
2321 if (ST->hasBWI())
2322 if (const auto *Entry =
2323 CostTableLookup(AVX512BWShuffleTbl, Kind, LT.second))
2324 if (auto KindCost = Entry->Cost[CostKind])
2325 return LT.first * *KindCost;
2326
2327 static const CostKindTblEntry AVX512InLaneShuffleTbl[] = {
2328 {TTI::SK_PermuteTwoSrc, MVT::v8f64, { 1, 3, 1, 1 } },
2329 {TTI::SK_PermuteTwoSrc, MVT::v16f32, { 1, 3, 1, 1 } },
2330 {TTI::SK_PermuteTwoSrc, MVT::v8i64, { 1, 3, 1, 1 } },
2331 {TTI::SK_PermuteTwoSrc, MVT::v16i32, { 1, 3, 1, 1 } },
2332 {TTI::SK_PermuteTwoSrc, MVT::v4f64, { 1, 3, 1, 1 } },
2333 {TTI::SK_PermuteTwoSrc, MVT::v8f32, { 1, 3, 1, 1 } },
2334 {TTI::SK_PermuteTwoSrc, MVT::v4i64, { 1, 3, 1, 1 } },
2335 {TTI::SK_PermuteTwoSrc, MVT::v8i32, { 1, 3, 1, 1 } },
2336 };
2337
2338 if (IsInLaneShuffle && ST->hasAVX512())
2339 if (const auto *Entry =
2340 CostTableLookup(AVX512InLaneShuffleTbl, Kind, LT.second))
2341 if (auto KindCost = Entry->Cost[CostKind])
2342 return LT.first * *KindCost;
2343
2344 static const CostKindTblEntry AVX512ShuffleTbl[] = {
2345 {TTI::SK_Broadcast, MVT::v8f64, { 1, 3, 1, 1 } }, // vbroadcastsd
2346 {TTI::SK_Broadcast, MVT::v4f64, { 1, 3, 1, 1 } }, // vbroadcastsd
2347 {TTI::SK_Broadcast, MVT::v16f32, { 1, 3, 1, 1 } }, // vbroadcastss
2348 {TTI::SK_Broadcast, MVT::v8f32, { 1, 3, 1, 1 } }, // vbroadcastss
2349 {TTI::SK_Broadcast, MVT::v8i64, { 1, 3, 1, 1 } }, // vpbroadcastq
2350 {TTI::SK_Broadcast, MVT::v4i64, { 1, 3, 1, 1 } }, // vpbroadcastq
2351 {TTI::SK_Broadcast, MVT::v16i32, { 1, 3, 1, 1 } }, // vpbroadcastd
2352 {TTI::SK_Broadcast, MVT::v8i32, { 1, 3, 1, 1 } }, // vpbroadcastd
2353 {TTI::SK_Broadcast, MVT::v32i16, { 1, 3, 1, 1 } }, // vpbroadcastw
2354 {TTI::SK_Broadcast, MVT::v16i16, { 1, 3, 1, 1 } }, // vpbroadcastw
2355 {TTI::SK_Broadcast, MVT::v32f16, { 1, 3, 1, 1 } }, // vpbroadcastw
2356 {TTI::SK_Broadcast, MVT::v16f16, { 1, 3, 1, 1 } }, // vpbroadcastw
2357 {TTI::SK_Broadcast, MVT::v64i8, { 1, 3, 1, 1 } }, // vpbroadcastb
2358 {TTI::SK_Broadcast, MVT::v32i8, { 1, 3, 1, 1 }}, // vpbroadcastb
2359
2360 {TTI::SK_Reverse, MVT::v8f64, { 1, 5, 2, 3 } }, // vpermpd
2361 {TTI::SK_Reverse, MVT::v16f32, { 1, 3, 2, 3 } }, // vpermps
2362 {TTI::SK_Reverse, MVT::v8i64, { 1, 5, 2, 3 } }, // vpermq
2363 {TTI::SK_Reverse, MVT::v16i32, { 1, 3, 2, 3 } }, // vpermd
2364 {TTI::SK_Reverse, MVT::v32i16, { 7, 7, 7, 7 } }, // per mca
2365 {TTI::SK_Reverse, MVT::v32f16, { 7, 7, 7, 7 } }, // per mca
2366 {TTI::SK_Reverse, MVT::v64i8, { 7, 7, 7, 7 } }, // per mca
2367
2368 {TTI::SK_Splice, MVT::v8f64, { 1, 1, 1, 1 } }, // vpalignd
2369 {TTI::SK_Splice, MVT::v4f64, { 1, 1, 1, 1 } }, // vpalignd
2370 {TTI::SK_Splice, MVT::v16f32, { 1, 1, 1, 1 } }, // vpalignd
2371 {TTI::SK_Splice, MVT::v8f32, { 1, 1, 1, 1 } }, // vpalignd
2372 {TTI::SK_Splice, MVT::v8i64, { 1, 1, 1, 1 } }, // vpalignd
2373 {TTI::SK_Splice, MVT::v4i64, { 1, 1, 1, 1 } }, // vpalignd
2374 {TTI::SK_Splice, MVT::v16i32, { 1, 1, 1, 1 } }, // vpalignd
2375 {TTI::SK_Splice, MVT::v8i32, { 1, 1, 1, 1 } }, // vpalignd
2376 {TTI::SK_Splice, MVT::v32i16, { 4, 4, 4, 4 } }, // split + palignr
2377 {TTI::SK_Splice, MVT::v32f16, { 4, 4, 4, 4 } }, // split + palignr
2378 {TTI::SK_Splice, MVT::v64i8, { 4, 4, 4, 4 } }, // split + palignr
2379
2380 {TTI::SK_PermuteSingleSrc, MVT::v8f64, { 1, 3, 1, 1 } }, // vpermpd
2381 {TTI::SK_PermuteSingleSrc, MVT::v4f64, { 1, 3, 1, 1 } }, // vpermpd
2382 {TTI::SK_PermuteSingleSrc, MVT::v2f64, { 1, 3, 1, 1 } }, // vpermpd
2383 {TTI::SK_PermuteSingleSrc, MVT::v16f32, { 1, 3, 1, 1 } }, // vpermps
2384 {TTI::SK_PermuteSingleSrc, MVT::v8f32, { 1, 3, 1, 1 } }, // vpermps
2385 {TTI::SK_PermuteSingleSrc, MVT::v4f32, { 1, 3, 1, 1 } }, // vpermps
2386 {TTI::SK_PermuteSingleSrc, MVT::v8i64, { 1, 3, 1, 1 } }, // vpermq
2387 {TTI::SK_PermuteSingleSrc, MVT::v4i64, { 1, 3, 1, 1 } }, // vpermq
2388 {TTI::SK_PermuteSingleSrc, MVT::v2i64, { 1, 3, 1, 1 } }, // vpermq
2389 {TTI::SK_PermuteSingleSrc, MVT::v16i32, { 1, 3, 1, 1 } }, // vpermd
2390 {TTI::SK_PermuteSingleSrc, MVT::v8i32, { 1, 3, 1, 1 } }, // vpermd
2391 {TTI::SK_PermuteSingleSrc, MVT::v4i32, { 1, 3, 1, 1 } }, // vpermd
2392 {TTI::SK_PermuteSingleSrc, MVT::v16i8, { 1, 3, 1, 1 } }, // pshufb
2393
2394 {TTI::SK_PermuteTwoSrc, MVT::v8f64, { 2, 3, 1, 1 } }, // vpermt2pd
2395 {TTI::SK_PermuteTwoSrc, MVT::v16f32, { 2, 3, 1, 1 } }, // vpermt2ps
2396 {TTI::SK_PermuteTwoSrc, MVT::v8i64, { 2, 3, 1, 1 } }, // vpermt2q
2397 {TTI::SK_PermuteTwoSrc, MVT::v16i32, { 2, 3, 1, 1 } }, // vpermt2d
2398 {TTI::SK_PermuteTwoSrc, MVT::v4f64, { 2, 3, 1, 1 } }, // vpermt2pd
2399 {TTI::SK_PermuteTwoSrc, MVT::v8f32, { 2, 3, 1, 1 } }, // vpermt2ps
2400 {TTI::SK_PermuteTwoSrc, MVT::v4i64, { 2, 3, 1, 1 } }, // vpermt2q
2401 {TTI::SK_PermuteTwoSrc, MVT::v8i32, { 2, 3, 1, 1 } }, // vpermt2d
2402 {TTI::SK_PermuteTwoSrc, MVT::v2f64, { 1, 3, 1, 1 } },
2403 {TTI::SK_PermuteTwoSrc, MVT::v4f32, { 1, 3, 1, 1 } },
2404 {TTI::SK_PermuteTwoSrc, MVT::v2i64, { 1, 3, 1, 1 } },
2405 {TTI::SK_PermuteTwoSrc, MVT::v4i32, { 1, 3, 1, 1 } },
2406
2407 // FIXME: This just applies the type legalization cost rules above
2408 // assuming these completely split.
2409 {TTI::SK_PermuteSingleSrc, MVT::v32i16, { 14, 14, 14, 14 } },
2410 {TTI::SK_PermuteSingleSrc, MVT::v32f16, { 14, 14, 14, 14 } },
2411 {TTI::SK_PermuteSingleSrc, MVT::v64i8, { 14, 14, 14, 14 } },
2412 {TTI::SK_PermuteTwoSrc, MVT::v32i16, { 42, 42, 42, 42 } },
2413 {TTI::SK_PermuteTwoSrc, MVT::v32f16, { 42, 42, 42, 42 } },
2414 {TTI::SK_PermuteTwoSrc, MVT::v64i8, { 42, 42, 42, 42 } },
2415
2416 {TTI::SK_Select, MVT::v32i16, { 1, 1, 1, 1 } }, // vpternlogq
2417 {TTI::SK_Select, MVT::v32f16, { 1, 1, 1, 1 } }, // vpternlogq
2418 {TTI::SK_Select, MVT::v64i8, { 1, 1, 1, 1 } }, // vpternlogq
2419 {TTI::SK_Select, MVT::v8f64, { 1, 1, 1, 1 } }, // vblendmpd
2420 {TTI::SK_Select, MVT::v16f32, { 1, 1, 1, 1 } }, // vblendmps
2421 {TTI::SK_Select, MVT::v8i64, { 1, 1, 1, 1 } }, // vblendmq
2422 {TTI::SK_Select, MVT::v16i32, { 1, 1, 1, 1 } }, // vblendmd
2423 };
2424
2425 if (ST->hasAVX512())
2426 if (const auto *Entry = CostTableLookup(AVX512ShuffleTbl, Kind, LT.second))
2427 if (auto KindCost = Entry->Cost[CostKind])
2428 return LT.first * *KindCost;
2429
2430 static const CostKindTblEntry AVX2InLaneShuffleTbl[] = {
2431 { TTI::SK_PermuteSingleSrc, MVT::v16i16, { 1, 1, 1, 1 } }, // vpshufb
2432 { TTI::SK_PermuteSingleSrc, MVT::v16f16, { 1, 1, 1, 1 } }, // vpshufb
2433 { TTI::SK_PermuteSingleSrc, MVT::v32i8, { 1, 1, 1, 1 } }, // vpshufb
2434
2435 { TTI::SK_Transpose, MVT::v4f64, { 1, 1, 1, 1 } }, // vshufpd/vunpck
2436 { TTI::SK_Transpose, MVT::v4i64, { 1, 1, 1, 1 } }, // vshufpd/vunpck
2437
2438 { TTI::SK_PermuteTwoSrc, MVT::v4f64, { 2, 2, 2, 2 } }, // 2*vshufpd + vblendpd
2439 { TTI::SK_PermuteTwoSrc, MVT::v8f32, { 2, 2, 2, 2 } }, // 2*vshufps + vblendps
2440 { TTI::SK_PermuteTwoSrc, MVT::v4i64, { 2, 2, 2, 2 } }, // 2*vpshufd + vpblendd
2441 { TTI::SK_PermuteTwoSrc, MVT::v8i32, { 2, 2, 2, 2 } }, // 2*vpshufd + vpblendd
2442 { TTI::SK_PermuteTwoSrc, MVT::v16i16, { 2, 2, 2, 2 } }, // 2*vpshufb + vpor
2443 { TTI::SK_PermuteTwoSrc, MVT::v16f16, { 2, 2, 2, 2 } }, // 2*vpshufb + vpor
2444 { TTI::SK_PermuteTwoSrc, MVT::v32i8, { 2, 2, 2, 2 } }, // 2*vpshufb + vpor
2445 };
2446
2447 if (IsInLaneShuffle && ST->hasAVX2())
2448 if (const auto *Entry =
2449 CostTableLookup(AVX2InLaneShuffleTbl, Kind, LT.second))
2450 if (auto KindCost = Entry->Cost[CostKind])
2451 return LT.first * *KindCost;
2452
2453 static const CostKindTblEntry AVX2ShuffleTbl[] = {
2454 { TTI::SK_Broadcast, MVT::v4f64, { 1, 3, 1, 2 } }, // vbroadcastpd
2455 { TTI::SK_Broadcast, MVT::v8f32, { 1, 3, 1, 2 } }, // vbroadcastps
2456 { TTI::SK_Broadcast, MVT::v4i64, { 1, 3, 1, 2 } }, // vpbroadcastq
2457 { TTI::SK_Broadcast, MVT::v8i32, { 1, 3, 1, 2 } }, // vpbroadcastd
2458 { TTI::SK_Broadcast, MVT::v16i16, { 1, 3, 1, 2 } }, // vpbroadcastw
2459 { TTI::SK_Broadcast, MVT::v8i16, { 1, 3, 1, 1 } }, // vpbroadcastw
2460 { TTI::SK_Broadcast, MVT::v16f16, { 1, 3, 1, 2 } }, // vpbroadcastw
2461 { TTI::SK_Broadcast, MVT::v8f16, { 1, 3, 1, 1 } }, // vpbroadcastw
2462 { TTI::SK_Broadcast, MVT::v32i8, { 1, 3, 1, 2 } }, // vpbroadcastb
2463 { TTI::SK_Broadcast, MVT::v16i8, { 1, 3, 1, 1 } }, // vpbroadcastb
2464
2465 { TTI::SK_Reverse, MVT::v4f64, { 1, 6, 1, 2 } }, // vpermpd
2466 { TTI::SK_Reverse, MVT::v8f32, { 2, 7, 2, 4 } }, // vpermps
2467 { TTI::SK_Reverse, MVT::v4i64, { 1, 6, 1, 2 } }, // vpermq
2468 { TTI::SK_Reverse, MVT::v8i32, { 2, 7, 2, 4 } }, // vpermd
2469 { TTI::SK_Reverse, MVT::v16i16, { 2, 9, 2, 4 } }, // vperm2i128 + pshufb
2470 { TTI::SK_Reverse, MVT::v16f16, { 2, 9, 2, 4 } }, // vperm2i128 + pshufb
2471 { TTI::SK_Reverse, MVT::v32i8, { 2, 9, 2, 4 } }, // vperm2i128 + pshufb
2472
2473 { TTI::SK_Select, MVT::v16i16, { 1, 1, 1, 1 } }, // vpblendvb
2474 { TTI::SK_Select, MVT::v16f16, { 1, 1, 1, 1 } }, // vpblendvb
2475 { TTI::SK_Select, MVT::v32i8, { 1, 1, 1, 1 } }, // vpblendvb
2476
2477 { TTI::SK_Splice, MVT::v8i32, { 2, 2, 2, 2 } }, // vperm2i128 + vpalignr
2478 { TTI::SK_Splice, MVT::v8f32, { 2, 2, 2, 2 } }, // vperm2i128 + vpalignr
2479 { TTI::SK_Splice, MVT::v16i16, { 2, 2, 2, 2 } }, // vperm2i128 + vpalignr
2480 { TTI::SK_Splice, MVT::v16f16, { 2, 2, 2, 2 } }, // vperm2i128 + vpalignr
2481 { TTI::SK_Splice, MVT::v32i8, { 2, 2, 2, 2 } }, // vperm2i128 + vpalignr
2482
2483 { TTI::SK_PermuteSingleSrc, MVT::v4f64, { 1, 1, 1, 1 } }, // vpermpd
2484 { TTI::SK_PermuteSingleSrc, MVT::v8f32, { 1, 1, 1, 1 } }, // vpermps
2485 { TTI::SK_PermuteSingleSrc, MVT::v4i64, { 1, 1, 1, 1 } }, // vpermq
2486 { TTI::SK_PermuteSingleSrc, MVT::v8i32, { 1, 1, 1, 1 } }, // vpermd
2487 { TTI::SK_PermuteSingleSrc, MVT::v16i16, { 4, 4, 4, 4 } },
2488 { TTI::SK_PermuteSingleSrc, MVT::v16f16, { 4, 4, 4, 4 } },
2489 { TTI::SK_PermuteSingleSrc, MVT::v32i8, { 4, 4, 4, 4 } },
2490
2491 { TTI::SK_PermuteTwoSrc, MVT::v4f64, { 3, 3, 3, 3 } }, // 2*vpermpd + vblendpd
2492 { TTI::SK_PermuteTwoSrc, MVT::v8f32, { 3, 3, 3, 3 } }, // 2*vpermps + vblendps
2493 { TTI::SK_PermuteTwoSrc, MVT::v4i64, { 3, 3, 3, 3 } }, // 2*vpermq + vpblendd
2494 { TTI::SK_PermuteTwoSrc, MVT::v8i32, { 3, 3, 3, 3 } }, // 2*vpermd + vpblendd
2495 { TTI::SK_PermuteTwoSrc, MVT::v16i16, { 7, 7, 7, 7 } },
2496 { TTI::SK_PermuteTwoSrc, MVT::v16f16, { 7, 7, 7, 7 } },
2497 { TTI::SK_PermuteTwoSrc, MVT::v32i8, { 7, 7, 7, 7 } },
2498 };
2499
2500 if (ST->hasAVX2())
2501 if (const auto *Entry = CostTableLookup(AVX2ShuffleTbl, Kind, LT.second))
2502 if (auto KindCost = Entry->Cost[CostKind])
2503 return LT.first * *KindCost;
2504
2505 static const CostKindTblEntry XOPShuffleTbl[] = {
2506 { TTI::SK_PermuteSingleSrc, MVT::v4f64, { 2, 2, 2, 2 } }, // vperm2f128 + vpermil2pd
2507 { TTI::SK_PermuteSingleSrc, MVT::v8f32, { 2, 2, 2, 2 } }, // vperm2f128 + vpermil2ps
2508 { TTI::SK_PermuteSingleSrc, MVT::v4i64, { 2, 2, 2, 2 } }, // vperm2f128 + vpermil2pd
2509 { TTI::SK_PermuteSingleSrc, MVT::v8i32, { 2, 2, 2, 2 } }, // vperm2f128 + vpermil2ps
2510 { TTI::SK_PermuteSingleSrc, MVT::v16i16,{ 4, 4, 4, 4 } }, // vextractf128 + 2*vpperm
2511 // + vinsertf128
2512 { TTI::SK_PermuteSingleSrc, MVT::v32i8, { 4, 4, 4, 4 } }, // vextractf128 + 2*vpperm
2513 // + vinsertf128
2514
2515 { TTI::SK_PermuteTwoSrc, MVT::v16i16, { 9, 9, 9, 9 } }, // 2*vextractf128 + 6*vpperm
2516 // + vinsertf128
2517
2518 { TTI::SK_PermuteTwoSrc, MVT::v8i16, { 1, 1, 1, 1 } }, // vpperm
2519 { TTI::SK_PermuteTwoSrc, MVT::v32i8, { 9, 9, 9, 9 } }, // 2*vextractf128 + 6*vpperm
2520 // + vinsertf128
2521 { TTI::SK_PermuteTwoSrc, MVT::v16i8, { 1, 1, 1, 1 } }, // vpperm
2522 };
2523
2524 if (ST->hasXOP())
2525 if (const auto *Entry = CostTableLookup(XOPShuffleTbl, Kind, LT.second))
2526 if (auto KindCost = Entry->Cost[CostKind])
2527 return LT.first * *KindCost;
2528
2529 static const CostKindTblEntry AVX1InLaneShuffleTbl[] = {
2530 { TTI::SK_PermuteSingleSrc, MVT::v4f64, { 1, 1, 1, 1 } }, // vpermilpd
2531 { TTI::SK_PermuteSingleSrc, MVT::v4i64, { 1, 1, 1, 1 } }, // vpermilpd
2532 { TTI::SK_PermuteSingleSrc, MVT::v8f32, { 1, 1, 1, 1 } }, // vpermilps
2533 { TTI::SK_PermuteSingleSrc, MVT::v8i32, { 1, 1, 1, 1 } }, // vpermilps
2534
2535 { TTI::SK_PermuteSingleSrc, MVT::v16i16, { 4, 4, 4, 4 } }, // vextractf128 + 2*pshufb
2536 // + vpor + vinsertf128
2537 { TTI::SK_PermuteSingleSrc, MVT::v16f16, { 4, 4, 4, 4 } }, // vextractf128 + 2*pshufb
2538 // + vpor + vinsertf128
2539 { TTI::SK_PermuteSingleSrc, MVT::v32i8, { 4, 4, 4, 4 } }, // vextractf128 + 2*pshufb
2540 // + vpor + vinsertf128
2541
2542 { TTI::SK_Transpose, MVT::v4f64, { 1, 1, 1, 1 } }, // vshufpd/vunpck
2543 { TTI::SK_Transpose, MVT::v4i64, { 1, 1, 1, 1 } }, // vshufpd/vunpck
2544
2545 { TTI::SK_PermuteTwoSrc, MVT::v4f64, { 2, 2, 2, 2 } }, // 2*vshufpd + vblendpd
2546 { TTI::SK_PermuteTwoSrc, MVT::v8f32, { 2, 2, 2, 2 } }, // 2*vshufps + vblendps
2547 { TTI::SK_PermuteTwoSrc, MVT::v4i64, { 2, 2, 2, 2 } }, // 2*vpermilpd + vblendpd
2548 { TTI::SK_PermuteTwoSrc, MVT::v8i32, { 2, 2, 2, 2 } }, // 2*vpermilps + vblendps
2549 { TTI::SK_PermuteTwoSrc, MVT::v16i16, { 9, 9, 9, 9 } }, // 2*vextractf128 + 4*pshufb
2550 // + 2*vpor + vinsertf128
2551 { TTI::SK_PermuteTwoSrc, MVT::v16f16, { 9, 9, 9, 9 } }, // 2*vextractf128 + 4*pshufb
2552 // + 2*vpor + vinsertf128
2553 { TTI::SK_PermuteTwoSrc, MVT::v32i8, { 9, 9, 9, 9 } }, // 2*vextractf128 + 4*pshufb
2554 // + 2*vpor + vinsertf128
2555 };
2556
2557 if (IsInLaneShuffle && ST->hasAVX())
2558 if (const auto *Entry =
2559 CostTableLookup(AVX1InLaneShuffleTbl, Kind, LT.second))
2560 if (auto KindCost = Entry->Cost[CostKind])
2561 return LT.first * *KindCost;
2562
2563 static const CostKindTblEntry AVX1ShuffleTbl[] = {
2564 {TTI::SK_Broadcast, MVT::v4f64, {2,3,2,3}}, // vperm2f128 + vpermilpd
2565 {TTI::SK_Broadcast, MVT::v8f32, {2,3,2,3}}, // vperm2f128 + vpermilps
2566 {TTI::SK_Broadcast, MVT::v4i64, {2,3,2,3}}, // vperm2f128 + vpermilpd
2567 {TTI::SK_Broadcast, MVT::v8i32, {2,3,2,3}}, // vperm2f128 + vpermilps
2568 {TTI::SK_Broadcast, MVT::v16i16, {2,3,3,4}}, // vpshuflw + vpshufd + vinsertf128
2569 {TTI::SK_Broadcast, MVT::v16f16, {2,3,3,4}}, // vpshuflw + vpshufd + vinsertf128
2570 {TTI::SK_Broadcast, MVT::v32i8, {3,4,3,6}}, // vpshufb + vinsertf128
2571
2572 {TTI::SK_Reverse, MVT::v4f64, {2,6,2,2}}, // vperm2f128 + vpermilpd
2573 {TTI::SK_Reverse, MVT::v8f32, {2,7,2,4}}, // vperm2f128 + vpermilps
2574 {TTI::SK_Reverse, MVT::v4i64, {2,6,2,2}}, // vperm2f128 + vpermilpd
2575 {TTI::SK_Reverse, MVT::v8i32, {2,7,2,4}}, // vperm2f128 + vpermilps
2576 {TTI::SK_Reverse, MVT::v16i16, {2,9,5,5}}, // vextractf128 + 2*pshufb
2577 // + vinsertf128
2578 {TTI::SK_Reverse, MVT::v16f16, {2,9,5,5}}, // vextractf128 + 2*pshufb
2579 // + vinsertf128
2580 {TTI::SK_Reverse, MVT::v32i8, {2,9,5,5}}, // vextractf128 + 2*pshufb
2581 // + vinsertf128
2582
2583 {TTI::SK_Select, MVT::v4i64, {1,1,1,1}}, // vblendpd
2584 {TTI::SK_Select, MVT::v4f64, {1,1,1,1}}, // vblendpd
2585 {TTI::SK_Select, MVT::v8i32, {1,1,1,1}}, // vblendps
2586 {TTI::SK_Select, MVT::v8f32, {1,1,1,1}}, // vblendps
2587 {TTI::SK_Select, MVT::v16i16, {3,3,3,3}}, // vpand + vpandn + vpor
2588 {TTI::SK_Select, MVT::v16f16, {3,3,3,3}}, // vpand + vpandn + vpor
2589 {TTI::SK_Select, MVT::v32i8, {3,3,3,3}}, // vpand + vpandn + vpor
2590
2591 {TTI::SK_Splice, MVT::v4i64, {2,2,2,2}}, // vperm2f128 + shufpd
2592 {TTI::SK_Splice, MVT::v4f64, {2,2,2,2}}, // vperm2f128 + shufpd
2593 {TTI::SK_Splice, MVT::v8i32, {4,4,4,4}}, // 2*vperm2f128 + 2*vshufps
2594 {TTI::SK_Splice, MVT::v8f32, {4,4,4,4}}, // 2*vperm2f128 + 2*vshufps
2595 {TTI::SK_Splice, MVT::v16i16, {5,5,5,5}}, // 2*vperm2f128 + 2*vpalignr + vinsertf128
2596 {TTI::SK_Splice, MVT::v16f16, {5,5,5,5}}, // 2*vperm2f128 + 2*vpalignr + vinsertf128
2597 {TTI::SK_Splice, MVT::v32i8, {5,5,5,5}}, // 2*vperm2f128 + 2*vpalignr + vinsertf128
2598
2599 {TTI::SK_PermuteSingleSrc, MVT::v4f64, {2,2,2,2}}, // vperm2f128 + vshufpd
2600 {TTI::SK_PermuteSingleSrc, MVT::v4i64, {2,2,2,2}}, // vperm2f128 + vshufpd
2601 {TTI::SK_PermuteSingleSrc, MVT::v8f32, {4,4,4,4}}, // 2*vperm2f128 + 2*vshufps
2602 {TTI::SK_PermuteSingleSrc, MVT::v8i32, {4,4,4,4}}, // 2*vperm2f128 + 2*vshufps
2603 {TTI::SK_PermuteSingleSrc, MVT::v16i16,{8,8,8,8}}, // vextractf128 + 4*pshufb
2604 // + 2*por + vinsertf128
2605 {TTI::SK_PermuteSingleSrc, MVT::v16f16,{8,8,8,8}}, // vextractf128 + 4*pshufb
2606 // + 2*por + vinsertf128
2607 {TTI::SK_PermuteSingleSrc, MVT::v32i8, {8,8,8,8}}, // vextractf128 + 4*pshufb
2608 // + 2*por + vinsertf128
2609
2610 {TTI::SK_PermuteTwoSrc, MVT::v4f64, {3,3,3,3}}, // 2*vperm2f128 + vshufpd
2611 {TTI::SK_PermuteTwoSrc, MVT::v4i64, {3,3,3,3}}, // 2*vperm2f128 + vshufpd
2612 {TTI::SK_PermuteTwoSrc, MVT::v8f32, {4,4,4,4}}, // 2*vperm2f128 + 2*vshufps
2613 {TTI::SK_PermuteTwoSrc, MVT::v8i32, {4,4,4,4}}, // 2*vperm2f128 + 2*vshufps
2614 {TTI::SK_PermuteTwoSrc, MVT::v16i16,{15,15,15,15}}, // 2*vextractf128 + 8*pshufb
2615 // + 4*por + vinsertf128
2616 {TTI::SK_PermuteTwoSrc, MVT::v16f16,{15,15,15,15}}, // 2*vextractf128 + 8*pshufb
2617 // + 4*por + vinsertf128
2618 {TTI::SK_PermuteTwoSrc, MVT::v32i8, {15,15,15,15}}, // 2*vextractf128 + 8*pshufb
2619 // + 4*por + vinsertf128
2620 };
2621
2622 if (ST->hasAVX())
2623 if (const auto *Entry = CostTableLookup(AVX1ShuffleTbl, Kind, LT.second))
2624 if (auto KindCost = Entry->Cost[CostKind])
2625 return LT.first * *KindCost;
2626
2627 static const CostKindTblEntry SSE41ShuffleTbl[] = {
2628 {TTI::SK_Select, MVT::v2i64, {1,1,1,1}}, // pblendw
2629 {TTI::SK_Select, MVT::v2f64, {1,1,1,1}}, // movsd
2630 {TTI::SK_Select, MVT::v4i32, {1,1,1,1}}, // pblendw
2631 {TTI::SK_Select, MVT::v4f32, {1,1,1,1}}, // blendps
2632 {TTI::SK_Select, MVT::v8i16, {1,1,1,1}}, // pblendw
2633 {TTI::SK_Select, MVT::v8f16, {1,1,1,1}}, // pblendw
2634 {TTI::SK_Select, MVT::v16i8, {1,1,1,1}} // pblendvb
2635 };
2636
2637 if (ST->hasSSE41())
2638 if (const auto *Entry = CostTableLookup(SSE41ShuffleTbl, Kind, LT.second))
2639 if (auto KindCost = Entry->Cost[CostKind])
2640 return LT.first * *KindCost;
2641
2642 static const CostKindTblEntry SSSE3ShuffleTbl[] = {
2643 {TTI::SK_Broadcast, MVT::v8i16, {1, 3, 2, 2}}, // pshufb
2644 {TTI::SK_Broadcast, MVT::v8f16, {1, 3, 2, 2}}, // pshufb
2645 {TTI::SK_Broadcast, MVT::v16i8, {1, 3, 2, 2}}, // pshufb
2646
2647 {TTI::SK_Reverse, MVT::v8i16, {1, 2, 1, 2}}, // pshufb
2648 {TTI::SK_Reverse, MVT::v8f16, {1, 2, 1, 2}}, // pshufb
2649 {TTI::SK_Reverse, MVT::v16i8, {1, 2, 1, 2}}, // pshufb
2650
2651 {TTI::SK_Splice, MVT::v4i32, {1, 1, 1, 1}}, // palignr
2652 {TTI::SK_Splice, MVT::v4f32, {1, 1, 1, 1}}, // palignr
2653 {TTI::SK_Splice, MVT::v8i16, {1, 1, 1, 1}}, // palignr
2654 {TTI::SK_Splice, MVT::v8f16, {1, 1, 1, 1}}, // palignr
2655 {TTI::SK_Splice, MVT::v16i8, {1, 1, 1, 1}}, // palignr
2656
2657 {TTI::SK_PermuteSingleSrc, MVT::v8i16, {1, 1, 1, 1}}, // pshufb
2658 {TTI::SK_PermuteSingleSrc, MVT::v8f16, {1, 1, 1, 1}}, // pshufb
2659 {TTI::SK_PermuteSingleSrc, MVT::v16i8, {1, 1, 1, 1}}, // pshufb
2660
2661 {TTI::SK_PermuteTwoSrc, MVT::v8i16, {3, 3, 3, 3}}, // 2*pshufb + por
2662 {TTI::SK_PermuteTwoSrc, MVT::v8f16, {3, 3, 3, 3}}, // 2*pshufb + por
2663 {TTI::SK_PermuteTwoSrc, MVT::v16i8, {3, 3, 3, 3}}, // 2*pshufb + por
2664 };
2665
2666 if (ST->hasSSSE3())
2667 if (const auto *Entry = CostTableLookup(SSSE3ShuffleTbl, Kind, LT.second))
2668 if (auto KindCost = Entry->Cost[CostKind])
2669 return LT.first * *KindCost;
2670
2671 static const CostKindTblEntry SSE2ShuffleTbl[] = {
2672 {TTI::SK_Broadcast, MVT::v2f64, {1, 1, 1, 1}}, // shufpd
2673 {TTI::SK_Broadcast, MVT::v2i64, {1, 1, 1, 1}}, // pshufd
2674 {TTI::SK_Broadcast, MVT::v4i32, {1, 1, 1, 1}}, // pshufd
2675 {TTI::SK_Broadcast, MVT::v8i16, {1, 2, 2, 2}}, // pshuflw + pshufd
2676 {TTI::SK_Broadcast, MVT::v8f16, {1, 2, 2, 2}}, // pshuflw + pshufd
2677 {TTI::SK_Broadcast, MVT::v16i8, {2, 3, 3, 4}}, // unpck + pshuflw + pshufd
2678
2679 {TTI::SK_Reverse, MVT::v2f64, {1, 1, 1, 1}}, // shufpd
2680 {TTI::SK_Reverse, MVT::v2i64, {1, 1, 1, 1}}, // pshufd
2681 {TTI::SK_Reverse, MVT::v4i32, {1, 1, 1, 1}}, // pshufd
2682 {TTI::SK_Reverse, MVT::v8i16, {2, 3, 3, 3}}, // pshuflw + pshufhw + pshufd
2683 {TTI::SK_Reverse, MVT::v8f16, {2, 3, 3, 3}}, // pshuflw + pshufhw + pshufd
2684 {TTI::SK_Reverse, MVT::v16i8, {5, 6,11,11}}, // 2*pshuflw + 2*pshufhw
2685 // + 2*pshufd + 2*unpck + packus
2686
2687 {TTI::SK_Select, MVT::v2i64, {1, 1, 1, 1}}, // movsd
2688 {TTI::SK_Select, MVT::v2f64, {1, 1, 1, 1}}, // movsd
2689 {TTI::SK_Select, MVT::v4i32, {2, 2, 2, 2}}, // 2*shufps
2690 {TTI::SK_Select, MVT::v8i16, {2, 2, 3, 3}}, // pand + pandn + por
2691 {TTI::SK_Select, MVT::v8f16, {2, 2, 3, 3}}, // pand + pandn + por
2692 {TTI::SK_Select, MVT::v16i8, {2, 2, 3, 3}}, // pand + pandn + por
2693
2694 {TTI::SK_Splice, MVT::v2i64, {1, 1, 1, 1}}, // shufpd
2695 {TTI::SK_Splice, MVT::v2f64, {1, 1, 1, 1}}, // shufpd
2696 {TTI::SK_Splice, MVT::v4i32, {2, 2, 2, 2}}, // 2*{unpck,movsd,pshufd}
2697 {TTI::SK_Splice, MVT::v8i16, {3, 3, 3, 3}}, // psrldq + psrlldq + por
2698 {TTI::SK_Splice, MVT::v8f16, {3, 3, 3, 3}}, // psrldq + psrlldq + por
2699 {TTI::SK_Splice, MVT::v16i8, {3, 3, 3, 3}}, // psrldq + psrlldq + por
2700
2701 {TTI::SK_PermuteSingleSrc, MVT::v2f64, {1, 1, 1, 1}}, // shufpd
2702 {TTI::SK_PermuteSingleSrc, MVT::v2i64, {1, 1, 1, 1}}, // pshufd
2703 {TTI::SK_PermuteSingleSrc, MVT::v4i32, {1, 1, 1, 1}}, // pshufd
2704 {TTI::SK_PermuteSingleSrc, MVT::v8i16, {3, 5, 5, 5}}, // 2*pshuflw + 2*pshufhw
2705 // + pshufd/unpck
2706 {TTI::SK_PermuteSingleSrc, MVT::v8f16, {3, 5, 5, 5}}, // 2*pshuflw + 2*pshufhw
2707 // + pshufd/unpck
2708 {TTI::SK_PermuteSingleSrc, MVT::v16i8, {8, 10, 10, 10}}, // 2*pshuflw + 2*pshufhw
2709 // + 2*pshufd + 2*unpck + 2*packus
2710
2711 {TTI::SK_PermuteTwoSrc, MVT::v2f64, {1, 1, 1, 1}}, // shufpd
2712 {TTI::SK_PermuteTwoSrc, MVT::v2i64, {1, 1, 1, 1}}, // shufpd
2713 {TTI::SK_PermuteTwoSrc, MVT::v4i32, {2, 2, 2, 2}}, // 2*{unpck,movsd,pshufd}
2714 {TTI::SK_PermuteTwoSrc, MVT::v8i16, {6, 8, 8, 8}}, // blend+permute
2715 {TTI::SK_PermuteTwoSrc, MVT::v8f16, {6, 8, 8, 8}}, // blend+permute
2716 {TTI::SK_PermuteTwoSrc, MVT::v16i8, {11, 13, 13, 13}}, // blend+permute
2717 };
2718
2719 static const CostTblEntry SSE3BroadcastLoadTbl[] = {
2720 {TTI::SK_Broadcast, MVT::v2f64, 0}, // broadcast handled by movddup
2721 };
2722
2723 if (ST->hasSSE2()) {
2724 bool IsLoad =
2725 llvm::any_of(Args, [](const auto &V) { return isa<LoadInst>(V); });
2726 if (ST->hasSSE3() && IsLoad)
2727 if (const auto *Entry =
2728 CostTableLookup(SSE3BroadcastLoadTbl, Kind, LT.second)) {
2729 assert(isLegalBroadcastLoad(SrcTy->getElementType(),
2730 LT.second.getVectorElementCount()) &&
2731 "Table entry missing from isLegalBroadcastLoad()");
2732 return LT.first * Entry->Cost;
2733 }
2734
2735 if (const auto *Entry = CostTableLookup(SSE2ShuffleTbl, Kind, LT.second))
2736 if (auto KindCost = Entry->Cost[CostKind])
2737 return LT.first * *KindCost;
2738 }
2739
2740 static const CostKindTblEntry SSE1ShuffleTbl[] = {
2741 { TTI::SK_Broadcast, MVT::v4f32, {1,1,1,1} }, // shufps
2742 { TTI::SK_Reverse, MVT::v4f32, {1,1,1,1} }, // shufps
2743 { TTI::SK_Select, MVT::v4f32, {2,2,2,2} }, // 2*shufps
2744 { TTI::SK_Splice, MVT::v4f32, {2,2,2,2} }, // 2*shufps
2745 { TTI::SK_PermuteSingleSrc, MVT::v4f32, {1,1,1,1} }, // shufps
2746 { TTI::SK_PermuteTwoSrc, MVT::v4f32, {2,2,2,2} }, // 2*shufps
2747 };
2748
2749 if (ST->hasSSE1()) {
2750 if (LT.first == 1 && LT.second == MVT::v4f32 && Mask.size() == 4) {
2751 // SHUFPS: both pairs must come from the same source register.
2752 auto MatchSHUFPS = [](int X, int Y) {
2753 return X < 0 || Y < 0 || ((X & 4) == (Y & 4));
2754 };
2755 if (MatchSHUFPS(Mask[0], Mask[1]) && MatchSHUFPS(Mask[2], Mask[3]))
2756 return 1;
2757 }
2758 if (const auto *Entry = CostTableLookup(SSE1ShuffleTbl, Kind, LT.second))
2759 if (auto KindCost = Entry->Cost[CostKind])
2760 return LT.first * *KindCost;
2761 }
2762
2763 return BaseT::getShuffleCost(Kind, DstTy, SrcTy, CostKind, Mask, Index,
2764 SubTp);
2765}
2766
2768 Type *Src,
2770 TTI::TargetCostKind CostKind,
2771 const Instruction *I) const {
2772 int ISD = TLI->InstructionOpcodeToISD(Opcode);
2773 assert(ISD && "Invalid opcode");
2774
2775 // A narrow (i8/i16) zero-extension used as a GEP *index* can be folded into
2776 // the addressing mode of the consuming memory op, but only if the source is
2777 // already materialised zero-extended in a full register. X86's SIB form
2778 // [base + index*scale + disp] reads the index at full width and does NOT
2779 // zero-extend a narrow index (unlike AArch64's uxtw-extended addressing), so
2780 // a "dirty" narrow source (e.g. an i16 add result used only as an index)
2781 // still needs a dedicated movzx and is not free. Price it as free only with
2782 // positive evidence that no movzx is required.
2783 if (ISD == ISD::ZERO_EXTEND && I && I->hasOneUse() && Src->isIntegerTy() &&
2784 Src->getScalarSizeInBits() < 32) {
2785 const Use &U = *I->use_begin();
2786 if (isa<GetElementPtrInst>(U.getUser()) &&
2787 U.getOperandNo() != GetElementPtrInst::getPointerOperandIndex()) {
2788 const Value *Op = I->getOperand(0);
2789 // Clean sources: an extending load, a zeroext argument, or a value whose
2790 // high bits are provably zero (e.g. from a shift/mask). These mirror the
2791 // proof-based reasoning the middle end uses elsewhere (ValueTracking and
2792 // InstCombine's canEvaluateZExtd); we intentionally do NOT treat a merely
2793 // multiply-used operand as clean, since that is a guess rather than
2794 // proof.
2795 if (isa<LoadInst>(Op))
2796 return TTI::TCC_Free;
2797 if (const auto *A = dyn_cast<Argument>(Op))
2798 if (A->hasAttribute(Attribute::ZExt))
2799 return TTI::TCC_Free;
2800 if (computeKnownBits(Op, I->getDataLayout(), /*AC=*/nullptr, I)
2801 .countMinLeadingZeros() > 0)
2802 return TTI::TCC_Free;
2803 }
2804 }
2805
2806 // The cost tables include both specific, custom (non-legal) src/dst type
2807 // conversions and generic, legalized types. We test for customs first, before
2808 // falling back to legalization.
2809 // FIXME: Need a better design of the cost table to handle non-simple types of
2810 // potential massive combinations (elem_num x src_type x dst_type).
2811 static const TypeConversionCostKindTblEntry AVX512BWConversionTbl[]{
2812 { ISD::SIGN_EXTEND, MVT::v32i16, MVT::v32i8, { 1, 1, 1, 1 } },
2813 { ISD::ZERO_EXTEND, MVT::v32i16, MVT::v32i8, { 1, 1, 1, 1 } },
2814
2815 // Mask sign extend has an instruction.
2816 { ISD::SIGN_EXTEND, MVT::v2i8, MVT::v2i1, { 1, 1, 1, 1 } },
2817 { ISD::SIGN_EXTEND, MVT::v16i8, MVT::v2i1, { 1, 1, 1, 1 } },
2818 { ISD::SIGN_EXTEND, MVT::v2i16, MVT::v2i1, { 1, 1, 1, 1 } },
2819 { ISD::SIGN_EXTEND, MVT::v8i16, MVT::v2i1, { 1, 1, 1, 1 } },
2820 { ISD::SIGN_EXTEND, MVT::v4i8, MVT::v4i1, { 1, 1, 1, 1 } },
2821 { ISD::SIGN_EXTEND, MVT::v16i8, MVT::v4i1, { 1, 1, 1, 1 } },
2822 { ISD::SIGN_EXTEND, MVT::v4i16, MVT::v4i1, { 1, 1, 1, 1 } },
2823 { ISD::SIGN_EXTEND, MVT::v8i16, MVT::v4i1, { 1, 1, 1, 1 } },
2824 { ISD::SIGN_EXTEND, MVT::v8i8, MVT::v8i1, { 1, 1, 1, 1 } },
2825 { ISD::SIGN_EXTEND, MVT::v16i8, MVT::v8i1, { 1, 1, 1, 1 } },
2826 { ISD::SIGN_EXTEND, MVT::v8i16, MVT::v8i1, { 1, 1, 1, 1 } },
2827 { ISD::SIGN_EXTEND, MVT::v16i8, MVT::v16i1, { 1, 1, 1, 1 } },
2828 { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i1, { 1, 1, 1, 1 } },
2829 { ISD::SIGN_EXTEND, MVT::v32i8, MVT::v32i1, { 1, 1, 1, 1 } },
2830 { ISD::SIGN_EXTEND, MVT::v32i16, MVT::v32i1, { 1, 1, 1, 1 } },
2831 { ISD::SIGN_EXTEND, MVT::v64i8, MVT::v64i1, { 1, 1, 1, 1 } },
2832 { ISD::SIGN_EXTEND, MVT::v32i16, MVT::v64i1, { 1, 1, 1, 1 } },
2833
2834 // Mask zero extend is a sext + shift.
2835 { ISD::ZERO_EXTEND, MVT::v2i8, MVT::v2i1, { 2, 1, 1, 1 } },
2836 { ISD::ZERO_EXTEND, MVT::v16i8, MVT::v2i1, { 2, 1, 1, 1 } },
2837 { ISD::ZERO_EXTEND, MVT::v2i16, MVT::v2i1, { 2, 1, 1, 1 } },
2838 { ISD::ZERO_EXTEND, MVT::v8i16, MVT::v2i1, { 2, 1, 1, 1 } },
2839 { ISD::ZERO_EXTEND, MVT::v4i8, MVT::v4i1, { 2, 1, 1, 1 } },
2840 { ISD::ZERO_EXTEND, MVT::v16i8, MVT::v4i1, { 2, 1, 1, 1 } },
2841 { ISD::ZERO_EXTEND, MVT::v4i16, MVT::v4i1, { 2, 1, 1, 1 } },
2842 { ISD::ZERO_EXTEND, MVT::v8i16, MVT::v4i1, { 2, 1, 1, 1 } },
2843 { ISD::ZERO_EXTEND, MVT::v8i8, MVT::v8i1, { 2, 1, 1, 1 } },
2844 { ISD::ZERO_EXTEND, MVT::v16i8, MVT::v8i1, { 2, 1, 1, 1 } },
2845 { ISD::ZERO_EXTEND, MVT::v8i16, MVT::v8i1, { 2, 1, 1, 1 } },
2846 { ISD::ZERO_EXTEND, MVT::v16i8, MVT::v16i1, { 2, 1, 1, 1 } },
2847 { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i1, { 2, 1, 1, 1 } },
2848 { ISD::ZERO_EXTEND, MVT::v32i8, MVT::v32i1, { 2, 1, 1, 1 } },
2849 { ISD::ZERO_EXTEND, MVT::v32i16, MVT::v32i1, { 2, 1, 1, 1 } },
2850 { ISD::ZERO_EXTEND, MVT::v64i8, MVT::v64i1, { 2, 1, 1, 1 } },
2851 { ISD::ZERO_EXTEND, MVT::v32i16, MVT::v64i1, { 2, 1, 1, 1 } },
2852
2853 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i8, { 2, 1, 1, 1 } },
2854 { ISD::TRUNCATE, MVT::v2i1, MVT::v16i8, { 2, 1, 1, 1 } },
2855 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i16, { 2, 1, 1, 1 } },
2856 { ISD::TRUNCATE, MVT::v2i1, MVT::v8i16, { 2, 1, 1, 1 } },
2857 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i8, { 2, 1, 1, 1 } },
2858 { ISD::TRUNCATE, MVT::v4i1, MVT::v16i8, { 2, 1, 1, 1 } },
2859 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i16, { 2, 1, 1, 1 } },
2860 { ISD::TRUNCATE, MVT::v4i1, MVT::v8i16, { 2, 1, 1, 1 } },
2861 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i8, { 2, 1, 1, 1 } },
2862 { ISD::TRUNCATE, MVT::v8i1, MVT::v16i8, { 2, 1, 1, 1 } },
2863 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i16, { 2, 1, 1, 1 } },
2864 { ISD::TRUNCATE, MVT::v16i1, MVT::v16i8, { 2, 1, 1, 1 } },
2865 { ISD::TRUNCATE, MVT::v16i1, MVT::v16i16, { 2, 1, 1, 1 } },
2866 { ISD::TRUNCATE, MVT::v32i1, MVT::v32i8, { 2, 1, 1, 1 } },
2867 { ISD::TRUNCATE, MVT::v32i1, MVT::v32i16, { 2, 1, 1, 1 } },
2868 { ISD::TRUNCATE, MVT::v64i1, MVT::v64i8, { 2, 1, 1, 1 } },
2869 { ISD::TRUNCATE, MVT::v64i1, MVT::v32i16, { 2, 1, 1, 1 } },
2870
2871 { ISD::TRUNCATE, MVT::v32i8, MVT::v32i16, { 2, 1, 1, 1 } },
2872 { ISD::TRUNCATE, MVT::v16i8, MVT::v16i16, { 2, 1, 1, 1 } }, // widen to zmm
2873 { ISD::TRUNCATE, MVT::v2i8, MVT::v2i16, { 2, 1, 1, 1 } }, // vpmovwb
2874 { ISD::TRUNCATE, MVT::v4i8, MVT::v4i16, { 2, 1, 1, 1 } }, // vpmovwb
2875 { ISD::TRUNCATE, MVT::v8i8, MVT::v8i16, { 2, 1, 1, 1 } }, // vpmovwb
2876 };
2877
2878 static const TypeConversionCostKindTblEntry AVX512DQConversionTbl[] = {
2879 // Mask sign extend has an instruction.
2880 { ISD::SIGN_EXTEND, MVT::v2i64, MVT::v2i1, { 1, 1, 1, 1 } },
2881 { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v2i1, { 1, 1, 1, 1 } },
2882 { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v4i1, { 1, 1, 1, 1 } },
2883 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i1, { 1, 1, 1, 1 } },
2884 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i1, { 1, 1, 1, 1 } },
2885 { ISD::SIGN_EXTEND, MVT::v8i64, MVT::v16i1, { 1, 1, 1, 1 } },
2886 { ISD::SIGN_EXTEND, MVT::v8i64, MVT::v8i1, { 1, 1, 1, 1 } },
2887 { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i1, { 1, 1, 1, 1 } },
2888
2889 // Mask zero extend is a sext + shift.
2890 { ISD::ZERO_EXTEND, MVT::v2i64, MVT::v2i1, { 2, 1, 1, 1, } },
2891 { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v2i1, { 2, 1, 1, 1, } },
2892 { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v4i1, { 2, 1, 1, 1, } },
2893 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i1, { 2, 1, 1, 1, } },
2894 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i1, { 2, 1, 1, 1, } },
2895 { ISD::ZERO_EXTEND, MVT::v8i64, MVT::v16i1, { 2, 1, 1, 1, } },
2896 { ISD::ZERO_EXTEND, MVT::v8i64, MVT::v8i1, { 2, 1, 1, 1, } },
2897 { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i1, { 2, 1, 1, 1, } },
2898
2899 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i64, { 2, 1, 1, 1 } },
2900 { ISD::TRUNCATE, MVT::v2i1, MVT::v4i32, { 2, 1, 1, 1 } },
2901 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i32, { 2, 1, 1, 1 } },
2902 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i64, { 2, 1, 1, 1 } },
2903 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i32, { 2, 1, 1, 1 } },
2904 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i64, { 2, 1, 1, 1 } },
2905 { ISD::TRUNCATE, MVT::v16i1, MVT::v16i32, { 2, 1, 1, 1 } },
2906 { ISD::TRUNCATE, MVT::v16i1, MVT::v8i64, { 2, 1, 1, 1 } },
2907
2908 { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i64, { 1, 1, 1, 1 } },
2909 { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i64, { 1, 1, 1, 1 } },
2910
2911 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i64, { 1, 1, 1, 1 } },
2912 { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i64, { 1, 1, 1, 1 } },
2913
2914 { ISD::FP_TO_SINT, MVT::v8i64, MVT::v8f32, { 1, 1, 1, 1 } },
2915 { ISD::FP_TO_SINT, MVT::v8i64, MVT::v8f64, { 1, 1, 1, 1 } },
2916
2917 { ISD::FP_TO_UINT, MVT::v8i64, MVT::v8f32, { 1, 1, 1, 1 } },
2918 { ISD::FP_TO_UINT, MVT::v8i64, MVT::v8f64, { 1, 1, 1, 1 } },
2919 };
2920
2921 // TODO: For AVX512DQ + AVX512VL, we also have cheap casts for 128-bit and
2922 // 256-bit wide vectors.
2923
2924 static const TypeConversionCostKindTblEntry AVX512FConversionTbl[] = {
2925 { ISD::FP_EXTEND, MVT::v8f64, MVT::v8f32, { 1, 1, 1, 1 } },
2926 { ISD::FP_EXTEND, MVT::v8f64, MVT::v16f32, { 3, 1, 1, 1 } },
2927 { ISD::FP_EXTEND, MVT::v16f64, MVT::v16f32, { 4, 1, 1, 1 } }, // 2*vcvtps2pd+vextractf64x4
2928 { ISD::FP_EXTEND, MVT::v16f32, MVT::v16f16, { 1, 1, 1, 1 } }, // vcvtph2ps
2929 { ISD::FP_EXTEND, MVT::v8f64, MVT::v8f16, { 2, 1, 1, 1 } }, // vcvtph2ps+vcvtps2pd
2930 { ISD::FP_ROUND, MVT::v8f32, MVT::v8f64, { 1, 1, 1, 1 } },
2931 { ISD::FP_ROUND, MVT::v16f16, MVT::v16f32, { 1, 1, 1, 1 } }, // vcvtps2ph
2932
2933 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i8, { 3, 1, 1, 1 } }, // sext+vpslld+vptestmd
2934 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i8, { 3, 1, 1, 1 } }, // sext+vpslld+vptestmd
2935 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i8, { 3, 1, 1, 1 } }, // sext+vpslld+vptestmd
2936 { ISD::TRUNCATE, MVT::v16i1, MVT::v16i8, { 3, 1, 1, 1 } }, // sext+vpslld+vptestmd
2937 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i16, { 3, 1, 1, 1 } }, // sext+vpsllq+vptestmq
2938 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i16, { 3, 1, 1, 1 } }, // sext+vpsllq+vptestmq
2939 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i16, { 3, 1, 1, 1 } }, // sext+vpsllq+vptestmq
2940 { ISD::TRUNCATE, MVT::v16i1, MVT::v16i16, { 3, 1, 1, 1 } }, // sext+vpslld+vptestmd
2941 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i32, { 2, 1, 1, 1 } }, // zmm vpslld+vptestmd
2942 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i32, { 2, 1, 1, 1 } }, // zmm vpslld+vptestmd
2943 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i32, { 2, 1, 1, 1 } }, // zmm vpslld+vptestmd
2944 { ISD::TRUNCATE, MVT::v16i1, MVT::v16i32, { 2, 1, 1, 1 } }, // vpslld+vptestmd
2945 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i64, { 2, 1, 1, 1 } }, // zmm vpsllq+vptestmq
2946 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i64, { 2, 1, 1, 1 } }, // zmm vpsllq+vptestmq
2947 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i64, { 2, 1, 1, 1 } }, // vpsllq+vptestmq
2948 { ISD::TRUNCATE, MVT::v2i8, MVT::v2i32, { 2, 1, 1, 1 } }, // vpmovdb
2949 { ISD::TRUNCATE, MVT::v4i8, MVT::v4i32, { 2, 1, 1, 1 } }, // vpmovdb
2950 { ISD::TRUNCATE, MVT::v16i8, MVT::v16i32, { 2, 1, 1, 1 } }, // vpmovdb
2951 { ISD::TRUNCATE, MVT::v32i8, MVT::v16i32, { 2, 1, 1, 1 } }, // vpmovdb
2952 { ISD::TRUNCATE, MVT::v64i8, MVT::v16i32, { 2, 1, 1, 1 } }, // vpmovdb
2953 { ISD::TRUNCATE, MVT::v16i16, MVT::v16i32, { 2, 1, 1, 1 } }, // vpmovdw
2954 { ISD::TRUNCATE, MVT::v32i16, MVT::v16i32, { 2, 1, 1, 1 } }, // vpmovdw
2955 { ISD::TRUNCATE, MVT::v2i8, MVT::v2i64, { 2, 1, 1, 1 } }, // vpmovqb
2956 { ISD::TRUNCATE, MVT::v2i16, MVT::v2i64, { 1, 1, 1, 1 } }, // vpshufb
2957 { ISD::TRUNCATE, MVT::v8i8, MVT::v8i64, { 2, 1, 1, 1 } }, // vpmovqb
2958 { ISD::TRUNCATE, MVT::v16i8, MVT::v8i64, { 2, 1, 1, 1 } }, // vpmovqb
2959 { ISD::TRUNCATE, MVT::v32i8, MVT::v8i64, { 2, 1, 1, 1 } }, // vpmovqb
2960 { ISD::TRUNCATE, MVT::v64i8, MVT::v8i64, { 2, 1, 1, 1 } }, // vpmovqb
2961 { ISD::TRUNCATE, MVT::v8i16, MVT::v8i64, { 2, 1, 1, 1 } }, // vpmovqw
2962 { ISD::TRUNCATE, MVT::v16i16, MVT::v8i64, { 2, 1, 1, 1 } }, // vpmovqw
2963 { ISD::TRUNCATE, MVT::v32i16, MVT::v8i64, { 2, 1, 1, 1 } }, // vpmovqw
2964 { ISD::TRUNCATE, MVT::v8i32, MVT::v8i64, { 1, 1, 1, 1 } }, // vpmovqd
2965 { ISD::TRUNCATE, MVT::v4i32, MVT::v4i64, { 1, 1, 1, 1 } }, // zmm vpmovqd
2966 { ISD::TRUNCATE, MVT::v16i8, MVT::v16i64, { 5, 1, 1, 1 } },// 2*vpmovqd+concat+vpmovdb
2967
2968 { ISD::TRUNCATE, MVT::v16i8, MVT::v16i16, { 3, 1, 1, 1 } }, // extend to v16i32
2969 { ISD::TRUNCATE, MVT::v32i8, MVT::v32i16, { 8, 1, 1, 1 } },
2970 { ISD::TRUNCATE, MVT::v64i8, MVT::v32i16, { 8, 1, 1, 1 } },
2971
2972 // Sign extend is zmm vpternlogd+vptruncdb.
2973 // Zero extend is zmm broadcast load+vptruncdw.
2974 { ISD::SIGN_EXTEND, MVT::v2i8, MVT::v2i1, { 3, 1, 1, 1 } },
2975 { ISD::ZERO_EXTEND, MVT::v2i8, MVT::v2i1, { 4, 1, 1, 1 } },
2976 { ISD::SIGN_EXTEND, MVT::v4i8, MVT::v4i1, { 3, 1, 1, 1 } },
2977 { ISD::ZERO_EXTEND, MVT::v4i8, MVT::v4i1, { 4, 1, 1, 1 } },
2978 { ISD::SIGN_EXTEND, MVT::v8i8, MVT::v8i1, { 3, 1, 1, 1 } },
2979 { ISD::ZERO_EXTEND, MVT::v8i8, MVT::v8i1, { 4, 1, 1, 1 } },
2980 { ISD::SIGN_EXTEND, MVT::v16i8, MVT::v16i1, { 3, 1, 1, 1 } },
2981 { ISD::ZERO_EXTEND, MVT::v16i8, MVT::v16i1, { 4, 1, 1, 1 } },
2982
2983 // Sign extend is zmm vpternlogd+vptruncdw.
2984 // Zero extend is zmm vpternlogd+vptruncdw+vpsrlw.
2985 { ISD::SIGN_EXTEND, MVT::v2i16, MVT::v2i1, { 3, 1, 1, 1 } },
2986 { ISD::ZERO_EXTEND, MVT::v2i16, MVT::v2i1, { 4, 1, 1, 1 } },
2987 { ISD::SIGN_EXTEND, MVT::v4i16, MVT::v4i1, { 3, 1, 1, 1 } },
2988 { ISD::ZERO_EXTEND, MVT::v4i16, MVT::v4i1, { 4, 1, 1, 1 } },
2989 { ISD::SIGN_EXTEND, MVT::v8i16, MVT::v8i1, { 3, 1, 1, 1 } },
2990 { ISD::ZERO_EXTEND, MVT::v8i16, MVT::v8i1, { 4, 1, 1, 1 } },
2991 { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i1, { 3, 1, 1, 1 } },
2992 { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i1, { 4, 1, 1, 1 } },
2993
2994 { ISD::SIGN_EXTEND, MVT::v2i32, MVT::v2i1, { 1, 1, 1, 1 } }, // zmm vpternlogd
2995 { ISD::ZERO_EXTEND, MVT::v2i32, MVT::v2i1, { 2, 1, 1, 1 } }, // zmm vpternlogd+psrld
2996 { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v4i1, { 1, 1, 1, 1 } }, // zmm vpternlogd
2997 { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v4i1, { 2, 1, 1, 1 } }, // zmm vpternlogd+psrld
2998 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i1, { 1, 1, 1, 1 } }, // zmm vpternlogd
2999 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i1, { 2, 1, 1, 1 } }, // zmm vpternlogd+psrld
3000 { ISD::SIGN_EXTEND, MVT::v2i64, MVT::v2i1, { 1, 1, 1, 1 } }, // zmm vpternlogq
3001 { ISD::ZERO_EXTEND, MVT::v2i64, MVT::v2i1, { 2, 1, 1, 1 } }, // zmm vpternlogq+psrlq
3002 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i1, { 1, 1, 1, 1 } }, // zmm vpternlogq
3003 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i1, { 2, 1, 1, 1 } }, // zmm vpternlogq+psrlq
3004
3005 { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i1, { 1, 1, 1, 1 } }, // vpternlogd
3006 { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i1, { 2, 1, 1, 1 } }, // vpternlogd+psrld
3007 { ISD::SIGN_EXTEND, MVT::v8i64, MVT::v8i1, { 1, 1, 1, 1 } }, // vpternlogq
3008 { ISD::ZERO_EXTEND, MVT::v8i64, MVT::v8i1, { 2, 1, 1, 1 } }, // vpternlogq+psrlq
3009
3010 { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i8, { 1, 1, 1, 1 } },
3011 { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i8, { 1, 1, 1, 1 } },
3012 { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i16, { 1, 1, 1, 1 } },
3013 { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i16, { 1, 1, 1, 1 } },
3014 { ISD::SIGN_EXTEND, MVT::v8i64, MVT::v8i8, { 1, 1, 1, 1 } },
3015 { ISD::ZERO_EXTEND, MVT::v8i64, MVT::v8i8, { 1, 1, 1, 1 } },
3016 { ISD::SIGN_EXTEND, MVT::v8i64, MVT::v8i16, { 1, 1, 1, 1 } },
3017 { ISD::ZERO_EXTEND, MVT::v8i64, MVT::v8i16, { 1, 1, 1, 1 } },
3018 { ISD::SIGN_EXTEND, MVT::v8i64, MVT::v8i32, { 1, 1, 1, 1 } },
3019 { ISD::ZERO_EXTEND, MVT::v8i64, MVT::v8i32, { 1, 1, 1, 1 } },
3020
3021 { ISD::SIGN_EXTEND, MVT::v32i16, MVT::v32i8, { 3, 1, 1, 1 } }, // FIXME: May not be right
3022 { ISD::ZERO_EXTEND, MVT::v32i16, MVT::v32i8, { 3, 1, 1, 1 } }, // FIXME: May not be right
3023
3024 { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i1, { 4, 1, 1, 1 } },
3025 { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i1, { 3, 1, 1, 1 } },
3026 { ISD::SINT_TO_FP, MVT::v8f64, MVT::v16i8, { 2, 1, 1, 1 } },
3027 { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i8, { 1, 1, 1, 1 } },
3028 { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i16, { 2, 1, 1, 1 } },
3029 { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i16, { 1, 1, 1, 1 } },
3030 { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i32, { 1, 1, 1, 1 } },
3031 { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i32, { 1, 1, 1, 1 } },
3032
3033 { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i1, { 4, 1, 1, 1 } },
3034 { ISD::UINT_TO_FP, MVT::v16f32, MVT::v16i1, { 3, 1, 1, 1 } },
3035 { ISD::UINT_TO_FP, MVT::v8f64, MVT::v16i8, { 2, 1, 1, 1 } },
3036 { ISD::UINT_TO_FP, MVT::v16f32, MVT::v16i8, { 1, 1, 1, 1 } },
3037 { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i16, { 2, 1, 1, 1 } },
3038 { ISD::UINT_TO_FP, MVT::v16f32, MVT::v16i16, { 1, 1, 1, 1 } },
3039 { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i32, { 1, 1, 1, 1 } },
3040 { ISD::UINT_TO_FP, MVT::v16f32, MVT::v16i32, { 1, 1, 1, 1 } },
3041 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i64, {26, 1, 1, 1 } },
3042 { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i64, { 5, 1, 1, 1 } },
3043
3044 { ISD::FP_TO_SINT, MVT::v16i8, MVT::v16f32, { 2, 1, 1, 1 } },
3045 { ISD::FP_TO_SINT, MVT::v16i8, MVT::v16f64, { 7, 1, 1, 1 } },
3046 { ISD::FP_TO_SINT, MVT::v32i8, MVT::v32f64, {15, 1, 1, 1 } },
3047 { ISD::FP_TO_SINT, MVT::v64i8, MVT::v64f32, {11, 1, 1, 1 } },
3048 { ISD::FP_TO_SINT, MVT::v64i8, MVT::v64f64, {31, 1, 1, 1 } },
3049 { ISD::FP_TO_SINT, MVT::v8i16, MVT::v8f64, { 3, 1, 1, 1 } },
3050 { ISD::FP_TO_SINT, MVT::v16i16, MVT::v16f64, { 7, 1, 1, 1 } },
3051 { ISD::FP_TO_SINT, MVT::v32i16, MVT::v32f32, { 5, 1, 1, 1 } },
3052 { ISD::FP_TO_SINT, MVT::v32i16, MVT::v32f64, {15, 1, 1, 1 } },
3053 { ISD::FP_TO_SINT, MVT::v8i32, MVT::v8f64, { 1, 1, 1, 1 } },
3054 { ISD::FP_TO_SINT, MVT::v16i32, MVT::v16f64, { 3, 1, 1, 1 } },
3055
3056 { ISD::FP_TO_UINT, MVT::v8i32, MVT::v8f64, { 1, 1, 1, 1 } },
3057 { ISD::FP_TO_UINT, MVT::v8i16, MVT::v8f64, { 3, 1, 1, 1 } },
3058 { ISD::FP_TO_UINT, MVT::v8i8, MVT::v8f64, { 3, 1, 1, 1 } },
3059 { ISD::FP_TO_UINT, MVT::v16i32, MVT::v16f32, { 1, 1, 1, 1 } },
3060 { ISD::FP_TO_UINT, MVT::v16i16, MVT::v16f32, { 3, 1, 1, 1 } },
3061 { ISD::FP_TO_UINT, MVT::v16i8, MVT::v16f32, { 3, 1, 1, 1 } },
3062 };
3063
3064 static const TypeConversionCostKindTblEntry AVX512BWVLConversionTbl[] {
3065 // Mask sign extend has an instruction.
3066 { ISD::SIGN_EXTEND, MVT::v2i8, MVT::v2i1, { 1, 1, 1, 1 } },
3067 { ISD::SIGN_EXTEND, MVT::v16i8, MVT::v2i1, { 1, 1, 1, 1 } },
3068 { ISD::SIGN_EXTEND, MVT::v2i16, MVT::v2i1, { 1, 1, 1, 1 } },
3069 { ISD::SIGN_EXTEND, MVT::v8i16, MVT::v2i1, { 1, 1, 1, 1 } },
3070 { ISD::SIGN_EXTEND, MVT::v4i16, MVT::v4i1, { 1, 1, 1, 1 } },
3071 { ISD::SIGN_EXTEND, MVT::v16i8, MVT::v4i1, { 1, 1, 1, 1 } },
3072 { ISD::SIGN_EXTEND, MVT::v4i8, MVT::v4i1, { 1, 1, 1, 1 } },
3073 { ISD::SIGN_EXTEND, MVT::v8i16, MVT::v4i1, { 1, 1, 1, 1 } },
3074 { ISD::SIGN_EXTEND, MVT::v8i8, MVT::v8i1, { 1, 1, 1, 1 } },
3075 { ISD::SIGN_EXTEND, MVT::v16i8, MVT::v8i1, { 1, 1, 1, 1 } },
3076 { ISD::SIGN_EXTEND, MVT::v8i16, MVT::v8i1, { 1, 1, 1, 1 } },
3077 { ISD::SIGN_EXTEND, MVT::v16i8, MVT::v16i1, { 1, 1, 1, 1 } },
3078 { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i1, { 1, 1, 1, 1 } },
3079 { ISD::SIGN_EXTEND, MVT::v32i8, MVT::v32i1, { 1, 1, 1, 1 } },
3080 { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v32i1, { 1, 1, 1, 1 } },
3081 { ISD::SIGN_EXTEND, MVT::v32i8, MVT::v64i1, { 1, 1, 1, 1 } },
3082 { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v64i1, { 1, 1, 1, 1 } },
3083
3084 // Mask zero extend is a sext + shift.
3085 { ISD::ZERO_EXTEND, MVT::v2i8, MVT::v2i1, { 2, 1, 1, 1 } },
3086 { ISD::ZERO_EXTEND, MVT::v16i8, MVT::v2i1, { 2, 1, 1, 1 } },
3087 { ISD::ZERO_EXTEND, MVT::v2i16, MVT::v2i1, { 2, 1, 1, 1 } },
3088 { ISD::ZERO_EXTEND, MVT::v8i16, MVT::v2i1, { 2, 1, 1, 1 } },
3089 { ISD::ZERO_EXTEND, MVT::v4i8, MVT::v4i1, { 2, 1, 1, 1 } },
3090 { ISD::ZERO_EXTEND, MVT::v16i8, MVT::v4i1, { 2, 1, 1, 1 } },
3091 { ISD::ZERO_EXTEND, MVT::v4i16, MVT::v4i1, { 2, 1, 1, 1 } },
3092 { ISD::ZERO_EXTEND, MVT::v8i16, MVT::v4i1, { 2, 1, 1, 1 } },
3093 { ISD::ZERO_EXTEND, MVT::v8i8, MVT::v8i1, { 2, 1, 1, 1 } },
3094 { ISD::ZERO_EXTEND, MVT::v16i8, MVT::v8i1, { 2, 1, 1, 1 } },
3095 { ISD::ZERO_EXTEND, MVT::v8i16, MVT::v8i1, { 2, 1, 1, 1 } },
3096 { ISD::ZERO_EXTEND, MVT::v16i8, MVT::v16i1, { 2, 1, 1, 1 } },
3097 { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i1, { 2, 1, 1, 1 } },
3098 { ISD::ZERO_EXTEND, MVT::v32i8, MVT::v32i1, { 2, 1, 1, 1 } },
3099 { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v32i1, { 2, 1, 1, 1 } },
3100 { ISD::ZERO_EXTEND, MVT::v32i8, MVT::v64i1, { 2, 1, 1, 1 } },
3101 { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v64i1, { 2, 1, 1, 1 } },
3102
3103 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i8, { 2, 1, 1, 1 } },
3104 { ISD::TRUNCATE, MVT::v2i1, MVT::v16i8, { 2, 1, 1, 1 } },
3105 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i16, { 2, 1, 1, 1 } },
3106 { ISD::TRUNCATE, MVT::v2i1, MVT::v8i16, { 2, 1, 1, 1 } },
3107 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i8, { 2, 1, 1, 1 } },
3108 { ISD::TRUNCATE, MVT::v4i1, MVT::v16i8, { 2, 1, 1, 1 } },
3109 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i16, { 2, 1, 1, 1 } },
3110 { ISD::TRUNCATE, MVT::v4i1, MVT::v8i16, { 2, 1, 1, 1 } },
3111 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i8, { 2, 1, 1, 1 } },
3112 { ISD::TRUNCATE, MVT::v8i1, MVT::v16i8, { 2, 1, 1, 1 } },
3113 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i16, { 2, 1, 1, 1 } },
3114 { ISD::TRUNCATE, MVT::v16i1, MVT::v16i8, { 2, 1, 1, 1 } },
3115 { ISD::TRUNCATE, MVT::v16i1, MVT::v16i16, { 2, 1, 1, 1 } },
3116 { ISD::TRUNCATE, MVT::v32i1, MVT::v32i8, { 2, 1, 1, 1 } },
3117 { ISD::TRUNCATE, MVT::v32i1, MVT::v16i16, { 2, 1, 1, 1 } },
3118 { ISD::TRUNCATE, MVT::v64i1, MVT::v32i8, { 2, 1, 1, 1 } },
3119 { ISD::TRUNCATE, MVT::v64i1, MVT::v16i16, { 2, 1, 1, 1 } },
3120
3121 { ISD::TRUNCATE, MVT::v16i8, MVT::v16i16, { 2, 1, 1, 1 } },
3122 };
3123
3124 static const TypeConversionCostKindTblEntry AVX512DQVLConversionTbl[] = {
3125 // Mask sign extend has an instruction.
3126 { ISD::SIGN_EXTEND, MVT::v2i64, MVT::v2i1, { 1, 1, 1, 1 } },
3127 { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v2i1, { 1, 1, 1, 1 } },
3128 { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v4i1, { 1, 1, 1, 1 } },
3129 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v16i1, { 1, 1, 1, 1 } },
3130 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i1, { 1, 1, 1, 1 } },
3131 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v8i1, { 1, 1, 1, 1 } },
3132 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v16i1, { 1, 1, 1, 1 } },
3133 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i1, { 1, 1, 1, 1 } },
3134
3135 // Mask zero extend is a sext + shift.
3136 { ISD::ZERO_EXTEND, MVT::v2i64, MVT::v2i1, { 2, 1, 1, 1 } },
3137 { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v2i1, { 2, 1, 1, 1 } },
3138 { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v4i1, { 2, 1, 1, 1 } },
3139 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v16i1, { 2, 1, 1, 1 } },
3140 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i1, { 2, 1, 1, 1 } },
3141 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v8i1, { 2, 1, 1, 1 } },
3142 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v16i1, { 2, 1, 1, 1 } },
3143 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i1, { 2, 1, 1, 1 } },
3144
3145 { ISD::TRUNCATE, MVT::v16i1, MVT::v4i64, { 2, 1, 1, 1 } },
3146 { ISD::TRUNCATE, MVT::v16i1, MVT::v8i32, { 2, 1, 1, 1 } },
3147 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i64, { 2, 1, 1, 1 } },
3148 { ISD::TRUNCATE, MVT::v2i1, MVT::v4i32, { 2, 1, 1, 1 } },
3149 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i32, { 2, 1, 1, 1 } },
3150 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i64, { 2, 1, 1, 1 } },
3151 { ISD::TRUNCATE, MVT::v8i1, MVT::v4i64, { 2, 1, 1, 1 } },
3152 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i32, { 2, 1, 1, 1 } },
3153
3154 { ISD::SINT_TO_FP, MVT::v2f32, MVT::v2i64, { 1, 1, 1, 1 } },
3155 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v2i64, { 1, 1, 1, 1 } },
3156 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i64, { 1, 1, 1, 1 } },
3157 { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i64, { 1, 1, 1, 1 } },
3158
3159 { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i64, { 1, 1, 1, 1 } },
3160 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, { 1, 1, 1, 1 } },
3161 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i64, { 1, 1, 1, 1 } },
3162 { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i64, { 1, 1, 1, 1 } },
3163
3164 { ISD::FP_TO_SINT, MVT::v2i64, MVT::v4f32, { 1, 1, 1, 1 } },
3165 { ISD::FP_TO_SINT, MVT::v4i64, MVT::v4f32, { 1, 1, 1, 1 } },
3166 { ISD::FP_TO_SINT, MVT::v2i64, MVT::v2f64, { 1, 1, 1, 1 } },
3167 { ISD::FP_TO_SINT, MVT::v4i64, MVT::v4f64, { 1, 1, 1, 1 } },
3168
3169 { ISD::FP_TO_UINT, MVT::v2i64, MVT::v4f32, { 1, 1, 1, 1 } },
3170 { ISD::FP_TO_UINT, MVT::v4i64, MVT::v4f32, { 1, 1, 1, 1 } },
3171 { ISD::FP_TO_UINT, MVT::v2i64, MVT::v2f64, { 1, 1, 1, 1 } },
3172 { ISD::FP_TO_UINT, MVT::v4i64, MVT::v4f64, { 1, 1, 1, 1 } },
3173 };
3174
3175 static const TypeConversionCostKindTblEntry AVX512VLConversionTbl[] = {
3176 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i8, { 3, 1, 1, 1 } }, // sext+vpslld+vptestmd
3177 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i8, { 3, 1, 1, 1 } }, // sext+vpslld+vptestmd
3178 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i8, { 3, 1, 1, 1 } }, // sext+vpslld+vptestmd
3179 { ISD::TRUNCATE, MVT::v16i1, MVT::v16i8, { 8, 1, 1, 1 } }, // split+2*v8i8
3180 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i16, { 3, 1, 1, 1 } }, // sext+vpsllq+vptestmq
3181 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i16, { 3, 1, 1, 1 } }, // sext+vpsllq+vptestmq
3182 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i16, { 3, 1, 1, 1 } }, // sext+vpsllq+vptestmq
3183 { ISD::TRUNCATE, MVT::v16i1, MVT::v16i16, { 8, 1, 1, 1 } }, // split+2*v8i16
3184 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i32, { 2, 1, 1, 1 } }, // vpslld+vptestmd
3185 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i32, { 2, 1, 1, 1 } }, // vpslld+vptestmd
3186 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i32, { 2, 1, 1, 1 } }, // vpslld+vptestmd
3187 { ISD::TRUNCATE, MVT::v16i1, MVT::v8i32, { 2, 1, 1, 1 } }, // vpslld+vptestmd
3188 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i64, { 2, 1, 1, 1 } }, // vpsllq+vptestmq
3189 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i64, { 2, 1, 1, 1 } }, // vpsllq+vptestmq
3190 { ISD::TRUNCATE, MVT::v4i32, MVT::v4i64, { 1, 1, 1, 1 } }, // vpmovqd
3191 { ISD::TRUNCATE, MVT::v4i8, MVT::v4i64, { 2, 1, 1, 1 } }, // vpmovqb
3192 { ISD::TRUNCATE, MVT::v4i16, MVT::v4i64, { 2, 1, 1, 1 } }, // vpmovqw
3193 { ISD::TRUNCATE, MVT::v8i8, MVT::v8i32, { 2, 1, 1, 1 } }, // vpmovwb
3194
3195 // sign extend is vpcmpeq+maskedmove+vpmovdw+vpacksswb
3196 // zero extend is vpcmpeq+maskedmove+vpmovdw+vpsrlw+vpackuswb
3197 { ISD::SIGN_EXTEND, MVT::v2i8, MVT::v2i1, { 5, 1, 1, 1 } },
3198 { ISD::ZERO_EXTEND, MVT::v2i8, MVT::v2i1, { 6, 1, 1, 1 } },
3199 { ISD::SIGN_EXTEND, MVT::v4i8, MVT::v4i1, { 5, 1, 1, 1 } },
3200 { ISD::ZERO_EXTEND, MVT::v4i8, MVT::v4i1, { 6, 1, 1, 1 } },
3201 { ISD::SIGN_EXTEND, MVT::v8i8, MVT::v8i1, { 5, 1, 1, 1 } },
3202 { ISD::ZERO_EXTEND, MVT::v8i8, MVT::v8i1, { 6, 1, 1, 1 } },
3203 { ISD::SIGN_EXTEND, MVT::v16i8, MVT::v16i1, {10, 1, 1, 1 } },
3204 { ISD::ZERO_EXTEND, MVT::v16i8, MVT::v16i1, {12, 1, 1, 1 } },
3205
3206 // sign extend is vpcmpeq+maskedmove+vpmovdw
3207 // zero extend is vpcmpeq+maskedmove+vpmovdw+vpsrlw
3208 { ISD::SIGN_EXTEND, MVT::v2i16, MVT::v2i1, { 4, 1, 1, 1 } },
3209 { ISD::ZERO_EXTEND, MVT::v2i16, MVT::v2i1, { 5, 1, 1, 1 } },
3210 { ISD::SIGN_EXTEND, MVT::v4i16, MVT::v4i1, { 4, 1, 1, 1 } },
3211 { ISD::ZERO_EXTEND, MVT::v4i16, MVT::v4i1, { 5, 1, 1, 1 } },
3212 { ISD::SIGN_EXTEND, MVT::v8i16, MVT::v8i1, { 4, 1, 1, 1 } },
3213 { ISD::ZERO_EXTEND, MVT::v8i16, MVT::v8i1, { 5, 1, 1, 1 } },
3214 { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i1, {10, 1, 1, 1 } },
3215 { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i1, {12, 1, 1, 1 } },
3216
3217 { ISD::SIGN_EXTEND, MVT::v2i32, MVT::v2i1, { 1, 1, 1, 1 } }, // vpternlogd
3218 { ISD::ZERO_EXTEND, MVT::v2i32, MVT::v2i1, { 2, 1, 1, 1 } }, // vpternlogd+psrld
3219 { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v4i1, { 1, 1, 1, 1 } }, // vpternlogd
3220 { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v4i1, { 2, 1, 1, 1 } }, // vpternlogd+psrld
3221 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i1, { 1, 1, 1, 1 } }, // vpternlogd
3222 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i1, { 2, 1, 1, 1 } }, // vpternlogd+psrld
3223 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v16i1, { 1, 1, 1, 1 } }, // vpternlogd
3224 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v16i1, { 2, 1, 1, 1 } }, // vpternlogd+psrld
3225
3226 { ISD::SIGN_EXTEND, MVT::v2i64, MVT::v2i1, { 1, 1, 1, 1 } }, // vpternlogq
3227 { ISD::ZERO_EXTEND, MVT::v2i64, MVT::v2i1, { 2, 1, 1, 1 } }, // vpternlogq+psrlq
3228 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i1, { 1, 1, 1, 1 } }, // vpternlogq
3229 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i1, { 2, 1, 1, 1 } }, // vpternlogq+psrlq
3230
3231 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v16i8, { 1, 1, 1, 1 } },
3232 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v16i8, { 1, 1, 1, 1 } },
3233 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v16i8, { 1, 1, 1, 1 } },
3234 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v16i8, { 1, 1, 1, 1 } },
3235 { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i8, { 1, 1, 1, 1 } },
3236 { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i8, { 1, 1, 1, 1 } },
3237 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v8i16, { 1, 1, 1, 1 } },
3238 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v8i16, { 1, 1, 1, 1 } },
3239 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, { 1, 1, 1, 1 } },
3240 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, { 1, 1, 1, 1 } },
3241 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, { 1, 1, 1, 1 } },
3242 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, { 1, 1, 1, 1 } },
3243
3244 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v16i8, { 1, 1, 1, 1 } },
3245 { ISD::SINT_TO_FP, MVT::v8f32, MVT::v16i8, { 1, 1, 1, 1 } },
3246 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v8i16, { 1, 1, 1, 1 } },
3247 { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i16, { 1, 1, 1, 1 } },
3248
3249 { ISD::UINT_TO_FP, MVT::f32, MVT::i64, { 1, 1, 1, 1 } },
3250 { ISD::UINT_TO_FP, MVT::f64, MVT::i64, { 1, 1, 1, 1 } },
3251 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v16i8, { 1, 1, 1, 1 } },
3252 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v16i8, { 1, 1, 1, 1 } },
3253 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v8i16, { 1, 1, 1, 1 } },
3254 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i16, { 1, 1, 1, 1 } },
3255 { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i32, { 1, 1, 1, 1 } },
3256 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, { 1, 1, 1, 1 } },
3257 { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i32, { 1, 1, 1, 1 } },
3258 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i32, { 1, 1, 1, 1 } },
3259 { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i64, { 5, 1, 1, 1 } },
3260 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, { 5, 1, 1, 1 } },
3261 { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i64, { 5, 1, 1, 1 } },
3262
3263 { ISD::FP_TO_SINT, MVT::v16i8, MVT::v8f32, { 2, 1, 1, 1 } },
3264 { ISD::FP_TO_SINT, MVT::v16i8, MVT::v16f32, { 2, 1, 1, 1 } },
3265 { ISD::FP_TO_SINT, MVT::v32i8, MVT::v32f32, { 5, 1, 1, 1 } },
3266
3267 { ISD::FP_TO_UINT, MVT::i64, MVT::f32, { 1, 1, 1, 1 } },
3268 { ISD::FP_TO_UINT, MVT::i64, MVT::f64, { 1, 1, 1, 1 } },
3269 { ISD::FP_TO_UINT, MVT::v4i32, MVT::v4f32, { 1, 1, 1, 1 } },
3270 { ISD::FP_TO_UINT, MVT::v4i32, MVT::v2f64, { 1, 1, 1, 1 } },
3271 { ISD::FP_TO_UINT, MVT::v4i32, MVT::v4f64, { 1, 1, 1, 1 } },
3272 { ISD::FP_TO_UINT, MVT::v8i32, MVT::v8f32, { 1, 1, 1, 1 } },
3273 { ISD::FP_TO_UINT, MVT::v8i32, MVT::v8f64, { 1, 1, 1, 1 } },
3274 };
3275
3276 static const TypeConversionCostKindTblEntry AVX2ConversionTbl[] = {
3277 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i1, { 3, 1, 1, 1 } },
3278 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i1, { 3, 1, 1, 1 } },
3279 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i1, { 3, 1, 1, 1 } },
3280 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i1, { 3, 1, 1, 1 } },
3281 { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i1, { 1, 1, 1, 1 } },
3282 { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i1, { 1, 1, 1, 1 } },
3283
3284 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v16i8, { 2, 1, 1, 1 } },
3285 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v16i8, { 2, 1, 1, 1 } },
3286 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v16i8, { 2, 1, 1, 1 } },
3287 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v16i8, { 2, 1, 1, 1 } },
3288 { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i8, { 2, 1, 1, 1 } },
3289 { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i8, { 2, 1, 1, 1 } },
3290 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v8i16, { 2, 1, 1, 1 } },
3291 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v8i16, { 2, 1, 1, 1 } },
3292 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, { 2, 1, 1, 1 } },
3293 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, { 2, 1, 1, 1 } },
3294 { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i16, { 3, 1, 1, 1 } },
3295 { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i16, { 3, 1, 1, 1 } },
3296 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, { 2, 1, 1, 1 } },
3297 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, { 2, 1, 1, 1 } },
3298
3299 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i32, { 2, 1, 1, 1 } },
3300
3301 { ISD::TRUNCATE, MVT::v16i16, MVT::v16i32, { 4, 1, 1, 1 } },
3302 { ISD::TRUNCATE, MVT::v16i8, MVT::v16i32, { 4, 1, 1, 1 } },
3303 { ISD::TRUNCATE, MVT::v16i8, MVT::v8i16, { 1, 1, 1, 1 } },
3304 { ISD::TRUNCATE, MVT::v16i8, MVT::v4i32, { 1, 1, 1, 1 } },
3305 { ISD::TRUNCATE, MVT::v16i8, MVT::v2i64, { 1, 1, 1, 1 } },
3306 { ISD::TRUNCATE, MVT::v16i8, MVT::v8i32, { 4, 1, 1, 1 } },
3307 { ISD::TRUNCATE, MVT::v16i8, MVT::v4i64, { 4, 1, 1, 1 } },
3308 { ISD::TRUNCATE, MVT::v8i16, MVT::v4i32, { 1, 1, 1, 1 } },
3309 { ISD::TRUNCATE, MVT::v8i16, MVT::v2i64, { 1, 1, 1, 1 } },
3310 { ISD::TRUNCATE, MVT::v8i16, MVT::v4i64, { 5, 1, 1, 1 } },
3311 { ISD::TRUNCATE, MVT::v4i32, MVT::v4i64, { 1, 1, 1, 1 } },
3312 { ISD::TRUNCATE, MVT::v8i16, MVT::v8i32, { 2, 1, 1, 1 } },
3313
3314 { ISD::FP_EXTEND, MVT::v8f64, MVT::v8f32, { 3, 1, 1, 1 } },
3315 { ISD::FP_ROUND, MVT::v8f32, MVT::v8f64, { 3, 1, 1, 1 } },
3316
3317 { ISD::FP_TO_SINT, MVT::v16i16, MVT::v8f32, { 1, 1, 1, 1 } },
3318 { ISD::FP_TO_SINT, MVT::v4i32, MVT::v4f64, { 1, 1, 1, 1 } },
3319 { ISD::FP_TO_SINT, MVT::v8i32, MVT::v8f32, { 1, 1, 1, 1 } },
3320 { ISD::FP_TO_SINT, MVT::v8i32, MVT::v8f64, { 3, 1, 1, 1 } },
3321
3322 { ISD::FP_TO_UINT, MVT::i64, MVT::f32, { 3, 1, 1, 1 } },
3323 { ISD::FP_TO_UINT, MVT::i64, MVT::f64, { 3, 1, 1, 1 } },
3324 { ISD::FP_TO_UINT, MVT::v16i16, MVT::v8f32, { 1, 1, 1, 1 } },
3325 { ISD::FP_TO_UINT, MVT::v4i32, MVT::v4f32, { 3, 1, 1, 1 } },
3326 { ISD::FP_TO_UINT, MVT::v4i32, MVT::v2f64, { 4, 1, 1, 1 } },
3327 { ISD::FP_TO_UINT, MVT::v4i32, MVT::v4f64, { 4, 1, 1, 1 } },
3328 { ISD::FP_TO_UINT, MVT::v8i32, MVT::v8f32, { 3, 1, 1, 1 } },
3329 { ISD::FP_TO_UINT, MVT::v8i32, MVT::v4f64, { 4, 1, 1, 1 } },
3330
3331 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v16i8, { 2, 1, 1, 1 } },
3332 { ISD::SINT_TO_FP, MVT::v8f32, MVT::v16i8, { 2, 1, 1, 1 } },
3333 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v8i16, { 2, 1, 1, 1 } },
3334 { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i16, { 2, 1, 1, 1 } },
3335 { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i32, { 1, 1, 1, 1 } },
3336 { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i32, { 1, 1, 1, 1 } },
3337 { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i32, { 3, 1, 1, 1 } },
3338
3339 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v16i8, { 2, 1, 1, 1 } },
3340 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v16i8, { 2, 1, 1, 1 } },
3341 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v8i16, { 2, 1, 1, 1 } },
3342 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i16, { 2, 1, 1, 1 } },
3343 { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i32, { 2, 1, 1, 1 } },
3344 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i32, { 1, 1, 1, 1 } },
3345 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, { 2, 1, 1, 1 } },
3346 { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i32, { 2, 1, 1, 1 } },
3347 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i32, { 2, 1, 1, 1 } },
3348 { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i32, { 4, 1, 1, 1 } },
3349 };
3350
3351 static const TypeConversionCostKindTblEntry AVXConversionTbl[] = {
3352 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i1, { 4, 1, 1, 1 } },
3353 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i1, { 4, 1, 1, 1 } },
3354 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i1, { 4, 1, 1, 1 } },
3355 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i1, { 4, 1, 1, 1 } },
3356 { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i1, { 4, 1, 1, 1 } },
3357 { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i1, { 4, 1, 1, 1 } },
3358
3359 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v16i8, { 3, 1, 1, 1 } },
3360 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v16i8, { 3, 1, 1, 1 } },
3361 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v16i8, { 3, 1, 1, 1 } },
3362 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v16i8, { 3, 1, 1, 1 } },
3363 { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i8, { 3, 1, 1, 1 } },
3364 { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i8, { 3, 1, 1, 1 } },
3365 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v8i16, { 3, 1, 1, 1 } },
3366 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v8i16, { 3, 1, 1, 1 } },
3367 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, { 3, 1, 1, 1 } },
3368 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, { 3, 1, 1, 1 } },
3369 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, { 3, 1, 1, 1 } },
3370 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, { 3, 1, 1, 1 } },
3371
3372 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i64, { 4, 1, 1, 1 } },
3373 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i32, { 5, 1, 1, 1 } },
3374 { ISD::TRUNCATE, MVT::v16i1, MVT::v16i16, { 4, 1, 1, 1 } },
3375 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i64, { 9, 1, 1, 1 } },
3376 { ISD::TRUNCATE, MVT::v16i1, MVT::v16i64, {11, 1, 1, 1 } },
3377
3378 { ISD::TRUNCATE, MVT::v16i16, MVT::v16i32, { 6, 1, 1, 1 } },
3379 { ISD::TRUNCATE, MVT::v16i8, MVT::v16i32, { 6, 1, 1, 1 } },
3380 { ISD::TRUNCATE, MVT::v16i8, MVT::v16i16, { 2, 1, 1, 1 } }, // and+extract+packuswb
3381 { ISD::TRUNCATE, MVT::v16i8, MVT::v8i32, { 5, 1, 1, 1 } },
3382 { ISD::TRUNCATE, MVT::v8i16, MVT::v8i32, { 5, 1, 1, 1 } },
3383 { ISD::TRUNCATE, MVT::v16i8, MVT::v4i64, { 5, 1, 1, 1 } },
3384 { ISD::TRUNCATE, MVT::v8i16, MVT::v4i64, { 3, 1, 1, 1 } }, // and+extract+2*packusdw
3385 { ISD::TRUNCATE, MVT::v4i32, MVT::v4i64, { 2, 1, 1, 1 } },
3386
3387 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i1, { 3, 1, 1, 1 } },
3388 { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i1, { 3, 1, 1, 1 } },
3389 { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i1, { 8, 1, 1, 1 } },
3390 { ISD::SINT_TO_FP, MVT::v8f32, MVT::v16i8, { 4, 1, 1, 1 } },
3391 { ISD::SINT_TO_FP, MVT::v4f64, MVT::v16i8, { 2, 1, 1, 1 } },
3392 { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i16, { 4, 1, 1, 1 } },
3393 { ISD::SINT_TO_FP, MVT::v4f64, MVT::v8i16, { 2, 1, 1, 1 } },
3394 { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i32, { 2, 1, 1, 1 } },
3395 { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i32, { 2, 1, 1, 1 } },
3396 { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i32, { 4, 1, 1, 1 } },
3397 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v2i64, { 5, 1, 1, 1 } },
3398 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i64, { 8, 1, 1, 1 } },
3399
3400 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i1, { 7, 1, 1, 1 } },
3401 { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i1, { 7, 1, 1, 1 } },
3402 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i1, { 6, 1, 1, 1 } },
3403 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v16i8, { 4, 1, 1, 1 } },
3404 { ISD::UINT_TO_FP, MVT::v4f64, MVT::v16i8, { 2, 1, 1, 1 } },
3405 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i16, { 4, 1, 1, 1 } },
3406 { ISD::UINT_TO_FP, MVT::v4f64, MVT::v8i16, { 2, 1, 1, 1 } },
3407 { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i32, { 4, 1, 1, 1 } },
3408 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i32, { 4, 1, 1, 1 } },
3409 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, { 5, 1, 1, 1 } },
3410 { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i32, { 6, 1, 1, 1 } },
3411 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i32, { 8, 1, 1, 1 } },
3412 { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i32, {10, 1, 1, 1 } },
3413 { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i64, {11, 1, 1, 1 } },
3414 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i64, {18, 1, 1, 1 } },
3415 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, { 5, 1, 1, 1 } },
3416 { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i64, {10, 1, 1, 1 } },
3417
3418 { ISD::FP_TO_SINT, MVT::v16i8, MVT::v8f32, { 2, 1, 1, 1 } },
3419 { ISD::FP_TO_SINT, MVT::v16i8, MVT::v4f64, { 2, 1, 1, 1 } },
3420 { ISD::FP_TO_SINT, MVT::v32i8, MVT::v8f32, { 2, 1, 1, 1 } },
3421 { ISD::FP_TO_SINT, MVT::v32i8, MVT::v4f64, { 2, 1, 1, 1 } },
3422 { ISD::FP_TO_SINT, MVT::v8i16, MVT::v8f32, { 2, 1, 1, 1 } },
3423 { ISD::FP_TO_SINT, MVT::v8i16, MVT::v4f64, { 2, 1, 1, 1 } },
3424 { ISD::FP_TO_SINT, MVT::v16i16, MVT::v8f32, { 2, 1, 1, 1 } },
3425 { ISD::FP_TO_SINT, MVT::v16i16, MVT::v4f64, { 2, 1, 1, 1 } },
3426 { ISD::FP_TO_SINT, MVT::v4i32, MVT::v4f64, { 2, 1, 1, 1 } },
3427 { ISD::FP_TO_SINT, MVT::v8i32, MVT::v8f32, { 2, 1, 1, 1 } },
3428 { ISD::FP_TO_SINT, MVT::v8i32, MVT::v8f64, { 5, 1, 1, 1 } },
3429
3430 { ISD::FP_TO_UINT, MVT::v16i8, MVT::v8f32, { 2, 1, 1, 1 } },
3431 { ISD::FP_TO_UINT, MVT::v16i8, MVT::v4f64, { 2, 1, 1, 1 } },
3432 { ISD::FP_TO_UINT, MVT::v32i8, MVT::v8f32, { 2, 1, 1, 1 } },
3433 { ISD::FP_TO_UINT, MVT::v32i8, MVT::v4f64, { 2, 1, 1, 1 } },
3434 { ISD::FP_TO_UINT, MVT::v8i16, MVT::v8f32, { 2, 1, 1, 1 } },
3435 { ISD::FP_TO_UINT, MVT::v8i16, MVT::v4f64, { 2, 1, 1, 1 } },
3436 { ISD::FP_TO_UINT, MVT::v16i16, MVT::v8f32, { 2, 1, 1, 1 } },
3437 { ISD::FP_TO_UINT, MVT::v16i16, MVT::v4f64, { 2, 1, 1, 1 } },
3438 { ISD::FP_TO_UINT, MVT::v4i32, MVT::v4f32, { 3, 1, 1, 1 } },
3439 { ISD::FP_TO_UINT, MVT::v4i32, MVT::v2f64, { 4, 1, 1, 1 } },
3440 { ISD::FP_TO_UINT, MVT::v4i32, MVT::v4f64, { 6, 1, 1, 1 } },
3441 { ISD::FP_TO_UINT, MVT::v8i32, MVT::v8f32, { 7, 1, 1, 1 } },
3442 { ISD::FP_TO_UINT, MVT::v8i32, MVT::v4f64, { 7, 1, 1, 1 } },
3443
3444 { ISD::FP_EXTEND, MVT::v4f64, MVT::v4f32, { 1, 1, 1, 1 } },
3445 { ISD::FP_ROUND, MVT::v4f32, MVT::v4f64, { 1, 1, 1, 1 } },
3446 };
3447
3448 static const TypeConversionCostKindTblEntry SSE41ConversionTbl[] = {
3449 { ISD::ZERO_EXTEND, MVT::v2i64, MVT::v16i8, { 1, 1, 1, 1 } },
3450 { ISD::SIGN_EXTEND, MVT::v2i64, MVT::v16i8, { 1, 1, 1, 1 } },
3451 { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v16i8, { 1, 1, 1, 1 } },
3452 { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v16i8, { 1, 1, 1, 1 } },
3453 { ISD::ZERO_EXTEND, MVT::v8i16, MVT::v16i8, { 1, 1, 1, 1 } },
3454 { ISD::SIGN_EXTEND, MVT::v8i16, MVT::v16i8, { 1, 1, 1, 1 } },
3455 { ISD::ZERO_EXTEND, MVT::v2i64, MVT::v8i16, { 1, 1, 1, 1 } },
3456 { ISD::SIGN_EXTEND, MVT::v2i64, MVT::v8i16, { 1, 1, 1, 1 } },
3457 { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v8i16, { 1, 1, 1, 1 } },
3458 { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v8i16, { 1, 1, 1, 1 } },
3459 { ISD::ZERO_EXTEND, MVT::v2i64, MVT::v4i32, { 1, 1, 1, 1 } },
3460 { ISD::SIGN_EXTEND, MVT::v2i64, MVT::v4i32, { 1, 1, 1, 1 } },
3461
3462 // These truncates end up widening elements.
3463 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i8, { 1, 1, 1, 1 } }, // PMOVXZBQ
3464 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i16, { 1, 1, 1, 1 } }, // PMOVXZWQ
3465 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i8, { 1, 1, 1, 1 } }, // PMOVXZBD
3466
3467 { ISD::TRUNCATE, MVT::v16i8, MVT::v4i32, { 2, 1, 1, 1 } },
3468 { ISD::TRUNCATE, MVT::v8i16, MVT::v4i32, { 2, 1, 1, 1 } },
3469 { ISD::TRUNCATE, MVT::v16i8, MVT::v2i64, { 2, 1, 1, 1 } },
3470
3471 { ISD::SINT_TO_FP, MVT::f32, MVT::i32, { 1, 1, 1, 1 } },
3472 { ISD::SINT_TO_FP, MVT::f64, MVT::i32, { 1, 1, 1, 1 } },
3473 { ISD::SINT_TO_FP, MVT::f32, MVT::i64, { 1, 1, 1, 1 } },
3474 { ISD::SINT_TO_FP, MVT::f64, MVT::i64, { 1, 1, 1, 1 } },
3475 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v16i8, { 1, 1, 1, 1 } },
3476 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v16i8, { 1, 1, 1, 1 } },
3477 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v8i16, { 1, 1, 1, 1 } },
3478 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v8i16, { 1, 1, 1, 1 } },
3479 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i32, { 1, 1, 1, 1 } },
3480 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v4i32, { 1, 1, 1, 1 } },
3481 { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i32, { 2, 1, 1, 1 } },
3482
3483 { ISD::UINT_TO_FP, MVT::f32, MVT::i32, { 1, 1, 1, 1 } },
3484 { ISD::UINT_TO_FP, MVT::f64, MVT::i32, { 1, 1, 1, 1 } },
3485 { ISD::UINT_TO_FP, MVT::f32, MVT::i64, { 4, 1, 1, 1 } },
3486 { ISD::UINT_TO_FP, MVT::f64, MVT::i64, { 4, 1, 1, 1 } },
3487 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v16i8, { 1, 1, 1, 1 } },
3488 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v16i8, { 1, 1, 1, 1 } },
3489 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v8i16, { 1, 1, 1, 1 } },
3490 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v8i16, { 1, 1, 1, 1 } },
3491 { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i32, { 3, 1, 1, 1 } },
3492 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, { 3, 1, 1, 1 } },
3493 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v4i32, { 2, 1, 1, 1 } },
3494 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v2i64, {12, 1, 1, 1 } },
3495 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i64, {22, 1, 1, 1 } },
3496 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, { 4, 1, 1, 1 } },
3497
3498 { ISD::FP_TO_SINT, MVT::i32, MVT::f32, { 1, 1, 1, 1 } },
3499 { ISD::FP_TO_SINT, MVT::i64, MVT::f32, { 1, 1, 1, 1 } },
3500 { ISD::FP_TO_SINT, MVT::i32, MVT::f64, { 1, 1, 1, 1 } },
3501 { ISD::FP_TO_SINT, MVT::i64, MVT::f64, { 1, 1, 1, 1 } },
3502 { ISD::FP_TO_SINT, MVT::v16i8, MVT::v4f32, { 2, 1, 1, 1 } },
3503 { ISD::FP_TO_SINT, MVT::v16i8, MVT::v2f64, { 2, 1, 1, 1 } },
3504 { ISD::FP_TO_SINT, MVT::v8i16, MVT::v4f32, { 1, 1, 1, 1 } },
3505 { ISD::FP_TO_SINT, MVT::v8i16, MVT::v2f64, { 1, 1, 1, 1 } },
3506 { ISD::FP_TO_SINT, MVT::v4i32, MVT::v4f32, { 1, 1, 1, 1 } },
3507 { ISD::FP_TO_SINT, MVT::v4i32, MVT::v2f64, { 1, 1, 1, 1 } },
3508
3509 { ISD::FP_TO_UINT, MVT::i32, MVT::f32, { 1, 1, 1, 1 } },
3510 { ISD::FP_TO_UINT, MVT::i64, MVT::f32, { 4, 1, 1, 1 } },
3511 { ISD::FP_TO_UINT, MVT::i32, MVT::f64, { 1, 1, 1, 1 } },
3512 { ISD::FP_TO_UINT, MVT::i64, MVT::f64, { 4, 1, 1, 1 } },
3513 { ISD::FP_TO_UINT, MVT::v16i8, MVT::v4f32, { 2, 1, 1, 1 } },
3514 { ISD::FP_TO_UINT, MVT::v16i8, MVT::v2f64, { 2, 1, 1, 1 } },
3515 { ISD::FP_TO_UINT, MVT::v8i16, MVT::v4f32, { 1, 1, 1, 1 } },
3516 { ISD::FP_TO_UINT, MVT::v8i16, MVT::v2f64, { 1, 1, 1, 1 } },
3517 { ISD::FP_TO_UINT, MVT::v4i32, MVT::v4f32, { 4, 1, 1, 1 } },
3518 { ISD::FP_TO_UINT, MVT::v4i32, MVT::v2f64, { 4, 1, 1, 1 } },
3519 };
3520
3521 static const TypeConversionCostKindTblEntry SSE2ConversionTbl[] = {
3522 // These are somewhat magic numbers justified by comparing the
3523 // output of llvm-mca for our various supported scheduler models
3524 // and basing it off the worst case scenario.
3525 { ISD::SINT_TO_FP, MVT::f32, MVT::i32, { 3, 1, 1, 1 } },
3526 { ISD::SINT_TO_FP, MVT::f64, MVT::i32, { 3, 1, 1, 1 } },
3527 { ISD::SINT_TO_FP, MVT::f32, MVT::i64, { 3, 1, 1, 1 } },
3528 { ISD::SINT_TO_FP, MVT::f64, MVT::i64, { 3, 1, 1, 1 } },
3529 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v16i8, { 3, 1, 1, 1 } },
3530 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v16i8, { 4, 1, 1, 1 } },
3531 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v8i16, { 3, 1, 1, 1 } },
3532 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v8i16, { 4, 1, 1, 1 } },
3533 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i32, { 3, 1, 1, 1 } },
3534 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v4i32, { 4, 1, 1, 1 } },
3535 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v2i64, { 8, 1, 1, 1 } },
3536 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v2i64, { 8, 1, 1, 1 } },
3537
3538 { ISD::UINT_TO_FP, MVT::f32, MVT::i32, { 3, 1, 1, 1 } },
3539 { ISD::UINT_TO_FP, MVT::f64, MVT::i32, { 3, 1, 1, 1 } },
3540 { ISD::UINT_TO_FP, MVT::f32, MVT::i64, { 8, 1, 1, 1 } },
3541 { ISD::UINT_TO_FP, MVT::f64, MVT::i64, { 9, 1, 1, 1 } },
3542 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v16i8, { 4, 1, 1, 1 } },
3543 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v16i8, { 4, 1, 1, 1 } },
3544 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v8i16, { 4, 1, 1, 1 } },
3545 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v8i16, { 4, 1, 1, 1 } },
3546 { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i32, { 7, 1, 1, 1 } },
3547 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v4i32, { 7, 1, 1, 1 } },
3548 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, { 5, 1, 1, 1 } },
3549 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, {15, 1, 1, 1 } },
3550 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v2i64, {18, 1, 1, 1 } },
3551
3552 { ISD::FP_TO_SINT, MVT::i32, MVT::f32, { 4, 1, 1, 1 } },
3553 { ISD::FP_TO_SINT, MVT::i64, MVT::f32, { 4, 1, 1, 1 } },
3554 { ISD::FP_TO_SINT, MVT::i32, MVT::f64, { 4, 1, 1, 1 } },
3555 { ISD::FP_TO_SINT, MVT::i64, MVT::f64, { 4, 1, 1, 1 } },
3556 { ISD::FP_TO_SINT, MVT::v16i8, MVT::v4f32, { 6, 1, 1, 1 } },
3557 { ISD::FP_TO_SINT, MVT::v16i8, MVT::v2f64, { 6, 1, 1, 1 } },
3558 { ISD::FP_TO_SINT, MVT::v8i16, MVT::v4f32, { 5, 1, 1, 1 } },
3559 { ISD::FP_TO_SINT, MVT::v8i16, MVT::v2f64, { 5, 1, 1, 1 } },
3560 { ISD::FP_TO_SINT, MVT::v4i32, MVT::v4f32, { 4, 1, 1, 1 } },
3561 { ISD::FP_TO_SINT, MVT::v4i32, MVT::v2f64, { 4, 1, 1, 1 } },
3562
3563 { ISD::FP_TO_UINT, MVT::i32, MVT::f32, { 4, 1, 1, 1 } },
3564 { ISD::FP_TO_UINT, MVT::i64, MVT::f32, { 4, 1, 1, 1 } },
3565 { ISD::FP_TO_UINT, MVT::i32, MVT::f64, { 4, 1, 1, 1 } },
3566 { ISD::FP_TO_UINT, MVT::i64, MVT::f64, {15, 1, 1, 1 } },
3567 { ISD::FP_TO_UINT, MVT::v16i8, MVT::v4f32, { 6, 1, 1, 1 } },
3568 { ISD::FP_TO_UINT, MVT::v16i8, MVT::v2f64, { 6, 1, 1, 1 } },
3569 { ISD::FP_TO_UINT, MVT::v8i16, MVT::v4f32, { 5, 1, 1, 1 } },
3570 { ISD::FP_TO_UINT, MVT::v8i16, MVT::v2f64, { 5, 1, 1, 1 } },
3571 { ISD::FP_TO_UINT, MVT::v4i32, MVT::v4f32, { 8, 1, 1, 1 } },
3572 { ISD::FP_TO_UINT, MVT::v4i32, MVT::v2f64, { 8, 1, 1, 1 } },
3573
3574 { ISD::ZERO_EXTEND, MVT::v2i64, MVT::v16i8, { 4, 1, 1, 1 } },
3575 { ISD::SIGN_EXTEND, MVT::v2i64, MVT::v16i8, { 4, 1, 1, 1 } },
3576 { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v16i8, { 2, 1, 1, 1 } },
3577 { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v16i8, { 3, 1, 1, 1 } },
3578 { ISD::ZERO_EXTEND, MVT::v8i16, MVT::v16i8, { 1, 1, 1, 1 } },
3579 { ISD::SIGN_EXTEND, MVT::v8i16, MVT::v16i8, { 2, 1, 1, 1 } },
3580 { ISD::ZERO_EXTEND, MVT::v2i64, MVT::v8i16, { 2, 1, 1, 1 } },
3581 { ISD::SIGN_EXTEND, MVT::v2i64, MVT::v8i16, { 3, 1, 1, 1 } },
3582 { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v8i16, { 1, 1, 1, 1 } },
3583 { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v8i16, { 2, 1, 1, 1 } },
3584 { ISD::ZERO_EXTEND, MVT::v2i64, MVT::v4i32, { 1, 1, 1, 1 } },
3585 { ISD::SIGN_EXTEND, MVT::v2i64, MVT::v4i32, { 2, 1, 1, 1 } },
3586
3587 // These truncates are really widening elements.
3588 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i32, { 1, 1, 1, 1 } }, // PSHUFD
3589 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i16, { 2, 1, 1, 1 } }, // PUNPCKLWD+DQ
3590 { ISD::TRUNCATE, MVT::v2i1, MVT::v2i8, { 3, 1, 1, 1 } }, // PUNPCKLBW+WD+PSHUFD
3591 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i16, { 1, 1, 1, 1 } }, // PUNPCKLWD
3592 { ISD::TRUNCATE, MVT::v4i1, MVT::v4i8, { 2, 1, 1, 1 } }, // PUNPCKLBW+WD
3593 { ISD::TRUNCATE, MVT::v8i1, MVT::v8i8, { 1, 1, 1, 1 } }, // PUNPCKLBW
3594
3595 { ISD::TRUNCATE, MVT::v16i8, MVT::v8i16, { 2, 1, 1, 1 } }, // PAND+PACKUSWB
3596 { ISD::TRUNCATE, MVT::v16i8, MVT::v16i16, { 3, 1, 1, 1 } },
3597 { ISD::TRUNCATE, MVT::v16i8, MVT::v4i32, { 3, 1, 1, 1 } }, // PAND+2*PACKUSWB
3598 { ISD::TRUNCATE, MVT::v16i8, MVT::v16i32, { 7, 1, 1, 1 } },
3599 { ISD::TRUNCATE, MVT::v2i16, MVT::v2i32, { 1, 1, 1, 1 } },
3600 { ISD::TRUNCATE, MVT::v8i16, MVT::v4i32, { 3, 1, 1, 1 } },
3601 { ISD::TRUNCATE, MVT::v8i16, MVT::v8i32, { 5, 1, 1, 1 } },
3602 { ISD::TRUNCATE, MVT::v16i16, MVT::v16i32, {10, 1, 1, 1 } },
3603 { ISD::TRUNCATE, MVT::v16i8, MVT::v2i64, { 4, 1, 1, 1 } }, // PAND+3*PACKUSWB
3604 { ISD::TRUNCATE, MVT::v8i16, MVT::v2i64, { 2, 1, 1, 1 } }, // PSHUFD+PSHUFLW
3605 { ISD::TRUNCATE, MVT::v4i32, MVT::v2i64, { 1, 1, 1, 1 } }, // PSHUFD
3606 };
3607
3608 static const TypeConversionCostKindTblEntry F16ConversionTbl[] = {
3609 { ISD::FP_ROUND, MVT::f16, MVT::f32, { 1, 1, 1, 1 } },
3610 { ISD::FP_ROUND, MVT::v8f16, MVT::v8f32, { 1, 1, 1, 1 } },
3611 { ISD::FP_ROUND, MVT::v4f16, MVT::v4f32, { 1, 1, 1, 1 } },
3612 { ISD::FP_EXTEND, MVT::f32, MVT::f16, { 1, 1, 1, 1 } },
3613 { ISD::FP_EXTEND, MVT::f64, MVT::f16, { 2, 1, 1, 1 } }, // vcvtph2ps+vcvtps2pd
3614 { ISD::FP_EXTEND, MVT::v8f32, MVT::v8f16, { 1, 1, 1, 1 } },
3615 { ISD::FP_EXTEND, MVT::v4f32, MVT::v4f16, { 1, 1, 1, 1 } },
3616 { ISD::FP_EXTEND, MVT::v4f64, MVT::v4f16, { 2, 1, 1, 1 } }, // vcvtph2ps+vcvtps2pd
3617 };
3618
3619 // Attempt to map directly to (simple) MVT types to let us match custom entries.
3620 EVT SrcTy = TLI->getValueType(DL, Src);
3621 EVT DstTy = TLI->getValueType(DL, Dst);
3622
3623 // If we're sign-extending a vector comparison result back to the comparison
3624 // width, this will be free without AVX512 (or for 8/16-bit types without
3625 // BWI).
3626 if (!ST->hasAVX512() || (!ST->hasBWI() && DstTy.getScalarSizeInBits() < 32)) {
3627 if (I && Opcode == Instruction::CastOps::SExt &&
3628 SrcTy.isFixedLengthVectorOf(MVT::i1)) {
3629 if (auto *CmpI = dyn_cast<CmpInst>(I->getOperand(0))) {
3630 Type *CmpTy = CmpI->getOperand(0)->getType();
3631 if (CmpTy->getScalarSizeInBits() == DstTy.getScalarSizeInBits())
3632 return TTI::TCC_Free;
3633 }
3634 }
3635 }
3636
3637 // The function getSimpleVT only handles simple value types.
3638 if (SrcTy.isSimple() && DstTy.isSimple()) {
3639 MVT SimpleSrcTy = SrcTy.getSimpleVT();
3640 MVT SimpleDstTy = DstTy.getSimpleVT();
3641
3642 if (ST->useAVX512Regs()) {
3643 if (ST->hasBWI())
3644 if (const auto *Entry = ConvertCostTableLookup(
3645 AVX512BWConversionTbl, ISD, SimpleDstTy, SimpleSrcTy))
3646 if (auto KindCost = Entry->Cost[CostKind])
3647 return *KindCost;
3648
3649 if (ST->hasDQI())
3650 if (const auto *Entry = ConvertCostTableLookup(
3651 AVX512DQConversionTbl, ISD, SimpleDstTy, SimpleSrcTy))
3652 if (auto KindCost = Entry->Cost[CostKind])
3653 return *KindCost;
3654
3655 if (ST->hasAVX512())
3656 if (const auto *Entry = ConvertCostTableLookup(
3657 AVX512FConversionTbl, ISD, SimpleDstTy, SimpleSrcTy))
3658 if (auto KindCost = Entry->Cost[CostKind])
3659 return *KindCost;
3660 }
3661
3662 if (ST->hasBWI())
3663 if (const auto *Entry = ConvertCostTableLookup(
3664 AVX512BWVLConversionTbl, ISD, SimpleDstTy, SimpleSrcTy))
3665 if (auto KindCost = Entry->Cost[CostKind])
3666 return *KindCost;
3667
3668 if (ST->hasDQI())
3669 if (const auto *Entry = ConvertCostTableLookup(
3670 AVX512DQVLConversionTbl, ISD, SimpleDstTy, SimpleSrcTy))
3671 if (auto KindCost = Entry->Cost[CostKind])
3672 return *KindCost;
3673
3674 if (ST->hasAVX512())
3675 if (const auto *Entry = ConvertCostTableLookup(AVX512VLConversionTbl, ISD,
3676 SimpleDstTy, SimpleSrcTy))
3677 if (auto KindCost = Entry->Cost[CostKind])
3678 return *KindCost;
3679
3680 if (ST->hasAVX2()) {
3681 if (const auto *Entry = ConvertCostTableLookup(AVX2ConversionTbl, ISD,
3682 SimpleDstTy, SimpleSrcTy))
3683 if (auto KindCost = Entry->Cost[CostKind])
3684 return *KindCost;
3685 }
3686
3687 if (ST->hasAVX()) {
3688 if (const auto *Entry = ConvertCostTableLookup(AVXConversionTbl, ISD,
3689 SimpleDstTy, SimpleSrcTy))
3690 if (auto KindCost = Entry->Cost[CostKind])
3691 return *KindCost;
3692 }
3693
3694 if (ST->hasF16C()) {
3695 if (const auto *Entry = ConvertCostTableLookup(F16ConversionTbl, ISD,
3696 SimpleDstTy, SimpleSrcTy))
3697 if (auto KindCost = Entry->Cost[CostKind])
3698 return *KindCost;
3699 }
3700
3701 if (ST->hasSSE41()) {
3702 if (const auto *Entry = ConvertCostTableLookup(SSE41ConversionTbl, ISD,
3703 SimpleDstTy, SimpleSrcTy))
3704 if (auto KindCost = Entry->Cost[CostKind])
3705 return *KindCost;
3706 }
3707
3708 if (ST->hasSSE2()) {
3709 if (const auto *Entry = ConvertCostTableLookup(SSE2ConversionTbl, ISD,
3710 SimpleDstTy, SimpleSrcTy))
3711 if (auto KindCost = Entry->Cost[CostKind])
3712 return *KindCost;
3713 }
3714
3715 if ((ISD == ISD::FP_ROUND && SimpleDstTy == MVT::f16) ||
3716 (ISD == ISD::FP_EXTEND && SimpleSrcTy == MVT::f16)) {
3717 // fp16 conversions not covered by any table entries require a libcall.
3718 // Return a large (arbitrary) number to model this.
3719 return InstructionCost(64);
3720 }
3721 }
3722
3723 // Fall back to legalized types.
3724 std::pair<InstructionCost, MVT> LTSrc = getTypeLegalizationCost(Src);
3725 std::pair<InstructionCost, MVT> LTDest = getTypeLegalizationCost(Dst);
3726
3727 // If we're truncating to the same legalized type - just assume its free.
3728 if (ISD == ISD::TRUNCATE && LTSrc.second == LTDest.second)
3729 return TTI::TCC_Free;
3730
3731 if (ST->useAVX512Regs()) {
3732 if (ST->hasBWI())
3733 if (const auto *Entry = ConvertCostTableLookup(
3734 AVX512BWConversionTbl, ISD, LTDest.second, LTSrc.second))
3735 if (auto KindCost = Entry->Cost[CostKind])
3736 return std::max(LTSrc.first, LTDest.first) * *KindCost;
3737
3738 if (ST->hasDQI())
3739 if (const auto *Entry = ConvertCostTableLookup(
3740 AVX512DQConversionTbl, ISD, LTDest.second, LTSrc.second))
3741 if (auto KindCost = Entry->Cost[CostKind])
3742 return std::max(LTSrc.first, LTDest.first) * *KindCost;
3743
3744 if (ST->hasAVX512())
3745 if (const auto *Entry = ConvertCostTableLookup(
3746 AVX512FConversionTbl, ISD, LTDest.second, LTSrc.second))
3747 if (auto KindCost = Entry->Cost[CostKind])
3748 return std::max(LTSrc.first, LTDest.first) * *KindCost;
3749 }
3750
3751 if (ST->hasBWI())
3752 if (const auto *Entry = ConvertCostTableLookup(AVX512BWVLConversionTbl, ISD,
3753 LTDest.second, LTSrc.second))
3754 if (auto KindCost = Entry->Cost[CostKind])
3755 return std::max(LTSrc.first, LTDest.first) * *KindCost;
3756
3757 if (ST->hasDQI())
3758 if (const auto *Entry = ConvertCostTableLookup(AVX512DQVLConversionTbl, ISD,
3759 LTDest.second, LTSrc.second))
3760 if (auto KindCost = Entry->Cost[CostKind])
3761 return std::max(LTSrc.first, LTDest.first) * *KindCost;
3762
3763 if (ST->hasAVX512())
3764 if (const auto *Entry = ConvertCostTableLookup(AVX512VLConversionTbl, ISD,
3765 LTDest.second, LTSrc.second))
3766 if (auto KindCost = Entry->Cost[CostKind])
3767 return std::max(LTSrc.first, LTDest.first) * *KindCost;
3768
3769 if (ST->hasAVX2())
3770 if (const auto *Entry = ConvertCostTableLookup(AVX2ConversionTbl, ISD,
3771 LTDest.second, LTSrc.second))
3772 if (auto KindCost = Entry->Cost[CostKind])
3773 return std::max(LTSrc.first, LTDest.first) * *KindCost;
3774
3775 if (ST->hasAVX())
3776 if (const auto *Entry = ConvertCostTableLookup(AVXConversionTbl, ISD,
3777 LTDest.second, LTSrc.second))
3778 if (auto KindCost = Entry->Cost[CostKind])
3779 return std::max(LTSrc.first, LTDest.first) * *KindCost;
3780
3781 if (ST->hasF16C()) {
3782 if (const auto *Entry = ConvertCostTableLookup(F16ConversionTbl, ISD,
3783 LTDest.second, LTSrc.second))
3784 if (auto KindCost = Entry->Cost[CostKind])
3785 return std::max(LTSrc.first, LTDest.first) * *KindCost;
3786 }
3787
3788 if (ST->hasSSE41())
3789 if (const auto *Entry = ConvertCostTableLookup(SSE41ConversionTbl, ISD,
3790 LTDest.second, LTSrc.second))
3791 if (auto KindCost = Entry->Cost[CostKind])
3792 return std::max(LTSrc.first, LTDest.first) * *KindCost;
3793
3794 if (ST->hasSSE2())
3795 if (const auto *Entry = ConvertCostTableLookup(SSE2ConversionTbl, ISD,
3796 LTDest.second, LTSrc.second))
3797 if (auto KindCost = Entry->Cost[CostKind])
3798 return std::max(LTSrc.first, LTDest.first) * *KindCost;
3799
3800 // Fallback, for i8/i16 sitofp/uitofp cases we need to extend to i32 for
3801 // sitofp.
3802 if ((ISD == ISD::SINT_TO_FP || ISD == ISD::UINT_TO_FP) &&
3803 1 < Src->getScalarSizeInBits() && Src->getScalarSizeInBits() < 32) {
3804 Type *ExtSrc = Src->getWithNewBitWidth(32);
3805 unsigned ExtOpc =
3806 (ISD == ISD::SINT_TO_FP) ? Instruction::SExt : Instruction::ZExt;
3807
3808 // For scalar loads the extend would be free.
3809 InstructionCost ExtCost = 0;
3810 if (!(Src->isIntegerTy() && I && isa<LoadInst>(I->getOperand(0))))
3811 ExtCost = getCastInstrCost(ExtOpc, ExtSrc, Src, CCH, CostKind);
3812
3813 return ExtCost + getCastInstrCost(Instruction::SIToFP, Dst, ExtSrc,
3814 TTI::CastContextHint::None, CostKind);
3815 }
3816
3817 // Fallback for fptosi/fptoui i8/i16 cases we need to truncate from fptosi
3818 // i32.
3819 if ((ISD == ISD::FP_TO_SINT || ISD == ISD::FP_TO_UINT) &&
3820 1 < Dst->getScalarSizeInBits() && Dst->getScalarSizeInBits() < 32) {
3821 Type *TruncDst = Dst->getWithNewBitWidth(32);
3822 return getCastInstrCost(Instruction::FPToSI, TruncDst, Src, CCH, CostKind) +
3823 getCastInstrCost(Instruction::Trunc, Dst, TruncDst,
3824 TTI::CastContextHint::None, CostKind);
3825 }
3826
3827 // TODO: Allow non-throughput costs that aren't binary.
3828 auto AdjustCost = [&CostKind](InstructionCost Cost,
3830 if (CostKind != TTI::TCK_RecipThroughput)
3831 return Cost == 0 ? 0 : N;
3832 return Cost * N;
3833 };
3834 return AdjustCost(
3835 BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I));
3836}
3837
3838// Additive cost for a predicated op's "predicate fanout": a select, masked
3839// load/store or gather/scatter keeps a compact <N x i1> mask, but if its data
3840// legalizes into more parts than the mask, codegen builds a sub-mask per extra
3841// part (kshiftr on AVX-512, unpack/extend on SSE/AVX) the per-part tables miss.
3842// FanoutCostPerPart is a tie-break: it beats the vectorizer's widest-VF bias.
3844 Type *DataVTy, Type *MaskVTy) {
3845 constexpr unsigned FanoutCostPerPart = 4;
3846 unsigned DataParts = TTI.getNumberOfParts(DataVTy);
3847 unsigned MaskParts = TTI.getNumberOfParts(MaskVTy);
3848 if (DataParts > MaskParts && MaskParts > 0)
3849 return InstructionCost((DataParts - MaskParts) * FanoutCostPerPart);
3850 return InstructionCost(0);
3851}
3852
3854 unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
3856 TTI::OperandValueInfo Op2Info, const Instruction *I) const {
3857 // Early out if this type isn't scalar/vector integer/float.
3858 if (!(ValTy->isIntOrIntVectorTy() || ValTy->isFPOrFPVectorTy()))
3859 return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,
3860 Op1Info, Op2Info, I);
3861
3862 // Legalize the type.
3863 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(ValTy);
3864
3865 MVT MTy = LT.second;
3866
3867 int ISD = TLI->InstructionOpcodeToISD(Opcode);
3868 assert(ISD && "Invalid opcode");
3869
3870 // Predicate fanout (see getPredicateFanoutCost), AVX-512 only: on SSE/AVX a
3871 // select blend is already priced per part, so charging it there shrinks VF.
3872 InstructionCost MaskExpCost = 0;
3873 if (Opcode == Instruction::Select && ST->hasAVX512() &&
3875 MaskExpCost = getPredicateFanoutCost(*this, ValTy, CondTy);
3876
3877 InstructionCost ExtraCost = 0;
3878 if (Opcode == Instruction::ICmp || Opcode == Instruction::FCmp) {
3879 // Some vector comparison predicates cost extra instructions.
3880 // TODO: Adjust ExtraCost based on CostKind?
3881 // TODO: Should we invert this and assume worst case cmp costs
3882 // and reduce for particular predicates?
3883 if (MTy.isVector() &&
3884 !((ST->hasXOP() && (!ST->hasAVX2() || MTy.is128BitVector())) ||
3885 (ST->hasAVX512() && 32 <= MTy.getScalarSizeInBits()) ||
3886 ST->hasBWI())) {
3887 // Fallback to I if a specific predicate wasn't specified.
3888 CmpInst::Predicate Pred = VecPred;
3889 if (I && (Pred == CmpInst::BAD_ICMP_PREDICATE ||
3891 Pred = cast<CmpInst>(I)->getPredicate();
3892
3893 bool CmpWithConstant = false;
3894 if (auto *CmpInstr = dyn_cast_or_null<CmpInst>(I))
3895 CmpWithConstant = isa<Constant>(CmpInstr->getOperand(1));
3896
3897 switch (Pred) {
3899 // xor(cmpeq(x,y),-1)
3900 ExtraCost = CmpWithConstant ? 0 : 1;
3901 break;
3904 // xor(cmpgt(x,y),-1)
3905 ExtraCost = CmpWithConstant ? 0 : 1;
3906 break;
3909 // cmpgt(xor(x,signbit),xor(y,signbit))
3910 // xor(cmpeq(pmaxu(x,y),x),-1)
3911 ExtraCost = CmpWithConstant ? 1 : 2;
3912 break;
3915 if ((ST->hasSSE41() && MTy.getScalarSizeInBits() == 32) ||
3916 (ST->hasSSE2() && MTy.getScalarSizeInBits() < 32)) {
3917 // cmpeq(psubus(x,y),0)
3918 // cmpeq(pminu(x,y),x)
3919 ExtraCost = 1;
3920 } else {
3921 // xor(cmpgt(xor(x,signbit),xor(y,signbit)),-1)
3922 ExtraCost = CmpWithConstant ? 2 : 3;
3923 }
3924 break;
3927 // Without AVX we need to expand FCMP_ONE/FCMP_UEQ cases.
3928 // Use FCMP_UEQ expansion - FCMP_ONE should be the same.
3929 if (CondTy && !ST->hasAVX())
3930 return getCmpSelInstrCost(Opcode, ValTy, CondTy,
3932 Op1Info, Op2Info) +
3933 getCmpSelInstrCost(Opcode, ValTy, CondTy,
3935 Op1Info, Op2Info) +
3936 getArithmeticInstrCost(Instruction::Or, CondTy, CostKind);
3937
3938 break;
3941 // Assume worst case scenario and add the maximum extra cost.
3942 ExtraCost = 3;
3943 break;
3944 default:
3945 break;
3946 }
3947 }
3948 }
3949
3950 static const CostKindTblEntry SLMCostTbl[] = {
3951 // slm pcmpeq/pcmpgt throughput is 2
3952 { ISD::SETCC, MVT::v2i64, { 2, 5, 1, 2 } },
3953 // slm pblendvb/blendvpd/blendvps throughput is 4
3954 { ISD::SELECT, MVT::v2f64, { 4, 4, 1, 3 } }, // vblendvpd
3955 { ISD::SELECT, MVT::v4f32, { 4, 4, 1, 3 } }, // vblendvps
3956 { ISD::SELECT, MVT::v2i64, { 4, 4, 1, 3 } }, // pblendvb
3957 { ISD::SELECT, MVT::v8i32, { 4, 4, 1, 3 } }, // pblendvb
3958 { ISD::SELECT, MVT::v8i16, { 4, 4, 1, 3 } }, // pblendvb
3959 { ISD::SELECT, MVT::v16i8, { 4, 4, 1, 3 } }, // pblendvb
3960 };
3961
3962 static const CostKindTblEntry AVX512BWCostTbl[] = {
3963 { ISD::SETCC, MVT::v32i16, { 1, 1, 1, 1 } },
3964 { ISD::SETCC, MVT::v16i16, { 1, 1, 1, 1 } },
3965 { ISD::SETCC, MVT::v64i8, { 1, 1, 1, 1 } },
3966 { ISD::SETCC, MVT::v32i8, { 1, 1, 1, 1 } },
3967
3968 { ISD::SELECT, MVT::v32i16, { 1, 1, 1, 1 } },
3969 { ISD::SELECT, MVT::v64i8, { 1, 1, 1, 1 } },
3970 };
3971
3972 static const CostKindTblEntry AVX512CostTbl[] = {
3973 { ISD::SETCC, MVT::v8f64, { 1, 4, 1, 1 } },
3974 { ISD::SETCC, MVT::v4f64, { 1, 4, 1, 1 } },
3975 { ISD::SETCC, MVT::v16f32, { 1, 4, 1, 1 } },
3976 { ISD::SETCC, MVT::v8f32, { 1, 4, 1, 1 } },
3977
3978 { ISD::SETCC, MVT::v8i64, { 1, 1, 1, 1 } },
3979 { ISD::SETCC, MVT::v4i64, { 1, 1, 1, 1 } },
3980 { ISD::SETCC, MVT::v2i64, { 1, 1, 1, 1 } },
3981 { ISD::SETCC, MVT::v16i32, { 1, 1, 1, 1 } },
3982 { ISD::SETCC, MVT::v8i32, { 1, 1, 1, 1 } },
3983 { ISD::SETCC, MVT::v32i16, { 3, 7, 5, 5 } },
3984 { ISD::SETCC, MVT::v64i8, { 3, 7, 5, 5 } },
3985
3986 { ISD::SELECT, MVT::v8i64, { 1, 1, 1, 1 } },
3987 { ISD::SELECT, MVT::v4i64, { 1, 1, 1, 1 } },
3988 { ISD::SELECT, MVT::v2i64, { 1, 1, 1, 1 } },
3989 { ISD::SELECT, MVT::v16i32, { 1, 1, 1, 1 } },
3990 { ISD::SELECT, MVT::v8i32, { 1, 1, 1, 1 } },
3991 { ISD::SELECT, MVT::v4i32, { 1, 1, 1, 1 } },
3992 { ISD::SELECT, MVT::v8f64, { 1, 1, 1, 1 } },
3993 { ISD::SELECT, MVT::v4f64, { 1, 1, 1, 1 } },
3994 { ISD::SELECT, MVT::v2f64, { 1, 1, 1, 1 } },
3995 { ISD::SELECT, MVT::f64, { 1, 1, 1, 1 } },
3996 { ISD::SELECT, MVT::v16f32, { 1, 1, 1, 1 } },
3997 { ISD::SELECT, MVT::v8f32 , { 1, 1, 1, 1 } },
3998 { ISD::SELECT, MVT::v4f32, { 1, 1, 1, 1 } },
3999 { ISD::SELECT, MVT::f32 , { 1, 1, 1, 1 } },
4000
4001 { ISD::SELECT, MVT::v32i16, { 2, 2, 4, 4 } },
4002 { ISD::SELECT, MVT::v16i16, { 1, 1, 1, 1 } },
4003 { ISD::SELECT, MVT::v8i16, { 1, 1, 1, 1 } },
4004 { ISD::SELECT, MVT::v64i8, { 2, 2, 4, 4 } },
4005 { ISD::SELECT, MVT::v32i8, { 1, 1, 1, 1 } },
4006 { ISD::SELECT, MVT::v16i8, { 1, 1, 1, 1 } },
4007 };
4008
4009 static const CostKindTblEntry AVX2CostTbl[] = {
4010 { ISD::SETCC, MVT::v4f64, { 1, 4, 1, 2 } },
4011 { ISD::SETCC, MVT::v2f64, { 1, 4, 1, 1 } },
4012 { ISD::SETCC, MVT::f64, { 1, 4, 1, 1 } },
4013 { ISD::SETCC, MVT::v8f32, { 1, 4, 1, 2 } },
4014 { ISD::SETCC, MVT::v4f32, { 1, 4, 1, 1 } },
4015 { ISD::SETCC, MVT::f32, { 1, 4, 1, 1 } },
4016
4017 { ISD::SETCC, MVT::v4i64, { 1, 1, 1, 2 } },
4018 { ISD::SETCC, MVT::v8i32, { 1, 1, 1, 2 } },
4019 { ISD::SETCC, MVT::v16i16, { 1, 1, 1, 2 } },
4020 { ISD::SETCC, MVT::v32i8, { 1, 1, 1, 2 } },
4021
4022 { ISD::SELECT, MVT::v4f64, { 2, 2, 1, 2 } }, // vblendvpd
4023 { ISD::SELECT, MVT::v8f32, { 2, 2, 1, 2 } }, // vblendvps
4024 { ISD::SELECT, MVT::v4i64, { 2, 2, 1, 2 } }, // pblendvb
4025 { ISD::SELECT, MVT::v8i32, { 2, 2, 1, 2 } }, // pblendvb
4026 { ISD::SELECT, MVT::v16i16, { 2, 2, 1, 2 } }, // pblendvb
4027 { ISD::SELECT, MVT::v32i8, { 2, 2, 1, 2 } }, // pblendvb
4028 };
4029
4030 static const CostKindTblEntry XOPCostTbl[] = {
4031 { ISD::SETCC, MVT::v4i64, { 4, 2, 5, 6 } },
4032 { ISD::SETCC, MVT::v2i64, { 1, 1, 1, 1 } },
4033 };
4034
4035 static const CostKindTblEntry AVX1CostTbl[] = {
4036 { ISD::SETCC, MVT::v4f64, { 2, 3, 1, 2 } },
4037 { ISD::SETCC, MVT::v2f64, { 1, 3, 1, 1 } },
4038 { ISD::SETCC, MVT::f64, { 1, 3, 1, 1 } },
4039 { ISD::SETCC, MVT::v8f32, { 2, 3, 1, 2 } },
4040 { ISD::SETCC, MVT::v4f32, { 1, 3, 1, 1 } },
4041 { ISD::SETCC, MVT::f32, { 1, 3, 1, 1 } },
4042
4043 // AVX1 does not support 8-wide integer compare.
4044 { ISD::SETCC, MVT::v4i64, { 4, 2, 5, 6 } },
4045 { ISD::SETCC, MVT::v8i32, { 4, 2, 5, 6 } },
4046 { ISD::SETCC, MVT::v16i16, { 4, 2, 5, 6 } },
4047 { ISD::SETCC, MVT::v32i8, { 4, 2, 5, 6 } },
4048
4049 { ISD::SELECT, MVT::v4f64, { 3, 3, 1, 2 } }, // vblendvpd
4050 { ISD::SELECT, MVT::v8f32, { 3, 3, 1, 2 } }, // vblendvps
4051 { ISD::SELECT, MVT::v4i64, { 3, 3, 1, 2 } }, // vblendvpd
4052 { ISD::SELECT, MVT::v8i32, { 3, 3, 1, 2 } }, // vblendvps
4053 { ISD::SELECT, MVT::v16i16, { 3, 3, 3, 3 } }, // vandps + vandnps + vorps
4054 { ISD::SELECT, MVT::v32i8, { 3, 3, 3, 3 } }, // vandps + vandnps + vorps
4055 };
4056
4057 static const CostKindTblEntry SSE42CostTbl[] = {
4058 { ISD::SETCC, MVT::v2i64, { 1, 2, 1, 2 } },
4059 };
4060
4061 static const CostKindTblEntry SSE41CostTbl[] = {
4062 { ISD::SETCC, MVT::v2f64, { 1, 5, 1, 1 } },
4063 { ISD::SETCC, MVT::v4f32, { 1, 5, 1, 1 } },
4064
4065 { ISD::SELECT, MVT::v2f64, { 2, 2, 1, 2 } }, // blendvpd
4066 { ISD::SELECT, MVT::f64, { 2, 2, 1, 2 } }, // blendvpd
4067 { ISD::SELECT, MVT::v4f32, { 2, 2, 1, 2 } }, // blendvps
4068 { ISD::SELECT, MVT::f32 , { 2, 2, 1, 2 } }, // blendvps
4069 { ISD::SELECT, MVT::v2i64, { 2, 2, 1, 2 } }, // pblendvb
4070 { ISD::SELECT, MVT::v4i32, { 2, 2, 1, 2 } }, // pblendvb
4071 { ISD::SELECT, MVT::v8i16, { 2, 2, 1, 2 } }, // pblendvb
4072 { ISD::SELECT, MVT::v16i8, { 2, 2, 1, 2 } }, // pblendvb
4073 };
4074
4075 static const CostKindTblEntry SSE2CostTbl[] = {
4076 { ISD::SETCC, MVT::v2f64, { 2, 5, 1, 1 } },
4077 { ISD::SETCC, MVT::f64, { 1, 5, 1, 1 } },
4078
4079 { ISD::SETCC, MVT::v2i64, { 5, 4, 5, 5 } }, // pcmpeqd/pcmpgtd expansion
4080 { ISD::SETCC, MVT::v4i32, { 1, 1, 1, 1 } },
4081 { ISD::SETCC, MVT::v8i16, { 1, 1, 1, 1 } },
4082 { ISD::SETCC, MVT::v16i8, { 1, 1, 1, 1 } },
4083
4084 { ISD::SELECT, MVT::v2f64, { 2, 2, 3, 3 } }, // andpd + andnpd + orpd
4085 { ISD::SELECT, MVT::f64, { 2, 2, 3, 3 } }, // andpd + andnpd + orpd
4086 { ISD::SELECT, MVT::v2i64, { 2, 2, 3, 3 } }, // pand + pandn + por
4087 { ISD::SELECT, MVT::v4i32, { 2, 2, 3, 3 } }, // pand + pandn + por
4088 { ISD::SELECT, MVT::v8i16, { 2, 2, 3, 3 } }, // pand + pandn + por
4089 { ISD::SELECT, MVT::v16i8, { 2, 2, 3, 3 } }, // pand + pandn + por
4090 };
4091
4092 static const CostKindTblEntry SSE1CostTbl[] = {
4093 { ISD::SETCC, MVT::v4f32, { 2, 5, 1, 1 } },
4094 { ISD::SETCC, MVT::f32, { 1, 5, 1, 1 } },
4095
4096 { ISD::SELECT, MVT::v4f32, { 2, 2, 3, 3 } }, // andps + andnps + orps
4097 { ISD::SELECT, MVT::f32, { 2, 2, 3, 3 } }, // andps + andnps + orps
4098 };
4099
4100 if (ST->useSLMArithCosts())
4101 if (const auto *Entry = CostTableLookup(SLMCostTbl, ISD, MTy))
4102 if (auto KindCost = Entry->Cost[CostKind])
4103 return LT.first * (ExtraCost + *KindCost) + MaskExpCost;
4104
4105 if (ST->hasBWI())
4106 if (const auto *Entry = CostTableLookup(AVX512BWCostTbl, ISD, MTy))
4107 if (auto KindCost = Entry->Cost[CostKind])
4108 return LT.first * (ExtraCost + *KindCost) + MaskExpCost;
4109
4110 if (ST->hasAVX512())
4111 if (const auto *Entry = CostTableLookup(AVX512CostTbl, ISD, MTy))
4112 if (auto KindCost = Entry->Cost[CostKind])
4113 return LT.first * (ExtraCost + *KindCost) + MaskExpCost;
4114
4115 if (ST->hasAVX2())
4116 if (const auto *Entry = CostTableLookup(AVX2CostTbl, ISD, MTy))
4117 if (auto KindCost = Entry->Cost[CostKind])
4118 return LT.first * (ExtraCost + *KindCost) + MaskExpCost;
4119
4120 if (ST->hasXOP())
4121 if (const auto *Entry = CostTableLookup(XOPCostTbl, ISD, MTy))
4122 if (auto KindCost = Entry->Cost[CostKind])
4123 return LT.first * (ExtraCost + *KindCost) + MaskExpCost;
4124
4125 if (ST->hasAVX())
4126 if (const auto *Entry = CostTableLookup(AVX1CostTbl, ISD, MTy))
4127 if (auto KindCost = Entry->Cost[CostKind])
4128 return LT.first * (ExtraCost + *KindCost) + MaskExpCost;
4129
4130 if (ST->hasSSE42())
4131 if (const auto *Entry = CostTableLookup(SSE42CostTbl, ISD, MTy))
4132 if (auto KindCost = Entry->Cost[CostKind])
4133 return LT.first * (ExtraCost + *KindCost) + MaskExpCost;
4134
4135 if (ST->hasSSE41())
4136 if (const auto *Entry = CostTableLookup(SSE41CostTbl, ISD, MTy))
4137 if (auto KindCost = Entry->Cost[CostKind])
4138 return LT.first * (ExtraCost + *KindCost) + MaskExpCost;
4139
4140 if (ST->hasSSE2())
4141 if (const auto *Entry = CostTableLookup(SSE2CostTbl, ISD, MTy))
4142 if (auto KindCost = Entry->Cost[CostKind])
4143 return LT.first * (ExtraCost + *KindCost) + MaskExpCost;
4144
4145 if (ST->hasSSE1())
4146 if (const auto *Entry = CostTableLookup(SSE1CostTbl, ISD, MTy))
4147 if (auto KindCost = Entry->Cost[CostKind])
4148 return LT.first * (ExtraCost + *KindCost) + MaskExpCost;
4149
4150 // Assume a 3cy latency for fp select ops.
4151 if (CostKind == TTI::TCK_Latency && Opcode == Instruction::Select)
4152 if (ValTy->getScalarType()->isFloatingPointTy())
4153 return 3;
4154
4155 return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,
4156 Op1Info, Op2Info, I) +
4157 MaskExpCost;
4158}
4159
4161
4162/// Returns true if \p V is the square root, divided into with the reciprocal
4163/// allowed, and the target replaces the pair with the rsqrt* based estimate,
4164/// costed with the division. The estimate is formed for the legalized type
4165/// \p VT.
4167 const X86TargetLowering &TLI, MVT VT,
4168 TTI::TargetCostKind CostKind) {
4169 using namespace PatternMatch;
4170 if (CostKind != TTI::TCK_RecipThroughput && CostKind != TTI::TCK_Latency)
4171 return false;
4173 if (!II || II->getIntrinsicID() != Intrinsic::sqrt || !II->hasOneUse() ||
4174 !match(II->user_back(), m_FDiv(m_Value(), m_Specific(II))) ||
4175 !cast<FPMathOperator>(II->user_back())->hasAllowReciprocal())
4176 return false;
4177 return TLI.hasSqrtEstimate(VT, /*Reciprocal=*/true) &&
4178 TLI.getRecipEstimateSqrtEnabled(VT, *II->getFunction()) !=
4180}
4181
4184 TTI::TargetCostKind CostKind) const {
4185 // Costs should match the codegen from:
4186 // BITREVERSE: llvm\test\CodeGen\X86\vector-bitreverse.ll
4187 // BSWAP: llvm\test\CodeGen\X86\bswap-vector.ll
4188 // CTLZ: llvm\test\CodeGen\X86\vector-lzcnt-*.ll
4189 // CTPOP: llvm\test\CodeGen\X86\vector-popcnt-*.ll
4190 // CTTZ: llvm\test\CodeGen\X86\vector-tzcnt-*.ll
4191
4192 // TODO: Overflow intrinsics (*ADDO, *SUBO, *MULO) with vector types are not
4193 // specialized in these tables yet.
4194 static const CostKindTblEntry AVX512VBMI2CostTbl[] = {
4195 { ISD::FSHL, MVT::v8i64, { 1, 1, 1, 1 } },
4196 { ISD::FSHL, MVT::v4i64, { 1, 1, 1, 1 } },
4197 { ISD::FSHL, MVT::v2i64, { 1, 1, 1, 1 } },
4198 { ISD::FSHL, MVT::v16i32, { 1, 1, 1, 1 } },
4199 { ISD::FSHL, MVT::v8i32, { 1, 1, 1, 1 } },
4200 { ISD::FSHL, MVT::v4i32, { 1, 1, 1, 1 } },
4201 { ISD::FSHL, MVT::v32i16, { 1, 1, 1, 1 } },
4202 { ISD::FSHL, MVT::v16i16, { 1, 1, 1, 1 } },
4203 { ISD::FSHL, MVT::v8i16, { 1, 1, 1, 1 } },
4204 { ISD::ROTL, MVT::v32i16, { 1, 1, 1, 1 } },
4205 { ISD::ROTL, MVT::v16i16, { 1, 1, 1, 1 } },
4206 { ISD::ROTL, MVT::v8i16, { 1, 1, 1, 1 } },
4207 { ISD::ROTR, MVT::v32i16, { 1, 1, 1, 1 } },
4208 { ISD::ROTR, MVT::v16i16, { 1, 1, 1, 1 } },
4209 { ISD::ROTR, MVT::v8i16, { 1, 1, 1, 1 } },
4210 { X86ISD::VROTLI, MVT::v32i16, { 1, 1, 1, 1 } },
4211 { X86ISD::VROTLI, MVT::v16i16, { 1, 1, 1, 1 } },
4212 { X86ISD::VROTLI, MVT::v8i16, { 1, 1, 1, 1 } },
4213 };
4214 static const CostKindTblEntry AVX512BITALGCostTbl[] = {
4215 { ISD::CTPOP, MVT::v32i16, { 1, 1, 1, 1 } },
4216 { ISD::CTPOP, MVT::v64i8, { 1, 1, 1, 1 } },
4217 { ISD::CTPOP, MVT::v16i16, { 1, 1, 1, 1 } },
4218 { ISD::CTPOP, MVT::v32i8, { 1, 1, 1, 1 } },
4219 { ISD::CTPOP, MVT::v8i16, { 1, 1, 1, 1 } },
4220 { ISD::CTPOP, MVT::v16i8, { 1, 1, 1, 1 } },
4221 };
4222 static const CostKindTblEntry AVX512VPOPCNTDQCostTbl[] = {
4223 { ISD::CTPOP, MVT::v8i64, { 1, 1, 1, 1 } },
4224 { ISD::CTPOP, MVT::v16i32, { 1, 1, 1, 1 } },
4225 { ISD::CTPOP, MVT::v4i64, { 1, 1, 1, 1 } },
4226 { ISD::CTPOP, MVT::v8i32, { 1, 1, 1, 1 } },
4227 { ISD::CTPOP, MVT::v2i64, { 1, 1, 1, 1 } },
4228 { ISD::CTPOP, MVT::v4i32, { 1, 1, 1, 1 } },
4229 };
4230 static const CostKindTblEntry AVX512CDCostTbl[] = {
4231 { ISD::CTLZ, MVT::v8i64, { 1, 5, 1, 1 } },
4232 { ISD::CTLZ, MVT::v16i32, { 1, 5, 1, 1 } },
4233 { ISD::CTLZ, MVT::v32i16, { 18, 27, 23, 27 } },
4234 { ISD::CTLZ, MVT::v64i8, { 3, 16, 9, 11 } },
4235 { ISD::CTLZ, MVT::v4i64, { 1, 5, 1, 1 } },
4236 { ISD::CTLZ, MVT::v8i32, { 1, 5, 1, 1 } },
4237 { ISD::CTLZ, MVT::v16i16, { 8, 19, 11, 13 } },
4238 { ISD::CTLZ, MVT::v32i8, { 2, 11, 9, 10 } },
4239 { ISD::CTLZ, MVT::v2i64, { 1, 5, 1, 1 } },
4240 { ISD::CTLZ, MVT::v4i32, { 1, 5, 1, 1 } },
4241 { ISD::CTLZ, MVT::v8i16, { 3, 15, 4, 6 } },
4242 { ISD::CTLZ, MVT::v16i8, { 2, 10, 9, 10 } },
4243
4244 { ISD::CTTZ, MVT::v8i64, { 2, 8, 6, 7 } },
4245 { ISD::CTTZ, MVT::v16i32, { 2, 8, 6, 7 } },
4246 { ISD::CTTZ, MVT::v4i64, { 1, 8, 6, 6 } },
4247 { ISD::CTTZ, MVT::v8i32, { 1, 8, 6, 6 } },
4248 { ISD::CTTZ, MVT::v2i64, { 1, 8, 6, 6 } },
4249 { ISD::CTTZ, MVT::v4i32, { 1, 8, 6, 6 } },
4250 };
4251 static const CostKindTblEntry AVX512BWCostTbl[] = {
4252 { ISD::ABS, MVT::v32i16, { 1, 1, 1, 1 } },
4253 { ISD::ABS, MVT::v64i8, { 1, 1, 1, 1 } },
4254 { ISD::BITREVERSE, MVT::v2i64, { 3, 10, 10, 11 } },
4255 { ISD::BITREVERSE, MVT::v4i64, { 3, 11, 10, 11 } },
4256 { ISD::BITREVERSE, MVT::v8i64, { 3, 12, 10, 14 } },
4257 { ISD::BITREVERSE, MVT::v4i32, { 3, 10, 10, 11 } },
4258 { ISD::BITREVERSE, MVT::v8i32, { 3, 11, 10, 11 } },
4259 { ISD::BITREVERSE, MVT::v16i32, { 3, 12, 10, 14 } },
4260 { ISD::BITREVERSE, MVT::v8i16, { 3, 10, 10, 11 } },
4261 { ISD::BITREVERSE, MVT::v16i16, { 3, 11, 10, 11 } },
4262 { ISD::BITREVERSE, MVT::v32i16, { 3, 12, 10, 14 } },
4263 { ISD::BITREVERSE, MVT::v16i8, { 2, 5, 9, 9 } },
4264 { ISD::BITREVERSE, MVT::v32i8, { 2, 5, 9, 9 } },
4265 { ISD::BITREVERSE, MVT::v64i8, { 2, 5, 9, 12 } },
4266 { ISD::BSWAP, MVT::v2i64, { 1, 1, 1, 2 } },
4267 { ISD::BSWAP, MVT::v4i64, { 1, 1, 1, 2 } },
4268 { ISD::BSWAP, MVT::v8i64, { 1, 1, 1, 2 } },
4269 { ISD::BSWAP, MVT::v4i32, { 1, 1, 1, 2 } },
4270 { ISD::BSWAP, MVT::v8i32, { 1, 1, 1, 2 } },
4271 { ISD::BSWAP, MVT::v16i32, { 1, 1, 1, 2 } },
4272 { ISD::BSWAP, MVT::v8i16, { 1, 1, 1, 2 } },
4273 { ISD::BSWAP, MVT::v16i16, { 1, 1, 1, 2 } },
4274 { ISD::BSWAP, MVT::v32i16, { 1, 1, 1, 2 } },
4275 { ISD::CTLZ, MVT::v8i64, { 8, 22, 23, 23 } },
4276 { ISD::CTLZ, MVT::v16i32, { 8, 23, 25, 25 } },
4277 { ISD::CTLZ, MVT::v32i16, { 4, 15, 15, 16 } },
4278 { ISD::CTLZ, MVT::v64i8, { 3, 12, 10, 9 } },
4279 { ISD::CTPOP, MVT::v2i64, { 3, 7, 10, 10 } },
4280 { ISD::CTPOP, MVT::v4i64, { 3, 7, 10, 10 } },
4281 { ISD::CTPOP, MVT::v8i64, { 3, 8, 10, 12 } },
4282 { ISD::CTPOP, MVT::v4i32, { 7, 11, 14, 14 } },
4283 { ISD::CTPOP, MVT::v8i32, { 7, 11, 14, 14 } },
4284 { ISD::CTPOP, MVT::v16i32, { 7, 12, 14, 16 } },
4285 { ISD::CTPOP, MVT::v8i16, { 2, 7, 11, 11 } },
4286 { ISD::CTPOP, MVT::v16i16, { 2, 7, 11, 11 } },
4287 { ISD::CTPOP, MVT::v32i16, { 3, 7, 11, 13 } },
4288 { ISD::CTPOP, MVT::v16i8, { 2, 4, 8, 8 } },
4289 { ISD::CTPOP, MVT::v32i8, { 2, 4, 8, 8 } },
4290 { ISD::CTPOP, MVT::v64i8, { 2, 5, 8, 10 } },
4291 { ISD::CTTZ, MVT::v8i16, { 3, 9, 14, 14 } },
4292 { ISD::CTTZ, MVT::v16i16, { 3, 9, 14, 14 } },
4293 { ISD::CTTZ, MVT::v32i16, { 3, 10, 14, 16 } },
4294 { ISD::CTTZ, MVT::v16i8, { 2, 6, 11, 11 } },
4295 { ISD::CTTZ, MVT::v32i8, { 2, 6, 11, 11 } },
4296 { ISD::CTTZ, MVT::v64i8, { 3, 7, 11, 13 } },
4297 { ISD::MASK_BEFOREFIRST, MVT::v32i1, { 4, 8, 4, 8 } }, // kmov seq
4298 { ISD::MASK_BEFOREFIRST, MVT::v64i1, { 4, 8, 4, 8 } }, // kmov seq
4299 { ISD::MULHS, MVT::v32i16, { 1, 5, 1, 1 } },
4300 { ISD::MULHU, MVT::v32i16, { 1, 5, 1, 1 } },
4301 { ISD::ROTL, MVT::v32i16, { 2, 8, 6, 8 } },
4302 { ISD::ROTL, MVT::v16i16, { 2, 8, 6, 7 } },
4303 { ISD::ROTL, MVT::v8i16, { 2, 7, 6, 7 } },
4304 { ISD::ROTL, MVT::v64i8, { 5, 6, 11, 12 } },
4305 { ISD::ROTL, MVT::v32i8, { 5, 15, 7, 10 } },
4306 { ISD::ROTL, MVT::v16i8, { 5, 15, 7, 10 } },
4307 { ISD::ROTR, MVT::v32i16, { 2, 8, 6, 8 } },
4308 { ISD::ROTR, MVT::v16i16, { 2, 8, 6, 7 } },
4309 { ISD::ROTR, MVT::v8i16, { 2, 7, 6, 7 } },
4310 { ISD::ROTR, MVT::v64i8, { 5, 6, 12, 14 } },
4311 { ISD::ROTR, MVT::v32i8, { 5, 14, 6, 9 } },
4312 { ISD::ROTR, MVT::v16i8, { 5, 14, 6, 9 } },
4313 { X86ISD::VROTLI, MVT::v32i16, { 2, 5, 3, 3 } },
4314 { X86ISD::VROTLI, MVT::v16i16, { 1, 5, 3, 3 } },
4315 { X86ISD::VROTLI, MVT::v8i16, { 1, 5, 3, 3 } },
4316 { X86ISD::VROTLI, MVT::v64i8, { 2, 9, 3, 4 } },
4317 { X86ISD::VROTLI, MVT::v32i8, { 1, 9, 3, 4 } },
4318 { X86ISD::VROTLI, MVT::v16i8, { 1, 8, 3, 4 } },
4319 { ISD::SADDSAT, MVT::v32i16, { 1, 1, 1, 1 } },
4320 { ISD::SADDSAT, MVT::v64i8, { 1, 1, 1, 1 } },
4321 { ISD::SMAX, MVT::v32i16, { 1, 1, 1, 1 } },
4322 { ISD::SMAX, MVT::v64i8, { 1, 1, 1, 1 } },
4323 { ISD::SMIN, MVT::v32i16, { 1, 1, 1, 1 } },
4324 { ISD::SMIN, MVT::v64i8, { 1, 1, 1, 1 } },
4325 { ISD::SMULO, MVT::v32i16, { 3, 6, 4, 4 } },
4326 { ISD::SMULO, MVT::v64i8, { 8, 21, 17, 18 } },
4327 { ISD::UMULO, MVT::v32i16, { 2, 5, 3, 3 } },
4328 { ISD::UMULO, MVT::v64i8, { 8, 15, 15, 16 } },
4329 { ISD::SSUBSAT, MVT::v32i16, { 1, 1, 1, 1 } },
4330 { ISD::SSUBSAT, MVT::v64i8, { 1, 1, 1, 1 } },
4331 { ISD::UADDSAT, MVT::v32i16, { 1, 1, 1, 1 } },
4332 { ISD::UADDSAT, MVT::v64i8, { 1, 1, 1, 1 } },
4333 { ISD::UMAX, MVT::v32i16, { 1, 1, 1, 1 } },
4334 { ISD::UMAX, MVT::v64i8, { 1, 1, 1, 1 } },
4335 { ISD::UMIN, MVT::v32i16, { 1, 1, 1, 1 } },
4336 { ISD::UMIN, MVT::v64i8, { 1, 1, 1, 1 } },
4337 { ISD::USUBSAT, MVT::v32i16, { 1, 1, 1, 1 } },
4338 { ISD::USUBSAT, MVT::v64i8, { 1, 1, 1, 1 } },
4339 };
4340 static const CostKindTblEntry AVX512CostTbl[] = {
4341 { ISD::ABS, MVT::v8i64, { 1, 1, 1, 1 } },
4342 { ISD::ABS, MVT::v4i64, { 1, 1, 1, 1 } },
4343 { ISD::ABS, MVT::v2i64, { 1, 1, 1, 1 } },
4344 { ISD::ABS, MVT::v16i32, { 1, 1, 1, 1 } },
4345 { ISD::ABS, MVT::v8i32, { 1, 1, 1, 1 } },
4346 { ISD::ABS, MVT::v32i16, { 2, 7, 4, 4 } },
4347 { ISD::ABS, MVT::v16i16, { 1, 1, 1, 1 } },
4348 { ISD::ABS, MVT::v64i8, { 2, 7, 4, 4 } },
4349 { ISD::ABS, MVT::v32i8, { 1, 1, 1, 1 } },
4350 { ISD::BITREVERSE, MVT::v8i64, { 9, 13, 20, 20 } },
4351 { ISD::BITREVERSE, MVT::v16i32, { 9, 13, 20, 20 } },
4352 { ISD::BITREVERSE, MVT::v32i16, { 9, 13, 20, 20 } },
4353 { ISD::BITREVERSE, MVT::v64i8, { 6, 11, 17, 17 } },
4354 { ISD::BSWAP, MVT::v8i64, { 4, 7, 5, 5 } },
4355 { ISD::BSWAP, MVT::v16i32, { 4, 7, 5, 5 } },
4356 { ISD::BSWAP, MVT::v32i16, { 4, 7, 5, 5 } },
4357 { ISD::CTLZ, MVT::v8i64, { 10, 28, 32, 32 } },
4358 { ISD::CTLZ, MVT::v16i32, { 12, 30, 38, 38 } },
4359 { ISD::CTLZ, MVT::v32i16, { 8, 15, 29, 29 } },
4360 { ISD::CTLZ, MVT::v64i8, { 6, 11, 19, 19 } },
4361 { ISD::CTPOP, MVT::v8i64, { 16, 16, 19, 19 } },
4362 { ISD::CTPOP, MVT::v16i32, { 24, 19, 27, 27 } },
4363 { ISD::CTPOP, MVT::v32i16, { 18, 15, 22, 22 } },
4364 { ISD::CTPOP, MVT::v64i8, { 12, 11, 16, 16 } },
4365 { ISD::CTTZ, MVT::v8i64, { 2, 8, 6, 7 } },
4366 { ISD::CTTZ, MVT::v16i32, { 2, 8, 6, 7 } },
4367 { ISD::CTTZ, MVT::v32i16, { 7, 17, 27, 27 } },
4368 { ISD::CTTZ, MVT::v64i8, { 6, 13, 21, 21 } },
4369 { ISD::MASK_BEFOREFIRST, MVT::v2i1, { 4, 8, 4, 8 } }, // kmov seq
4370 { ISD::MASK_BEFOREFIRST, MVT::v4i1, { 4, 8, 4, 8 } }, // kmov seq
4371 { ISD::MASK_BEFOREFIRST, MVT::v8i1, { 4, 8, 4, 8 } }, // kmov seq
4372 { ISD::MASK_BEFOREFIRST, MVT::v16i1, { 4, 8, 4, 8 } }, // kmov seq
4373 { ISD::MULHS, MVT::v16i32, { 3, 10, 6, 7 } },
4374 { ISD::MULHS, MVT::v8i32, { 3, 9, 6, 6 } },
4375 { ISD::MULHS, MVT::v32i16, { 3, 7, 5, 5 } },
4376 { ISD::MULHS, MVT::v16i16, { 1, 5, 1, 1 } },
4377 { ISD::MULHU, MVT::v16i32, { 3, 10, 6, 7 } },
4378 { ISD::MULHU, MVT::v8i32, { 3, 9, 6, 6 } },
4379 { ISD::MULHU, MVT::v32i16, { 3, 7, 5, 5 } },
4380 { ISD::MULHU, MVT::v16i16, { 1, 5, 1, 1 } },
4381 { ISD::ROTL, MVT::v8i64, { 1, 1, 1, 1 } },
4382 { ISD::ROTL, MVT::v4i64, { 1, 1, 1, 1 } },
4383 { ISD::ROTL, MVT::v2i64, { 1, 1, 1, 1 } },
4384 { ISD::ROTL, MVT::v16i32, { 1, 1, 1, 1 } },
4385 { ISD::ROTL, MVT::v8i32, { 1, 1, 1, 1 } },
4386 { ISD::ROTL, MVT::v4i32, { 1, 1, 1, 1 } },
4387 { ISD::ROTR, MVT::v8i64, { 1, 1, 1, 1 } },
4388 { ISD::ROTR, MVT::v4i64, { 1, 1, 1, 1 } },
4389 { ISD::ROTR, MVT::v2i64, { 1, 1, 1, 1 } },
4390 { ISD::ROTR, MVT::v16i32, { 1, 1, 1, 1 } },
4391 { ISD::ROTR, MVT::v8i32, { 1, 1, 1, 1 } },
4392 { ISD::ROTR, MVT::v4i32, { 1, 1, 1, 1 } },
4393 { X86ISD::VROTLI, MVT::v8i64, { 1, 1, 1, 1 } },
4394 { X86ISD::VROTLI, MVT::v4i64, { 1, 1, 1, 1 } },
4395 { X86ISD::VROTLI, MVT::v2i64, { 1, 1, 1, 1 } },
4396 { X86ISD::VROTLI, MVT::v16i32, { 1, 1, 1, 1 } },
4397 { X86ISD::VROTLI, MVT::v8i32, { 1, 1, 1, 1 } },
4398 { X86ISD::VROTLI, MVT::v4i32, { 1, 1, 1, 1 } },
4399 { ISD::SADDSAT, MVT::v2i64, { 3, 3, 8, 9 } },
4400 { ISD::SADDSAT, MVT::v4i64, { 2, 2, 6, 7 } },
4401 { ISD::SADDSAT, MVT::v8i64, { 3, 3, 6, 7 } },
4402 { ISD::SADDSAT, MVT::v4i32, { 2, 2, 6, 7 } },
4403 { ISD::SADDSAT, MVT::v8i32, { 2, 2, 6, 7 } },
4404 { ISD::SADDSAT, MVT::v16i32, { 3, 3, 6, 7 } },
4405 { ISD::SADDSAT, MVT::v32i16, { 2, 2, 2, 2 } },
4406 { ISD::SADDSAT, MVT::v64i8, { 2, 2, 2, 2 } },
4407 { ISD::SMAX, MVT::v8i64, { 1, 3, 1, 1 } },
4408 { ISD::SMAX, MVT::v16i32, { 1, 1, 1, 1 } },
4409 { ISD::SMAX, MVT::v32i16, { 3, 7, 5, 5 } },
4410 { ISD::SMAX, MVT::v64i8, { 3, 7, 5, 5 } },
4411 { ISD::SMAX, MVT::v4i64, { 1, 3, 1, 1 } },
4412 { ISD::SMAX, MVT::v2i64, { 1, 3, 1, 1 } },
4413 { ISD::SMIN, MVT::v8i64, { 1, 3, 1, 1 } },
4414 { ISD::SMIN, MVT::v16i32, { 1, 1, 1, 1 } },
4415 { ISD::SMIN, MVT::v32i16, { 3, 7, 5, 5 } },
4416 { ISD::SMIN, MVT::v64i8, { 3, 7, 5, 5 } },
4417 { ISD::SMIN, MVT::v4i64, { 1, 3, 1, 1 } },
4418 { ISD::SMIN, MVT::v2i64, { 1, 3, 1, 1 } },
4419 { ISD::SMULO, MVT::v8i64, { 44, 44, 81, 93 } },
4420 { ISD::SMULO, MVT::v16i32, { 5, 12, 9, 11 } },
4421 { ISD::SMULO, MVT::v32i16, { 6, 12, 17, 17 } },
4422 { ISD::SMULO, MVT::v64i8, { 22, 28, 42, 42 } },
4423 { ISD::SSUBSAT, MVT::v2i64, { 2, 13, 9, 10 } },
4424 { ISD::SSUBSAT, MVT::v4i64, { 2, 15, 7, 8 } },
4425 { ISD::SSUBSAT, MVT::v8i64, { 2, 14, 7, 8 } },
4426 { ISD::SSUBSAT, MVT::v4i32, { 2, 14, 7, 8 } },
4427 { ISD::SSUBSAT, MVT::v8i32, { 2, 15, 7, 8 } },
4428 { ISD::SSUBSAT, MVT::v16i32, { 2, 14, 7, 8 } },
4429 { ISD::SSUBSAT, MVT::v32i16, { 2, 2, 2, 2 } },
4430 { ISD::SSUBSAT, MVT::v64i8, { 2, 2, 2, 2 } },
4431 { ISD::UMAX, MVT::v8i64, { 1, 3, 1, 1 } },
4432 { ISD::UMAX, MVT::v16i32, { 1, 1, 1, 1 } },
4433 { ISD::UMAX, MVT::v32i16, { 3, 7, 5, 5 } },
4434 { ISD::UMAX, MVT::v64i8, { 3, 7, 5, 5 } },
4435 { ISD::UMAX, MVT::v4i64, { 1, 3, 1, 1 } },
4436 { ISD::UMAX, MVT::v2i64, { 1, 3, 1, 1 } },
4437 { ISD::UMIN, MVT::v8i64, { 1, 3, 1, 1 } },
4438 { ISD::UMIN, MVT::v16i32, { 1, 1, 1, 1 } },
4439 { ISD::UMIN, MVT::v32i16, { 3, 7, 5, 5 } },
4440 { ISD::UMIN, MVT::v64i8, { 3, 7, 5, 5 } },
4441 { ISD::UMIN, MVT::v4i64, { 1, 3, 1, 1 } },
4442 { ISD::UMIN, MVT::v2i64, { 1, 3, 1, 1 } },
4443 { ISD::UMULO, MVT::v8i64, { 52, 52, 95, 104} },
4444 { ISD::UMULO, MVT::v16i32, { 5, 12, 8, 10 } },
4445 { ISD::UMULO, MVT::v32i16, { 5, 13, 16, 16 } },
4446 { ISD::UMULO, MVT::v64i8, { 18, 24, 30, 30 } },
4447 { ISD::UADDSAT, MVT::v2i64, { 1, 4, 4, 4 } },
4448 { ISD::UADDSAT, MVT::v4i64, { 1, 4, 4, 4 } },
4449 { ISD::UADDSAT, MVT::v8i64, { 1, 4, 4, 4 } },
4450 { ISD::UADDSAT, MVT::v4i32, { 1, 2, 4, 4 } },
4451 { ISD::UADDSAT, MVT::v8i32, { 1, 2, 4, 4 } },
4452 { ISD::UADDSAT, MVT::v16i32, { 2, 2, 4, 4 } },
4453 { ISD::UADDSAT, MVT::v32i16, { 2, 2, 2, 2 } },
4454 { ISD::UADDSAT, MVT::v64i8, { 2, 2, 2, 2 } },
4455 { ISD::USUBSAT, MVT::v2i64, { 1, 4, 2, 2 } },
4456 { ISD::USUBSAT, MVT::v4i64, { 1, 4, 2, 2 } },
4457 { ISD::USUBSAT, MVT::v8i64, { 1, 4, 2, 2 } },
4458 { ISD::USUBSAT, MVT::v8i32, { 1, 2, 2, 2 } },
4459 { ISD::USUBSAT, MVT::v16i32, { 1, 2, 2, 2 } },
4460 { ISD::USUBSAT, MVT::v32i16, { 2, 2, 2, 2 } },
4461 { ISD::USUBSAT, MVT::v64i8, { 2, 2, 2, 2 } },
4462 { ISD::FMAXNUM, MVT::f32, { 2, 2, 3, 3 } },
4463 { ISD::FMAXNUM, MVT::v4f32, { 1, 1, 3, 3 } },
4464 { ISD::FMAXNUM, MVT::v8f32, { 2, 2, 3, 3 } },
4465 { ISD::FMAXNUM, MVT::v16f32, { 4, 4, 3, 3 } },
4466 { ISD::FMAXNUM, MVT::f64, { 2, 2, 3, 3 } },
4467 { ISD::FMAXNUM, MVT::v2f64, { 1, 1, 3, 3 } },
4468 { ISD::FMAXNUM, MVT::v4f64, { 2, 2, 3, 3 } },
4469 { ISD::FMAXNUM, MVT::v8f64, { 3, 3, 3, 3 } },
4470 { ISD::FSQRT, MVT::f32, { 3, 12, 1, 1 } }, // Skylake from http://www.agner.org/
4471 { ISD::FSQRT, MVT::v4f32, { 3, 12, 1, 1 } }, // Skylake from http://www.agner.org/
4472 { ISD::FSQRT, MVT::v8f32, { 6, 12, 1, 1 } }, // Skylake from http://www.agner.org/
4473 { ISD::FSQRT, MVT::v16f32, { 12, 20, 1, 3 } }, // Skylake from http://www.agner.org/
4474 { ISD::FSQRT, MVT::f64, { 6, 18, 1, 1 } }, // Skylake from http://www.agner.org/
4475 { ISD::FSQRT, MVT::v2f64, { 6, 18, 1, 1 } }, // Skylake from http://www.agner.org/
4476 { ISD::FSQRT, MVT::v4f64, { 12, 18, 1, 1 } }, // Skylake from http://www.agner.org/
4477 { ISD::FSQRT, MVT::v8f64, { 24, 32, 1, 3 } }, // Skylake from http://www.agner.org/
4478 };
4479 static const CostKindTblEntry XOPCostTbl[] = {
4480 { ISD::BITREVERSE, MVT::v4i64, { 3, 6, 5, 6 } },
4481 { ISD::BITREVERSE, MVT::v8i32, { 3, 6, 5, 6 } },
4482 { ISD::BITREVERSE, MVT::v16i16, { 3, 6, 5, 6 } },
4483 { ISD::BITREVERSE, MVT::v32i8, { 3, 6, 5, 6 } },
4484 { ISD::BITREVERSE, MVT::v2i64, { 2, 7, 1, 1 } },
4485 { ISD::BITREVERSE, MVT::v4i32, { 2, 7, 1, 1 } },
4486 { ISD::BITREVERSE, MVT::v8i16, { 2, 7, 1, 1 } },
4487 { ISD::BITREVERSE, MVT::v16i8, { 2, 7, 1, 1 } },
4488 { ISD::BITREVERSE, MVT::i64, { 2, 2, 3, 4 } },
4489 { ISD::BITREVERSE, MVT::i32, { 2, 2, 3, 4 } },
4490 { ISD::BITREVERSE, MVT::i16, { 2, 2, 3, 4 } },
4491 { ISD::BITREVERSE, MVT::i8, { 2, 2, 3, 4 } },
4492 // XOP: ROTL = VPROT(X,Y), ROTR = VPROT(X,SUB(0,Y))
4493 { ISD::ROTL, MVT::v4i64, { 4, 7, 5, 6 } },
4494 { ISD::ROTL, MVT::v8i32, { 4, 7, 5, 6 } },
4495 { ISD::ROTL, MVT::v16i16, { 4, 7, 5, 6 } },
4496 { ISD::ROTL, MVT::v32i8, { 4, 7, 5, 6 } },
4497 { ISD::ROTL, MVT::v2i64, { 1, 3, 1, 1 } },
4498 { ISD::ROTL, MVT::v4i32, { 1, 3, 1, 1 } },
4499 { ISD::ROTL, MVT::v8i16, { 1, 3, 1, 1 } },
4500 { ISD::ROTL, MVT::v16i8, { 1, 3, 1, 1 } },
4501 { ISD::ROTR, MVT::v4i64, { 4, 7, 8, 9 } },
4502 { ISD::ROTR, MVT::v8i32, { 4, 7, 8, 9 } },
4503 { ISD::ROTR, MVT::v16i16, { 4, 7, 8, 9 } },
4504 { ISD::ROTR, MVT::v32i8, { 4, 7, 8, 9 } },
4505 { ISD::ROTR, MVT::v2i64, { 1, 3, 3, 3 } },
4506 { ISD::ROTR, MVT::v4i32, { 1, 3, 3, 3 } },
4507 { ISD::ROTR, MVT::v8i16, { 1, 3, 3, 3 } },
4508 { ISD::ROTR, MVT::v16i8, { 1, 3, 3, 3 } },
4509 { X86ISD::VROTLI, MVT::v4i64, { 4, 7, 5, 6 } },
4510 { X86ISD::VROTLI, MVT::v8i32, { 4, 7, 5, 6 } },
4511 { X86ISD::VROTLI, MVT::v16i16, { 4, 7, 5, 6 } },
4512 { X86ISD::VROTLI, MVT::v32i8, { 4, 7, 5, 6 } },
4513 { X86ISD::VROTLI, MVT::v2i64, { 1, 3, 1, 1 } },
4514 { X86ISD::VROTLI, MVT::v4i32, { 1, 3, 1, 1 } },
4515 { X86ISD::VROTLI, MVT::v8i16, { 1, 3, 1, 1 } },
4516 { X86ISD::VROTLI, MVT::v16i8, { 1, 3, 1, 1 } },
4517 };
4518 static const CostKindTblEntry AVX2CostTbl[] = {
4519 { ISD::ABS, MVT::v2i64, { 2, 4, 3, 5 } }, // VBLENDVPD(X,VPSUBQ(0,X),X)
4520 { ISD::ABS, MVT::v4i64, { 2, 4, 3, 5 } }, // VBLENDVPD(X,VPSUBQ(0,X),X)
4521 { ISD::ABS, MVT::v4i32, { 1, 1, 1, 1 } },
4522 { ISD::ABS, MVT::v8i32, { 1, 1, 1, 2 } },
4523 { ISD::ABS, MVT::v8i16, { 1, 1, 1, 1 } },
4524 { ISD::ABS, MVT::v16i16, { 1, 1, 1, 2 } },
4525 { ISD::ABS, MVT::v16i8, { 1, 1, 1, 1 } },
4526 { ISD::ABS, MVT::v32i8, { 1, 1, 1, 2 } },
4527 { ISD::BITREVERSE, MVT::v2i64, { 3, 11, 10, 11 } },
4528 { ISD::BITREVERSE, MVT::v4i64, { 5, 11, 10, 17 } },
4529 { ISD::BITREVERSE, MVT::v4i32, { 3, 11, 10, 11 } },
4530 { ISD::BITREVERSE, MVT::v8i32, { 5, 11, 10, 17 } },
4531 { ISD::BITREVERSE, MVT::v8i16, { 3, 11, 10, 11 } },
4532 { ISD::BITREVERSE, MVT::v16i16, { 5, 11, 10, 17 } },
4533 { ISD::BITREVERSE, MVT::v16i8, { 3, 6, 9, 9 } },
4534 { ISD::BITREVERSE, MVT::v32i8, { 4, 5, 9, 15 } },
4535 { ISD::BSWAP, MVT::v2i64, { 1, 2, 1, 2 } },
4536 { ISD::BSWAP, MVT::v4i64, { 1, 3, 1, 2 } },
4537 { ISD::BSWAP, MVT::v4i32, { 1, 2, 1, 2 } },
4538 { ISD::BSWAP, MVT::v8i32, { 1, 3, 1, 2 } },
4539 { ISD::BSWAP, MVT::v8i16, { 1, 2, 1, 2 } },
4540 { ISD::BSWAP, MVT::v16i16, { 1, 3, 1, 2 } },
4541 { ISD::CTLZ, MVT::v2i64, { 7, 18, 24, 25 } },
4542 { ISD::CTLZ, MVT::v4i64, { 14, 18, 24, 44 } },
4543 { ISD::CTLZ, MVT::v4i32, { 5, 16, 19, 20 } },
4544 { ISD::CTLZ, MVT::v8i32, { 10, 16, 19, 34 } },
4545 { ISD::CTLZ, MVT::v8i16, { 4, 13, 14, 15 } },
4546 { ISD::CTLZ, MVT::v16i16, { 6, 14, 14, 24 } },
4547 { ISD::CTLZ, MVT::v16i8, { 3, 12, 9, 10 } },
4548 { ISD::CTLZ, MVT::v32i8, { 4, 12, 9, 14 } },
4549 { ISD::CTPOP, MVT::v2i64, { 3, 9, 10, 10 } },
4550 { ISD::CTPOP, MVT::v4i64, { 4, 9, 10, 14 } },
4551 { ISD::CTPOP, MVT::v4i32, { 7, 12, 14, 14 } },
4552 { ISD::CTPOP, MVT::v8i32, { 7, 12, 14, 18 } },
4553 { ISD::CTPOP, MVT::v8i16, { 3, 7, 11, 11 } },
4554 { ISD::CTPOP, MVT::v16i16, { 6, 8, 11, 18 } },
4555 { ISD::CTPOP, MVT::v16i8, { 2, 5, 8, 8 } },
4556 { ISD::CTPOP, MVT::v32i8, { 3, 5, 8, 12 } },
4557 { ISD::CTTZ, MVT::v2i64, { 4, 11, 13, 13 } },
4558 { ISD::CTTZ, MVT::v4i64, { 5, 11, 13, 20 } },
4559 { ISD::CTTZ, MVT::v4i32, { 7, 14, 17, 17 } },
4560 { ISD::CTTZ, MVT::v8i32, { 7, 15, 17, 24 } },
4561 { ISD::CTTZ, MVT::v8i16, { 4, 9, 14, 14 } },
4562 { ISD::CTTZ, MVT::v16i16, { 6, 9, 14, 24 } },
4563 { ISD::CTTZ, MVT::v16i8, { 3, 7, 11, 11 } },
4564 { ISD::CTTZ, MVT::v32i8, { 5, 7, 11, 18 } },
4565 { ISD::MASK_BEFOREFIRST, MVT::v2i64, { 7, 13, 8, 13 } }, // movmsk seq
4566 { ISD::MASK_BEFOREFIRST, MVT::v4i32, { 7, 13, 8, 13 } }, // movmsk seq
4567 { ISD::MASK_BEFOREFIRST, MVT::v8i16, { 8, 14, 9, 14 } }, // movmsk seq
4568 { ISD::MASK_BEFOREFIRST, MVT::v16i8, { 7, 11, 8, 11 } }, // movmsk seq
4569 { ISD::MASK_BEFOREFIRST, MVT::v32i8, { 8, 14, 9, 14 } }, // movmsk seq
4570 { ISD::MULHS, MVT::v8i32, { 4, 9, 6, 12 } },
4571 { ISD::MULHS, MVT::v16i16, { 2, 5, 1, 2 } },
4572 { ISD::MULHU, MVT::v8i32, { 4, 9, 6, 12 } },
4573 { ISD::MULHU, MVT::v16i16, { 2, 5, 1, 2 } },
4574 { ISD::SADDSAT, MVT::v2i64, { 4, 13, 8, 11 } },
4575 { ISD::SADDSAT, MVT::v4i64, { 3, 10, 8, 12 } },
4576 { ISD::SADDSAT, MVT::v4i32, { 2, 6, 7, 9 } },
4577 { ISD::SADDSAT, MVT::v8i32, { 4, 6, 7, 13 } },
4578 { ISD::SADDSAT, MVT::v16i16, { 1, 1, 1, 2 } },
4579 { ISD::SADDSAT, MVT::v32i8, { 1, 1, 1, 2 } },
4580 { ISD::SMAX, MVT::v2i64, { 2, 7, 2, 3 } },
4581 { ISD::SMAX, MVT::v4i64, { 2, 7, 2, 3 } },
4582 { ISD::SMAX, MVT::v8i32, { 1, 1, 1, 2 } },
4583 { ISD::SMAX, MVT::v16i16, { 1, 1, 1, 2 } },
4584 { ISD::SMAX, MVT::v32i8, { 1, 1, 1, 2 } },
4585 { ISD::SMIN, MVT::v2i64, { 2, 7, 2, 3 } },
4586 { ISD::SMIN, MVT::v4i64, { 2, 7, 2, 3 } },
4587 { ISD::SMIN, MVT::v8i32, { 1, 1, 1, 2 } },
4588 { ISD::SMIN, MVT::v16i16, { 1, 1, 1, 2 } },
4589 { ISD::SMIN, MVT::v32i8, { 1, 1, 1, 2 } },
4590 { ISD::SMULO, MVT::v4i64, { 20, 20, 33, 37 } },
4591 { ISD::SMULO, MVT::v2i64, { 8, 8, 13, 15 } },
4592 { ISD::SMULO, MVT::v8i32, { 8, 20, 13, 24 } },
4593 { ISD::SMULO, MVT::v4i32, { 5, 15, 11, 12 } },
4594 { ISD::SMULO, MVT::v16i16, { 4, 14, 8, 14 } },
4595 { ISD::SMULO, MVT::v8i16, { 3, 9, 6, 6 } },
4596 { ISD::SMULO, MVT::v32i8, { 9, 15, 18, 35 } },
4597 { ISD::SMULO, MVT::v16i8, { 6, 22, 14, 21 } },
4598 { ISD::SSUBSAT, MVT::v2i64, { 4, 13, 9, 13 } },
4599 { ISD::SSUBSAT, MVT::v4i64, { 4, 15, 9, 13 } },
4600 { ISD::SSUBSAT, MVT::v4i32, { 3, 14, 9, 11 } },
4601 { ISD::SSUBSAT, MVT::v8i32, { 4, 15, 9, 16 } },
4602 { ISD::SSUBSAT, MVT::v16i16, { 1, 1, 1, 2 } },
4603 { ISD::SSUBSAT, MVT::v32i8, { 1, 1, 1, 2 } },
4604 { ISD::UADDSAT, MVT::v2i64, { 2, 8, 6, 6 } },
4605 { ISD::UADDSAT, MVT::v4i64, { 3, 8, 6, 10 } },
4606 { ISD::UADDSAT, MVT::v8i32, { 2, 2, 4, 8 } },
4607 { ISD::UADDSAT, MVT::v16i16, { 1, 1, 1, 2 } },
4608 { ISD::UADDSAT, MVT::v32i8, { 1, 1, 1, 2 } },
4609 { ISD::UMAX, MVT::v2i64, { 2, 8, 5, 6 } },
4610 { ISD::UMAX, MVT::v4i64, { 2, 8, 5, 8 } },
4611 { ISD::UMAX, MVT::v8i32, { 1, 1, 1, 2 } },
4612 { ISD::UMAX, MVT::v16i16, { 1, 1, 1, 2 } },
4613 { ISD::UMAX, MVT::v32i8, { 1, 1, 1, 2 } },
4614 { ISD::UMIN, MVT::v2i64, { 2, 8, 5, 6 } },
4615 { ISD::UMIN, MVT::v4i64, { 2, 8, 5, 8 } },
4616 { ISD::UMIN, MVT::v8i32, { 1, 1, 1, 2 } },
4617 { ISD::UMIN, MVT::v16i16, { 1, 1, 1, 2 } },
4618 { ISD::UMIN, MVT::v32i8, { 1, 1, 1, 2 } },
4619 { ISD::UMULO, MVT::v4i64, { 24, 24, 39, 43 } },
4620 { ISD::UMULO, MVT::v2i64, { 10, 10, 15, 19 } },
4621 { ISD::UMULO, MVT::v8i32, { 8, 11, 13, 23 } },
4622 { ISD::UMULO, MVT::v4i32, { 5, 12, 11, 12 } },
4623 { ISD::UMULO, MVT::v16i16, { 4, 6, 8, 13 } },
4624 { ISD::UMULO, MVT::v8i16, { 2, 8, 6, 6 } },
4625 { ISD::UMULO, MVT::v32i8, { 9, 13, 17, 33 } },
4626 { ISD::UMULO, MVT::v16i8, { 6, 19, 13, 20 } },
4627 { ISD::USUBSAT, MVT::v2i64, { 2, 7, 6, 6 } },
4628 { ISD::USUBSAT, MVT::v4i64, { 3, 7, 6, 10 } },
4629 { ISD::USUBSAT, MVT::v8i32, { 2, 2, 2, 4 } },
4630 { ISD::USUBSAT, MVT::v16i16, { 1, 1, 1, 2 } },
4631 { ISD::USUBSAT, MVT::v32i8, { 1, 1, 1, 2 } },
4632 { ISD::FMAXNUM, MVT::f32, { 2, 7, 3, 5 } }, // MAXSS + CMPUNORDSS + BLENDVPS
4633 { ISD::FMAXNUM, MVT::v4f32, { 2, 7, 3, 5 } }, // MAXPS + CMPUNORDPS + BLENDVPS
4634 { ISD::FMAXNUM, MVT::v8f32, { 3, 7, 3, 6 } }, // MAXPS + CMPUNORDPS + BLENDVPS
4635 { ISD::FMAXNUM, MVT::f64, { 2, 7, 3, 5 } }, // MAXSD + CMPUNORDSD + BLENDVPD
4636 { ISD::FMAXNUM, MVT::v2f64, { 2, 7, 3, 5 } }, // MAXPD + CMPUNORDPD + BLENDVPD
4637 { ISD::FMAXNUM, MVT::v4f64, { 3, 7, 3, 6 } }, // MAXPD + CMPUNORDPD + BLENDVPD
4638 { ISD::FSQRT, MVT::f32, { 7, 15, 1, 1 } }, // vsqrtss
4639 { ISD::FSQRT, MVT::v4f32, { 7, 15, 1, 1 } }, // vsqrtps
4640 { ISD::FSQRT, MVT::v8f32, { 14, 21, 1, 3 } }, // vsqrtps
4641 { ISD::FSQRT, MVT::f64, { 14, 21, 1, 1 } }, // vsqrtsd
4642 { ISD::FSQRT, MVT::v2f64, { 14, 21, 1, 1 } }, // vsqrtpd
4643 { ISD::FSQRT, MVT::v4f64, { 28, 35, 1, 3 } }, // vsqrtpd
4644 };
4645 static const CostKindTblEntry AVX1CostTbl[] = {
4646 { ISD::ABS, MVT::v4i64, { 6, 8, 6, 12 } }, // VBLENDVPD(X,VPSUBQ(0,X),X)
4647 { ISD::ABS, MVT::v8i32, { 3, 6, 4, 5 } },
4648 { ISD::ABS, MVT::v16i16, { 3, 6, 4, 5 } },
4649 { ISD::ABS, MVT::v32i8, { 3, 6, 4, 5 } },
4650 { ISD::BITREVERSE, MVT::v4i64, { 17, 20, 20, 33 } }, // 2 x 128-bit Op + extract/insert
4651 { ISD::BITREVERSE, MVT::v2i64, { 8, 13, 10, 16 } },
4652 { ISD::BITREVERSE, MVT::v8i32, { 17, 20, 20, 33 } }, // 2 x 128-bit Op + extract/insert
4653 { ISD::BITREVERSE, MVT::v4i32, { 8, 13, 10, 16 } },
4654 { ISD::BITREVERSE, MVT::v16i16, { 17, 20, 20, 33 } }, // 2 x 128-bit Op + extract/insert
4655 { ISD::BITREVERSE, MVT::v8i16, { 8, 13, 10, 16 } },
4656 { ISD::BITREVERSE, MVT::v32i8, { 13, 15, 17, 26 } }, // 2 x 128-bit Op + extract/insert
4657 { ISD::BITREVERSE, MVT::v16i8, { 7, 7, 9, 13 } },
4658 { ISD::BSWAP, MVT::v4i64, { 5, 6, 5, 10 } },
4659 { ISD::BSWAP, MVT::v2i64, { 2, 2, 1, 3 } },
4660 { ISD::BSWAP, MVT::v8i32, { 5, 6, 5, 10 } },
4661 { ISD::BSWAP, MVT::v4i32, { 2, 2, 1, 3 } },
4662 { ISD::BSWAP, MVT::v16i16, { 5, 6, 5, 10 } },
4663 { ISD::BSWAP, MVT::v8i16, { 2, 2, 1, 3 } },
4664 { ISD::CTLZ, MVT::v4i64, { 29, 33, 49, 58 } }, // 2 x 128-bit Op + extract/insert
4665 { ISD::CTLZ, MVT::v2i64, { 14, 24, 24, 28 } },
4666 { ISD::CTLZ, MVT::v8i32, { 24, 28, 39, 48 } }, // 2 x 128-bit Op + extract/insert
4667 { ISD::CTLZ, MVT::v4i32, { 12, 20, 19, 23 } },
4668 { ISD::CTLZ, MVT::v16i16, { 19, 22, 29, 38 } }, // 2 x 128-bit Op + extract/insert
4669 { ISD::CTLZ, MVT::v8i16, { 9, 16, 14, 18 } },
4670 { ISD::CTLZ, MVT::v32i8, { 14, 15, 19, 28 } }, // 2 x 128-bit Op + extract/insert
4671 { ISD::CTLZ, MVT::v16i8, { 7, 12, 9, 13 } },
4672 { ISD::CTPOP, MVT::v4i64, { 14, 18, 19, 28 } }, // 2 x 128-bit Op + extract/insert
4673 { ISD::CTPOP, MVT::v2i64, { 7, 14, 10, 14 } },
4674 { ISD::CTPOP, MVT::v8i32, { 18, 24, 27, 36 } }, // 2 x 128-bit Op + extract/insert
4675 { ISD::CTPOP, MVT::v4i32, { 9, 20, 14, 18 } },
4676 { ISD::CTPOP, MVT::v16i16, { 16, 21, 22, 31 } }, // 2 x 128-bit Op + extract/insert
4677 { ISD::CTPOP, MVT::v8i16, { 8, 18, 11, 15 } },
4678 { ISD::CTPOP, MVT::v32i8, { 13, 15, 16, 25 } }, // 2 x 128-bit Op + extract/insert
4679 { ISD::CTPOP, MVT::v16i8, { 6, 12, 8, 12 } },
4680 { ISD::CTTZ, MVT::v4i64, { 17, 22, 24, 33 } }, // 2 x 128-bit Op + extract/insert
4681 { ISD::CTTZ, MVT::v2i64, { 9, 19, 13, 17 } },
4682 { ISD::CTTZ, MVT::v8i32, { 21, 27, 32, 41 } }, // 2 x 128-bit Op + extract/insert
4683 { ISD::CTTZ, MVT::v4i32, { 11, 24, 17, 21 } },
4684 { ISD::CTTZ, MVT::v16i16, { 18, 24, 27, 36 } }, // 2 x 128-bit Op + extract/insert
4685 { ISD::CTTZ, MVT::v8i16, { 9, 21, 14, 18 } },
4686 { ISD::CTTZ, MVT::v32i8, { 15, 18, 21, 30 } }, // 2 x 128-bit Op + extract/insert
4687 { ISD::CTTZ, MVT::v16i8, { 8, 16, 11, 15 } },
4688 { ISD::MASK_BEFOREFIRST, MVT::v2i64, { 8, 11, 9, 11 } }, // movmsk seq
4689 { ISD::MASK_BEFOREFIRST, MVT::v4i32, { 8, 11, 9, 11 } }, // movmsk seq
4690 { ISD::MASK_BEFOREFIRST, MVT::v8i16, { 10, 13, 11, 13 } }, // movmsk seq
4691 { ISD::MASK_BEFOREFIRST, MVT::v16i8, { 8, 11, 9, 11 } }, // movmsk seq
4692 { ISD::MASK_BEFOREFIRST, MVT::v32i8, { 18, 24, 19, 24 } }, // movmsk seq
4693 { ISD::MULHS, MVT::v8i32, { 9, 11, 14, 18 } },
4694 { ISD::MULHS, MVT::v16i16, { 3, 7, 5, 6 } },
4695 { ISD::MULHU, MVT::v8i32, { 9, 11, 14, 18 } },
4696 { ISD::MULHU, MVT::v16i16, { 3, 7, 5, 6 } },
4697 { ISD::SADDSAT, MVT::v2i64, { 6, 13, 8, 11 } },
4698 { ISD::SADDSAT, MVT::v4i64, { 13, 20, 15, 25 } }, // 2 x 128-bit Op + extract/insert
4699 { ISD::SADDSAT, MVT::v8i32, { 12, 18, 14, 24 } }, // 2 x 128-bit Op + extract/insert
4700 { ISD::SADDSAT, MVT::v16i16, { 3, 3, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4701 { ISD::SADDSAT, MVT::v32i8, { 3, 3, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4702 { ISD::SMAX, MVT::v4i64, { 6, 9, 6, 12 } }, // 2 x 128-bit Op + extract/insert
4703 { ISD::SMAX, MVT::v2i64, { 3, 7, 2, 4 } },
4704 { ISD::SMAX, MVT::v8i32, { 4, 6, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4705 { ISD::SMAX, MVT::v16i16, { 4, 6, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4706 { ISD::SMAX, MVT::v32i8, { 4, 6, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4707 { ISD::SMIN, MVT::v4i64, { 6, 9, 6, 12 } }, // 2 x 128-bit Op + extract/insert
4708 { ISD::SMIN, MVT::v2i64, { 3, 7, 2, 3 } },
4709 { ISD::SMIN, MVT::v8i32, { 4, 6, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4710 { ISD::SMIN, MVT::v16i16, { 4, 6, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4711 { ISD::SMIN, MVT::v32i8, { 4, 6, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4712 { ISD::SMULO, MVT::v4i64, { 20, 20, 33, 37 } },
4713 { ISD::SMULO, MVT::v2i64, { 9, 9, 13, 17 } },
4714 { ISD::SMULO, MVT::v8i32, { 15, 20, 24, 29 } },
4715 { ISD::SMULO, MVT::v4i32, { 7, 15, 11, 13 } },
4716 { ISD::SMULO, MVT::v16i16, { 8, 14, 14, 15 } },
4717 { ISD::SMULO, MVT::v8i16, { 3, 9, 6, 6 } },
4718 { ISD::SMULO, MVT::v32i8, { 20, 20, 37, 39 } },
4719 { ISD::SMULO, MVT::v16i8, { 9, 22, 18, 21 } },
4720 { ISD::SSUBSAT, MVT::v2i64, { 7, 13, 9, 13 } },
4721 { ISD::SSUBSAT, MVT::v4i64, { 15, 21, 18, 29 } }, // 2 x 128-bit Op + extract/insert
4722 { ISD::SSUBSAT, MVT::v8i32, { 15, 19, 18, 29 } }, // 2 x 128-bit Op + extract/insert
4723 { ISD::SSUBSAT, MVT::v16i16, { 3, 3, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4724 { ISD::SSUBSAT, MVT::v32i8, { 3, 3, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4725 { ISD::UADDSAT, MVT::v2i64, { 3, 8, 6, 6 } },
4726 { ISD::UADDSAT, MVT::v4i64, { 8, 11, 14, 15 } }, // 2 x 128-bit Op + extract/insert
4727 { ISD::UADDSAT, MVT::v8i32, { 6, 6, 10, 11 } }, // 2 x 128-bit Op + extract/insert
4728 { ISD::UADDSAT, MVT::v16i16, { 3, 3, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4729 { ISD::UADDSAT, MVT::v32i8, { 3, 3, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4730 { ISD::UMAX, MVT::v4i64, { 9, 10, 11, 17 } }, // 2 x 128-bit Op + extract/insert
4731 { ISD::UMAX, MVT::v2i64, { 4, 8, 5, 7 } },
4732 { ISD::UMAX, MVT::v8i32, { 4, 6, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4733 { ISD::UMAX, MVT::v16i16, { 4, 6, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4734 { ISD::UMAX, MVT::v32i8, { 4, 6, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4735 { ISD::UMIN, MVT::v4i64, { 9, 10, 11, 17 } }, // 2 x 128-bit Op + extract/insert
4736 { ISD::UMIN, MVT::v2i64, { 4, 8, 5, 7 } },
4737 { ISD::UMIN, MVT::v8i32, { 4, 6, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4738 { ISD::UMIN, MVT::v16i16, { 4, 6, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4739 { ISD::UMIN, MVT::v32i8, { 4, 6, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4740 { ISD::UMULO, MVT::v4i64, { 24, 26, 39, 45 } },
4741 { ISD::UMULO, MVT::v2i64, { 10, 12, 15, 20 } },
4742 { ISD::UMULO, MVT::v8i32, { 14, 15, 23, 28 } },
4743 { ISD::UMULO, MVT::v4i32, { 7, 12, 11, 13 } },
4744 { ISD::UMULO, MVT::v16i16, { 7, 11, 13, 14 } },
4745 { ISD::UMULO, MVT::v8i16, { 3, 8, 6, 6 } },
4746 { ISD::UMULO, MVT::v32i8, { 19, 19, 35, 37 } },
4747 { ISD::UMULO, MVT::v16i8, { 9, 19, 17, 20 } },
4748 { ISD::USUBSAT, MVT::v2i64, { 3, 7, 6, 6 } },
4749 { ISD::USUBSAT, MVT::v4i64, { 8, 10, 14, 15 } }, // 2 x 128-bit Op + extract/insert
4750 { ISD::USUBSAT, MVT::v8i32, { 4, 4, 7, 8 } }, // 2 x 128-bit Op + extract/insert
4751 { ISD::USUBSAT, MVT::v8i32, { 3, 3, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4752 { ISD::USUBSAT, MVT::v16i16, { 3, 3, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4753 { ISD::USUBSAT, MVT::v32i8, { 3, 3, 5, 6 } }, // 2 x 128-bit Op + extract/insert
4754 { ISD::FMAXNUM, MVT::f32, { 3, 6, 3, 5 } }, // MAXSS + CMPUNORDSS + BLENDVPS
4755 { ISD::FMAXNUM, MVT::v4f32, { 3, 6, 3, 5 } }, // MAXPS + CMPUNORDPS + BLENDVPS
4756 { ISD::FMAXNUM, MVT::v8f32, { 5, 7, 3, 10 } }, // MAXPS + CMPUNORDPS + BLENDVPS
4757 { ISD::FMAXNUM, MVT::f64, { 3, 6, 3, 5 } }, // MAXSD + CMPUNORDSD + BLENDVPD
4758 { ISD::FMAXNUM, MVT::v2f64, { 3, 6, 3, 5 } }, // MAXPD + CMPUNORDPD + BLENDVPD
4759 { ISD::FMAXNUM, MVT::v4f64, { 5, 7, 3, 10 } }, // MAXPD + CMPUNORDPD + BLENDVPD
4760 { ISD::FSQRT, MVT::f32, { 21, 21, 1, 1 } }, // vsqrtss
4761 { ISD::FSQRT, MVT::v4f32, { 21, 21, 1, 1 } }, // vsqrtps
4762 { ISD::FSQRT, MVT::v8f32, { 42, 42, 1, 3 } }, // vsqrtps
4763 { ISD::FSQRT, MVT::f64, { 27, 27, 1, 1 } }, // vsqrtsd
4764 { ISD::FSQRT, MVT::v2f64, { 27, 27, 1, 1 } }, // vsqrtpd
4765 { ISD::FSQRT, MVT::v4f64, { 54, 54, 1, 3 } }, // vsqrtpd
4766 { ISD::VECTOR_SHUFFLE_VAR, MVT::v2i64, { 1, 1, 2, 2 } }, // vpaddq+vpermilpd
4767 { ISD::VECTOR_SHUFFLE_VAR, MVT::v4i32, { 1, 1, 1, 1 } }, // vpermilps
4768 };
4769 static const CostKindTblEntry GFNICostTbl[] = {
4770 { ISD::BITREVERSE, MVT::i8, { 3, 3, 3, 4 } }, // gf2p8affineqb
4771 { ISD::BITREVERSE, MVT::i16, { 3, 3, 4, 6 } }, // gf2p8affineqb
4772 { ISD::BITREVERSE, MVT::i32, { 3, 3, 4, 5 } }, // gf2p8affineqb
4773 { ISD::BITREVERSE, MVT::i64, { 3, 3, 4, 6 } }, // gf2p8affineqb
4774 { ISD::BITREVERSE, MVT::v16i8, { 1, 6, 1, 2 } }, // gf2p8affineqb
4775 { ISD::BITREVERSE, MVT::v32i8, { 1, 6, 1, 2 } }, // gf2p8affineqb
4776 { ISD::BITREVERSE, MVT::v64i8, { 1, 6, 1, 2 } }, // gf2p8affineqb
4777 { ISD::BITREVERSE, MVT::v8i16, { 1, 8, 2, 4 } }, // gf2p8affineqb
4778 { ISD::BITREVERSE, MVT::v16i16, { 1, 9, 2, 4 } }, // gf2p8affineqb
4779 { ISD::BITREVERSE, MVT::v32i16, { 1, 9, 2, 4 } }, // gf2p8affineqb
4780 { ISD::BITREVERSE, MVT::v4i32, { 1, 8, 2, 4 } }, // gf2p8affineqb
4781 { ISD::BITREVERSE, MVT::v8i32, { 1, 9, 2, 4 } }, // gf2p8affineqb
4782 { ISD::BITREVERSE, MVT::v16i32, { 1, 9, 2, 4 } }, // gf2p8affineqb
4783 { ISD::BITREVERSE, MVT::v2i64, { 1, 8, 2, 4 } }, // gf2p8affineqb
4784 { ISD::BITREVERSE, MVT::v4i64, { 1, 9, 2, 4 } }, // gf2p8affineqb
4785 { ISD::BITREVERSE, MVT::v8i64, { 1, 9, 2, 4 } }, // gf2p8affineqb
4786 { X86ISD::VROTLI, MVT::v16i8, { 1, 6, 1, 2 } }, // gf2p8affineqb
4787 { X86ISD::VROTLI, MVT::v32i8, { 1, 6, 1, 2 } }, // gf2p8affineqb
4788 { X86ISD::VROTLI, MVT::v64i8, { 1, 6, 1, 2 } }, // gf2p8affineqb
4789 };
4790 static const CostKindTblEntry GLMCostTbl[] = {
4791 { ISD::FSQRT, MVT::f32, { 19, 20, 1, 1 } }, // sqrtss
4792 { ISD::FSQRT, MVT::v4f32, { 37, 41, 1, 5 } }, // sqrtps
4793 { ISD::FSQRT, MVT::f64, { 34, 35, 1, 1 } }, // sqrtsd
4794 { ISD::FSQRT, MVT::v2f64, { 67, 71, 1, 5 } }, // sqrtpd
4795 };
4796 static const CostKindTblEntry SLMCostTbl[] = {
4797 { ISD::BSWAP, MVT::v2i64, { 5, 5, 1, 5 } },
4798 { ISD::BSWAP, MVT::v4i32, { 5, 5, 1, 5 } },
4799 { ISD::BSWAP, MVT::v8i16, { 5, 5, 1, 5 } },
4800 { ISD::FSQRT, MVT::f32, { 20, 20, 1, 1 } }, // sqrtss
4801 { ISD::FSQRT, MVT::v4f32, { 40, 41, 1, 5 } }, // sqrtps
4802 { ISD::FSQRT, MVT::f64, { 35, 35, 1, 1 } }, // sqrtsd
4803 { ISD::FSQRT, MVT::v2f64, { 70, 71, 1, 5 } }, // sqrtpd
4804 };
4805 static const CostKindTblEntry SSE42CostTbl[] = {
4806 { ISD::FMAXNUM, MVT::f32, { 5, 5, 7, 7 } }, // MAXSS + CMPUNORDSS + BLENDVPS
4807 { ISD::FMAXNUM, MVT::v4f32, { 4, 4, 4, 5 } }, // MAXPS + CMPUNORDPS + BLENDVPS
4808 { ISD::FMAXNUM, MVT::f64, { 5, 5, 7, 7 } }, // MAXSD + CMPUNORDSD + BLENDVPD
4809 { ISD::FMAXNUM, MVT::v2f64, { 4, 4, 4, 5 } }, // MAXPD + CMPUNORDPD + BLENDVPD
4810 { ISD::FSQRT, MVT::f32, { 18, 18, 1, 1 } }, // Nehalem from http://www.agner.org/
4811 { ISD::FSQRT, MVT::v4f32, { 18, 18, 1, 1 } }, // Nehalem from http://www.agner.org/
4812 };
4813 static const CostKindTblEntry SSE41CostTbl[] = {
4814 { ISD::ABS, MVT::v2i64, { 3, 4, 3, 5 } }, // BLENDVPD(X,PSUBQ(0,X),X)
4815 { ISD::MASK_BEFOREFIRST, MVT::v2i64, { 8, 11, 9, 11 } }, // movmsk seq
4816 { ISD::MULHS, MVT::v4i32, { 3, 9, 6, 7 } },
4817 { ISD::MULHU, MVT::v4i32, { 3, 9, 6, 7 } },
4818 { ISD::SADDSAT, MVT::v2i64, { 10, 14, 17, 21 } },
4819 { ISD::SADDSAT, MVT::v4i32, { 5, 11, 8, 10 } },
4820 { ISD::SSUBSAT, MVT::v2i64, { 12, 19, 25, 29 } },
4821 { ISD::SSUBSAT, MVT::v4i32, { 6, 14, 10, 12 } },
4822 { ISD::SMAX, MVT::v2i64, { 3, 7, 2, 3 } },
4823 { ISD::SMAX, MVT::v4i32, { 1, 1, 1, 1 } },
4824 { ISD::SMAX, MVT::v16i8, { 1, 1, 1, 1 } },
4825 { ISD::SMIN, MVT::v2i64, { 3, 7, 2, 3 } },
4826 { ISD::SMIN, MVT::v4i32, { 1, 1, 1, 1 } },
4827 { ISD::SMIN, MVT::v16i8, { 1, 1, 1, 1 } },
4828 { ISD::SMULO, MVT::v2i64, { 9, 11, 13, 17 } },
4829 { ISD::SMULO, MVT::v4i32, { 20, 24, 13, 19 } },
4830 { ISD::SMULO, MVT::v8i16, { 5, 9, 8, 8 } },
4831 { ISD::SMULO, MVT::v16i8, { 13, 22, 24, 25 } },
4832 { ISD::UADDSAT, MVT::v2i64, { 6, 13, 14, 14 } },
4833 { ISD::UADDSAT, MVT::v4i32, { 2, 2, 4, 4 } },
4834 { ISD::USUBSAT, MVT::v2i64, { 6, 10, 14, 14 } },
4835 { ISD::USUBSAT, MVT::v4i32, { 1, 2, 2, 2 } },
4836 { ISD::UMAX, MVT::v2i64, { 2, 11, 6, 7 } },
4837 { ISD::UMAX, MVT::v4i32, { 1, 1, 1, 1 } },
4838 { ISD::UMAX, MVT::v8i16, { 1, 1, 1, 1 } },
4839 { ISD::UMIN, MVT::v2i64, { 2, 11, 6, 7 } },
4840 { ISD::UMIN, MVT::v4i32, { 1, 1, 1, 1 } },
4841 { ISD::UMIN, MVT::v8i16, { 1, 1, 1, 1 } },
4842 { ISD::UMULO, MVT::v2i64, { 14, 20, 15, 20 } },
4843 { ISD::UMULO, MVT::v4i32, { 19, 22, 12, 18 } },
4844 { ISD::UMULO, MVT::v8i16, { 4, 9, 7, 7 } },
4845 { ISD::UMULO, MVT::v16i8, { 13, 19, 18, 20 } },
4846 };
4847 static const CostKindTblEntry SSSE3CostTbl[] = {
4848 { ISD::ABS, MVT::v4i32, { 1, 2, 1, 1 } },
4849 { ISD::ABS, MVT::v8i16, { 1, 2, 1, 1 } },
4850 { ISD::ABS, MVT::v16i8, { 1, 2, 1, 1 } },
4851 { ISD::BITREVERSE, MVT::v2i64, { 16, 20, 11, 21 } },
4852 { ISD::BITREVERSE, MVT::v4i32, { 16, 20, 11, 21 } },
4853 { ISD::BITREVERSE, MVT::v8i16, { 16, 20, 11, 21 } },
4854 { ISD::BITREVERSE, MVT::v16i8, { 11, 12, 10, 16 } },
4855 { ISD::BSWAP, MVT::v2i64, { 2, 3, 1, 5 } },
4856 { ISD::BSWAP, MVT::v4i32, { 2, 3, 1, 5 } },
4857 { ISD::BSWAP, MVT::v8i16, { 2, 3, 1, 5 } },
4858 { ISD::CTLZ, MVT::v2i64, { 18, 28, 28, 35 } },
4859 { ISD::CTLZ, MVT::v4i32, { 15, 20, 22, 28 } },
4860 { ISD::CTLZ, MVT::v8i16, { 13, 17, 16, 22 } },
4861 { ISD::CTLZ, MVT::v16i8, { 11, 15, 10, 16 } },
4862 { ISD::CTPOP, MVT::v2i64, { 13, 19, 12, 18 } },
4863 { ISD::CTPOP, MVT::v4i32, { 18, 24, 16, 22 } },
4864 { ISD::CTPOP, MVT::v8i16, { 13, 18, 14, 20 } },
4865 { ISD::CTPOP, MVT::v16i8, { 11, 12, 10, 16 } },
4866 { ISD::CTTZ, MVT::v2i64, { 13, 25, 15, 22 } },
4867 { ISD::CTTZ, MVT::v4i32, { 18, 26, 19, 25 } },
4868 { ISD::CTTZ, MVT::v8i16, { 13, 20, 17, 23 } },
4869 { ISD::CTTZ, MVT::v16i8, { 11, 16, 13, 19 } },
4870 { ISD::MASK_BEFOREFIRST, MVT::v16i8, { 8, 11, 9, 11 } }, // movmsk seq
4871 { ISD::VECTOR_SHUFFLE_VAR, MVT::v8i16, { 2, 6, 3, 5 } }, // pmul+padd+pshufb
4872 { ISD::VECTOR_SHUFFLE_VAR, MVT::v16i8, { 1, 1, 1, 1 } }, // pshufb
4873 };
4874 static const CostKindTblEntry SSE2CostTbl[] = {
4875 { ISD::ABS, MVT::v2i64, { 3, 6, 5, 5 } },
4876 { ISD::ABS, MVT::v4i32, { 1, 4, 4, 4 } },
4877 { ISD::ABS, MVT::v8i16, { 1, 2, 3, 3 } },
4878 { ISD::ABS, MVT::v16i8, { 1, 2, 3, 3 } },
4879 { ISD::BITREVERSE, MVT::v2i64, { 16, 20, 32, 32 } },
4880 { ISD::BITREVERSE, MVT::v4i32, { 16, 20, 30, 30 } },
4881 { ISD::BITREVERSE, MVT::v8i16, { 16, 20, 25, 25 } },
4882 { ISD::BITREVERSE, MVT::v16i8, { 11, 12, 21, 21 } },
4883 { ISD::BSWAP, MVT::v2i64, { 5, 6, 11, 11 } },
4884 { ISD::BSWAP, MVT::v4i32, { 5, 5, 9, 9 } },
4885 { ISD::BSWAP, MVT::v8i16, { 5, 5, 4, 5 } },
4886 { ISD::CTLZ, MVT::v2i64, { 10, 45, 36, 38 } },
4887 { ISD::CTLZ, MVT::v4i32, { 10, 45, 38, 40 } },
4888 { ISD::CTLZ, MVT::v8i16, { 9, 38, 32, 34 } },
4889 { ISD::CTLZ, MVT::v16i8, { 8, 39, 29, 32 } },
4890 { ISD::CTPOP, MVT::v2i64, { 12, 26, 16, 18 } },
4891 { ISD::CTPOP, MVT::v4i32, { 15, 29, 21, 23 } },
4892 { ISD::CTPOP, MVT::v8i16, { 13, 25, 18, 20 } },
4893 { ISD::CTPOP, MVT::v16i8, { 10, 21, 14, 16 } },
4894 { ISD::CTTZ, MVT::v2i64, { 14, 28, 19, 21 } },
4895 { ISD::CTTZ, MVT::v4i32, { 18, 31, 24, 26 } },
4896 { ISD::CTTZ, MVT::v8i16, { 16, 27, 21, 23 } },
4897 { ISD::CTTZ, MVT::v16i8, { 13, 23, 17, 19 } },
4898 { ISD::MASK_BEFOREFIRST, MVT::v2i64, { 10, 13, 11, 13 } }, // movmsk seq
4899 { ISD::MASK_BEFOREFIRST, MVT::v4i32, { 8, 11, 9, 11 } }, // movmsk seq
4900 { ISD::MASK_BEFOREFIRST, MVT::v8i16, { 10, 13, 11, 13 } }, // movmsk seq
4901 { ISD::MASK_BEFOREFIRST, MVT::v16i8, { 10, 13, 11, 13 } }, // movmsk seq
4902 { ISD::MULHS, MVT::v4i32, { 5, 11, 15, 15 } },
4903 { ISD::MULHS, MVT::v8i16, { 1, 5, 1, 1 } },
4904 { ISD::MULHU, MVT::v4i32, { 3, 9, 7, 7 } },
4905 { ISD::MULHU, MVT::v8i16, { 1, 5, 1, 1 } },
4906 { ISD::SADDSAT, MVT::v2i64, { 12, 14, 24, 24 } },
4907 { ISD::SADDSAT, MVT::v4i32, { 6, 11, 11, 12 } },
4908 { ISD::SADDSAT, MVT::v8i16, { 1, 2, 1, 1 } },
4909 { ISD::SADDSAT, MVT::v16i8, { 1, 2, 1, 1 } },
4910 { ISD::SMAX, MVT::v2i64, { 4, 8, 15, 15 } },
4911 { ISD::SMAX, MVT::v4i32, { 2, 4, 5, 5 } },
4912 { ISD::SMAX, MVT::v8i16, { 1, 1, 1, 1 } },
4913 { ISD::SMAX, MVT::v16i8, { 2, 4, 5, 5 } },
4914 { ISD::SMIN, MVT::v2i64, { 4, 8, 15, 15 } },
4915 { ISD::SMIN, MVT::v4i32, { 2, 4, 5, 5 } },
4916 { ISD::SMIN, MVT::v8i16, { 1, 1, 1, 1 } },
4917 { ISD::SMIN, MVT::v16i8, { 2, 4, 5, 5 } },
4918 { ISD::SMULO, MVT::v2i64, { 30, 33, 13, 23 } },
4919 { ISD::SMULO, MVT::v4i32, { 20, 24, 23, 23 } },
4920 { ISD::SMULO, MVT::v8i16, { 5, 10, 8, 8 } },
4921 { ISD::SMULO, MVT::v16i8, { 13, 23, 24, 25 } },
4922 { ISD::SSUBSAT, MVT::v2i64, { 16, 19, 31, 31 } },
4923 { ISD::SSUBSAT, MVT::v4i32, { 6, 14, 12, 13 } },
4924 { ISD::SSUBSAT, MVT::v8i16, { 1, 2, 1, 1 } },
4925 { ISD::SSUBSAT, MVT::v16i8, { 1, 2, 1, 1 } },
4926 { ISD::UADDSAT, MVT::v2i64, { 7, 13, 14, 14 } },
4927 { ISD::UADDSAT, MVT::v4i32, { 4, 5, 7, 7 } },
4928 { ISD::UADDSAT, MVT::v8i16, { 1, 2, 1, 1 } },
4929 { ISD::UADDSAT, MVT::v16i8, { 1, 2, 1, 1 } },
4930 { ISD::UMAX, MVT::v2i64, { 4, 8, 15, 15 } },
4931 { ISD::UMAX, MVT::v4i32, { 2, 5, 8, 8 } },
4932 { ISD::UMAX, MVT::v8i16, { 1, 3, 3, 3 } },
4933 { ISD::UMAX, MVT::v16i8, { 1, 1, 1, 1 } },
4934 { ISD::UMIN, MVT::v2i64, { 4, 8, 15, 15 } },
4935 { ISD::UMIN, MVT::v4i32, { 2, 5, 8, 8 } },
4936 { ISD::UMIN, MVT::v8i16, { 1, 3, 3, 3 } },
4937 { ISD::UMIN, MVT::v16i8, { 1, 1, 1, 1 } },
4938 { ISD::UMULO, MVT::v2i64, { 30, 33, 15, 29 } },
4939 { ISD::UMULO, MVT::v4i32, { 19, 22, 14, 18 } },
4940 { ISD::UMULO, MVT::v8i16, { 4, 9, 7, 7 } },
4941 { ISD::UMULO, MVT::v16i8, { 13, 19, 20, 20 } },
4942 { ISD::USUBSAT, MVT::v2i64, { 7, 10, 14, 14 } },
4943 { ISD::USUBSAT, MVT::v4i32, { 4, 4, 7, 7 } },
4944 { ISD::USUBSAT, MVT::v8i16, { 1, 2, 1, 1 } },
4945 { ISD::USUBSAT, MVT::v16i8, { 1, 2, 1, 1 } },
4946 { ISD::FMAXNUM, MVT::f64, { 5, 5, 7, 7 } },
4947 { ISD::FMAXNUM, MVT::v2f64, { 4, 6, 6, 6 } },
4948 { ISD::FSQRT, MVT::f64, { 32, 32, 1, 1 } }, // Nehalem from http://www.agner.org/
4949 { ISD::FSQRT, MVT::v2f64, { 32, 32, 1, 1 } }, // Nehalem from http://www.agner.org/
4950 };
4951 static const CostKindTblEntry SSE1CostTbl[] = {
4952 { ISD::FMAXNUM, MVT::f32, { 5, 5, 7, 7 } },
4953 { ISD::FMAXNUM, MVT::v4f32, { 4, 6, 6, 6 } },
4954 { ISD::FSQRT, MVT::f32, { 28, 30, 1, 2 } }, // Pentium III from http://www.agner.org/
4955 { ISD::FSQRT, MVT::v4f32, { 56, 56, 1, 2 } }, // Pentium III from http://www.agner.org/
4956 };
4957 static const CostKindTblEntry BMI64CostTbl[] = { // 64-bit targets
4958 { ISD::CTTZ, MVT::i64, { 1, 1, 1, 1 } },
4959 };
4960 static const CostKindTblEntry BMI32CostTbl[] = { // 32 or 64-bit targets
4961 { ISD::CTTZ, MVT::i32, { 1, 1, 1, 1 } },
4962 { ISD::CTTZ, MVT::i16, { 2, 1, 1, 1 } },
4963 { ISD::CTTZ, MVT::i8, { 2, 1, 1, 1 } },
4964 };
4965 static const CostKindTblEntry LZCNT64CostTbl[] = { // 64-bit targets
4966 { ISD::CTLZ, MVT::i64, { 1, 1, 1, 1 } },
4967 };
4968 static const CostKindTblEntry LZCNT32CostTbl[] = { // 32 or 64-bit targets
4969 { ISD::CTLZ, MVT::i32, { 1, 1, 1, 1 } },
4970 { ISD::CTLZ, MVT::i16, { 2, 1, 1, 1 } },
4971 { ISD::CTLZ, MVT::i8, { 2, 1, 1, 1 } },
4972 };
4973 static const CostKindTblEntry POPCNT64CostTbl[] = { // 64-bit targets
4974 { ISD::CTPOP, MVT::i64, { 1, 1, 1, 1 } }, // popcnt
4975 };
4976 static const CostKindTblEntry POPCNT32CostTbl[] = { // 32 or 64-bit targets
4977 { ISD::CTPOP, MVT::i32, { 1, 1, 1, 1 } }, // popcnt
4978 { ISD::CTPOP, MVT::i16, { 1, 1, 2, 2 } }, // popcnt(zext())
4979 { ISD::CTPOP, MVT::i8, { 1, 1, 2, 2 } }, // popcnt(zext())
4980 };
4981 static const CostKindTblEntry PCLMULCostTbl[] = {
4982 { ISD::CLMUL, MVT::v2i64, { 3, 12, 4, 8 } }, // MOV+2xPCLMUL+unpack
4983 { ISD::CLMUL, MVT::v4i32, { 8, 18, 12, 16 } }, // MOV+4xPCLMUL+unpack
4984 { ISD::CLMUL, MVT::i64, { 3, 12, 4, 8 } }, // MOV+PCLMUL+MOV
4985 { ISD::CLMUL, MVT::i32, { 3, 12, 4, 8 } }, // MOV+PCLMUL+MOV
4986 { ISD::CLMUL, MVT::i16, { 3, 12, 4, 8 } }, // MOV+PCLMUL+MOV
4987 { ISD::CLMUL, MVT::i8, { 3, 12, 4, 8 } }, // MOV+PCLMUL+MOV
4988 };
4989 static const CostKindTblEntry X64CostTbl[] = { // 64-bit targets
4990 { ISD::ABS, MVT::i64, { 1, 2, 3, 3 } }, // SUB+CMOV
4991 { ISD::BITREVERSE, MVT::i64, { 10, 12, 20, 22 } },
4992 { ISD::BSWAP, MVT::i64, { 1, 2, 1, 2 } },
4993 { ISD::CTLZ, MVT::i64, { 1, 2, 3, 3 } }, // MOV+BSR+XOR
4994 { ISD::CTLZ, MVT::i32, { 1, 2, 3, 3 } }, // MOV+BSR+XOR
4995 { ISD::CTLZ, MVT::i16, { 2, 2, 3, 3 } }, // MOV+BSR+XOR
4996 { ISD::CTLZ, MVT::i8, { 2, 2, 4, 3 } }, // MOV+BSR+XOR
4997 { ISD::CTLZ_ZERO_POISON,MVT::i64,{ 1, 2, 2, 2 } }, // BSR+XOR
4998 { ISD::CTTZ, MVT::i64, { 1, 2, 2, 2 } }, // MOV+BSF
4999 { ISD::CTTZ, MVT::i32, { 1, 2, 2, 2 } }, // MOV+BSF
5000 { ISD::CTTZ, MVT::i16, { 2, 2, 2, 2 } }, // MOV+BSF
5001 { ISD::CTTZ, MVT::i8, { 2, 2, 2, 2 } }, // MOV+BSF
5002 { ISD::CTTZ_ZERO_POISON,MVT::i64,{ 1, 2, 1, 2 } }, // BSF
5003 { ISD::CTPOP, MVT::i64, { 10, 6, 19, 19 } },
5004 { ISD::ROTL, MVT::i64, { 2, 3, 1, 3 } },
5005 { ISD::ROTR, MVT::i64, { 2, 3, 1, 3 } },
5006 { X86ISD::VROTLI, MVT::i64, { 1, 1, 1, 1 } },
5007 { ISD::FSHL, MVT::i64, { 4, 4, 1, 4 } },
5008 { ISD::SADDSAT, MVT::i64, { 4, 4, 7, 10 } },
5009 { ISD::SSUBSAT, MVT::i64, { 4, 5, 8, 11 } },
5010 { ISD::UADDSAT, MVT::i64, { 2, 3, 4, 7 } },
5011 { ISD::USUBSAT, MVT::i64, { 2, 3, 4, 7 } },
5012 { ISD::SMAX, MVT::i64, { 1, 3, 2, 3 } },
5013 { ISD::SMIN, MVT::i64, { 1, 3, 2, 3 } },
5014 { ISD::UMAX, MVT::i64, { 1, 3, 2, 3 } },
5015 { ISD::UMIN, MVT::i64, { 1, 3, 2, 3 } },
5016 { ISD::SADDO, MVT::i64, { 2, 2, 4, 6 } },
5017 { ISD::UADDO, MVT::i64, { 2, 2, 4, 6 } },
5018 { ISD::SMULO, MVT::i64, { 4, 4, 4, 6 } },
5019 { ISD::UMULO, MVT::i64, { 8, 8, 4, 7 } },
5020 };
5021 static const CostKindTblEntry X86CostTbl[] = { // 32 or 64-bit targets
5022 { ISD::ABS, MVT::i32, { 1, 2, 3, 3 } }, // SUB+XOR+SRA or SUB+CMOV
5023 { ISD::ABS, MVT::i16, { 2, 2, 3, 3 } }, // SUB+XOR+SRA or SUB+CMOV
5024 { ISD::ABS, MVT::i8, { 2, 4, 4, 3 } }, // SUB+XOR+SRA
5025 { ISD::BITREVERSE, MVT::i32, { 9, 12, 17, 19 } },
5026 { ISD::BITREVERSE, MVT::i16, { 9, 12, 17, 19 } },
5027 { ISD::BITREVERSE, MVT::i8, { 7, 9, 13, 14 } },
5028 { ISD::BSWAP, MVT::i32, { 1, 1, 1, 1 } },
5029 { ISD::BSWAP, MVT::i16, { 1, 2, 1, 2 } }, // ROL
5030 { ISD::CTLZ, MVT::i32, { 2, 2, 4, 5 } }, // BSR+XOR or BSR+XOR+CMOV
5031 { ISD::CTLZ, MVT::i16, { 2, 2, 4, 5 } }, // BSR+XOR or BSR+XOR+CMOV
5032 { ISD::CTLZ, MVT::i8, { 2, 2, 5, 6 } }, // BSR+XOR or BSR+XOR+CMOV
5033 { ISD::CTLZ_ZERO_POISON,MVT::i32,{ 1, 2, 2, 2 } }, // BSR+XOR
5034 { ISD::CTLZ_ZERO_POISON,MVT::i16,{ 2, 2, 2, 2 } }, // BSR+XOR
5035 { ISD::CTLZ_ZERO_POISON,MVT::i8, { 2, 2, 3, 3 } }, // BSR+XOR
5036 { ISD::CTTZ, MVT::i32, { 2, 2, 3, 3 } }, // TEST+BSF+CMOV/BRANCH
5037 { ISD::CTTZ, MVT::i16, { 2, 2, 2, 3 } }, // TEST+BSF+CMOV/BRANCH
5038 { ISD::CTTZ, MVT::i8, { 2, 2, 2, 3 } }, // TEST+BSF+CMOV/BRANCH
5039 { ISD::CTTZ_ZERO_POISON,MVT::i32,{ 1, 2, 1, 2 } }, // BSF
5040 { ISD::CTTZ_ZERO_POISON,MVT::i16,{ 2, 2, 1, 2 } }, // BSF
5041 { ISD::CTTZ_ZERO_POISON,MVT::i8, { 2, 2, 1, 2 } }, // BSF
5042 { ISD::CTPOP, MVT::i32, { 8, 7, 15, 15 } },
5043 { ISD::CTPOP, MVT::i16, { 9, 8, 17, 17 } },
5044 { ISD::CTPOP, MVT::i8, { 7, 6, 6, 6 } },
5045 { ISD::ROTL, MVT::i32, { 2, 3, 1, 3 } },
5046 { ISD::ROTL, MVT::i16, { 2, 3, 1, 3 } },
5047 { ISD::ROTL, MVT::i8, { 2, 3, 1, 3 } },
5048 { ISD::ROTR, MVT::i32, { 2, 3, 1, 3 } },
5049 { ISD::ROTR, MVT::i16, { 2, 3, 1, 3 } },
5050 { ISD::ROTR, MVT::i8, { 2, 3, 1, 3 } },
5051 { X86ISD::VROTLI, MVT::i32, { 1, 1, 1, 1 } },
5052 { X86ISD::VROTLI, MVT::i16, { 1, 1, 1, 1 } },
5053 { X86ISD::VROTLI, MVT::i8, { 1, 1, 1, 1 } },
5054 { ISD::FSHL, MVT::i32, { 4, 4, 1, 4 } },
5055 { ISD::FSHL, MVT::i16, { 4, 4, 2, 5 } },
5056 { ISD::FSHL, MVT::i8, { 4, 4, 2, 5 } },
5057 { ISD::SADDSAT, MVT::i32, { 3, 4, 6, 9 } },
5058 { ISD::SADDSAT, MVT::i16, { 4, 4, 7, 10 } },
5059 { ISD::SADDSAT, MVT::i8, { 4, 5, 8, 11 } },
5060 { ISD::SSUBSAT, MVT::i32, { 4, 4, 7, 10 } },
5061 { ISD::SSUBSAT, MVT::i16, { 4, 4, 7, 10 } },
5062 { ISD::SSUBSAT, MVT::i8, { 4, 5, 8, 11 } },
5063 { ISD::UADDSAT, MVT::i32, { 2, 3, 4, 7 } },
5064 { ISD::UADDSAT, MVT::i16, { 2, 3, 4, 7 } },
5065 { ISD::UADDSAT, MVT::i8, { 3, 3, 5, 8 } },
5066 { ISD::USUBSAT, MVT::i32, { 2, 3, 4, 7 } },
5067 { ISD::USUBSAT, MVT::i16, { 2, 3, 4, 7 } },
5068 { ISD::USUBSAT, MVT::i8, { 3, 3, 5, 8 } },
5069 { ISD::SMAX, MVT::i32, { 1, 2, 2, 3 } },
5070 { ISD::SMAX, MVT::i16, { 1, 4, 2, 4 } },
5071 { ISD::SMAX, MVT::i8, { 1, 4, 2, 4 } },
5072 { ISD::SMIN, MVT::i32, { 1, 2, 2, 3 } },
5073 { ISD::SMIN, MVT::i16, { 1, 4, 2, 4 } },
5074 { ISD::SMIN, MVT::i8, { 1, 4, 2, 4 } },
5075 { ISD::UMAX, MVT::i32, { 1, 2, 2, 3 } },
5076 { ISD::UMAX, MVT::i16, { 1, 4, 2, 4 } },
5077 { ISD::UMAX, MVT::i8, { 1, 4, 2, 4 } },
5078 { ISD::UMIN, MVT::i32, { 1, 2, 2, 3 } },
5079 { ISD::UMIN, MVT::i16, { 1, 4, 2, 4 } },
5080 { ISD::UMIN, MVT::i8, { 1, 4, 2, 4 } },
5081 { ISD::SADDO, MVT::i32, { 2, 2, 4, 6 } },
5082 { ISD::SADDO, MVT::i16, { 2, 2, 4, 6 } },
5083 { ISD::SADDO, MVT::i8, { 2, 2, 4, 6 } },
5084 { ISD::UADDO, MVT::i32, { 2, 2, 4, 6 } },
5085 { ISD::UADDO, MVT::i16, { 2, 2, 4, 6 } },
5086 { ISD::UADDO, MVT::i8, { 2, 2, 4, 6 } },
5087 { ISD::SMULO, MVT::i32, { 2, 2, 4, 6 } },
5088 { ISD::SMULO, MVT::i16, { 5, 5, 4, 6 } },
5089 { ISD::SMULO, MVT::i8, { 6, 6, 4, 6 } },
5090 { ISD::UMULO, MVT::i32, { 6, 6, 4, 8 } },
5091 { ISD::UMULO, MVT::i16, { 6, 6, 4, 9 } },
5092 { ISD::UMULO, MVT::i8, { 6, 6, 4, 6 } },
5093 };
5094
5095 Type *RetTy = ICA.getReturnType();
5096 Type *OpTy = RetTy;
5097 Intrinsic::ID IID = ICA.getID();
5098 unsigned ISD = ISD::DELETED_NODE;
5099 switch (IID) {
5100 default:
5101 break;
5102 case Intrinsic::abs:
5103 ISD = ISD::ABS;
5104 break;
5105 case Intrinsic::bitreverse:
5107 break;
5108 case Intrinsic::bswap:
5109 ISD = ISD::BSWAP;
5110 break;
5111 case Intrinsic::ctlz:
5112 ISD = ISD::CTLZ;
5113 break;
5114 case Intrinsic::ctpop:
5115 ISD = ISD::CTPOP;
5116 break;
5117 case Intrinsic::cttz:
5118 ISD = ISD::CTTZ;
5119 break;
5120 case Intrinsic::fshl:
5121 ISD = ISD::FSHL;
5122 if (!ICA.isTypeBasedOnly()) {
5123 const SmallVectorImpl<const Value *> &Args = ICA.getArgs();
5124 if (Args[0] == Args[1]) {
5125 ISD = ISD::ROTL;
5126 // Handle uniform constant rotation amounts.
5127 // TODO: Handle funnel-shift cases.
5128 const APInt *Amt;
5129 if (Args[2] &&
5131 ISD = X86ISD::VROTLI;
5132 }
5133 }
5134 break;
5135 case Intrinsic::fshr:
5136 // FSHR has same costs so don't duplicate.
5137 ISD = ISD::FSHL;
5138 if (!ICA.isTypeBasedOnly()) {
5139 const SmallVectorImpl<const Value *> &Args = ICA.getArgs();
5140 if (Args[0] == Args[1]) {
5141 ISD = ISD::ROTR;
5142 // Handle uniform constant rotation amount.
5143 // TODO: Handle funnel-shift cases.
5144 const APInt *Amt;
5145 if (Args[2] &&
5147 ISD = X86ISD::VROTLI;
5148 }
5149 }
5150 break;
5151 case Intrinsic::lrint:
5152 case Intrinsic::llrint: {
5153 // X86 can use the CVTP2SI instructions to lower lrint/llrint calls, which
5154 // have the same costs as the CVTTP2SI (fptosi) instructions
5155 const SmallVectorImpl<Type *> &ArgTys = ICA.getArgTypes();
5156 return getCastInstrCost(Instruction::FPToSI, RetTy, ArgTys[0],
5157 TTI::CastContextHint::None, CostKind);
5158 }
5159 case Intrinsic::mask_beforefirst:
5161 break;
5162 case Intrinsic::maxnum:
5163 case Intrinsic::minnum:
5164 // FMINNUM has same costs so don't duplicate.
5165 ISD = ISD::FMAXNUM;
5166 break;
5167 case Intrinsic::sadd_sat:
5168 ISD = ISD::SADDSAT;
5169 break;
5170 case Intrinsic::smax:
5171 ISD = ISD::SMAX;
5172 break;
5173 case Intrinsic::smin:
5174 ISD = ISD::SMIN;
5175 break;
5176 case Intrinsic::smulh:
5177 ISD = ISD::MULHS;
5178 break;
5179 case Intrinsic::ssub_sat:
5180 ISD = ISD::SSUBSAT;
5181 break;
5182 case Intrinsic::uadd_sat:
5183 ISD = ISD::UADDSAT;
5184 break;
5185 case Intrinsic::umax:
5186 ISD = ISD::UMAX;
5187 break;
5188 case Intrinsic::umin:
5189 ISD = ISD::UMIN;
5190 break;
5191 case Intrinsic::usub_sat:
5192 ISD = ISD::USUBSAT;
5193 break;
5194 case Intrinsic::umulh:
5195 ISD = ISD::MULHU;
5196 break;
5197 case Intrinsic::sqrt:
5198 // The estimate sequence is costed with the division it is folded into.
5199 if (isFoldedIntoRsqrtEstimate(ICA.getInst(), *TLI,
5200 getTypeLegalizationCost(RetTy).second,
5201 CostKind))
5202 return TTI::TCC_Free;
5203 ISD = ISD::FSQRT;
5204 break;
5205 case Intrinsic::sadd_with_overflow:
5206 case Intrinsic::ssub_with_overflow:
5207 // SSUBO has same costs so don't duplicate.
5208 ISD = ISD::SADDO;
5209 OpTy = RetTy->getContainedType(0);
5210 break;
5211 case Intrinsic::uadd_with_overflow:
5212 case Intrinsic::usub_with_overflow:
5213 // USUBO has same costs so don't duplicate.
5214 ISD = ISD::UADDO;
5215 OpTy = RetTy->getContainedType(0);
5216 break;
5217 case Intrinsic::smul_with_overflow:
5218 ISD = ISD::SMULO;
5219 OpTy = RetTy->getContainedType(0);
5220 break;
5221 case Intrinsic::umul_with_overflow:
5222 ISD = ISD::UMULO;
5223 OpTy = RetTy->getContainedType(0);
5224 break;
5225 case Intrinsic::vector_shuffle:
5226 // TODO: mask op zext/trunc costs.
5228 break;
5229 case Intrinsic::clmul:
5230 ISD = ISD::CLMUL;
5231 break;
5232 }
5233
5234 if (ISD != ISD::DELETED_NODE) {
5235 auto adjustTableCost = [&](int ISD, unsigned Cost,
5236 std::pair<InstructionCost, MVT> LT,
5238 InstructionCost LegalizationCost = LT.first;
5239 MVT MTy = LT.second;
5240
5241 // If there are no NANs to deal with, then these are reduced to a
5242 // single MIN** or MAX** instruction instead of the MIN/CMP/SELECT that we
5243 // assume is used in the non-fast case.
5244 if (ISD == ISD::FMAXNUM || ISD == ISD::FMINNUM) {
5245 if (FMF.noNaNs())
5246 return LegalizationCost * 1;
5247 }
5248
5249 // For cases where some ops can be folded into a load/store, assume free.
5250 if (MTy.isScalarInteger()) {
5251 if (ISD == ISD::BSWAP && ST->hasMOVBE() && ST->hasFastMOVBE()) {
5252 if (const Instruction *II = ICA.getInst()) {
5253 if (II->hasOneUse() && isa<StoreInst>(II->user_back()))
5254 return TTI::TCC_Free;
5255 if (auto *LI = dyn_cast<LoadInst>(II->getOperand(0))) {
5256 if (LI->hasOneUse())
5257 return TTI::TCC_Free;
5258 }
5259 }
5260 }
5261 }
5262
5263 return LegalizationCost * (int)Cost;
5264 };
5265
5266 // Legalize the type.
5267 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(OpTy);
5268 MVT MTy = LT.second;
5269
5270 // Without BMI/LZCNT see if we're only looking for a *_ZERO_POISON cost.
5271 if (((ISD == ISD::CTTZ && !ST->hasBMI()) ||
5272 (ISD == ISD::CTLZ && !ST->hasLZCNT())) &&
5273 !MTy.isVector() && !ICA.isTypeBasedOnly()) {
5274 const SmallVectorImpl<const Value *> &Args = ICA.getArgs();
5275 if (auto *Cst = dyn_cast<ConstantInt>(Args[1]))
5276 if (Cst->isAllOnesValue())
5277 ISD =
5279 }
5280
5281 // FSQRT is a single instruction.
5282 if (ISD == ISD::FSQRT && CostKind == TTI::TCK_CodeSize)
5283 return LT.first;
5284
5285 if (ST->useGLMDivSqrtCosts())
5286 if (const auto *Entry = CostTableLookup(GLMCostTbl, ISD, MTy))
5287 if (auto KindCost = Entry->Cost[CostKind])
5288 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5289
5290 if (ST->useSLMArithCosts())
5291 if (const auto *Entry = CostTableLookup(SLMCostTbl, ISD, MTy))
5292 if (auto KindCost = Entry->Cost[CostKind])
5293 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5294
5295 if (ST->hasVBMI2())
5296 if (const auto *Entry = CostTableLookup(AVX512VBMI2CostTbl, ISD, MTy))
5297 if (auto KindCost = Entry->Cost[CostKind])
5298 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5299
5300 if (ST->hasBITALG())
5301 if (const auto *Entry = CostTableLookup(AVX512BITALGCostTbl, ISD, MTy))
5302 if (auto KindCost = Entry->Cost[CostKind])
5303 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5304
5305 if (ST->hasVPOPCNTDQ())
5306 if (const auto *Entry = CostTableLookup(AVX512VPOPCNTDQCostTbl, ISD, MTy))
5307 if (auto KindCost = Entry->Cost[CostKind])
5308 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5309
5310 if (ST->hasGFNI())
5311 if (const auto *Entry = CostTableLookup(GFNICostTbl, ISD, MTy))
5312 if (auto KindCost = Entry->Cost[CostKind])
5313 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5314
5315 if (ST->hasCDI())
5316 if (const auto *Entry = CostTableLookup(AVX512CDCostTbl, ISD, MTy))
5317 if (auto KindCost = Entry->Cost[CostKind])
5318 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5319
5320 if (ST->hasBWI())
5321 if (const auto *Entry = CostTableLookup(AVX512BWCostTbl, ISD, MTy))
5322 if (auto KindCost = Entry->Cost[CostKind])
5323 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5324
5325 if (ST->hasAVX512())
5326 if (const auto *Entry = CostTableLookup(AVX512CostTbl, ISD, MTy))
5327 if (auto KindCost = Entry->Cost[CostKind])
5328 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5329
5330 if (ST->hasXOP())
5331 if (const auto *Entry = CostTableLookup(XOPCostTbl, ISD, MTy))
5332 if (auto KindCost = Entry->Cost[CostKind])
5333 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5334
5335 if (ST->hasAVX2())
5336 if (const auto *Entry = CostTableLookup(AVX2CostTbl, ISD, MTy))
5337 if (auto KindCost = Entry->Cost[CostKind])
5338 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5339
5340 if (ST->hasAVX())
5341 if (const auto *Entry = CostTableLookup(AVX1CostTbl, ISD, MTy))
5342 if (auto KindCost = Entry->Cost[CostKind])
5343 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5344
5345 if (ST->hasSSE42())
5346 if (const auto *Entry = CostTableLookup(SSE42CostTbl, ISD, MTy))
5347 if (auto KindCost = Entry->Cost[CostKind])
5348 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5349
5350 if (ST->hasSSE41())
5351 if (const auto *Entry = CostTableLookup(SSE41CostTbl, ISD, MTy))
5352 if (auto KindCost = Entry->Cost[CostKind])
5353 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5354
5355 if (ST->hasSSSE3())
5356 if (const auto *Entry = CostTableLookup(SSSE3CostTbl, ISD, MTy))
5357 if (auto KindCost = Entry->Cost[CostKind])
5358 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5359
5360 if (ST->hasSSE2())
5361 if (const auto *Entry = CostTableLookup(SSE2CostTbl, ISD, MTy))
5362 if (auto KindCost = Entry->Cost[CostKind])
5363 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5364
5365 if (ST->hasSSE1())
5366 if (const auto *Entry = CostTableLookup(SSE1CostTbl, ISD, MTy))
5367 if (auto KindCost = Entry->Cost[CostKind])
5368 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5369
5370 if (ST->hasBMI()) {
5371 if (ST->is64Bit())
5372 if (const auto *Entry = CostTableLookup(BMI64CostTbl, ISD, MTy))
5373 if (auto KindCost = Entry->Cost[CostKind])
5374 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5375
5376 if (const auto *Entry = CostTableLookup(BMI32CostTbl, ISD, MTy))
5377 if (auto KindCost = Entry->Cost[CostKind])
5378 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5379 }
5380
5381 if (ST->hasLZCNT()) {
5382 if (ST->is64Bit())
5383 if (const auto *Entry = CostTableLookup(LZCNT64CostTbl, ISD, MTy))
5384 if (auto KindCost = Entry->Cost[CostKind])
5385 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5386
5387 if (const auto *Entry = CostTableLookup(LZCNT32CostTbl, ISD, MTy))
5388 if (auto KindCost = Entry->Cost[CostKind])
5389 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5390 }
5391
5392 if (ST->hasPOPCNT()) {
5393 if (ST->is64Bit())
5394 if (const auto *Entry = CostTableLookup(POPCNT64CostTbl, ISD, MTy))
5395 if (auto KindCost = Entry->Cost[CostKind])
5396 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5397
5398 if (const auto *Entry = CostTableLookup(POPCNT32CostTbl, ISD, MTy))
5399 if (auto KindCost = Entry->Cost[CostKind])
5400 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5401 }
5402
5403 // FIXME: PCLMUL w/ AVX/AVX512 and VPCLMULQDQ are not handled properly.
5404 if (ST->hasPCLMUL())
5405 if (const auto *Entry = CostTableLookup(PCLMULCostTbl, ISD, MTy))
5406 if (auto KindCost = Entry->Cost[CostKind])
5407 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5408
5409 if (ST->is64Bit())
5410 if (const auto *Entry = CostTableLookup(X64CostTbl, ISD, MTy))
5411 if (auto KindCost = Entry->Cost[CostKind])
5412 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5413
5414 if (const auto *Entry = CostTableLookup(X86CostTbl, ISD, MTy))
5415 if (auto KindCost = Entry->Cost[CostKind])
5416 return adjustTableCost(Entry->ISD, *KindCost, LT, ICA.getFlags());
5417
5418 // Without arg data, we need to compute the expanded costs of custom lowered
5419 // intrinsics to prevent use of the (very low) default costs.
5420 if (ICA.isTypeBasedOnly() &&
5421 (IID == Intrinsic::fshl || IID == Intrinsic::fshr)) {
5422 Type *CondTy = RetTy->getWithNewBitWidth(1);
5424 Cost += getArithmeticInstrCost(BinaryOperator::Or, RetTy, CostKind);
5425 Cost += getArithmeticInstrCost(BinaryOperator::Sub, RetTy, CostKind);
5426 Cost += getArithmeticInstrCost(BinaryOperator::Shl, RetTy, CostKind);
5427 Cost += getArithmeticInstrCost(BinaryOperator::LShr, RetTy, CostKind);
5428 Cost += getArithmeticInstrCost(BinaryOperator::And, RetTy, CostKind);
5429 Cost += getCmpSelInstrCost(BinaryOperator::ICmp, RetTy, CondTy,
5430 CmpInst::ICMP_EQ, CostKind);
5431 Cost += getCmpSelInstrCost(BinaryOperator::Select, RetTy, CondTy,
5432 CmpInst::ICMP_EQ, CostKind);
5433 return Cost;
5434 }
5435 }
5436
5437 return BaseT::getIntrinsicInstrCost(ICA, CostKind);
5438}
5439
5441 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
5442 const Value *Op0, const Value *Op1, TTI::VectorInstrContext VIC) const {
5443 static const CostTblEntry SLMCostTbl[] = {
5444 { ISD::EXTRACT_VECTOR_ELT, MVT::i8, 4 },
5445 { ISD::EXTRACT_VECTOR_ELT, MVT::i16, 4 },
5446 { ISD::EXTRACT_VECTOR_ELT, MVT::i32, 4 },
5447 { ISD::EXTRACT_VECTOR_ELT, MVT::i64, 7 }
5448 };
5449
5450 assert(Val->isVectorTy() && "This must be a vector type");
5451 auto *VT = cast<VectorType>(Val);
5452 if (VT->isScalableTy())
5454
5455 Type *ScalarType = Val->getScalarType();
5456 InstructionCost RegisterFileMoveCost = 0;
5457
5458 // Non-immediate extraction/insertion can be handled as a sequence of
5459 // aliased loads+stores via the stack.
5460 if (Index == -1U && (Opcode == Instruction::ExtractElement ||
5461 Opcode == Instruction::InsertElement)) {
5462 // TODO: On some SSE41+ targets, we expand to cmp+splat+select patterns:
5463 // inselt N0, N1, N2 --> select (SplatN2 == {0,1,2...}) ? SplatN1 : N0.
5464
5465 // TODO: Move this to BasicTTIImpl.h? We'd need better gep + index handling.
5466 assert(isa<FixedVectorType>(Val) && "Fixed vector type expected");
5467 Align VecAlign = DL.getPrefTypeAlign(Val);
5468 Align SclAlign = DL.getPrefTypeAlign(ScalarType);
5469
5470 // Extract - store vector to stack, load scalar.
5471 if (Opcode == Instruction::ExtractElement) {
5472 return getMemoryOpCost(Instruction::Store, Val, VecAlign, 0, CostKind) +
5473 getMemoryOpCost(Instruction::Load, ScalarType, SclAlign, 0,
5474 CostKind);
5475 }
5476 // Insert - store vector to stack, store scalar, load vector.
5477 if (Opcode == Instruction::InsertElement) {
5478 return getMemoryOpCost(Instruction::Store, Val, VecAlign, 0, CostKind) +
5479 getMemoryOpCost(Instruction::Store, ScalarType, SclAlign, 0,
5480 CostKind) +
5481 getMemoryOpCost(Instruction::Load, Val, VecAlign, 0, CostKind);
5482 }
5483 }
5484
5485 if (Index != -1U && (Opcode == Instruction::ExtractElement ||
5486 Opcode == Instruction::InsertElement)) {
5487 // Extraction of vXi1 elements are now efficiently handled by MOVMSK.
5488 if (Opcode == Instruction::ExtractElement &&
5489 ScalarType->getScalarSizeInBits() == 1 &&
5490 cast<FixedVectorType>(Val)->getNumElements() > 1)
5491 return 1;
5492
5493 // Legalize the type.
5494 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Val);
5495
5496 // This type is legalized to a scalar type.
5497 if (!LT.second.isVector())
5498 return TTI::TCC_Free;
5499
5500 // The type may be split. Normalize the index to the new type.
5501 unsigned SizeInBits = LT.second.getSizeInBits();
5502 unsigned NumElts = LT.second.getVectorNumElements();
5503 unsigned SubNumElts = NumElts;
5504 Index = Index % NumElts;
5505
5506 // For >128-bit vectors, we need to extract higher 128-bit subvectors.
5507 // For inserts, we also need to insert the subvector back.
5508 if (SizeInBits > 128) {
5509 assert((SizeInBits % 128) == 0 && "Illegal vector");
5510 unsigned NumSubVecs = SizeInBits / 128;
5511 SubNumElts = NumElts / NumSubVecs;
5512 if (SubNumElts <= Index) {
5513 RegisterFileMoveCost += (Opcode == Instruction::InsertElement ? 2 : 1);
5514 Index %= SubNumElts;
5515 }
5516 }
5517
5518 MVT MScalarTy = LT.second.getScalarType();
5519 auto IsCheapPInsrPExtrInsertPS = [&]() {
5520 // Assume pinsr/pextr XMM <-> GPR is relatively cheap on all targets.
5521 // Inserting f32 into index0 is just movss.
5522 // Also, assume insertps is relatively cheap on all >= SSE41 targets.
5523 return (MScalarTy == MVT::i16 && ST->hasSSE2()) ||
5524 (MScalarTy.isInteger() && ST->hasSSE41()) ||
5525 (MScalarTy == MVT::f32 && ST->hasSSE1() && Index == 0 &&
5526 Opcode == Instruction::InsertElement) ||
5527 (MScalarTy == MVT::f32 && ST->hasSSE41() &&
5528 Opcode == Instruction::InsertElement);
5529 };
5530
5531 if (Index == 0) {
5532 // Floating point scalars are already located in index #0.
5533 // Many insertions to #0 can fold away for scalar fp-ops, so let's assume
5534 // true for all.
5535 if (ScalarType->isFloatingPointTy() &&
5536 (Opcode != Instruction::InsertElement || !Op0 ||
5537 isa<UndefValue>(Op0)))
5538 return RegisterFileMoveCost;
5539
5540 if (Opcode == Instruction::InsertElement &&
5542 // Consider the gather cost to be cheap.
5544 return RegisterFileMoveCost;
5545 if (!IsCheapPInsrPExtrInsertPS()) {
5546 // mov constant-to-GPR + movd/movq GPR -> XMM.
5547 if (isa_and_nonnull<Constant>(Op1) && Op1->getType()->isIntegerTy())
5548 return 2 + RegisterFileMoveCost;
5549 // Assume movd/movq GPR -> XMM is relatively cheap on all targets.
5550 return 1 + RegisterFileMoveCost;
5551 }
5552 }
5553
5554 // Assume movd/movq XMM -> GPR is relatively cheap on all targets.
5555 if (ScalarType->isIntegerTy() && Opcode == Instruction::ExtractElement)
5556 return 1 + RegisterFileMoveCost;
5557 }
5558
5559 int ISD = TLI->InstructionOpcodeToISD(Opcode);
5560 assert(ISD && "Unexpected vector opcode");
5561 if (ST->useSLMArithCosts())
5562 if (auto *Entry = CostTableLookup(SLMCostTbl, ISD, MScalarTy))
5563 return Entry->Cost + RegisterFileMoveCost;
5564
5565 // Consider cheap cases.
5566 if (IsCheapPInsrPExtrInsertPS())
5567 return 1 + RegisterFileMoveCost;
5568
5569 // For extractions we just need to shuffle the element to index 0, which
5570 // should be very cheap (assume cost = 1). For insertions we need to shuffle
5571 // the elements to its destination. In both cases we must handle the
5572 // subvector move(s).
5573 // If the vector type is already less than 128-bits then don't reduce it.
5574 // TODO: Under what circumstances should we shuffle using the full width?
5575 InstructionCost ShuffleCost = 1;
5576 if (Opcode == Instruction::InsertElement) {
5577 auto *SubTy = cast<VectorType>(Val);
5578 EVT VT = TLI->getValueType(DL, Val);
5579 if (VT.getScalarType() != MScalarTy || VT.getSizeInBits() >= 128)
5580 SubTy = FixedVectorType::get(ScalarType, SubNumElts);
5581 ShuffleCost = getShuffleCost(TTI::SK_PermuteTwoSrc, SubTy, SubTy,
5582 CostKind, {}, 0, SubTy);
5583 }
5584 int IntOrFpCost = ScalarType->isFloatingPointTy() ? 0 : 1;
5585 return ShuffleCost + IntOrFpCost + RegisterFileMoveCost;
5586 }
5587
5588 return BaseT::getVectorInstrCost(Opcode, Val, CostKind, Index, Op0, Op1,
5589 VIC) +
5590 RegisterFileMoveCost;
5591}
5592
5594 VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract,
5595 TTI::TargetCostKind CostKind, bool ForPoisonSrc, ArrayRef<Value *> VL,
5596 TTI::VectorInstrContext VIC) const {
5597 assert(DemandedElts.getBitWidth() ==
5598 cast<FixedVectorType>(Ty)->getNumElements() &&
5599 "Vector size mismatch");
5600
5601 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty);
5602 MVT MScalarTy = LT.second.getScalarType();
5603 unsigned LegalVectorBitWidth = LT.second.getSizeInBits();
5605 // The square roots, folded with the divisions into the estimate, are
5606 // computed separately to be inserted.
5607 if (Insert && !VL.empty())
5608 for (unsigned I : seq(DemandedElts.getBitWidth()))
5609 if (DemandedElts[I] &&
5610 isFoldedIntoRsqrtEstimate(VL[I], *TLI, MScalarTy, CostKind))
5612 IntrinsicCostAttributes(Intrinsic::sqrt, VL[I]->getType(),
5613 {VL[I]->getType()}),
5614 CostKind);
5615
5616 constexpr unsigned LaneBitWidth = 128;
5617 assert((LegalVectorBitWidth < LaneBitWidth ||
5618 (LegalVectorBitWidth % LaneBitWidth) == 0) &&
5619 "Illegal vector");
5620
5621 const int NumLegalVectors = LT.first.getValue();
5622 assert(NumLegalVectors >= 0 && "Negative cost!");
5623
5624 // For insertions, a ISD::BUILD_VECTOR style vector initialization can be much
5625 // cheaper than an accumulation of ISD::INSERT_VECTOR_ELT. SLPVectorizer has
5626 // a special heuristic regarding poison input which is passed here in
5627 // ForPoisonSrc.
5628 if (Insert && !ForPoisonSrc) {
5629 // This is nearly identical to BaseT::getScalarizationOverhead(), except
5630 // it is passing nullptr to getVectorInstrCost() for Op0 (instead of
5631 // Constant::getNullValue()), which makes the X86TTIImpl
5632 // getVectorInstrCost() return 0 instead of 1.
5633 for (unsigned I : seq(DemandedElts.getBitWidth())) {
5634 if (!DemandedElts[I])
5635 continue;
5636 Cost += getVectorInstrCost(Instruction::InsertElement, Ty, CostKind, I,
5638 VL.empty() ? nullptr : VL[I],
5640 }
5641 return Cost;
5642 }
5643
5644 if (Insert) {
5645 if ((MScalarTy == MVT::i16 && ST->hasSSE2()) ||
5646 (MScalarTy.isInteger() && ST->hasSSE41()) ||
5647 (MScalarTy == MVT::f32 && ST->hasSSE41())) {
5648 // For types we can insert directly, insertion into 128-bit sub vectors is
5649 // cheap, followed by a cheap chain of concatenations.
5650 if (LegalVectorBitWidth <= LaneBitWidth) {
5651 Cost += BaseT::getScalarizationOverhead(Ty, DemandedElts, Insert,
5652 /*Extract*/ false, CostKind);
5653 } else {
5654 // In each 128-lane, if at least one index is demanded but not all
5655 // indices are demanded and this 128-lane is not the first 128-lane of
5656 // the legalized-vector, then this 128-lane needs a extracti128; If in
5657 // each 128-lane, there is at least one demanded index, this 128-lane
5658 // needs a inserti128.
5659
5660 // The following cases will help you build a better understanding:
5661 // Assume we insert several elements into a v8i32 vector in avx2,
5662 // Case#1: inserting into 1th index needs vpinsrd + inserti128.
5663 // Case#2: inserting into 5th index needs extracti128 + vpinsrd +
5664 // inserti128.
5665 // Case#3: inserting into 4,5,6,7 index needs 4*vpinsrd + inserti128.
5666 assert((LegalVectorBitWidth % LaneBitWidth) == 0 && "Illegal vector");
5667 unsigned NumLegalLanes = LegalVectorBitWidth / LaneBitWidth;
5668 unsigned NumLanesTotal = NumLegalLanes * NumLegalVectors;
5669 unsigned NumLegalElts =
5670 LT.second.getVectorNumElements() * NumLegalVectors;
5671 assert(NumLegalElts >= DemandedElts.getBitWidth() &&
5672 "Vector has been legalized to smaller element count");
5673 assert((NumLegalElts % NumLanesTotal) == 0 &&
5674 "Unexpected elts per lane");
5675 unsigned NumEltsPerLane = NumLegalElts / NumLanesTotal;
5676
5677 APInt WidenedDemandedElts = DemandedElts.zext(NumLegalElts);
5678 auto *LaneTy =
5679 FixedVectorType::get(Ty->getElementType(), NumEltsPerLane);
5680
5681 for (unsigned I = 0; I != NumLanesTotal; ++I) {
5682 APInt LaneEltMask = WidenedDemandedElts.extractBits(
5683 NumEltsPerLane, NumEltsPerLane * I);
5684 if (LaneEltMask.isZero())
5685 continue;
5686 // FIXME: we don't need to extract if all non-demanded elements
5687 // are legalization-inserted padding.
5688 if (!LaneEltMask.isAllOnes())
5689 Cost += getShuffleCost(TTI::SK_ExtractSubvector, Ty, Ty, CostKind,
5690 {}, I * NumEltsPerLane, LaneTy);
5691 Cost += BaseT::getScalarizationOverhead(LaneTy, LaneEltMask, Insert,
5692 /*Extract*/ false, CostKind);
5693 }
5694
5695 APInt AffectedLanes =
5696 APIntOps::ScaleBitMask(WidenedDemandedElts, NumLanesTotal);
5697 APInt FullyAffectedLegalVectors = APIntOps::ScaleBitMask(
5698 AffectedLanes, NumLegalVectors, /*MatchAllBits=*/true);
5699 for (int LegalVec = 0; LegalVec != NumLegalVectors; ++LegalVec) {
5700 for (unsigned Lane = 0; Lane != NumLegalLanes; ++Lane) {
5701 unsigned I = NumLegalLanes * LegalVec + Lane;
5702 // No need to insert unaffected lane; or lane 0 of each legal vector
5703 // iff ALL lanes of that vector were affected and will be inserted.
5704 if (!AffectedLanes[I] ||
5705 (Lane == 0 && FullyAffectedLegalVectors[LegalVec]))
5706 continue;
5707 Cost += getShuffleCost(TTI::SK_InsertSubvector, Ty, Ty, CostKind,
5708 {}, I * NumEltsPerLane, LaneTy);
5709 }
5710 }
5711 }
5712 } else if (LT.second.isVector()) {
5713 // Without fast insertion, we need to use MOVD/MOVQ to pass each demanded
5714 // integer element as a SCALAR_TO_VECTOR, then we build the vector as a
5715 // series of UNPCK followed by CONCAT_VECTORS - all of these can be
5716 // considered cheap.
5717 if (Ty->isIntOrIntVectorTy())
5718 Cost += DemandedElts.popcount();
5719
5720 // Get the smaller of the legalized or original pow2-extended number of
5721 // vector elements, which represents the number of unpacks we'll end up
5722 // performing.
5723 unsigned NumElts = LT.second.getVectorNumElements();
5724 unsigned Pow2Elts =
5725 PowerOf2Ceil(cast<FixedVectorType>(Ty)->getNumElements());
5726 Cost += (std::min<unsigned>(NumElts, Pow2Elts) - 1) * LT.first;
5727 }
5728 }
5729
5730 if (Extract) {
5731 // vXi1 can be efficiently extracted with MOVMSK.
5732 // TODO: AVX512 predicate mask handling.
5733 // NOTE: This doesn't work well for roundtrip scalarization.
5734 if (!Insert && Ty->getScalarSizeInBits() == 1 && !ST->hasAVX512()) {
5735 unsigned NumElts = cast<FixedVectorType>(Ty)->getNumElements();
5736 unsigned MaxElts = ST->hasAVX2() ? 32 : 16;
5737 unsigned MOVMSKCost = (NumElts + MaxElts - 1) / MaxElts;
5738 return MOVMSKCost;
5739 }
5740
5741 if (LT.second.isVector()) {
5742 unsigned NumLegalElts =
5743 LT.second.getVectorNumElements() * NumLegalVectors;
5744 assert(NumLegalElts >= DemandedElts.getBitWidth() &&
5745 "Vector has been legalized to smaller element count");
5746
5747 // If we're extracting elements from a 128-bit subvector lane,
5748 // we only need to extract each lane once, not for every element.
5749 if (LegalVectorBitWidth > LaneBitWidth) {
5750 unsigned NumLegalLanes = LegalVectorBitWidth / LaneBitWidth;
5751 unsigned NumLanesTotal = NumLegalLanes * NumLegalVectors;
5752 assert((NumLegalElts % NumLanesTotal) == 0 &&
5753 "Unexpected elts per lane");
5754 unsigned NumEltsPerLane = NumLegalElts / NumLanesTotal;
5755
5756 // Add cost for each demanded 128-bit subvector extraction.
5757 // Luckily this is a lot easier than for insertion.
5758 APInt WidenedDemandedElts = DemandedElts.zext(NumLegalElts);
5759 auto *LaneTy =
5760 FixedVectorType::get(Ty->getElementType(), NumEltsPerLane);
5761
5762 for (unsigned I = 0; I != NumLanesTotal; ++I) {
5763 APInt LaneEltMask = WidenedDemandedElts.extractBits(
5764 NumEltsPerLane, I * NumEltsPerLane);
5765 if (LaneEltMask.isZero())
5766 continue;
5767 Cost += getShuffleCost(TTI::SK_ExtractSubvector, Ty, Ty, CostKind, {},
5768 I * NumEltsPerLane, LaneTy);
5770 LaneTy, LaneEltMask, /*Insert*/ false, Extract, CostKind);
5771 }
5772
5773 return Cost;
5774 }
5775 }
5776
5777 // Fallback to default extraction.
5778 Cost += BaseT::getScalarizationOverhead(Ty, DemandedElts, /*Insert*/ false,
5779 Extract, CostKind);
5780 }
5781
5782 return Cost;
5783}
5784
5786X86TTIImpl::getReplicationShuffleCost(Type *EltTy, int ReplicationFactor,
5787 int VF, const APInt &DemandedDstElts,
5788 TTI::TargetCostKind CostKind) const {
5789 const unsigned EltTyBits = DL.getTypeSizeInBits(EltTy);
5790 // We don't differentiate element types here, only element bit width.
5791 EltTy = IntegerType::getIntNTy(EltTy->getContext(), EltTyBits);
5792
5793 auto bailout = [&]() {
5794 return BaseT::getReplicationShuffleCost(EltTy, ReplicationFactor, VF,
5795 DemandedDstElts, CostKind);
5796 };
5797
5798 // For now, only deal with AVX512 cases.
5799 if (!ST->hasAVX512())
5800 return bailout();
5801
5802 // Do we have a native shuffle for this element type, or should we promote?
5803 unsigned PromEltTyBits = EltTyBits;
5804 switch (EltTyBits) {
5805 case 32:
5806 case 64:
5807 break; // AVX512F.
5808 case 16:
5809 if (!ST->hasBWI())
5810 PromEltTyBits = 32; // promote to i32, AVX512F.
5811 break; // AVX512BW
5812 case 8:
5813 if (!ST->hasVBMI())
5814 PromEltTyBits = 32; // promote to i32, AVX512F.
5815 break; // AVX512VBMI
5816 case 1:
5817 // There is no support for shuffling i1 elements. We *must* promote.
5818 if (ST->hasBWI()) {
5819 if (ST->hasVBMI())
5820 PromEltTyBits = 8; // promote to i8, AVX512VBMI.
5821 else
5822 PromEltTyBits = 16; // promote to i16, AVX512BW.
5823 break;
5824 }
5825 PromEltTyBits = 32; // promote to i32, AVX512F.
5826 break;
5827 default:
5828 return bailout();
5829 }
5830 auto *PromEltTy = IntegerType::getIntNTy(EltTy->getContext(), PromEltTyBits);
5831
5832 auto *SrcVecTy = FixedVectorType::get(EltTy, VF);
5833 auto *PromSrcVecTy = FixedVectorType::get(PromEltTy, VF);
5834
5835 int NumDstElements = VF * ReplicationFactor;
5836 auto *PromDstVecTy = FixedVectorType::get(PromEltTy, NumDstElements);
5837 auto *DstVecTy = FixedVectorType::get(EltTy, NumDstElements);
5838
5839 // Legalize the types.
5840 MVT LegalSrcVecTy = getTypeLegalizationCost(SrcVecTy).second;
5841 MVT LegalPromSrcVecTy = getTypeLegalizationCost(PromSrcVecTy).second;
5842 MVT LegalPromDstVecTy = getTypeLegalizationCost(PromDstVecTy).second;
5843 MVT LegalDstVecTy = getTypeLegalizationCost(DstVecTy).second;
5844 // They should have legalized into vector types.
5845 if (!LegalSrcVecTy.isVector() || !LegalPromSrcVecTy.isVector() ||
5846 !LegalPromDstVecTy.isVector() || !LegalDstVecTy.isVector())
5847 return bailout();
5848
5849 if (PromEltTyBits != EltTyBits) {
5850 // If we have to perform the shuffle with wider elt type than our data type,
5851 // then we will first need to anyext (we don't care about the new bits)
5852 // the source elements, and then truncate Dst elements.
5853 InstructionCost PromotionCost;
5854 PromotionCost += getCastInstrCost(
5855 Instruction::SExt, /*Dst=*/PromSrcVecTy, /*Src=*/SrcVecTy,
5857 PromotionCost +=
5858 getCastInstrCost(Instruction::Trunc, /*Dst=*/DstVecTy,
5859 /*Src=*/PromDstVecTy,
5861 return PromotionCost + getReplicationShuffleCost(PromEltTy,
5862 ReplicationFactor, VF,
5863 DemandedDstElts, CostKind);
5864 }
5865
5866 assert(LegalSrcVecTy.getScalarSizeInBits() == EltTyBits &&
5867 LegalSrcVecTy.getScalarType() == LegalDstVecTy.getScalarType() &&
5868 "We expect that the legalization doesn't affect the element width, "
5869 "doesn't coalesce/split elements.");
5870
5871 unsigned NumEltsPerDstVec = LegalDstVecTy.getVectorNumElements();
5872 unsigned NumDstVectors =
5873 divideCeil(DstVecTy->getNumElements(), NumEltsPerDstVec);
5874
5875 auto *SingleDstVecTy = FixedVectorType::get(EltTy, NumEltsPerDstVec);
5876
5877 // Not all the produced Dst elements may be demanded. In our case,
5878 // given that a single Dst vector is formed by a single shuffle,
5879 // if all elements that will form a single Dst vector aren't demanded,
5880 // then we won't need to do that shuffle, so adjust the cost accordingly.
5881 APInt DemandedDstVectors = APIntOps::ScaleBitMask(
5882 DemandedDstElts.zext(NumDstVectors * NumEltsPerDstVec), NumDstVectors);
5883 unsigned NumDstVectorsDemanded = DemandedDstVectors.popcount();
5884
5885 InstructionCost SingleShuffleCost =
5886 getShuffleCost(TTI::SK_PermuteSingleSrc, SingleDstVecTy, SingleDstVecTy,
5887 CostKind, /*Mask=*/{},
5888 /*Index=*/0, /*SubTp=*/nullptr);
5889 return NumDstVectorsDemanded * SingleShuffleCost;
5890}
5891
5893 Align Alignment,
5894 unsigned AddressSpace,
5895 TTI::TargetCostKind CostKind,
5896 TTI::OperandValueInfo OpInfo,
5897 const Instruction *I) const {
5898 // FIXME: Load latency isn't handled here
5899 if (Opcode == Instruction::Load && CostKind == TTI::TCK_Latency)
5900 return BaseT::getMemoryOpCost(Opcode, Src, Alignment, AddressSpace,
5901 CostKind, OpInfo, I);
5902
5903 // TODO: Handle other cost kinds.
5904 if (CostKind != TTI::TCK_RecipThroughput) {
5905 if (auto *SI = dyn_cast_or_null<StoreInst>(I)) {
5906 // Store instruction with index and scale costs 2 Uops.
5907 // Check the preceding GEP to identify non-const indices.
5908 if (auto *GEP = dyn_cast<GetElementPtrInst>(SI->getPointerOperand())) {
5909 if (!all_of(GEP->indices(), [](Value *V) { return isa<Constant>(V); }))
5910 return TTI::TCC_Basic * 2;
5911 }
5912 }
5913 return TTI::TCC_Basic;
5914 }
5915
5916 assert((Opcode == Instruction::Load || Opcode == Instruction::Store) &&
5917 "Invalid Opcode");
5918 // Type legalization can't handle structs
5919 if (TLI->getValueType(DL, Src, true) == MVT::Other)
5920 return BaseT::getMemoryOpCost(Opcode, Src, Alignment, AddressSpace,
5921 CostKind, OpInfo, I);
5922
5923 // Legalize the type.
5924 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Src);
5925
5926 auto *VTy = dyn_cast<FixedVectorType>(Src);
5927
5929
5930 // Add a cost for constant load to vector.
5931 if (Opcode == Instruction::Store && OpInfo.isConstant())
5932 Cost += getMemoryOpCost(Instruction::Load, Src, DL.getABITypeAlign(Src),
5933 /*AddressSpace=*/0, CostKind, OpInfo);
5934
5935 // Handle the simple case of non-vectors.
5936 // NOTE: this assumes that legalization never creates vector from scalars!
5937 if (!VTy || !LT.second.isVector()) {
5938 // Each load/store unit costs 1.
5939 return (LT.second.isFloatingPoint() ? Cost : 0) + LT.first * 1;
5940 }
5941
5942 bool IsLoad = Opcode == Instruction::Load;
5943
5944 Type *EltTy = VTy->getElementType();
5945
5946 const int EltTyBits = DL.getTypeSizeInBits(EltTy);
5947
5948 // Source of truth: how many elements were there in the original IR vector?
5949 const unsigned SrcNumElt = VTy->getNumElements();
5950
5951 // How far have we gotten?
5952 int NumEltRemaining = SrcNumElt;
5953 // Note that we intentionally capture by-reference, NumEltRemaining changes.
5954 auto NumEltDone = [&]() { return SrcNumElt - NumEltRemaining; };
5955
5956 const int MaxLegalOpSizeBytes = divideCeil(LT.second.getSizeInBits(), 8);
5957
5958 // Note that even if we can store 64 bits of an XMM, we still operate on XMM.
5959 const unsigned XMMBits = 128;
5960 if (XMMBits % EltTyBits != 0)
5961 // Vector size must be a multiple of the element size. I.e. no padding.
5962 return BaseT::getMemoryOpCost(Opcode, Src, Alignment, AddressSpace,
5963 CostKind, OpInfo, I);
5964 const int NumEltPerXMM = XMMBits / EltTyBits;
5965
5966 auto *XMMVecTy = FixedVectorType::get(EltTy, NumEltPerXMM);
5967
5968 for (int CurrOpSizeBytes = MaxLegalOpSizeBytes, SubVecEltsLeft = 0;
5969 NumEltRemaining > 0; CurrOpSizeBytes /= 2) {
5970 // How many elements would a single op deal with at once?
5971 if ((8 * CurrOpSizeBytes) % EltTyBits != 0)
5972 // Vector size must be a multiple of the element size. I.e. no padding.
5973 return BaseT::getMemoryOpCost(Opcode, Src, Alignment, AddressSpace,
5974 CostKind, OpInfo, I);
5975 int CurrNumEltPerOp = (8 * CurrOpSizeBytes) / EltTyBits;
5976
5977 assert(CurrOpSizeBytes > 0 && CurrNumEltPerOp > 0 && "How'd we get here?");
5978 assert((((NumEltRemaining * EltTyBits) < (2 * 8 * CurrOpSizeBytes)) ||
5979 (CurrOpSizeBytes == MaxLegalOpSizeBytes)) &&
5980 "Unless we haven't halved the op size yet, "
5981 "we have less than two op's sized units of work left.");
5982
5983 auto *CurrVecTy = CurrNumEltPerOp > NumEltPerXMM
5984 ? FixedVectorType::get(EltTy, CurrNumEltPerOp)
5985 : XMMVecTy;
5986
5987 assert(CurrVecTy->getNumElements() % CurrNumEltPerOp == 0 &&
5988 "After halving sizes, the vector elt count is no longer a multiple "
5989 "of number of elements per operation?");
5990 auto *CoalescedVecTy =
5991 CurrNumEltPerOp == 1
5992 ? CurrVecTy
5994 IntegerType::get(Src->getContext(),
5995 EltTyBits * CurrNumEltPerOp),
5996 CurrVecTy->getNumElements() / CurrNumEltPerOp);
5997 assert(DL.getTypeSizeInBits(CoalescedVecTy) ==
5998 DL.getTypeSizeInBits(CurrVecTy) &&
5999 "coalesciing elements doesn't change vector width.");
6000
6001 while (NumEltRemaining > 0) {
6002 assert(SubVecEltsLeft >= 0 && "Subreg element count overconsumtion?");
6003
6004 // Can we use this vector size, as per the remaining element count?
6005 // Iff the vector is naturally aligned, we can do a wide load regardless.
6006 if (NumEltRemaining < CurrNumEltPerOp &&
6007 (!IsLoad || Alignment < CurrOpSizeBytes) && CurrOpSizeBytes != 1)
6008 break; // Try smalled vector size.
6009
6010 // This isn't exactly right. We're using slow unaligned 32-byte accesses
6011 // as a proxy for a double-pumped AVX memory interface such as on
6012 // Sandybridge.
6013 // Sub-32-bit loads/stores will be slower either with PINSR*/PEXTR* or
6014 // will be scalarized.
6015 //
6016 // For a vector load, each non-0th 1/2/4-byte in-lane remainder chunk is
6017 // materialized by a *single* folded PINSR*(mem) that both loads and
6018 // inserts the lane (1B->PINSRB, 2B->PINSRW, 4B->PINSRD; the byte and
6019 // dword folds need SSE4.1, the word fold only SSE2).
6020 // When that fold is available the chunk is one instruction, so it must be
6021 // priced once here (as a plain load) and the separate lane-insert charge
6022 // below must be skipped - otherwise the folded insert is double-counted.
6023 // Stores (the symmetric PEXTR*(mem) fold) are left unchanged here.
6024 bool Is0thSubVec = (NumEltDone() % LT.second.getVectorNumElements()) == 0;
6025 bool FoldedInLaneInsert = IsLoad && !Is0thSubVec &&
6026 ((CurrOpSizeBytes == 1 && ST->hasSSE41()) ||
6027 (CurrOpSizeBytes == 2 && ST->hasSSE2()) ||
6028 (CurrOpSizeBytes == 4 && ST->hasSSE41()));
6029 if (CurrOpSizeBytes == 32 && ST->isUnalignedMem32Slow())
6030 Cost += 2;
6031 else if (CurrOpSizeBytes < 4 && !FoldedInLaneInsert)
6032 Cost += 2;
6033 else
6034 Cost += 1;
6035
6036 // If we're loading a uniform value, then we don't need to split the load,
6037 // loading just a single (widest) vector can be reused by all splits.
6038 if (IsLoad && OpInfo.isUniform())
6039 return Cost;
6040
6041 // If we have fully processed the previous reg, we need to replenish it.
6042 if (SubVecEltsLeft == 0) {
6043 SubVecEltsLeft += CurrVecTy->getNumElements();
6044 // And that's free only for the 0'th subvector of a legalized vector.
6045 if (!Is0thSubVec)
6046 Cost +=
6049 VTy, VTy, CostKind, {}, NumEltDone(), CurrVecTy);
6050 }
6051
6052 // While we can directly load/store ZMM, YMM, and 64-bit halves of XMM,
6053 // for smaller widths (32/16/8) we have to insert/extract them separately.
6054 // Again, it's free for the 0'th subreg (if op is 32/64 bit wide,
6055 // but let's pretend that it is also true for 16/8 bit wide ops...)
6056 if (CurrOpSizeBytes <= 32 / 8 && !Is0thSubVec && !FoldedInLaneInsert) {
6057 int NumEltDoneInCurrXMM = NumEltDone() % NumEltPerXMM;
6058 assert(NumEltDoneInCurrXMM % CurrNumEltPerOp == 0 && "");
6059 int CoalescedVecEltIdx = NumEltDoneInCurrXMM / CurrNumEltPerOp;
6060 APInt DemandedElts =
6061 APInt::getBitsSet(CoalescedVecTy->getNumElements(),
6062 CoalescedVecEltIdx, CoalescedVecEltIdx + 1);
6063 assert(DemandedElts.popcount() == 1 && "Inserting single value");
6064 Cost += getScalarizationOverhead(CoalescedVecTy, DemandedElts, IsLoad,
6065 !IsLoad, CostKind);
6066 }
6067
6068 SubVecEltsLeft -= CurrNumEltPerOp;
6069 NumEltRemaining -= CurrNumEltPerOp;
6070 Alignment = commonAlignment(Alignment, CurrOpSizeBytes);
6071 }
6072 }
6073
6074 assert(NumEltRemaining <= 0 && "Should have processed all the elements.");
6075
6076 return Cost;
6077}
6078
6081 TTI::TargetCostKind CostKind) const {
6082 switch (MICA.getID()) {
6083 case Intrinsic::masked_scatter:
6084 case Intrinsic::masked_gather:
6085 return getGatherScatterOpCost(MICA, CostKind);
6086 case Intrinsic::masked_load:
6087 case Intrinsic::masked_store:
6088 return getMaskedMemoryOpCost(MICA, CostKind);
6089 case Intrinsic::masked_compressstore:
6090 // Fallback to scalarization for slow compressstore targets (e.g. znver4).
6091 if (ST->isVecCompressStoreSlow())
6092 return BaseT::getMemIntrinsicInstrCost(MICA, CostKind);
6093 break;
6094 }
6095
6096 static const CostKindTblEntry AVX512VBMI2CostTable[] = {
6097 { Intrinsic::masked_expandload, MVT::v16i8, { 2, 7, 1, 3 } },
6098 { Intrinsic::masked_expandload, MVT::v32i8, { 2, 8, 1, 3 } },
6099 { Intrinsic::masked_expandload, MVT::v64i8, { 2, 9, 1, 3 } },
6100
6101 { Intrinsic::masked_expandload, MVT::v8i16, { 2, 7, 1, 3 } },
6102 { Intrinsic::masked_expandload, MVT::v16i16, { 2, 8, 1, 3 } },
6103 { Intrinsic::masked_expandload, MVT::v32i16, { 2, 9, 1, 3 } },
6104
6105 { Intrinsic::masked_expandload, MVT::v8f16, { 2, 7, 1, 3 } },
6106 { Intrinsic::masked_expandload, MVT::v16f16, { 2, 8, 1, 3 } },
6107 { Intrinsic::masked_expandload, MVT::v32f16, { 2, 9, 1, 3 } },
6108
6109 { Intrinsic::masked_expandload, MVT::v8bf16, { 2, 7, 1, 3 } },
6110 { Intrinsic::masked_expandload, MVT::v16bf16,{ 2, 8, 1, 3 } },
6111 { Intrinsic::masked_expandload, MVT::v32bf16,{ 2, 9, 1, 3 } },
6112
6113 { Intrinsic::masked_compressstore, MVT::v16i8, { 3,10, 1, 7 } },
6114 { Intrinsic::masked_compressstore, MVT::v32i8, { 3,11, 1, 7 } },
6115 { Intrinsic::masked_compressstore, MVT::v64i8, { 3,12, 1, 8 } },
6116
6117 { Intrinsic::masked_compressstore, MVT::v8i16, { 3,10, 1, 7 } },
6118 { Intrinsic::masked_compressstore, MVT::v16i16, { 3,11, 1, 7 } },
6119 { Intrinsic::masked_compressstore, MVT::v32i16, { 3,12, 1, 8 } },
6120
6121 { Intrinsic::masked_compressstore, MVT::v8f16, { 3,10, 1, 7 } },
6122 { Intrinsic::masked_compressstore, MVT::v16f16, { 3,11, 1, 7 } },
6123 { Intrinsic::masked_compressstore, MVT::v32f16, { 3,12, 1, 8 } },
6124
6125 { Intrinsic::masked_compressstore, MVT::v8bf16, { 3,10, 1, 7 } },
6126 { Intrinsic::masked_compressstore, MVT::v16bf16,{ 3,11, 1, 7 } },
6127 { Intrinsic::masked_compressstore, MVT::v32bf16,{ 3,12, 1, 8 } },
6128 };
6129
6130 static const CostKindTblEntry AVX512CostTable[] = {
6131 { Intrinsic::masked_expandload, MVT::v4i32, { 2, 7, 1, 3 } },
6132 { Intrinsic::masked_expandload, MVT::v4f32, { 2, 7, 1, 3 } },
6133 { Intrinsic::masked_expandload, MVT::v8i32, { 2, 8, 1, 3 } },
6134 { Intrinsic::masked_expandload, MVT::v8f32, { 2, 8, 1, 3 } },
6135 { Intrinsic::masked_expandload, MVT::v16i32, { 2, 9, 1, 3 } },
6136 { Intrinsic::masked_expandload, MVT::v16f32, { 2, 9, 1, 3 } },
6137
6138 { Intrinsic::masked_expandload, MVT::v2i64, { 2, 7, 1, 3 } },
6139 { Intrinsic::masked_expandload, MVT::v2f64, { 2, 7, 1, 3 } },
6140 { Intrinsic::masked_expandload, MVT::v4i64, { 2, 8, 1, 3 } },
6141 { Intrinsic::masked_expandload, MVT::v4f64, { 2, 8, 1, 3 } },
6142 { Intrinsic::masked_expandload, MVT::v8i64, { 2, 9, 1, 3 } },
6143 { Intrinsic::masked_expandload, MVT::v8f64, { 2, 9, 1, 3 } },
6144
6145 { Intrinsic::masked_compressstore, MVT::v4i32, { 3,10, 1, 7 } },
6146 { Intrinsic::masked_compressstore, MVT::v4f32, { 3,10, 1, 7 } },
6147 { Intrinsic::masked_compressstore, MVT::v8i32, { 3,11, 1, 7 } },
6148 { Intrinsic::masked_compressstore, MVT::v8f32, { 3,11, 1, 7 } },
6149 { Intrinsic::masked_compressstore, MVT::v16i32, { 3,12, 1, 8 } },
6150 { Intrinsic::masked_compressstore, MVT::v16f32, { 3,12, 1, 8 } },
6151
6152 { Intrinsic::masked_compressstore, MVT::v2i64, { 3,10, 1, 7 } },
6153 { Intrinsic::masked_compressstore, MVT::v2f64, { 3,10, 1, 7 } },
6154 { Intrinsic::masked_compressstore, MVT::v4i64, { 3,11, 1, 7 } },
6155 { Intrinsic::masked_compressstore, MVT::v4f64, { 3,11, 1, 7 } },
6156 { Intrinsic::masked_compressstore, MVT::v8i64, { 3,12, 1, 8 } },
6157 { Intrinsic::masked_compressstore, MVT::v8f64, { 3,12, 1, 8 } },
6158 };
6159
6160 std::pair<InstructionCost, MVT> LT =
6162
6163 if (ST->hasVBMI2())
6164 if (const auto *Entry =
6165 CostTableLookup(AVX512VBMI2CostTable, MICA.getID(), LT.second))
6166 if (auto KindCost = Entry->Cost[CostKind])
6167 return LT.first * *KindCost;
6168
6169 if (ST->hasAVX512())
6170 if (const auto *Entry =
6171 CostTableLookup(AVX512CostTable, MICA.getID(), LT.second))
6172 if (auto KindCost = Entry->Cost[CostKind])
6173 return LT.first * *KindCost;
6174
6175 return BaseT::getMemIntrinsicInstrCost(MICA, CostKind);
6176}
6177
6180 TTI::TargetCostKind CostKind) const {
6181 unsigned Opcode = MICA.getID() == Intrinsic::masked_load ? Instruction::Load
6182 : Instruction::Store;
6183 Type *SrcTy = MICA.getDataType();
6184 Align Alignment = MICA.getAlignment();
6185 unsigned AddressSpace = MICA.getAddressSpace();
6186
6187 bool IsLoad = (Instruction::Load == Opcode);
6188 bool IsStore = (Instruction::Store == Opcode);
6189
6190 auto *SrcVTy = dyn_cast<FixedVectorType>(SrcTy);
6191 if (!SrcVTy)
6192 // To calculate scalar take the regular cost, without mask
6193 return getMemoryOpCost(Opcode, SrcTy, Alignment, AddressSpace, CostKind);
6194
6195 unsigned NumElem = SrcVTy->getNumElements();
6196 auto *MaskTy =
6197 FixedVectorType::get(Type::getInt8Ty(SrcVTy->getContext()), NumElem);
6198 if ((IsLoad && !isLegalMaskedLoad(SrcVTy, Alignment, AddressSpace)) ||
6199 (IsStore && !isLegalMaskedStore(SrcVTy, Alignment, AddressSpace))) {
6200 // Scalarization
6201 APInt DemandedElts = APInt::getAllOnes(NumElem);
6203 MaskTy, DemandedElts, /*Insert*/ false, /*Extract*/ true, CostKind);
6204 InstructionCost ScalarCompareCost = getCmpSelInstrCost(
6205 Instruction::ICmp, Type::getInt8Ty(SrcVTy->getContext()), nullptr,
6206 CmpInst::BAD_ICMP_PREDICATE, CostKind);
6207 InstructionCost BranchCost = getCFInstrCost(Instruction::CondBr, CostKind);
6208 InstructionCost MaskCmpCost = NumElem * (BranchCost + ScalarCompareCost);
6210 SrcVTy, DemandedElts, IsLoad, IsStore, CostKind);
6211 InstructionCost MemopCost =
6212 NumElem * BaseT::getMemoryOpCost(Opcode, SrcVTy->getScalarType(),
6213 Alignment, AddressSpace, CostKind);
6214 return MemopCost + ValueSplitCost + MaskSplitCost + MaskCmpCost;
6215 }
6216
6217 // Legalize the type.
6218 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(SrcVTy);
6219 auto VT = TLI->getValueType(DL, SrcVTy);
6221 MVT Ty = LT.second;
6222 if (Ty == MVT::i16 || Ty == MVT::i32 || Ty == MVT::i64)
6223 // APX masked load/store for scalar is cheap.
6224 return Cost + LT.first;
6225
6226 if (VT.isSimple() && Ty != VT.getSimpleVT() &&
6227 LT.second.getVectorNumElements() == NumElem)
6228 // Promotion requires extend/truncate for data and a shuffle for mask.
6229 Cost += getShuffleCost(TTI::SK_PermuteTwoSrc, SrcVTy, SrcVTy, CostKind, {},
6230 0, nullptr) +
6231 getShuffleCost(TTI::SK_PermuteTwoSrc, MaskTy, MaskTy, CostKind, {},
6232 0, nullptr);
6233
6234 else if (LT.first * Ty.getVectorNumElements() > NumElem) {
6235 auto *NewMaskTy = FixedVectorType::get(MaskTy->getElementType(),
6236 (unsigned)LT.first.getValue() *
6237 Ty.getVectorNumElements());
6238 // Expanding requires fill mask with zeroes
6239 Cost += getShuffleCost(TTI::SK_InsertSubvector, NewMaskTy, NewMaskTy,
6240 CostKind, {}, 0, MaskTy);
6241 }
6242
6243 // Predicate fanout (see getPredicateFanoutCost): only a variable mask needs
6244 // a per-part sub-mask; a constant mask is folded by codegen and pays nothing.
6245 InstructionCost MaskExpCost = 0;
6246 if (MICA.getVariableMask()) {
6247 auto *MaskVecTy =
6248 FixedVectorType::get(Type::getInt1Ty(SrcVTy->getContext()), NumElem);
6249 MaskExpCost = getPredicateFanoutCost(*this, SrcVTy, MaskVecTy);
6250 }
6251
6252 // Pre-AVX512 - each maskmov load costs 2 + store costs ~8.
6253 if (!ST->hasAVX512())
6254 return Cost + LT.first * (IsLoad ? 2 : 8) + MaskExpCost;
6255
6256 // AVX-512 masked load/store is cheaper.
6257 return Cost + LT.first + MaskExpCost;
6258}
6259
6261 ArrayRef<const Value *> Ptrs, const Value *Base,
6262 const TTI::PointersChainInfo &Info, Type *AccessTy,
6263 const TTI::TargetCostKind CostKind) const {
6264 if (Info.isSameBase() && Info.isKnownStride()) {
6265 // If all the pointers have known stride all the differences are translated
6266 // into constants. X86 memory addressing allows encoding it into
6267 // displacement. So we just need to take the base GEP cost.
6268 if (const auto *BaseGEP = dyn_cast<GetElementPtrInst>(Base)) {
6269 SmallVector<const Value *> Indices(BaseGEP->indices());
6270 return getGEPCost(BaseGEP->getSourceElementType(),
6271 BaseGEP->getPointerOperand(), Indices, CostKind,
6272 nullptr);
6273 }
6274 return TTI::TCC_Free;
6275 }
6276 return BaseT::getPointersChainCost(Ptrs, Base, Info, AccessTy, CostKind);
6277}
6278
6281 const SCEV *Ptr,
6282 TTI::TargetCostKind CostKind) const {
6283 // Address computations in vectorized code with non-consecutive addresses will
6284 // likely result in more instructions compared to scalar code where the
6285 // computation can more often be merged into the index mode. The resulting
6286 // extra micro-ops can significantly decrease throughput.
6287 const unsigned NumVectorInstToHideOverhead = 10;
6288
6289 // Cost modeling of Strided Access Computation is hidden by the indexing
6290 // modes of X86 regardless of the stride value. We dont believe that there
6291 // is a difference between constant strided access in gerenal and constant
6292 // strided value which is less than or equal to 64.
6293 // Even in the case of (loop invariant) stride whose value is not known at
6294 // compile time, the address computation will not incur more than one extra
6295 // ADD instruction.
6296 if (PtrTy->isVectorTy() && SE) {
6298 return 1;
6299 if (!ST->hasAVX2()) {
6300 // TODO: AVX2 is the current cut-off because we don't have correct
6301 // interleaving costs for prior ISA's.
6302 if (!BaseT::isStridedAccess(Ptr))
6303 return NumVectorInstToHideOverhead;
6304 }
6305 }
6306
6307 return BaseT::getAddressComputationCost(PtrTy, SE, Ptr, CostKind);
6308}
6309
6311 unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
6313 TTI::PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp,
6314 TTI::TargetCostKind CostKind, std::optional<FastMathFlags> FMF) const {
6315 auto ExpandCost = [&]() {
6316 return BaseT::getPartialReductionCost(Opcode, InputTypeA, InputTypeB,
6317 AccumType, VF, OpAExtend, OpBExtend,
6318 BinOp, CostKind, FMF);
6319 };
6320
6321 // The dot product instructions multiply-accumulate i8 x i8 -> i32,
6322 // i16 x i16 -> i32, bf16 x bf16 -> f32 or f16 x f16 -> f32. Partial
6323 // reductions may also multiply inputs extended from different types, which
6324 // they can't handle.
6325 if (VF.isScalable() || !BinOp || OpAExtend == TTI::PR_None ||
6326 OpBExtend == TTI::PR_None || InputTypeA != InputTypeB)
6327 return ExpandCost();
6328
6329 unsigned Opc;
6330 if (Opcode == Instruction::Add && *BinOp == Instruction::Mul &&
6331 AccumType->isIntegerTy(32) &&
6332 (InputTypeA->isIntegerTy(8) || InputTypeA->isIntegerTy(16))) {
6333 if (OpAExtend != OpBExtend)
6335 else if (OpAExtend == TTI::PR_SignExtend)
6337 else
6339 } else if (Opcode == Instruction::FAdd && *BinOp == Instruction::FMul &&
6340 AccumType->isFloatTy() &&
6341 (InputTypeA->isBFloatTy() || InputTypeA->isHalfTy())) {
6342 // VDPBF16PS and VDPPHPS, like the expansion, reassociate the additions and
6343 // fuse the multiplications.
6344 if (!FMF || !FMF->allowReassoc() || !FMF->allowContract())
6347 } else {
6348 return ExpandCost();
6349 }
6350
6351 unsigned Ratio =
6352 AccumType->getScalarSizeInBits() / InputTypeA->getScalarSizeInBits();
6353 if (!VF.isKnownMultipleOf(Ratio))
6354 return ExpandCost();
6355
6356 // One dot product per legal accumulator vector. Accumulators narrower than
6357 // a legal vector are widened by expanding the partial reduction instead.
6358 auto *AccVecTy = VectorType::get(AccumType, VF.divideCoefficientBy(Ratio));
6359 auto *InputVecTy = VectorType::get(InputTypeA, VF);
6360 std::pair<InstructionCost, MVT> AccLT = getTypeLegalizationCost(AccVecTy);
6361 std::pair<InstructionCost, MVT> InputLT = getTypeLegalizationCost(InputVecTy);
6362 if (AccLT.second.getFixedSizeInBits() >
6363 AccVecTy->getPrimitiveSizeInBits().getFixedValue() ||
6364 !TLI->isPartialReduceMLALegalOrCustom(Opc, AccLT.second, InputLT.second))
6365 return ExpandCost();
6366
6367 // Without VNNI, the signed i16 dot product is a PMADDWD and an ADD, which
6368 // cost about the same.
6369 if (Opc == ISD::PARTIAL_REDUCE_SMLA && InputTypeA->isIntegerTy(16) &&
6370 !ST->hasVNNI() && !ST->hasAVXVNNI())
6371 return 2 * getArithmeticInstrCost(Instruction::Add, AccVecTy, CostKind);
6372
6373 return AccLT.first;
6374}
6375
6378 std::optional<FastMathFlags> FMF,
6379 TTI::TargetCostKind CostKind) const {
6381 return BaseT::getArithmeticReductionCost(Opcode, ValTy, FMF, CostKind);
6382
6383 // We use llvm-mca across all supported CPUs to measure the logic cost stats.
6384 // We use the Intel Architecture Code Analyzer(IACA) to measure the throughput
6385 // and make it as the cost. TODO: Update old IACA numbers to llvm-mca.
6386
6387 static const CostKindTblEntry SLMCostTbl[] = {
6388 { ISD::FADD, MVT::v2f64, {3, 3, 3, 3} },
6389 { ISD::ADD, MVT::v2i64, {5, 5, 5, 5} },
6390 };
6391
6392 static const CostKindTblEntry SSE2CostTbl[] = {
6393 { ISD::FADD, MVT::v2f64, {2, 2, 2, 2} },
6394 { ISD::FADD, MVT::v2f32, {2, 2, 2, 2} },
6395 { ISD::FADD, MVT::v4f32, {4, 4, 4, 4} },
6396 { ISD::ADD, MVT::v2i64, {2, 2, 2, 2} }, // The data reported by the IACA tool is "1.6".
6397 { ISD::ADD, MVT::v2i32, {2, 2, 2, 2} }, // FIXME: chosen to be less than v4i32
6398 { ISD::ADD, MVT::v4i32, {3, 3, 3, 3} }, // The data reported by the IACA tool is "3.3".
6399 { ISD::ADD, MVT::v2i16, {2, 2, 2, 2} }, // The data reported by the IACA tool is "4.3".
6400 { ISD::ADD, MVT::v4i16, {3, 3, 3, 3} }, // The data reported by the IACA tool is "4.3".
6401 { ISD::ADD, MVT::v8i16, {4, 4, 4, 4} }, // The data reported by the IACA tool is "4.3".
6402 { ISD::ADD, MVT::v2i8, {2, 2, 2, 2} },
6403 { ISD::ADD, MVT::v4i8, {2, 2, 2, 2} },
6404 { ISD::ADD, MVT::v8i8, {2, 2, 2, 2} },
6405 { ISD::ADD, MVT::v16i8, {3, 3, 3, 3} },
6406
6407 { ISD::AND, MVT::v2i64, {2, 2, 3, 3} },
6408 { ISD::AND, MVT::v4i32, {3, 4, 5, 5} },
6409 { ISD::AND, MVT::v8i16, {4, 7, 8, 8} },
6410 { ISD::AND, MVT::v16i8, {6,10,11,11} },
6411 { ISD::OR, MVT::v2i64, {2, 2, 3, 3} },
6412 { ISD::OR, MVT::v4i32, {3, 4, 5, 5} },
6413 { ISD::OR, MVT::v8i16, {4, 7, 8, 8} },
6414 { ISD::OR, MVT::v16i8, {6,10,11,11} },
6415 { ISD::XOR, MVT::v2i64, {2, 2, 3, 3} },
6416 { ISD::XOR, MVT::v4i32, {3, 4, 5, 5} },
6417 { ISD::XOR, MVT::v8i16, {4, 7, 8, 8} },
6418 { ISD::XOR, MVT::v16i8, {6,10,11,11} },
6419 };
6420
6421 static const CostKindTblEntry AVX1CostTbl[] = {
6422 { ISD::FADD, MVT::v4f64, {3, 3, 3, 3} },
6423 { ISD::FADD, MVT::v4f32, {3, 3, 3, 3} },
6424 { ISD::FADD, MVT::v8f32, {4, 4, 4, 4} },
6425 { ISD::ADD, MVT::v2i64, {1, 1, 1, 1} }, // The data reported by the IACA tool is "1.5".
6426 { ISD::ADD, MVT::v4i64, {3, 3, 3, 3} },
6427 { ISD::ADD, MVT::v8i32, {5, 5, 5, 5} },
6428 { ISD::ADD, MVT::v16i16, {5, 5, 5, 5} },
6429 { ISD::ADD, MVT::v32i8, {4, 4, 4, 4} },
6430
6431 { ISD::AND, MVT::v4i64, {3, 7, 5, 5} },
6432 { ISD::AND, MVT::v8i32, {4, 9, 7, 7} },
6433 { ISD::AND, MVT::v16i16, {5,11, 9, 9} },
6434 { ISD::AND, MVT::v8i16, {4, 7, 7, 7} },
6435 { ISD::AND, MVT::v32i8, {6,13,11,11} },
6436 { ISD::AND, MVT::v16i8, {5,10, 9, 9} },
6437 { ISD::OR, MVT::v4i64, {3, 7, 5, 5} },
6438 { ISD::OR, MVT::v8i32, {4, 9, 7, 7} },
6439 { ISD::OR, MVT::v16i16, {5,11, 9, 9} },
6440 { ISD::OR, MVT::v8i16, {4, 7, 7, 7} },
6441 { ISD::OR, MVT::v32i8, {6,13,11,11} },
6442 { ISD::OR, MVT::v16i8, {5,10, 9, 9} },
6443 { ISD::XOR, MVT::v4i64, {3, 7, 5, 5} },
6444 { ISD::XOR, MVT::v8i32, {4, 9, 7, 7} },
6445 { ISD::XOR, MVT::v16i16, {5,11, 9, 9} },
6446 { ISD::XOR, MVT::v8i16, {4, 7, 7, 7} },
6447 { ISD::XOR, MVT::v32i8, {6,13,11,11} },
6448 { ISD::XOR, MVT::v16i8, {5,10, 9, 9} },
6449 };
6450
6451 static const CostKindTblEntry AVX2CostTbl[] = {
6452 { ISD::AND, MVT::v4i64, {2, 7, 5, 5} },
6453 { ISD::AND, MVT::v2i64, {1, 2, 3, 3} },
6454 { ISD::AND, MVT::v8i32, {3, 9, 7, 7} },
6455 { ISD::AND, MVT::v4i32, {2, 4, 5, 5} },
6456 { ISD::AND, MVT::v16i16, {3,11, 9, 9} },
6457 { ISD::AND, MVT::v8i16, {2, 6, 7, 7} },
6458 { ISD::AND, MVT::v32i8, {3,13,11,11} },
6459 { ISD::AND, MVT::v16i8, {3, 8, 9, 9} },
6460 { ISD::OR, MVT::v4i64, {2, 7, 5, 5} },
6461 { ISD::OR, MVT::v2i64, {1, 2, 3, 3} },
6462 { ISD::OR, MVT::v8i32, {3, 9, 7, 7} },
6463 { ISD::OR, MVT::v4i32, {2, 4, 5, 5} },
6464 { ISD::OR, MVT::v16i16, {3,11, 9, 9} },
6465 { ISD::OR, MVT::v8i16, {2, 6, 7, 7} },
6466 { ISD::OR, MVT::v32i8, {3,13,11,11} },
6467 { ISD::OR, MVT::v16i8, {3, 8, 9, 9} },
6468 { ISD::XOR, MVT::v4i64, {2, 7, 5, 5} },
6469 { ISD::XOR, MVT::v2i64, {1, 2, 3, 3} },
6470 { ISD::XOR, MVT::v8i32, {3, 9, 7, 7} },
6471 { ISD::XOR, MVT::v4i32, {2, 4, 5, 5} },
6472 { ISD::XOR, MVT::v16i16, {3,11, 9, 9} },
6473 { ISD::XOR, MVT::v8i16, {2, 6, 7, 7} },
6474 { ISD::XOR, MVT::v32i8, {3,13,11,11} },
6475 { ISD::XOR, MVT::v16i8, {3, 8, 9, 9} },
6476 };
6477
6478 static const CostKindTblEntry AVX512FCostTbl[] = {
6479 { ISD::FADD, MVT::v8f64, {4, 4, 4, 4} },
6480 { ISD::FADD, MVT::v16f32, {5, 5, 5, 5} },
6481 { ISD::ADD, MVT::v8i64, {4, 4, 4, 4} },
6482 { ISD::ADD, MVT::v16i32, {6, 6, 6, 6} },
6483
6484 { ISD::AND, MVT::v8i64, {3,10, 7, 7} },
6485 { ISD::AND, MVT::v16i32, {4,12, 9, 9} },
6486 { ISD::AND, MVT::v32i16, {4,14,11,11} },
6487 { ISD::AND, MVT::v64i8, {4,16,13,13} },
6488 { ISD::AND, MVT::v16i8, {2, 8, 9, 9} },
6489 { ISD::OR, MVT::v8i64, {3,10, 7, 7} },
6490 { ISD::OR, MVT::v16i32, {4,12, 9, 9} },
6491 { ISD::OR, MVT::v32i16, {4,14,11,11} },
6492 { ISD::OR, MVT::v64i8, {4,16,13,13} },
6493 { ISD::OR, MVT::v16i8, {2, 8, 9, 9} },
6494 { ISD::XOR, MVT::v8i64, {3,10, 7, 7} },
6495 { ISD::XOR, MVT::v16i32, {4,12, 9, 9} },
6496 { ISD::XOR, MVT::v32i16, {4,14,11,11} },
6497 { ISD::XOR, MVT::v64i8, {4,16,13,13} },
6498 { ISD::XOR, MVT::v16i8, {2, 8, 9, 9} },
6499 };
6500
6501 static const CostKindTblEntry AVX512BWCostTbl[] = {
6502 { ISD::ADD, MVT::v32i16, {7, 7, 7, 7} },
6503 { ISD::ADD, MVT::v64i8, {4, 4, 4, 4} },
6504 };
6505
6506 int ISD = TLI->InstructionOpcodeToISD(Opcode);
6507 assert(ISD && "Invalid opcode");
6508
6509 // Before legalizing the type, give a chance to look up illegal narrow types
6510 // in the table.
6511 // FIXME: Is there a better way to do this?
6512 EVT VT = TLI->getValueType(DL, ValTy);
6513 if (VT.isSimple()) {
6514 MVT MTy = VT.getSimpleVT();
6515 if (ST->useSLMArithCosts())
6516 if (const auto *Entry = CostTableLookup(SLMCostTbl, ISD, MTy))
6517 if (auto KindCost = Entry->Cost[CostKind])
6518 return *KindCost;
6519
6520 if (ST->hasBWI())
6521 if (const auto *Entry = CostTableLookup(AVX512BWCostTbl, ISD, MTy))
6522 if (auto KindCost = Entry->Cost[CostKind])
6523 return *KindCost;
6524
6525 if (ST->hasAVX512())
6526 if (const auto *Entry = CostTableLookup(AVX512FCostTbl, ISD, MTy))
6527 if (auto KindCost = Entry->Cost[CostKind])
6528 return *KindCost;
6529
6530 if (ST->hasAVX2())
6531 if (const auto *Entry = CostTableLookup(AVX2CostTbl, ISD, MTy))
6532 if (auto KindCost = Entry->Cost[CostKind])
6533 return *KindCost;
6534
6535 if (ST->hasAVX())
6536 if (const auto *Entry = CostTableLookup(AVX1CostTbl, ISD, MTy))
6537 if (auto KindCost = Entry->Cost[CostKind])
6538 return *KindCost;
6539
6540 if (ST->hasSSE2())
6541 if (const auto *Entry = CostTableLookup(SSE2CostTbl, ISD, MTy))
6542 if (auto KindCost = Entry->Cost[CostKind])
6543 return *KindCost;
6544 }
6545
6546 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(ValTy);
6547
6548 MVT MTy = LT.second;
6549
6550 auto *ValVTy = cast<FixedVectorType>(ValTy);
6551
6552 InstructionCost ArithmeticCost = 0;
6553 if (LT.first != 1 && MTy.isVector() &&
6554 MTy.getVectorNumElements() < ValVTy->getNumElements()) {
6555 // Type needs to be split. We need LT.first - 1 arithmetic ops.
6556 auto *SingleOpTy = FixedVectorType::get(ValVTy->getElementType(),
6557 MTy.getVectorNumElements());
6558 ArithmeticCost = getArithmeticInstrCost(Opcode, SingleOpTy, CostKind);
6559 ArithmeticCost *= LT.first - 1;
6560 }
6561
6562 // FIXME: These assume a naive kshift+binop lowering, which is probably
6563 // conservative in most cases.
6564 static const CostKindTblEntry AVX512BoolReduction[] = {
6565 { ISD::AND, MVT::v2i1, { 3, 3, 3, 3} },
6566 { ISD::AND, MVT::v4i1, { 5, 5, 5, 5} },
6567 { ISD::AND, MVT::v8i1, { 7, 7, 7, 7} },
6568 { ISD::AND, MVT::v16i1, { 9, 9, 9, 9} },
6569 { ISD::AND, MVT::v32i1, {11,11,11,11} },
6570 { ISD::AND, MVT::v64i1, {13,13,13,13} },
6571 { ISD::OR, MVT::v2i1, { 3, 3, 3, 3} },
6572 { ISD::OR, MVT::v4i1, { 5, 5, 5, 5} },
6573 { ISD::OR, MVT::v8i1, { 7, 7, 7, 7} },
6574 { ISD::OR, MVT::v16i1, { 9, 9, 9, 9} },
6575 { ISD::OR, MVT::v32i1, {11,11,11,11} },
6576 { ISD::OR, MVT::v64i1, {13,13,13,13} },
6577 };
6578
6579 static const CostKindTblEntry AVX2BoolReduction[] = {
6580 { ISD::AND, MVT::v16i16, { 2, 2, 2, 2} }, // vpmovmskb + cmp
6581 { ISD::AND, MVT::v32i8, { 2, 2, 2, 2} }, // vpmovmskb + cmp
6582 { ISD::OR, MVT::v16i16, { 2, 2, 2, 2} }, // vpmovmskb + cmp
6583 { ISD::OR, MVT::v32i8, { 2, 2, 2, 2} }, // vpmovmskb + cmp
6584 };
6585
6586 static const CostKindTblEntry AVX1BoolReduction[] = {
6587 { ISD::AND, MVT::v4i64, {2, 2, 2, 2} }, // vmovmskpd + cmp
6588 { ISD::AND, MVT::v8i32, {2, 2, 2, 2} }, // vmovmskps + cmp
6589 { ISD::AND, MVT::v16i16, {4, 4, 4, 4} }, // vextractf128 + vpand + vpmovmskb + cmp
6590 { ISD::AND, MVT::v32i8, {4, 4, 4, 4} }, // vextractf128 + vpand + vpmovmskb + cmp
6591 { ISD::OR, MVT::v4i64, {2, 2, 2, 2} }, // vmovmskpd + cmp
6592 { ISD::OR, MVT::v8i32, {2, 2, 2, 2} }, // vmovmskps + cmp
6593 { ISD::OR, MVT::v16i16, {4, 4, 4, 4} }, // vextractf128 + vpor + vpmovmskb + cmp
6594 { ISD::OR, MVT::v32i8, {4, 4, 4, 4} }, // vextractf128 + vpor + vpmovmskb + cmp
6595 };
6596
6597 static const CostKindTblEntry SSE2BoolReduction[] = {
6598 { ISD::AND, MVT::v2i64, {2, 2, 2, 2} }, // movmskpd + cmp
6599 { ISD::AND, MVT::v4i32, {2, 2, 2, 2} }, // movmskps + cmp
6600 { ISD::AND, MVT::v8i16, {2, 2, 2, 2} }, // pmovmskb + cmp
6601 { ISD::AND, MVT::v16i8, {2, 2, 2, 2} }, // pmovmskb + cmp
6602 { ISD::OR, MVT::v2i64, {2, 2, 2, 2} }, // movmskpd + cmp
6603 { ISD::OR, MVT::v4i32, {2, 2, 2, 2} }, // movmskps + cmp
6604 { ISD::OR, MVT::v8i16, {2, 2, 2, 2} }, // pmovmskb + cmp
6605 { ISD::OR, MVT::v16i8, {2, 2, 2, 2} }, // pmovmskb + cmp
6606 };
6607
6608 // Handle bool allof/anyof vXi1 patterns before we check legal types.
6609 if (ValVTy->getElementType()->isIntegerTy(1)) {
6610 if (ISD == ISD::ADD) {
6611 // vXi1 addition reduction will bitcast to scalar and perform a popcount.
6612 auto *IntTy = IntegerType::getIntNTy(ValVTy->getContext(),
6613 ValVTy->getNumElements());
6614 IntrinsicCostAttributes ICA(Intrinsic::ctpop, IntTy, {IntTy});
6615 return getCastInstrCost(Instruction::BitCast, IntTy, ValVTy,
6617 CostKind) +
6618 getIntrinsicInstrCost(ICA, CostKind);
6619 }
6620
6621 if (ST->hasAVX512())
6622 if (const auto *Entry = CostTableLookup(AVX512BoolReduction, ISD, MTy))
6623 if (auto KindCost = Entry->Cost[CostKind])
6624 return ArithmeticCost + *KindCost;
6625 if (ST->hasAVX2())
6626 if (const auto *Entry = CostTableLookup(AVX2BoolReduction, ISD, MTy))
6627 if (auto KindCost = Entry->Cost[CostKind])
6628 return ArithmeticCost + *KindCost;
6629 if (ST->hasAVX())
6630 if (const auto *Entry = CostTableLookup(AVX1BoolReduction, ISD, MTy))
6631 if (auto KindCost = Entry->Cost[CostKind])
6632 return ArithmeticCost + *KindCost;
6633 if (ST->hasSSE2())
6634 if (const auto *Entry = CostTableLookup(SSE2BoolReduction, ISD, MTy))
6635 if (auto KindCost = Entry->Cost[CostKind])
6636 return ArithmeticCost + *KindCost;
6637
6638 return BaseT::getArithmeticReductionCost(Opcode, ValVTy, FMF, CostKind);
6639 }
6640
6641 // Special case: vXi8 mul reductions are performed as vXi16.
6642 if (ISD == ISD::MUL && MTy.getScalarType() == MVT::i8) {
6643 auto *WideSclTy = IntegerType::get(ValVTy->getContext(), 16);
6644 auto *WideVecTy = FixedVectorType::get(WideSclTy, ValVTy->getNumElements());
6645 return getCastInstrCost(Instruction::ZExt, WideVecTy, ValTy,
6647 CostKind) +
6648 getArithmeticReductionCost(Opcode, WideVecTy, FMF, CostKind);
6649 }
6650
6651 if (ST->useSLMArithCosts())
6652 if (const auto *Entry = CostTableLookup(SLMCostTbl, ISD, MTy))
6653 if (auto KindCost = Entry->Cost[CostKind])
6654 return ArithmeticCost + *KindCost;
6655
6656 if (ST->hasBWI())
6657 if (const auto *Entry = CostTableLookup(AVX512BWCostTbl, ISD, MTy))
6658 if (auto KindCost = Entry->Cost[CostKind])
6659 return ArithmeticCost + *KindCost;
6660
6661 if (ST->hasAVX512())
6662 if (const auto *Entry = CostTableLookup(AVX512FCostTbl, ISD, MTy))
6663 if (auto KindCost = Entry->Cost[CostKind])
6664 return ArithmeticCost + *KindCost;
6665
6666 if (ST->hasAVX2())
6667 if (const auto *Entry = CostTableLookup(AVX2CostTbl, ISD, MTy))
6668 if (auto KindCost = Entry->Cost[CostKind])
6669 return ArithmeticCost + *KindCost;
6670
6671 if (ST->hasAVX())
6672 if (const auto *Entry = CostTableLookup(AVX1CostTbl, ISD, MTy))
6673 if (auto KindCost = Entry->Cost[CostKind])
6674 return ArithmeticCost + *KindCost;
6675
6676 if (ST->hasSSE2())
6677 if (const auto *Entry = CostTableLookup(SSE2CostTbl, ISD, MTy))
6678 if (auto KindCost = Entry->Cost[CostKind])
6679 return ArithmeticCost + *KindCost;
6680
6681 unsigned NumVecElts = ValVTy->getNumElements();
6682 unsigned ScalarSize = ValVTy->getScalarSizeInBits();
6683
6684 // Special case power of 2 reductions where the scalar type isn't changed
6685 // by type legalization.
6686 if (!isPowerOf2_32(NumVecElts) || ScalarSize != MTy.getScalarSizeInBits())
6687 return BaseT::getArithmeticReductionCost(Opcode, ValVTy, FMF, CostKind);
6688
6689 InstructionCost ReductionCost = 0;
6690
6691 auto *Ty = ValVTy;
6692 if (LT.first != 1 && MTy.isVector() &&
6693 MTy.getVectorNumElements() < ValVTy->getNumElements()) {
6694 // Type needs to be split. We need LT.first - 1 arithmetic ops.
6695 Ty = FixedVectorType::get(ValVTy->getElementType(),
6696 MTy.getVectorNumElements());
6697 ReductionCost = getArithmeticInstrCost(Opcode, Ty, CostKind);
6698 ReductionCost *= LT.first - 1;
6699 NumVecElts = MTy.getVectorNumElements();
6700 }
6701
6702 // Now handle reduction with the legal type, taking into account size changes
6703 // at each level.
6704 while (NumVecElts > 1) {
6705 // Determine the size of the remaining vector we need to reduce.
6706 unsigned Size = NumVecElts * ScalarSize;
6707 NumVecElts /= 2;
6708 // If we're reducing from 256/512 bits, use an extract_subvector.
6709 if (Size > 128) {
6710 auto *SubTy = FixedVectorType::get(ValVTy->getElementType(), NumVecElts);
6711 ReductionCost += getShuffleCost(TTI::SK_ExtractSubvector, Ty, Ty,
6712 CostKind, {}, NumVecElts, SubTy);
6713 Ty = SubTy;
6714 } else if (Size == 128) {
6715 // Reducing from 128 bits is a permute of v2f64/v2i64.
6716 FixedVectorType *ShufTy;
6717 if (ValVTy->isFloatingPointTy())
6718 ShufTy =
6719 FixedVectorType::get(Type::getDoubleTy(ValVTy->getContext()), 2);
6720 else
6721 ShufTy =
6722 FixedVectorType::get(Type::getInt64Ty(ValVTy->getContext()), 2);
6723 ReductionCost += getShuffleCost(TTI::SK_PermuteSingleSrc, ShufTy, ShufTy,
6724 CostKind, {}, 0, nullptr);
6725 } else if (Size == 64) {
6726 // Reducing from 64 bits is a shuffle of v4f32/v4i32.
6727 FixedVectorType *ShufTy;
6728 if (ValVTy->isFloatingPointTy())
6729 ShufTy =
6730 FixedVectorType::get(Type::getFloatTy(ValVTy->getContext()), 4);
6731 else
6732 ShufTy =
6733 FixedVectorType::get(Type::getInt32Ty(ValVTy->getContext()), 4);
6734 ReductionCost += getShuffleCost(TTI::SK_PermuteSingleSrc, ShufTy, ShufTy,
6735 CostKind, {}, 0, nullptr);
6736 } else {
6737 // Reducing from smaller size is a shift by immediate.
6738 auto *ShiftTy = FixedVectorType::get(
6739 Type::getIntNTy(ValVTy->getContext(), Size), 128 / Size);
6740 ReductionCost += getArithmeticInstrCost(
6741 Instruction::LShr, ShiftTy, CostKind,
6744 }
6745
6746 // Add the arithmetic op for this level.
6747 ReductionCost += getArithmeticInstrCost(Opcode, Ty, CostKind);
6748 }
6749
6750 // Add the final extract element to the cost.
6751 return ReductionCost + getVectorInstrCost(Instruction::ExtractElement, Ty,
6752 CostKind, 0, nullptr, nullptr,
6754}
6755
6757 TTI::TargetCostKind CostKind,
6758 FastMathFlags FMF) const {
6759 IntrinsicCostAttributes ICA(IID, Ty, {Ty, Ty}, FMF);
6760 return getIntrinsicInstrCost(ICA, CostKind);
6761}
6762
6765 FastMathFlags FMF,
6766 TTI::TargetCostKind CostKind) const {
6767 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(ValTy);
6768
6769 MVT MTy = LT.second;
6770
6772 if (ValTy->isIntOrIntVectorTy()) {
6773 ISD = (IID == Intrinsic::umin || IID == Intrinsic::umax) ? ISD::UMIN
6774 : ISD::SMIN;
6775 } else {
6776 assert(ValTy->isFPOrFPVectorTy() &&
6777 "Expected float point or integer vector type.");
6778 ISD = (IID == Intrinsic::minnum || IID == Intrinsic::maxnum)
6779 ? ISD::FMINNUM
6780 : ISD::FMINIMUM;
6781 }
6782
6783 // We use llvm-mca across all supported CPUs to measure the cost stats.
6784 static const CostKindTblEntry SSE2CostTbl[] = {
6785 {ISD::SMIN, MVT::v2i64, {3, 4, 5, 6}},
6786 {ISD::UMIN, MVT::v2i64, {3, 4, 5, 6}},
6787 {ISD::SMIN, MVT::v2i32, {2, 2, 5, 6}},
6788 {ISD::UMIN, MVT::v2i32, {2, 2, 5, 6}},
6789 {ISD::SMIN, MVT::v4i32, {3, 7,11,12}},
6790 {ISD::UMIN, MVT::v4i32, {4, 7,14,15}},
6791 {ISD::SMIN, MVT::v2i16, {2, 3, 4, 4}},
6792 {ISD::UMIN, MVT::v2i16, {2, 3, 4, 6}},
6793 {ISD::SMIN, MVT::v4i16, {3, 5, 6, 6}},
6794 {ISD::UMIN, MVT::v4i16, {3, 5, 8, 10}},
6795 {ISD::SMIN, MVT::v8i16, {3, 8, 8, 8}},
6796 {ISD::UMIN, MVT::v8i16, {4, 8,12,14}},
6797 {ISD::SMIN, MVT::v2i8, {2, 3, 5, 6}},
6798 {ISD::UMIN, MVT::v2i8, {2, 3, 4, 4}},
6799 {ISD::SMIN, MVT::v4i8, {4, 6,12,13}},
6800 {ISD::UMIN, MVT::v4i8, {3, 6, 7, 7}},
6801 {ISD::SMIN, MVT::v8i8, {5, 9,18,19}},
6802 {ISD::UMIN, MVT::v8i8, {4, 8, 9, 9}},
6803 {ISD::SMIN, MVT::v16i8, {7,13,24,25}},
6804 {ISD::UMIN, MVT::v16i8, {3,10,11,11}},
6805 };
6806
6807 static const CostKindTblEntry SSE41CostTbl[] = {
6808 {ISD::SMIN, MVT::v2i64, {3, 4, 4, 6}},
6809 {ISD::UMIN, MVT::v2i64, {3, 4, 4, 6}},
6810 {ISD::SMIN, MVT::v2i32, {2, 2, 3, 3}},
6811 {ISD::UMIN, MVT::v2i32, {2, 2, 3, 3}},
6812 {ISD::SMIN, MVT::v4i32, {3, 4, 5, 5}},
6813 {ISD::UMIN, MVT::v4i32, {3, 4, 5, 5}},
6814 {ISD::UMIN, MVT::v2i16, {2, 3, 4, 4}},
6815 {ISD::SMIN, MVT::v4i16, {3, 5, 6, 6}},
6816 {ISD::UMIN, MVT::v4i16, {3, 5, 6, 6}},
6817 {ISD::SMIN, MVT::v8i16, {2, 8, 4, 5}},
6818 {ISD::UMIN, MVT::v8i16, {2, 5, 2, 2}},
6819 {ISD::SMIN, MVT::v2i8, {2, 3, 4, 4}},
6820 {ISD::SMIN, MVT::v4i8, {3, 6, 7, 7}},
6821 {ISD::SMIN, MVT::v8i8, {4, 8, 9, 9}},
6822 {ISD::SMIN, MVT::v16i8, {3,10, 7, 8}},
6823 {ISD::UMIN, MVT::v16i8, {3, 8, 5, 5}},
6824 };
6825
6826 static const CostKindTblEntry AVX1CostTbl[] = {
6827 {ISD::SMIN, MVT::v4i64, {5,11, 7,10}},
6828 {ISD::UMIN, MVT::v4i64, {6,12,10,13}},
6829 {ISD::SMIN, MVT::v8i32, {4, 9, 7, 7}},
6830 {ISD::UMIN, MVT::v8i32, {4, 9, 7, 7}},
6831 {ISD::SMIN, MVT::v16i16, {3,15, 6, 7}},
6832 {ISD::UMIN, MVT::v16i16, {2, 9, 4, 4}},
6833 {ISD::SMIN, MVT::v32i8, {4,17, 8, 9}},
6834 {ISD::UMIN, MVT::v32i8, {3,11, 6, 6}},
6835 };
6836
6837 static const CostKindTblEntry AVX2CostTbl[] = {
6838 {ISD::SMIN, MVT::v4i64, {4,11, 7,10}},
6839 {ISD::UMIN, MVT::v4i64, {4,12,10,13}},
6840 {ISD::SMIN, MVT::v2i32, {1, 2, 3, 3}},
6841 {ISD::UMIN, MVT::v2i32, {1, 2, 3, 3}},
6842 {ISD::UMIN, MVT::v4i32, {2, 4, 5, 5}},
6843 {ISD::SMIN, MVT::v4i32, {2, 4, 5, 5}},
6844 {ISD::SMIN, MVT::v8i32, {3, 9, 7, 7}},
6845 {ISD::UMIN, MVT::v8i32, {3, 9, 7, 7}},
6846 {ISD::SMIN, MVT::v4i16, {2, 4, 5, 5}},
6847 {ISD::UMIN, MVT::v4i16, {2, 4, 5, 5}},
6848 {ISD::SMIN, MVT::v16i16, {2,15, 6, 7}},
6849 {ISD::SMIN, MVT::v8i8, {3, 6, 7, 7}},
6850 {ISD::UMIN, MVT::v8i8, {3, 6, 7, 7}},
6851 {ISD::SMIN, MVT::v32i8, {3,17, 8, 9}},
6852 };
6853
6854 static const CostKindTblEntry AVX512FCostTbl[] = {
6855 {ISD::SMIN, MVT::v2i64, {2, 4, 3, 3}},
6856 {ISD::UMIN, MVT::v2i64, {2, 4, 3, 3}},
6857 {ISD::SMIN, MVT::v4i64, {3,10, 5, 5}},
6858 {ISD::UMIN, MVT::v4i64, {3,10, 5, 5}},
6859 {ISD::SMIN, MVT::v8i64, {5,16, 7, 7}},
6860 {ISD::UMIN, MVT::v8i64, {5,16, 7, 7}},
6861 {ISD::SMIN, MVT::v16i32, {4,12, 9, 9}},
6862 {ISD::UMIN, MVT::v16i32, {4,12, 9, 9}},
6863 };
6864
6865 static const CostKindTblEntry AVX512BWCostTbl[] = {
6866 {ISD::SMIN, MVT::v2i16, {1, 2, 3, 3}},
6867 {ISD::UMIN, MVT::v2i16, {1, 2, 3, 3}},
6868 {ISD::SMIN, MVT::v32i16, {2,19, 8, 9}},
6869 {ISD::UMIN, MVT::v32i16, {2,12, 6, 6}},
6870 {ISD::SMIN, MVT::v2i8, {1, 2, 3, 3}},
6871 {ISD::UMIN, MVT::v2i8, {1, 2, 3, 3}},
6872 {ISD::SMIN, MVT::v4i8, {2, 4, 5, 5}},
6873 {ISD::UMIN, MVT::v4i8, {2, 4, 5, 5}},
6874 {ISD::SMIN, MVT::v16i8, {2,10, 6, 7}},
6875 {ISD::UMIN, MVT::v16i8, {2, 6, 4, 4}},
6876 {ISD::SMIN, MVT::v32i8, {2,17, 8, 9}},
6877 {ISD::UMIN, MVT::v32i8, {2,10, 6, 6}},
6878 {ISD::SMIN, MVT::v64i8, {2,21,10,11}},
6879 {ISD::UMIN, MVT::v64i8, {2,14, 8, 8}},
6880 };
6881
6882 // Before legalizing the type, give a chance to look up illegal narrow types
6883 // in the table.
6884 // FIXME: Is there a better way to do this?
6885 EVT VT = TLI->getValueType(DL, ValTy);
6886 if (VT.isSimple()) {
6887 MVT MTy = VT.getSimpleVT();
6888 if (ST->hasBWI())
6889 if (const auto *Entry = CostTableLookup(AVX512BWCostTbl, ISD, MTy))
6890 if (auto KindCost = Entry->Cost[CostKind])
6891 return *KindCost;
6892
6893 if (ST->hasAVX512())
6894 if (const auto *Entry = CostTableLookup(AVX512FCostTbl, ISD, MTy))
6895 if (auto KindCost = Entry->Cost[CostKind])
6896 return *KindCost;
6897
6898 if (ST->hasAVX2())
6899 if (const auto *Entry = CostTableLookup(AVX2CostTbl, ISD, MTy))
6900 if (auto KindCost = Entry->Cost[CostKind])
6901 return *KindCost;
6902
6903 if (ST->hasAVX())
6904 if (const auto *Entry = CostTableLookup(AVX1CostTbl, ISD, MTy))
6905 if (auto KindCost = Entry->Cost[CostKind])
6906 return *KindCost;
6907
6908 if (ST->hasSSE41())
6909 if (const auto *Entry = CostTableLookup(SSE41CostTbl, ISD, MTy))
6910 if (auto KindCost = Entry->Cost[CostKind])
6911 return *KindCost;
6912
6913 if (ST->hasSSE2())
6914 if (const auto *Entry = CostTableLookup(SSE2CostTbl, ISD, MTy))
6915 if (auto KindCost = Entry->Cost[CostKind])
6916 return *KindCost;
6917 }
6918
6919 auto *ValVTy = cast<FixedVectorType>(ValTy);
6920 unsigned NumVecElts = ValVTy->getNumElements();
6921
6922 auto *Ty = ValVTy;
6923 InstructionCost MinMaxCost = 0;
6924 if (LT.first != 1 && MTy.isVector() &&
6925 MTy.getVectorNumElements() < ValVTy->getNumElements()) {
6926 // Type needs to be split. We need LT.first - 1 operations ops.
6927 Ty = FixedVectorType::get(ValVTy->getElementType(),
6928 MTy.getVectorNumElements());
6929 MinMaxCost = getMinMaxCost(IID, Ty, CostKind, FMF);
6930 MinMaxCost *= LT.first - 1;
6931 NumVecElts = MTy.getVectorNumElements();
6932 }
6933
6934 if (ST->hasBWI())
6935 if (const auto *Entry = CostTableLookup(AVX512BWCostTbl, ISD, MTy))
6936 if (auto KindCost = Entry->Cost[CostKind])
6937 return MinMaxCost + *KindCost;
6938
6939 if (ST->hasAVX512())
6940 if (const auto *Entry = CostTableLookup(AVX512FCostTbl, ISD, MTy))
6941 if (auto KindCost = Entry->Cost[CostKind])
6942 return MinMaxCost + *KindCost;
6943
6944 if (ST->hasAVX2())
6945 if (const auto *Entry = CostTableLookup(AVX2CostTbl, ISD, MTy))
6946 if (auto KindCost = Entry->Cost[CostKind])
6947 return MinMaxCost + *KindCost;
6948
6949 if (ST->hasAVX())
6950 if (const auto *Entry = CostTableLookup(AVX1CostTbl, ISD, MTy))
6951 if (auto KindCost = Entry->Cost[CostKind])
6952 return MinMaxCost + *KindCost;
6953
6954 if (ST->hasSSE41())
6955 if (const auto *Entry = CostTableLookup(SSE41CostTbl, ISD, MTy))
6956 if (auto KindCost = Entry->Cost[CostKind])
6957 return MinMaxCost + *KindCost;
6958
6959 if (ST->hasSSE2())
6960 if (const auto *Entry = CostTableLookup(SSE2CostTbl, ISD, MTy))
6961 if (auto KindCost = Entry->Cost[CostKind])
6962 return MinMaxCost + *KindCost;
6963
6964 unsigned ScalarSize = ValTy->getScalarSizeInBits();
6965
6966 // Special case power of 2 reductions where the scalar type isn't changed
6967 // by type legalization.
6968 if (!isPowerOf2_32(ValVTy->getNumElements()) ||
6969 ScalarSize != MTy.getScalarSizeInBits())
6970 return BaseT::getMinMaxReductionCost(IID, ValTy, FMF, CostKind);
6971
6972 // Now handle reduction with the legal type, taking into account size changes
6973 // at each level.
6974 while (NumVecElts > 1) {
6975 // Determine the size of the remaining vector we need to reduce.
6976 unsigned Size = NumVecElts * ScalarSize;
6977 NumVecElts /= 2;
6978 // If we're reducing from 256/512 bits, use an extract_subvector.
6979 if (Size > 128) {
6980 auto *SubTy = FixedVectorType::get(ValVTy->getElementType(), NumVecElts);
6981 MinMaxCost += getShuffleCost(TTI::SK_ExtractSubvector, Ty, Ty, CostKind,
6982 {}, NumVecElts, SubTy);
6983 Ty = SubTy;
6984 } else if (Size == 128) {
6985 // Reducing from 128 bits is a permute of v2f64/v2i64.
6986 VectorType *ShufTy;
6987 if (ValTy->isFloatingPointTy())
6988 ShufTy =
6990 else
6991 ShufTy = FixedVectorType::get(Type::getInt64Ty(ValTy->getContext()), 2);
6992 MinMaxCost += getShuffleCost(TTI::SK_PermuteSingleSrc, ShufTy, ShufTy,
6993 CostKind, {}, 0, nullptr);
6994 } else if (Size == 64) {
6995 // Reducing from 64 bits is a shuffle of v4f32/v4i32.
6996 FixedVectorType *ShufTy;
6997 if (ValTy->isFloatingPointTy())
6998 ShufTy = FixedVectorType::get(Type::getFloatTy(ValTy->getContext()), 4);
6999 else
7000 ShufTy = FixedVectorType::get(Type::getInt32Ty(ValTy->getContext()), 4);
7001 MinMaxCost += getShuffleCost(TTI::SK_PermuteSingleSrc, ShufTy, ShufTy,
7002 CostKind, {}, 0, nullptr);
7003 } else {
7004 // Reducing from smaller size is a shift by immediate.
7005 auto *ShiftTy = FixedVectorType::get(
7006 Type::getIntNTy(ValTy->getContext(), Size), 128 / Size);
7007 MinMaxCost += getArithmeticInstrCost(
7008 Instruction::LShr, ShiftTy, TTI::TCK_RecipThroughput,
7011 }
7012
7013 // Add the arithmetic op for this level.
7014 MinMaxCost += getMinMaxCost(IID, Ty, CostKind, FMF);
7015 }
7016
7017 // Add the final extract element to the cost.
7018 return MinMaxCost + getVectorInstrCost(Instruction::ExtractElement, Ty,
7019 CostKind, 0, nullptr, nullptr,
7021}
7022
7023/// Calculate the cost of materializing a 64-bit value. This helper
7024/// method might only calculate a fraction of a larger immediate. Therefore it
7025/// is valid to return a cost of ZERO.
7027 if (Val == 0)
7028 return TTI::TCC_Free;
7029
7030 if (isInt<32>(Val))
7031 return TTI::TCC_Basic;
7032
7033 return 2 * TTI::TCC_Basic;
7034}
7035
7037 TTI::TargetCostKind CostKind) const {
7038 assert(Ty->isIntegerTy());
7039
7040 unsigned BitSize = Ty->getPrimitiveSizeInBits();
7041 if (BitSize == 0)
7042 return ~0U;
7043
7044 // Never hoist constants larger than 128bit, because this might lead to
7045 // incorrect code generation or assertions in codegen.
7046 // Fixme: Create a cost model for types larger than i128 once the codegen
7047 // issues have been fixed.
7048 if (BitSize > 128)
7049 return TTI::TCC_Free;
7050
7051 if (Imm == 0)
7052 return TTI::TCC_Free;
7053
7054 // Sign-extend all constants to a multiple of 64-bit.
7055 APInt ImmVal = Imm;
7056 if (BitSize % 64 != 0)
7057 ImmVal = Imm.sext(alignTo(BitSize, 64));
7058
7059 // Split the constant into 64-bit chunks and calculate the cost for each
7060 // chunk.
7062 for (unsigned ShiftVal = 0; ShiftVal < BitSize; ShiftVal += 64) {
7063 APInt Tmp = ImmVal.ashr(ShiftVal).sextOrTrunc(64);
7064 int64_t Val = Tmp.getSExtValue();
7065 Cost += getIntImmCost(Val);
7066 }
7067 // We need at least one instruction to materialize the constant.
7068 return std::max<InstructionCost>(1, Cost);
7069}
7070
7072 const APInt &Imm, Type *Ty,
7073 TTI::TargetCostKind CostKind,
7074 Instruction *Inst) const {
7075 assert(Ty->isIntegerTy());
7076
7077 unsigned BitSize = Ty->getPrimitiveSizeInBits();
7078 unsigned ImmBitWidth = Imm.getBitWidth();
7079
7080 // There is no cost model for constants with a bit size of 0. Return TCC_Free
7081 // here, so that constant hoisting will ignore this constant.
7082 if (BitSize == 0)
7083 return TTI::TCC_Free;
7084
7085 unsigned ImmIdx = ~0U;
7086 switch (Opcode) {
7087 default:
7088 return TTI::TCC_Free;
7089 case Instruction::GetElementPtr:
7090 // Always hoist the base address of a GetElementPtr. This prevents the
7091 // creation of new constants for every base constant that gets constant
7092 // folded with the offset.
7093 if (Idx == 0)
7094 return 2 * TTI::TCC_Basic;
7095 return TTI::TCC_Free;
7096 case Instruction::Store:
7097 ImmIdx = 0;
7098 break;
7099 case Instruction::ICmp:
7100 // This is an imperfect hack to prevent constant hoisting of
7101 // compares that might be trying to check if a 64-bit value fits in
7102 // 32-bits. The backend can optimize these cases using a right shift by 32.
7103 // There are other predicates and immediates the backend can use shifts for.
7104 if (Idx == 1 && ImmBitWidth == 64) {
7105 uint64_t ImmVal = Imm.getZExtValue();
7106 if (ImmVal == 0x100000000ULL || ImmVal == 0xffffffff)
7107 return TTI::TCC_Free;
7108
7109 if (auto *Cmp = dyn_cast_or_null<CmpInst>(Inst)) {
7110 if (Cmp->isEquality()) {
7111 KnownBits Known = computeKnownBits(Cmp->getOperand(0), DL);
7112 if (Known.countMinTrailingZeros() >= 32)
7113 return TTI::TCC_Free;
7114 }
7115 }
7116 }
7117 ImmIdx = 1;
7118 break;
7119 case Instruction::And:
7120 // We support 64-bit ANDs with immediates with 32-bits of leading zeroes
7121 // by using a 32-bit operation with implicit zero extension. Detect such
7122 // immediates here as the normal path expects bit 31 to be sign extended.
7123 if (Idx == 1 && ImmBitWidth == 64 && Imm.isIntN(32))
7124 return TTI::TCC_Free;
7125 // If we have BMI then we can use BEXTR/BZHI to mask out upper i64 bits.
7126 if (Idx == 1 && ImmBitWidth == 64 && ST->is64Bit() && ST->hasBMI() &&
7127 Imm.isMask())
7128 return X86TTIImpl::getIntImmCost(ST->hasBMI2() ? 255 : 65535);
7129 ImmIdx = 1;
7130 break;
7131 case Instruction::Add:
7132 case Instruction::Sub:
7133 // For add/sub, we can use the opposite instruction for INT32_MIN.
7134 if (Idx == 1 && ImmBitWidth == 64 && Imm.getZExtValue() == 0x80000000)
7135 return TTI::TCC_Free;
7136 ImmIdx = 1;
7137 break;
7138 case Instruction::UDiv:
7139 case Instruction::SDiv:
7140 case Instruction::URem:
7141 case Instruction::SRem:
7142 // Division by constant is typically expanded later into a different
7143 // instruction sequence. This completely changes the constants.
7144 // Report them as "free" to stop ConstantHoist from marking them as opaque.
7145 return TTI::TCC_Free;
7146 case Instruction::Mul:
7147 case Instruction::Or:
7148 case Instruction::Xor:
7149 ImmIdx = 1;
7150 break;
7151 // Always return TCC_Free for the shift value of a shift instruction.
7152 case Instruction::Shl:
7153 case Instruction::LShr:
7154 case Instruction::AShr:
7155 if (Idx == 1)
7156 return TTI::TCC_Free;
7157 break;
7158 case Instruction::Trunc:
7159 case Instruction::ZExt:
7160 case Instruction::SExt:
7161 case Instruction::IntToPtr:
7162 case Instruction::PtrToInt:
7163 case Instruction::BitCast:
7164 case Instruction::PHI:
7165 case Instruction::Call:
7166 case Instruction::Select:
7167 case Instruction::Ret:
7168 case Instruction::Load:
7169 break;
7170 }
7171
7172 if (Idx == ImmIdx) {
7173 uint64_t NumConstants = divideCeil(BitSize, 64);
7175 return (Cost <= NumConstants * TTI::TCC_Basic)
7176 ? static_cast<int>(TTI::TCC_Free)
7177 : Cost;
7178 }
7179
7180 return X86TTIImpl::getIntImmCost(Imm, Ty, CostKind);
7181}
7182
7185 const APInt &Imm, Type *Ty,
7186 TTI::TargetCostKind CostKind) const {
7187 assert(Ty->isIntegerTy());
7188
7189 unsigned BitSize = Ty->getPrimitiveSizeInBits();
7190 // There is no cost model for constants with a bit size of 0. Return TCC_Free
7191 // here, so that constant hoisting will ignore this constant.
7192 if (BitSize == 0)
7193 return TTI::TCC_Free;
7194
7195 switch (IID) {
7196 default:
7197 return TTI::TCC_Free;
7198 case Intrinsic::sadd_with_overflow:
7199 case Intrinsic::uadd_with_overflow:
7200 case Intrinsic::ssub_with_overflow:
7201 case Intrinsic::usub_with_overflow:
7202 case Intrinsic::smul_with_overflow:
7203 case Intrinsic::umul_with_overflow:
7204 if ((Idx == 1) && Imm.getBitWidth() <= 64 && Imm.isSignedIntN(32))
7205 return TTI::TCC_Free;
7206 break;
7207 case Intrinsic::experimental_stackmap:
7208 if ((Idx < 2) || (Imm.getBitWidth() <= 64 && Imm.isSignedIntN(64)))
7209 return TTI::TCC_Free;
7210 break;
7211 case Intrinsic::experimental_patchpoint_void:
7212 case Intrinsic::experimental_patchpoint:
7213 if ((Idx < 4) || (Imm.getBitWidth() <= 64 && Imm.isSignedIntN(64)))
7214 return TTI::TCC_Free;
7215 break;
7216 }
7217 return X86TTIImpl::getIntImmCost(Imm, Ty, CostKind);
7218}
7219
7221 TTI::TargetCostKind CostKind,
7222 const Instruction *I) const {
7223 if (CostKind != TTI::TCK_RecipThroughput)
7224 return Opcode == Instruction::PHI ? TTI::TCC_Free : TTI::TCC_Basic;
7225 // Branches are assumed to be predicted.
7226 return TTI::TCC_Free;
7227}
7228
7229int X86TTIImpl::getGatherOverhead() const {
7230 // Some CPUs have more overhead for gather. The specified overhead is relative
7231 // to the Load operation. "2" is the number provided by Intel architects. This
7232 // parameter is used for cost estimation of Gather Op and comparison with
7233 // other alternatives.
7234 // TODO: Remove the explicit hasAVX512()?, That would mean we would only
7235 // enable gather with a -march.
7236 if (ST->hasAVX512() || (ST->hasAVX2() && ST->hasFastGather()))
7237 return 2;
7238
7239 return 1024;
7240}
7241
7242int X86TTIImpl::getScatterOverhead() const {
7243 if (ST->hasAVX512())
7244 return 2;
7245
7246 return 1024;
7247}
7248
7249// Return an average cost of Gather / Scatter instruction, maybe improved later.
7250InstructionCost X86TTIImpl::getGSVectorCost(unsigned Opcode,
7251 TTI::TargetCostKind CostKind,
7252 Type *SrcVTy, const Value *Ptr,
7253 Align Alignment,
7254 unsigned AddressSpace) const {
7255
7256 assert(isa<VectorType>(SrcVTy) && "Unexpected type in getGSVectorCost");
7257 unsigned VF = cast<FixedVectorType>(SrcVTy)->getNumElements();
7258
7259 // Try to reduce index size from 64 bit (default for GEP)
7260 // to 32. It is essential for VF 16. If the index can't be reduced to 32, the
7261 // operation will use 16 x 64 indices which do not fit in a zmm and needs
7262 // to split. Also check that the base pointer is the same for all lanes,
7263 // and that there's at most one variable index.
7264 auto getIndexSizeInBits = [](const Value *Ptr, const DataLayout &DL) {
7265 unsigned IndexSize = DL.getPointerSizeInBits();
7266 const GetElementPtrInst *GEP = dyn_cast_or_null<GetElementPtrInst>(Ptr);
7267 if (IndexSize < 64 || !GEP)
7268 return IndexSize;
7269
7270 unsigned NumOfVarIndices = 0;
7271 const Value *Ptrs = GEP->getPointerOperand();
7272 if (Ptrs->getType()->isVectorTy() && !getSplatValue(Ptrs))
7273 return IndexSize;
7274 for (unsigned I = 1, E = GEP->getNumOperands(); I != E; ++I) {
7275 if (isa<Constant>(GEP->getOperand(I)))
7276 continue;
7277 Type *IndxTy = GEP->getOperand(I)->getType();
7278 if (auto *IndexVTy = dyn_cast<VectorType>(IndxTy))
7279 IndxTy = IndexVTy->getElementType();
7280 if ((IndxTy->getPrimitiveSizeInBits() == 64 &&
7281 !isa<SExtInst>(GEP->getOperand(I))) ||
7282 ++NumOfVarIndices > 1)
7283 return IndexSize; // 64
7284 }
7285 return (unsigned)32;
7286 };
7287
7288 // Trying to reduce IndexSize to 32 bits for vector 16.
7289 // By default the IndexSize is equal to pointer size.
7290 unsigned IndexSize = (ST->hasAVX512() && VF >= 16)
7291 ? getIndexSizeInBits(Ptr, DL)
7292 : DL.getPointerSizeInBits();
7293
7294 auto *IndexVTy = FixedVectorType::get(
7295 IntegerType::get(SrcVTy->getContext(), IndexSize), VF);
7296 std::pair<InstructionCost, MVT> IdxsLT = getTypeLegalizationCost(IndexVTy);
7297 std::pair<InstructionCost, MVT> SrcLT = getTypeLegalizationCost(SrcVTy);
7298 InstructionCost::CostType SplitFactor =
7299 std::max(IdxsLT.first, SrcLT.first).getValue();
7300 if (SplitFactor > 1) {
7301 // Handle splitting of vector of pointers
7302 auto *SplitSrcTy =
7303 FixedVectorType::get(SrcVTy->getScalarType(), VF / SplitFactor);
7304 return SplitFactor * getGSVectorCost(Opcode, CostKind, SplitSrcTy, Ptr,
7305 Alignment, AddressSpace);
7306 }
7307
7308 // If we didn't split, this will be a single gather/scatter instruction.
7309 if (CostKind == TTI::TCK_CodeSize)
7310 return 1;
7311
7312 // The gather / scatter cost is given by Intel architects. It is a rough
7313 // number since we are looking at one instruction in a time.
7314 const int GSOverhead = (Opcode == Instruction::Load) ? getGatherOverhead()
7315 : getScatterOverhead();
7316 return GSOverhead + VF * getMemoryOpCost(Opcode, SrcVTy->getScalarType(),
7317 Alignment, AddressSpace, CostKind);
7318}
7319
7320/// Calculate the cost of Gather / Scatter operation
7323 TTI::TargetCostKind CostKind) const {
7324 bool IsLoad = MICA.getID() == Intrinsic::masked_gather ||
7325 MICA.getID() == Intrinsic::vp_gather;
7326 unsigned Opcode = IsLoad ? Instruction::Load : Instruction::Store;
7327 Type *SrcVTy = MICA.getDataType();
7328 const Value *Ptr = MICA.getPointer();
7329 Align Alignment = MICA.getAlignment();
7330 if ((Opcode == Instruction::Load &&
7331 (!isLegalMaskedGather(SrcVTy, Align(Alignment)) ||
7333 Align(Alignment)))) ||
7334 (Opcode == Instruction::Store &&
7335 (!isLegalMaskedScatter(SrcVTy, Align(Alignment)) ||
7337 Align(Alignment)))))
7338 return BaseT::getMemIntrinsicInstrCost(MICA, CostKind);
7339
7340 assert(SrcVTy->isVectorTy() && "Unexpected data type for Gather/Scatter");
7341 unsigned AddressSpace = MICA.getAddressSpace();
7343 getGSVectorCost(Opcode, CostKind, SrcVTy, Ptr, Alignment, AddressSpace);
7344
7345 // Predicate fanout (see getPredicateFanoutCost); variable mask only.
7346 if (MICA.getVariableMask()) {
7347 auto *MaskVecTy =
7349 cast<FixedVectorType>(SrcVTy)->getNumElements());
7350 Cost += getPredicateFanoutCost(*this, SrcVTy, MaskVecTy);
7351 }
7352 return Cost;
7353}
7354
7356 const TargetTransformInfo::LSRCost &C2) const {
7357 // X86 specific here are "instruction number 1st priority".
7358 return std::tie(C1.Insns, C1.NumRegs, C1.AddRecCost, C1.NumIVMuls,
7359 C1.NumBaseAdds, C1.ScaleCost, C1.ImmCost, C1.SetupCost) <
7360 std::tie(C2.Insns, C2.NumRegs, C2.AddRecCost, C2.NumIVMuls,
7361 C2.NumBaseAdds, C2.ScaleCost, C2.ImmCost, C2.SetupCost);
7362}
7363
7365 return ST->hasMacroFusion() || ST->hasBranchFusion();
7366}
7367
7368static bool isLegalMaskedLoadStore(Type *ScalarTy, const X86Subtarget *ST) {
7369 if (!ST->hasAVX())
7370 return false;
7371
7372 if (ScalarTy->isPointerTy())
7373 return true;
7374
7375 if (ScalarTy->isFloatTy() || ScalarTy->isDoubleTy())
7376 return true;
7377
7378 if ((ScalarTy->isHalfTy() || ScalarTy->isBFloatTy()) && ST->hasBWI())
7379 return true;
7380
7381 if (!ScalarTy->isIntegerTy())
7382 return false;
7383
7384 unsigned IntWidth = ScalarTy->getIntegerBitWidth();
7385 return IntWidth == 32 || IntWidth == 64 ||
7386 ((IntWidth == 8 || IntWidth == 16) && ST->hasBWI());
7387}
7388
7390 unsigned AddressSpace,
7391 TTI::MaskKind MaskKind) const {
7392 Type *ScalarTy = DataTy->getScalarType();
7393
7394 // The backend can't handle a single element vector w/o CFCMOV.
7395 if (isa<VectorType>(DataTy) &&
7396 cast<FixedVectorType>(DataTy)->getNumElements() == 1)
7397 return ST->hasCF() &&
7398 hasConditionalLoadStoreForType(ScalarTy, /*IsStore=*/false);
7399
7400 return isLegalMaskedLoadStore(ScalarTy, ST);
7401}
7402
7404 unsigned AddressSpace,
7405 TTI::MaskKind MaskKind) const {
7406 Type *ScalarTy = DataTy->getScalarType();
7407
7408 // The backend can't handle a single element vector w/o CFCMOV.
7409 if (isa<VectorType>(DataTy) &&
7410 cast<FixedVectorType>(DataTy)->getNumElements() == 1)
7411 return ST->hasCF() &&
7412 hasConditionalLoadStoreForType(ScalarTy, /*IsStore=*/true);
7413
7414 return isLegalMaskedLoadStore(ScalarTy, ST);
7415}
7416
7417bool X86TTIImpl::isLegalNTLoad(Type *DataType, Align Alignment) const {
7418 unsigned DataSize = DL.getTypeStoreSize(DataType);
7419 // The only supported nontemporal loads are for aligned vectors of 16 or 32
7420 // bytes. Note that 32-byte nontemporal vector loads are supported by AVX2
7421 // (the equivalent stores only require AVX).
7422 if (Alignment >= DataSize && (DataSize == 16 || DataSize == 32))
7423 return DataSize == 16 ? ST->hasSSE1() : ST->hasAVX2();
7424
7425 return false;
7426}
7427
7428bool X86TTIImpl::isLegalNTStore(Type *DataType, Align Alignment) const {
7429 unsigned DataSize = DL.getTypeStoreSize(DataType);
7430
7431 // SSE4A supports nontemporal stores of float and double at arbitrary
7432 // alignment.
7433 if (ST->hasSSE4A() && (DataType->isFloatTy() || DataType->isDoubleTy()))
7434 return true;
7435
7436 // Besides the SSE4A subtarget exception above, only aligned stores are
7437 // available nontemporaly on any other subtarget. And only stores with a size
7438 // of 4..32 bytes (powers of 2, only) are permitted.
7439 if (Alignment < DataSize || DataSize < 4 || DataSize > 32 ||
7440 !isPowerOf2_32(DataSize))
7441 return false;
7442
7443 // 32-byte vector nontemporal stores are supported by AVX (the equivalent
7444 // loads require AVX2).
7445 if (DataSize == 32)
7446 return ST->hasAVX();
7447 if (DataSize == 16)
7448 return ST->hasSSE1();
7449 return true;
7450}
7451
7453 ElementCount NumElements) const {
7454 // movddup
7455 return ST->hasSSE3() && !NumElements.isScalable() &&
7456 NumElements.getFixedValue() == 2 &&
7457 ElementTy == Type::getDoubleTy(ElementTy->getContext());
7458}
7459
7460bool X86TTIImpl::isLegalMaskedExpandLoad(Type *DataTy, Align Alignment) const {
7461 if (!isa<VectorType>(DataTy))
7462 return false;
7463
7464 if (!ST->hasAVX512())
7465 return false;
7466
7467 // The backend can't handle a single element vector.
7468 if (cast<FixedVectorType>(DataTy)->getNumElements() == 1)
7469 return false;
7470
7471 Type *ScalarTy = cast<VectorType>(DataTy)->getElementType();
7472
7473 if (ScalarTy->isFloatTy() || ScalarTy->isDoubleTy())
7474 return true;
7475
7476 if (ScalarTy->isHalfTy() || ScalarTy->isBFloatTy())
7477 return ST->hasVBMI2();
7478
7479 if (!ScalarTy->isIntegerTy())
7480 return false;
7481
7482 unsigned IntWidth = ScalarTy->getIntegerBitWidth();
7483 return IntWidth == 32 || IntWidth == 64 ||
7484 ((IntWidth == 8 || IntWidth == 16) && ST->hasVBMI2());
7485}
7486
7488 Align Alignment) const {
7489 return isLegalMaskedExpandLoad(DataTy, Alignment);
7490}
7491
7492bool X86TTIImpl::supportsGather() const {
7493 // Some CPUs have better gather performance than others.
7494 // TODO: Remove the explicit ST->hasAVX512()?, That would mean we would only
7495 // enable gather with a -march.
7496 return ST->hasAVX512() || (ST->hasFastGather() && ST->hasAVX2());
7497}
7498
7500 Align Alignment) const {
7501 // Gather / Scatter for vector 2 is not profitable on KNL / SKX
7502 // Vector-4 of gather/scatter instruction does not exist on KNL. We can extend
7503 // it to 8 elements, but zeroing upper bits of the mask vector will add more
7504 // instructions. Right now we give the scalar cost of vector-4 for KNL. TODO:
7505 // Check, maybe the gather/scatter instruction is better in the VariableMask
7506 // case.
7507 unsigned NumElts = cast<FixedVectorType>(VTy)->getNumElements();
7508 return NumElts == 1 ||
7509 (ST->hasAVX512() && (NumElts == 2 || (NumElts == 4 && !ST->hasVLX())));
7510}
7511
7513 Align Alignment) const {
7514 Type *ScalarTy = DataTy->getScalarType();
7515 if (ScalarTy->isPointerTy())
7516 return true;
7517
7518 if (ScalarTy->isFloatTy() || ScalarTy->isDoubleTy())
7519 return true;
7520
7521 if (!ScalarTy->isIntegerTy())
7522 return false;
7523
7524 unsigned IntWidth = ScalarTy->getIntegerBitWidth();
7525 return IntWidth == 32 || IntWidth == 64;
7526}
7527
7528bool X86TTIImpl::isLegalMaskedGather(Type *DataTy, Align Alignment) const {
7529 if (!supportsGather() || !ST->preferGather())
7530 return false;
7531 return isLegalMaskedGatherScatter(DataTy, Alignment);
7532}
7533
7534bool X86TTIImpl::isLegalAltInstr(VectorType *VecTy, unsigned Opcode0,
7535 unsigned Opcode1,
7536 const SmallBitVector &OpcodeMask,
7537 ArrayRef<const Value *> Scalars) const {
7538 // ADDSUBPS 4xf32 SSE3
7539 // VADDSUBPS 4xf32 AVX
7540 // VADDSUBPS 8xf32 AVX2
7541 // ADDSUBPD 2xf64 SSE3
7542 // VADDSUBPD 2xf64 AVX
7543 // VADDSUBPD 4xf64 AVX2
7544
7545 unsigned NumElements = cast<FixedVectorType>(VecTy)->getNumElements();
7546 assert(OpcodeMask.size() == NumElements && "Mask and VecTy are incompatible");
7547 if (!isPowerOf2_32(NumElements))
7548 return false;
7549 // Check the opcode pattern. We apply the mask on the opcode arguments and
7550 // then check if it is what we expect.
7551 auto IsLaneOrder = [&](unsigned EvenOpc, unsigned OddOpc) {
7552 return all_of(seq<unsigned>(0, NumElements), [&](unsigned Lane) {
7553 return (OpcodeMask.test(Lane) ? Opcode1 : Opcode0) ==
7554 (Lane % 2 == 0 ? EvenOpc : OddOpc);
7555 });
7556 };
7557 // We expect FSub for even lanes and FAdd for odd lanes.
7558 const bool IsAddSub = IsLaneOrder(Instruction::FSub, Instruction::FAdd);
7559 // Now check that the pattern is supported by the target ISA.
7560 Type *ElemTy = cast<VectorType>(VecTy)->getElementType();
7561 if (IsAddSub && ST->hasSSE3() &&
7562 ((ElemTy->isFloatTy() && NumElements % 4 == 0) ||
7563 (ElemTy->isDoubleTy() && NumElements % 2 == 0)))
7564 return true;
7565 // The multiplication is fused into every lane: fmaddsub (the even lanes
7566 // subtract and the odd lanes add the product) or fmsubadd (the other way
7567 // round). The subtracted product is the first operand of the subtraction.
7568 using namespace PatternMatch;
7569 auto IsFusedWithFMul = [](const Value *V) {
7570 const auto *I = dyn_cast<Instruction>(V);
7571 if (!I || !I->hasAllowContract())
7572 return false;
7573 auto IsFMul = [&](const Value *Op) {
7574 return match(Op,
7576 cast<Instruction>(Op)->getParent() == I->getParent();
7577 };
7578 return IsFMul(I->getOperand(0)) ||
7579 (I->getOpcode() == Instruction::FAdd && IsFMul(I->getOperand(1)));
7580 };
7581 return ST->hasFMA() && !Scalars.empty() &&
7582 (ElemTy->isFloatTy() || ElemTy->isDoubleTy()) &&
7583 (IsAddSub || IsLaneOrder(Instruction::FAdd, Instruction::FSub)) &&
7584 all_of(Scalars, IsFusedWithFMul);
7585}
7586
7587bool X86TTIImpl::isLegalMaskedScatter(Type *DataType, Align Alignment) const {
7588 // AVX2 doesn't support scatter
7589 if (!ST->hasAVX512() || !ST->preferScatter())
7590 return false;
7591 return isLegalMaskedGatherScatter(DataType, Alignment);
7592}
7593
7594bool X86TTIImpl::hasDivRemOp(Type *DataType, bool IsSigned) const {
7595 EVT VT = TLI->getValueType(DL, DataType);
7596 return TLI->isOperationLegal(IsSigned ? ISD::SDIVREM : ISD::UDIVREM, VT);
7597}
7598
7600 // FDIV is always expensive, even if it has a very low uop count.
7601 // TODO: Still necessary for recent CPUs with low latency/throughput fdiv?
7602 if (I->getOpcode() == Instruction::FDiv)
7603 return true;
7604
7606}
7607
7608bool X86TTIImpl::isFCmpOrdCheaperThanFCmpZero(Type *Ty) const { return false; }
7609
7611 const Function *Callee) const {
7612 const TargetMachine &TM = getTLI()->getTargetMachine();
7613
7614 // Work this as a subsetting of subtarget features.
7615 const X86Subtarget &CallerSubtarget = TM.getSubtarget<X86Subtarget>(*Caller);
7616 const X86Subtarget &CalleeSubtarget = TM.getSubtarget<X86Subtarget>(*Callee);
7617 const FeatureBitset &CallerBits = CallerSubtarget.getFeatureBits();
7618 const FeatureBitset &CalleeBits = CalleeSubtarget.getFeatureBits();
7619
7620 // Check whether callee features are a subset of caller features
7621 // (apart from the ignore list).
7622 const FeatureBitset &InlineIgnoreFeatures =
7623 CallerSubtarget.getInlineIgnoreFeatures();
7624 FeatureBitset RealCallerBits = CallerBits & ~InlineIgnoreFeatures;
7625 FeatureBitset RealCalleeBits = CalleeBits & ~InlineIgnoreFeatures;
7626 if ((RealCallerBits & RealCalleeBits) != RealCalleeBits)
7627 return false;
7628
7629 // If the features are not exactly the same (or there is a difference in
7630 // AVX512 register usage), we need to additionally check for calls
7631 // that may become ABI-incompatible as a result of inlining.
7632 if (RealCallerBits == RealCalleeBits &&
7633 CallerSubtarget.useAVX512Regs() == CalleeSubtarget.useAVX512Regs())
7634 return true;
7635
7636 for (const Instruction &I : instructions(Callee)) {
7637 if (const auto *CB = dyn_cast<CallBase>(&I)) {
7638 // Having more target features is fine for inline ASM and intrinsics.
7639 if (CB->isInlineAsm() || CB->getIntrinsicID() != Intrinsic::not_intrinsic)
7640 continue;
7641
7643 for (Value *Arg : CB->args())
7644 Types.push_back(Arg->getType());
7645 if (!CB->getType()->isVoidTy())
7646 Types.push_back(CB->getType());
7647
7648 // Simple types are always ABI compatible.
7649 auto IsSimpleTy = [](Type *Ty) {
7650 return !Ty->isVectorTy() && !Ty->isAggregateType();
7651 };
7652 if (all_of(Types, IsSimpleTy))
7653 continue;
7654
7655 // Do a precise compatibility check.
7656 if (!areTypesABICompatible(Caller, Callee, Types))
7657 return false;
7658 }
7659 }
7660 return true;
7661}
7662
7664 const Function *Callee,
7665 ArrayRef<Type *> Types) const {
7666 const TargetMachine &TM = getTLI()->getTargetMachine();
7667 const TargetLowering *CallerTLI =
7668 TM.getSubtargetImpl(*Caller)->getTargetLowering();
7669 const TargetLowering *CalleeTLI =
7670 TM.getSubtargetImpl(*Callee)->getTargetLowering();
7671
7672 LLVMContext &Ctx = Caller->getContext();
7673 const DataLayout &DL = Caller->getDataLayout();
7674 CallingConv::ID CC = Callee->getCallingConv();
7675 return all_of(Types, [&](Type *Ty) {
7676 SmallVector<EVT> VTs;
7677 ComputeValueVTs(*CallerTLI, DL, Ty, VTs);
7678 return all_of(VTs, [&](EVT VT) {
7679 return CallerTLI->getRegisterTypeForCallingConv(Ctx, CC, VT) ==
7680 CalleeTLI->getRegisterTypeForCallingConv(Ctx, CC, VT);
7681 });
7682 });
7683}
7684
7686X86TTIImpl::enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const {
7688 Options.MaxNumLoads = TLI->getMaxExpandSizeMemcmp(OptSize);
7689 Options.NumLoadsPerBlock = IsZeroCmp ? 2 : 1;
7690 // All GPR and vector loads can be unaligned.
7691 Options.AllowOverlappingLoads = true;
7692 if (IsZeroCmp) {
7693 // Only enable vector loads for equality comparison. Right now the vector
7694 // version is not as fast for three way compare (see #33329).
7695 const unsigned PreferredWidth = ST->getPreferVectorWidth();
7696 if (PreferredWidth >= 512 && ST->hasAVX512())
7697 Options.LoadSizes.push_back(64);
7698 if (PreferredWidth >= 256 && ST->hasAVX()) Options.LoadSizes.push_back(32);
7699 if (PreferredWidth >= 128 && ST->hasSSE2()) Options.LoadSizes.push_back(16);
7700 }
7701 if (ST->is64Bit()) {
7702 Options.LoadSizes.push_back(8);
7703 }
7704 Options.LoadSizes.push_back(4);
7705 Options.LoadSizes.push_back(2);
7706 Options.LoadSizes.push_back(1);
7707 return Options;
7708}
7709
7711 return supportsGather();
7712}
7713
7715 return false;
7716}
7717
7719 // TODO: We expect this to be beneficial regardless of arch,
7720 // but there are currently some unexplained performance artifacts on Atom.
7721 // As a temporary solution, disable on Atom.
7722 return !(ST->isAtom());
7723}
7724
7726 switch (II->getIntrinsicID()) {
7727 default:
7728 return true;
7729 case Intrinsic::vector_reduce_and:
7730 case Intrinsic::vector_reduce_or:
7731 case Intrinsic::vector_reduce_xor:
7732 case Intrinsic::vector_reduce_mul:
7733 case Intrinsic::vector_reduce_smax:
7734 case Intrinsic::vector_reduce_smin:
7735 case Intrinsic::vector_reduce_umax:
7736 case Intrinsic::vector_reduce_umin:
7737 return false;
7738 }
7739}
7740
7741// Get estimation for interleaved load/store operations and strided load.
7742// \p Indices contains indices for strided load.
7743// \p Factor - the factor of interleaving.
7744// AVX-512 provides 3-src shuffles that significantly reduces the cost.
7746 unsigned Opcode, FixedVectorType *VecTy, unsigned Factor,
7747 ArrayRef<unsigned> Indices, Align Alignment, unsigned AddressSpace,
7748 TTI::TargetCostKind CostKind, bool UseMaskForCond,
7749 bool UseMaskForGaps) const {
7750 // VecTy for interleave memop is <VF*Factor x Elt>.
7751 // So, for VF=4, Interleave Factor = 3, Element type = i32 we have
7752 // VecTy = <12 x i32>.
7753
7754 // Calculate the number of memory operations (NumOfMemOps), required
7755 // for load/store the VecTy.
7756 MVT LegalVT = getTypeLegalizationCost(VecTy).second;
7757 unsigned VecTySize = DL.getTypeStoreSize(VecTy);
7758 unsigned LegalVTSize = LegalVT.getStoreSize();
7759 unsigned NumOfMemOps = (VecTySize + LegalVTSize - 1) / LegalVTSize;
7760
7761 // Get the cost of one memory operation.
7762 auto *SingleMemOpTy = FixedVectorType::get(VecTy->getElementType(),
7763 LegalVT.getVectorNumElements());
7764 InstructionCost MemOpCost;
7765 bool UseMaskedMemOp = UseMaskForCond || UseMaskForGaps;
7766 if (UseMaskedMemOp) {
7767 unsigned IID = Opcode == Instruction::Load ? Intrinsic::masked_load
7768 : Intrinsic::masked_store;
7769 MemOpCost = getMaskedMemoryOpCost(
7770 {IID, SingleMemOpTy, Alignment, AddressSpace}, CostKind);
7771 } else
7772 MemOpCost = getMemoryOpCost(Opcode, SingleMemOpTy, Alignment, AddressSpace,
7773 CostKind);
7774
7775 unsigned VF = VecTy->getNumElements() / Factor;
7776 MVT VT =
7777 MVT::getVectorVT(TLI->getSimpleValueType(DL, VecTy->getScalarType()), VF);
7778
7779 InstructionCost MaskCost;
7780 if (UseMaskedMemOp) {
7781 APInt DemandedLoadStoreElts = APInt::getZero(VecTy->getNumElements());
7782 for (unsigned Index : Indices) {
7783 assert(Index < Factor && "Invalid index for interleaved memory op");
7784 for (unsigned Elm = 0; Elm < VF; Elm++)
7785 DemandedLoadStoreElts.setBit(Index + Elm * Factor);
7786 }
7787
7788 Type *I1Type = Type::getInt1Ty(VecTy->getContext());
7789
7790 MaskCost = getReplicationShuffleCost(
7791 I1Type, Factor, VF,
7792 UseMaskForGaps ? DemandedLoadStoreElts
7794 CostKind);
7795
7796 // The Gaps mask is invariant and created outside the loop, therefore the
7797 // cost of creating it is not accounted for here. However if we have both
7798 // a MaskForGaps and some other mask that guards the execution of the
7799 // memory access, we need to account for the cost of And-ing the two masks
7800 // inside the loop.
7801 if (UseMaskForGaps) {
7802 auto *MaskVT = FixedVectorType::get(I1Type, VecTy->getNumElements());
7803 MaskCost += getArithmeticInstrCost(BinaryOperator::And, MaskVT, CostKind);
7804 }
7805 }
7806
7807 if (Opcode == Instruction::Load) {
7808 // The tables (AVX512InterleavedLoadTbl and AVX512InterleavedStoreTbl)
7809 // contain the cost of the optimized shuffle sequence that the
7810 // X86InterleavedAccess pass will generate.
7811 // The cost of loads and stores are computed separately from the table.
7812
7813 // X86InterleavedAccess support only the following interleaved-access group.
7814 static const CostTblEntry AVX512InterleavedLoadTbl[] = {
7815 {3, MVT::v16i8, 12}, //(load 48i8 and) deinterleave into 3 x 16i8
7816 {3, MVT::v32i8, 14}, //(load 96i8 and) deinterleave into 3 x 32i8
7817 {3, MVT::v64i8, 22}, //(load 96i8 and) deinterleave into 3 x 32i8
7818 };
7819
7820 if (const auto *Entry =
7821 CostTableLookup(AVX512InterleavedLoadTbl, Factor, VT))
7822 return MaskCost + NumOfMemOps * MemOpCost + Entry->Cost;
7823 //If an entry does not exist, fallback to the default implementation.
7824
7825 // Kind of shuffle depends on number of loaded values.
7826 // If we load the entire data in one register, we can use a 1-src shuffle.
7827 // Otherwise, we'll merge 2 sources in each operation.
7828 TTI::ShuffleKind ShuffleKind =
7829 (NumOfMemOps > 1) ? TTI::SK_PermuteTwoSrc : TTI::SK_PermuteSingleSrc;
7830
7831 InstructionCost ShuffleCost = getShuffleCost(
7832 ShuffleKind, SingleMemOpTy, SingleMemOpTy, CostKind, {}, 0, nullptr);
7833
7834 unsigned NumOfLoadsInInterleaveGrp =
7835 Indices.size() ? Indices.size() : Factor;
7836 auto *ResultTy = FixedVectorType::get(VecTy->getElementType(),
7837 VecTy->getNumElements() / Factor);
7838 InstructionCost NumOfResults =
7839 getTypeLegalizationCost(ResultTy).first * NumOfLoadsInInterleaveGrp;
7840
7841 // About a half of the loads may be folded in shuffles when we have only
7842 // one result. If we have more than one result, or the loads are masked,
7843 // we do not fold loads at all.
7844 unsigned NumOfUnfoldedLoads =
7845 UseMaskedMemOp || NumOfResults > 1 ? NumOfMemOps : NumOfMemOps / 2;
7846
7847 // Get a number of shuffle operations per result.
7848 unsigned NumOfShufflesPerResult =
7849 std::max((unsigned)1, (unsigned)(NumOfMemOps - 1));
7850
7851 // The SK_MergeTwoSrc shuffle clobbers one of src operands.
7852 // When we have more than one destination, we need additional instructions
7853 // to keep sources.
7854 InstructionCost NumOfMoves = 0;
7855 if (NumOfResults > 1 && ShuffleKind == TTI::SK_PermuteTwoSrc)
7856 NumOfMoves = NumOfResults * NumOfShufflesPerResult / 2;
7857
7858 InstructionCost Cost = NumOfResults * NumOfShufflesPerResult * ShuffleCost +
7859 MaskCost + NumOfUnfoldedLoads * MemOpCost +
7860 NumOfMoves;
7861
7862 return Cost;
7863 }
7864
7865 // Store.
7866 assert(Opcode == Instruction::Store &&
7867 "Expected Store Instruction at this point");
7868 // X86InterleavedAccess support only the following interleaved-access group.
7869 static const CostTblEntry AVX512InterleavedStoreTbl[] = {
7870 {3, MVT::v16i8, 12}, // interleave 3 x 16i8 into 48i8 (and store)
7871 {3, MVT::v32i8, 14}, // interleave 3 x 32i8 into 96i8 (and store)
7872 {3, MVT::v64i8, 26}, // interleave 3 x 64i8 into 96i8 (and store)
7873
7874 {4, MVT::v8i8, 10}, // interleave 4 x 8i8 into 32i8 (and store)
7875 {4, MVT::v16i8, 11}, // interleave 4 x 16i8 into 64i8 (and store)
7876 {4, MVT::v32i8, 14}, // interleave 4 x 32i8 into 128i8 (and store)
7877 {4, MVT::v64i8, 24} // interleave 4 x 32i8 into 256i8 (and store)
7878 };
7879
7880 if (const auto *Entry =
7881 CostTableLookup(AVX512InterleavedStoreTbl, Factor, VT))
7882 return MaskCost + NumOfMemOps * MemOpCost + Entry->Cost;
7883 //If an entry does not exist, fallback to the default implementation.
7884
7885 // There is no strided stores meanwhile. And store can't be folded in
7886 // shuffle.
7887 unsigned NumOfSources = Factor; // The number of values to be merged.
7888 InstructionCost ShuffleCost =
7889 getShuffleCost(TTI::SK_PermuteTwoSrc, SingleMemOpTy, SingleMemOpTy,
7890 CostKind, {}, 0, nullptr);
7891 unsigned NumOfShufflesPerStore = NumOfSources - 1;
7892
7893 // The SK_MergeTwoSrc shuffle clobbers one of src operands.
7894 // We need additional instructions to keep sources.
7895 unsigned NumOfMoves = NumOfMemOps * NumOfShufflesPerStore / 2;
7897 MaskCost +
7898 NumOfMemOps * (MemOpCost + NumOfShufflesPerStore * ShuffleCost) +
7899 NumOfMoves;
7900 return Cost;
7901}
7902
7904 unsigned Opcode, Type *BaseTy, unsigned Factor, ArrayRef<unsigned> Indices,
7905 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
7906 bool UseMaskForCond, bool UseMaskForGaps) const {
7907 auto *VecTy = cast<FixedVectorType>(BaseTy);
7908
7909 auto isSupportedOnAVX512 = [&](Type *VecTy) {
7910 Type *EltTy = cast<VectorType>(VecTy)->getElementType();
7911 if (EltTy->isFloatTy() || EltTy->isDoubleTy() || EltTy->isIntegerTy(64) ||
7912 EltTy->isIntegerTy(32) || EltTy->isPointerTy())
7913 return true;
7914 if (EltTy->isIntegerTy(16) || EltTy->isIntegerTy(8) || EltTy->isHalfTy())
7915 return ST->hasBWI();
7916 if (EltTy->isBFloatTy())
7917 return ST->hasBF16();
7918 return false;
7919 };
7920 if (ST->hasAVX512() && isSupportedOnAVX512(VecTy))
7922 Opcode, VecTy, Factor, Indices, Alignment,
7923 AddressSpace, CostKind, UseMaskForCond, UseMaskForGaps);
7924
7925 if (UseMaskForCond || UseMaskForGaps)
7926 return BaseT::getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
7927 Alignment, AddressSpace, CostKind,
7928 UseMaskForCond, UseMaskForGaps);
7929
7930 // Get estimation for interleaved load/store operations for SSE-AVX2.
7931 // As opposed to AVX-512, SSE-AVX2 do not have generic shuffles that allow
7932 // computing the cost using a generic formula as a function of generic
7933 // shuffles. We therefore use a lookup table instead, filled according to
7934 // the instruction sequences that codegen currently generates.
7935
7936 // VecTy for interleave memop is <VF*Factor x Elt>.
7937 // So, for VF=4, Interleave Factor = 3, Element type = i32 we have
7938 // VecTy = <12 x i32>.
7939 MVT LegalVT = getTypeLegalizationCost(VecTy).second;
7940
7941 // This function can be called with VecTy=<6xi128>, Factor=3, in which case
7942 // the VF=2, while v2i128 is an unsupported MVT vector type
7943 // (see MachineValueType.h::getVectorVT()).
7944 if (!LegalVT.isVector())
7945 return BaseT::getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
7946 Alignment, AddressSpace, CostKind);
7947
7948 unsigned VF = VecTy->getNumElements() / Factor;
7949 Type *ScalarTy = VecTy->getElementType();
7950 // Deduplicate entries, model floats/pointers as appropriately-sized integers.
7951 if (!ScalarTy->isIntegerTy())
7952 ScalarTy =
7953 Type::getIntNTy(ScalarTy->getContext(), DL.getTypeSizeInBits(ScalarTy));
7954
7955 // Get the cost of all the memory operations.
7956 // FIXME: discount dead loads.
7957 InstructionCost MemOpCosts =
7958 getMemoryOpCost(Opcode, VecTy, Alignment, AddressSpace, CostKind);
7959
7960 auto *VT = FixedVectorType::get(ScalarTy, VF);
7961 EVT ETy = TLI->getValueType(DL, VT);
7962 if (!ETy.isSimple())
7963 return BaseT::getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
7964 Alignment, AddressSpace, CostKind);
7965
7966 // TODO: Complete for other data-types and strides.
7967 // Each combination of Stride, element bit width and VF results in a different
7968 // sequence; The cost tables are therefore accessed with:
7969 // Factor (stride) and VectorType=VFxiN.
7970 // The Cost accounts only for the shuffle sequence;
7971 // The cost of the loads/stores is accounted for separately.
7972 //
7973 static const CostTblEntry AVX2InterleavedLoadTbl[] = {
7974 {2, MVT::v2i8, 2}, // (load 4i8 and) deinterleave into 2 x 2i8
7975 {2, MVT::v4i8, 2}, // (load 8i8 and) deinterleave into 2 x 4i8
7976 {2, MVT::v8i8, 2}, // (load 16i8 and) deinterleave into 2 x 8i8
7977 {2, MVT::v16i8, 4}, // (load 32i8 and) deinterleave into 2 x 16i8
7978 {2, MVT::v32i8, 6}, // (load 64i8 and) deinterleave into 2 x 32i8
7979
7980 {2, MVT::v8i16, 6}, // (load 16i16 and) deinterleave into 2 x 8i16
7981 {2, MVT::v16i16, 9}, // (load 32i16 and) deinterleave into 2 x 16i16
7982 {2, MVT::v32i16, 18}, // (load 64i16 and) deinterleave into 2 x 32i16
7983
7984 {2, MVT::v8i32, 4}, // (load 16i32 and) deinterleave into 2 x 8i32
7985 {2, MVT::v16i32, 8}, // (load 32i32 and) deinterleave into 2 x 16i32
7986 {2, MVT::v32i32, 16}, // (load 64i32 and) deinterleave into 2 x 32i32
7987
7988 {2, MVT::v4i64, 4}, // (load 8i64 and) deinterleave into 2 x 4i64
7989 {2, MVT::v8i64, 8}, // (load 16i64 and) deinterleave into 2 x 8i64
7990 {2, MVT::v16i64, 16}, // (load 32i64 and) deinterleave into 2 x 16i64
7991 {2, MVT::v32i64, 32}, // (load 64i64 and) deinterleave into 2 x 32i64
7992
7993 {3, MVT::v2i8, 3}, // (load 6i8 and) deinterleave into 3 x 2i8
7994 {3, MVT::v4i8, 3}, // (load 12i8 and) deinterleave into 3 x 4i8
7995 {3, MVT::v8i8, 6}, // (load 24i8 and) deinterleave into 3 x 8i8
7996 {3, MVT::v16i8, 11}, // (load 48i8 and) deinterleave into 3 x 16i8
7997 {3, MVT::v32i8, 14}, // (load 96i8 and) deinterleave into 3 x 32i8
7998
7999 {3, MVT::v2i16, 5}, // (load 6i16 and) deinterleave into 3 x 2i16
8000 {3, MVT::v4i16, 7}, // (load 12i16 and) deinterleave into 3 x 4i16
8001 {3, MVT::v8i16, 9}, // (load 24i16 and) deinterleave into 3 x 8i16
8002 {3, MVT::v16i16, 28}, // (load 48i16 and) deinterleave into 3 x 16i16
8003 {3, MVT::v32i16, 56}, // (load 96i16 and) deinterleave into 3 x 32i16
8004
8005 {3, MVT::v2i32, 3}, // (load 6i32 and) deinterleave into 3 x 2i32
8006 {3, MVT::v4i32, 3}, // (load 12i32 and) deinterleave into 3 x 4i32
8007 {3, MVT::v8i32, 7}, // (load 24i32 and) deinterleave into 3 x 8i32
8008 {3, MVT::v16i32, 14}, // (load 48i32 and) deinterleave into 3 x 16i32
8009 {3, MVT::v32i32, 32}, // (load 96i32 and) deinterleave into 3 x 32i32
8010
8011 {3, MVT::v2i64, 1}, // (load 6i64 and) deinterleave into 3 x 2i64
8012 {3, MVT::v4i64, 5}, // (load 12i64 and) deinterleave into 3 x 4i64
8013 {3, MVT::v8i64, 10}, // (load 24i64 and) deinterleave into 3 x 8i64
8014 {3, MVT::v16i64, 20}, // (load 48i64 and) deinterleave into 3 x 16i64
8015
8016 {4, MVT::v2i8, 4}, // (load 8i8 and) deinterleave into 4 x 2i8
8017 {4, MVT::v4i8, 4}, // (load 16i8 and) deinterleave into 4 x 4i8
8018 {4, MVT::v8i8, 12}, // (load 32i8 and) deinterleave into 4 x 8i8
8019 {4, MVT::v16i8, 24}, // (load 64i8 and) deinterleave into 4 x 16i8
8020 {4, MVT::v32i8, 56}, // (load 128i8 and) deinterleave into 4 x 32i8
8021
8022 {4, MVT::v2i16, 6}, // (load 8i16 and) deinterleave into 4 x 2i16
8023 {4, MVT::v4i16, 17}, // (load 16i16 and) deinterleave into 4 x 4i16
8024 {4, MVT::v8i16, 33}, // (load 32i16 and) deinterleave into 4 x 8i16
8025 {4, MVT::v16i16, 75}, // (load 64i16 and) deinterleave into 4 x 16i16
8026 {4, MVT::v32i16, 150}, // (load 128i16 and) deinterleave into 4 x 32i16
8027
8028 {4, MVT::v2i32, 4}, // (load 8i32 and) deinterleave into 4 x 2i32
8029 {4, MVT::v4i32, 8}, // (load 16i32 and) deinterleave into 4 x 4i32
8030 {4, MVT::v8i32, 16}, // (load 32i32 and) deinterleave into 4 x 8i32
8031 {4, MVT::v16i32, 32}, // (load 64i32 and) deinterleave into 4 x 16i32
8032 {4, MVT::v32i32, 68}, // (load 128i32 and) deinterleave into 4 x 32i32
8033
8034 {4, MVT::v2i64, 6}, // (load 8i64 and) deinterleave into 4 x 2i64
8035 {4, MVT::v4i64, 8}, // (load 16i64 and) deinterleave into 4 x 4i64
8036 {4, MVT::v8i64, 20}, // (load 32i64 and) deinterleave into 4 x 8i64
8037 {4, MVT::v16i64, 40}, // (load 64i64 and) deinterleave into 4 x 16i64
8038
8039 {6, MVT::v2i8, 6}, // (load 12i8 and) deinterleave into 6 x 2i8
8040 {6, MVT::v4i8, 14}, // (load 24i8 and) deinterleave into 6 x 4i8
8041 {6, MVT::v8i8, 18}, // (load 48i8 and) deinterleave into 6 x 8i8
8042 {6, MVT::v16i8, 43}, // (load 96i8 and) deinterleave into 6 x 16i8
8043 {6, MVT::v32i8, 82}, // (load 192i8 and) deinterleave into 6 x 32i8
8044
8045 {6, MVT::v2i16, 13}, // (load 12i16 and) deinterleave into 6 x 2i16
8046 {6, MVT::v4i16, 9}, // (load 24i16 and) deinterleave into 6 x 4i16
8047 {6, MVT::v8i16, 39}, // (load 48i16 and) deinterleave into 6 x 8i16
8048 {6, MVT::v16i16, 106}, // (load 96i16 and) deinterleave into 6 x 16i16
8049 {6, MVT::v32i16, 212}, // (load 192i16 and) deinterleave into 6 x 32i16
8050
8051 {6, MVT::v2i32, 6}, // (load 12i32 and) deinterleave into 6 x 2i32
8052 {6, MVT::v4i32, 15}, // (load 24i32 and) deinterleave into 6 x 4i32
8053 {6, MVT::v8i32, 31}, // (load 48i32 and) deinterleave into 6 x 8i32
8054 {6, MVT::v16i32, 64}, // (load 96i32 and) deinterleave into 6 x 16i32
8055
8056 {6, MVT::v2i64, 6}, // (load 12i64 and) deinterleave into 6 x 2i64
8057 {6, MVT::v4i64, 18}, // (load 24i64 and) deinterleave into 6 x 4i64
8058 {6, MVT::v8i64, 36}, // (load 48i64 and) deinterleave into 6 x 8i64
8059
8060 {8, MVT::v8i32, 40} // (load 64i32 and) deinterleave into 8 x 8i32
8061 };
8062
8063 static const CostTblEntry SSSE3InterleavedLoadTbl[] = {
8064 {2, MVT::v4i16, 2}, // (load 8i16 and) deinterleave into 2 x 4i16
8065 };
8066
8067 static const CostTblEntry SSE2InterleavedLoadTbl[] = {
8068 {2, MVT::v2i16, 2}, // (load 4i16 and) deinterleave into 2 x 2i16
8069 {2, MVT::v4i16, 7}, // (load 8i16 and) deinterleave into 2 x 4i16
8070
8071 {2, MVT::v2i32, 2}, // (load 4i32 and) deinterleave into 2 x 2i32
8072 {2, MVT::v4i32, 2}, // (load 8i32 and) deinterleave into 2 x 4i32
8073
8074 {2, MVT::v2i64, 2}, // (load 4i64 and) deinterleave into 2 x 2i64
8075 };
8076
8077 static const CostTblEntry AVX2InterleavedStoreTbl[] = {
8078 {2, MVT::v16i8, 3}, // interleave 2 x 16i8 into 32i8 (and store)
8079 {2, MVT::v32i8, 4}, // interleave 2 x 32i8 into 64i8 (and store)
8080
8081 {2, MVT::v8i16, 3}, // interleave 2 x 8i16 into 16i16 (and store)
8082 {2, MVT::v16i16, 4}, // interleave 2 x 16i16 into 32i16 (and store)
8083 {2, MVT::v32i16, 8}, // interleave 2 x 32i16 into 64i16 (and store)
8084
8085 {2, MVT::v4i32, 2}, // interleave 2 x 4i32 into 8i32 (and store)
8086 {2, MVT::v8i32, 4}, // interleave 2 x 8i32 into 16i32 (and store)
8087 {2, MVT::v16i32, 8}, // interleave 2 x 16i32 into 32i32 (and store)
8088 {2, MVT::v32i32, 16}, // interleave 2 x 32i32 into 64i32 (and store)
8089
8090 {2, MVT::v2i64, 2}, // interleave 2 x 2i64 into 4i64 (and store)
8091 {2, MVT::v4i64, 4}, // interleave 2 x 4i64 into 8i64 (and store)
8092 {2, MVT::v8i64, 8}, // interleave 2 x 8i64 into 16i64 (and store)
8093 {2, MVT::v16i64, 16}, // interleave 2 x 16i64 into 32i64 (and store)
8094 {2, MVT::v32i64, 32}, // interleave 2 x 32i64 into 64i64 (and store)
8095
8096 {3, MVT::v2i8, 4}, // interleave 3 x 2i8 into 6i8 (and store)
8097 {3, MVT::v4i8, 4}, // interleave 3 x 4i8 into 12i8 (and store)
8098 {3, MVT::v8i8, 6}, // interleave 3 x 8i8 into 24i8 (and store)
8099 {3, MVT::v16i8, 11}, // interleave 3 x 16i8 into 48i8 (and store)
8100 {3, MVT::v32i8, 13}, // interleave 3 x 32i8 into 96i8 (and store)
8101
8102 {3, MVT::v2i16, 4}, // interleave 3 x 2i16 into 6i16 (and store)
8103 {3, MVT::v4i16, 6}, // interleave 3 x 4i16 into 12i16 (and store)
8104 {3, MVT::v8i16, 12}, // interleave 3 x 8i16 into 24i16 (and store)
8105 {3, MVT::v16i16, 27}, // interleave 3 x 16i16 into 48i16 (and store)
8106 {3, MVT::v32i16, 54}, // interleave 3 x 32i16 into 96i16 (and store)
8107
8108 {3, MVT::v2i32, 4}, // interleave 3 x 2i32 into 6i32 (and store)
8109 {3, MVT::v4i32, 5}, // interleave 3 x 4i32 into 12i32 (and store)
8110 {3, MVT::v8i32, 11}, // interleave 3 x 8i32 into 24i32 (and store)
8111 {3, MVT::v16i32, 22}, // interleave 3 x 16i32 into 48i32 (and store)
8112 {3, MVT::v32i32, 48}, // interleave 3 x 32i32 into 96i32 (and store)
8113
8114 {3, MVT::v2i64, 4}, // interleave 3 x 2i64 into 6i64 (and store)
8115 {3, MVT::v4i64, 6}, // interleave 3 x 4i64 into 12i64 (and store)
8116 {3, MVT::v8i64, 12}, // interleave 3 x 8i64 into 24i64 (and store)
8117 {3, MVT::v16i64, 24}, // interleave 3 x 16i64 into 48i64 (and store)
8118
8119 {4, MVT::v2i8, 4}, // interleave 4 x 2i8 into 8i8 (and store)
8120 {4, MVT::v4i8, 4}, // interleave 4 x 4i8 into 16i8 (and store)
8121 {4, MVT::v8i8, 4}, // interleave 4 x 8i8 into 32i8 (and store)
8122 {4, MVT::v16i8, 8}, // interleave 4 x 16i8 into 64i8 (and store)
8123 {4, MVT::v32i8, 12}, // interleave 4 x 32i8 into 128i8 (and store)
8124
8125 {4, MVT::v2i16, 2}, // interleave 4 x 2i16 into 8i16 (and store)
8126 {4, MVT::v4i16, 6}, // interleave 4 x 4i16 into 16i16 (and store)
8127 {4, MVT::v8i16, 10}, // interleave 4 x 8i16 into 32i16 (and store)
8128 {4, MVT::v16i16, 32}, // interleave 4 x 16i16 into 64i16 (and store)
8129 {4, MVT::v32i16, 64}, // interleave 4 x 32i16 into 128i16 (and store)
8130
8131 {4, MVT::v2i32, 5}, // interleave 4 x 2i32 into 8i32 (and store)
8132 {4, MVT::v4i32, 6}, // interleave 4 x 4i32 into 16i32 (and store)
8133 {4, MVT::v8i32, 16}, // interleave 4 x 8i32 into 32i32 (and store)
8134 {4, MVT::v16i32, 32}, // interleave 4 x 16i32 into 64i32 (and store)
8135 {4, MVT::v32i32, 64}, // interleave 4 x 32i32 into 128i32 (and store)
8136
8137 {4, MVT::v2i64, 6}, // interleave 4 x 2i64 into 8i64 (and store)
8138 {4, MVT::v4i64, 8}, // interleave 4 x 4i64 into 16i64 (and store)
8139 {4, MVT::v8i64, 20}, // interleave 4 x 8i64 into 32i64 (and store)
8140 {4, MVT::v16i64, 40}, // interleave 4 x 16i64 into 64i64 (and store)
8141
8142 {6, MVT::v2i8, 7}, // interleave 6 x 2i8 into 12i8 (and store)
8143 {6, MVT::v4i8, 9}, // interleave 6 x 4i8 into 24i8 (and store)
8144 {6, MVT::v8i8, 16}, // interleave 6 x 8i8 into 48i8 (and store)
8145 {6, MVT::v16i8, 27}, // interleave 6 x 16i8 into 96i8 (and store)
8146 {6, MVT::v32i8, 90}, // interleave 6 x 32i8 into 192i8 (and store)
8147
8148 {6, MVT::v2i16, 10}, // interleave 6 x 2i16 into 12i16 (and store)
8149 {6, MVT::v4i16, 15}, // interleave 6 x 4i16 into 24i16 (and store)
8150 {6, MVT::v8i16, 21}, // interleave 6 x 8i16 into 48i16 (and store)
8151 {6, MVT::v16i16, 58}, // interleave 6 x 16i16 into 96i16 (and store)
8152 {6, MVT::v32i16, 90}, // interleave 6 x 32i16 into 192i16 (and store)
8153
8154 {6, MVT::v2i32, 9}, // interleave 6 x 2i32 into 12i32 (and store)
8155 {6, MVT::v4i32, 12}, // interleave 6 x 4i32 into 24i32 (and store)
8156 {6, MVT::v8i32, 33}, // interleave 6 x 8i32 into 48i32 (and store)
8157 {6, MVT::v16i32, 66}, // interleave 6 x 16i32 into 96i32 (and store)
8158
8159 {6, MVT::v2i64, 8}, // interleave 6 x 2i64 into 12i64 (and store)
8160 {6, MVT::v4i64, 15}, // interleave 6 x 4i64 into 24i64 (and store)
8161 {6, MVT::v8i64, 30}, // interleave 6 x 8i64 into 48i64 (and store)
8162 };
8163
8164 static const CostTblEntry SSE2InterleavedStoreTbl[] = {
8165 {2, MVT::v2i8, 1}, // interleave 2 x 2i8 into 4i8 (and store)
8166 {2, MVT::v4i8, 1}, // interleave 2 x 4i8 into 8i8 (and store)
8167 {2, MVT::v8i8, 1}, // interleave 2 x 8i8 into 16i8 (and store)
8168
8169 {2, MVT::v2i16, 1}, // interleave 2 x 2i16 into 4i16 (and store)
8170 {2, MVT::v4i16, 1}, // interleave 2 x 4i16 into 8i16 (and store)
8171
8172 {2, MVT::v2i32, 1}, // interleave 2 x 2i32 into 4i32 (and store)
8173 };
8174
8175 if (Opcode == Instruction::Load) {
8176 auto GetDiscountedCost = [Factor, NumMembers = Indices.size(),
8177 MemOpCosts](const CostTblEntry *Entry) {
8178 // NOTE: this is just an approximation!
8179 // It can over/under -estimate the cost!
8180 return MemOpCosts + divideCeil(NumMembers * Entry->Cost, Factor);
8181 };
8182
8183 if (ST->hasAVX2())
8184 if (const auto *Entry = CostTableLookup(AVX2InterleavedLoadTbl, Factor,
8185 ETy.getSimpleVT()))
8186 return GetDiscountedCost(Entry);
8187
8188 if (ST->hasSSSE3())
8189 if (const auto *Entry = CostTableLookup(SSSE3InterleavedLoadTbl, Factor,
8190 ETy.getSimpleVT()))
8191 return GetDiscountedCost(Entry);
8192
8193 if (ST->hasSSE2())
8194 if (const auto *Entry = CostTableLookup(SSE2InterleavedLoadTbl, Factor,
8195 ETy.getSimpleVT()))
8196 return GetDiscountedCost(Entry);
8197 } else {
8198 assert(Opcode == Instruction::Store &&
8199 "Expected Store Instruction at this point");
8200 assert((!Indices.size() || Indices.size() == Factor) &&
8201 "Interleaved store only supports fully-interleaved groups.");
8202 if (ST->hasAVX2())
8203 if (const auto *Entry = CostTableLookup(AVX2InterleavedStoreTbl, Factor,
8204 ETy.getSimpleVT()))
8205 return MemOpCosts + Entry->Cost;
8206
8207 if (ST->hasSSE2())
8208 if (const auto *Entry = CostTableLookup(SSE2InterleavedStoreTbl, Factor,
8209 ETy.getSimpleVT()))
8210 return MemOpCosts + Entry->Cost;
8211 }
8212
8213 return BaseT::getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
8214 Alignment, AddressSpace, CostKind,
8215 UseMaskForCond, UseMaskForGaps);
8216}
8217
8219 StackOffset BaseOffset,
8220 bool HasBaseReg, int64_t Scale,
8221 unsigned AddrSpace) const {
8222 // Scaling factors are not free at all.
8223 // An indexed folded instruction, i.e., inst (reg1, reg2, scale),
8224 // will take 2 allocations in the out of order engine instead of 1
8225 // for plain addressing mode, i.e. inst (reg1).
8226 // E.g.,
8227 // vaddps (%rsi,%rdx), %ymm0, %ymm1
8228 // Requires two allocations (one for the load, one for the computation)
8229 // whereas:
8230 // vaddps (%rsi), %ymm0, %ymm1
8231 // Requires just 1 allocation, i.e., freeing allocations for other operations
8232 // and having less micro operations to execute.
8233 //
8234 // For some X86 architectures, this is even worse because for instance for
8235 // stores, the complex addressing mode forces the instruction to use the
8236 // "load" ports instead of the dedicated "store" port.
8237 // E.g., on Haswell:
8238 // vmovaps %ymm1, (%r8, %rdi) can use port 2 or 3.
8239 // vmovaps %ymm1, (%r8) can use port 2, 3, or 7.
8241 AM.BaseGV = BaseGV;
8242 AM.BaseOffs = BaseOffset.getFixed();
8243 AM.HasBaseReg = HasBaseReg;
8244 AM.Scale = Scale;
8245 AM.ScalableOffset = BaseOffset.getScalable();
8246 if (getTLI()->isLegalAddressingMode(DL, AM, Ty, AddrSpace))
8247 // Scale represents reg2 * scale, thus account for 1
8248 // as soon as we use a second register.
8249 return AM.Scale != 0;
8251}
8252
8254 // TODO: Hook MispredictPenalty of SchedMachineModel into this.
8255 return 14;
8256}
8257
8259 unsigned Bits = Ty->getScalarSizeInBits();
8260
8261 // XOP has v16i8/v8i16/v4i32/v2i64 variable vector shifts.
8262 // Splitting for v32i8/v16i16 on XOP+AVX2 targets is still preferred.
8263 if (ST->hasXOP() && (Bits == 8 || Bits == 16 || Bits == 32 || Bits == 64))
8264 return false;
8265
8266 // AVX2 has vpsllv[dq] instructions (and other shifts) that make variable
8267 // shifts just as cheap as scalar ones.
8268 if (ST->hasAVX2() && (Bits == 32 || Bits == 64))
8269 return false;
8270
8271 // AVX512BW has shifts such as vpsllvw.
8272 if (ST->hasBWI() && Bits == 16)
8273 return false;
8274
8275 // Otherwise, it's significantly cheaper to shift by a scalar amount than by a
8276 // fully general vector.
8277 return true;
8278}
8279
8280unsigned X86TTIImpl::getStoreMinimumVF(unsigned VF, Type *ScalarMemTy,
8281 Type *ScalarValTy, Align Alignment,
8282 unsigned AddrSpace) const {
8283 if (ST->hasF16C() && ScalarMemTy->isHalfTy()) {
8284 return 4;
8285 }
8286 return BaseT::getStoreMinimumVF(VF, ScalarMemTy, ScalarValTy, Alignment,
8287 AddrSpace);
8288}
8289
8291 SmallVectorImpl<Use *> &Ops) const {
8292 using namespace llvm::PatternMatch;
8293
8294 if (I->getOpcode() == Instruction::And &&
8295 (ST->hasBMI() || (I->getType()->isVectorTy() && ST->hasSSE2()))) {
8296 for (auto &Op : I->operands()) {
8297 // (and X, (not Y)) -> (andn X, Y)
8298 if (match(Op.get(), m_Not(m_Value())) && !I->getType()->isIntegerTy(8)) {
8299 Ops.push_back(&Op);
8300 return true;
8301 }
8302 // (and X, (splat (not Y))) -> (andn X, (splat Y))
8303 if (match(Op.get(),
8305 m_Value(), m_ZeroMask()))) {
8306 Use &InsertElt = cast<Instruction>(Op)->getOperandUse(0);
8307 Use &Not = cast<Instruction>(InsertElt)->getOperandUse(1);
8308 Ops.push_back(&Not);
8309 Ops.push_back(&InsertElt);
8310 Ops.push_back(&Op);
8311 return true;
8312 }
8313 }
8314 }
8315
8316 FixedVectorType *VTy = dyn_cast<FixedVectorType>(I->getType());
8317 if (!VTy)
8318 return false;
8319
8320 if (I->getOpcode() == Instruction::Mul &&
8321 VTy->getElementType()->isIntegerTy(64)) {
8322 for (auto &Op : I->operands()) {
8323 // Make sure we are not already sinking this operand
8324 if (any_of(Ops, [&](Use *U) { return U->get() == Op; }))
8325 continue;
8326
8327 // Look for PMULDQ pattern where the input is a sext_inreg from vXi32 or
8328 // the PMULUDQ pattern where the input is a zext_inreg from vXi32.
8329 if (ST->hasSSE41() &&
8330 match(Op.get(), m_AShr(m_Shl(m_Value(), m_SpecificInt(32)),
8331 m_SpecificInt(32)))) {
8332 Ops.push_back(&cast<Instruction>(Op)->getOperandUse(0));
8333 Ops.push_back(&Op);
8334 } else if (ST->hasSSE2() &&
8335 match(Op.get(),
8336 m_And(m_Value(), m_SpecificInt(UINT64_C(0xffffffff))))) {
8337 Ops.push_back(&Op);
8338 }
8339 }
8340
8341 return !Ops.empty();
8342 }
8343
8344 // A uniform shift amount in a vector shift or funnel shift may be much
8345 // cheaper than a generic variable vector shift, so make that pattern visible
8346 // to SDAG by sinking the shuffle instruction next to the shift.
8347 int ShiftAmountOpNum = -1;
8348 if (I->isShift())
8349 ShiftAmountOpNum = 1;
8350 else if (auto *II = dyn_cast<IntrinsicInst>(I)) {
8351 if (II->getIntrinsicID() == Intrinsic::fshl ||
8352 II->getIntrinsicID() == Intrinsic::fshr)
8353 ShiftAmountOpNum = 2;
8354 }
8355
8356 if (ShiftAmountOpNum == -1)
8357 return false;
8358
8359 auto *Shuf = dyn_cast<ShuffleVectorInst>(I->getOperand(ShiftAmountOpNum));
8360 if (Shuf && getSplatIndex(Shuf->getShuffleMask()) >= 0 &&
8361 isVectorShiftByScalarCheap(I->getType())) {
8362 Ops.push_back(&I->getOperandUse(ShiftAmountOpNum));
8363 return true;
8364 }
8365
8366 return false;
8367}
8368
8370 bool HasEGPR = ST->hasEGPR();
8371 bool UseAPXFastCC = ST->useAPXFastCC();
8372 const TargetMachine &TM = getTLI()->getTargetMachine();
8373
8374 for (User *U : F.users()) {
8376 if (!CB || CB->getCalledOperand() != &F)
8377 continue;
8378 Function *CallerFunc = CB->getFunction();
8379 const X86Subtarget &CallerST = TM.getSubtarget<X86Subtarget>(*CallerFunc);
8380 if (CallerST.hasEGPR() != HasEGPR ||
8381 CallerST.useAPXFastCC() != UseAPXFastCC)
8382 return false;
8383 }
8384
8385 return true;
8386}
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t Imm
Expand Atomic instructions
This file provides a helper that implements much of the TTI interface in terms of the target-independ...
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Cost tables and simple lookup functions.
Hexagon Common GEP
iv users
Definition IVUsers.cpp:48
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static LVOptions Options
Definition LVOptions.cpp:25
unsigned Opc
CostTblEntryT< CostKindCosts > CostKindTblEntry
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
uint64_t IntrinsicInst * II
#define P(N)
int64_t C1
RISCVCC::CondCode CC
This file implements the SmallBitVector class.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
This file describes how to lower LLVM code to machine code.
This pass exposes codegen information to IR-level passes.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static InstructionCost getPredicateFanoutCost(const X86TTIImpl &TTI, Type *DataVTy, Type *MaskVTy)
static bool isFoldedIntoRsqrtEstimate(const Value *V, const X86TargetLowering &TLI, MVT VT, TTI::TargetCostKind CostKind)
Returns true if V is the square root, divided into with the reciprocal allowed, and the target replac...
static bool isLegalMaskedLoadStore(Type *ScalarTy, const X86Subtarget *ST)
TypeConversionCostTblEntryT< CostKindCosts > TypeConversionCostKindTblEntry
This file a TargetTransformInfoImplBase conforming object specific to the X86 target machine.
static LLVM_ABI unsigned int semanticsPrecision(const fltSemantics &)
Definition APFloat.cpp:609
static constexpr const fltSemantics & IEEEsingle()
Definition APFloat.h:304
static constexpr const fltSemantics & IEEEdouble()
Definition APFloat.h:305
Class for arbitrary precision integers.
Definition APInt.h:78
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
Definition APInt.h:230
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
Definition APInt.cpp:1057
unsigned popcount() const
Count the number of bits set.
Definition APInt.h:1690
void setBit(unsigned BitPosition)
Set the given bit to 1 whose position is given as "bitPosition".
Definition APInt.h:1350
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
Definition APInt.h:367
static APInt getBitsSet(unsigned numBits, unsigned loBit, unsigned hiBit)
Get a value with a block of bits set.
Definition APInt.h:254
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
Definition APInt.h:376
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1508
LLVM_ABI APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition APInt.cpp:1086
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
Definition APInt.h:829
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition APInt.h:196
LLVM_ABI APInt extractBits(unsigned numBits, unsigned bitPosition) const
Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
Definition APInt.cpp:478
int64_t getSExtValue() const
Get sign extended value.
Definition APInt.h:1582
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
InstructionCost getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, bool UseMaskForCond=false, bool UseMaskForGaps=false) const override
InstructionCost getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF, TTI::TargetCostKind CostKind) const override
TTI::ShuffleKind improveShuffleKindFromMask(TTI::ShuffleKind Kind, ArrayRef< int > Mask, VectorType *SrcTy, int &Index, VectorType *&SubTy) const
bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace, Instruction *I=nullptr, int64_t ScalableOffset=0) const override
unsigned getStoreMinimumVF(unsigned VF, Type *ScalarMemTy, Type *ScalarValTy, Align Alignment, unsigned AddrSpace) const override
InstructionCost getScalarizationOverhead(VectorType *InTy, const APInt &DemandedElts, bool Insert, bool Extract, TTI::TargetCostKind CostKind, bool ForPoisonSrc=true, ArrayRef< Value * > VL={}, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
InstructionCost getArithmeticReductionCost(unsigned Opcode, VectorType *Ty, std::optional< FastMathFlags > FMF, TTI::TargetCostKind CostKind) const override
InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
InstructionCost getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy, TTI::TargetCostKind CostKind, ArrayRef< int > Mask, int Index, VectorType *SubTp, ArrayRef< const Value * > Args={}, const Instruction *CtxI=nullptr, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const override
std::pair< InstructionCost, MVT > getTypeLegalizationCost(Type *Ty) const
InstructionCost getPartialReductionCost(unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType, ElementCount VF, TTI::PartialReductionExtendKind OpAExtend, TTI::PartialReductionExtendKind OpBExtend, std::optional< unsigned > BinOp, TTI::TargetCostKind CostKind, std::optional< FastMathFlags > FMF) const override
InstructionCost getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF, const APInt &DemandedDstElts, TTI::TargetCostKind CostKind) const override
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, const Value *Op0, const Value *Op1, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind) const override
InstructionCost getAddressComputationCost(Type *PtrTy, ScalarEvolution *, const SCEV *, TTI::TargetCostKind) const override
InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef< const Value * > Operands, TTI::TargetCostKind CostKind, Type *AccessType) const override
InstructionCost getMemIntrinsicInstrCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const override
InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, TTI::OperandValueInfo OpInfo={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Opd1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Opd2Info={TTI::OK_AnyValue, TTI::OP_None}, ArrayRef< const Value * > Args={}, const Instruction *CtxI=nullptr, const TargetLibraryInfo *TLibInfo=nullptr, ArrayRef< const Value * > Scalars={}) const override
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Value * getCalledOperand() const
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition InstrTypes.h:743
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:770
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:764
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:763
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition InstrTypes.h:748
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition InstrTypes.h:751
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:765
@ ICMP_NE
not equal
Definition InstrTypes.h:762
@ ICMP_SGE
signed greater or equal
Definition InstrTypes.h:768
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:766
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition InstrTypes.h:750
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
constexpr bool isScalar() const
Exactly one element.
Definition TypeSize.h:317
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:23
Container class for subtarget features.
Class to represent fixed width SIMD vectors.
unsigned getNumElements() const
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:838
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition Function.cpp:731
static unsigned getPointerOperandIndex()
static InstructionCost getInvalid(CostType Val=0)
CostType getValue() const
This function is intended to be used as sparingly as possible, since the class provides the full rang...
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:333
const SmallVectorImpl< Type * > & getArgTypes() const
const SmallVectorImpl< const Value * > & getArgs() const
const IntrinsicInst * getInst() const
A wrapper class for inspecting calls to intrinsic functions.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
Machine Value Type.
bool is128BitVector() const
Return true if this is a 128-bit vector type.
uint64_t getScalarSizeInBits() const
unsigned getVectorNumElements() const
bool isVector() const
Return true if this is a vector value type.
bool isInteger() const
Return true if this is an integer or a vector integer type.
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
bool isScalarInteger() const
Return true if this is an integer, not including vectors.
static MVT getVectorVT(MVT VT, unsigned NumElements)
MVT getVectorElementType() const
MVT getScalarType() const
If this is a vector, return the element type, otherwise return this.
Information for memory intrinsic cost model.
This class represents an analyzed expression in the program.
The main scalar evolution driver.
static LLVM_ABI bool isIdentityMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from exactly one source vector without lane crossin...
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
bool test(unsigned Idx) const
Returns true if bit Idx is set.
size_type size() const
Returns the number of bits in this bitvector.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:31
static StackOffset getScalable(int64_t Scalable)
Definition TypeSize.h:41
static StackOffset getFixed(int64_t Fixed)
Definition TypeSize.h:40
Provides information about what library functions are available for the current target.
virtual MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain combinations of ABIs, Targets and features require that types are legal for some operations a...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Primary interface to the complete machine description for the target machine.
const STC & getSubtarget(const Function &F) const
This method returns a pointer to the specified type of TargetSubtargetInfo.
virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
virtual const TargetLowering * getTargetLowering() const
bool isStridedAccess(const SCEV *Ptr) const
unsigned minRequiredElementSize(const Value *Val, bool &isSigned) const
const SCEVConstant * getConstantStrideStep(ScalarEvolution *SE, const SCEV *Ptr) const
virtual bool isExpensiveToSpeculativelyExecute(const Instruction *I) const
virtual InstructionCost getPointersChainCost(ArrayRef< const Value * > Ptrs, const Value *Base, const TTI::PointersChainInfo &Info, Type *AccessTy, const TTI::TargetCostKind CostKind) const
MaskKind
Some targets only support masked load/store with a constant mask.
TargetCostKind
The kind of cost model.
@ TCK_RecipThroughput
Reciprocal throughput.
@ TCK_CodeSize
Instruction code size.
@ TCK_SizeAndLatency
The weighted sum of size and latency.
@ TCK_Latency
The latency of instruction.
static bool requiresOrderedReduction(std::optional< FastMathFlags > FMF)
A helper function to determine the type of reduction algorithm used for a given Opcode and set of Fas...
llvm::VectorInstrContext VectorInstrContext
@ TCC_Free
Expected to fold away in lowering.
@ TCC_Basic
The cost of a typical 'add' instruction.
ShuffleKind
The various kinds of shuffle patterns for vector queries.
@ SK_InsertSubvector
InsertSubvector. Index indicates start offset.
@ SK_Select
Selects elements from the corresponding lane of either source operand.
@ SK_PermuteSingleSrc
Shuffle elements of single source vector with any shuffle mask.
@ SK_Transpose
Transpose two vectors.
@ SK_Splice
Concatenates elements from the first input vector with elements of the second input vector.
@ SK_Broadcast
Broadcast element 0 to all other elements.
@ SK_PermuteTwoSrc
Merge elements from two source vectors into one with any shuffle mask.
@ SK_Reverse
Reverse the order of the vector.
@ SK_ExtractSubvector
ExtractSubvector Index indicates start offset.
CastContextHint
Represents a hint about the context in which a cast is used.
@ None
The cast is not used with a load/store of any kind.
CacheLevel
The possible cache levels.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:352
static constexpr TypeSize getScalable(ScalarTy MinimumSize)
Definition TypeSize.h:355
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:295
LLVM_ABI unsigned getIntegerBitWidth() const
bool isVectorTy() const
True if this is an instance of VectorType.
Definition Type.h:283
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:294
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition Type.h:258
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:277
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition Type.h:155
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
Definition Type.h:147
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.h:354
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Definition Type.cpp:292
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:370
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition Type.cpp:187
LLVM_ABI Type * getWithNewBitWidth(unsigned NewBitWidth) const
Given an integer or vector type, change the lane bitwidth to NewBitwidth, whilst keeping the old numb...
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Definition Type.h:144
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition Type.h:130
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition Type.h:158
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
Definition Type.cpp:291
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition Type.h:186
LLVM_ABI bool isScalableTy() const
Return true if this is a type whose size is a known multiple of vscale.
Definition Type.cpp:61
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:252
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:298
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
Definition Type.cpp:272
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition Type.h:222
Type * getContainedType(unsigned i) const
This method is used to implement the type iterator (defined at the end of the file).
Definition Type.h:399
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
Definition Type.cpp:271
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
Value * getOperand(unsigned i) const
Definition User.h:207
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
Base class of all SIMD vector types.
static VectorType * getExtendedElementVectorType(VectorType *VTy)
This static method is like getInteger except that the element types are twice as wide as the elements...
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
static VectorType * getDoubleElementsVectorType(VectorType *VTy)
This static method returns a VectorType with twice as many elements as the input type and the same el...
Type * getElementType() const
bool useAVX512Regs() const
bool hasAVX512() const
bool useAPXFastCC() const
bool hasAVX2() const
bool useFastCCForInternalCall(Function &F) const override
bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1, const SmallBitVector &OpcodeMask, ArrayRef< const Value * > Scalars) const override
InstructionCost getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF, const APInt &DemandedDstElts, TTI::TargetCostKind CostKind) const override
bool isLegalNTLoad(Type *DataType, Align Alignment) const override
std::optional< unsigned > getCacheAssociativity(TargetTransformInfo::CacheLevel Level) const override
InstructionCost getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF, TTI::TargetCostKind CostKind) const override
Try to calculate op costs for min/max reduction operations.
bool isLegalBroadcastLoad(Type *ElementTy, ElementCount NumElements) const override
unsigned getRegisterClassForType(bool Vector, Type *Ty) const override
InstructionCost getMemIntrinsicInstrCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const override
Get memory intrinsic cost based on arguments.
unsigned getMaxInterleaveFactor(ElementCount VF, bool HasUnorderedReductions) const override
InstructionCost getPartialReductionCost(unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType, ElementCount VF, TTI::PartialReductionExtendKind OpAExtend, TTI::PartialReductionExtendKind OpBExtend, std::optional< unsigned > BinOp, TTI::TargetCostKind CostKind, std::optional< FastMathFlags > FMF) const override
bool isLegalNTStore(Type *DataType, Align Alignment) const override
InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const override
InstructionCost getInterleavedMemoryOpCostAVX512(unsigned Opcode, FixedVectorType *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, bool UseMaskForCond=false, bool UseMaskForGaps=false) const
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const override
bool isVectorShiftByScalarCheap(Type *Ty) const override
bool isLegalMaskedGather(Type *DataType, Align Alignment) const override
bool shouldExpandReduction(const IntrinsicInst *II) const override
InstructionCost getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, StackOffset BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace) const override
Return the cost of the scaling factor used in the addressing mode represented by AM for this target,...
unsigned getAtomicMemIntrinsicMaxElementSize() const override
bool forceScalarizeMaskedGather(VectorType *VTy, Align Alignment) const override
InstructionCost getBranchMispredictPenalty() const override
bool isExpensiveToSpeculativelyExecute(const Instruction *I) const override
bool hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const override
InstructionCost getAltInstrCost(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1, const SmallBitVector &OpcodeMask, TTI::TargetCostKind CostKind, ArrayRef< const Value * > Scalars) const override
bool isLegalMaskedStore(Type *DataType, Align Alignment, unsigned AddressSpace, TTI::MaskKind MaskKind=TTI::MaskKind::VariableOrConstantMask) const override
std::optional< unsigned > getCacheSize(TargetTransformInfo::CacheLevel Level) const override
bool isLegalMaskedGatherScatter(Type *DataType, Align Alignment) const
bool isLegalMaskedLoad(Type *DataType, Align Alignment, unsigned AddressSpace, TTI::MaskKind MaskKind=TTI::MaskKind::VariableOrConstantMask) const override
bool enableInterleavedAccessVectorization() const override
unsigned getLoadStoreVecRegBitWidth(unsigned AS) const override
unsigned getNumberOfRegisters(unsigned ClassID) const override
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, const Value *Op0, const Value *Op1, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
bool isLegalMaskedScatter(Type *DataType, Align Alignment) const override
InstructionCost getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy, TTI::TargetCostKind CostKind, ArrayRef< int > Mask, int Index, VectorType *SubTp, ArrayRef< const Value * > Args={}, const Instruction *CtxI=nullptr, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, ArrayRef< const Value * > Args={}, const Instruction *CtxI=nullptr, const TargetLibraryInfo *TLibInfo=nullptr, ArrayRef< const Value * > Scalars={}) const override
unsigned getStoreMinimumVF(unsigned VF, Type *ScalarMemTy, Type *ScalarValTy, Align Alignment, unsigned AddrSpace) const override
bool hasDivRemOp(Type *DataType, bool IsSigned) const override
bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) const override
InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) const override
bool supportsEfficientVectorElementLoadStore() const override
InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind, Instruction *Inst=nullptr) const override
bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const override
bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) const override
TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const override
InstructionCost getPointersChainCost(ArrayRef< const Value * > Ptrs, const Value *Base, const TTI::PointersChainInfo &Info, Type *AccessTy, const TTI::TargetCostKind CostKind) const override
InstructionCost getIntImmCost(int64_t) const
Calculate the cost of materializing a 64-bit value.
InstructionCost getMinMaxCost(Intrinsic::ID IID, Type *Ty, TTI::TargetCostKind CostKind, FastMathFlags FMF) const
InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const override
InstructionCost getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, bool UseMaskForCond=false, bool UseMaskForGaps=false) const override
bool canMacroFuseCmp() const override
bool areInlineCompatible(const Function *Caller, const Function *Callee) const override
InstructionCost getMaskedMemoryOpCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const
bool prefersVectorizedAddressing() const override
bool areTypesABICompatible(const Function *Caller, const Function *Callee, ArrayRef< Type * > Type) const override
bool forceScalarizeMaskedScatter(VectorType *VTy, Align Alignment) const override
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind) const override
Get intrinsic cost based on arguments.
bool isProfitableToSinkOperands(Instruction *I, SmallVectorImpl< Use * > &Ops) const override
InstructionCost getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract, TTI::TargetCostKind CostKind, bool ForPoisonSrc=true, ArrayRef< Value * > VL={}, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
Estimate the overhead of scalarizing an instruction.
InstructionCost getArithmeticReductionCost(unsigned Opcode, VectorType *Ty, std::optional< FastMathFlags > FMF, TTI::TargetCostKind CostKind) const override
InstructionCost getGatherScatterOpCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const
Calculate the cost of Gather / Scatter operation.
InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, TTI::OperandValueInfo OpInfo={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
InstructionCost getAddressComputationCost(Type *PtrTy, ScalarEvolution *SE, const SCEV *Ptr, TTI::TargetCostKind CostKind) const override
InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1, const TargetTransformInfo::LSRCost &C2) const override
constexpr bool isKnownMultipleOf(ScalarTy RHS) const
This function tells the caller whether the element count is known at compile time to be a multiple of...
Definition TypeSize.h:181
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:201
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition TypeSize.h:169
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition TypeSize.h:166
constexpr LeafTy divideCoefficientBy(ScalarTy RHS) const
We do not provide the '/' operator here because division for polynomial types does not work in the sa...
Definition TypeSize.h:253
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI APInt ScaleBitMask(const APInt &A, unsigned NewBitWidth, bool MatchAllBits=false)
Splat/Merge neighboring bits to widen/narrow the bitmask represented by.
Definition APInt.cpp:3052
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
ISD namespace - This namespace contains an enum which represents all of the SelectionDAG node types a...
Definition ISDOpcodes.h:26
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition ISDOpcodes.h:43
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
Definition ISDOpcodes.h:851
@ DELETED_NODE
DELETED_NODE - This is an illegal value that is used to catch errors.
Definition ISDOpcodes.h:47
@ PARTIAL_REDUCE_SMLA
PARTIAL_REDUCE_[U|S]MLA(Accumulator, Input1, Input2) The partial reduction nodes sign or zero extend ...
@ MASK_BEFOREFIRST
Has one mask vector operand.
@ BSWAP
Byte Swap and Counting operators.
Definition ISDOpcodes.h:811
@ ADD
Simple integer binary arithmetic operators.
Definition ISDOpcodes.h:266
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition ISDOpcodes.h:912
@ FADD
Simple binary floating point operators.
Definition ISDOpcodes.h:420
@ VECTOR_SHUFFLE_VAR
VECTOR_SHUFFLE_VAR(VEC, MASK) - Returns VEC permuted by MASK, an integer vector with the same number ...
Definition ISDOpcodes.h:665
@ ABS
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth.
Definition ISDOpcodes.h:771
@ SDIVREM
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition ISDOpcodes.h:282
@ CLMUL
Carry-less multiplication operations.
Definition ISDOpcodes.h:802
@ CTLZ_ZERO_POISON
Definition ISDOpcodes.h:820
@ PARTIAL_REDUCE_UMLA
@ SIGN_EXTEND
Conversion operators.
Definition ISDOpcodes.h:876
@ PARTIAL_REDUCE_FMLA
@ FNEG
Perform various unary floating-point operations inspired by libm.
@ SSUBSAT
RESULT = [US]SUBSAT(LHS, RHS) - Perform saturation subtraction on 2 integers with the same bit width ...
Definition ISDOpcodes.h:377
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition ISDOpcodes.h:828
@ SADDO
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
Definition ISDOpcodes.h:351
@ MULHU
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition ISDOpcodes.h:720
@ SHL
Shift and rotation operations.
Definition ISDOpcodes.h:793
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition ISDOpcodes.h:581
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition ISDOpcodes.h:882
@ FMINNUM
FMINNUM/FMAXNUM - Same semantics as the llvm.minnum/maxnum intrinsics.
@ SMULO
Same for multiplication.
Definition ISDOpcodes.h:359
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
Definition ISDOpcodes.h:751
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
@ FMINIMUM
FMINIMUM/FMAXIMUM - Same semantics as the llvm.minimum/maximum intrinsics.
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition ISDOpcodes.h:958
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition ISDOpcodes.h:763
@ CTTZ_ZERO_POISON
Bit counting operators with a poisoned result for zero inputs.
Definition ISDOpcodes.h:819
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
Definition ISDOpcodes.h:991
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition ISDOpcodes.h:888
@ PARTIAL_REDUCE_SUMLA
@ SADDSAT
RESULT = [US]ADDSAT(LHS, RHS) - Perform saturation addition on 2 integers with the same bit width (W)...
Definition ISDOpcodes.h:368
SpecificConstantMatch m_ZeroInt()
Convenience matchers for specific integer values.
BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)
Matches a register not-ed by a G_XOR.
OneUse_match< SubPat > m_OneUse(const SubPat &SP)
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
ap_match< APInt > m_APIntAllowPoison(const APInt *&Res)
Match APInt while allowing poison in splat vector constants.
specific_intval< false > m_SpecificInt(const APInt &V)
Match a specific integer value or vector with all elements equal to the value.
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
bool match(Val *V, const Pattern &P)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
auto m_Value()
Match an arbitrary value and ignore it.
TwoOps_match< V1_t, V2_t, Instruction::ShuffleVector > m_Shuffle(const V1_t &v1, const V2_t &v2)
Matches ShuffleVectorInst independently of mask value.
OneOps_match< OpTy, Instruction::Load > m_Load(const OpTy &Op)
Matches LoadInst.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::FDiv > m_FDiv(const LHS &L, const RHS &R)
AllowFmf_match< T, FastMathFlags::AllowContract > m_AllowContract(const T &SubPattern)
ThreeOps_match< Val_t, Elt_t, Idx_t, Instruction::InsertElement > m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx)
Matches InsertElementInst.
This is an optimization pass for GlobalISel generic memory operations.
constexpr auto not_equal_to(T &&Arg)
Functor variant of std::not_equal_to that can be used as a UnaryPredicate in functional algorithms li...
Definition STLExtras.h:2196
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1755
const CostTblEntryT< CostType > * CostTableLookup(ArrayRef< CostTblEntryT< CostType > > Tbl, int ISD, MVT Ty)
Find in cost table.
Definition CostTable.h:36
InstructionCost Cost
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:166
@ Known
Known to have no common set bits.
LLVM_ABI void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< EVT > *MemVTs=nullptr, SmallVectorImpl< TypeSize > *Offsets=nullptr, TypeSize StartingOffset=TypeSize::getZero())
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
Definition Analysis.cpp:121
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2575
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
Definition Casting.h:732
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
constexpr T alignDown(U Value, V Align, W Skew=0)
Returns the largest unsigned integer less than or equal to Value and is Skew mod Align.
Definition MathExtras.h:546
LLVM_ABI Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
bool isa_and_nonnull(const Y &Val)
Definition Casting.h:676
LLVM_ABI unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Return the number of times the sign bit of the register is replicated into the other bits.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
Definition MathExtras.h:380
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1762
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition MathExtras.h:280
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:149
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
constexpr int PoisonMaskElem
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition MathExtras.h:389
TargetTransformInfo TTI
DWARFExpression::Operation Op
OutputIt copy(R &&Range, OutputIt Out)
Definition STLExtras.h:1901
CostTblEntryT< uint16_t > CostTblEntry
Definition CostTable.h:31
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
Definition STLExtras.h:2035
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:341
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
Definition Alignment.h:206
LLVM_ABI void processShuffleMasks(ArrayRef< int > Mask, unsigned NumOfSrcRegs, unsigned NumOfDestRegs, unsigned NumOfUsedRegs, function_ref< void()> NoInputAction, function_ref< void(ArrayRef< int >, unsigned, unsigned)> SingleInputAction, function_ref< void(ArrayRef< int >, unsigned, unsigned, bool)> ManyInputsAction)
Splits and processes shuffle mask depending on the number of input and output registers.
const TypeConversionCostTblEntryT< CostType > * ConvertCostTableLookup(ArrayRef< TypeConversionCostTblEntryT< CostType > > Tbl, int ISD, MVT Dst, MVT Src)
Find in type conversion cost table.
Definition CostTable.h:67
LLVM_ABI int getSplatIndex(ArrayRef< int > Mask)
If all non-negative Mask elements are the same value, return that value.
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Cost Table Entry.
Definition CostTable.h:26
Extended Value Type.
Definition ValueTypes.h:35
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition ValueTypes.h:160
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition ValueTypes.h:411
uint64_t getScalarSizeInBits() const
Definition ValueTypes.h:423
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition ValueTypes.h:354
bool isVector() const
Return true if this is a vector value type.
Definition ValueTypes.h:191
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
Definition ValueTypes.h:361
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg + ScalableOffset*...
unsigned Insns
TODO: Some of these could be merged.
Returns options for expansion of memcmp. IsZeroCmp is.
Describe known properties for a set of pointers.
Type Conversion Cost Table.
Definition CostTable.h:56