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 | //===----------------------------------------------------------------------===// |
Alexey Bataev | b271a58 | 2016-10-12 13:24:13 +0000 | [diff] [blame] | 16 | /// About Cost Model numbers used below it's necessary to say the following: |
| 17 | /// the numbers correspond to some "generic" X86 CPU instead of usage of |
| 18 | /// concrete CPU model. Usually the numbers correspond to CPU where the feature |
| 19 | /// apeared at the first time. For example, if we do Subtarget.hasSSE42() in |
| 20 | /// the lookups below the cost is based on Nehalem as that was the first CPU |
| 21 | /// to support that feature level and thus has most likely the worst case cost. |
| 22 | /// Some examples of other technologies/CPUs: |
| 23 | /// SSE 3 - Pentium4 / Athlon64 |
| 24 | /// SSE 4.1 - Penryn |
| 25 | /// SSE 4.2 - Nehalem |
| 26 | /// AVX - Sandy Bridge |
| 27 | /// AVX2 - Haswell |
| 28 | /// AVX-512 - Xeon Phi / Skylake |
| 29 | /// And some examples of instruction target dependent costs (latency) |
| 30 | /// divss sqrtss rsqrtss |
| 31 | /// AMD K7 11-16 19 3 |
| 32 | /// Piledriver 9-24 13-15 5 |
| 33 | /// Jaguar 14 16 2 |
| 34 | /// Pentium II,III 18 30 2 |
| 35 | /// Nehalem 7-14 7-18 3 |
| 36 | /// Haswell 10-13 11 5 |
| 37 | /// TODO: Develop and implement the target dependent cost model and |
| 38 | /// specialize cost numbers for different Cost Model Targets such as throughput, |
| 39 | /// code size, latency and uop count. |
| 40 | //===----------------------------------------------------------------------===// |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 41 | |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 42 | #include "X86TargetTransformInfo.h" |
Chandler Carruth | d3e7355 | 2013-01-07 03:08:10 +0000 | [diff] [blame] | 43 | #include "llvm/Analysis/TargetTransformInfo.h" |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 44 | #include "llvm/CodeGen/BasicTTIImpl.h" |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 45 | #include "llvm/IR/IntrinsicInst.h" |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 46 | #include "llvm/Support/Debug.h" |
Renato Golin | d4c392e | 2013-01-24 23:01:00 +0000 | [diff] [blame] | 47 | #include "llvm/Target/CostTable.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 48 | #include "llvm/Target/TargetLowering.h" |
Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 49 | |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 50 | using namespace llvm; |
| 51 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 52 | #define DEBUG_TYPE "x86tti" |
| 53 | |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 54 | //===----------------------------------------------------------------------===// |
| 55 | // |
| 56 | // X86 cost model. |
| 57 | // |
| 58 | //===----------------------------------------------------------------------===// |
| 59 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 60 | TargetTransformInfo::PopcntSupportKind |
| 61 | X86TTIImpl::getPopcntSupport(unsigned TyWidth) { |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 62 | assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2"); |
| 63 | // TODO: Currently the __builtin_popcount() implementation using SSE3 |
| 64 | // instructions is inefficient. Once the problem is fixed, we should |
Craig Topper | 0a63e1d | 2013-09-08 00:47:31 +0000 | [diff] [blame] | 65 | // call ST->hasSSE3() instead of ST->hasPOPCNT(). |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 66 | return ST->hasPOPCNT() ? TTI::PSK_FastHardware : TTI::PSK_Software; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 69 | unsigned X86TTIImpl::getNumberOfRegisters(bool Vector) { |
Nadav Rotem | b1791a7 | 2013-01-09 22:29:00 +0000 | [diff] [blame] | 70 | if (Vector && !ST->hasSSE1()) |
| 71 | return 0; |
| 72 | |
Adam Nemet | 2820a5b | 2014-07-09 18:22:33 +0000 | [diff] [blame] | 73 | if (ST->is64Bit()) { |
| 74 | if (Vector && ST->hasAVX512()) |
| 75 | return 32; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 76 | return 16; |
Adam Nemet | 2820a5b | 2014-07-09 18:22:33 +0000 | [diff] [blame] | 77 | } |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 78 | return 8; |
| 79 | } |
| 80 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 81 | unsigned X86TTIImpl::getRegisterBitWidth(bool Vector) { |
Nadav Rotem | b1791a7 | 2013-01-09 22:29:00 +0000 | [diff] [blame] | 82 | if (Vector) { |
Adam Nemet | 2820a5b | 2014-07-09 18:22:33 +0000 | [diff] [blame] | 83 | if (ST->hasAVX512()) return 512; |
Nadav Rotem | b1791a7 | 2013-01-09 22:29:00 +0000 | [diff] [blame] | 84 | if (ST->hasAVX()) return 256; |
| 85 | if (ST->hasSSE1()) return 128; |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | if (ST->is64Bit()) |
| 90 | return 64; |
Nadav Rotem | b1791a7 | 2013-01-09 22:29:00 +0000 | [diff] [blame] | 91 | |
Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 92 | return 32; |
Nadav Rotem | b1791a7 | 2013-01-09 22:29:00 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Wei Mi | 062c744 | 2015-05-06 17:12:25 +0000 | [diff] [blame] | 95 | unsigned X86TTIImpl::getMaxInterleaveFactor(unsigned VF) { |
| 96 | // If the loop will not be vectorized, don't interleave the loop. |
| 97 | // Let regular unroll to unroll the loop, which saves the overflow |
| 98 | // check and memory check cost. |
| 99 | if (VF == 1) |
| 100 | return 1; |
| 101 | |
Nadav Rotem | b696c36 | 2013-01-09 01:15:42 +0000 | [diff] [blame] | 102 | if (ST->isAtom()) |
| 103 | return 1; |
| 104 | |
| 105 | // Sandybridge and Haswell have multiple execution ports and pipelined |
| 106 | // vector units. |
| 107 | if (ST->hasAVX()) |
| 108 | return 4; |
| 109 | |
| 110 | return 2; |
| 111 | } |
| 112 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 113 | int X86TTIImpl::getArithmeticInstrCost( |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 114 | unsigned Opcode, Type *Ty, TTI::OperandValueKind Op1Info, |
| 115 | TTI::OperandValueKind Op2Info, TTI::OperandValueProperties Opd1PropInfo, |
| 116 | TTI::OperandValueProperties Opd2PropInfo) { |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 117 | // Legalize the type. |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 118 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Ty); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 119 | |
| 120 | int ISD = TLI->InstructionOpcodeToISD(Opcode); |
| 121 | assert(ISD && "Invalid opcode"); |
| 122 | |
Karthik Bhat | 7f33ff7 | 2014-08-25 04:56:54 +0000 | [diff] [blame] | 123 | if (ISD == ISD::SDIV && |
| 124 | Op2Info == TargetTransformInfo::OK_UniformConstantValue && |
| 125 | Opd2PropInfo == TargetTransformInfo::OP_PowerOf2) { |
| 126 | // On X86, vector signed division by constants power-of-two are |
| 127 | // normally expanded to the sequence SRA + SRL + ADD + SRA. |
| 128 | // The OperandValue properties many not be same as that of previous |
| 129 | // operation;conservatively assume OP_None. |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 130 | int Cost = 2 * getArithmeticInstrCost(Instruction::AShr, Ty, Op1Info, |
| 131 | Op2Info, TargetTransformInfo::OP_None, |
| 132 | TargetTransformInfo::OP_None); |
Karthik Bhat | 7f33ff7 | 2014-08-25 04:56:54 +0000 | [diff] [blame] | 133 | Cost += getArithmeticInstrCost(Instruction::LShr, Ty, Op1Info, Op2Info, |
| 134 | TargetTransformInfo::OP_None, |
| 135 | TargetTransformInfo::OP_None); |
| 136 | Cost += getArithmeticInstrCost(Instruction::Add, Ty, Op1Info, Op2Info, |
| 137 | TargetTransformInfo::OP_None, |
| 138 | TargetTransformInfo::OP_None); |
| 139 | |
| 140 | return Cost; |
| 141 | } |
| 142 | |
Simon Pilgrim | 365be4f | 2016-10-20 18:00:35 +0000 | [diff] [blame] | 143 | static const CostTblEntry AVX512BWUniformConstCostTable[] = { |
| 144 | { ISD::SDIV, MVT::v32i16, 6 }, // vpmulhw sequence |
| 145 | { ISD::UDIV, MVT::v32i16, 6 }, // vpmulhuw sequence |
| 146 | }; |
| 147 | |
| 148 | if (Op2Info == TargetTransformInfo::OK_UniformConstantValue && |
| 149 | ST->hasBWI()) { |
| 150 | if (const auto *Entry = CostTableLookup(AVX512BWUniformConstCostTable, ISD, |
| 151 | LT.second)) |
| 152 | return LT.first * Entry->Cost; |
| 153 | } |
| 154 | |
| 155 | static const CostTblEntry AVX512UniformConstCostTable[] = { |
| 156 | { ISD::SDIV, MVT::v16i32, 15 }, // vpmuldq sequence |
| 157 | { ISD::UDIV, MVT::v16i32, 15 }, // vpmuludq sequence |
| 158 | }; |
| 159 | |
| 160 | if (Op2Info == TargetTransformInfo::OK_UniformConstantValue && |
| 161 | ST->hasAVX512()) { |
| 162 | if (const auto *Entry = CostTableLookup(AVX512UniformConstCostTable, ISD, |
| 163 | LT.second)) |
| 164 | return LT.first * Entry->Cost; |
| 165 | } |
| 166 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 167 | static const CostTblEntry AVX2UniformConstCostTable[] = { |
Simon Pilgrim | 8fbf1c1 | 2015-07-06 22:35:19 +0000 | [diff] [blame] | 168 | { ISD::SRA, MVT::v4i64, 4 }, // 2 x psrad + shuffle. |
| 169 | |
Benjamin Kramer | 7c37227 | 2014-04-26 14:53:05 +0000 | [diff] [blame] | 170 | { ISD::SDIV, MVT::v16i16, 6 }, // vpmulhw sequence |
| 171 | { ISD::UDIV, MVT::v16i16, 6 }, // vpmulhuw sequence |
| 172 | { ISD::SDIV, MVT::v8i32, 15 }, // vpmuldq sequence |
| 173 | { ISD::UDIV, MVT::v8i32, 15 }, // vpmuludq sequence |
| 174 | }; |
| 175 | |
| 176 | if (Op2Info == TargetTransformInfo::OK_UniformConstantValue && |
| 177 | ST->hasAVX2()) { |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 178 | if (const auto *Entry = CostTableLookup(AVX2UniformConstCostTable, ISD, |
| 179 | LT.second)) |
| 180 | return LT.first * Entry->Cost; |
Benjamin Kramer | 7c37227 | 2014-04-26 14:53:05 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Simon Pilgrim | 365be4f | 2016-10-20 18:00:35 +0000 | [diff] [blame] | 183 | static const CostTblEntry SSE2UniformConstCostTable[] = { |
| 184 | { ISD::SDIV, MVT::v16i16, 12 }, // pmulhw sequence |
| 185 | { ISD::SDIV, MVT::v8i16, 6 }, // pmulhw sequence |
| 186 | { ISD::UDIV, MVT::v16i16, 12 }, // pmulhuw sequence |
| 187 | { ISD::UDIV, MVT::v8i16, 6 }, // pmulhuw sequence |
| 188 | { ISD::SDIV, MVT::v8i32, 38 }, // pmuludq sequence |
| 189 | { ISD::SDIV, MVT::v4i32, 19 }, // pmuludq sequence |
| 190 | { ISD::UDIV, MVT::v8i32, 30 }, // pmuludq sequence |
| 191 | { ISD::UDIV, MVT::v4i32, 15 }, // pmuludq sequence |
| 192 | }; |
| 193 | |
| 194 | if (Op2Info == TargetTransformInfo::OK_UniformConstantValue && |
| 195 | ST->hasSSE2()) { |
| 196 | // pmuldq sequence. |
| 197 | if (ISD == ISD::SDIV && LT.second == MVT::v8i32 && ST->hasAVX()) |
| 198 | return LT.first * 30; |
| 199 | if (ISD == ISD::SDIV && LT.second == MVT::v4i32 && ST->hasSSE41()) |
| 200 | return LT.first * 15; |
| 201 | |
| 202 | if (const auto *Entry = CostTableLookup(SSE2UniformConstCostTable, ISD, |
| 203 | LT.second)) |
| 204 | return LT.first * Entry->Cost; |
| 205 | } |
| 206 | |
Simon Pilgrim | 025e26d | 2016-10-20 16:39:11 +0000 | [diff] [blame] | 207 | static const CostTblEntry AVX512BWCostTable[] = { |
| 208 | // Vectorizing division is a bad idea. See the SSE2 table for more comments. |
| 209 | { ISD::SDIV, MVT::v64i8, 64*20 }, |
| 210 | { ISD::SDIV, MVT::v32i16, 32*20 }, |
| 211 | { ISD::SDIV, MVT::v16i32, 16*20 }, |
| 212 | { ISD::SDIV, MVT::v8i64, 8*20 }, |
| 213 | { ISD::UDIV, MVT::v64i8, 64*20 }, |
| 214 | { ISD::UDIV, MVT::v32i16, 32*20 }, |
| 215 | { ISD::UDIV, MVT::v16i32, 16*20 }, |
| 216 | { ISD::UDIV, MVT::v8i64, 8*20 }, |
| 217 | }; |
| 218 | |
| 219 | // Look for AVX512BW lowering tricks for custom cases. |
| 220 | if (ST->hasBWI()) { |
| 221 | if (const auto *Entry = CostTableLookup(AVX512BWCostTable, ISD, |
| 222 | LT.second)) |
| 223 | return LT.first * Entry->Cost; |
| 224 | } |
| 225 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 226 | static const CostTblEntry AVX512CostTable[] = { |
Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 227 | { ISD::SHL, MVT::v16i32, 1 }, |
| 228 | { ISD::SRL, MVT::v16i32, 1 }, |
| 229 | { ISD::SRA, MVT::v16i32, 1 }, |
| 230 | { ISD::SHL, MVT::v8i64, 1 }, |
| 231 | { ISD::SRL, MVT::v8i64, 1 }, |
| 232 | { ISD::SRA, MVT::v8i64, 1 }, |
| 233 | }; |
| 234 | |
Simon Pilgrim | 3d11c99 | 2015-09-30 08:17:50 +0000 | [diff] [blame] | 235 | if (ST->hasAVX512()) { |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 236 | if (const auto *Entry = CostTableLookup(AVX512CostTable, ISD, LT.second)) |
| 237 | return LT.first * Entry->Cost; |
Simon Pilgrim | 3d11c99 | 2015-09-30 08:17:50 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 240 | static const CostTblEntry AVX2CostTable[] = { |
Michael Liao | 70dd7f9 | 2013-03-20 22:01:10 +0000 | [diff] [blame] | 241 | // Shifts on v4i64/v8i32 on AVX2 is legal even though we declare to |
| 242 | // customize them to detect the cases where shift amount is a scalar one. |
| 243 | { ISD::SHL, MVT::v4i32, 1 }, |
| 244 | { ISD::SRL, MVT::v4i32, 1 }, |
| 245 | { ISD::SRA, MVT::v4i32, 1 }, |
| 246 | { ISD::SHL, MVT::v8i32, 1 }, |
| 247 | { ISD::SRL, MVT::v8i32, 1 }, |
| 248 | { ISD::SRA, MVT::v8i32, 1 }, |
| 249 | { ISD::SHL, MVT::v2i64, 1 }, |
| 250 | { ISD::SRL, MVT::v2i64, 1 }, |
| 251 | { ISD::SHL, MVT::v4i64, 1 }, |
| 252 | { ISD::SRL, MVT::v4i64, 1 }, |
Simon Pilgrim | 3d11c99 | 2015-09-30 08:17:50 +0000 | [diff] [blame] | 253 | }; |
Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 254 | |
Simon Pilgrim | 3d11c99 | 2015-09-30 08:17:50 +0000 | [diff] [blame] | 255 | // Look for AVX2 lowering tricks. |
| 256 | if (ST->hasAVX2()) { |
| 257 | if (ISD == ISD::SHL && LT.second == MVT::v16i16 && |
| 258 | (Op2Info == TargetTransformInfo::OK_UniformConstantValue || |
| 259 | Op2Info == TargetTransformInfo::OK_NonUniformConstantValue)) |
| 260 | // On AVX2, a packed v16i16 shift left by a constant build_vector |
| 261 | // is lowered into a vector multiply (vpmullw). |
| 262 | return LT.first; |
| 263 | |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 264 | if (const auto *Entry = CostTableLookup(AVX2CostTable, ISD, LT.second)) |
| 265 | return LT.first * Entry->Cost; |
Simon Pilgrim | 3d11c99 | 2015-09-30 08:17:50 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 268 | static const CostTblEntry XOPCostTable[] = { |
Simon Pilgrim | 3d11c99 | 2015-09-30 08:17:50 +0000 | [diff] [blame] | 269 | // 128bit shifts take 1cy, but right shifts require negation beforehand. |
| 270 | { ISD::SHL, MVT::v16i8, 1 }, |
| 271 | { ISD::SRL, MVT::v16i8, 2 }, |
| 272 | { ISD::SRA, MVT::v16i8, 2 }, |
| 273 | { ISD::SHL, MVT::v8i16, 1 }, |
| 274 | { ISD::SRL, MVT::v8i16, 2 }, |
| 275 | { ISD::SRA, MVT::v8i16, 2 }, |
| 276 | { ISD::SHL, MVT::v4i32, 1 }, |
| 277 | { ISD::SRL, MVT::v4i32, 2 }, |
| 278 | { ISD::SRA, MVT::v4i32, 2 }, |
| 279 | { ISD::SHL, MVT::v2i64, 1 }, |
| 280 | { ISD::SRL, MVT::v2i64, 2 }, |
| 281 | { ISD::SRA, MVT::v2i64, 2 }, |
| 282 | // 256bit shifts require splitting if AVX2 didn't catch them above. |
| 283 | { ISD::SHL, MVT::v32i8, 2 }, |
| 284 | { ISD::SRL, MVT::v32i8, 4 }, |
| 285 | { ISD::SRA, MVT::v32i8, 4 }, |
| 286 | { ISD::SHL, MVT::v16i16, 2 }, |
| 287 | { ISD::SRL, MVT::v16i16, 4 }, |
| 288 | { ISD::SRA, MVT::v16i16, 4 }, |
| 289 | { ISD::SHL, MVT::v8i32, 2 }, |
| 290 | { ISD::SRL, MVT::v8i32, 4 }, |
| 291 | { ISD::SRA, MVT::v8i32, 4 }, |
| 292 | { ISD::SHL, MVT::v4i64, 2 }, |
| 293 | { ISD::SRL, MVT::v4i64, 4 }, |
| 294 | { ISD::SRA, MVT::v4i64, 4 }, |
| 295 | }; |
| 296 | |
| 297 | // Look for XOP lowering tricks. |
| 298 | if (ST->hasXOP()) { |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 299 | if (const auto *Entry = CostTableLookup(XOPCostTable, ISD, LT.second)) |
| 300 | return LT.first * Entry->Cost; |
Simon Pilgrim | 3d11c99 | 2015-09-30 08:17:50 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 303 | static const CostTblEntry AVX2CustomCostTable[] = { |
Simon Pilgrim | 5965680 | 2015-06-11 07:46:37 +0000 | [diff] [blame] | 304 | { ISD::SHL, MVT::v32i8, 11 }, // vpblendvb sequence. |
Simon Pilgrim | 0be4fa7 | 2015-05-25 17:49:13 +0000 | [diff] [blame] | 305 | { ISD::SHL, MVT::v16i16, 10 }, // extend/vpsrlvd/pack sequence. |
Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 306 | |
Simon Pilgrim | 5965680 | 2015-06-11 07:46:37 +0000 | [diff] [blame] | 307 | { ISD::SRL, MVT::v32i8, 11 }, // vpblendvb sequence. |
Simon Pilgrim | 0be4fa7 | 2015-05-25 17:49:13 +0000 | [diff] [blame] | 308 | { ISD::SRL, MVT::v16i16, 10 }, // extend/vpsrlvd/pack sequence. |
Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 309 | |
Simon Pilgrim | 5965680 | 2015-06-11 07:46:37 +0000 | [diff] [blame] | 310 | { ISD::SRA, MVT::v32i8, 24 }, // vpblendvb sequence. |
Simon Pilgrim | 0be4fa7 | 2015-05-25 17:49:13 +0000 | [diff] [blame] | 311 | { ISD::SRA, MVT::v16i16, 10 }, // extend/vpsravd/pack sequence. |
Simon Pilgrim | 86478c6 | 2015-07-29 20:31:45 +0000 | [diff] [blame] | 312 | { ISD::SRA, MVT::v2i64, 4 }, // srl/xor/sub sequence. |
| 313 | { ISD::SRA, MVT::v4i64, 4 }, // srl/xor/sub sequence. |
Simon Pilgrim | 025e26d | 2016-10-20 16:39:11 +0000 | [diff] [blame] | 314 | }; |
Arnold Schwaighofer | a04b9ef | 2013-06-25 19:14:09 +0000 | [diff] [blame] | 315 | |
Simon Pilgrim | 025e26d | 2016-10-20 16:39:11 +0000 | [diff] [blame] | 316 | // Look for AVX2 lowering tricks for custom cases. |
| 317 | if (ST->hasAVX2()) { |
| 318 | if (const auto *Entry = CostTableLookup(AVX2CustomCostTable, ISD, |
| 319 | LT.second)) |
| 320 | return LT.first * Entry->Cost; |
| 321 | } |
| 322 | |
| 323 | static const CostTblEntry AVXCustomCostTable[] = { |
Arnold Schwaighofer | a04b9ef | 2013-06-25 19:14:09 +0000 | [diff] [blame] | 324 | // Vectorizing division is a bad idea. See the SSE2 table for more comments. |
| 325 | { ISD::SDIV, MVT::v32i8, 32*20 }, |
| 326 | { ISD::SDIV, MVT::v16i16, 16*20 }, |
| 327 | { ISD::SDIV, MVT::v8i32, 8*20 }, |
| 328 | { ISD::SDIV, MVT::v4i64, 4*20 }, |
| 329 | { ISD::UDIV, MVT::v32i8, 32*20 }, |
| 330 | { ISD::UDIV, MVT::v16i16, 16*20 }, |
| 331 | { ISD::UDIV, MVT::v8i32, 8*20 }, |
| 332 | { ISD::UDIV, MVT::v4i64, 4*20 }, |
Michael Liao | 70dd7f9 | 2013-03-20 22:01:10 +0000 | [diff] [blame] | 333 | }; |
| 334 | |
Simon Pilgrim | 3d11c99 | 2015-09-30 08:17:50 +0000 | [diff] [blame] | 335 | // Look for AVX2 lowering tricks for custom cases. |
Simon Pilgrim | 025e26d | 2016-10-20 16:39:11 +0000 | [diff] [blame] | 336 | if (ST->hasAVX()) { |
| 337 | if (const auto *Entry = CostTableLookup(AVXCustomCostTable, ISD, |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 338 | LT.second)) |
| 339 | return LT.first * Entry->Cost; |
Michael Liao | 70dd7f9 | 2013-03-20 22:01:10 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 342 | static const CostTblEntry |
Michael Kuperstein | 3ceac2b | 2016-08-04 22:48:03 +0000 | [diff] [blame] | 343 | SSE2UniformCostTable[] = { |
| 344 | // Uniform splats are cheaper for the following instructions. |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 345 | { ISD::SHL, MVT::v16i8, 1 }, // psllw. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 346 | { ISD::SHL, MVT::v32i8, 2 }, // psllw. |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 347 | { ISD::SHL, MVT::v8i16, 1 }, // psllw. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 348 | { ISD::SHL, MVT::v16i16, 2 }, // psllw. |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 349 | { ISD::SHL, MVT::v4i32, 1 }, // pslld |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 350 | { ISD::SHL, MVT::v8i32, 2 }, // pslld |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 351 | { ISD::SHL, MVT::v2i64, 1 }, // psllq. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 352 | { ISD::SHL, MVT::v4i64, 2 }, // psllq. |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 353 | |
| 354 | { ISD::SRL, MVT::v16i8, 1 }, // psrlw. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 355 | { ISD::SRL, MVT::v32i8, 2 }, // psrlw. |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 356 | { ISD::SRL, MVT::v8i16, 1 }, // psrlw. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 357 | { ISD::SRL, MVT::v16i16, 2 }, // psrlw. |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 358 | { ISD::SRL, MVT::v4i32, 1 }, // psrld. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 359 | { ISD::SRL, MVT::v8i32, 2 }, // psrld. |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 360 | { ISD::SRL, MVT::v2i64, 1 }, // psrlq. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 361 | { ISD::SRL, MVT::v4i64, 2 }, // psrlq. |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 362 | |
| 363 | { ISD::SRA, MVT::v16i8, 4 }, // psrlw, pand, pxor, psubb. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 364 | { ISD::SRA, MVT::v32i8, 8 }, // psrlw, pand, pxor, psubb. |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 365 | { ISD::SRA, MVT::v8i16, 1 }, // psraw. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 366 | { ISD::SRA, MVT::v16i16, 2 }, // psraw. |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 367 | { ISD::SRA, MVT::v4i32, 1 }, // psrad. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 368 | { ISD::SRA, MVT::v8i32, 2 }, // psrad. |
Simon Pilgrim | 8fbf1c1 | 2015-07-06 22:35:19 +0000 | [diff] [blame] | 369 | { ISD::SRA, MVT::v2i64, 4 }, // 2 x psrad + shuffle. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 370 | { ISD::SRA, MVT::v4i64, 8 }, // 2 x psrad + shuffle. |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 371 | }; |
| 372 | |
Michael Kuperstein | 3ceac2b | 2016-08-04 22:48:03 +0000 | [diff] [blame] | 373 | if (ST->hasSSE2() && |
| 374 | ((Op2Info == TargetTransformInfo::OK_UniformConstantValue) || |
| 375 | (Op2Info == TargetTransformInfo::OK_UniformValue))) { |
Michael Kuperstein | 3ceac2b | 2016-08-04 22:48:03 +0000 | [diff] [blame] | 376 | if (const auto *Entry = |
| 377 | CostTableLookup(SSE2UniformCostTable, ISD, LT.second)) |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 378 | return LT.first * Entry->Cost; |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Andrea Di Biagio | b7882b3 | 2014-02-12 23:43:47 +0000 | [diff] [blame] | 381 | if (ISD == ISD::SHL && |
| 382 | Op2Info == TargetTransformInfo::OK_NonUniformConstantValue) { |
Craig Topper | eda02a9 | 2015-10-25 03:15:29 +0000 | [diff] [blame] | 383 | MVT VT = LT.second; |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 384 | // Vector shift left by non uniform constant can be lowered |
| 385 | // into vector multiply (pmullw/pmulld). |
Andrea Di Biagio | b7882b3 | 2014-02-12 23:43:47 +0000 | [diff] [blame] | 386 | if ((VT == MVT::v8i16 && ST->hasSSE2()) || |
| 387 | (VT == MVT::v4i32 && ST->hasSSE41())) |
Andrea Di Biagio | b7882b3 | 2014-02-12 23:43:47 +0000 | [diff] [blame] | 388 | return LT.first; |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 389 | |
| 390 | // v16i16 and v8i32 shifts by non-uniform constants are lowered into a |
| 391 | // sequence of extract + two vector multiply + insert. |
| 392 | if ((VT == MVT::v8i32 || VT == MVT::v16i16) && |
| 393 | (ST->hasAVX() && !ST->hasAVX2())) |
| 394 | ISD = ISD::MUL; |
| 395 | |
| 396 | // A vector shift left by non uniform constant is converted |
| 397 | // into a vector multiply; the new multiply is eventually |
| 398 | // lowered into a sequence of shuffles and 2 x pmuludq. |
Andrea Di Biagio | b7882b3 | 2014-02-12 23:43:47 +0000 | [diff] [blame] | 399 | if (VT == MVT::v4i32 && ST->hasSSE2()) |
Andrea Di Biagio | b7882b3 | 2014-02-12 23:43:47 +0000 | [diff] [blame] | 400 | ISD = ISD::MUL; |
| 401 | } |
Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 402 | |
Simon Pilgrim | 6ac1e98 | 2016-10-23 16:49:04 +0000 | [diff] [blame^] | 403 | static const CostTblEntry SSE41CostTable[] = { |
| 404 | { ISD::SHL, MVT::v16i8, 11 }, // pblendvb sequence. |
| 405 | { ISD::SHL, MVT::v32i8, 2*11 }, // pblendvb sequence. |
| 406 | { ISD::SHL, MVT::v8i16, 14 }, // pblendvb sequence. |
| 407 | { ISD::SHL, MVT::v16i16, 2*14 }, // pblendvb sequence. |
| 408 | |
| 409 | { ISD::SRL, MVT::v16i8, 12 }, // pblendvb sequence. |
| 410 | { ISD::SRL, MVT::v32i8, 2*12 }, // pblendvb sequence. |
| 411 | { ISD::SRL, MVT::v8i16, 14 }, // pblendvb sequence. |
| 412 | { ISD::SRL, MVT::v16i16, 2*14 }, // pblendvb sequence. |
| 413 | { ISD::SRL, MVT::v4i32, 11 }, // Shift each lane + blend. |
| 414 | { ISD::SRL, MVT::v8i32, 2*11 }, // Shift each lane + blend. |
| 415 | |
| 416 | { ISD::SRA, MVT::v16i8, 24 }, // pblendvb sequence. |
| 417 | { ISD::SRA, MVT::v32i8, 2*24 }, // pblendvb sequence. |
| 418 | { ISD::SRA, MVT::v8i16, 14 }, // pblendvb sequence. |
| 419 | { ISD::SRA, MVT::v16i16, 2*14 }, // pblendvb sequence. |
| 420 | { ISD::SRA, MVT::v4i32, 12 }, // Shift each lane + blend. |
| 421 | { ISD::SRA, MVT::v8i32, 2*12 }, // Shift each lane + blend. |
| 422 | }; |
| 423 | |
| 424 | if (ST->hasSSE41()) { |
| 425 | if (const auto *Entry = CostTableLookup(SSE41CostTable, ISD, LT.second)) |
| 426 | return LT.first * Entry->Cost; |
| 427 | } |
| 428 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 429 | static const CostTblEntry SSE2CostTable[] = { |
Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 430 | // We don't correctly identify costs of casts because they are marked as |
| 431 | // custom. |
Simon Pilgrim | 5965680 | 2015-06-11 07:46:37 +0000 | [diff] [blame] | 432 | { ISD::SHL, MVT::v16i8, 26 }, // cmpgtb sequence. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 433 | { ISD::SHL, MVT::v32i8, 2*26 }, // cmpgtb sequence. |
Simon Pilgrim | 5965680 | 2015-06-11 07:46:37 +0000 | [diff] [blame] | 434 | { ISD::SHL, MVT::v8i16, 32 }, // cmpgtb sequence. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 435 | { ISD::SHL, MVT::v16i16, 2*32 }, // cmpgtb sequence. |
Simon Pilgrim | 5965680 | 2015-06-11 07:46:37 +0000 | [diff] [blame] | 436 | { ISD::SHL, MVT::v4i32, 2*5 }, // We optimized this using mul. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 437 | { ISD::SHL, MVT::v8i32, 2*2*5 }, // We optimized this using mul. |
Simon Pilgrim | 59764dc | 2015-07-18 20:06:30 +0000 | [diff] [blame] | 438 | { ISD::SHL, MVT::v2i64, 4 }, // splat+shuffle sequence. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 439 | { ISD::SHL, MVT::v4i64, 2*4 }, // splat+shuffle sequence. |
NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 440 | |
| 441 | { ISD::SRL, MVT::v16i8, 26 }, // cmpgtb sequence. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 442 | { ISD::SRL, MVT::v32i8, 2*26 }, // cmpgtb sequence. |
NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 443 | { ISD::SRL, MVT::v8i16, 32 }, // cmpgtb sequence. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 444 | { ISD::SRL, MVT::v16i16, 2*32 }, // cmpgtb sequence. |
NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 445 | { ISD::SRL, MVT::v4i32, 16 }, // Shift each lane + blend. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 446 | { ISD::SRL, MVT::v8i32, 2*16 }, // Shift each lane + blend. |
Simon Pilgrim | 59764dc | 2015-07-18 20:06:30 +0000 | [diff] [blame] | 447 | { ISD::SRL, MVT::v2i64, 4 }, // splat+shuffle sequence. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 448 | { ISD::SRL, MVT::v4i64, 2*4 }, // splat+shuffle sequence. |
NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 449 | |
| 450 | { ISD::SRA, MVT::v16i8, 54 }, // unpacked cmpgtb sequence. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 451 | { ISD::SRA, MVT::v32i8, 2*54 }, // unpacked cmpgtb sequence. |
NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 452 | { ISD::SRA, MVT::v8i16, 32 }, // cmpgtb sequence. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 453 | { ISD::SRA, MVT::v16i16, 2*32 }, // cmpgtb sequence. |
NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 454 | { ISD::SRA, MVT::v4i32, 16 }, // Shift each lane + blend. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 455 | { ISD::SRA, MVT::v8i32, 2*16 }, // Shift each lane + blend. |
Simon Pilgrim | 86478c6 | 2015-07-29 20:31:45 +0000 | [diff] [blame] | 456 | { ISD::SRA, MVT::v2i64, 12 }, // srl/xor/sub sequence. |
Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 457 | { ISD::SRA, MVT::v4i64, 2*12 }, // srl/xor/sub sequence. |
NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 458 | |
| 459 | // It is not a good idea to vectorize division. We have to scalarize it and |
Arnold Schwaighofer | a04b9ef | 2013-06-25 19:14:09 +0000 | [diff] [blame] | 460 | // in the process we will often end up having to spilling regular |
| 461 | // registers. The overhead of division is going to dominate most kernels |
| 462 | // anyways so try hard to prevent vectorization of division - it is |
| 463 | // generally a bad idea. Assume somewhat arbitrarily that we have to be able |
| 464 | // to hide "20 cycles" for each lane. |
| 465 | { ISD::SDIV, MVT::v16i8, 16*20 }, |
| 466 | { ISD::SDIV, MVT::v8i16, 8*20 }, |
| 467 | { ISD::SDIV, MVT::v4i32, 4*20 }, |
| 468 | { ISD::SDIV, MVT::v2i64, 2*20 }, |
| 469 | { ISD::UDIV, MVT::v16i8, 16*20 }, |
| 470 | { ISD::UDIV, MVT::v8i16, 8*20 }, |
| 471 | { ISD::UDIV, MVT::v4i32, 4*20 }, |
| 472 | { ISD::UDIV, MVT::v2i64, 2*20 }, |
Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 473 | }; |
| 474 | |
| 475 | if (ST->hasSSE2()) { |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 476 | if (const auto *Entry = CostTableLookup(SSE2CostTable, ISD, LT.second)) |
| 477 | return LT.first * Entry->Cost; |
Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 480 | static const CostTblEntry AVX1CostTable[] = { |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 481 | // We don't have to scalarize unsupported ops. We can issue two half-sized |
| 482 | // operations and we only need to extract the upper YMM half. |
| 483 | // Two ops + 1 extract + 1 insert = 4. |
Andrea Di Biagio | b7882b3 | 2014-02-12 23:43:47 +0000 | [diff] [blame] | 484 | { ISD::MUL, MVT::v16i16, 4 }, |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 485 | { ISD::MUL, MVT::v8i32, 4 }, |
| 486 | { ISD::SUB, MVT::v8i32, 4 }, |
| 487 | { ISD::ADD, MVT::v8i32, 4 }, |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 488 | { ISD::SUB, MVT::v4i64, 4 }, |
| 489 | { ISD::ADD, MVT::v4i64, 4 }, |
Arnold Schwaighofer | 20ef54f | 2013-03-02 04:02:52 +0000 | [diff] [blame] | 490 | // A v4i64 multiply is custom lowered as two split v2i64 vectors that then |
| 491 | // are lowered as a series of long multiplies(3), shifts(4) and adds(2) |
| 492 | // Because we believe v4i64 to be a legal type, we must also include the |
| 493 | // split factor of two in the cost table. Therefore, the cost here is 18 |
| 494 | // instead of 9. |
| 495 | { ISD::MUL, MVT::v4i64, 18 }, |
| 496 | }; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 497 | |
| 498 | // Look for AVX1 lowering tricks. |
Arnold Schwaighofer | 20ef54f | 2013-03-02 04:02:52 +0000 | [diff] [blame] | 499 | if (ST->hasAVX() && !ST->hasAVX2()) { |
Craig Topper | eda02a9 | 2015-10-25 03:15:29 +0000 | [diff] [blame] | 500 | MVT VT = LT.second; |
Andrea Di Biagio | b7882b3 | 2014-02-12 23:43:47 +0000 | [diff] [blame] | 501 | |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 502 | if (const auto *Entry = CostTableLookup(AVX1CostTable, ISD, VT)) |
| 503 | return LT.first * Entry->Cost; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 504 | } |
Arnold Schwaighofer | 20ef54f | 2013-03-02 04:02:52 +0000 | [diff] [blame] | 505 | |
| 506 | // Custom lowering of vectors. |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 507 | static const CostTblEntry CustomLowered[] = { |
Arnold Schwaighofer | 20ef54f | 2013-03-02 04:02:52 +0000 | [diff] [blame] | 508 | // A v2i64/v4i64 and multiply is custom lowered as a series of long |
| 509 | // multiplies(3), shifts(4) and adds(2). |
| 510 | { ISD::MUL, MVT::v2i64, 9 }, |
| 511 | { ISD::MUL, MVT::v4i64, 9 }, |
| 512 | }; |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 513 | if (const auto *Entry = CostTableLookup(CustomLowered, ISD, LT.second)) |
| 514 | return LT.first * Entry->Cost; |
Arnold Schwaighofer | 20ef54f | 2013-03-02 04:02:52 +0000 | [diff] [blame] | 515 | |
| 516 | // Special lowering of v4i32 mul on sse2, sse3: Lower v4i32 mul as 2x shuffle, |
| 517 | // 2x pmuludq, 2x shuffle. |
| 518 | if (ISD == ISD::MUL && LT.second == MVT::v4i32 && ST->hasSSE2() && |
| 519 | !ST->hasSSE41()) |
Andrea Di Biagio | b7882b3 | 2014-02-12 23:43:47 +0000 | [diff] [blame] | 520 | return LT.first * 6; |
Arnold Schwaighofer | 20ef54f | 2013-03-02 04:02:52 +0000 | [diff] [blame] | 521 | |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 522 | // Fallback to the default implementation. |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 523 | return BaseT::getArithmeticInstrCost(Opcode, Ty, Op1Info, Op2Info); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 524 | } |
| 525 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 526 | int X86TTIImpl::getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, |
| 527 | Type *SubTp) { |
Karthik Bhat | e03a25d | 2014-06-20 04:32:48 +0000 | [diff] [blame] | 528 | // We only estimate the cost of reverse and alternate shuffles. |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 529 | if (Kind != TTI::SK_Reverse && Kind != TTI::SK_Alternate) |
| 530 | return BaseT::getShuffleCost(Kind, Tp, Index, SubTp); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 531 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 532 | if (Kind == TTI::SK_Reverse) { |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 533 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Tp); |
| 534 | int Cost = 1; |
Karthik Bhat | e03a25d | 2014-06-20 04:32:48 +0000 | [diff] [blame] | 535 | if (LT.second.getSizeInBits() > 128) |
| 536 | Cost = 3; // Extract + insert + copy. |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 537 | |
Karthik Bhat | e03a25d | 2014-06-20 04:32:48 +0000 | [diff] [blame] | 538 | // Multiple by the number of parts. |
| 539 | return Cost * LT.first; |
| 540 | } |
| 541 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 542 | if (Kind == TTI::SK_Alternate) { |
Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 543 | // 64-bit packed float vectors (v2f32) are widened to type v4f32. |
| 544 | // 64-bit packed integer vectors (v2i32) are promoted to type v2i64. |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 545 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Tp); |
Karthik Bhat | e03a25d | 2014-06-20 04:32:48 +0000 | [diff] [blame] | 546 | |
Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 547 | // The backend knows how to generate a single VEX.256 version of |
| 548 | // instruction VPBLENDW if the target supports AVX2. |
| 549 | if (ST->hasAVX2() && LT.second == MVT::v16i16) |
| 550 | return LT.first; |
| 551 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 552 | static const CostTblEntry AVXAltShuffleTbl[] = { |
Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 553 | {ISD::VECTOR_SHUFFLE, MVT::v4i64, 1}, // vblendpd |
| 554 | {ISD::VECTOR_SHUFFLE, MVT::v4f64, 1}, // vblendpd |
| 555 | |
| 556 | {ISD::VECTOR_SHUFFLE, MVT::v8i32, 1}, // vblendps |
| 557 | {ISD::VECTOR_SHUFFLE, MVT::v8f32, 1}, // vblendps |
| 558 | |
| 559 | // This shuffle is custom lowered into a sequence of: |
| 560 | // 2x vextractf128 , 2x vpblendw , 1x vinsertf128 |
| 561 | {ISD::VECTOR_SHUFFLE, MVT::v16i16, 5}, |
| 562 | |
| 563 | // This shuffle is custom lowered into a long sequence of: |
| 564 | // 2x vextractf128 , 4x vpshufb , 2x vpor , 1x vinsertf128 |
| 565 | {ISD::VECTOR_SHUFFLE, MVT::v32i8, 9} |
| 566 | }; |
| 567 | |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 568 | if (ST->hasAVX()) |
| 569 | if (const auto *Entry = CostTableLookup(AVXAltShuffleTbl, |
| 570 | ISD::VECTOR_SHUFFLE, LT.second)) |
| 571 | return LT.first * Entry->Cost; |
Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 572 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 573 | static const CostTblEntry SSE41AltShuffleTbl[] = { |
Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 574 | // These are lowered into movsd. |
| 575 | {ISD::VECTOR_SHUFFLE, MVT::v2i64, 1}, |
| 576 | {ISD::VECTOR_SHUFFLE, MVT::v2f64, 1}, |
| 577 | |
| 578 | // packed float vectors with four elements are lowered into BLENDI dag |
| 579 | // nodes. A v4i32/v4f32 BLENDI generates a single 'blendps'/'blendpd'. |
| 580 | {ISD::VECTOR_SHUFFLE, MVT::v4i32, 1}, |
| 581 | {ISD::VECTOR_SHUFFLE, MVT::v4f32, 1}, |
| 582 | |
| 583 | // This shuffle generates a single pshufw. |
| 584 | {ISD::VECTOR_SHUFFLE, MVT::v8i16, 1}, |
| 585 | |
| 586 | // There is no instruction that matches a v16i8 alternate shuffle. |
| 587 | // The backend will expand it into the sequence 'pshufb + pshufb + or'. |
| 588 | {ISD::VECTOR_SHUFFLE, MVT::v16i8, 3} |
| 589 | }; |
| 590 | |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 591 | if (ST->hasSSE41()) |
| 592 | if (const auto *Entry = CostTableLookup(SSE41AltShuffleTbl, ISD::VECTOR_SHUFFLE, |
| 593 | LT.second)) |
| 594 | return LT.first * Entry->Cost; |
Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 595 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 596 | static const CostTblEntry SSSE3AltShuffleTbl[] = { |
Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 597 | {ISD::VECTOR_SHUFFLE, MVT::v2i64, 1}, // movsd |
| 598 | {ISD::VECTOR_SHUFFLE, MVT::v2f64, 1}, // movsd |
| 599 | |
| 600 | // SSE3 doesn't have 'blendps'. The following shuffles are expanded into |
| 601 | // the sequence 'shufps + pshufd' |
| 602 | {ISD::VECTOR_SHUFFLE, MVT::v4i32, 2}, |
| 603 | {ISD::VECTOR_SHUFFLE, MVT::v4f32, 2}, |
| 604 | |
| 605 | {ISD::VECTOR_SHUFFLE, MVT::v8i16, 3}, // pshufb + pshufb + or |
| 606 | {ISD::VECTOR_SHUFFLE, MVT::v16i8, 3} // pshufb + pshufb + or |
| 607 | }; |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 608 | |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 609 | if (ST->hasSSSE3()) |
| 610 | if (const auto *Entry = CostTableLookup(SSSE3AltShuffleTbl, |
| 611 | ISD::VECTOR_SHUFFLE, LT.second)) |
| 612 | return LT.first * Entry->Cost; |
Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 613 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 614 | static const CostTblEntry SSEAltShuffleTbl[] = { |
Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 615 | {ISD::VECTOR_SHUFFLE, MVT::v2i64, 1}, // movsd |
| 616 | {ISD::VECTOR_SHUFFLE, MVT::v2f64, 1}, // movsd |
| 617 | |
| 618 | {ISD::VECTOR_SHUFFLE, MVT::v4i32, 2}, // shufps + pshufd |
| 619 | {ISD::VECTOR_SHUFFLE, MVT::v4f32, 2}, // shufps + pshufd |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 620 | |
Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 621 | // This is expanded into a long sequence of four extract + four insert. |
| 622 | {ISD::VECTOR_SHUFFLE, MVT::v8i16, 8}, // 4 x pextrw + 4 pinsrw. |
| 623 | |
| 624 | // 8 x (pinsrw + pextrw + and + movb + movzb + or) |
| 625 | {ISD::VECTOR_SHUFFLE, MVT::v16i8, 48} |
| 626 | }; |
| 627 | |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 628 | // Fall-back (SSE3 and SSE2). |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 629 | if (const auto *Entry = CostTableLookup(SSEAltShuffleTbl, |
| 630 | ISD::VECTOR_SHUFFLE, LT.second)) |
| 631 | return LT.first * Entry->Cost; |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 632 | return BaseT::getShuffleCost(Kind, Tp, Index, SubTp); |
Karthik Bhat | e03a25d | 2014-06-20 04:32:48 +0000 | [diff] [blame] | 633 | } |
| 634 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 635 | return BaseT::getShuffleCost(Kind, Tp, Index, SubTp); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 636 | } |
| 637 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 638 | int X86TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) { |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 639 | int ISD = TLI->InstructionOpcodeToISD(Opcode); |
| 640 | assert(ISD && "Invalid opcode"); |
| 641 | |
Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 642 | // FIXME: Need a better design of the cost table to handle non-simple types of |
| 643 | // potential massive combinations (elem_num x src_type x dst_type). |
| 644 | |
Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 645 | static const TypeConversionCostTblEntry AVX512DQConversionTbl[] = { |
Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 646 | { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i64, 1 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 647 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, 1 }, |
Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 648 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i64, 1 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 649 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i64, 1 }, |
Simon Pilgrim | 285d9e4 | 2016-07-17 19:02:27 +0000 | [diff] [blame] | 650 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i64, 1 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 651 | { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i64, 1 }, |
Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 652 | |
Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 653 | { ISD::FP_TO_UINT, MVT::v2i64, MVT::v2f32, 1 }, |
| 654 | { ISD::FP_TO_UINT, MVT::v4i64, MVT::v4f32, 1 }, |
| 655 | { ISD::FP_TO_UINT, MVT::v8i64, MVT::v8f32, 1 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 656 | { ISD::FP_TO_UINT, MVT::v2i64, MVT::v2f64, 1 }, |
| 657 | { ISD::FP_TO_UINT, MVT::v4i64, MVT::v4f64, 1 }, |
| 658 | { ISD::FP_TO_UINT, MVT::v8i64, MVT::v8f64, 1 }, |
Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 659 | }; |
| 660 | |
Michael Kuperstein | f0c5933 | 2016-07-11 21:39:44 +0000 | [diff] [blame] | 661 | // TODO: For AVX512DQ + AVX512VL, we also have cheap casts for 128-bit and |
| 662 | // 256-bit wide vectors. |
| 663 | |
Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 664 | static const TypeConversionCostTblEntry AVX512FConversionTbl[] = { |
Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 665 | { ISD::FP_EXTEND, MVT::v8f64, MVT::v8f32, 1 }, |
| 666 | { ISD::FP_EXTEND, MVT::v8f64, MVT::v16f32, 3 }, |
| 667 | { ISD::FP_ROUND, MVT::v8f32, MVT::v8f64, 1 }, |
Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 668 | |
| 669 | { ISD::TRUNCATE, MVT::v16i8, MVT::v16i32, 1 }, |
| 670 | { ISD::TRUNCATE, MVT::v16i16, MVT::v16i32, 1 }, |
| 671 | { ISD::TRUNCATE, MVT::v8i16, MVT::v8i64, 1 }, |
| 672 | { ISD::TRUNCATE, MVT::v8i32, MVT::v8i64, 1 }, |
Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 673 | |
| 674 | // v16i1 -> v16i32 - load + broadcast |
| 675 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i1, 2 }, |
| 676 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i1, 2 }, |
Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 677 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i8, 1 }, |
| 678 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i8, 1 }, |
| 679 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i16, 1 }, |
| 680 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i16, 1 }, |
Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 681 | { ISD::ZERO_EXTEND, MVT::v8i64, MVT::v8i16, 1 }, |
| 682 | { ISD::SIGN_EXTEND, MVT::v8i64, MVT::v8i16, 1 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 683 | { ISD::SIGN_EXTEND, MVT::v8i64, MVT::v8i32, 1 }, |
| 684 | { ISD::ZERO_EXTEND, MVT::v8i64, MVT::v8i32, 1 }, |
Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 685 | |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 686 | { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i1, 4 }, |
Elena Demikhovsky | d5e95b5 | 2014-11-13 11:46:16 +0000 | [diff] [blame] | 687 | { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i1, 3 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 688 | { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i8, 2 }, |
Elena Demikhovsky | d5e95b5 | 2014-11-13 11:46:16 +0000 | [diff] [blame] | 689 | { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i8, 2 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 690 | { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i16, 2 }, |
Elena Demikhovsky | d5e95b5 | 2014-11-13 11:46:16 +0000 | [diff] [blame] | 691 | { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i16, 2 }, |
| 692 | { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i32, 1 }, |
Elena Demikhovsky | d5e95b5 | 2014-11-13 11:46:16 +0000 | [diff] [blame] | 693 | { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i32, 1 }, |
Michael Kuperstein | f0c5933 | 2016-07-11 21:39:44 +0000 | [diff] [blame] | 694 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i64, 26 }, |
| 695 | { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i64, 26 }, |
Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 696 | |
Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 697 | { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i1, 4 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 698 | { ISD::UINT_TO_FP, MVT::v16f32, MVT::v16i1, 3 }, |
Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 699 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i8, 2 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 700 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i8, 2 }, |
| 701 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i8, 2 }, |
| 702 | { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i8, 2 }, |
| 703 | { ISD::UINT_TO_FP, MVT::v16f32, MVT::v16i8, 2 }, |
Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 704 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i16, 5 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 705 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i16, 2 }, |
| 706 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i16, 2 }, |
| 707 | { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i16, 2 }, |
| 708 | { ISD::UINT_TO_FP, MVT::v16f32, MVT::v16i16, 2 }, |
Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 709 | { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i32, 2 }, |
Simon Pilgrim | 285d9e4 | 2016-07-17 19:02:27 +0000 | [diff] [blame] | 710 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i32, 1 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 711 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, 1 }, |
| 712 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i32, 1 }, |
| 713 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i32, 1 }, |
| 714 | { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i32, 1 }, |
| 715 | { ISD::UINT_TO_FP, MVT::v16f32, MVT::v16i32, 1 }, |
Simon Pilgrim | 285d9e4 | 2016-07-17 19:02:27 +0000 | [diff] [blame] | 716 | { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i64, 5 }, |
Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 717 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, 5 }, |
| 718 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i64, 12 }, |
| 719 | { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i64, 26 }, |
| 720 | |
| 721 | { ISD::FP_TO_UINT, MVT::v2i32, MVT::v2f32, 1 }, |
| 722 | { ISD::FP_TO_UINT, MVT::v4i32, MVT::v4f32, 1 }, |
| 723 | { ISD::FP_TO_UINT, MVT::v8i32, MVT::v8f32, 1 }, |
| 724 | { ISD::FP_TO_UINT, MVT::v16i32, MVT::v16f32, 1 }, |
Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 725 | }; |
| 726 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 727 | static const TypeConversionCostTblEntry AVX2ConversionTbl[] = { |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 728 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i1, 3 }, |
| 729 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i1, 3 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 730 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i1, 3 }, |
| 731 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i1, 3 }, |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 732 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i8, 3 }, |
| 733 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i8, 3 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 734 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i8, 3 }, |
| 735 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i8, 3 }, |
| 736 | { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i8, 1 }, |
| 737 | { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i8, 1 }, |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 738 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i16, 3 }, |
| 739 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i16, 3 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 740 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, 1 }, |
| 741 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, 1 }, |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 742 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, 1 }, |
| 743 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, 1 }, |
| 744 | |
| 745 | { ISD::TRUNCATE, MVT::v4i8, MVT::v4i64, 2 }, |
| 746 | { ISD::TRUNCATE, MVT::v4i16, MVT::v4i64, 2 }, |
| 747 | { ISD::TRUNCATE, MVT::v4i32, MVT::v4i64, 2 }, |
| 748 | { ISD::TRUNCATE, MVT::v8i8, MVT::v8i32, 2 }, |
| 749 | { ISD::TRUNCATE, MVT::v8i16, MVT::v8i32, 2 }, |
| 750 | { ISD::TRUNCATE, MVT::v8i32, MVT::v8i64, 4 }, |
Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 751 | |
| 752 | { ISD::FP_EXTEND, MVT::v8f64, MVT::v8f32, 3 }, |
| 753 | { ISD::FP_ROUND, MVT::v8f32, MVT::v8f64, 3 }, |
Quentin Colombet | 360460b | 2014-11-11 02:23:47 +0000 | [diff] [blame] | 754 | |
| 755 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i32, 8 }, |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 756 | }; |
| 757 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 758 | static const TypeConversionCostTblEntry AVXConversionTbl[] = { |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 759 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i1, 6 }, |
| 760 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i1, 4 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 761 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i1, 7 }, |
| 762 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i1, 4 }, |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 763 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i8, 6 }, |
| 764 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i8, 4 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 765 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i8, 7 }, |
| 766 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i8, 4 }, |
| 767 | { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i8, 4 }, |
| 768 | { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i8, 4 }, |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 769 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i16, 6 }, |
| 770 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i16, 3 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 771 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, 4 }, |
| 772 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, 4 }, |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 773 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, 4 }, |
| 774 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, 4 }, |
| 775 | |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 776 | { ISD::TRUNCATE, MVT::v16i8, MVT::v16i16, 4 }, |
| 777 | { ISD::TRUNCATE, MVT::v8i8, MVT::v8i32, 4 }, |
| 778 | { ISD::TRUNCATE, MVT::v8i16, MVT::v8i32, 5 }, |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 779 | { ISD::TRUNCATE, MVT::v4i8, MVT::v4i64, 4 }, |
| 780 | { ISD::TRUNCATE, MVT::v4i16, MVT::v4i64, 4 }, |
| 781 | { ISD::TRUNCATE, MVT::v4i32, MVT::v4i64, 4 }, |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 782 | { ISD::TRUNCATE, MVT::v8i32, MVT::v8i64, 9 }, |
Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 783 | |
Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 784 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i1, 3 }, |
Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 785 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i1, 3 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 786 | { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i1, 8 }, |
| 787 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i8, 3 }, |
Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 788 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i8, 3 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 789 | { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i8, 8 }, |
| 790 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i16, 3 }, |
Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 791 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i16, 3 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 792 | { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i16, 5 }, |
| 793 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i32, 1 }, |
Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 794 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i32, 1 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 795 | { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i32, 1 }, |
Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 796 | |
Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 797 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i1, 7 }, |
Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 798 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i1, 7 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 799 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i1, 6 }, |
| 800 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i8, 2 }, |
Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 801 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i8, 2 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 802 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i8, 5 }, |
| 803 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i16, 2 }, |
Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 804 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i16, 2 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 805 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i16, 5 }, |
Michael Kuperstein | f0c5933 | 2016-07-11 21:39:44 +0000 | [diff] [blame] | 806 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i32, 6 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 807 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, 6 }, |
Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 808 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i32, 6 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 809 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i32, 9 }, |
Quentin Colombet | 85b904d | 2014-03-27 22:27:41 +0000 | [diff] [blame] | 810 | // The generic code to compute the scalar overhead is currently broken. |
| 811 | // Workaround this limitation by estimating the scalarization overhead |
| 812 | // here. We have roughly 10 instructions per scalar element. |
| 813 | // Multiply that by the vector width. |
| 814 | // FIXME: remove that when PR19268 is fixed. |
Michael Kuperstein | f0c5933 | 2016-07-11 21:39:44 +0000 | [diff] [blame] | 815 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, 10 }, |
| 816 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i64, 20 }, |
| 817 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i64, 13 }, |
| 818 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i64, 13 }, |
Simon Pilgrim | 285d9e4 | 2016-07-17 19:02:27 +0000 | [diff] [blame] | 819 | |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 820 | { ISD::FP_TO_SINT, MVT::v4i8, MVT::v4f32, 1 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 821 | { ISD::FP_TO_SINT, MVT::v8i8, MVT::v8f32, 7 }, |
Adam Nemet | 6dafe97 | 2014-03-30 18:07:13 +0000 | [diff] [blame] | 822 | // This node is expanded into scalarized operations but BasicTTI is overly |
| 823 | // optimistic estimating its cost. It computes 3 per element (one |
| 824 | // vector-extract, one scalar conversion and one vector-insert). The |
| 825 | // problem is that the inserts form a read-modify-write chain so latency |
| 826 | // should be factored in too. Inflating the cost per element by 1. |
| 827 | { ISD::FP_TO_UINT, MVT::v8i32, MVT::v8f32, 8*4 }, |
Adam Nemet | 10c4ce2 | 2014-03-31 21:54:48 +0000 | [diff] [blame] | 828 | { ISD::FP_TO_UINT, MVT::v4i32, MVT::v4f64, 4*4 }, |
Michael Kuperstein | f0c5933 | 2016-07-11 21:39:44 +0000 | [diff] [blame] | 829 | |
| 830 | { ISD::FP_EXTEND, MVT::v4f64, MVT::v4f32, 1 }, |
| 831 | { ISD::FP_ROUND, MVT::v4f32, MVT::v4f64, 1 }, |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 832 | }; |
| 833 | |
Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 834 | static const TypeConversionCostTblEntry SSE41ConversionTbl[] = { |
Michael Kuperstein | 9a0542a | 2016-06-10 17:01:05 +0000 | [diff] [blame] | 835 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i8, 2 }, |
| 836 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i8, 2 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 837 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i16, 2 }, |
| 838 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i16, 2 }, |
| 839 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, 2 }, |
| 840 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, 2 }, |
Michael Kuperstein | 9a0542a | 2016-06-10 17:01:05 +0000 | [diff] [blame] | 841 | |
Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 842 | { ISD::ZERO_EXTEND, MVT::v4i16, MVT::v4i8, 1 }, |
| 843 | { ISD::SIGN_EXTEND, MVT::v4i16, MVT::v4i8, 2 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 844 | { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v4i8, 1 }, |
| 845 | { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v4i8, 1 }, |
| 846 | { ISD::ZERO_EXTEND, MVT::v8i16, MVT::v8i8, 1 }, |
| 847 | { ISD::SIGN_EXTEND, MVT::v8i16, MVT::v8i8, 1 }, |
| 848 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i8, 2 }, |
| 849 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i8, 2 }, |
| 850 | { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i8, 2 }, |
| 851 | { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i8, 2 }, |
| 852 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i8, 4 }, |
| 853 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i8, 4 }, |
| 854 | { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v4i16, 1 }, |
| 855 | { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v4i16, 1 }, |
| 856 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, 2 }, |
| 857 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, 2 }, |
| 858 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i16, 4 }, |
| 859 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i16, 4 }, |
Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 860 | |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 861 | { ISD::TRUNCATE, MVT::v4i8, MVT::v4i16, 2 }, |
| 862 | { ISD::TRUNCATE, MVT::v8i8, MVT::v8i16, 1 }, |
| 863 | { ISD::TRUNCATE, MVT::v4i8, MVT::v4i32, 1 }, |
Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 864 | { ISD::TRUNCATE, MVT::v4i16, MVT::v4i32, 1 }, |
Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 865 | { ISD::TRUNCATE, MVT::v8i8, MVT::v8i32, 3 }, |
Simon Pilgrim | 285d9e4 | 2016-07-17 19:02:27 +0000 | [diff] [blame] | 866 | { ISD::TRUNCATE, MVT::v8i16, MVT::v8i32, 3 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 867 | { ISD::TRUNCATE, MVT::v16i16, MVT::v16i32, 6 }, |
| 868 | |
Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 869 | }; |
| 870 | |
| 871 | static const TypeConversionCostTblEntry SSE2ConversionTbl[] = { |
Simon Pilgrim | e2c244f | 2015-07-19 15:36:12 +0000 | [diff] [blame] | 872 | // These are somewhat magic numbers justified by looking at the output of |
| 873 | // Intel's IACA, running some kernels and making sure when we take |
| 874 | // legalization into account the throughput will be overestimated. |
Simon Pilgrim | e2c244f | 2015-07-19 15:36:12 +0000 | [diff] [blame] | 875 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v16i8, 8 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 876 | { ISD::SINT_TO_FP, MVT::v2f64, MVT::v16i8, 16*10 }, |
| 877 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v8i16, 15 }, |
| 878 | { ISD::SINT_TO_FP, MVT::v2f64, MVT::v8i16, 8*10 }, |
Sanjay Patel | 04b3496 | 2016-07-06 19:15:54 +0000 | [diff] [blame] | 879 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i32, 5 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 880 | { ISD::SINT_TO_FP, MVT::v2f64, MVT::v4i32, 4*10 }, |
| 881 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v2i64, 15 }, |
| 882 | { ISD::SINT_TO_FP, MVT::v2f64, MVT::v2i64, 2*10 }, |
Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 883 | |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 884 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v16i8, 16*10 }, |
| 885 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v16i8, 8 }, |
| 886 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v8i16, 15 }, |
| 887 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v8i16, 8*10 }, |
| 888 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v4i32, 4*10 }, |
| 889 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, 8 }, |
| 890 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, 2*10 }, |
| 891 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v2i64, 15 }, |
Michael Kuperstein | 9a0542a | 2016-06-10 17:01:05 +0000 | [diff] [blame] | 892 | |
Simon Pilgrim | 4ddc92b | 2016-10-18 07:42:15 +0000 | [diff] [blame] | 893 | { ISD::FP_TO_SINT, MVT::v2i32, MVT::v2f64, 3 }, |
| 894 | |
Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 895 | { ISD::ZERO_EXTEND, MVT::v4i16, MVT::v4i8, 1 }, |
| 896 | { ISD::SIGN_EXTEND, MVT::v4i16, MVT::v4i8, 6 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 897 | { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v4i8, 2 }, |
| 898 | { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v4i8, 3 }, |
| 899 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i8, 4 }, |
| 900 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i8, 8 }, |
| 901 | { ISD::ZERO_EXTEND, MVT::v8i16, MVT::v8i8, 1 }, |
| 902 | { ISD::SIGN_EXTEND, MVT::v8i16, MVT::v8i8, 2 }, |
| 903 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i8, 6 }, |
| 904 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i8, 6 }, |
| 905 | { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i8, 3 }, |
| 906 | { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i8, 4 }, |
| 907 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i8, 9 }, |
| 908 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i8, 12 }, |
| 909 | { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v4i16, 1 }, |
| 910 | { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v4i16, 2 }, |
| 911 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i16, 3 }, |
| 912 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i16, 10 }, |
| 913 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, 3 }, |
| 914 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, 4 }, |
| 915 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i16, 6 }, |
Simon Pilgrim | 285d9e4 | 2016-07-17 19:02:27 +0000 | [diff] [blame] | 916 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i16, 8 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 917 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, 3 }, |
| 918 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, 5 }, |
Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 919 | |
Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 920 | { ISD::TRUNCATE, MVT::v4i8, MVT::v4i16, 4 }, |
Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 921 | { ISD::TRUNCATE, MVT::v8i8, MVT::v8i16, 2 }, |
| 922 | { ISD::TRUNCATE, MVT::v16i8, MVT::v16i16, 3 }, |
| 923 | { ISD::TRUNCATE, MVT::v4i8, MVT::v4i32, 3 }, |
| 924 | { ISD::TRUNCATE, MVT::v4i16, MVT::v4i32, 3 }, |
| 925 | { ISD::TRUNCATE, MVT::v8i8, MVT::v8i32, 4 }, |
| 926 | { ISD::TRUNCATE, MVT::v16i8, MVT::v16i32, 7 }, |
| 927 | { ISD::TRUNCATE, MVT::v8i16, MVT::v8i32, 5 }, |
| 928 | { ISD::TRUNCATE, MVT::v16i16, MVT::v16i32, 10 }, |
Simon Pilgrim | e2c244f | 2015-07-19 15:36:12 +0000 | [diff] [blame] | 929 | }; |
| 930 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 931 | std::pair<int, MVT> LTSrc = TLI->getTypeLegalizationCost(DL, Src); |
| 932 | std::pair<int, MVT> LTDest = TLI->getTypeLegalizationCost(DL, Dst); |
Simon Pilgrim | e2c244f | 2015-07-19 15:36:12 +0000 | [diff] [blame] | 933 | |
| 934 | if (ST->hasSSE2() && !ST->hasAVX()) { |
Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 935 | if (const auto *Entry = ConvertCostTableLookup(SSE2ConversionTbl, ISD, |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 936 | LTDest.second, LTSrc.second)) |
| 937 | return LTSrc.first * Entry->Cost; |
Simon Pilgrim | e2c244f | 2015-07-19 15:36:12 +0000 | [diff] [blame] | 938 | } |
| 939 | |
Simon Pilgrim | e2c244f | 2015-07-19 15:36:12 +0000 | [diff] [blame] | 940 | EVT SrcTy = TLI->getValueType(DL, Src); |
| 941 | EVT DstTy = TLI->getValueType(DL, Dst); |
| 942 | |
| 943 | // The function getSimpleVT only handles simple value types. |
| 944 | if (!SrcTy.isSimple() || !DstTy.isSimple()) |
| 945 | return BaseT::getCastInstrCost(Opcode, Dst, Src); |
| 946 | |
Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 947 | if (ST->hasDQI()) |
| 948 | if (const auto *Entry = ConvertCostTableLookup(AVX512DQConversionTbl, ISD, |
| 949 | DstTy.getSimpleVT(), |
| 950 | SrcTy.getSimpleVT())) |
| 951 | return Entry->Cost; |
| 952 | |
| 953 | if (ST->hasAVX512()) |
| 954 | if (const auto *Entry = ConvertCostTableLookup(AVX512FConversionTbl, ISD, |
| 955 | DstTy.getSimpleVT(), |
| 956 | SrcTy.getSimpleVT())) |
| 957 | return Entry->Cost; |
| 958 | |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 959 | if (ST->hasAVX2()) { |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 960 | if (const auto *Entry = ConvertCostTableLookup(AVX2ConversionTbl, ISD, |
| 961 | DstTy.getSimpleVT(), |
| 962 | SrcTy.getSimpleVT())) |
| 963 | return Entry->Cost; |
Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 964 | } |
| 965 | |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 966 | if (ST->hasAVX()) { |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 967 | if (const auto *Entry = ConvertCostTableLookup(AVXConversionTbl, ISD, |
| 968 | DstTy.getSimpleVT(), |
| 969 | SrcTy.getSimpleVT())) |
| 970 | return Entry->Cost; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 971 | } |
| 972 | |
Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 973 | if (ST->hasSSE41()) { |
| 974 | if (const auto *Entry = ConvertCostTableLookup(SSE41ConversionTbl, ISD, |
| 975 | DstTy.getSimpleVT(), |
| 976 | SrcTy.getSimpleVT())) |
| 977 | return Entry->Cost; |
| 978 | } |
| 979 | |
| 980 | if (ST->hasSSE2()) { |
| 981 | if (const auto *Entry = ConvertCostTableLookup(SSE2ConversionTbl, ISD, |
| 982 | DstTy.getSimpleVT(), |
| 983 | SrcTy.getSimpleVT())) |
| 984 | return Entry->Cost; |
| 985 | } |
| 986 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 987 | return BaseT::getCastInstrCost(Opcode, Dst, Src); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 988 | } |
| 989 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 990 | int X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy) { |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 991 | // Legalize the type. |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 992 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, ValTy); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 993 | |
| 994 | MVT MTy = LT.second; |
| 995 | |
| 996 | int ISD = TLI->InstructionOpcodeToISD(Opcode); |
| 997 | assert(ISD && "Invalid opcode"); |
| 998 | |
Simon Pilgrim | eec3a95 | 2016-05-09 21:14:38 +0000 | [diff] [blame] | 999 | static const CostTblEntry SSE2CostTbl[] = { |
| 1000 | { ISD::SETCC, MVT::v2i64, 8 }, |
| 1001 | { ISD::SETCC, MVT::v4i32, 1 }, |
| 1002 | { ISD::SETCC, MVT::v8i16, 1 }, |
| 1003 | { ISD::SETCC, MVT::v16i8, 1 }, |
| 1004 | }; |
| 1005 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 1006 | static const CostTblEntry SSE42CostTbl[] = { |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 1007 | { ISD::SETCC, MVT::v2f64, 1 }, |
| 1008 | { ISD::SETCC, MVT::v4f32, 1 }, |
| 1009 | { ISD::SETCC, MVT::v2i64, 1 }, |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1010 | }; |
| 1011 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 1012 | static const CostTblEntry AVX1CostTbl[] = { |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 1013 | { ISD::SETCC, MVT::v4f64, 1 }, |
| 1014 | { ISD::SETCC, MVT::v8f32, 1 }, |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1015 | // AVX1 does not support 8-wide integer compare. |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 1016 | { ISD::SETCC, MVT::v4i64, 4 }, |
| 1017 | { ISD::SETCC, MVT::v8i32, 4 }, |
| 1018 | { ISD::SETCC, MVT::v16i16, 4 }, |
| 1019 | { ISD::SETCC, MVT::v32i8, 4 }, |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1020 | }; |
| 1021 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 1022 | static const CostTblEntry AVX2CostTbl[] = { |
Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 1023 | { ISD::SETCC, MVT::v4i64, 1 }, |
| 1024 | { ISD::SETCC, MVT::v8i32, 1 }, |
| 1025 | { ISD::SETCC, MVT::v16i16, 1 }, |
| 1026 | { ISD::SETCC, MVT::v32i8, 1 }, |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1027 | }; |
| 1028 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 1029 | static const CostTblEntry AVX512CostTbl[] = { |
Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 1030 | { ISD::SETCC, MVT::v8i64, 1 }, |
| 1031 | { ISD::SETCC, MVT::v16i32, 1 }, |
| 1032 | { ISD::SETCC, MVT::v8f64, 1 }, |
| 1033 | { ISD::SETCC, MVT::v16f32, 1 }, |
| 1034 | }; |
| 1035 | |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 1036 | if (ST->hasAVX512()) |
| 1037 | if (const auto *Entry = CostTableLookup(AVX512CostTbl, ISD, MTy)) |
| 1038 | return LT.first * Entry->Cost; |
Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 1039 | |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 1040 | if (ST->hasAVX2()) |
| 1041 | if (const auto *Entry = CostTableLookup(AVX2CostTbl, ISD, MTy)) |
| 1042 | return LT.first * Entry->Cost; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1043 | |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 1044 | if (ST->hasAVX()) |
| 1045 | if (const auto *Entry = CostTableLookup(AVX1CostTbl, ISD, MTy)) |
| 1046 | return LT.first * Entry->Cost; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1047 | |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 1048 | if (ST->hasSSE42()) |
| 1049 | if (const auto *Entry = CostTableLookup(SSE42CostTbl, ISD, MTy)) |
| 1050 | return LT.first * Entry->Cost; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1051 | |
Simon Pilgrim | eec3a95 | 2016-05-09 21:14:38 +0000 | [diff] [blame] | 1052 | if (ST->hasSSE2()) |
| 1053 | if (const auto *Entry = CostTableLookup(SSE2CostTbl, ISD, MTy)) |
| 1054 | return LT.first * Entry->Cost; |
| 1055 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1056 | return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 1059 | int X86TTIImpl::getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, |
| 1060 | ArrayRef<Type *> Tys, FastMathFlags FMF) { |
Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1061 | // Costs should match the codegen from: |
| 1062 | // BITREVERSE: llvm\test\CodeGen\X86\vector-bitreverse.ll |
| 1063 | // BSWAP: llvm\test\CodeGen\X86\bswap-vector.ll |
Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1064 | // CTLZ: llvm\test\CodeGen\X86\vector-lzcnt-*.ll |
Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1065 | // CTPOP: llvm\test\CodeGen\X86\vector-popcnt-*.ll |
Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1066 | // CTTZ: llvm\test\CodeGen\X86\vector-tzcnt-*.ll |
Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 1067 | static const CostTblEntry XOPCostTbl[] = { |
| 1068 | { ISD::BITREVERSE, MVT::v4i64, 4 }, |
| 1069 | { ISD::BITREVERSE, MVT::v8i32, 4 }, |
| 1070 | { ISD::BITREVERSE, MVT::v16i16, 4 }, |
| 1071 | { ISD::BITREVERSE, MVT::v32i8, 4 }, |
| 1072 | { ISD::BITREVERSE, MVT::v2i64, 1 }, |
| 1073 | { ISD::BITREVERSE, MVT::v4i32, 1 }, |
| 1074 | { ISD::BITREVERSE, MVT::v8i16, 1 }, |
| 1075 | { ISD::BITREVERSE, MVT::v16i8, 1 }, |
| 1076 | { ISD::BITREVERSE, MVT::i64, 3 }, |
| 1077 | { ISD::BITREVERSE, MVT::i32, 3 }, |
| 1078 | { ISD::BITREVERSE, MVT::i16, 3 }, |
| 1079 | { ISD::BITREVERSE, MVT::i8, 3 } |
| 1080 | }; |
Simon Pilgrim | 3fc09f7 | 2016-06-11 19:23:02 +0000 | [diff] [blame] | 1081 | static const CostTblEntry AVX2CostTbl[] = { |
| 1082 | { ISD::BITREVERSE, MVT::v4i64, 5 }, |
| 1083 | { ISD::BITREVERSE, MVT::v8i32, 5 }, |
| 1084 | { ISD::BITREVERSE, MVT::v16i16, 5 }, |
Simon Pilgrim | 356e823 | 2016-06-20 23:08:21 +0000 | [diff] [blame] | 1085 | { ISD::BITREVERSE, MVT::v32i8, 5 }, |
| 1086 | { ISD::BSWAP, MVT::v4i64, 1 }, |
| 1087 | { ISD::BSWAP, MVT::v8i32, 1 }, |
Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1088 | { ISD::BSWAP, MVT::v16i16, 1 }, |
Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1089 | { ISD::CTLZ, MVT::v4i64, 23 }, |
| 1090 | { ISD::CTLZ, MVT::v8i32, 18 }, |
| 1091 | { ISD::CTLZ, MVT::v16i16, 14 }, |
| 1092 | { ISD::CTLZ, MVT::v32i8, 9 }, |
Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1093 | { ISD::CTPOP, MVT::v4i64, 7 }, |
| 1094 | { ISD::CTPOP, MVT::v8i32, 11 }, |
| 1095 | { ISD::CTPOP, MVT::v16i16, 9 }, |
Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1096 | { ISD::CTPOP, MVT::v32i8, 6 }, |
| 1097 | { ISD::CTTZ, MVT::v4i64, 10 }, |
| 1098 | { ISD::CTTZ, MVT::v8i32, 14 }, |
| 1099 | { ISD::CTTZ, MVT::v16i16, 12 }, |
| 1100 | { ISD::CTTZ, MVT::v32i8, 9 } |
Simon Pilgrim | 3fc09f7 | 2016-06-11 19:23:02 +0000 | [diff] [blame] | 1101 | }; |
| 1102 | static const CostTblEntry AVX1CostTbl[] = { |
| 1103 | { ISD::BITREVERSE, MVT::v4i64, 10 }, |
| 1104 | { ISD::BITREVERSE, MVT::v8i32, 10 }, |
| 1105 | { ISD::BITREVERSE, MVT::v16i16, 10 }, |
Simon Pilgrim | 356e823 | 2016-06-20 23:08:21 +0000 | [diff] [blame] | 1106 | { ISD::BITREVERSE, MVT::v32i8, 10 }, |
| 1107 | { ISD::BSWAP, MVT::v4i64, 4 }, |
| 1108 | { ISD::BSWAP, MVT::v8i32, 4 }, |
Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1109 | { ISD::BSWAP, MVT::v16i16, 4 }, |
Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1110 | { ISD::CTLZ, MVT::v4i64, 46 }, |
| 1111 | { ISD::CTLZ, MVT::v8i32, 36 }, |
| 1112 | { ISD::CTLZ, MVT::v16i16, 28 }, |
| 1113 | { ISD::CTLZ, MVT::v32i8, 18 }, |
Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1114 | { ISD::CTPOP, MVT::v4i64, 14 }, |
| 1115 | { ISD::CTPOP, MVT::v8i32, 22 }, |
| 1116 | { ISD::CTPOP, MVT::v16i16, 18 }, |
Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1117 | { ISD::CTPOP, MVT::v32i8, 12 }, |
| 1118 | { ISD::CTTZ, MVT::v4i64, 20 }, |
| 1119 | { ISD::CTTZ, MVT::v8i32, 28 }, |
| 1120 | { ISD::CTTZ, MVT::v16i16, 24 }, |
| 1121 | { ISD::CTTZ, MVT::v32i8, 18 }, |
Simon Pilgrim | 3fc09f7 | 2016-06-11 19:23:02 +0000 | [diff] [blame] | 1122 | }; |
| 1123 | static const CostTblEntry SSSE3CostTbl[] = { |
| 1124 | { ISD::BITREVERSE, MVT::v2i64, 5 }, |
| 1125 | { ISD::BITREVERSE, MVT::v4i32, 5 }, |
| 1126 | { ISD::BITREVERSE, MVT::v8i16, 5 }, |
Simon Pilgrim | 356e823 | 2016-06-20 23:08:21 +0000 | [diff] [blame] | 1127 | { ISD::BITREVERSE, MVT::v16i8, 5 }, |
| 1128 | { ISD::BSWAP, MVT::v2i64, 1 }, |
| 1129 | { ISD::BSWAP, MVT::v4i32, 1 }, |
Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1130 | { ISD::BSWAP, MVT::v8i16, 1 }, |
Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1131 | { ISD::CTLZ, MVT::v2i64, 23 }, |
| 1132 | { ISD::CTLZ, MVT::v4i32, 18 }, |
| 1133 | { ISD::CTLZ, MVT::v8i16, 14 }, |
| 1134 | { ISD::CTLZ, MVT::v16i8, 9 }, |
Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1135 | { ISD::CTPOP, MVT::v2i64, 7 }, |
| 1136 | { ISD::CTPOP, MVT::v4i32, 11 }, |
| 1137 | { ISD::CTPOP, MVT::v8i16, 9 }, |
Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1138 | { ISD::CTPOP, MVT::v16i8, 6 }, |
| 1139 | { ISD::CTTZ, MVT::v2i64, 10 }, |
| 1140 | { ISD::CTTZ, MVT::v4i32, 14 }, |
| 1141 | { ISD::CTTZ, MVT::v8i16, 12 }, |
| 1142 | { ISD::CTTZ, MVT::v16i8, 9 } |
Simon Pilgrim | 356e823 | 2016-06-20 23:08:21 +0000 | [diff] [blame] | 1143 | }; |
| 1144 | static const CostTblEntry SSE2CostTbl[] = { |
| 1145 | { ISD::BSWAP, MVT::v2i64, 7 }, |
| 1146 | { ISD::BSWAP, MVT::v4i32, 7 }, |
Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1147 | { ISD::BSWAP, MVT::v8i16, 7 }, |
Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1148 | /* ISD::CTLZ - currently scalarized pre-SSSE3 */ |
Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1149 | { ISD::CTPOP, MVT::v2i64, 12 }, |
| 1150 | { ISD::CTPOP, MVT::v4i32, 15 }, |
| 1151 | { ISD::CTPOP, MVT::v8i16, 13 }, |
Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1152 | { ISD::CTPOP, MVT::v16i8, 10 }, |
| 1153 | { ISD::CTTZ, MVT::v2i64, 14 }, |
| 1154 | { ISD::CTTZ, MVT::v4i32, 18 }, |
| 1155 | { ISD::CTTZ, MVT::v8i16, 16 }, |
| 1156 | { ISD::CTTZ, MVT::v16i8, 13 } |
Simon Pilgrim | 3fc09f7 | 2016-06-11 19:23:02 +0000 | [diff] [blame] | 1157 | }; |
Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 1158 | |
| 1159 | unsigned ISD = ISD::DELETED_NODE; |
| 1160 | switch (IID) { |
| 1161 | default: |
| 1162 | break; |
| 1163 | case Intrinsic::bitreverse: |
| 1164 | ISD = ISD::BITREVERSE; |
| 1165 | break; |
Simon Pilgrim | 356e823 | 2016-06-20 23:08:21 +0000 | [diff] [blame] | 1166 | case Intrinsic::bswap: |
| 1167 | ISD = ISD::BSWAP; |
| 1168 | break; |
Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1169 | case Intrinsic::ctlz: |
| 1170 | ISD = ISD::CTLZ; |
| 1171 | break; |
Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1172 | case Intrinsic::ctpop: |
| 1173 | ISD = ISD::CTPOP; |
| 1174 | break; |
Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1175 | case Intrinsic::cttz: |
| 1176 | ISD = ISD::CTTZ; |
| 1177 | break; |
Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | // Legalize the type. |
| 1181 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, RetTy); |
| 1182 | MVT MTy = LT.second; |
| 1183 | |
| 1184 | // Attempt to lookup cost. |
| 1185 | if (ST->hasXOP()) |
| 1186 | if (const auto *Entry = CostTableLookup(XOPCostTbl, ISD, MTy)) |
| 1187 | return LT.first * Entry->Cost; |
| 1188 | |
Simon Pilgrim | 3fc09f7 | 2016-06-11 19:23:02 +0000 | [diff] [blame] | 1189 | if (ST->hasAVX2()) |
| 1190 | if (const auto *Entry = CostTableLookup(AVX2CostTbl, ISD, MTy)) |
| 1191 | return LT.first * Entry->Cost; |
| 1192 | |
| 1193 | if (ST->hasAVX()) |
| 1194 | if (const auto *Entry = CostTableLookup(AVX1CostTbl, ISD, MTy)) |
| 1195 | return LT.first * Entry->Cost; |
| 1196 | |
| 1197 | if (ST->hasSSSE3()) |
| 1198 | if (const auto *Entry = CostTableLookup(SSSE3CostTbl, ISD, MTy)) |
| 1199 | return LT.first * Entry->Cost; |
| 1200 | |
Simon Pilgrim | 356e823 | 2016-06-20 23:08:21 +0000 | [diff] [blame] | 1201 | if (ST->hasSSE2()) |
| 1202 | if (const auto *Entry = CostTableLookup(SSE2CostTbl, ISD, MTy)) |
| 1203 | return LT.first * Entry->Cost; |
| 1204 | |
Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 1205 | return BaseT::getIntrinsicInstrCost(IID, RetTy, Tys, FMF); |
| 1206 | } |
| 1207 | |
| 1208 | int X86TTIImpl::getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, |
| 1209 | ArrayRef<Value *> Args, FastMathFlags FMF) { |
| 1210 | return BaseT::getIntrinsicInstrCost(IID, RetTy, Args, FMF); |
| 1211 | } |
| 1212 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1213 | int X86TTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) { |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1214 | assert(Val->isVectorTy() && "This must be a vector type"); |
| 1215 | |
Sanjay Patel | aedc347 | 2016-05-25 17:27:54 +0000 | [diff] [blame] | 1216 | Type *ScalarType = Val->getScalarType(); |
| 1217 | |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1218 | if (Index != -1U) { |
| 1219 | // Legalize the type. |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1220 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Val); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1221 | |
| 1222 | // This type is legalized to a scalar type. |
| 1223 | if (!LT.second.isVector()) |
| 1224 | return 0; |
| 1225 | |
| 1226 | // The type may be split. Normalize the index to the new type. |
| 1227 | unsigned Width = LT.second.getVectorNumElements(); |
| 1228 | Index = Index % Width; |
| 1229 | |
| 1230 | // Floating point scalars are already located in index #0. |
Sanjay Patel | aedc347 | 2016-05-25 17:27:54 +0000 | [diff] [blame] | 1231 | if (ScalarType->isFloatingPointTy() && Index == 0) |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1232 | return 0; |
| 1233 | } |
| 1234 | |
Sanjay Patel | aedc347 | 2016-05-25 17:27:54 +0000 | [diff] [blame] | 1235 | // Add to the base cost if we know that the extracted element of a vector is |
| 1236 | // destined to be moved to and used in the integer register file. |
| 1237 | int RegisterFileMoveCost = 0; |
| 1238 | if (Opcode == Instruction::ExtractElement && ScalarType->isPointerTy()) |
| 1239 | RegisterFileMoveCost = 1; |
| 1240 | |
| 1241 | return BaseT::getVectorInstrCost(Opcode, Val, Index) + RegisterFileMoveCost; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1244 | int X86TTIImpl::getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) { |
Nadav Rotem | f9ecbcb | 2013-06-27 17:52:04 +0000 | [diff] [blame] | 1245 | assert (Ty->isVectorTy() && "Can only scalarize vectors"); |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1246 | int Cost = 0; |
Nadav Rotem | f9ecbcb | 2013-06-27 17:52:04 +0000 | [diff] [blame] | 1247 | |
| 1248 | for (int i = 0, e = Ty->getVectorNumElements(); i < e; ++i) { |
| 1249 | if (Insert) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1250 | Cost += getVectorInstrCost(Instruction::InsertElement, Ty, i); |
Nadav Rotem | f9ecbcb | 2013-06-27 17:52:04 +0000 | [diff] [blame] | 1251 | if (Extract) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1252 | Cost += getVectorInstrCost(Instruction::ExtractElement, Ty, i); |
Nadav Rotem | f9ecbcb | 2013-06-27 17:52:04 +0000 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | return Cost; |
| 1256 | } |
| 1257 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1258 | int X86TTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, |
| 1259 | unsigned AddressSpace) { |
Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 1260 | // Handle non-power-of-two vectors such as <3 x float> |
Nadav Rotem | f9ecbcb | 2013-06-27 17:52:04 +0000 | [diff] [blame] | 1261 | if (VectorType *VTy = dyn_cast<VectorType>(Src)) { |
| 1262 | unsigned NumElem = VTy->getVectorNumElements(); |
| 1263 | |
| 1264 | // Handle a few common cases: |
| 1265 | // <3 x float> |
| 1266 | if (NumElem == 3 && VTy->getScalarSizeInBits() == 32) |
| 1267 | // Cost = 64 bit store + extract + 32 bit store. |
| 1268 | return 3; |
| 1269 | |
| 1270 | // <3 x double> |
| 1271 | if (NumElem == 3 && VTy->getScalarSizeInBits() == 64) |
| 1272 | // Cost = 128 bit store + unpack + 64 bit store. |
| 1273 | return 3; |
| 1274 | |
Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 1275 | // Assume that all other non-power-of-two numbers are scalarized. |
Nadav Rotem | f9ecbcb | 2013-06-27 17:52:04 +0000 | [diff] [blame] | 1276 | if (!isPowerOf2_32(NumElem)) { |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1277 | int Cost = BaseT::getMemoryOpCost(Opcode, VTy->getScalarType(), Alignment, |
| 1278 | AddressSpace); |
| 1279 | int SplitCost = getScalarizationOverhead(Src, Opcode == Instruction::Load, |
| 1280 | Opcode == Instruction::Store); |
Nadav Rotem | f9ecbcb | 2013-06-27 17:52:04 +0000 | [diff] [blame] | 1281 | return NumElem * Cost + SplitCost; |
| 1282 | } |
| 1283 | } |
| 1284 | |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1285 | // Legalize the type. |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1286 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Src); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1287 | assert((Opcode == Instruction::Load || Opcode == Instruction::Store) && |
| 1288 | "Invalid Opcode"); |
| 1289 | |
| 1290 | // Each load/store unit costs 1. |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1291 | int Cost = LT.first * 1; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1292 | |
Sanjay Patel | 9f6c4d5 | 2016-03-09 22:23:33 +0000 | [diff] [blame] | 1293 | // This isn't exactly right. We're using slow unaligned 32-byte accesses as a |
| 1294 | // proxy for a double-pumped AVX memory interface such as on Sandybridge. |
| 1295 | if (LT.second.getStoreSize() == 32 && ST->isUnalignedMem32Slow()) |
| 1296 | Cost *= 2; |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1297 | |
| 1298 | return Cost; |
| 1299 | } |
Arnold Schwaighofer | 6042a26 | 2013-07-12 19:16:07 +0000 | [diff] [blame] | 1300 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1301 | int X86TTIImpl::getMaskedMemoryOpCost(unsigned Opcode, Type *SrcTy, |
| 1302 | unsigned Alignment, |
| 1303 | unsigned AddressSpace) { |
Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 1304 | VectorType *SrcVTy = dyn_cast<VectorType>(SrcTy); |
| 1305 | if (!SrcVTy) |
| 1306 | // To calculate scalar take the regular cost, without mask |
| 1307 | return getMemoryOpCost(Opcode, SrcTy, Alignment, AddressSpace); |
| 1308 | |
| 1309 | unsigned NumElem = SrcVTy->getVectorNumElements(); |
| 1310 | VectorType *MaskTy = |
Mehdi Amini | 867e914 | 2016-04-14 04:36:40 +0000 | [diff] [blame] | 1311 | VectorType::get(Type::getInt8Ty(SrcVTy->getContext()), NumElem); |
Elena Demikhovsky | 20662e3 | 2015-10-19 07:43:38 +0000 | [diff] [blame] | 1312 | if ((Opcode == Instruction::Load && !isLegalMaskedLoad(SrcVTy)) || |
| 1313 | (Opcode == Instruction::Store && !isLegalMaskedStore(SrcVTy)) || |
Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 1314 | !isPowerOf2_32(NumElem)) { |
| 1315 | // Scalarization |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1316 | int MaskSplitCost = getScalarizationOverhead(MaskTy, false, true); |
| 1317 | int ScalarCompareCost = getCmpSelInstrCost( |
Mehdi Amini | 867e914 | 2016-04-14 04:36:40 +0000 | [diff] [blame] | 1318 | Instruction::ICmp, Type::getInt8Ty(SrcVTy->getContext()), nullptr); |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1319 | int BranchCost = getCFInstrCost(Instruction::Br); |
| 1320 | int MaskCmpCost = NumElem * (BranchCost + ScalarCompareCost); |
Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 1321 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1322 | int ValueSplitCost = getScalarizationOverhead( |
| 1323 | SrcVTy, Opcode == Instruction::Load, Opcode == Instruction::Store); |
| 1324 | int MemopCost = |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1325 | NumElem * BaseT::getMemoryOpCost(Opcode, SrcVTy->getScalarType(), |
| 1326 | Alignment, AddressSpace); |
Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 1327 | return MemopCost + ValueSplitCost + MaskSplitCost + MaskCmpCost; |
| 1328 | } |
| 1329 | |
| 1330 | // Legalize the type. |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1331 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, SrcVTy); |
Cong Hou | da4e8ae | 2015-10-28 18:15:46 +0000 | [diff] [blame] | 1332 | auto VT = TLI->getValueType(DL, SrcVTy); |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1333 | int Cost = 0; |
Cong Hou | da4e8ae | 2015-10-28 18:15:46 +0000 | [diff] [blame] | 1334 | if (VT.isSimple() && LT.second != VT.getSimpleVT() && |
Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 1335 | LT.second.getVectorNumElements() == NumElem) |
| 1336 | // Promotion requires expand/truncate for data and a shuffle for mask. |
Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 1337 | Cost += getShuffleCost(TTI::SK_Alternate, SrcVTy, 0, nullptr) + |
| 1338 | getShuffleCost(TTI::SK_Alternate, MaskTy, 0, nullptr); |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1339 | |
Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 1340 | else if (LT.second.getVectorNumElements() > NumElem) { |
| 1341 | VectorType *NewMaskTy = VectorType::get(MaskTy->getVectorElementType(), |
| 1342 | LT.second.getVectorNumElements()); |
| 1343 | // Expanding requires fill mask with zeroes |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1344 | Cost += getShuffleCost(TTI::SK_InsertSubvector, NewMaskTy, 0, MaskTy); |
Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 1345 | } |
| 1346 | if (!ST->hasAVX512()) |
| 1347 | return Cost + LT.first*4; // Each maskmov costs 4 |
| 1348 | |
| 1349 | // AVX-512 masked load/store is cheapper |
| 1350 | return Cost+LT.first; |
| 1351 | } |
| 1352 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1353 | int X86TTIImpl::getAddressComputationCost(Type *Ty, bool IsComplex) { |
Arnold Schwaighofer | 6042a26 | 2013-07-12 19:16:07 +0000 | [diff] [blame] | 1354 | // Address computations in vectorized code with non-consecutive addresses will |
| 1355 | // likely result in more instructions compared to scalar code where the |
| 1356 | // computation can more often be merged into the index mode. The resulting |
| 1357 | // extra micro-ops can significantly decrease throughput. |
| 1358 | unsigned NumVectorInstToHideOverhead = 10; |
| 1359 | |
| 1360 | if (Ty->isVectorTy() && IsComplex) |
| 1361 | return NumVectorInstToHideOverhead; |
| 1362 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1363 | return BaseT::getAddressComputationCost(Ty, IsComplex); |
Arnold Schwaighofer | 6042a26 | 2013-07-12 19:16:07 +0000 | [diff] [blame] | 1364 | } |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 1365 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1366 | int X86TTIImpl::getReductionCost(unsigned Opcode, Type *ValTy, |
| 1367 | bool IsPairwise) { |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 1368 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1369 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, ValTy); |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 1370 | |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 1371 | MVT MTy = LT.second; |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 1372 | |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 1373 | int ISD = TLI->InstructionOpcodeToISD(Opcode); |
| 1374 | assert(ISD && "Invalid opcode"); |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 1375 | |
| 1376 | // We use the Intel Architecture Code Analyzer(IACA) to measure the throughput |
| 1377 | // and make it as the cost. |
| 1378 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 1379 | static const CostTblEntry SSE42CostTblPairWise[] = { |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 1380 | { ISD::FADD, MVT::v2f64, 2 }, |
| 1381 | { ISD::FADD, MVT::v4f32, 4 }, |
| 1382 | { ISD::ADD, MVT::v2i64, 2 }, // The data reported by the IACA tool is "1.6". |
| 1383 | { ISD::ADD, MVT::v4i32, 3 }, // The data reported by the IACA tool is "3.5". |
| 1384 | { ISD::ADD, MVT::v8i16, 5 }, |
| 1385 | }; |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 1386 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 1387 | static const CostTblEntry AVX1CostTblPairWise[] = { |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 1388 | { ISD::FADD, MVT::v4f32, 4 }, |
| 1389 | { ISD::FADD, MVT::v4f64, 5 }, |
| 1390 | { ISD::FADD, MVT::v8f32, 7 }, |
| 1391 | { ISD::ADD, MVT::v2i64, 1 }, // The data reported by the IACA tool is "1.5". |
| 1392 | { ISD::ADD, MVT::v4i32, 3 }, // The data reported by the IACA tool is "3.5". |
| 1393 | { ISD::ADD, MVT::v4i64, 5 }, // The data reported by the IACA tool is "4.8". |
| 1394 | { ISD::ADD, MVT::v8i16, 5 }, |
| 1395 | { ISD::ADD, MVT::v8i32, 5 }, |
| 1396 | }; |
| 1397 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 1398 | static const CostTblEntry SSE42CostTblNoPairWise[] = { |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 1399 | { ISD::FADD, MVT::v2f64, 2 }, |
| 1400 | { ISD::FADD, MVT::v4f32, 4 }, |
| 1401 | { ISD::ADD, MVT::v2i64, 2 }, // The data reported by the IACA tool is "1.6". |
| 1402 | { ISD::ADD, MVT::v4i32, 3 }, // The data reported by the IACA tool is "3.3". |
| 1403 | { ISD::ADD, MVT::v8i16, 4 }, // The data reported by the IACA tool is "4.3". |
| 1404 | }; |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 1405 | |
Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 1406 | static const CostTblEntry AVX1CostTblNoPairWise[] = { |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 1407 | { ISD::FADD, MVT::v4f32, 3 }, |
| 1408 | { ISD::FADD, MVT::v4f64, 3 }, |
| 1409 | { ISD::FADD, MVT::v8f32, 4 }, |
| 1410 | { ISD::ADD, MVT::v2i64, 1 }, // The data reported by the IACA tool is "1.5". |
| 1411 | { ISD::ADD, MVT::v4i32, 3 }, // The data reported by the IACA tool is "2.8". |
| 1412 | { ISD::ADD, MVT::v4i64, 3 }, |
| 1413 | { ISD::ADD, MVT::v8i16, 4 }, |
| 1414 | { ISD::ADD, MVT::v8i32, 5 }, |
| 1415 | }; |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 1416 | |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 1417 | if (IsPairwise) { |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 1418 | if (ST->hasAVX()) |
| 1419 | if (const auto *Entry = CostTableLookup(AVX1CostTblPairWise, ISD, MTy)) |
| 1420 | return LT.first * Entry->Cost; |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 1421 | |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 1422 | if (ST->hasSSE42()) |
| 1423 | if (const auto *Entry = CostTableLookup(SSE42CostTblPairWise, ISD, MTy)) |
| 1424 | return LT.first * Entry->Cost; |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 1425 | } else { |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 1426 | if (ST->hasAVX()) |
| 1427 | if (const auto *Entry = CostTableLookup(AVX1CostTblNoPairWise, ISD, MTy)) |
| 1428 | return LT.first * Entry->Cost; |
Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 1429 | |
Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 1430 | if (ST->hasSSE42()) |
| 1431 | if (const auto *Entry = CostTableLookup(SSE42CostTblNoPairWise, ISD, MTy)) |
| 1432 | return LT.first * Entry->Cost; |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 1433 | } |
| 1434 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1435 | return BaseT::getReductionCost(Opcode, ValTy, IsPairwise); |
Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 1436 | } |
| 1437 | |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 1438 | /// \brief Calculate the cost of materializing a 64-bit value. This helper |
| 1439 | /// method might only calculate a fraction of a larger immediate. Therefore it |
| 1440 | /// is valid to return a cost of ZERO. |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1441 | int X86TTIImpl::getIntImmCost(int64_t Val) { |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 1442 | if (Val == 0) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1443 | return TTI::TCC_Free; |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 1444 | |
| 1445 | if (isInt<32>(Val)) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1446 | return TTI::TCC_Basic; |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 1447 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1448 | return 2 * TTI::TCC_Basic; |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1451 | int X86TTIImpl::getIntImmCost(const APInt &Imm, Type *Ty) { |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1452 | assert(Ty->isIntegerTy()); |
| 1453 | |
| 1454 | unsigned BitSize = Ty->getPrimitiveSizeInBits(); |
| 1455 | if (BitSize == 0) |
| 1456 | return ~0U; |
| 1457 | |
Juergen Ributzka | 4317617 | 2014-05-19 21:00:53 +0000 | [diff] [blame] | 1458 | // Never hoist constants larger than 128bit, because this might lead to |
| 1459 | // incorrect code generation or assertions in codegen. |
| 1460 | // Fixme: Create a cost model for types larger than i128 once the codegen |
| 1461 | // issues have been fixed. |
| 1462 | if (BitSize > 128) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1463 | return TTI::TCC_Free; |
Juergen Ributzka | 4317617 | 2014-05-19 21:00:53 +0000 | [diff] [blame] | 1464 | |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1465 | if (Imm == 0) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1466 | return TTI::TCC_Free; |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1467 | |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 1468 | // Sign-extend all constants to a multiple of 64-bit. |
| 1469 | APInt ImmVal = Imm; |
| 1470 | if (BitSize & 0x3f) |
| 1471 | ImmVal = Imm.sext((BitSize + 63) & ~0x3fU); |
| 1472 | |
| 1473 | // Split the constant into 64-bit chunks and calculate the cost for each |
| 1474 | // chunk. |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1475 | int Cost = 0; |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 1476 | for (unsigned ShiftVal = 0; ShiftVal < BitSize; ShiftVal += 64) { |
| 1477 | APInt Tmp = ImmVal.ashr(ShiftVal).sextOrTrunc(64); |
| 1478 | int64_t Val = Tmp.getSExtValue(); |
| 1479 | Cost += getIntImmCost(Val); |
| 1480 | } |
Sanjay Patel | 4c7d094 | 2016-04-05 19:27:39 +0000 | [diff] [blame] | 1481 | // We need at least one instruction to materialize the constant. |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1482 | return std::max(1, Cost); |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1483 | } |
| 1484 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1485 | int X86TTIImpl::getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, |
| 1486 | Type *Ty) { |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1487 | assert(Ty->isIntegerTy()); |
| 1488 | |
| 1489 | unsigned BitSize = Ty->getPrimitiveSizeInBits(); |
Juergen Ributzka | 4317617 | 2014-05-19 21:00:53 +0000 | [diff] [blame] | 1490 | // There is no cost model for constants with a bit size of 0. Return TCC_Free |
| 1491 | // here, so that constant hoisting will ignore this constant. |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1492 | if (BitSize == 0) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1493 | return TTI::TCC_Free; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1494 | |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1495 | unsigned ImmIdx = ~0U; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1496 | switch (Opcode) { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1497 | default: |
| 1498 | return TTI::TCC_Free; |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1499 | case Instruction::GetElementPtr: |
Juergen Ributzka | 27435b3 | 2014-04-02 21:45:36 +0000 | [diff] [blame] | 1500 | // Always hoist the base address of a GetElementPtr. This prevents the |
| 1501 | // creation of new constants for every base constant that gets constant |
| 1502 | // folded with the offset. |
Juergen Ributzka | 631c491 | 2014-03-25 18:01:25 +0000 | [diff] [blame] | 1503 | if (Idx == 0) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1504 | return 2 * TTI::TCC_Basic; |
| 1505 | return TTI::TCC_Free; |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1506 | case Instruction::Store: |
| 1507 | ImmIdx = 0; |
| 1508 | break; |
Craig Topper | 074e845 | 2015-12-20 18:41:54 +0000 | [diff] [blame] | 1509 | case Instruction::ICmp: |
| 1510 | // This is an imperfect hack to prevent constant hoisting of |
| 1511 | // compares that might be trying to check if a 64-bit value fits in |
| 1512 | // 32-bits. The backend can optimize these cases using a right shift by 32. |
| 1513 | // Ideally we would check the compare predicate here. There also other |
| 1514 | // similar immediates the backend can use shifts for. |
| 1515 | if (Idx == 1 && Imm.getBitWidth() == 64) { |
| 1516 | uint64_t ImmVal = Imm.getZExtValue(); |
| 1517 | if (ImmVal == 0x100000000ULL || ImmVal == 0xffffffff) |
| 1518 | return TTI::TCC_Free; |
| 1519 | } |
| 1520 | ImmIdx = 1; |
| 1521 | break; |
Craig Topper | 79dd1bf | 2015-10-06 02:50:24 +0000 | [diff] [blame] | 1522 | case Instruction::And: |
| 1523 | // We support 64-bit ANDs with immediates with 32-bits of leading zeroes |
| 1524 | // by using a 32-bit operation with implicit zero extension. Detect such |
| 1525 | // immediates here as the normal path expects bit 31 to be sign extended. |
| 1526 | if (Idx == 1 && Imm.getBitWidth() == 64 && isUInt<32>(Imm.getZExtValue())) |
| 1527 | return TTI::TCC_Free; |
Justin Bogner | b03fd12 | 2016-08-17 05:10:15 +0000 | [diff] [blame] | 1528 | LLVM_FALLTHROUGH; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1529 | case Instruction::Add: |
| 1530 | case Instruction::Sub: |
| 1531 | case Instruction::Mul: |
| 1532 | case Instruction::UDiv: |
| 1533 | case Instruction::SDiv: |
| 1534 | case Instruction::URem: |
| 1535 | case Instruction::SRem: |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1536 | case Instruction::Or: |
| 1537 | case Instruction::Xor: |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1538 | ImmIdx = 1; |
| 1539 | break; |
Michael Zolotukhin | 1f4a960 | 2014-04-30 19:17:32 +0000 | [diff] [blame] | 1540 | // Always return TCC_Free for the shift value of a shift instruction. |
| 1541 | case Instruction::Shl: |
| 1542 | case Instruction::LShr: |
| 1543 | case Instruction::AShr: |
| 1544 | if (Idx == 1) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1545 | return TTI::TCC_Free; |
Michael Zolotukhin | 1f4a960 | 2014-04-30 19:17:32 +0000 | [diff] [blame] | 1546 | break; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1547 | case Instruction::Trunc: |
| 1548 | case Instruction::ZExt: |
| 1549 | case Instruction::SExt: |
| 1550 | case Instruction::IntToPtr: |
| 1551 | case Instruction::PtrToInt: |
| 1552 | case Instruction::BitCast: |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1553 | case Instruction::PHI: |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1554 | case Instruction::Call: |
| 1555 | case Instruction::Select: |
| 1556 | case Instruction::Ret: |
| 1557 | case Instruction::Load: |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1558 | break; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1559 | } |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1560 | |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 1561 | if (Idx == ImmIdx) { |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1562 | int NumConstants = (BitSize + 63) / 64; |
| 1563 | int Cost = X86TTIImpl::getIntImmCost(Imm, Ty); |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1564 | return (Cost <= NumConstants * TTI::TCC_Basic) |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1565 | ? static_cast<int>(TTI::TCC_Free) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1566 | : Cost; |
Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 1567 | } |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1568 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1569 | return X86TTIImpl::getIntImmCost(Imm, Ty); |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1572 | int X86TTIImpl::getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, |
| 1573 | Type *Ty) { |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1574 | assert(Ty->isIntegerTy()); |
| 1575 | |
| 1576 | unsigned BitSize = Ty->getPrimitiveSizeInBits(); |
Juergen Ributzka | 4317617 | 2014-05-19 21:00:53 +0000 | [diff] [blame] | 1577 | // There is no cost model for constants with a bit size of 0. Return TCC_Free |
| 1578 | // here, so that constant hoisting will ignore this constant. |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1579 | if (BitSize == 0) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1580 | return TTI::TCC_Free; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1581 | |
| 1582 | switch (IID) { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1583 | default: |
| 1584 | return TTI::TCC_Free; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1585 | case Intrinsic::sadd_with_overflow: |
| 1586 | case Intrinsic::uadd_with_overflow: |
| 1587 | case Intrinsic::ssub_with_overflow: |
| 1588 | case Intrinsic::usub_with_overflow: |
| 1589 | case Intrinsic::smul_with_overflow: |
| 1590 | case Intrinsic::umul_with_overflow: |
Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 1591 | if ((Idx == 1) && Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue())) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1592 | return TTI::TCC_Free; |
Juergen Ributzka | 5eef98c | 2014-03-25 18:01:23 +0000 | [diff] [blame] | 1593 | break; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1594 | case Intrinsic::experimental_stackmap: |
Juergen Ributzka | 5eef98c | 2014-03-25 18:01:23 +0000 | [diff] [blame] | 1595 | if ((Idx < 2) || (Imm.getBitWidth() <= 64 && isInt<64>(Imm.getSExtValue()))) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1596 | return TTI::TCC_Free; |
Juergen Ributzka | 5eef98c | 2014-03-25 18:01:23 +0000 | [diff] [blame] | 1597 | break; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1598 | case Intrinsic::experimental_patchpoint_void: |
| 1599 | case Intrinsic::experimental_patchpoint_i64: |
Juergen Ributzka | 5eef98c | 2014-03-25 18:01:23 +0000 | [diff] [blame] | 1600 | if ((Idx < 4) || (Imm.getBitWidth() <= 64 && isInt<64>(Imm.getSExtValue()))) |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1601 | return TTI::TCC_Free; |
Juergen Ributzka | 5eef98c | 2014-03-25 18:01:23 +0000 | [diff] [blame] | 1602 | break; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1603 | } |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1604 | return X86TTIImpl::getIntImmCost(Imm, Ty); |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 1605 | } |
NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 1606 | |
Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 1607 | // Return an average cost of Gather / Scatter instruction, maybe improved later |
| 1608 | int X86TTIImpl::getGSVectorCost(unsigned Opcode, Type *SrcVTy, Value *Ptr, |
| 1609 | unsigned Alignment, unsigned AddressSpace) { |
| 1610 | |
| 1611 | assert(isa<VectorType>(SrcVTy) && "Unexpected type in getGSVectorCost"); |
| 1612 | unsigned VF = SrcVTy->getVectorNumElements(); |
| 1613 | |
| 1614 | // Try to reduce index size from 64 bit (default for GEP) |
| 1615 | // to 32. It is essential for VF 16. If the index can't be reduced to 32, the |
| 1616 | // operation will use 16 x 64 indices which do not fit in a zmm and needs |
| 1617 | // to split. Also check that the base pointer is the same for all lanes, |
| 1618 | // and that there's at most one variable index. |
| 1619 | auto getIndexSizeInBits = [](Value *Ptr, const DataLayout& DL) { |
| 1620 | unsigned IndexSize = DL.getPointerSizeInBits(); |
| 1621 | GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr); |
| 1622 | if (IndexSize < 64 || !GEP) |
| 1623 | return IndexSize; |
Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 1624 | |
Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 1625 | unsigned NumOfVarIndices = 0; |
| 1626 | Value *Ptrs = GEP->getPointerOperand(); |
| 1627 | if (Ptrs->getType()->isVectorTy() && !getSplatValue(Ptrs)) |
| 1628 | return IndexSize; |
| 1629 | for (unsigned i = 1; i < GEP->getNumOperands(); ++i) { |
| 1630 | if (isa<Constant>(GEP->getOperand(i))) |
| 1631 | continue; |
| 1632 | Type *IndxTy = GEP->getOperand(i)->getType(); |
| 1633 | if (IndxTy->isVectorTy()) |
| 1634 | IndxTy = IndxTy->getVectorElementType(); |
| 1635 | if ((IndxTy->getPrimitiveSizeInBits() == 64 && |
| 1636 | !isa<SExtInst>(GEP->getOperand(i))) || |
| 1637 | ++NumOfVarIndices > 1) |
| 1638 | return IndexSize; // 64 |
| 1639 | } |
| 1640 | return (unsigned)32; |
| 1641 | }; |
| 1642 | |
| 1643 | |
| 1644 | // Trying to reduce IndexSize to 32 bits for vector 16. |
| 1645 | // By default the IndexSize is equal to pointer size. |
| 1646 | unsigned IndexSize = (VF >= 16) ? getIndexSizeInBits(Ptr, DL) : |
| 1647 | DL.getPointerSizeInBits(); |
| 1648 | |
Mehdi Amini | 867e914 | 2016-04-14 04:36:40 +0000 | [diff] [blame] | 1649 | Type *IndexVTy = VectorType::get(IntegerType::get(SrcVTy->getContext(), |
Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 1650 | IndexSize), VF); |
| 1651 | std::pair<int, MVT> IdxsLT = TLI->getTypeLegalizationCost(DL, IndexVTy); |
| 1652 | std::pair<int, MVT> SrcLT = TLI->getTypeLegalizationCost(DL, SrcVTy); |
| 1653 | int SplitFactor = std::max(IdxsLT.first, SrcLT.first); |
| 1654 | if (SplitFactor > 1) { |
| 1655 | // Handle splitting of vector of pointers |
| 1656 | Type *SplitSrcTy = VectorType::get(SrcVTy->getScalarType(), VF / SplitFactor); |
| 1657 | return SplitFactor * getGSVectorCost(Opcode, SplitSrcTy, Ptr, Alignment, |
| 1658 | AddressSpace); |
| 1659 | } |
| 1660 | |
| 1661 | // The gather / scatter cost is given by Intel architects. It is a rough |
| 1662 | // number since we are looking at one instruction in a time. |
| 1663 | const int GSOverhead = 2; |
| 1664 | return GSOverhead + VF * getMemoryOpCost(Opcode, SrcVTy->getScalarType(), |
| 1665 | Alignment, AddressSpace); |
| 1666 | } |
| 1667 | |
| 1668 | /// Return the cost of full scalarization of gather / scatter operation. |
| 1669 | /// |
| 1670 | /// Opcode - Load or Store instruction. |
| 1671 | /// SrcVTy - The type of the data vector that should be gathered or scattered. |
| 1672 | /// VariableMask - The mask is non-constant at compile time. |
| 1673 | /// Alignment - Alignment for one element. |
| 1674 | /// AddressSpace - pointer[s] address space. |
| 1675 | /// |
| 1676 | int X86TTIImpl::getGSScalarCost(unsigned Opcode, Type *SrcVTy, |
| 1677 | bool VariableMask, unsigned Alignment, |
| 1678 | unsigned AddressSpace) { |
| 1679 | unsigned VF = SrcVTy->getVectorNumElements(); |
| 1680 | |
| 1681 | int MaskUnpackCost = 0; |
| 1682 | if (VariableMask) { |
| 1683 | VectorType *MaskTy = |
Mehdi Amini | 867e914 | 2016-04-14 04:36:40 +0000 | [diff] [blame] | 1684 | VectorType::get(Type::getInt1Ty(SrcVTy->getContext()), VF); |
Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 1685 | MaskUnpackCost = getScalarizationOverhead(MaskTy, false, true); |
| 1686 | int ScalarCompareCost = |
Mehdi Amini | 867e914 | 2016-04-14 04:36:40 +0000 | [diff] [blame] | 1687 | getCmpSelInstrCost(Instruction::ICmp, Type::getInt1Ty(SrcVTy->getContext()), |
Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 1688 | nullptr); |
| 1689 | int BranchCost = getCFInstrCost(Instruction::Br); |
| 1690 | MaskUnpackCost += VF * (BranchCost + ScalarCompareCost); |
| 1691 | } |
| 1692 | |
| 1693 | // The cost of the scalar loads/stores. |
| 1694 | int MemoryOpCost = VF * getMemoryOpCost(Opcode, SrcVTy->getScalarType(), |
| 1695 | Alignment, AddressSpace); |
| 1696 | |
| 1697 | int InsertExtractCost = 0; |
| 1698 | if (Opcode == Instruction::Load) |
| 1699 | for (unsigned i = 0; i < VF; ++i) |
| 1700 | // Add the cost of inserting each scalar load into the vector |
| 1701 | InsertExtractCost += |
| 1702 | getVectorInstrCost(Instruction::InsertElement, SrcVTy, i); |
| 1703 | else |
| 1704 | for (unsigned i = 0; i < VF; ++i) |
| 1705 | // Add the cost of extracting each element out of the data vector |
| 1706 | InsertExtractCost += |
| 1707 | getVectorInstrCost(Instruction::ExtractElement, SrcVTy, i); |
| 1708 | |
| 1709 | return MemoryOpCost + MaskUnpackCost + InsertExtractCost; |
| 1710 | } |
| 1711 | |
| 1712 | /// Calculate the cost of Gather / Scatter operation |
| 1713 | int X86TTIImpl::getGatherScatterOpCost(unsigned Opcode, Type *SrcVTy, |
| 1714 | Value *Ptr, bool VariableMask, |
| 1715 | unsigned Alignment) { |
| 1716 | assert(SrcVTy->isVectorTy() && "Unexpected data type for Gather/Scatter"); |
| 1717 | unsigned VF = SrcVTy->getVectorNumElements(); |
| 1718 | PointerType *PtrTy = dyn_cast<PointerType>(Ptr->getType()); |
| 1719 | if (!PtrTy && Ptr->getType()->isVectorTy()) |
| 1720 | PtrTy = dyn_cast<PointerType>(Ptr->getType()->getVectorElementType()); |
| 1721 | assert(PtrTy && "Unexpected type for Ptr argument"); |
| 1722 | unsigned AddressSpace = PtrTy->getAddressSpace(); |
| 1723 | |
| 1724 | bool Scalarize = false; |
| 1725 | if ((Opcode == Instruction::Load && !isLegalMaskedGather(SrcVTy)) || |
| 1726 | (Opcode == Instruction::Store && !isLegalMaskedScatter(SrcVTy))) |
| 1727 | Scalarize = true; |
| 1728 | // Gather / Scatter for vector 2 is not profitable on KNL / SKX |
| 1729 | // Vector-4 of gather/scatter instruction does not exist on KNL. |
| 1730 | // We can extend it to 8 elements, but zeroing upper bits of |
| 1731 | // the mask vector will add more instructions. Right now we give the scalar |
| 1732 | // cost of vector-4 for KNL. TODO: Check, maybe the gather/scatter instruction is |
| 1733 | // better in the VariableMask case. |
| 1734 | if (VF == 2 || (VF == 4 && !ST->hasVLX())) |
| 1735 | Scalarize = true; |
| 1736 | |
| 1737 | if (Scalarize) |
| 1738 | return getGSScalarCost(Opcode, SrcVTy, VariableMask, Alignment, AddressSpace); |
| 1739 | |
| 1740 | return getGSVectorCost(Opcode, SrcVTy, Ptr, Alignment, AddressSpace); |
| 1741 | } |
| 1742 | |
Elena Demikhovsky | 20662e3 | 2015-10-19 07:43:38 +0000 | [diff] [blame] | 1743 | bool X86TTIImpl::isLegalMaskedLoad(Type *DataTy) { |
| 1744 | Type *ScalarTy = DataTy->getScalarType(); |
Elena Demikhovsky | 1ca72e1 | 2015-11-19 07:17:16 +0000 | [diff] [blame] | 1745 | int DataWidth = isa<PointerType>(ScalarTy) ? |
| 1746 | DL.getPointerSizeInBits() : ScalarTy->getPrimitiveSizeInBits(); |
NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 1747 | |
Igor Breger | f44b79d | 2016-08-02 09:15:28 +0000 | [diff] [blame] | 1748 | return ((DataWidth == 32 || DataWidth == 64) && ST->hasAVX()) || |
| 1749 | ((DataWidth == 8 || DataWidth == 16) && ST->hasBWI()); |
NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 1750 | } |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 1751 | |
Elena Demikhovsky | 20662e3 | 2015-10-19 07:43:38 +0000 | [diff] [blame] | 1752 | bool X86TTIImpl::isLegalMaskedStore(Type *DataType) { |
| 1753 | return isLegalMaskedLoad(DataType); |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 1754 | } |
| 1755 | |
Elena Demikhovsky | 0928585 | 2015-10-25 15:37:55 +0000 | [diff] [blame] | 1756 | bool X86TTIImpl::isLegalMaskedGather(Type *DataTy) { |
| 1757 | // This function is called now in two cases: from the Loop Vectorizer |
| 1758 | // and from the Scalarizer. |
| 1759 | // When the Loop Vectorizer asks about legality of the feature, |
| 1760 | // the vectorization factor is not calculated yet. The Loop Vectorizer |
| 1761 | // sends a scalar type and the decision is based on the width of the |
| 1762 | // scalar element. |
| 1763 | // Later on, the cost model will estimate usage this intrinsic based on |
| 1764 | // the vector type. |
| 1765 | // The Scalarizer asks again about legality. It sends a vector type. |
| 1766 | // In this case we can reject non-power-of-2 vectors. |
| 1767 | if (isa<VectorType>(DataTy) && !isPowerOf2_32(DataTy->getVectorNumElements())) |
| 1768 | return false; |
| 1769 | Type *ScalarTy = DataTy->getScalarType(); |
Elena Demikhovsky | 1ca72e1 | 2015-11-19 07:17:16 +0000 | [diff] [blame] | 1770 | int DataWidth = isa<PointerType>(ScalarTy) ? |
| 1771 | DL.getPointerSizeInBits() : ScalarTy->getPrimitiveSizeInBits(); |
Elena Demikhovsky | 0928585 | 2015-10-25 15:37:55 +0000 | [diff] [blame] | 1772 | |
| 1773 | // AVX-512 allows gather and scatter |
Igor Breger | f44b79d | 2016-08-02 09:15:28 +0000 | [diff] [blame] | 1774 | return (DataWidth == 32 || DataWidth == 64) && ST->hasAVX512(); |
Elena Demikhovsky | 0928585 | 2015-10-25 15:37:55 +0000 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | bool X86TTIImpl::isLegalMaskedScatter(Type *DataType) { |
| 1778 | return isLegalMaskedGather(DataType); |
| 1779 | } |
| 1780 | |
Eric Christopher | d566fb1 | 2015-07-29 22:09:48 +0000 | [diff] [blame] | 1781 | bool X86TTIImpl::areInlineCompatible(const Function *Caller, |
| 1782 | const Function *Callee) const { |
Eric Christopher | e100226 | 2015-07-02 01:11:50 +0000 | [diff] [blame] | 1783 | const TargetMachine &TM = getTLI()->getTargetMachine(); |
| 1784 | |
| 1785 | // Work this as a subsetting of subtarget features. |
| 1786 | const FeatureBitset &CallerBits = |
| 1787 | TM.getSubtargetImpl(*Caller)->getFeatureBits(); |
| 1788 | const FeatureBitset &CalleeBits = |
| 1789 | TM.getSubtargetImpl(*Callee)->getFeatureBits(); |
| 1790 | |
| 1791 | // FIXME: This is likely too limiting as it will include subtarget features |
| 1792 | // that we might not care about for inlining, but it is conservatively |
| 1793 | // correct. |
| 1794 | return (CallerBits & CalleeBits) == CalleeBits; |
| 1795 | } |
Michael Kuperstein | b2443ed | 2016-10-20 21:04:31 +0000 | [diff] [blame] | 1796 | |
| 1797 | bool X86TTIImpl::enableInterleavedAccessVectorization() { |
| 1798 | // TODO: We expect this to be beneficial regardless of arch, |
| 1799 | // but there are currently some unexplained performance artifacts on Atom. |
| 1800 | // As a temporary solution, disable on Atom. |
| 1801 | return !(ST->isAtom() || ST->isSLM()); |
| 1802 | } |