Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1 | //===-- 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 | |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 17 | #include "X86TargetTransformInfo.h" |
Chandler Carruth | d3e7355 | 2013-01-07 03:08:10 +0000 | [diff] [blame] | 18 | #include "llvm/Analysis/TargetTransformInfo.h" |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/BasicTTIImpl.h" |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 20 | #include "llvm/IR/IntrinsicInst.h" |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Debug.h" |
Renato Golin | d4c392e | 2013-01-24 23:01:00 +0000 | [diff] [blame] | 22 | #include "llvm/Target/CostTable.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetLowering.h" |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 24 | using namespace llvm; |
| 25 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 26 | #define DEBUG_TYPE "x86tti" |
| 27 | |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 28 | //===----------------------------------------------------------------------===// |
| 29 | // |
| 30 | // X86 cost model. |
| 31 | // |
| 32 | //===----------------------------------------------------------------------===// |
| 33 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 34 | TargetTransformInfo::PopcntSupportKind |
| 35 | X86TTIImpl::getPopcntSupport(unsigned TyWidth) { |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 36 | assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2"); |
| 37 | // TODO: Currently the __builtin_popcount() implementation using SSE3 |
| 38 | // instructions is inefficient. Once the problem is fixed, we should |
Craig Topper | 0a63e1d | 2013-09-08 00:47:31 +0000 | [diff] [blame] | 39 | // call ST->hasSSE3() instead of ST->hasPOPCNT(). |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 40 | return ST->hasPOPCNT() ? TTI::PSK_FastHardware : TTI::PSK_Software; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 43 | unsigned X86TTIImpl::getNumberOfRegisters(bool Vector) { |
Nadav Rotem | b1791a7 | 2013-01-09 22:29:00 +0000 | [diff] [blame] | 44 | if (Vector && !ST->hasSSE1()) |
| 45 | return 0; |
| 46 | |
Adam Nemet | 2820a5b | 2014-07-09 18:22:33 +0000 | [diff] [blame] | 47 | if (ST->is64Bit()) { |
| 48 | if (Vector && ST->hasAVX512()) |
| 49 | return 32; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 50 | return 16; |
Adam Nemet | 2820a5b | 2014-07-09 18:22:33 +0000 | [diff] [blame] | 51 | } |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 52 | return 8; |
| 53 | } |
| 54 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 55 | unsigned X86TTIImpl::getRegisterBitWidth(bool Vector) { |
Nadav Rotem | b1791a7 | 2013-01-09 22:29:00 +0000 | [diff] [blame] | 56 | if (Vector) { |
Adam Nemet | 2820a5b | 2014-07-09 18:22:33 +0000 | [diff] [blame] | 57 | if (ST->hasAVX512()) return 512; |
Nadav Rotem | b1791a7 | 2013-01-09 22:29:00 +0000 | [diff] [blame] | 58 | if (ST->hasAVX()) return 256; |
| 59 | if (ST->hasSSE1()) return 128; |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | if (ST->is64Bit()) |
| 64 | return 64; |
| 65 | return 32; |
| 66 | |
| 67 | } |
| 68 | |
Wei Mi | 062c744 | 2015-05-06 17:12:25 +0000 | [diff] [blame] | 69 | unsigned X86TTIImpl::getMaxInterleaveFactor(unsigned VF) { |
| 70 | // If the loop will not be vectorized, don't interleave the loop. |
| 71 | // Let regular unroll to unroll the loop, which saves the overflow |
| 72 | // check and memory check cost. |
| 73 | if (VF == 1) |
| 74 | return 1; |
| 75 | |
Nadav Rotem | b696c36 | 2013-01-09 01:15:42 +0000 | [diff] [blame] | 76 | if (ST->isAtom()) |
| 77 | return 1; |
| 78 | |
| 79 | // Sandybridge and Haswell have multiple execution ports and pipelined |
| 80 | // vector units. |
| 81 | if (ST->hasAVX()) |
| 82 | return 4; |
| 83 | |
| 84 | return 2; |
| 85 | } |
| 86 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 87 | unsigned X86TTIImpl::getArithmeticInstrCost( |
| 88 | unsigned Opcode, Type *Ty, TTI::OperandValueKind Op1Info, |
| 89 | TTI::OperandValueKind Op2Info, TTI::OperandValueProperties Opd1PropInfo, |
| 90 | TTI::OperandValueProperties Opd2PropInfo) { |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 91 | // Legalize the type. |
| 92 | std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Ty); |
| 93 | |
| 94 | int ISD = TLI->InstructionOpcodeToISD(Opcode); |
| 95 | assert(ISD && "Invalid opcode"); |
| 96 | |
Karthik Bhat | 7f33ff7 | 2014-08-25 04:56:54 +0000 | [diff] [blame] | 97 | if (ISD == ISD::SDIV && |
| 98 | Op2Info == TargetTransformInfo::OK_UniformConstantValue && |
| 99 | Opd2PropInfo == TargetTransformInfo::OP_PowerOf2) { |
| 100 | // On X86, vector signed division by constants power-of-two are |
| 101 | // normally expanded to the sequence SRA + SRL + ADD + SRA. |
| 102 | // The OperandValue properties many not be same as that of previous |
| 103 | // operation;conservatively assume OP_None. |
| 104 | unsigned Cost = |
| 105 | 2 * getArithmeticInstrCost(Instruction::AShr, Ty, Op1Info, Op2Info, |
| 106 | TargetTransformInfo::OP_None, |
| 107 | TargetTransformInfo::OP_None); |
| 108 | Cost += getArithmeticInstrCost(Instruction::LShr, Ty, Op1Info, Op2Info, |
| 109 | TargetTransformInfo::OP_None, |
| 110 | TargetTransformInfo::OP_None); |
| 111 | Cost += getArithmeticInstrCost(Instruction::Add, Ty, Op1Info, Op2Info, |
| 112 | TargetTransformInfo::OP_None, |
| 113 | TargetTransformInfo::OP_None); |
| 114 | |
| 115 | return Cost; |
| 116 | } |
| 117 | |
Benjamin Kramer | 7c37227 | 2014-04-26 14:53:05 +0000 | [diff] [blame] | 118 | static const CostTblEntry<MVT::SimpleValueType> |
| 119 | AVX2UniformConstCostTable[] = { |
Simon Pilgrim | 8fbf1c1 | 2015-07-06 22:35:19 +0000 | [diff] [blame^] | 120 | { ISD::SRA, MVT::v4i64, 4 }, // 2 x psrad + shuffle. |
| 121 | |
Benjamin Kramer | 7c37227 | 2014-04-26 14:53:05 +0000 | [diff] [blame] | 122 | { ISD::SDIV, MVT::v16i16, 6 }, // vpmulhw sequence |
| 123 | { ISD::UDIV, MVT::v16i16, 6 }, // vpmulhuw sequence |
| 124 | { ISD::SDIV, MVT::v8i32, 15 }, // vpmuldq sequence |
| 125 | { ISD::UDIV, MVT::v8i32, 15 }, // vpmuludq sequence |
| 126 | }; |
| 127 | |
| 128 | if (Op2Info == TargetTransformInfo::OK_UniformConstantValue && |
| 129 | ST->hasAVX2()) { |
| 130 | int Idx = CostTableLookup(AVX2UniformConstCostTable, ISD, LT.second); |
| 131 | if (Idx != -1) |
| 132 | return LT.first * AVX2UniformConstCostTable[Idx].Cost; |
| 133 | } |
| 134 | |
Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 135 | static const CostTblEntry<MVT::SimpleValueType> AVX512CostTable[] = { |
| 136 | { ISD::SHL, MVT::v16i32, 1 }, |
| 137 | { ISD::SRL, MVT::v16i32, 1 }, |
| 138 | { ISD::SRA, MVT::v16i32, 1 }, |
| 139 | { ISD::SHL, MVT::v8i64, 1 }, |
| 140 | { ISD::SRL, MVT::v8i64, 1 }, |
| 141 | { ISD::SRA, MVT::v8i64, 1 }, |
| 142 | }; |
| 143 | |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 144 | static const CostTblEntry<MVT::SimpleValueType> AVX2CostTable[] = { |
Michael Liao | 70dd7f9 | 2013-03-20 22:01:10 +0000 | [diff] [blame] | 145 | // Shifts on v4i64/v8i32 on AVX2 is legal even though we declare to |
| 146 | // customize them to detect the cases where shift amount is a scalar one. |
| 147 | { ISD::SHL, MVT::v4i32, 1 }, |
| 148 | { ISD::SRL, MVT::v4i32, 1 }, |
| 149 | { ISD::SRA, MVT::v4i32, 1 }, |
| 150 | { ISD::SHL, MVT::v8i32, 1 }, |
| 151 | { ISD::SRL, MVT::v8i32, 1 }, |
| 152 | { ISD::SRA, MVT::v8i32, 1 }, |
| 153 | { ISD::SHL, MVT::v2i64, 1 }, |
| 154 | { ISD::SRL, MVT::v2i64, 1 }, |
| 155 | { ISD::SHL, MVT::v4i64, 1 }, |
| 156 | { ISD::SRL, MVT::v4i64, 1 }, |
Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 157 | |
Simon Pilgrim | 5965680 | 2015-06-11 07:46:37 +0000 | [diff] [blame] | 158 | { ISD::SHL, MVT::v32i8, 11 }, // vpblendvb sequence. |
Simon Pilgrim | 0be4fa7 | 2015-05-25 17:49:13 +0000 | [diff] [blame] | 159 | { ISD::SHL, MVT::v16i16, 10 }, // extend/vpsrlvd/pack sequence. |
Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 160 | |
Simon Pilgrim | 5965680 | 2015-06-11 07:46:37 +0000 | [diff] [blame] | 161 | { ISD::SRL, MVT::v32i8, 11 }, // vpblendvb sequence. |
Simon Pilgrim | 0be4fa7 | 2015-05-25 17:49:13 +0000 | [diff] [blame] | 162 | { ISD::SRL, MVT::v16i16, 10 }, // extend/vpsrlvd/pack sequence. |
Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 163 | |
Simon Pilgrim | 5965680 | 2015-06-11 07:46:37 +0000 | [diff] [blame] | 164 | { ISD::SRA, MVT::v32i8, 24 }, // vpblendvb sequence. |
Simon Pilgrim | 0be4fa7 | 2015-05-25 17:49:13 +0000 | [diff] [blame] | 165 | { ISD::SRA, MVT::v16i16, 10 }, // extend/vpsravd/pack sequence. |
| 166 | { ISD::SRA, MVT::v4i64, 4*10 }, // Scalarized. |
Arnold Schwaighofer | a04b9ef | 2013-06-25 19:14:09 +0000 | [diff] [blame] | 167 | |
| 168 | // Vectorizing division is a bad idea. See the SSE2 table for more comments. |
| 169 | { ISD::SDIV, MVT::v32i8, 32*20 }, |
| 170 | { ISD::SDIV, MVT::v16i16, 16*20 }, |
| 171 | { ISD::SDIV, MVT::v8i32, 8*20 }, |
| 172 | { ISD::SDIV, MVT::v4i64, 4*20 }, |
| 173 | { ISD::UDIV, MVT::v32i8, 32*20 }, |
| 174 | { ISD::UDIV, MVT::v16i16, 16*20 }, |
| 175 | { ISD::UDIV, MVT::v8i32, 8*20 }, |
| 176 | { ISD::UDIV, MVT::v4i64, 4*20 }, |
Michael Liao | 70dd7f9 | 2013-03-20 22:01:10 +0000 | [diff] [blame] | 177 | }; |
| 178 | |
Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 179 | if (ST->hasAVX512()) { |
| 180 | int Idx = CostTableLookup(AVX512CostTable, ISD, LT.second); |
| 181 | if (Idx != -1) |
| 182 | return LT.first * AVX512CostTable[Idx].Cost; |
| 183 | } |
Michael Liao | 70dd7f9 | 2013-03-20 22:01:10 +0000 | [diff] [blame] | 184 | // Look for AVX2 lowering tricks. |
| 185 | if (ST->hasAVX2()) { |
Andrea Di Biagio | b7882b3 | 2014-02-12 23:43:47 +0000 | [diff] [blame] | 186 | if (ISD == ISD::SHL && LT.second == MVT::v16i16 && |
| 187 | (Op2Info == TargetTransformInfo::OK_UniformConstantValue || |
| 188 | Op2Info == TargetTransformInfo::OK_NonUniformConstantValue)) |
| 189 | // On AVX2, a packed v16i16 shift left by a constant build_vector |
| 190 | // is lowered into a vector multiply (vpmullw). |
| 191 | return LT.first; |
| 192 | |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 193 | int Idx = CostTableLookup(AVX2CostTable, ISD, LT.second); |
Michael Liao | 70dd7f9 | 2013-03-20 22:01:10 +0000 | [diff] [blame] | 194 | if (Idx != -1) |
| 195 | return LT.first * AVX2CostTable[Idx].Cost; |
| 196 | } |
| 197 | |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 198 | static const CostTblEntry<MVT::SimpleValueType> |
| 199 | SSE2UniformConstCostTable[] = { |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 200 | // We don't correctly identify costs of casts because they are marked as |
| 201 | // custom. |
| 202 | // Constant splats are cheaper for the following instructions. |
| 203 | { ISD::SHL, MVT::v16i8, 1 }, // psllw. |
| 204 | { ISD::SHL, MVT::v8i16, 1 }, // psllw. |
| 205 | { ISD::SHL, MVT::v4i32, 1 }, // pslld |
| 206 | { ISD::SHL, MVT::v2i64, 1 }, // psllq. |
| 207 | |
| 208 | { ISD::SRL, MVT::v16i8, 1 }, // psrlw. |
| 209 | { ISD::SRL, MVT::v8i16, 1 }, // psrlw. |
| 210 | { ISD::SRL, MVT::v4i32, 1 }, // psrld. |
| 211 | { ISD::SRL, MVT::v2i64, 1 }, // psrlq. |
| 212 | |
| 213 | { ISD::SRA, MVT::v16i8, 4 }, // psrlw, pand, pxor, psubb. |
| 214 | { ISD::SRA, MVT::v8i16, 1 }, // psraw. |
| 215 | { ISD::SRA, MVT::v4i32, 1 }, // psrad. |
Simon Pilgrim | 8fbf1c1 | 2015-07-06 22:35:19 +0000 | [diff] [blame^] | 216 | { ISD::SRA, MVT::v2i64, 4 }, // 2 x psrad + shuffle. |
Benjamin Kramer | 7c37227 | 2014-04-26 14:53:05 +0000 | [diff] [blame] | 217 | |
| 218 | { ISD::SDIV, MVT::v8i16, 6 }, // pmulhw sequence |
| 219 | { ISD::UDIV, MVT::v8i16, 6 }, // pmulhuw sequence |
Benjamin Kramer | ce4b3fe | 2014-04-27 18:47:54 +0000 | [diff] [blame] | 220 | { ISD::SDIV, MVT::v4i32, 19 }, // pmuludq sequence |
Benjamin Kramer | 7c37227 | 2014-04-26 14:53:05 +0000 | [diff] [blame] | 221 | { ISD::UDIV, MVT::v4i32, 15 }, // pmuludq sequence |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | if (Op2Info == TargetTransformInfo::OK_UniformConstantValue && |
| 225 | ST->hasSSE2()) { |
Benjamin Kramer | ce4b3fe | 2014-04-27 18:47:54 +0000 | [diff] [blame] | 226 | // pmuldq sequence. |
| 227 | if (ISD == ISD::SDIV && LT.second == MVT::v4i32 && ST->hasSSE41()) |
| 228 | return LT.first * 15; |
| 229 | |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 230 | int Idx = CostTableLookup(SSE2UniformConstCostTable, ISD, LT.second); |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 231 | if (Idx != -1) |
| 232 | return LT.first * SSE2UniformConstCostTable[Idx].Cost; |
| 233 | } |
| 234 | |
Andrea Di Biagio | b7882b3 | 2014-02-12 23:43:47 +0000 | [diff] [blame] | 235 | if (ISD == ISD::SHL && |
| 236 | Op2Info == TargetTransformInfo::OK_NonUniformConstantValue) { |
| 237 | EVT VT = LT.second; |
| 238 | if ((VT == MVT::v8i16 && ST->hasSSE2()) || |
| 239 | (VT == MVT::v4i32 && ST->hasSSE41())) |
| 240 | // Vector shift left by non uniform constant can be lowered |
| 241 | // into vector multiply (pmullw/pmulld). |
| 242 | return LT.first; |
| 243 | if (VT == MVT::v4i32 && ST->hasSSE2()) |
| 244 | // A vector shift left by non uniform constant is converted |
| 245 | // into a vector multiply; the new multiply is eventually |
| 246 | // lowered into a sequence of shuffles and 2 x pmuludq. |
| 247 | ISD = ISD::MUL; |
| 248 | } |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 249 | |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 250 | static const CostTblEntry<MVT::SimpleValueType> SSE2CostTable[] = { |
Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 251 | // We don't correctly identify costs of casts because they are marked as |
| 252 | // custom. |
| 253 | // For some cases, where the shift amount is a scalar we would be able |
| 254 | // to generate better code. Unfortunately, when this is the case the value |
| 255 | // (the splat) will get hoisted out of the loop, thereby making it invisible |
| 256 | // to ISel. The cost model must return worst case assumptions because it is |
| 257 | // used for vectorization and we don't want to make vectorized code worse |
| 258 | // than scalar code. |
Simon Pilgrim | 5965680 | 2015-06-11 07:46:37 +0000 | [diff] [blame] | 259 | { ISD::SHL, MVT::v16i8, 26 }, // cmpgtb sequence. |
| 260 | { ISD::SHL, MVT::v8i16, 32 }, // cmpgtb sequence. |
| 261 | { ISD::SHL, MVT::v4i32, 2*5 }, // We optimized this using mul. |
Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 262 | { ISD::SHL, MVT::v2i64, 2*10 }, // Scalarized. |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 263 | { ISD::SHL, MVT::v4i64, 4*10 }, // Scalarized. |
Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 264 | |
Simon Pilgrim | 5965680 | 2015-06-11 07:46:37 +0000 | [diff] [blame] | 265 | { ISD::SRL, MVT::v16i8, 26 }, // cmpgtb sequence. |
| 266 | { ISD::SRL, MVT::v8i16, 32 }, // cmpgtb sequence. |
Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 267 | { ISD::SRL, MVT::v4i32, 4*10 }, // Scalarized. |
| 268 | { ISD::SRL, MVT::v2i64, 2*10 }, // Scalarized. |
| 269 | |
Simon Pilgrim | 5965680 | 2015-06-11 07:46:37 +0000 | [diff] [blame] | 270 | { ISD::SRA, MVT::v16i8, 54 }, // unpacked cmpgtb sequence. |
| 271 | { ISD::SRA, MVT::v8i16, 32 }, // cmpgtb sequence. |
Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 272 | { ISD::SRA, MVT::v4i32, 4*10 }, // Scalarized. |
| 273 | { ISD::SRA, MVT::v2i64, 2*10 }, // Scalarized. |
Arnold Schwaighofer | a04b9ef | 2013-06-25 19:14:09 +0000 | [diff] [blame] | 274 | |
| 275 | // It is not a good idea to vectorize division. We have to scalarize it and |
| 276 | // in the process we will often end up having to spilling regular |
| 277 | // registers. The overhead of division is going to dominate most kernels |
| 278 | // anyways so try hard to prevent vectorization of division - it is |
| 279 | // generally a bad idea. Assume somewhat arbitrarily that we have to be able |
| 280 | // to hide "20 cycles" for each lane. |
| 281 | { ISD::SDIV, MVT::v16i8, 16*20 }, |
| 282 | { ISD::SDIV, MVT::v8i16, 8*20 }, |
| 283 | { ISD::SDIV, MVT::v4i32, 4*20 }, |
| 284 | { ISD::SDIV, MVT::v2i64, 2*20 }, |
| 285 | { ISD::UDIV, MVT::v16i8, 16*20 }, |
| 286 | { ISD::UDIV, MVT::v8i16, 8*20 }, |
| 287 | { ISD::UDIV, MVT::v4i32, 4*20 }, |
| 288 | { ISD::UDIV, MVT::v2i64, 2*20 }, |
Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 289 | }; |
| 290 | |
| 291 | if (ST->hasSSE2()) { |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 292 | int Idx = CostTableLookup(SSE2CostTable, ISD, LT.second); |
Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 293 | if (Idx != -1) |
| 294 | return LT.first * SSE2CostTable[Idx].Cost; |
| 295 | } |
| 296 | |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 297 | static const CostTblEntry<MVT::SimpleValueType> AVX1CostTable[] = { |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 298 | // We don't have to scalarize unsupported ops. We can issue two half-sized |
| 299 | // operations and we only need to extract the upper YMM half. |
| 300 | // Two ops + 1 extract + 1 insert = 4. |
Andrea Di Biagio | b7882b3 | 2014-02-12 23:43:47 +0000 | [diff] [blame] | 301 | { ISD::MUL, MVT::v16i16, 4 }, |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 302 | { ISD::MUL, MVT::v8i32, 4 }, |
| 303 | { ISD::SUB, MVT::v8i32, 4 }, |
| 304 | { ISD::ADD, MVT::v8i32, 4 }, |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 305 | { ISD::SUB, MVT::v4i64, 4 }, |
| 306 | { ISD::ADD, MVT::v4i64, 4 }, |
Arnold Schwaighofer | 20ef54f | 2013-03-02 04:02:52 +0000 | [diff] [blame] | 307 | // A v4i64 multiply is custom lowered as two split v2i64 vectors that then |
| 308 | // are lowered as a series of long multiplies(3), shifts(4) and adds(2) |
| 309 | // Because we believe v4i64 to be a legal type, we must also include the |
| 310 | // split factor of two in the cost table. Therefore, the cost here is 18 |
| 311 | // instead of 9. |
| 312 | { ISD::MUL, MVT::v4i64, 18 }, |
| 313 | }; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 314 | |
| 315 | // Look for AVX1 lowering tricks. |
Arnold Schwaighofer | 20ef54f | 2013-03-02 04:02:52 +0000 | [diff] [blame] | 316 | if (ST->hasAVX() && !ST->hasAVX2()) { |
Andrea Di Biagio | b7882b3 | 2014-02-12 23:43:47 +0000 | [diff] [blame] | 317 | EVT VT = LT.second; |
| 318 | |
| 319 | // v16i16 and v8i32 shifts by non-uniform constants are lowered into a |
| 320 | // sequence of extract + two vector multiply + insert. |
| 321 | if (ISD == ISD::SHL && (VT == MVT::v8i32 || VT == MVT::v16i16) && |
| 322 | Op2Info == TargetTransformInfo::OK_NonUniformConstantValue) |
| 323 | ISD = ISD::MUL; |
| 324 | |
| 325 | int Idx = CostTableLookup(AVX1CostTable, ISD, VT); |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 326 | if (Idx != -1) |
| 327 | return LT.first * AVX1CostTable[Idx].Cost; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 328 | } |
Arnold Schwaighofer | 20ef54f | 2013-03-02 04:02:52 +0000 | [diff] [blame] | 329 | |
| 330 | // Custom lowering of vectors. |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 331 | static const CostTblEntry<MVT::SimpleValueType> CustomLowered[] = { |
Arnold Schwaighofer | 20ef54f | 2013-03-02 04:02:52 +0000 | [diff] [blame] | 332 | // A v2i64/v4i64 and multiply is custom lowered as a series of long |
| 333 | // multiplies(3), shifts(4) and adds(2). |
| 334 | { ISD::MUL, MVT::v2i64, 9 }, |
| 335 | { ISD::MUL, MVT::v4i64, 9 }, |
| 336 | }; |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 337 | int Idx = CostTableLookup(CustomLowered, ISD, LT.second); |
Arnold Schwaighofer | 20ef54f | 2013-03-02 04:02:52 +0000 | [diff] [blame] | 338 | if (Idx != -1) |
| 339 | return LT.first * CustomLowered[Idx].Cost; |
| 340 | |
| 341 | // Special lowering of v4i32 mul on sse2, sse3: Lower v4i32 mul as 2x shuffle, |
| 342 | // 2x pmuludq, 2x shuffle. |
| 343 | if (ISD == ISD::MUL && LT.second == MVT::v4i32 && ST->hasSSE2() && |
| 344 | !ST->hasSSE41()) |
Andrea Di Biagio | b7882b3 | 2014-02-12 23:43:47 +0000 | [diff] [blame] | 345 | return LT.first * 6; |
Arnold Schwaighofer | 20ef54f | 2013-03-02 04:02:52 +0000 | [diff] [blame] | 346 | |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 347 | // Fallback to the default implementation. |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 348 | return BaseT::getArithmeticInstrCost(Opcode, Ty, Op1Info, Op2Info); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 351 | unsigned X86TTIImpl::getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, |
| 352 | Type *SubTp) { |
Karthik Bhat | e03a25d | 2014-06-20 04:32:48 +0000 | [diff] [blame] | 353 | // We only estimate the cost of reverse and alternate shuffles. |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 354 | if (Kind != TTI::SK_Reverse && Kind != TTI::SK_Alternate) |
| 355 | return BaseT::getShuffleCost(Kind, Tp, Index, SubTp); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 356 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 357 | if (Kind == TTI::SK_Reverse) { |
Karthik Bhat | e03a25d | 2014-06-20 04:32:48 +0000 | [diff] [blame] | 358 | std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Tp); |
| 359 | unsigned Cost = 1; |
| 360 | if (LT.second.getSizeInBits() > 128) |
| 361 | Cost = 3; // Extract + insert + copy. |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 362 | |
Karthik Bhat | e03a25d | 2014-06-20 04:32:48 +0000 | [diff] [blame] | 363 | // Multiple by the number of parts. |
| 364 | return Cost * LT.first; |
| 365 | } |
| 366 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 367 | if (Kind == TTI::SK_Alternate) { |
Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 368 | // 64-bit packed float vectors (v2f32) are widened to type v4f32. |
| 369 | // 64-bit packed integer vectors (v2i32) are promoted to type v2i64. |
Karthik Bhat | e03a25d | 2014-06-20 04:32:48 +0000 | [diff] [blame] | 370 | std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Tp); |
| 371 | |
Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 372 | // The backend knows how to generate a single VEX.256 version of |
| 373 | // instruction VPBLENDW if the target supports AVX2. |
| 374 | if (ST->hasAVX2() && LT.second == MVT::v16i16) |
| 375 | return LT.first; |
| 376 | |
| 377 | static const CostTblEntry<MVT::SimpleValueType> AVXAltShuffleTbl[] = { |
| 378 | {ISD::VECTOR_SHUFFLE, MVT::v4i64, 1}, // vblendpd |
| 379 | {ISD::VECTOR_SHUFFLE, MVT::v4f64, 1}, // vblendpd |
| 380 | |
| 381 | {ISD::VECTOR_SHUFFLE, MVT::v8i32, 1}, // vblendps |
| 382 | {ISD::VECTOR_SHUFFLE, MVT::v8f32, 1}, // vblendps |
| 383 | |
| 384 | // This shuffle is custom lowered into a sequence of: |
| 385 | // 2x vextractf128 , 2x vpblendw , 1x vinsertf128 |
| 386 | {ISD::VECTOR_SHUFFLE, MVT::v16i16, 5}, |
| 387 | |
| 388 | // This shuffle is custom lowered into a long sequence of: |
| 389 | // 2x vextractf128 , 4x vpshufb , 2x vpor , 1x vinsertf128 |
| 390 | {ISD::VECTOR_SHUFFLE, MVT::v32i8, 9} |
| 391 | }; |
| 392 | |
| 393 | if (ST->hasAVX()) { |
| 394 | int Idx = CostTableLookup(AVXAltShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second); |
| 395 | if (Idx != -1) |
| 396 | return LT.first * AVXAltShuffleTbl[Idx].Cost; |
| 397 | } |
| 398 | |
| 399 | static const CostTblEntry<MVT::SimpleValueType> SSE41AltShuffleTbl[] = { |
| 400 | // These are lowered into movsd. |
| 401 | {ISD::VECTOR_SHUFFLE, MVT::v2i64, 1}, |
| 402 | {ISD::VECTOR_SHUFFLE, MVT::v2f64, 1}, |
| 403 | |
| 404 | // packed float vectors with four elements are lowered into BLENDI dag |
| 405 | // nodes. A v4i32/v4f32 BLENDI generates a single 'blendps'/'blendpd'. |
| 406 | {ISD::VECTOR_SHUFFLE, MVT::v4i32, 1}, |
| 407 | {ISD::VECTOR_SHUFFLE, MVT::v4f32, 1}, |
| 408 | |
| 409 | // This shuffle generates a single pshufw. |
| 410 | {ISD::VECTOR_SHUFFLE, MVT::v8i16, 1}, |
| 411 | |
| 412 | // There is no instruction that matches a v16i8 alternate shuffle. |
| 413 | // The backend will expand it into the sequence 'pshufb + pshufb + or'. |
| 414 | {ISD::VECTOR_SHUFFLE, MVT::v16i8, 3} |
| 415 | }; |
| 416 | |
| 417 | if (ST->hasSSE41()) { |
| 418 | int Idx = CostTableLookup(SSE41AltShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second); |
| 419 | if (Idx != -1) |
| 420 | return LT.first * SSE41AltShuffleTbl[Idx].Cost; |
| 421 | } |
| 422 | |
| 423 | static const CostTblEntry<MVT::SimpleValueType> SSSE3AltShuffleTbl[] = { |
| 424 | {ISD::VECTOR_SHUFFLE, MVT::v2i64, 1}, // movsd |
| 425 | {ISD::VECTOR_SHUFFLE, MVT::v2f64, 1}, // movsd |
| 426 | |
| 427 | // SSE3 doesn't have 'blendps'. The following shuffles are expanded into |
| 428 | // the sequence 'shufps + pshufd' |
| 429 | {ISD::VECTOR_SHUFFLE, MVT::v4i32, 2}, |
| 430 | {ISD::VECTOR_SHUFFLE, MVT::v4f32, 2}, |
| 431 | |
| 432 | {ISD::VECTOR_SHUFFLE, MVT::v8i16, 3}, // pshufb + pshufb + or |
| 433 | {ISD::VECTOR_SHUFFLE, MVT::v16i8, 3} // pshufb + pshufb + or |
| 434 | }; |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 435 | |
Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 436 | if (ST->hasSSSE3()) { |
| 437 | int Idx = CostTableLookup(SSSE3AltShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second); |
| 438 | if (Idx != -1) |
| 439 | return LT.first * SSSE3AltShuffleTbl[Idx].Cost; |
| 440 | } |
| 441 | |
| 442 | static const CostTblEntry<MVT::SimpleValueType> SSEAltShuffleTbl[] = { |
| 443 | {ISD::VECTOR_SHUFFLE, MVT::v2i64, 1}, // movsd |
| 444 | {ISD::VECTOR_SHUFFLE, MVT::v2f64, 1}, // movsd |
| 445 | |
| 446 | {ISD::VECTOR_SHUFFLE, MVT::v4i32, 2}, // shufps + pshufd |
| 447 | {ISD::VECTOR_SHUFFLE, MVT::v4f32, 2}, // shufps + pshufd |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 448 | |
Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 449 | // This is expanded into a long sequence of four extract + four insert. |
| 450 | {ISD::VECTOR_SHUFFLE, MVT::v8i16, 8}, // 4 x pextrw + 4 pinsrw. |
| 451 | |
| 452 | // 8 x (pinsrw + pextrw + and + movb + movzb + or) |
| 453 | {ISD::VECTOR_SHUFFLE, MVT::v16i8, 48} |
| 454 | }; |
| 455 | |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 456 | // Fall-back (SSE3 and SSE2). |
Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 457 | int Idx = CostTableLookup(SSEAltShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second); |
| 458 | if (Idx != -1) |
| 459 | return LT.first * SSEAltShuffleTbl[Idx].Cost; |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 460 | return BaseT::getShuffleCost(Kind, Tp, Index, SubTp); |
Karthik Bhat | e03a25d | 2014-06-20 04:32:48 +0000 | [diff] [blame] | 461 | } |
| 462 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 463 | return BaseT::getShuffleCost(Kind, Tp, Index, SubTp); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 466 | unsigned X86TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) { |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 467 | int ISD = TLI->InstructionOpcodeToISD(Opcode); |
| 468 | assert(ISD && "Invalid opcode"); |
| 469 | |
Arnold Schwaighofer | f47d2d7 | 2013-04-08 18:05:48 +0000 | [diff] [blame] | 470 | std::pair<unsigned, MVT> LTSrc = TLI->getTypeLegalizationCost(Src); |
| 471 | std::pair<unsigned, MVT> LTDest = TLI->getTypeLegalizationCost(Dst); |
| 472 | |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 473 | static const TypeConversionCostTblEntry<MVT::SimpleValueType> |
| 474 | SSE2ConvTbl[] = { |
Arnold Schwaighofer | f47d2d7 | 2013-04-08 18:05:48 +0000 | [diff] [blame] | 475 | // These are somewhat magic numbers justified by looking at the output of |
| 476 | // Intel's IACA, running some kernels and making sure when we take |
| 477 | // legalization into account the throughput will be overestimated. |
| 478 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, 2*10 }, |
| 479 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v4i32, 4*10 }, |
| 480 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v8i16, 8*10 }, |
| 481 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v16i8, 16*10 }, |
| 482 | { ISD::SINT_TO_FP, MVT::v2f64, MVT::v2i64, 2*10 }, |
| 483 | { ISD::SINT_TO_FP, MVT::v2f64, MVT::v4i32, 4*10 }, |
| 484 | { ISD::SINT_TO_FP, MVT::v2f64, MVT::v8i16, 8*10 }, |
| 485 | { ISD::SINT_TO_FP, MVT::v2f64, MVT::v16i8, 16*10 }, |
| 486 | // There are faster sequences for float conversions. |
| 487 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v2i64, 15 }, |
Quentin Colombet | 360460b | 2014-11-11 02:23:47 +0000 | [diff] [blame] | 488 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, 8 }, |
Arnold Schwaighofer | f47d2d7 | 2013-04-08 18:05:48 +0000 | [diff] [blame] | 489 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v8i16, 15 }, |
| 490 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v16i8, 8 }, |
| 491 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v2i64, 15 }, |
| 492 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i32, 15 }, |
| 493 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v8i16, 15 }, |
| 494 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v16i8, 8 }, |
| 495 | }; |
| 496 | |
| 497 | if (ST->hasSSE2() && !ST->hasAVX()) { |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 498 | int Idx = |
| 499 | ConvertCostTableLookup(SSE2ConvTbl, ISD, LTDest.second, LTSrc.second); |
Arnold Schwaighofer | f47d2d7 | 2013-04-08 18:05:48 +0000 | [diff] [blame] | 500 | if (Idx != -1) |
| 501 | return LTSrc.first * SSE2ConvTbl[Idx].Cost; |
| 502 | } |
| 503 | |
Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 504 | static const TypeConversionCostTblEntry<MVT::SimpleValueType> |
| 505 | AVX512ConversionTbl[] = { |
| 506 | { ISD::FP_EXTEND, MVT::v8f64, MVT::v8f32, 1 }, |
| 507 | { ISD::FP_EXTEND, MVT::v8f64, MVT::v16f32, 3 }, |
| 508 | { ISD::FP_ROUND, MVT::v8f32, MVT::v8f64, 1 }, |
| 509 | { ISD::FP_ROUND, MVT::v16f32, MVT::v8f64, 3 }, |
| 510 | |
| 511 | { ISD::TRUNCATE, MVT::v16i8, MVT::v16i32, 1 }, |
| 512 | { ISD::TRUNCATE, MVT::v16i16, MVT::v16i32, 1 }, |
| 513 | { ISD::TRUNCATE, MVT::v8i16, MVT::v8i64, 1 }, |
| 514 | { ISD::TRUNCATE, MVT::v8i32, MVT::v8i64, 1 }, |
| 515 | { ISD::TRUNCATE, MVT::v16i32, MVT::v8i64, 4 }, |
| 516 | |
| 517 | // v16i1 -> v16i32 - load + broadcast |
| 518 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i1, 2 }, |
| 519 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i1, 2 }, |
| 520 | |
| 521 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i8, 1 }, |
| 522 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i8, 1 }, |
| 523 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i16, 1 }, |
| 524 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i16, 1 }, |
| 525 | { ISD::SIGN_EXTEND, MVT::v8i64, MVT::v16i32, 3 }, |
| 526 | { ISD::ZERO_EXTEND, MVT::v8i64, MVT::v16i32, 3 }, |
| 527 | |
Elena Demikhovsky | d5e95b5 | 2014-11-13 11:46:16 +0000 | [diff] [blame] | 528 | { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i1, 3 }, |
| 529 | { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i8, 2 }, |
| 530 | { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i16, 2 }, |
| 531 | { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i32, 1 }, |
| 532 | { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i1, 4 }, |
| 533 | { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i16, 2 }, |
| 534 | { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i32, 1 }, |
Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 535 | }; |
| 536 | |
| 537 | if (ST->hasAVX512()) { |
| 538 | int Idx = ConvertCostTableLookup(AVX512ConversionTbl, ISD, LTDest.second, |
| 539 | LTSrc.second); |
| 540 | if (Idx != -1) |
| 541 | return AVX512ConversionTbl[Idx].Cost; |
| 542 | } |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 543 | EVT SrcTy = TLI->getValueType(Src); |
| 544 | EVT DstTy = TLI->getValueType(Dst); |
| 545 | |
Arnold Schwaighofer | c0c7ff4 | 2013-04-17 20:04:53 +0000 | [diff] [blame] | 546 | // The function getSimpleVT only handles simple value types. |
| 547 | if (!SrcTy.isSimple() || !DstTy.isSimple()) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 548 | return BaseT::getCastInstrCost(Opcode, Dst, Src); |
Arnold Schwaighofer | c0c7ff4 | 2013-04-17 20:04:53 +0000 | [diff] [blame] | 549 | |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 550 | static const TypeConversionCostTblEntry<MVT::SimpleValueType> |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 551 | AVX2ConversionTbl[] = { |
| 552 | { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i8, 1 }, |
| 553 | { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i8, 1 }, |
| 554 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i1, 3 }, |
| 555 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i1, 3 }, |
| 556 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i8, 3 }, |
| 557 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i8, 3 }, |
| 558 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, 1 }, |
| 559 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, 1 }, |
| 560 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i1, 3 }, |
| 561 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i1, 3 }, |
| 562 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i8, 3 }, |
| 563 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i8, 3 }, |
| 564 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i16, 3 }, |
| 565 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i16, 3 }, |
| 566 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, 1 }, |
| 567 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, 1 }, |
| 568 | |
| 569 | { ISD::TRUNCATE, MVT::v4i8, MVT::v4i64, 2 }, |
| 570 | { ISD::TRUNCATE, MVT::v4i16, MVT::v4i64, 2 }, |
| 571 | { ISD::TRUNCATE, MVT::v4i32, MVT::v4i64, 2 }, |
| 572 | { ISD::TRUNCATE, MVT::v8i8, MVT::v8i32, 2 }, |
| 573 | { ISD::TRUNCATE, MVT::v8i16, MVT::v8i32, 2 }, |
| 574 | { ISD::TRUNCATE, MVT::v8i32, MVT::v8i64, 4 }, |
Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 575 | |
| 576 | { ISD::FP_EXTEND, MVT::v8f64, MVT::v8f32, 3 }, |
| 577 | { ISD::FP_ROUND, MVT::v8f32, MVT::v8f64, 3 }, |
Quentin Colombet | 360460b | 2014-11-11 02:23:47 +0000 | [diff] [blame] | 578 | |
| 579 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i32, 8 }, |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 580 | }; |
| 581 | |
| 582 | static const TypeConversionCostTblEntry<MVT::SimpleValueType> |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 583 | AVXConversionTbl[] = { |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 584 | { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i8, 4 }, |
| 585 | { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i8, 4 }, |
| 586 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i1, 7 }, |
| 587 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i1, 4 }, |
| 588 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i8, 7 }, |
| 589 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i8, 4 }, |
| 590 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, 4 }, |
| 591 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, 4 }, |
| 592 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i1, 6 }, |
| 593 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i1, 4 }, |
| 594 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i8, 6 }, |
| 595 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i8, 4 }, |
| 596 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i16, 6 }, |
| 597 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i16, 3 }, |
| 598 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, 4 }, |
| 599 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, 4 }, |
| 600 | |
| 601 | { ISD::TRUNCATE, MVT::v4i8, MVT::v4i64, 4 }, |
| 602 | { ISD::TRUNCATE, MVT::v4i16, MVT::v4i64, 4 }, |
| 603 | { ISD::TRUNCATE, MVT::v4i32, MVT::v4i64, 4 }, |
| 604 | { ISD::TRUNCATE, MVT::v8i8, MVT::v8i32, 4 }, |
| 605 | { ISD::TRUNCATE, MVT::v8i16, MVT::v8i32, 5 }, |
| 606 | { ISD::TRUNCATE, MVT::v16i8, MVT::v16i16, 4 }, |
| 607 | { ISD::TRUNCATE, MVT::v8i32, MVT::v8i64, 9 }, |
Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 608 | |
| 609 | { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i1, 8 }, |
| 610 | { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i8, 8 }, |
| 611 | { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i16, 5 }, |
| 612 | { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i32, 1 }, |
| 613 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i1, 3 }, |
| 614 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i8, 3 }, |
| 615 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i16, 3 }, |
| 616 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i32, 1 }, |
| 617 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i1, 3 }, |
| 618 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i8, 3 }, |
| 619 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i16, 3 }, |
| 620 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i32, 1 }, |
| 621 | |
| 622 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i1, 6 }, |
| 623 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i8, 5 }, |
| 624 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i16, 5 }, |
| 625 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i32, 9 }, |
| 626 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i1, 7 }, |
| 627 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i8, 2 }, |
| 628 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i16, 2 }, |
| 629 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, 6 }, |
| 630 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i1, 7 }, |
| 631 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i8, 2 }, |
| 632 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i16, 2 }, |
| 633 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i32, 6 }, |
Quentin Colombet | 85b904d | 2014-03-27 22:27:41 +0000 | [diff] [blame] | 634 | // The generic code to compute the scalar overhead is currently broken. |
| 635 | // Workaround this limitation by estimating the scalarization overhead |
| 636 | // here. We have roughly 10 instructions per scalar element. |
| 637 | // Multiply that by the vector width. |
| 638 | // FIXME: remove that when PR19268 is fixed. |
Quentin Colombet | 3914bf5 | 2014-03-27 00:52:16 +0000 | [diff] [blame] | 639 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, 2*10 }, |
| 640 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i64, 4*10 }, |
Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 641 | |
Jim Grosbach | 72fbde8 | 2014-03-27 00:04:11 +0000 | [diff] [blame] | 642 | { ISD::FP_TO_SINT, MVT::v8i8, MVT::v8f32, 7 }, |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 643 | { ISD::FP_TO_SINT, MVT::v4i8, MVT::v4f32, 1 }, |
Adam Nemet | 6dafe97 | 2014-03-30 18:07:13 +0000 | [diff] [blame] | 644 | // This node is expanded into scalarized operations but BasicTTI is overly |
| 645 | // optimistic estimating its cost. It computes 3 per element (one |
| 646 | // vector-extract, one scalar conversion and one vector-insert). The |
| 647 | // problem is that the inserts form a read-modify-write chain so latency |
| 648 | // should be factored in too. Inflating the cost per element by 1. |
| 649 | { ISD::FP_TO_UINT, MVT::v8i32, MVT::v8f32, 8*4 }, |
Adam Nemet | 10c4ce2 | 2014-03-31 21:54:48 +0000 | [diff] [blame] | 650 | { ISD::FP_TO_UINT, MVT::v4i32, MVT::v4f64, 4*4 }, |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 651 | }; |
| 652 | |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 653 | if (ST->hasAVX2()) { |
| 654 | int Idx = ConvertCostTableLookup(AVX2ConversionTbl, ISD, |
| 655 | DstTy.getSimpleVT(), SrcTy.getSimpleVT()); |
| 656 | if (Idx != -1) |
| 657 | return AVX2ConversionTbl[Idx].Cost; |
| 658 | } |
| 659 | |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 660 | if (ST->hasAVX()) { |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 661 | int Idx = ConvertCostTableLookup(AVXConversionTbl, ISD, DstTy.getSimpleVT(), |
| 662 | SrcTy.getSimpleVT()); |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 663 | if (Idx != -1) |
| 664 | return AVXConversionTbl[Idx].Cost; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 667 | return BaseT::getCastInstrCost(Opcode, Dst, Src); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 670 | unsigned X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, |
| 671 | Type *CondTy) { |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 672 | // Legalize the type. |
| 673 | std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(ValTy); |
| 674 | |
| 675 | MVT MTy = LT.second; |
| 676 | |
| 677 | int ISD = TLI->InstructionOpcodeToISD(Opcode); |
| 678 | assert(ISD && "Invalid opcode"); |
| 679 | |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 680 | static const CostTblEntry<MVT::SimpleValueType> SSE42CostTbl[] = { |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 681 | { ISD::SETCC, MVT::v2f64, 1 }, |
| 682 | { ISD::SETCC, MVT::v4f32, 1 }, |
| 683 | { ISD::SETCC, MVT::v2i64, 1 }, |
| 684 | { ISD::SETCC, MVT::v4i32, 1 }, |
| 685 | { ISD::SETCC, MVT::v8i16, 1 }, |
| 686 | { ISD::SETCC, MVT::v16i8, 1 }, |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 687 | }; |
| 688 | |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 689 | static const CostTblEntry<MVT::SimpleValueType> AVX1CostTbl[] = { |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 690 | { ISD::SETCC, MVT::v4f64, 1 }, |
| 691 | { ISD::SETCC, MVT::v8f32, 1 }, |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 692 | // AVX1 does not support 8-wide integer compare. |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 693 | { ISD::SETCC, MVT::v4i64, 4 }, |
| 694 | { ISD::SETCC, MVT::v8i32, 4 }, |
| 695 | { ISD::SETCC, MVT::v16i16, 4 }, |
| 696 | { ISD::SETCC, MVT::v32i8, 4 }, |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 697 | }; |
| 698 | |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 699 | static const CostTblEntry<MVT::SimpleValueType> AVX2CostTbl[] = { |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 700 | { ISD::SETCC, MVT::v4i64, 1 }, |
| 701 | { ISD::SETCC, MVT::v8i32, 1 }, |
| 702 | { ISD::SETCC, MVT::v16i16, 1 }, |
| 703 | { ISD::SETCC, MVT::v32i8, 1 }, |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 704 | }; |
| 705 | |
Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 706 | static const CostTblEntry<MVT::SimpleValueType> AVX512CostTbl[] = { |
| 707 | { ISD::SETCC, MVT::v8i64, 1 }, |
| 708 | { ISD::SETCC, MVT::v16i32, 1 }, |
| 709 | { ISD::SETCC, MVT::v8f64, 1 }, |
| 710 | { ISD::SETCC, MVT::v16f32, 1 }, |
| 711 | }; |
| 712 | |
| 713 | if (ST->hasAVX512()) { |
| 714 | int Idx = CostTableLookup(AVX512CostTbl, ISD, MTy); |
| 715 | if (Idx != -1) |
| 716 | return LT.first * AVX512CostTbl[Idx].Cost; |
| 717 | } |
| 718 | |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 719 | if (ST->hasAVX2()) { |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 720 | int Idx = CostTableLookup(AVX2CostTbl, ISD, MTy); |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 721 | if (Idx != -1) |
| 722 | return LT.first * AVX2CostTbl[Idx].Cost; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | if (ST->hasAVX()) { |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 726 | int Idx = CostTableLookup(AVX1CostTbl, ISD, MTy); |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 727 | if (Idx != -1) |
| 728 | return LT.first * AVX1CostTbl[Idx].Cost; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | if (ST->hasSSE42()) { |
Benjamin Kramer | 21585fd | 2013-08-09 19:33:32 +0000 | [diff] [blame] | 732 | int Idx = CostTableLookup(SSE42CostTbl, ISD, MTy); |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 733 | if (Idx != -1) |
| 734 | return LT.first * SSE42CostTbl[Idx].Cost; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 735 | } |
| 736 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 737 | return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 738 | } |
| 739 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 740 | unsigned X86TTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val, |
| 741 | unsigned Index) { |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 742 | assert(Val->isVectorTy() && "This must be a vector type"); |
| 743 | |
| 744 | if (Index != -1U) { |
| 745 | // Legalize the type. |
| 746 | std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Val); |
| 747 | |
| 748 | // This type is legalized to a scalar type. |
| 749 | if (!LT.second.isVector()) |
| 750 | return 0; |
| 751 | |
| 752 | // The type may be split. Normalize the index to the new type. |
| 753 | unsigned Width = LT.second.getVectorNumElements(); |
| 754 | Index = Index % Width; |
| 755 | |
| 756 | // Floating point scalars are already located in index #0. |
| 757 | if (Val->getScalarType()->isFloatingPointTy() && Index == 0) |
| 758 | return 0; |
| 759 | } |
| 760 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 761 | return BaseT::getVectorInstrCost(Opcode, Val, Index); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 762 | } |
| 763 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 764 | unsigned X86TTIImpl::getScalarizationOverhead(Type *Ty, bool Insert, |
| 765 | bool Extract) { |
Nadav Rotem | f9ecbcb | 2013-06-27 17:52:04 +0000 | [diff] [blame] | 766 | assert (Ty->isVectorTy() && "Can only scalarize vectors"); |
| 767 | unsigned Cost = 0; |
| 768 | |
| 769 | for (int i = 0, e = Ty->getVectorNumElements(); i < e; ++i) { |
| 770 | if (Insert) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 771 | Cost += getVectorInstrCost(Instruction::InsertElement, Ty, i); |
Nadav Rotem | f9ecbcb | 2013-06-27 17:52:04 +0000 | [diff] [blame] | 772 | if (Extract) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 773 | Cost += getVectorInstrCost(Instruction::ExtractElement, Ty, i); |
Nadav Rotem | f9ecbcb | 2013-06-27 17:52:04 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | return Cost; |
| 777 | } |
| 778 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 779 | unsigned X86TTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src, |
| 780 | unsigned Alignment, |
| 781 | unsigned AddressSpace) { |
Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 782 | // Handle non-power-of-two vectors such as <3 x float> |
Nadav Rotem | f9ecbcb | 2013-06-27 17:52:04 +0000 | [diff] [blame] | 783 | if (VectorType *VTy = dyn_cast<VectorType>(Src)) { |
| 784 | unsigned NumElem = VTy->getVectorNumElements(); |
| 785 | |
| 786 | // Handle a few common cases: |
| 787 | // <3 x float> |
| 788 | if (NumElem == 3 && VTy->getScalarSizeInBits() == 32) |
| 789 | // Cost = 64 bit store + extract + 32 bit store. |
| 790 | return 3; |
| 791 | |
| 792 | // <3 x double> |
| 793 | if (NumElem == 3 && VTy->getScalarSizeInBits() == 64) |
| 794 | // Cost = 128 bit store + unpack + 64 bit store. |
| 795 | return 3; |
| 796 | |
Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 797 | // Assume that all other non-power-of-two numbers are scalarized. |
Nadav Rotem | f9ecbcb | 2013-06-27 17:52:04 +0000 | [diff] [blame] | 798 | if (!isPowerOf2_32(NumElem)) { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 799 | unsigned Cost = BaseT::getMemoryOpCost(Opcode, VTy->getScalarType(), |
| 800 | Alignment, AddressSpace); |
Nadav Rotem | f9ecbcb | 2013-06-27 17:52:04 +0000 | [diff] [blame] | 801 | unsigned SplitCost = getScalarizationOverhead(Src, |
| 802 | Opcode == Instruction::Load, |
| 803 | Opcode==Instruction::Store); |
| 804 | return NumElem * Cost + SplitCost; |
| 805 | } |
| 806 | } |
| 807 | |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 808 | // Legalize the type. |
| 809 | std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Src); |
| 810 | assert((Opcode == Instruction::Load || Opcode == Instruction::Store) && |
| 811 | "Invalid Opcode"); |
| 812 | |
| 813 | // Each load/store unit costs 1. |
| 814 | unsigned Cost = LT.first * 1; |
| 815 | |
| 816 | // On Sandybridge 256bit load/stores are double pumped |
| 817 | // (but not on Haswell). |
| 818 | if (LT.second.getSizeInBits() > 128 && !ST->hasAVX2()) |
| 819 | Cost*=2; |
| 820 | |
| 821 | return Cost; |
| 822 | } |
Arnold Schwaighofer | 6042a26 | 2013-07-12 19:16:07 +0000 | [diff] [blame] | 823 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 824 | unsigned X86TTIImpl::getMaskedMemoryOpCost(unsigned Opcode, Type *SrcTy, |
| 825 | unsigned Alignment, |
| 826 | unsigned AddressSpace) { |
Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 827 | VectorType *SrcVTy = dyn_cast<VectorType>(SrcTy); |
| 828 | if (!SrcVTy) |
| 829 | // To calculate scalar take the regular cost, without mask |
| 830 | return getMemoryOpCost(Opcode, SrcTy, Alignment, AddressSpace); |
| 831 | |
| 832 | unsigned NumElem = SrcVTy->getVectorNumElements(); |
| 833 | VectorType *MaskTy = |
| 834 | VectorType::get(Type::getInt8Ty(getGlobalContext()), NumElem); |
| 835 | if ((Opcode == Instruction::Load && !isLegalMaskedLoad(SrcVTy, 1)) || |
| 836 | (Opcode == Instruction::Store && !isLegalMaskedStore(SrcVTy, 1)) || |
| 837 | !isPowerOf2_32(NumElem)) { |
| 838 | // Scalarization |
| 839 | unsigned MaskSplitCost = getScalarizationOverhead(MaskTy, false, true); |
| 840 | unsigned ScalarCompareCost = |
| 841 | getCmpSelInstrCost(Instruction::ICmp, |
| 842 | Type::getInt8Ty(getGlobalContext()), NULL); |
| 843 | unsigned BranchCost = getCFInstrCost(Instruction::Br); |
| 844 | unsigned MaskCmpCost = NumElem * (BranchCost + ScalarCompareCost); |
| 845 | |
| 846 | unsigned ValueSplitCost = |
| 847 | getScalarizationOverhead(SrcVTy, Opcode == Instruction::Load, |
| 848 | Opcode == Instruction::Store); |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 849 | unsigned MemopCost = |
| 850 | NumElem * BaseT::getMemoryOpCost(Opcode, SrcVTy->getScalarType(), |
| 851 | Alignment, AddressSpace); |
Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 852 | return MemopCost + ValueSplitCost + MaskSplitCost + MaskCmpCost; |
| 853 | } |
| 854 | |
| 855 | // Legalize the type. |
| 856 | std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(SrcVTy); |
| 857 | unsigned Cost = 0; |
| 858 | if (LT.second != TLI->getValueType(SrcVTy).getSimpleVT() && |
| 859 | LT.second.getVectorNumElements() == NumElem) |
| 860 | // Promotion requires expand/truncate for data and a shuffle for mask. |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 861 | Cost += getShuffleCost(TTI::SK_Alternate, SrcVTy, 0, 0) + |
| 862 | getShuffleCost(TTI::SK_Alternate, MaskTy, 0, 0); |
| 863 | |
Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 864 | else if (LT.second.getVectorNumElements() > NumElem) { |
| 865 | VectorType *NewMaskTy = VectorType::get(MaskTy->getVectorElementType(), |
| 866 | LT.second.getVectorNumElements()); |
| 867 | // Expanding requires fill mask with zeroes |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 868 | Cost += getShuffleCost(TTI::SK_InsertSubvector, NewMaskTy, 0, MaskTy); |
Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 869 | } |
| 870 | if (!ST->hasAVX512()) |
| 871 | return Cost + LT.first*4; // Each maskmov costs 4 |
| 872 | |
| 873 | // AVX-512 masked load/store is cheapper |
| 874 | return Cost+LT.first; |
| 875 | } |
| 876 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 877 | unsigned X86TTIImpl::getAddressComputationCost(Type *Ty, bool IsComplex) { |
Arnold Schwaighofer | 6042a26 | 2013-07-12 19:16:07 +0000 | [diff] [blame] | 878 | // Address computations in vectorized code with non-consecutive addresses will |
| 879 | // likely result in more instructions compared to scalar code where the |
| 880 | // computation can more often be merged into the index mode. The resulting |
| 881 | // extra micro-ops can significantly decrease throughput. |
| 882 | unsigned NumVectorInstToHideOverhead = 10; |
| 883 | |
| 884 | if (Ty->isVectorTy() && IsComplex) |
| 885 | return NumVectorInstToHideOverhead; |
| 886 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 887 | return BaseT::getAddressComputationCost(Ty, IsComplex); |
Arnold Schwaighofer | 6042a26 | 2013-07-12 19:16:07 +0000 | [diff] [blame] | 888 | } |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 889 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 890 | unsigned X86TTIImpl::getReductionCost(unsigned Opcode, Type *ValTy, |
| 891 | bool IsPairwise) { |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 892 | |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 893 | std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(ValTy); |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 894 | |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 895 | MVT MTy = LT.second; |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 896 | |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 897 | int ISD = TLI->InstructionOpcodeToISD(Opcode); |
| 898 | assert(ISD && "Invalid opcode"); |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 899 | |
| 900 | // We use the Intel Architecture Code Analyzer(IACA) to measure the throughput |
| 901 | // and make it as the cost. |
| 902 | |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 903 | static const CostTblEntry<MVT::SimpleValueType> SSE42CostTblPairWise[] = { |
| 904 | { ISD::FADD, MVT::v2f64, 2 }, |
| 905 | { ISD::FADD, MVT::v4f32, 4 }, |
| 906 | { ISD::ADD, MVT::v2i64, 2 }, // The data reported by the IACA tool is "1.6". |
| 907 | { ISD::ADD, MVT::v4i32, 3 }, // The data reported by the IACA tool is "3.5". |
| 908 | { ISD::ADD, MVT::v8i16, 5 }, |
| 909 | }; |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 910 | |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 911 | static const CostTblEntry<MVT::SimpleValueType> AVX1CostTblPairWise[] = { |
| 912 | { ISD::FADD, MVT::v4f32, 4 }, |
| 913 | { ISD::FADD, MVT::v4f64, 5 }, |
| 914 | { ISD::FADD, MVT::v8f32, 7 }, |
| 915 | { ISD::ADD, MVT::v2i64, 1 }, // The data reported by the IACA tool is "1.5". |
| 916 | { ISD::ADD, MVT::v4i32, 3 }, // The data reported by the IACA tool is "3.5". |
| 917 | { ISD::ADD, MVT::v4i64, 5 }, // The data reported by the IACA tool is "4.8". |
| 918 | { ISD::ADD, MVT::v8i16, 5 }, |
| 919 | { ISD::ADD, MVT::v8i32, 5 }, |
| 920 | }; |
| 921 | |
| 922 | static const CostTblEntry<MVT::SimpleValueType> SSE42CostTblNoPairWise[] = { |
| 923 | { ISD::FADD, MVT::v2f64, 2 }, |
| 924 | { ISD::FADD, MVT::v4f32, 4 }, |
| 925 | { ISD::ADD, MVT::v2i64, 2 }, // The data reported by the IACA tool is "1.6". |
| 926 | { ISD::ADD, MVT::v4i32, 3 }, // The data reported by the IACA tool is "3.3". |
| 927 | { ISD::ADD, MVT::v8i16, 4 }, // The data reported by the IACA tool is "4.3". |
| 928 | }; |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 929 | |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 930 | static const CostTblEntry<MVT::SimpleValueType> AVX1CostTblNoPairWise[] = { |
| 931 | { ISD::FADD, MVT::v4f32, 3 }, |
| 932 | { ISD::FADD, MVT::v4f64, 3 }, |
| 933 | { ISD::FADD, MVT::v8f32, 4 }, |
| 934 | { ISD::ADD, MVT::v2i64, 1 }, // The data reported by the IACA tool is "1.5". |
| 935 | { ISD::ADD, MVT::v4i32, 3 }, // The data reported by the IACA tool is "2.8". |
| 936 | { ISD::ADD, MVT::v4i64, 3 }, |
| 937 | { ISD::ADD, MVT::v8i16, 4 }, |
| 938 | { ISD::ADD, MVT::v8i32, 5 }, |
| 939 | }; |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 940 | |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 941 | if (IsPairwise) { |
| 942 | if (ST->hasAVX()) { |
| 943 | int Idx = CostTableLookup(AVX1CostTblPairWise, ISD, MTy); |
| 944 | if (Idx != -1) |
| 945 | return LT.first * AVX1CostTblPairWise[Idx].Cost; |
| 946 | } |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 947 | |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 948 | if (ST->hasSSE42()) { |
| 949 | int Idx = CostTableLookup(SSE42CostTblPairWise, ISD, MTy); |
| 950 | if (Idx != -1) |
| 951 | return LT.first * SSE42CostTblPairWise[Idx].Cost; |
| 952 | } |
| 953 | } else { |
| 954 | if (ST->hasAVX()) { |
| 955 | int Idx = CostTableLookup(AVX1CostTblNoPairWise, ISD, MTy); |
| 956 | if (Idx != -1) |
| 957 | return LT.first * AVX1CostTblNoPairWise[Idx].Cost; |
| 958 | } |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 959 | |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 960 | if (ST->hasSSE42()) { |
| 961 | int Idx = CostTableLookup(SSE42CostTblNoPairWise, ISD, MTy); |
| 962 | if (Idx != -1) |
| 963 | return LT.first * SSE42CostTblNoPairWise[Idx].Cost; |
| 964 | } |
| 965 | } |
| 966 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 967 | return BaseT::getReductionCost(Opcode, ValTy, IsPairwise); |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 968 | } |
| 969 | |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 970 | /// \brief Calculate the cost of materializing a 64-bit value. This helper |
| 971 | /// method might only calculate a fraction of a larger immediate. Therefore it |
| 972 | /// is valid to return a cost of ZERO. |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 973 | unsigned X86TTIImpl::getIntImmCost(int64_t Val) { |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 974 | if (Val == 0) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 975 | return TTI::TCC_Free; |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 976 | |
| 977 | if (isInt<32>(Val)) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 978 | return TTI::TCC_Basic; |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 979 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 980 | return 2 * TTI::TCC_Basic; |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 981 | } |
| 982 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 983 | unsigned X86TTIImpl::getIntImmCost(const APInt &Imm, Type *Ty) { |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 984 | assert(Ty->isIntegerTy()); |
| 985 | |
| 986 | unsigned BitSize = Ty->getPrimitiveSizeInBits(); |
| 987 | if (BitSize == 0) |
| 988 | return ~0U; |
| 989 | |
Juergen Ributzka | 4317617 | 2014-05-19 21:00:53 +0000 | [diff] [blame] | 990 | // Never hoist constants larger than 128bit, because this might lead to |
| 991 | // incorrect code generation or assertions in codegen. |
| 992 | // Fixme: Create a cost model for types larger than i128 once the codegen |
| 993 | // issues have been fixed. |
| 994 | if (BitSize > 128) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 995 | return TTI::TCC_Free; |
Juergen Ributzka | 4317617 | 2014-05-19 21:00:53 +0000 | [diff] [blame] | 996 | |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 997 | if (Imm == 0) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 998 | return TTI::TCC_Free; |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 999 | |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 1000 | // Sign-extend all constants to a multiple of 64-bit. |
| 1001 | APInt ImmVal = Imm; |
| 1002 | if (BitSize & 0x3f) |
| 1003 | ImmVal = Imm.sext((BitSize + 63) & ~0x3fU); |
| 1004 | |
| 1005 | // Split the constant into 64-bit chunks and calculate the cost for each |
| 1006 | // chunk. |
| 1007 | unsigned Cost = 0; |
| 1008 | for (unsigned ShiftVal = 0; ShiftVal < BitSize; ShiftVal += 64) { |
| 1009 | APInt Tmp = ImmVal.ashr(ShiftVal).sextOrTrunc(64); |
| 1010 | int64_t Val = Tmp.getSExtValue(); |
| 1011 | Cost += getIntImmCost(Val); |
| 1012 | } |
| 1013 | // We need at least one instruction to materialze the constant. |
| 1014 | return std::max(1U, Cost); |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1017 | unsigned X86TTIImpl::getIntImmCost(unsigned Opcode, unsigned Idx, |
| 1018 | const APInt &Imm, Type *Ty) { |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1019 | assert(Ty->isIntegerTy()); |
| 1020 | |
| 1021 | unsigned BitSize = Ty->getPrimitiveSizeInBits(); |
Juergen Ributzka | 4317617 | 2014-05-19 21:00:53 +0000 | [diff] [blame] | 1022 | // There is no cost model for constants with a bit size of 0. Return TCC_Free |
| 1023 | // here, so that constant hoisting will ignore this constant. |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1024 | if (BitSize == 0) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1025 | return TTI::TCC_Free; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1026 | |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1027 | unsigned ImmIdx = ~0U; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1028 | switch (Opcode) { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1029 | default: |
| 1030 | return TTI::TCC_Free; |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1031 | case Instruction::GetElementPtr: |
Juergen Ributzka | 27435b3 | 2014-04-02 21:45:36 +0000 | [diff] [blame] | 1032 | // Always hoist the base address of a GetElementPtr. This prevents the |
| 1033 | // creation of new constants for every base constant that gets constant |
| 1034 | // folded with the offset. |
Juergen Ributzka | 631c491 | 2014-03-25 18:01:25 +0000 | [diff] [blame] | 1035 | if (Idx == 0) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1036 | return 2 * TTI::TCC_Basic; |
| 1037 | return TTI::TCC_Free; |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1038 | case Instruction::Store: |
| 1039 | ImmIdx = 0; |
| 1040 | break; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1041 | case Instruction::Add: |
| 1042 | case Instruction::Sub: |
| 1043 | case Instruction::Mul: |
| 1044 | case Instruction::UDiv: |
| 1045 | case Instruction::SDiv: |
| 1046 | case Instruction::URem: |
| 1047 | case Instruction::SRem: |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1048 | case Instruction::And: |
| 1049 | case Instruction::Or: |
| 1050 | case Instruction::Xor: |
| 1051 | case Instruction::ICmp: |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1052 | ImmIdx = 1; |
| 1053 | break; |
Michael Zolotukhin | 1f4a960 | 2014-04-30 19:17:32 +0000 | [diff] [blame] | 1054 | // Always return TCC_Free for the shift value of a shift instruction. |
| 1055 | case Instruction::Shl: |
| 1056 | case Instruction::LShr: |
| 1057 | case Instruction::AShr: |
| 1058 | if (Idx == 1) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1059 | return TTI::TCC_Free; |
Michael Zolotukhin | 1f4a960 | 2014-04-30 19:17:32 +0000 | [diff] [blame] | 1060 | break; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1061 | case Instruction::Trunc: |
| 1062 | case Instruction::ZExt: |
| 1063 | case Instruction::SExt: |
| 1064 | case Instruction::IntToPtr: |
| 1065 | case Instruction::PtrToInt: |
| 1066 | case Instruction::BitCast: |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1067 | case Instruction::PHI: |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1068 | case Instruction::Call: |
| 1069 | case Instruction::Select: |
| 1070 | case Instruction::Ret: |
| 1071 | case Instruction::Load: |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1072 | break; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1073 | } |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1074 | |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 1075 | if (Idx == ImmIdx) { |
| 1076 | unsigned NumConstants = (BitSize + 63) / 64; |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1077 | unsigned Cost = X86TTIImpl::getIntImmCost(Imm, Ty); |
| 1078 | return (Cost <= NumConstants * TTI::TCC_Basic) |
| 1079 | ? static_cast<unsigned>(TTI::TCC_Free) |
| 1080 | : Cost; |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 1081 | } |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1082 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1083 | return X86TTIImpl::getIntImmCost(Imm, Ty); |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1086 | unsigned X86TTIImpl::getIntImmCost(Intrinsic::ID IID, unsigned Idx, |
| 1087 | const APInt &Imm, Type *Ty) { |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1088 | assert(Ty->isIntegerTy()); |
| 1089 | |
| 1090 | unsigned BitSize = Ty->getPrimitiveSizeInBits(); |
Juergen Ributzka | 4317617 | 2014-05-19 21:00:53 +0000 | [diff] [blame] | 1091 | // There is no cost model for constants with a bit size of 0. Return TCC_Free |
| 1092 | // here, so that constant hoisting will ignore this constant. |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1093 | if (BitSize == 0) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1094 | return TTI::TCC_Free; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1095 | |
| 1096 | switch (IID) { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1097 | default: |
| 1098 | return TTI::TCC_Free; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1099 | case Intrinsic::sadd_with_overflow: |
| 1100 | case Intrinsic::uadd_with_overflow: |
| 1101 | case Intrinsic::ssub_with_overflow: |
| 1102 | case Intrinsic::usub_with_overflow: |
| 1103 | case Intrinsic::smul_with_overflow: |
| 1104 | case Intrinsic::umul_with_overflow: |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1105 | if ((Idx == 1) && Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue())) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1106 | return TTI::TCC_Free; |
Juergen Ributzka | 5eef98c | 2014-03-25 18:01:23 +0000 | [diff] [blame] | 1107 | break; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1108 | case Intrinsic::experimental_stackmap: |
Juergen Ributzka | 5eef98c | 2014-03-25 18:01:23 +0000 | [diff] [blame] | 1109 | if ((Idx < 2) || (Imm.getBitWidth() <= 64 && isInt<64>(Imm.getSExtValue()))) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1110 | return TTI::TCC_Free; |
Juergen Ributzka | 5eef98c | 2014-03-25 18:01:23 +0000 | [diff] [blame] | 1111 | break; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1112 | case Intrinsic::experimental_patchpoint_void: |
| 1113 | case Intrinsic::experimental_patchpoint_i64: |
Juergen Ributzka | 5eef98c | 2014-03-25 18:01:23 +0000 | [diff] [blame] | 1114 | if ((Idx < 4) || (Imm.getBitWidth() <= 64 && isInt<64>(Imm.getSExtValue()))) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1115 | return TTI::TCC_Free; |
Juergen Ributzka | 5eef98c | 2014-03-25 18:01:23 +0000 | [diff] [blame] | 1116 | break; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1117 | } |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1118 | return X86TTIImpl::getIntImmCost(Imm, Ty); |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1119 | } |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 1120 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1121 | bool X86TTIImpl::isLegalMaskedLoad(Type *DataTy, int Consecutive) { |
Elena Demikhovsky | fb81b93 | 2014-12-25 07:49:20 +0000 | [diff] [blame] | 1122 | int DataWidth = DataTy->getPrimitiveSizeInBits(); |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 1123 | |
| 1124 | // Todo: AVX512 allows gather/scatter, works with strided and random as well |
Elena Demikhovsky | fb81b93 | 2014-12-25 07:49:20 +0000 | [diff] [blame] | 1125 | if ((DataWidth < 32) || (Consecutive == 0)) |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 1126 | return false; |
| 1127 | if (ST->hasAVX512() || ST->hasAVX2()) |
| 1128 | return true; |
| 1129 | return false; |
| 1130 | } |
| 1131 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1132 | bool X86TTIImpl::isLegalMaskedStore(Type *DataType, int Consecutive) { |
Elena Demikhovsky | 3fcafa2 | 2014-12-14 09:43:50 +0000 | [diff] [blame] | 1133 | return isLegalMaskedLoad(DataType, Consecutive); |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
Eric Christopher | e100226 | 2015-07-02 01:11:50 +0000 | [diff] [blame] | 1136 | bool X86TTIImpl::hasCompatibleFunctionAttributes(const Function *Caller, |
| 1137 | const Function *Callee) const { |
| 1138 | const TargetMachine &TM = getTLI()->getTargetMachine(); |
| 1139 | |
| 1140 | // Work this as a subsetting of subtarget features. |
| 1141 | const FeatureBitset &CallerBits = |
| 1142 | TM.getSubtargetImpl(*Caller)->getFeatureBits(); |
| 1143 | const FeatureBitset &CalleeBits = |
| 1144 | TM.getSubtargetImpl(*Callee)->getFeatureBits(); |
| 1145 | |
| 1146 | // FIXME: This is likely too limiting as it will include subtarget features |
| 1147 | // that we might not care about for inlining, but it is conservatively |
| 1148 | // correct. |
| 1149 | return (CallerBits & CalleeBits) == CalleeBits; |
| 1150 | } |