blob: 207a7685c5947367ce61ab648a6bb54e8ce9261b [file] [log] [blame]
Chandler Carruth664e3542013-01-07 01:37:14 +00001//===-- X86TargetTransformInfo.cpp - X86 specific TTI pass ----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9/// \file
10/// This file implements a TargetTransformInfo analysis pass specific to the
11/// X86 target machine. It uses the target's detailed information to provide
12/// more precise answers to certain TTI queries, while letting the target
13/// independent and default TTI implementations handle the rest.
14///
15//===----------------------------------------------------------------------===//
16
17#define DEBUG_TYPE "x86tti"
18#include "X86.h"
19#include "X86TargetMachine.h"
Chandler Carruthd3e73552013-01-07 03:08:10 +000020#include "llvm/Analysis/TargetTransformInfo.h"
Juergen Ributzkaf26beda2014-01-25 02:02:55 +000021#include "llvm/IR/IntrinsicInst.h"
Chandler Carruth664e3542013-01-07 01:37:14 +000022#include "llvm/Support/Debug.h"
Renato Golind4c392e2013-01-24 23:01:00 +000023#include "llvm/Target/CostTable.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000024#include "llvm/Target/TargetLowering.h"
Chandler Carruth664e3542013-01-07 01:37:14 +000025using namespace llvm;
26
27// Declare the pass initialization routine locally as target-specific passes
28// don't havve a target-wide initialization entry point, and so we rely on the
29// pass constructor initialization.
30namespace llvm {
31void initializeX86TTIPass(PassRegistry &);
32}
33
34namespace {
35
Juergen Ributzka3e752e72014-01-24 18:22:59 +000036class X86TTI LLVM_FINAL : public ImmutablePass, public TargetTransformInfo {
Chandler Carruth664e3542013-01-07 01:37:14 +000037 const X86Subtarget *ST;
38 const X86TargetLowering *TLI;
39
40 /// Estimate the overhead of scalarizing an instruction. Insert and Extract
41 /// are set if the result needs to be inserted and/or extracted from vectors.
42 unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const;
43
44public:
Nadav Rotem02dd93e2013-06-27 17:54:10 +000045 X86TTI() : ImmutablePass(ID), ST(0), TLI(0) {
Chandler Carruth664e3542013-01-07 01:37:14 +000046 llvm_unreachable("This pass cannot be directly constructed");
47 }
48
49 X86TTI(const X86TargetMachine *TM)
Juergen Ributzka3e752e72014-01-24 18:22:59 +000050 : ImmutablePass(ID), ST(TM->getSubtargetImpl()),
51 TLI(TM->getTargetLowering()) {
Chandler Carruth664e3542013-01-07 01:37:14 +000052 initializeX86TTIPass(*PassRegistry::getPassRegistry());
53 }
54
Juergen Ributzka3e752e72014-01-24 18:22:59 +000055 virtual void initializePass() LLVM_OVERRIDE {
Chandler Carruth664e3542013-01-07 01:37:14 +000056 pushTTIStack(this);
57 }
58
59 virtual void finalizePass() {
60 popTTIStack();
61 }
62
Juergen Ributzka3e752e72014-01-24 18:22:59 +000063 virtual void getAnalysisUsage(AnalysisUsage &AU) const LLVM_OVERRIDE {
Chandler Carruth664e3542013-01-07 01:37:14 +000064 TargetTransformInfo::getAnalysisUsage(AU);
65 }
66
67 /// Pass identification.
68 static char ID;
69
70 /// Provide necessary pointer adjustments for the two base classes.
Juergen Ributzka3e752e72014-01-24 18:22:59 +000071 virtual void *getAdjustedAnalysisPointer(const void *ID) LLVM_OVERRIDE {
Chandler Carruth664e3542013-01-07 01:37:14 +000072 if (ID == &TargetTransformInfo::ID)
73 return (TargetTransformInfo*)this;
74 return this;
75 }
76
77 /// \name Scalar TTI Implementations
78 /// @{
Juergen Ributzka3e752e72014-01-24 18:22:59 +000079 virtual PopcntSupportKind
80 getPopcntSupport(unsigned TyWidth) const LLVM_OVERRIDE;
Chandler Carruth664e3542013-01-07 01:37:14 +000081
82 /// @}
83
84 /// \name Vector TTI Implementations
85 /// @{
86
Juergen Ributzka3e752e72014-01-24 18:22:59 +000087 virtual unsigned getNumberOfRegisters(bool Vector) const LLVM_OVERRIDE;
88 virtual unsigned getRegisterBitWidth(bool Vector) const LLVM_OVERRIDE;
89 virtual unsigned getMaximumUnrollFactor() const LLVM_OVERRIDE;
Arnold Schwaighoferb9773872013-04-04 23:26:21 +000090 virtual unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty,
91 OperandValueKind,
Juergen Ributzka3e752e72014-01-24 18:22:59 +000092 OperandValueKind) const LLVM_OVERRIDE;
Chandler Carruth664e3542013-01-07 01:37:14 +000093 virtual unsigned getShuffleCost(ShuffleKind Kind, Type *Tp,
Juergen Ributzka3e752e72014-01-24 18:22:59 +000094 int Index, Type *SubTp) const LLVM_OVERRIDE;
Chandler Carruth664e3542013-01-07 01:37:14 +000095 virtual unsigned getCastInstrCost(unsigned Opcode, Type *Dst,
Juergen Ributzka3e752e72014-01-24 18:22:59 +000096 Type *Src) const LLVM_OVERRIDE;
Chandler Carruth664e3542013-01-07 01:37:14 +000097 virtual unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Juergen Ributzka3e752e72014-01-24 18:22:59 +000098 Type *CondTy) const LLVM_OVERRIDE;
Chandler Carruth664e3542013-01-07 01:37:14 +000099 virtual unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
Juergen Ributzka3e752e72014-01-24 18:22:59 +0000100 unsigned Index) const LLVM_OVERRIDE;
Chandler Carruth664e3542013-01-07 01:37:14 +0000101 virtual unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
102 unsigned Alignment,
Juergen Ributzka3e752e72014-01-24 18:22:59 +0000103 unsigned AddressSpace) const LLVM_OVERRIDE;
Chandler Carruth664e3542013-01-07 01:37:14 +0000104
Juergen Ributzka3e752e72014-01-24 18:22:59 +0000105 virtual unsigned
106 getAddressComputationCost(Type *PtrTy, bool IsComplex) const LLVM_OVERRIDE;
Yi Jiang5c343de2013-09-19 17:48:48 +0000107
108 virtual unsigned getReductionCost(unsigned Opcode, Type *Ty,
Juergen Ributzka3e752e72014-01-24 18:22:59 +0000109 bool IsPairwiseForm) const LLVM_OVERRIDE;
Arnold Schwaighofer6042a262013-07-12 19:16:07 +0000110
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000111 virtual unsigned getIntImmCost(const APInt &Imm,
112 Type *Ty) const LLVM_OVERRIDE;
113
114 virtual unsigned getIntImmCost(unsigned Opcode, const APInt &Imm,
115 Type *Ty) const LLVM_OVERRIDE;
116 virtual unsigned getIntImmCost(Intrinsic::ID IID, const APInt &Imm,
117 Type *Ty) const LLVM_OVERRIDE;
118
Chandler Carruth664e3542013-01-07 01:37:14 +0000119 /// @}
120};
121
122} // end anonymous namespace
123
124INITIALIZE_AG_PASS(X86TTI, TargetTransformInfo, "x86tti",
125 "X86 Target Transform Info", true, true, false)
126char X86TTI::ID = 0;
127
128ImmutablePass *
129llvm::createX86TargetTransformInfoPass(const X86TargetMachine *TM) {
130 return new X86TTI(TM);
131}
132
133
134//===----------------------------------------------------------------------===//
135//
136// X86 cost model.
137//
138//===----------------------------------------------------------------------===//
139
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000140X86TTI::PopcntSupportKind X86TTI::getPopcntSupport(unsigned TyWidth) const {
Chandler Carruth664e3542013-01-07 01:37:14 +0000141 assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2");
142 // TODO: Currently the __builtin_popcount() implementation using SSE3
143 // instructions is inefficient. Once the problem is fixed, we should
Craig Topper0a63e1d2013-09-08 00:47:31 +0000144 // call ST->hasSSE3() instead of ST->hasPOPCNT().
145 return ST->hasPOPCNT() ? PSK_FastHardware : PSK_Software;
Chandler Carruth664e3542013-01-07 01:37:14 +0000146}
147
148unsigned X86TTI::getNumberOfRegisters(bool Vector) const {
Nadav Rotemb1791a72013-01-09 22:29:00 +0000149 if (Vector && !ST->hasSSE1())
150 return 0;
151
Chandler Carruth664e3542013-01-07 01:37:14 +0000152 if (ST->is64Bit())
153 return 16;
154 return 8;
155}
156
Nadav Rotemb1791a72013-01-09 22:29:00 +0000157unsigned X86TTI::getRegisterBitWidth(bool Vector) const {
158 if (Vector) {
159 if (ST->hasAVX()) return 256;
160 if (ST->hasSSE1()) return 128;
161 return 0;
162 }
163
164 if (ST->is64Bit())
165 return 64;
166 return 32;
167
168}
169
Nadav Rotemb696c362013-01-09 01:15:42 +0000170unsigned X86TTI::getMaximumUnrollFactor() const {
171 if (ST->isAtom())
172 return 1;
173
174 // Sandybridge and Haswell have multiple execution ports and pipelined
175 // vector units.
176 if (ST->hasAVX())
177 return 4;
178
179 return 2;
180}
181
Arnold Schwaighoferb9773872013-04-04 23:26:21 +0000182unsigned X86TTI::getArithmeticInstrCost(unsigned Opcode, Type *Ty,
183 OperandValueKind Op1Info,
184 OperandValueKind Op2Info) const {
Chandler Carruth664e3542013-01-07 01:37:14 +0000185 // Legalize the type.
186 std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Ty);
187
188 int ISD = TLI->InstructionOpcodeToISD(Opcode);
189 assert(ISD && "Invalid opcode");
190
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000191 static const CostTblEntry<MVT::SimpleValueType> AVX2CostTable[] = {
Michael Liao70dd7f92013-03-20 22:01:10 +0000192 // Shifts on v4i64/v8i32 on AVX2 is legal even though we declare to
193 // customize them to detect the cases where shift amount is a scalar one.
194 { ISD::SHL, MVT::v4i32, 1 },
195 { ISD::SRL, MVT::v4i32, 1 },
196 { ISD::SRA, MVT::v4i32, 1 },
197 { ISD::SHL, MVT::v8i32, 1 },
198 { ISD::SRL, MVT::v8i32, 1 },
199 { ISD::SRA, MVT::v8i32, 1 },
200 { ISD::SHL, MVT::v2i64, 1 },
201 { ISD::SRL, MVT::v2i64, 1 },
202 { ISD::SHL, MVT::v4i64, 1 },
203 { ISD::SRL, MVT::v4i64, 1 },
Arnold Schwaighofere9b50162013-04-03 21:46:05 +0000204
205 { ISD::SHL, MVT::v32i8, 42 }, // cmpeqb sequence.
206 { ISD::SHL, MVT::v16i16, 16*10 }, // Scalarized.
207
208 { ISD::SRL, MVT::v32i8, 32*10 }, // Scalarized.
209 { ISD::SRL, MVT::v16i16, 8*10 }, // Scalarized.
210
211 { ISD::SRA, MVT::v32i8, 32*10 }, // Scalarized.
212 { ISD::SRA, MVT::v16i16, 16*10 }, // Scalarized.
213 { ISD::SRA, MVT::v4i64, 4*10 }, // Scalarized.
Arnold Schwaighofera04b9ef2013-06-25 19:14:09 +0000214
215 // Vectorizing division is a bad idea. See the SSE2 table for more comments.
216 { ISD::SDIV, MVT::v32i8, 32*20 },
217 { ISD::SDIV, MVT::v16i16, 16*20 },
218 { ISD::SDIV, MVT::v8i32, 8*20 },
219 { ISD::SDIV, MVT::v4i64, 4*20 },
220 { ISD::UDIV, MVT::v32i8, 32*20 },
221 { ISD::UDIV, MVT::v16i16, 16*20 },
222 { ISD::UDIV, MVT::v8i32, 8*20 },
223 { ISD::UDIV, MVT::v4i64, 4*20 },
Michael Liao70dd7f92013-03-20 22:01:10 +0000224 };
225
226 // Look for AVX2 lowering tricks.
227 if (ST->hasAVX2()) {
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000228 int Idx = CostTableLookup(AVX2CostTable, ISD, LT.second);
Michael Liao70dd7f92013-03-20 22:01:10 +0000229 if (Idx != -1)
230 return LT.first * AVX2CostTable[Idx].Cost;
231 }
232
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000233 static const CostTblEntry<MVT::SimpleValueType>
234 SSE2UniformConstCostTable[] = {
Arnold Schwaighofer44f902e2013-04-04 23:26:24 +0000235 // We don't correctly identify costs of casts because they are marked as
236 // custom.
237 // Constant splats are cheaper for the following instructions.
238 { ISD::SHL, MVT::v16i8, 1 }, // psllw.
239 { ISD::SHL, MVT::v8i16, 1 }, // psllw.
240 { ISD::SHL, MVT::v4i32, 1 }, // pslld
241 { ISD::SHL, MVT::v2i64, 1 }, // psllq.
242
243 { ISD::SRL, MVT::v16i8, 1 }, // psrlw.
244 { ISD::SRL, MVT::v8i16, 1 }, // psrlw.
245 { ISD::SRL, MVT::v4i32, 1 }, // psrld.
246 { ISD::SRL, MVT::v2i64, 1 }, // psrlq.
247
248 { ISD::SRA, MVT::v16i8, 4 }, // psrlw, pand, pxor, psubb.
249 { ISD::SRA, MVT::v8i16, 1 }, // psraw.
250 { ISD::SRA, MVT::v4i32, 1 }, // psrad.
251 };
252
253 if (Op2Info == TargetTransformInfo::OK_UniformConstantValue &&
254 ST->hasSSE2()) {
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000255 int Idx = CostTableLookup(SSE2UniformConstCostTable, ISD, LT.second);
Arnold Schwaighofer44f902e2013-04-04 23:26:24 +0000256 if (Idx != -1)
257 return LT.first * SSE2UniformConstCostTable[Idx].Cost;
258 }
259
260
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000261 static const CostTblEntry<MVT::SimpleValueType> SSE2CostTable[] = {
Arnold Schwaighofere9b50162013-04-03 21:46:05 +0000262 // We don't correctly identify costs of casts because they are marked as
263 // custom.
264 // For some cases, where the shift amount is a scalar we would be able
265 // to generate better code. Unfortunately, when this is the case the value
266 // (the splat) will get hoisted out of the loop, thereby making it invisible
267 // to ISel. The cost model must return worst case assumptions because it is
268 // used for vectorization and we don't want to make vectorized code worse
269 // than scalar code.
270 { ISD::SHL, MVT::v16i8, 30 }, // cmpeqb sequence.
271 { ISD::SHL, MVT::v8i16, 8*10 }, // Scalarized.
272 { ISD::SHL, MVT::v4i32, 2*5 }, // We optimized this using mul.
273 { ISD::SHL, MVT::v2i64, 2*10 }, // Scalarized.
274
275 { ISD::SRL, MVT::v16i8, 16*10 }, // Scalarized.
276 { ISD::SRL, MVT::v8i16, 8*10 }, // Scalarized.
277 { ISD::SRL, MVT::v4i32, 4*10 }, // Scalarized.
278 { ISD::SRL, MVT::v2i64, 2*10 }, // Scalarized.
279
280 { ISD::SRA, MVT::v16i8, 16*10 }, // Scalarized.
281 { ISD::SRA, MVT::v8i16, 8*10 }, // Scalarized.
282 { ISD::SRA, MVT::v4i32, 4*10 }, // Scalarized.
283 { ISD::SRA, MVT::v2i64, 2*10 }, // Scalarized.
Arnold Schwaighofera04b9ef2013-06-25 19:14:09 +0000284
285 // It is not a good idea to vectorize division. We have to scalarize it and
286 // in the process we will often end up having to spilling regular
287 // registers. The overhead of division is going to dominate most kernels
288 // anyways so try hard to prevent vectorization of division - it is
289 // generally a bad idea. Assume somewhat arbitrarily that we have to be able
290 // to hide "20 cycles" for each lane.
291 { ISD::SDIV, MVT::v16i8, 16*20 },
292 { ISD::SDIV, MVT::v8i16, 8*20 },
293 { ISD::SDIV, MVT::v4i32, 4*20 },
294 { ISD::SDIV, MVT::v2i64, 2*20 },
295 { ISD::UDIV, MVT::v16i8, 16*20 },
296 { ISD::UDIV, MVT::v8i16, 8*20 },
297 { ISD::UDIV, MVT::v4i32, 4*20 },
298 { ISD::UDIV, MVT::v2i64, 2*20 },
Arnold Schwaighofere9b50162013-04-03 21:46:05 +0000299 };
300
301 if (ST->hasSSE2()) {
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000302 int Idx = CostTableLookup(SSE2CostTable, ISD, LT.second);
Arnold Schwaighofere9b50162013-04-03 21:46:05 +0000303 if (Idx != -1)
304 return LT.first * SSE2CostTable[Idx].Cost;
305 }
306
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000307 static const CostTblEntry<MVT::SimpleValueType> AVX1CostTable[] = {
Renato Goline1fb0592013-01-20 20:57:20 +0000308 // We don't have to scalarize unsupported ops. We can issue two half-sized
309 // operations and we only need to extract the upper YMM half.
310 // Two ops + 1 extract + 1 insert = 4.
311 { ISD::MUL, MVT::v8i32, 4 },
312 { ISD::SUB, MVT::v8i32, 4 },
313 { ISD::ADD, MVT::v8i32, 4 },
Renato Goline1fb0592013-01-20 20:57:20 +0000314 { ISD::SUB, MVT::v4i64, 4 },
315 { ISD::ADD, MVT::v4i64, 4 },
Arnold Schwaighofer20ef54f2013-03-02 04:02:52 +0000316 // A v4i64 multiply is custom lowered as two split v2i64 vectors that then
317 // are lowered as a series of long multiplies(3), shifts(4) and adds(2)
318 // Because we believe v4i64 to be a legal type, we must also include the
319 // split factor of two in the cost table. Therefore, the cost here is 18
320 // instead of 9.
321 { ISD::MUL, MVT::v4i64, 18 },
322 };
Chandler Carruth664e3542013-01-07 01:37:14 +0000323
324 // Look for AVX1 lowering tricks.
Arnold Schwaighofer20ef54f2013-03-02 04:02:52 +0000325 if (ST->hasAVX() && !ST->hasAVX2()) {
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000326 int Idx = CostTableLookup(AVX1CostTable, ISD, LT.second);
Renato Goline1fb0592013-01-20 20:57:20 +0000327 if (Idx != -1)
328 return LT.first * AVX1CostTable[Idx].Cost;
Chandler Carruth664e3542013-01-07 01:37:14 +0000329 }
Arnold Schwaighofer20ef54f2013-03-02 04:02:52 +0000330
331 // Custom lowering of vectors.
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000332 static const CostTblEntry<MVT::SimpleValueType> CustomLowered[] = {
Arnold Schwaighofer20ef54f2013-03-02 04:02:52 +0000333 // A v2i64/v4i64 and multiply is custom lowered as a series of long
334 // multiplies(3), shifts(4) and adds(2).
335 { ISD::MUL, MVT::v2i64, 9 },
336 { ISD::MUL, MVT::v4i64, 9 },
337 };
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000338 int Idx = CostTableLookup(CustomLowered, ISD, LT.second);
Arnold Schwaighofer20ef54f2013-03-02 04:02:52 +0000339 if (Idx != -1)
340 return LT.first * CustomLowered[Idx].Cost;
341
342 // Special lowering of v4i32 mul on sse2, sse3: Lower v4i32 mul as 2x shuffle,
343 // 2x pmuludq, 2x shuffle.
344 if (ISD == ISD::MUL && LT.second == MVT::v4i32 && ST->hasSSE2() &&
345 !ST->hasSSE41())
346 return 6;
347
Chandler Carruth664e3542013-01-07 01:37:14 +0000348 // Fallback to the default implementation.
Arnold Schwaighoferb9773872013-04-04 23:26:21 +0000349 return TargetTransformInfo::getArithmeticInstrCost(Opcode, Ty, Op1Info,
350 Op2Info);
Chandler Carruth664e3542013-01-07 01:37:14 +0000351}
352
353unsigned X86TTI::getShuffleCost(ShuffleKind Kind, Type *Tp, int Index,
354 Type *SubTp) const {
355 // We only estimate the cost of reverse shuffles.
Chandler Carruth2109f472013-01-07 03:20:02 +0000356 if (Kind != SK_Reverse)
Chandler Carruth664e3542013-01-07 01:37:14 +0000357 return TargetTransformInfo::getShuffleCost(Kind, Tp, Index, SubTp);
358
359 std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Tp);
360 unsigned Cost = 1;
361 if (LT.second.getSizeInBits() > 128)
362 Cost = 3; // Extract + insert + copy.
363
364 // Multiple by the number of parts.
365 return Cost * LT.first;
366}
367
368unsigned X86TTI::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) const {
369 int ISD = TLI->InstructionOpcodeToISD(Opcode);
370 assert(ISD && "Invalid opcode");
371
Arnold Schwaighoferf47d2d72013-04-08 18:05:48 +0000372 std::pair<unsigned, MVT> LTSrc = TLI->getTypeLegalizationCost(Src);
373 std::pair<unsigned, MVT> LTDest = TLI->getTypeLegalizationCost(Dst);
374
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000375 static const TypeConversionCostTblEntry<MVT::SimpleValueType>
376 SSE2ConvTbl[] = {
Arnold Schwaighoferf47d2d72013-04-08 18:05:48 +0000377 // These are somewhat magic numbers justified by looking at the output of
378 // Intel's IACA, running some kernels and making sure when we take
379 // legalization into account the throughput will be overestimated.
380 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, 2*10 },
381 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v4i32, 4*10 },
382 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v8i16, 8*10 },
383 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v16i8, 16*10 },
384 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v2i64, 2*10 },
385 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v4i32, 4*10 },
386 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v8i16, 8*10 },
387 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v16i8, 16*10 },
388 // There are faster sequences for float conversions.
389 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v2i64, 15 },
390 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, 15 },
391 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v8i16, 15 },
392 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v16i8, 8 },
393 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v2i64, 15 },
394 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i32, 15 },
395 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v8i16, 15 },
396 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v16i8, 8 },
397 };
398
399 if (ST->hasSSE2() && !ST->hasAVX()) {
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000400 int Idx =
401 ConvertCostTableLookup(SSE2ConvTbl, ISD, LTDest.second, LTSrc.second);
Arnold Schwaighoferf47d2d72013-04-08 18:05:48 +0000402 if (Idx != -1)
403 return LTSrc.first * SSE2ConvTbl[Idx].Cost;
404 }
405
Chandler Carruth664e3542013-01-07 01:37:14 +0000406 EVT SrcTy = TLI->getValueType(Src);
407 EVT DstTy = TLI->getValueType(Dst);
408
Arnold Schwaighoferc0c7ff42013-04-17 20:04:53 +0000409 // The function getSimpleVT only handles simple value types.
410 if (!SrcTy.isSimple() || !DstTy.isSimple())
411 return TargetTransformInfo::getCastInstrCost(Opcode, Dst, Src);
412
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000413 static const TypeConversionCostTblEntry<MVT::SimpleValueType>
Tim Northoverf0e21612014-02-06 18:18:36 +0000414 AVX2ConversionTbl[] = {
415 { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i8, 1 },
416 { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i8, 1 },
417 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i1, 3 },
418 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i1, 3 },
419 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i8, 3 },
420 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i8, 3 },
421 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, 1 },
422 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, 1 },
423 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i1, 3 },
424 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i1, 3 },
425 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i8, 3 },
426 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i8, 3 },
427 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i16, 3 },
428 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i16, 3 },
429 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, 1 },
430 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, 1 },
431
432 { ISD::TRUNCATE, MVT::v4i8, MVT::v4i64, 2 },
433 { ISD::TRUNCATE, MVT::v4i16, MVT::v4i64, 2 },
434 { ISD::TRUNCATE, MVT::v4i32, MVT::v4i64, 2 },
435 { ISD::TRUNCATE, MVT::v8i8, MVT::v8i32, 2 },
436 { ISD::TRUNCATE, MVT::v8i16, MVT::v8i32, 2 },
437 { ISD::TRUNCATE, MVT::v8i32, MVT::v8i64, 4 },
438 };
439
440 static const TypeConversionCostTblEntry<MVT::SimpleValueType>
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000441 AVXConversionTbl[] = {
Tim Northoverf0e21612014-02-06 18:18:36 +0000442 { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i8, 4 },
443 { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i8, 4 },
444 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i1, 7 },
445 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i1, 4 },
446 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i8, 7 },
447 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i8, 4 },
448 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, 4 },
449 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, 4 },
450 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i1, 6 },
451 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i1, 4 },
452 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i8, 6 },
453 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i8, 4 },
454 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i16, 6 },
455 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i16, 3 },
456 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, 4 },
457 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, 4 },
458
459 { ISD::TRUNCATE, MVT::v4i8, MVT::v4i64, 4 },
460 { ISD::TRUNCATE, MVT::v4i16, MVT::v4i64, 4 },
461 { ISD::TRUNCATE, MVT::v4i32, MVT::v4i64, 4 },
462 { ISD::TRUNCATE, MVT::v8i8, MVT::v8i32, 4 },
463 { ISD::TRUNCATE, MVT::v8i16, MVT::v8i32, 5 },
464 { ISD::TRUNCATE, MVT::v16i8, MVT::v16i16, 4 },
465 { ISD::TRUNCATE, MVT::v8i32, MVT::v8i64, 9 },
Benjamin Kramer52ceb442013-04-01 10:23:49 +0000466
467 { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i1, 8 },
468 { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i8, 8 },
469 { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i16, 5 },
470 { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i32, 1 },
471 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i1, 3 },
472 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i8, 3 },
473 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i16, 3 },
474 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i32, 1 },
475 { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i1, 3 },
476 { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i8, 3 },
477 { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i16, 3 },
478 { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i32, 1 },
479
480 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i1, 6 },
481 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i8, 5 },
482 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i16, 5 },
483 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i32, 9 },
484 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i1, 7 },
485 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i8, 2 },
486 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i16, 2 },
487 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, 6 },
488 { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i1, 7 },
489 { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i8, 2 },
490 { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i16, 2 },
491 { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i32, 6 },
492
Renato Goline1fb0592013-01-20 20:57:20 +0000493 { ISD::FP_TO_SINT, MVT::v8i8, MVT::v8f32, 1 },
494 { ISD::FP_TO_SINT, MVT::v4i8, MVT::v4f32, 1 },
Chandler Carruth664e3542013-01-07 01:37:14 +0000495 };
496
Tim Northoverf0e21612014-02-06 18:18:36 +0000497 if (ST->hasAVX2()) {
498 int Idx = ConvertCostTableLookup(AVX2ConversionTbl, ISD,
499 DstTy.getSimpleVT(), SrcTy.getSimpleVT());
500 if (Idx != -1)
501 return AVX2ConversionTbl[Idx].Cost;
502 }
503
Chandler Carruth664e3542013-01-07 01:37:14 +0000504 if (ST->hasAVX()) {
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000505 int Idx = ConvertCostTableLookup(AVXConversionTbl, ISD, DstTy.getSimpleVT(),
506 SrcTy.getSimpleVT());
Renato Goline1fb0592013-01-20 20:57:20 +0000507 if (Idx != -1)
508 return AVXConversionTbl[Idx].Cost;
Chandler Carruth664e3542013-01-07 01:37:14 +0000509 }
510
511 return TargetTransformInfo::getCastInstrCost(Opcode, Dst, Src);
512}
513
514unsigned X86TTI::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
515 Type *CondTy) const {
516 // Legalize the type.
517 std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(ValTy);
518
519 MVT MTy = LT.second;
520
521 int ISD = TLI->InstructionOpcodeToISD(Opcode);
522 assert(ISD && "Invalid opcode");
523
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000524 static const CostTblEntry<MVT::SimpleValueType> SSE42CostTbl[] = {
Renato Goline1fb0592013-01-20 20:57:20 +0000525 { ISD::SETCC, MVT::v2f64, 1 },
526 { ISD::SETCC, MVT::v4f32, 1 },
527 { ISD::SETCC, MVT::v2i64, 1 },
528 { ISD::SETCC, MVT::v4i32, 1 },
529 { ISD::SETCC, MVT::v8i16, 1 },
530 { ISD::SETCC, MVT::v16i8, 1 },
Chandler Carruth664e3542013-01-07 01:37:14 +0000531 };
532
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000533 static const CostTblEntry<MVT::SimpleValueType> AVX1CostTbl[] = {
Renato Goline1fb0592013-01-20 20:57:20 +0000534 { ISD::SETCC, MVT::v4f64, 1 },
535 { ISD::SETCC, MVT::v8f32, 1 },
Chandler Carruth664e3542013-01-07 01:37:14 +0000536 // AVX1 does not support 8-wide integer compare.
Renato Goline1fb0592013-01-20 20:57:20 +0000537 { ISD::SETCC, MVT::v4i64, 4 },
538 { ISD::SETCC, MVT::v8i32, 4 },
539 { ISD::SETCC, MVT::v16i16, 4 },
540 { ISD::SETCC, MVT::v32i8, 4 },
Chandler Carruth664e3542013-01-07 01:37:14 +0000541 };
542
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000543 static const CostTblEntry<MVT::SimpleValueType> AVX2CostTbl[] = {
Renato Goline1fb0592013-01-20 20:57:20 +0000544 { ISD::SETCC, MVT::v4i64, 1 },
545 { ISD::SETCC, MVT::v8i32, 1 },
546 { ISD::SETCC, MVT::v16i16, 1 },
547 { ISD::SETCC, MVT::v32i8, 1 },
Chandler Carruth664e3542013-01-07 01:37:14 +0000548 };
549
550 if (ST->hasAVX2()) {
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000551 int Idx = CostTableLookup(AVX2CostTbl, ISD, MTy);
Renato Goline1fb0592013-01-20 20:57:20 +0000552 if (Idx != -1)
553 return LT.first * AVX2CostTbl[Idx].Cost;
Chandler Carruth664e3542013-01-07 01:37:14 +0000554 }
555
556 if (ST->hasAVX()) {
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000557 int Idx = CostTableLookup(AVX1CostTbl, ISD, MTy);
Renato Goline1fb0592013-01-20 20:57:20 +0000558 if (Idx != -1)
559 return LT.first * AVX1CostTbl[Idx].Cost;
Chandler Carruth664e3542013-01-07 01:37:14 +0000560 }
561
562 if (ST->hasSSE42()) {
Benjamin Kramer21585fd2013-08-09 19:33:32 +0000563 int Idx = CostTableLookup(SSE42CostTbl, ISD, MTy);
Renato Goline1fb0592013-01-20 20:57:20 +0000564 if (Idx != -1)
565 return LT.first * SSE42CostTbl[Idx].Cost;
Chandler Carruth664e3542013-01-07 01:37:14 +0000566 }
567
568 return TargetTransformInfo::getCmpSelInstrCost(Opcode, ValTy, CondTy);
569}
570
571unsigned X86TTI::getVectorInstrCost(unsigned Opcode, Type *Val,
572 unsigned Index) const {
573 assert(Val->isVectorTy() && "This must be a vector type");
574
575 if (Index != -1U) {
576 // Legalize the type.
577 std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Val);
578
579 // This type is legalized to a scalar type.
580 if (!LT.second.isVector())
581 return 0;
582
583 // The type may be split. Normalize the index to the new type.
584 unsigned Width = LT.second.getVectorNumElements();
585 Index = Index % Width;
586
587 // Floating point scalars are already located in index #0.
588 if (Val->getScalarType()->isFloatingPointTy() && Index == 0)
589 return 0;
590 }
591
592 return TargetTransformInfo::getVectorInstrCost(Opcode, Val, Index);
593}
594
Nadav Rotemf9ecbcb2013-06-27 17:52:04 +0000595unsigned X86TTI::getScalarizationOverhead(Type *Ty, bool Insert,
596 bool Extract) const {
597 assert (Ty->isVectorTy() && "Can only scalarize vectors");
598 unsigned Cost = 0;
599
600 for (int i = 0, e = Ty->getVectorNumElements(); i < e; ++i) {
601 if (Insert)
602 Cost += TopTTI->getVectorInstrCost(Instruction::InsertElement, Ty, i);
603 if (Extract)
604 Cost += TopTTI->getVectorInstrCost(Instruction::ExtractElement, Ty, i);
605 }
606
607 return Cost;
608}
609
Chandler Carruth664e3542013-01-07 01:37:14 +0000610unsigned X86TTI::getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
611 unsigned AddressSpace) const {
Alp Tokerf907b892013-12-05 05:44:44 +0000612 // Handle non-power-of-two vectors such as <3 x float>
Nadav Rotemf9ecbcb2013-06-27 17:52:04 +0000613 if (VectorType *VTy = dyn_cast<VectorType>(Src)) {
614 unsigned NumElem = VTy->getVectorNumElements();
615
616 // Handle a few common cases:
617 // <3 x float>
618 if (NumElem == 3 && VTy->getScalarSizeInBits() == 32)
619 // Cost = 64 bit store + extract + 32 bit store.
620 return 3;
621
622 // <3 x double>
623 if (NumElem == 3 && VTy->getScalarSizeInBits() == 64)
624 // Cost = 128 bit store + unpack + 64 bit store.
625 return 3;
626
Alp Tokerf907b892013-12-05 05:44:44 +0000627 // Assume that all other non-power-of-two numbers are scalarized.
Nadav Rotemf9ecbcb2013-06-27 17:52:04 +0000628 if (!isPowerOf2_32(NumElem)) {
629 unsigned Cost = TargetTransformInfo::getMemoryOpCost(Opcode,
630 VTy->getScalarType(),
631 Alignment,
632 AddressSpace);
633 unsigned SplitCost = getScalarizationOverhead(Src,
634 Opcode == Instruction::Load,
635 Opcode==Instruction::Store);
636 return NumElem * Cost + SplitCost;
637 }
638 }
639
Chandler Carruth664e3542013-01-07 01:37:14 +0000640 // Legalize the type.
641 std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Src);
642 assert((Opcode == Instruction::Load || Opcode == Instruction::Store) &&
643 "Invalid Opcode");
644
645 // Each load/store unit costs 1.
646 unsigned Cost = LT.first * 1;
647
648 // On Sandybridge 256bit load/stores are double pumped
649 // (but not on Haswell).
650 if (LT.second.getSizeInBits() > 128 && !ST->hasAVX2())
651 Cost*=2;
652
653 return Cost;
654}
Arnold Schwaighofer6042a262013-07-12 19:16:07 +0000655
656unsigned X86TTI::getAddressComputationCost(Type *Ty, bool IsComplex) const {
657 // Address computations in vectorized code with non-consecutive addresses will
658 // likely result in more instructions compared to scalar code where the
659 // computation can more often be merged into the index mode. The resulting
660 // extra micro-ops can significantly decrease throughput.
661 unsigned NumVectorInstToHideOverhead = 10;
662
663 if (Ty->isVectorTy() && IsComplex)
664 return NumVectorInstToHideOverhead;
665
666 return TargetTransformInfo::getAddressComputationCost(Ty, IsComplex);
667}
Yi Jiang5c343de2013-09-19 17:48:48 +0000668
669unsigned X86TTI::getReductionCost(unsigned Opcode, Type *ValTy,
670 bool IsPairwise) const {
671
672 std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(ValTy);
673
674 MVT MTy = LT.second;
675
676 int ISD = TLI->InstructionOpcodeToISD(Opcode);
677 assert(ISD && "Invalid opcode");
678
679 // We use the Intel Architecture Code Analyzer(IACA) to measure the throughput
680 // and make it as the cost.
681
682 static const CostTblEntry<MVT::SimpleValueType> SSE42CostTblPairWise[] = {
683 { ISD::FADD, MVT::v2f64, 2 },
684 { ISD::FADD, MVT::v4f32, 4 },
685 { ISD::ADD, MVT::v2i64, 2 }, // The data reported by the IACA tool is "1.6".
686 { ISD::ADD, MVT::v4i32, 3 }, // The data reported by the IACA tool is "3.5".
687 { ISD::ADD, MVT::v8i16, 5 },
688 };
689
690 static const CostTblEntry<MVT::SimpleValueType> AVX1CostTblPairWise[] = {
691 { ISD::FADD, MVT::v4f32, 4 },
692 { ISD::FADD, MVT::v4f64, 5 },
693 { ISD::FADD, MVT::v8f32, 7 },
694 { ISD::ADD, MVT::v2i64, 1 }, // The data reported by the IACA tool is "1.5".
695 { ISD::ADD, MVT::v4i32, 3 }, // The data reported by the IACA tool is "3.5".
696 { ISD::ADD, MVT::v4i64, 5 }, // The data reported by the IACA tool is "4.8".
697 { ISD::ADD, MVT::v8i16, 5 },
698 { ISD::ADD, MVT::v8i32, 5 },
699 };
700
701 static const CostTblEntry<MVT::SimpleValueType> SSE42CostTblNoPairWise[] = {
702 { ISD::FADD, MVT::v2f64, 2 },
703 { ISD::FADD, MVT::v4f32, 4 },
704 { ISD::ADD, MVT::v2i64, 2 }, // The data reported by the IACA tool is "1.6".
705 { ISD::ADD, MVT::v4i32, 3 }, // The data reported by the IACA tool is "3.3".
706 { ISD::ADD, MVT::v8i16, 4 }, // The data reported by the IACA tool is "4.3".
707 };
708
709 static const CostTblEntry<MVT::SimpleValueType> AVX1CostTblNoPairWise[] = {
710 { ISD::FADD, MVT::v4f32, 3 },
711 { ISD::FADD, MVT::v4f64, 3 },
712 { ISD::FADD, MVT::v8f32, 4 },
713 { ISD::ADD, MVT::v2i64, 1 }, // The data reported by the IACA tool is "1.5".
714 { ISD::ADD, MVT::v4i32, 3 }, // The data reported by the IACA tool is "2.8".
715 { ISD::ADD, MVT::v4i64, 3 },
716 { ISD::ADD, MVT::v8i16, 4 },
717 { ISD::ADD, MVT::v8i32, 5 },
718 };
719
720 if (IsPairwise) {
721 if (ST->hasAVX()) {
722 int Idx = CostTableLookup(AVX1CostTblPairWise, ISD, MTy);
723 if (Idx != -1)
724 return LT.first * AVX1CostTblPairWise[Idx].Cost;
725 }
726
727 if (ST->hasSSE42()) {
728 int Idx = CostTableLookup(SSE42CostTblPairWise, ISD, MTy);
729 if (Idx != -1)
730 return LT.first * SSE42CostTblPairWise[Idx].Cost;
731 }
732 } else {
733 if (ST->hasAVX()) {
734 int Idx = CostTableLookup(AVX1CostTblNoPairWise, ISD, MTy);
735 if (Idx != -1)
736 return LT.first * AVX1CostTblNoPairWise[Idx].Cost;
737 }
738
739 if (ST->hasSSE42()) {
740 int Idx = CostTableLookup(SSE42CostTblNoPairWise, ISD, MTy);
741 if (Idx != -1)
742 return LT.first * SSE42CostTblNoPairWise[Idx].Cost;
743 }
744 }
745
746 return TargetTransformInfo::getReductionCost(Opcode, ValTy, IsPairwise);
747}
748
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000749unsigned X86TTI::getIntImmCost(const APInt &Imm, Type *Ty) const {
750 assert(Ty->isIntegerTy());
751
752 unsigned BitSize = Ty->getPrimitiveSizeInBits();
753 if (BitSize == 0)
754 return ~0U;
755
756 if (Imm.getBitWidth() <= 64 &&
757 (isInt<32>(Imm.getSExtValue()) || isUInt<32>(Imm.getZExtValue())))
758 return TCC_Basic;
759 else
760 return 2 * TCC_Basic;
761}
762
763unsigned X86TTI::getIntImmCost(unsigned Opcode, const APInt &Imm,
764 Type *Ty) const {
765 assert(Ty->isIntegerTy());
766
767 unsigned BitSize = Ty->getPrimitiveSizeInBits();
768 if (BitSize == 0)
769 return ~0U;
770
771 switch (Opcode) {
772 case Instruction::Add:
773 case Instruction::Sub:
774 case Instruction::Mul:
775 case Instruction::UDiv:
776 case Instruction::SDiv:
777 case Instruction::URem:
778 case Instruction::SRem:
779 case Instruction::Shl:
780 case Instruction::LShr:
781 case Instruction::AShr:
782 case Instruction::And:
783 case Instruction::Or:
784 case Instruction::Xor:
785 case Instruction::ICmp:
786 if (Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue()))
787 return TCC_Free;
788 else
789 return X86TTI::getIntImmCost(Imm, Ty);
790 case Instruction::Trunc:
791 case Instruction::ZExt:
792 case Instruction::SExt:
793 case Instruction::IntToPtr:
794 case Instruction::PtrToInt:
795 case Instruction::BitCast:
796 case Instruction::Call:
797 case Instruction::Select:
798 case Instruction::Ret:
799 case Instruction::Load:
800 case Instruction::Store:
801 return X86TTI::getIntImmCost(Imm, Ty);
802 }
803 return TargetTransformInfo::getIntImmCost(Opcode, Imm, Ty);
804}
805
806unsigned X86TTI::getIntImmCost(Intrinsic::ID IID, const APInt &Imm,
807 Type *Ty) const {
808 assert(Ty->isIntegerTy());
809
810 unsigned BitSize = Ty->getPrimitiveSizeInBits();
811 if (BitSize == 0)
812 return ~0U;
813
814 switch (IID) {
815 default: return TargetTransformInfo::getIntImmCost(IID, Imm, Ty);
816 case Intrinsic::sadd_with_overflow:
817 case Intrinsic::uadd_with_overflow:
818 case Intrinsic::ssub_with_overflow:
819 case Intrinsic::usub_with_overflow:
820 case Intrinsic::smul_with_overflow:
821 case Intrinsic::umul_with_overflow:
822 if (Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue()))
823 return TCC_Free;
824 else
825 return X86TTI::getIntImmCost(Imm, Ty);
826 case Intrinsic::experimental_stackmap:
827 case Intrinsic::experimental_patchpoint_void:
828 case Intrinsic::experimental_patchpoint_i64:
829 if (Imm.getBitWidth() <= 64 && isInt<64>(Imm.getSExtValue()))
830 return TCC_Free;
831 else
832 return X86TTI::getIntImmCost(Imm, Ty);
833 }
834}