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