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