| 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" |
| David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 45 | #include "llvm/CodeGen/CostTable.h" |
| 46 | #include "llvm/CodeGen/TargetLowering.h" |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 47 | #include "llvm/IR/IntrinsicInst.h" |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 48 | #include "llvm/Support/Debug.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 | |
| Tobias Grosser | d7eb619 | 2017-08-24 09:46:25 +0000 | [diff] [blame] | 69 | llvm::Optional<unsigned> X86TTIImpl::getCacheSize( |
| 70 | TargetTransformInfo::CacheLevel Level) const { |
| 71 | switch (Level) { |
| 72 | case TargetTransformInfo::CacheLevel::L1D: |
| Craig Topper | d5b5bbe | 2017-11-22 18:23:40 +0000 | [diff] [blame] | 73 | // - Penryn |
| Tobias Grosser | d7eb619 | 2017-08-24 09:46:25 +0000 | [diff] [blame] | 74 | // - Nehalem |
| 75 | // - Westmere |
| 76 | // - Sandy Bridge |
| 77 | // - Ivy Bridge |
| 78 | // - Haswell |
| 79 | // - Broadwell |
| 80 | // - Skylake |
| 81 | // - Kabylake |
| 82 | return 32 * 1024; // 32 KByte |
| 83 | case TargetTransformInfo::CacheLevel::L2D: |
| Craig Topper | d5b5bbe | 2017-11-22 18:23:40 +0000 | [diff] [blame] | 84 | // - Penryn |
| Tobias Grosser | d7eb619 | 2017-08-24 09:46:25 +0000 | [diff] [blame] | 85 | // - Nehalem |
| 86 | // - Westmere |
| 87 | // - Sandy Bridge |
| 88 | // - Ivy Bridge |
| 89 | // - Haswell |
| 90 | // - Broadwell |
| 91 | // - Skylake |
| 92 | // - Kabylake |
| 93 | return 256 * 1024; // 256 KByte |
| 94 | } |
| 95 | |
| 96 | llvm_unreachable("Unknown TargetTransformInfo::CacheLevel"); |
| 97 | } |
| 98 | |
| 99 | llvm::Optional<unsigned> X86TTIImpl::getCacheAssociativity( |
| 100 | TargetTransformInfo::CacheLevel Level) const { |
| Craig Topper | d5b5bbe | 2017-11-22 18:23:40 +0000 | [diff] [blame] | 101 | // - Penryn |
| Tobias Grosser | d7eb619 | 2017-08-24 09:46:25 +0000 | [diff] [blame] | 102 | // - Nehalem |
| 103 | // - Westmere |
| 104 | // - Sandy Bridge |
| 105 | // - Ivy Bridge |
| 106 | // - Haswell |
| 107 | // - Broadwell |
| 108 | // - Skylake |
| 109 | // - Kabylake |
| 110 | switch (Level) { |
| 111 | case TargetTransformInfo::CacheLevel::L1D: |
| 112 | LLVM_FALLTHROUGH; |
| 113 | case TargetTransformInfo::CacheLevel::L2D: |
| 114 | return 8; |
| 115 | } |
| 116 | |
| 117 | llvm_unreachable("Unknown TargetTransformInfo::CacheLevel"); |
| 118 | } |
| 119 | |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 120 | unsigned X86TTIImpl::getNumberOfRegisters(bool Vector) { |
| Nadav Rotem | b1791a7 | 2013-01-09 22:29:00 +0000 | [diff] [blame] | 121 | if (Vector && !ST->hasSSE1()) |
| 122 | return 0; |
| 123 | |
| Adam Nemet | 2820a5b | 2014-07-09 18:22:33 +0000 | [diff] [blame] | 124 | if (ST->is64Bit()) { |
| 125 | if (Vector && ST->hasAVX512()) |
| 126 | return 32; |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 127 | return 16; |
| Adam Nemet | 2820a5b | 2014-07-09 18:22:33 +0000 | [diff] [blame] | 128 | } |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 129 | return 8; |
| 130 | } |
| 131 | |
| Keno Fischer | 1ec5dd8 | 2017-04-05 20:51:38 +0000 | [diff] [blame] | 132 | unsigned X86TTIImpl::getRegisterBitWidth(bool Vector) const { |
| Craig Topper | 0d797a3 | 2018-01-20 00:26:08 +0000 | [diff] [blame] | 133 | unsigned PreferVectorWidth = ST->getPreferVectorWidth(); |
| Nadav Rotem | b1791a7 | 2013-01-09 22:29:00 +0000 | [diff] [blame] | 134 | if (Vector) { |
| Craig Topper | 0d797a3 | 2018-01-20 00:26:08 +0000 | [diff] [blame] | 135 | if (ST->hasAVX512() && PreferVectorWidth >= 512) |
| Mohammed Agabaria | 189e2d2 | 2017-01-05 09:51:02 +0000 | [diff] [blame] | 136 | return 512; |
| Craig Topper | 0d797a3 | 2018-01-20 00:26:08 +0000 | [diff] [blame] | 137 | if (ST->hasAVX() && PreferVectorWidth >= 256) |
| Mohammed Agabaria | 189e2d2 | 2017-01-05 09:51:02 +0000 | [diff] [blame] | 138 | return 256; |
| Craig Topper | 0d797a3 | 2018-01-20 00:26:08 +0000 | [diff] [blame] | 139 | if (ST->hasSSE1() && PreferVectorWidth >= 128) |
| Mohammed Agabaria | 189e2d2 | 2017-01-05 09:51:02 +0000 | [diff] [blame] | 140 | return 128; |
| Nadav Rotem | b1791a7 | 2013-01-09 22:29:00 +0000 | [diff] [blame] | 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | if (ST->is64Bit()) |
| 145 | return 64; |
| Nadav Rotem | b1791a7 | 2013-01-09 22:29:00 +0000 | [diff] [blame] | 146 | |
| Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 147 | return 32; |
| Nadav Rotem | b1791a7 | 2013-01-09 22:29:00 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| Keno Fischer | 1ec5dd8 | 2017-04-05 20:51:38 +0000 | [diff] [blame] | 150 | unsigned X86TTIImpl::getLoadStoreVecRegBitWidth(unsigned) const { |
| 151 | return getRegisterBitWidth(true); |
| 152 | } |
| 153 | |
| Wei Mi | 062c744 | 2015-05-06 17:12:25 +0000 | [diff] [blame] | 154 | unsigned X86TTIImpl::getMaxInterleaveFactor(unsigned VF) { |
| 155 | // If the loop will not be vectorized, don't interleave the loop. |
| 156 | // Let regular unroll to unroll the loop, which saves the overflow |
| 157 | // check and memory check cost. |
| 158 | if (VF == 1) |
| 159 | return 1; |
| 160 | |
| Nadav Rotem | b696c36 | 2013-01-09 01:15:42 +0000 | [diff] [blame] | 161 | if (ST->isAtom()) |
| 162 | return 1; |
| 163 | |
| 164 | // Sandybridge and Haswell have multiple execution ports and pipelined |
| 165 | // vector units. |
| 166 | if (ST->hasAVX()) |
| 167 | return 4; |
| 168 | |
| 169 | return 2; |
| 170 | } |
| 171 | |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 172 | int X86TTIImpl::getArithmeticInstrCost( |
| Simon Pilgrim | 3e5b525 | 2017-01-20 15:15:59 +0000 | [diff] [blame] | 173 | unsigned Opcode, Type *Ty, |
| Mohammed Agabaria | 2c96c43 | 2017-01-11 08:23:37 +0000 | [diff] [blame] | 174 | TTI::OperandValueKind Op1Info, TTI::OperandValueKind Op2Info, |
| 175 | TTI::OperandValueProperties Opd1PropInfo, |
| 176 | TTI::OperandValueProperties Opd2PropInfo, |
| 177 | ArrayRef<const Value *> Args) { |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 178 | // Legalize the type. |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 179 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Ty); |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 180 | |
| 181 | int ISD = TLI->InstructionOpcodeToISD(Opcode); |
| 182 | assert(ISD && "Invalid opcode"); |
| 183 | |
| Craig Topper | a985919 | 2018-03-25 15:58:12 +0000 | [diff] [blame] | 184 | static const CostTblEntry GLMCostTable[] = { |
| 185 | { ISD::FDIV, MVT::f32, 18 }, // divss |
| 186 | { ISD::FDIV, MVT::v4f32, 35 }, // divps |
| 187 | { ISD::FDIV, MVT::f64, 33 }, // divsd |
| 188 | { ISD::FDIV, MVT::v2f64, 65 }, // divpd |
| 189 | }; |
| 190 | |
| 191 | if (ST->isGLM()) |
| 192 | if (const auto *Entry = CostTableLookup(GLMCostTable, ISD, |
| 193 | LT.second)) |
| 194 | return LT.first * Entry->Cost; |
| 195 | |
| Mohammed Agabaria | 2c96c43 | 2017-01-11 08:23:37 +0000 | [diff] [blame] | 196 | static const CostTblEntry SLMCostTable[] = { |
| Craig Topper | a985919 | 2018-03-25 15:58:12 +0000 | [diff] [blame] | 197 | { ISD::MUL, MVT::v4i32, 11 }, // pmulld |
| 198 | { ISD::MUL, MVT::v8i16, 2 }, // pmullw |
| 199 | { ISD::MUL, MVT::v16i8, 14 }, // extend/pmullw/trunc sequence. |
| 200 | { ISD::FMUL, MVT::f64, 2 }, // mulsd |
| 201 | { ISD::FMUL, MVT::v2f64, 4 }, // mulpd |
| 202 | { ISD::FMUL, MVT::v4f32, 2 }, // mulps |
| 203 | { ISD::FDIV, MVT::f32, 17 }, // divss |
| 204 | { ISD::FDIV, MVT::v4f32, 39 }, // divps |
| 205 | { ISD::FDIV, MVT::f64, 32 }, // divsd |
| 206 | { ISD::FDIV, MVT::v2f64, 69 }, // divpd |
| 207 | { ISD::FADD, MVT::v2f64, 2 }, // addpd |
| 208 | { ISD::FSUB, MVT::v2f64, 2 }, // subpd |
| Mohammed Agabaria | eb09a81 | 2017-07-02 12:16:15 +0000 | [diff] [blame] | 209 | // v2i64/v4i64 mul is custom lowered as a series of long: |
| 210 | // multiplies(3), shifts(3) and adds(2) |
| Simon Pilgrim | 7b89ab5 | 2017-07-31 17:09:27 +0000 | [diff] [blame] | 211 | // slm muldq version throughput is 2 and addq throughput 4 |
| Simon Pilgrim | eb07016 | 2018-01-30 12:18:51 +0000 | [diff] [blame] | 212 | // thus: 3X2 (muldq throughput) + 3X1 (shift throughput) + |
| Simon Pilgrim | 7b89ab5 | 2017-07-31 17:09:27 +0000 | [diff] [blame] | 213 | // 3X4 (addq throughput) = 17 |
| Craig Topper | a985919 | 2018-03-25 15:58:12 +0000 | [diff] [blame] | 214 | { ISD::MUL, MVT::v2i64, 17 }, |
| Mohammed Agabaria | eb09a81 | 2017-07-02 12:16:15 +0000 | [diff] [blame] | 215 | // slm addq\subq throughput is 4 |
| Craig Topper | a985919 | 2018-03-25 15:58:12 +0000 | [diff] [blame] | 216 | { ISD::ADD, MVT::v2i64, 4 }, |
| 217 | { ISD::SUB, MVT::v2i64, 4 }, |
| Mohammed Agabaria | 2c96c43 | 2017-01-11 08:23:37 +0000 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | if (ST->isSLM()) { |
| 221 | if (Args.size() == 2 && ISD == ISD::MUL && LT.second == MVT::v4i32) { |
| 222 | // Check if the operands can be shrinked into a smaller datatype. |
| 223 | bool Op1Signed = false; |
| 224 | unsigned Op1MinSize = BaseT::minRequiredElementSize(Args[0], Op1Signed); |
| 225 | bool Op2Signed = false; |
| 226 | unsigned Op2MinSize = BaseT::minRequiredElementSize(Args[1], Op2Signed); |
| 227 | |
| 228 | bool signedMode = Op1Signed | Op2Signed; |
| 229 | unsigned OpMinSize = std::max(Op1MinSize, Op2MinSize); |
| 230 | |
| 231 | if (OpMinSize <= 7) |
| 232 | return LT.first * 3; // pmullw/sext |
| 233 | if (!signedMode && OpMinSize <= 8) |
| 234 | return LT.first * 3; // pmullw/zext |
| 235 | if (OpMinSize <= 15) |
| 236 | return LT.first * 5; // pmullw/pmulhw/pshuf |
| 237 | if (!signedMode && OpMinSize <= 16) |
| 238 | return LT.first * 5; // pmullw/pmulhw/pshuf |
| 239 | } |
| Craig Topper | a985919 | 2018-03-25 15:58:12 +0000 | [diff] [blame] | 240 | |
| Mohammed Agabaria | 2c96c43 | 2017-01-11 08:23:37 +0000 | [diff] [blame] | 241 | if (const auto *Entry = CostTableLookup(SLMCostTable, ISD, |
| 242 | LT.second)) { |
| 243 | return LT.first * Entry->Cost; |
| 244 | } |
| 245 | } |
| 246 | |
| Karthik Bhat | 7f33ff7 | 2014-08-25 04:56:54 +0000 | [diff] [blame] | 247 | if (ISD == ISD::SDIV && |
| 248 | Op2Info == TargetTransformInfo::OK_UniformConstantValue && |
| 249 | Opd2PropInfo == TargetTransformInfo::OP_PowerOf2) { |
| 250 | // On X86, vector signed division by constants power-of-two are |
| 251 | // normally expanded to the sequence SRA + SRL + ADD + SRA. |
| 252 | // The OperandValue properties many not be same as that of previous |
| 253 | // operation;conservatively assume OP_None. |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 254 | int Cost = 2 * getArithmeticInstrCost(Instruction::AShr, Ty, Op1Info, |
| 255 | Op2Info, TargetTransformInfo::OP_None, |
| 256 | TargetTransformInfo::OP_None); |
| Karthik Bhat | 7f33ff7 | 2014-08-25 04:56:54 +0000 | [diff] [blame] | 257 | Cost += getArithmeticInstrCost(Instruction::LShr, Ty, Op1Info, Op2Info, |
| 258 | TargetTransformInfo::OP_None, |
| 259 | TargetTransformInfo::OP_None); |
| 260 | Cost += getArithmeticInstrCost(Instruction::Add, Ty, Op1Info, Op2Info, |
| 261 | TargetTransformInfo::OP_None, |
| 262 | TargetTransformInfo::OP_None); |
| 263 | |
| 264 | return Cost; |
| 265 | } |
| 266 | |
| Simon Pilgrim | 365be4f | 2016-10-20 18:00:35 +0000 | [diff] [blame] | 267 | static const CostTblEntry AVX512BWUniformConstCostTable[] = { |
| Simon Pilgrim | 9c58950 | 2017-01-08 14:14:36 +0000 | [diff] [blame] | 268 | { ISD::SHL, MVT::v64i8, 2 }, // psllw + pand. |
| 269 | { ISD::SRL, MVT::v64i8, 2 }, // psrlw + pand. |
| 270 | { ISD::SRA, MVT::v64i8, 4 }, // psrlw, pand, pxor, psubb. |
| 271 | |
| Simon Pilgrim | 365be4f | 2016-10-20 18:00:35 +0000 | [diff] [blame] | 272 | { ISD::SDIV, MVT::v32i16, 6 }, // vpmulhw sequence |
| 273 | { ISD::UDIV, MVT::v32i16, 6 }, // vpmulhuw sequence |
| 274 | }; |
| 275 | |
| 276 | if (Op2Info == TargetTransformInfo::OK_UniformConstantValue && |
| 277 | ST->hasBWI()) { |
| 278 | if (const auto *Entry = CostTableLookup(AVX512BWUniformConstCostTable, ISD, |
| 279 | LT.second)) |
| 280 | return LT.first * Entry->Cost; |
| 281 | } |
| 282 | |
| 283 | static const CostTblEntry AVX512UniformConstCostTable[] = { |
| Simon Pilgrim | d419b73 | 2017-01-14 19:24:23 +0000 | [diff] [blame] | 284 | { ISD::SRA, MVT::v2i64, 1 }, |
| 285 | { ISD::SRA, MVT::v4i64, 1 }, |
| 286 | { ISD::SRA, MVT::v8i64, 1 }, |
| 287 | |
| Simon Pilgrim | 365be4f | 2016-10-20 18:00:35 +0000 | [diff] [blame] | 288 | { ISD::SDIV, MVT::v16i32, 15 }, // vpmuldq sequence |
| 289 | { ISD::UDIV, MVT::v16i32, 15 }, // vpmuludq sequence |
| 290 | }; |
| 291 | |
| 292 | if (Op2Info == TargetTransformInfo::OK_UniformConstantValue && |
| 293 | ST->hasAVX512()) { |
| 294 | if (const auto *Entry = CostTableLookup(AVX512UniformConstCostTable, ISD, |
| 295 | LT.second)) |
| 296 | return LT.first * Entry->Cost; |
| 297 | } |
| 298 | |
| Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 299 | static const CostTblEntry AVX2UniformConstCostTable[] = { |
| Simon Pilgrim | 9c58950 | 2017-01-08 14:14:36 +0000 | [diff] [blame] | 300 | { ISD::SHL, MVT::v32i8, 2 }, // psllw + pand. |
| 301 | { ISD::SRL, MVT::v32i8, 2 }, // psrlw + pand. |
| 302 | { ISD::SRA, MVT::v32i8, 4 }, // psrlw, pand, pxor, psubb. |
| 303 | |
| Simon Pilgrim | 8fbf1c1 | 2015-07-06 22:35:19 +0000 | [diff] [blame] | 304 | { ISD::SRA, MVT::v4i64, 4 }, // 2 x psrad + shuffle. |
| 305 | |
| Benjamin Kramer | 7c37227 | 2014-04-26 14:53:05 +0000 | [diff] [blame] | 306 | { ISD::SDIV, MVT::v16i16, 6 }, // vpmulhw sequence |
| 307 | { ISD::UDIV, MVT::v16i16, 6 }, // vpmulhuw sequence |
| 308 | { ISD::SDIV, MVT::v8i32, 15 }, // vpmuldq sequence |
| 309 | { ISD::UDIV, MVT::v8i32, 15 }, // vpmuludq sequence |
| 310 | }; |
| 311 | |
| 312 | if (Op2Info == TargetTransformInfo::OK_UniformConstantValue && |
| 313 | ST->hasAVX2()) { |
| Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 314 | if (const auto *Entry = CostTableLookup(AVX2UniformConstCostTable, ISD, |
| 315 | LT.second)) |
| 316 | return LT.first * Entry->Cost; |
| Benjamin Kramer | 7c37227 | 2014-04-26 14:53:05 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| Simon Pilgrim | 365be4f | 2016-10-20 18:00:35 +0000 | [diff] [blame] | 319 | static const CostTblEntry SSE2UniformConstCostTable[] = { |
| Simon Pilgrim | d3f0d03 | 2017-05-14 18:52:15 +0000 | [diff] [blame] | 320 | { ISD::SHL, MVT::v16i8, 2 }, // psllw + pand. |
| 321 | { ISD::SRL, MVT::v16i8, 2 }, // psrlw + pand. |
| 322 | { ISD::SRA, MVT::v16i8, 4 }, // psrlw, pand, pxor, psubb. |
| Simon Pilgrim | 9c58950 | 2017-01-08 14:14:36 +0000 | [diff] [blame] | 323 | |
| Simon Pilgrim | d3f0d03 | 2017-05-14 18:52:15 +0000 | [diff] [blame] | 324 | { ISD::SHL, MVT::v32i8, 4+2 }, // 2*(psllw + pand) + split. |
| 325 | { ISD::SRL, MVT::v32i8, 4+2 }, // 2*(psrlw + pand) + split. |
| 326 | { ISD::SRA, MVT::v32i8, 8+2 }, // 2*(psrlw, pand, pxor, psubb) + split. |
| Simon Pilgrim | 9c58950 | 2017-01-08 14:14:36 +0000 | [diff] [blame] | 327 | |
| Simon Pilgrim | d3f0d03 | 2017-05-14 18:52:15 +0000 | [diff] [blame] | 328 | { ISD::SDIV, MVT::v16i16, 12+2 }, // 2*pmulhw sequence + split. |
| 329 | { ISD::SDIV, MVT::v8i16, 6 }, // pmulhw sequence |
| 330 | { ISD::UDIV, MVT::v16i16, 12+2 }, // 2*pmulhuw sequence + split. |
| 331 | { ISD::UDIV, MVT::v8i16, 6 }, // pmulhuw sequence |
| 332 | { ISD::SDIV, MVT::v8i32, 38+2 }, // 2*pmuludq sequence + split. |
| 333 | { ISD::SDIV, MVT::v4i32, 19 }, // pmuludq sequence |
| 334 | { ISD::UDIV, MVT::v8i32, 30+2 }, // 2*pmuludq sequence + split. |
| 335 | { ISD::UDIV, MVT::v4i32, 15 }, // pmuludq sequence |
| Simon Pilgrim | 365be4f | 2016-10-20 18:00:35 +0000 | [diff] [blame] | 336 | }; |
| 337 | |
| 338 | if (Op2Info == TargetTransformInfo::OK_UniformConstantValue && |
| 339 | ST->hasSSE2()) { |
| 340 | // pmuldq sequence. |
| 341 | if (ISD == ISD::SDIV && LT.second == MVT::v8i32 && ST->hasAVX()) |
| Simon Pilgrim | d3f0d03 | 2017-05-14 18:52:15 +0000 | [diff] [blame] | 342 | return LT.first * 32; |
| Simon Pilgrim | 365be4f | 2016-10-20 18:00:35 +0000 | [diff] [blame] | 343 | if (ISD == ISD::SDIV && LT.second == MVT::v4i32 && ST->hasSSE41()) |
| 344 | return LT.first * 15; |
| 345 | |
| Simon Pilgrim | 5bef9c6 | 2017-05-14 17:59:46 +0000 | [diff] [blame] | 346 | // XOP has faster vXi8 shifts. |
| 347 | if ((ISD != ISD::SHL && ISD != ISD::SRL && ISD != ISD::SRA) || |
| 348 | !ST->hasXOP()) |
| 349 | if (const auto *Entry = |
| 350 | CostTableLookup(SSE2UniformConstCostTable, ISD, LT.second)) |
| 351 | return LT.first * Entry->Cost; |
| Simon Pilgrim | 365be4f | 2016-10-20 18:00:35 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| Simon Pilgrim | 1fa5487 | 2017-01-08 13:12:03 +0000 | [diff] [blame] | 354 | static const CostTblEntry AVX2UniformCostTable[] = { |
| 355 | // Uniform splats are cheaper for the following instructions. |
| 356 | { ISD::SHL, MVT::v16i16, 1 }, // psllw. |
| 357 | { ISD::SRL, MVT::v16i16, 1 }, // psrlw. |
| 358 | { ISD::SRA, MVT::v16i16, 1 }, // psraw. |
| 359 | }; |
| 360 | |
| 361 | if (ST->hasAVX2() && |
| 362 | ((Op2Info == TargetTransformInfo::OK_UniformConstantValue) || |
| 363 | (Op2Info == TargetTransformInfo::OK_UniformValue))) { |
| 364 | if (const auto *Entry = |
| 365 | CostTableLookup(AVX2UniformCostTable, ISD, LT.second)) |
| 366 | return LT.first * Entry->Cost; |
| 367 | } |
| 368 | |
| 369 | static const CostTblEntry SSE2UniformCostTable[] = { |
| 370 | // Uniform splats are cheaper for the following instructions. |
| 371 | { ISD::SHL, MVT::v8i16, 1 }, // psllw. |
| 372 | { ISD::SHL, MVT::v4i32, 1 }, // pslld |
| 373 | { ISD::SHL, MVT::v2i64, 1 }, // psllq. |
| 374 | |
| 375 | { ISD::SRL, MVT::v8i16, 1 }, // psrlw. |
| 376 | { ISD::SRL, MVT::v4i32, 1 }, // psrld. |
| 377 | { ISD::SRL, MVT::v2i64, 1 }, // psrlq. |
| 378 | |
| 379 | { ISD::SRA, MVT::v8i16, 1 }, // psraw. |
| 380 | { ISD::SRA, MVT::v4i32, 1 }, // psrad. |
| 381 | }; |
| 382 | |
| 383 | if (ST->hasSSE2() && |
| 384 | ((Op2Info == TargetTransformInfo::OK_UniformConstantValue) || |
| 385 | (Op2Info == TargetTransformInfo::OK_UniformValue))) { |
| 386 | if (const auto *Entry = |
| 387 | CostTableLookup(SSE2UniformCostTable, ISD, LT.second)) |
| 388 | return LT.first * Entry->Cost; |
| 389 | } |
| 390 | |
| Simon Pilgrim | 820e132 | 2016-10-27 15:27:00 +0000 | [diff] [blame] | 391 | static const CostTblEntry AVX512DQCostTable[] = { |
| 392 | { ISD::MUL, MVT::v2i64, 1 }, |
| 393 | { ISD::MUL, MVT::v4i64, 1 }, |
| 394 | { ISD::MUL, MVT::v8i64, 1 } |
| 395 | }; |
| 396 | |
| 397 | // Look for AVX512DQ lowering tricks for custom cases. |
| Simon Pilgrim | aa186c6 | 2017-01-05 22:48:02 +0000 | [diff] [blame] | 398 | if (ST->hasDQI()) |
| 399 | if (const auto *Entry = CostTableLookup(AVX512DQCostTable, ISD, LT.second)) |
| Simon Pilgrim | 820e132 | 2016-10-27 15:27:00 +0000 | [diff] [blame] | 400 | return LT.first * Entry->Cost; |
| Simon Pilgrim | 820e132 | 2016-10-27 15:27:00 +0000 | [diff] [blame] | 401 | |
| Simon Pilgrim | 025e26d | 2016-10-20 16:39:11 +0000 | [diff] [blame] | 402 | static const CostTblEntry AVX512BWCostTable[] = { |
| Simon Pilgrim | 6ed996c | 2017-01-15 20:44:00 +0000 | [diff] [blame] | 403 | { ISD::SHL, MVT::v8i16, 1 }, // vpsllvw |
| 404 | { ISD::SRL, MVT::v8i16, 1 }, // vpsrlvw |
| 405 | { ISD::SRA, MVT::v8i16, 1 }, // vpsravw |
| 406 | |
| 407 | { ISD::SHL, MVT::v16i16, 1 }, // vpsllvw |
| 408 | { ISD::SRL, MVT::v16i16, 1 }, // vpsrlvw |
| 409 | { ISD::SRA, MVT::v16i16, 1 }, // vpsravw |
| 410 | |
| Simon Pilgrim | a4109d6 | 2017-01-07 17:54:10 +0000 | [diff] [blame] | 411 | { ISD::SHL, MVT::v32i16, 1 }, // vpsllvw |
| 412 | { ISD::SRL, MVT::v32i16, 1 }, // vpsrlvw |
| 413 | { ISD::SRA, MVT::v32i16, 1 }, // vpsravw |
| 414 | |
| Simon Pilgrim | 5a81fef | 2017-01-11 10:36:51 +0000 | [diff] [blame] | 415 | { ISD::SHL, MVT::v64i8, 11 }, // vpblendvb sequence. |
| 416 | { ISD::SRL, MVT::v64i8, 11 }, // vpblendvb sequence. |
| 417 | { ISD::SRA, MVT::v64i8, 24 }, // vpblendvb sequence. |
| 418 | |
| Simon Pilgrim | 779da8e | 2016-11-14 15:54:24 +0000 | [diff] [blame] | 419 | { ISD::MUL, MVT::v64i8, 11 }, // extend/pmullw/trunc sequence. |
| 420 | { ISD::MUL, MVT::v32i8, 4 }, // extend/pmullw/trunc sequence. |
| 421 | { ISD::MUL, MVT::v16i8, 4 }, // extend/pmullw/trunc sequence. |
| 422 | |
| Simon Pilgrim | 025e26d | 2016-10-20 16:39:11 +0000 | [diff] [blame] | 423 | // Vectorizing division is a bad idea. See the SSE2 table for more comments. |
| 424 | { ISD::SDIV, MVT::v64i8, 64*20 }, |
| 425 | { ISD::SDIV, MVT::v32i16, 32*20 }, |
| Simon Pilgrim | 025e26d | 2016-10-20 16:39:11 +0000 | [diff] [blame] | 426 | { ISD::UDIV, MVT::v64i8, 64*20 }, |
| Simon Pilgrim | d833337 | 2017-01-06 11:12:53 +0000 | [diff] [blame] | 427 | { ISD::UDIV, MVT::v32i16, 32*20 } |
| Simon Pilgrim | 025e26d | 2016-10-20 16:39:11 +0000 | [diff] [blame] | 428 | }; |
| 429 | |
| 430 | // Look for AVX512BW lowering tricks for custom cases. |
| Simon Pilgrim | aa186c6 | 2017-01-05 22:48:02 +0000 | [diff] [blame] | 431 | if (ST->hasBWI()) |
| 432 | if (const auto *Entry = CostTableLookup(AVX512BWCostTable, ISD, LT.second)) |
| Simon Pilgrim | 025e26d | 2016-10-20 16:39:11 +0000 | [diff] [blame] | 433 | return LT.first * Entry->Cost; |
| Simon Pilgrim | 025e26d | 2016-10-20 16:39:11 +0000 | [diff] [blame] | 434 | |
| Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 435 | static const CostTblEntry AVX512CostTable[] = { |
| Simon Pilgrim | d833337 | 2017-01-06 11:12:53 +0000 | [diff] [blame] | 436 | { ISD::SHL, MVT::v16i32, 1 }, |
| 437 | { ISD::SRL, MVT::v16i32, 1 }, |
| 438 | { ISD::SRA, MVT::v16i32, 1 }, |
| Simon Pilgrim | d419b73 | 2017-01-14 19:24:23 +0000 | [diff] [blame] | 439 | |
| Simon Pilgrim | d833337 | 2017-01-06 11:12:53 +0000 | [diff] [blame] | 440 | { ISD::SHL, MVT::v8i64, 1 }, |
| 441 | { ISD::SRL, MVT::v8i64, 1 }, |
| Simon Pilgrim | d419b73 | 2017-01-14 19:24:23 +0000 | [diff] [blame] | 442 | |
| 443 | { ISD::SRA, MVT::v2i64, 1 }, |
| 444 | { ISD::SRA, MVT::v4i64, 1 }, |
| Simon Pilgrim | d833337 | 2017-01-06 11:12:53 +0000 | [diff] [blame] | 445 | { ISD::SRA, MVT::v8i64, 1 }, |
| Simon Pilgrim | 779da8e | 2016-11-14 15:54:24 +0000 | [diff] [blame] | 446 | |
| Simon Pilgrim | d833337 | 2017-01-06 11:12:53 +0000 | [diff] [blame] | 447 | { ISD::MUL, MVT::v32i8, 13 }, // extend/pmullw/trunc sequence. |
| 448 | { ISD::MUL, MVT::v16i8, 5 }, // extend/pmullw/trunc sequence. |
| Simon Pilgrim | cb9a02f6 | 2018-02-10 19:27:10 +0000 | [diff] [blame] | 449 | { ISD::MUL, MVT::v16i32, 1 }, // pmulld (Skylake from agner.org) |
| 450 | { ISD::MUL, MVT::v8i32, 1 }, // pmulld (Skylake from agner.org) |
| 451 | { ISD::MUL, MVT::v4i32, 1 }, // pmulld (Skylake from agner.org) |
| Simon Pilgrim | d833337 | 2017-01-06 11:12:53 +0000 | [diff] [blame] | 452 | { ISD::MUL, MVT::v8i64, 8 }, // 3*pmuludq/3*shift/2*add |
| 453 | |
| Simon Pilgrim | 9929f90 | 2018-02-26 22:10:17 +0000 | [diff] [blame] | 454 | { ISD::FADD, MVT::v8f64, 1 }, // Skylake from http://www.agner.org/ |
| 455 | { ISD::FSUB, MVT::v8f64, 1 }, // Skylake from http://www.agner.org/ |
| 456 | { ISD::FMUL, MVT::v8f64, 1 }, // Skylake from http://www.agner.org/ |
| 457 | |
| 458 | { ISD::FADD, MVT::v16f32, 1 }, // Skylake from http://www.agner.org/ |
| 459 | { ISD::FSUB, MVT::v16f32, 1 }, // Skylake from http://www.agner.org/ |
| 460 | { ISD::FMUL, MVT::v16f32, 1 }, // Skylake from http://www.agner.org/ |
| 461 | |
| Simon Pilgrim | d833337 | 2017-01-06 11:12:53 +0000 | [diff] [blame] | 462 | // Vectorizing division is a bad idea. See the SSE2 table for more comments. |
| 463 | { ISD::SDIV, MVT::v16i32, 16*20 }, |
| 464 | { ISD::SDIV, MVT::v8i64, 8*20 }, |
| 465 | { ISD::UDIV, MVT::v16i32, 16*20 }, |
| 466 | { ISD::UDIV, MVT::v8i64, 8*20 } |
| Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 467 | }; |
| 468 | |
| Simon Pilgrim | aa186c6 | 2017-01-05 22:48:02 +0000 | [diff] [blame] | 469 | if (ST->hasAVX512()) |
| Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 470 | if (const auto *Entry = CostTableLookup(AVX512CostTable, ISD, LT.second)) |
| 471 | return LT.first * Entry->Cost; |
| Simon Pilgrim | 3d11c99 | 2015-09-30 08:17:50 +0000 | [diff] [blame] | 472 | |
| Simon Pilgrim | 82e3e05 | 2017-01-07 21:47:10 +0000 | [diff] [blame] | 473 | static const CostTblEntry AVX2ShiftCostTable[] = { |
| Michael Liao | 70dd7f9 | 2013-03-20 22:01:10 +0000 | [diff] [blame] | 474 | // Shifts on v4i64/v8i32 on AVX2 is legal even though we declare to |
| 475 | // customize them to detect the cases where shift amount is a scalar one. |
| 476 | { ISD::SHL, MVT::v4i32, 1 }, |
| 477 | { ISD::SRL, MVT::v4i32, 1 }, |
| 478 | { ISD::SRA, MVT::v4i32, 1 }, |
| 479 | { ISD::SHL, MVT::v8i32, 1 }, |
| 480 | { ISD::SRL, MVT::v8i32, 1 }, |
| 481 | { ISD::SRA, MVT::v8i32, 1 }, |
| 482 | { ISD::SHL, MVT::v2i64, 1 }, |
| 483 | { ISD::SRL, MVT::v2i64, 1 }, |
| 484 | { ISD::SHL, MVT::v4i64, 1 }, |
| 485 | { ISD::SRL, MVT::v4i64, 1 }, |
| Simon Pilgrim | 3d11c99 | 2015-09-30 08:17:50 +0000 | [diff] [blame] | 486 | }; |
| Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 487 | |
| Simon Pilgrim | 3d11c99 | 2015-09-30 08:17:50 +0000 | [diff] [blame] | 488 | // Look for AVX2 lowering tricks. |
| 489 | if (ST->hasAVX2()) { |
| 490 | if (ISD == ISD::SHL && LT.second == MVT::v16i16 && |
| 491 | (Op2Info == TargetTransformInfo::OK_UniformConstantValue || |
| 492 | Op2Info == TargetTransformInfo::OK_NonUniformConstantValue)) |
| 493 | // On AVX2, a packed v16i16 shift left by a constant build_vector |
| 494 | // is lowered into a vector multiply (vpmullw). |
| Simon Pilgrim | 58e03a0 | 2018-04-25 15:22:03 +0000 | [diff] [blame] | 495 | return getArithmeticInstrCost(Instruction::Mul, Ty, Op1Info, Op2Info, |
| 496 | TargetTransformInfo::OP_None, |
| 497 | TargetTransformInfo::OP_None); |
| Simon Pilgrim | 3d11c99 | 2015-09-30 08:17:50 +0000 | [diff] [blame] | 498 | |
| Simon Pilgrim | 82e3e05 | 2017-01-07 21:47:10 +0000 | [diff] [blame] | 499 | if (const auto *Entry = CostTableLookup(AVX2ShiftCostTable, ISD, LT.second)) |
| Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 500 | return LT.first * Entry->Cost; |
| Simon Pilgrim | 3d11c99 | 2015-09-30 08:17:50 +0000 | [diff] [blame] | 501 | } |
| 502 | |
| Simon Pilgrim | 82e3e05 | 2017-01-07 21:47:10 +0000 | [diff] [blame] | 503 | static const CostTblEntry XOPShiftCostTable[] = { |
| Simon Pilgrim | 3d11c99 | 2015-09-30 08:17:50 +0000 | [diff] [blame] | 504 | // 128bit shifts take 1cy, but right shifts require negation beforehand. |
| 505 | { ISD::SHL, MVT::v16i8, 1 }, |
| 506 | { ISD::SRL, MVT::v16i8, 2 }, |
| 507 | { ISD::SRA, MVT::v16i8, 2 }, |
| 508 | { ISD::SHL, MVT::v8i16, 1 }, |
| 509 | { ISD::SRL, MVT::v8i16, 2 }, |
| 510 | { ISD::SRA, MVT::v8i16, 2 }, |
| 511 | { ISD::SHL, MVT::v4i32, 1 }, |
| 512 | { ISD::SRL, MVT::v4i32, 2 }, |
| 513 | { ISD::SRA, MVT::v4i32, 2 }, |
| 514 | { ISD::SHL, MVT::v2i64, 1 }, |
| 515 | { ISD::SRL, MVT::v2i64, 2 }, |
| 516 | { ISD::SRA, MVT::v2i64, 2 }, |
| 517 | // 256bit shifts require splitting if AVX2 didn't catch them above. |
| Simon Pilgrim | 4599eaa | 2017-05-14 13:38:53 +0000 | [diff] [blame] | 518 | { ISD::SHL, MVT::v32i8, 2+2 }, |
| 519 | { ISD::SRL, MVT::v32i8, 4+2 }, |
| 520 | { ISD::SRA, MVT::v32i8, 4+2 }, |
| 521 | { ISD::SHL, MVT::v16i16, 2+2 }, |
| 522 | { ISD::SRL, MVT::v16i16, 4+2 }, |
| 523 | { ISD::SRA, MVT::v16i16, 4+2 }, |
| 524 | { ISD::SHL, MVT::v8i32, 2+2 }, |
| 525 | { ISD::SRL, MVT::v8i32, 4+2 }, |
| 526 | { ISD::SRA, MVT::v8i32, 4+2 }, |
| 527 | { ISD::SHL, MVT::v4i64, 2+2 }, |
| 528 | { ISD::SRL, MVT::v4i64, 4+2 }, |
| 529 | { ISD::SRA, MVT::v4i64, 4+2 }, |
| Simon Pilgrim | 3d11c99 | 2015-09-30 08:17:50 +0000 | [diff] [blame] | 530 | }; |
| 531 | |
| 532 | // Look for XOP lowering tricks. |
| Simon Pilgrim | aa186c6 | 2017-01-05 22:48:02 +0000 | [diff] [blame] | 533 | if (ST->hasXOP()) |
| Simon Pilgrim | 82e3e05 | 2017-01-07 21:47:10 +0000 | [diff] [blame] | 534 | if (const auto *Entry = CostTableLookup(XOPShiftCostTable, ISD, LT.second)) |
| Simon Pilgrim | 025e26d | 2016-10-20 16:39:11 +0000 | [diff] [blame] | 535 | return LT.first * Entry->Cost; |
| Simon Pilgrim | 025e26d | 2016-10-20 16:39:11 +0000 | [diff] [blame] | 536 | |
| Simon Pilgrim | 1fa5487 | 2017-01-08 13:12:03 +0000 | [diff] [blame] | 537 | static const CostTblEntry SSE2UniformShiftCostTable[] = { |
| Michael Kuperstein | 3ceac2b | 2016-08-04 22:48:03 +0000 | [diff] [blame] | 538 | // Uniform splats are cheaper for the following instructions. |
| Simon Pilgrim | de4467b | 2017-05-14 20:02:34 +0000 | [diff] [blame] | 539 | { ISD::SHL, MVT::v16i16, 2+2 }, // 2*psllw + split. |
| 540 | { ISD::SHL, MVT::v8i32, 2+2 }, // 2*pslld + split. |
| 541 | { ISD::SHL, MVT::v4i64, 2+2 }, // 2*psllq + split. |
| Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 542 | |
| Simon Pilgrim | de4467b | 2017-05-14 20:02:34 +0000 | [diff] [blame] | 543 | { ISD::SRL, MVT::v16i16, 2+2 }, // 2*psrlw + split. |
| 544 | { ISD::SRL, MVT::v8i32, 2+2 }, // 2*psrld + split. |
| 545 | { ISD::SRL, MVT::v4i64, 2+2 }, // 2*psrlq + split. |
| Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 546 | |
| Simon Pilgrim | de4467b | 2017-05-14 20:02:34 +0000 | [diff] [blame] | 547 | { ISD::SRA, MVT::v16i16, 2+2 }, // 2*psraw + split. |
| 548 | { ISD::SRA, MVT::v8i32, 2+2 }, // 2*psrad + split. |
| 549 | { ISD::SRA, MVT::v2i64, 4 }, // 2*psrad + shuffle. |
| 550 | { ISD::SRA, MVT::v4i64, 8+2 }, // 2*(2*psrad + shuffle) + split. |
| Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 551 | }; |
| 552 | |
| Michael Kuperstein | 3ceac2b | 2016-08-04 22:48:03 +0000 | [diff] [blame] | 553 | if (ST->hasSSE2() && |
| 554 | ((Op2Info == TargetTransformInfo::OK_UniformConstantValue) || |
| 555 | (Op2Info == TargetTransformInfo::OK_UniformValue))) { |
| Simon Pilgrim | f96b4ab | 2017-05-14 20:25:42 +0000 | [diff] [blame] | 556 | |
| 557 | // Handle AVX2 uniform v4i64 ISD::SRA, it's not worth a table. |
| 558 | if (ISD == ISD::SRA && LT.second == MVT::v4i64 && ST->hasAVX2()) |
| 559 | return LT.first * 4; // 2*psrad + shuffle. |
| 560 | |
| Michael Kuperstein | 3ceac2b | 2016-08-04 22:48:03 +0000 | [diff] [blame] | 561 | if (const auto *Entry = |
| Simon Pilgrim | 1fa5487 | 2017-01-08 13:12:03 +0000 | [diff] [blame] | 562 | CostTableLookup(SSE2UniformShiftCostTable, ISD, LT.second)) |
| Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 563 | return LT.first * Entry->Cost; |
| Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| Andrea Di Biagio | b7882b3 | 2014-02-12 23:43:47 +0000 | [diff] [blame] | 566 | if (ISD == ISD::SHL && |
| 567 | Op2Info == TargetTransformInfo::OK_NonUniformConstantValue) { |
| Craig Topper | eda02a9 | 2015-10-25 03:15:29 +0000 | [diff] [blame] | 568 | MVT VT = LT.second; |
| Simon Pilgrim | a18ae9b | 2015-10-17 13:23:38 +0000 | [diff] [blame] | 569 | // Vector shift left by non uniform constant can be lowered |
| Simon Pilgrim | e70644d | 2017-01-07 21:33:00 +0000 | [diff] [blame] | 570 | // into vector multiply. |
| 571 | if (((VT == MVT::v8i16 || VT == MVT::v4i32) && ST->hasSSE2()) || |
| 572 | ((VT == MVT::v16i16 || VT == MVT::v8i32) && ST->hasAVX())) |
| Andrea Di Biagio | b7882b3 | 2014-02-12 23:43:47 +0000 | [diff] [blame] | 573 | ISD = ISD::MUL; |
| 574 | } |
| Arnold Schwaighofer | 44f902e | 2013-04-04 23:26:24 +0000 | [diff] [blame] | 575 | |
| Simon Pilgrim | 82e3e05 | 2017-01-07 21:47:10 +0000 | [diff] [blame] | 576 | static const CostTblEntry AVX2CostTable[] = { |
| 577 | { ISD::SHL, MVT::v32i8, 11 }, // vpblendvb sequence. |
| 578 | { ISD::SHL, MVT::v16i16, 10 }, // extend/vpsrlvd/pack sequence. |
| 579 | |
| 580 | { ISD::SRL, MVT::v32i8, 11 }, // vpblendvb sequence. |
| 581 | { ISD::SRL, MVT::v16i16, 10 }, // extend/vpsrlvd/pack sequence. |
| 582 | |
| 583 | { ISD::SRA, MVT::v32i8, 24 }, // vpblendvb sequence. |
| 584 | { ISD::SRA, MVT::v16i16, 10 }, // extend/vpsravd/pack sequence. |
| 585 | { ISD::SRA, MVT::v2i64, 4 }, // srl/xor/sub sequence. |
| 586 | { ISD::SRA, MVT::v4i64, 4 }, // srl/xor/sub sequence. |
| 587 | |
| 588 | { ISD::SUB, MVT::v32i8, 1 }, // psubb |
| 589 | { ISD::ADD, MVT::v32i8, 1 }, // paddb |
| 590 | { ISD::SUB, MVT::v16i16, 1 }, // psubw |
| 591 | { ISD::ADD, MVT::v16i16, 1 }, // paddw |
| 592 | { ISD::SUB, MVT::v8i32, 1 }, // psubd |
| 593 | { ISD::ADD, MVT::v8i32, 1 }, // paddd |
| 594 | { ISD::SUB, MVT::v4i64, 1 }, // psubq |
| 595 | { ISD::ADD, MVT::v4i64, 1 }, // paddq |
| 596 | |
| 597 | { ISD::MUL, MVT::v32i8, 17 }, // extend/pmullw/trunc sequence. |
| 598 | { ISD::MUL, MVT::v16i8, 7 }, // extend/pmullw/trunc sequence. |
| 599 | { ISD::MUL, MVT::v16i16, 1 }, // pmullw |
| Simon Pilgrim | cb9a02f6 | 2018-02-10 19:27:10 +0000 | [diff] [blame] | 600 | { ISD::MUL, MVT::v8i32, 2 }, // pmulld (Haswell from agner.org) |
| Simon Pilgrim | 82e3e05 | 2017-01-07 21:47:10 +0000 | [diff] [blame] | 601 | { ISD::MUL, MVT::v4i64, 8 }, // 3*pmuludq/3*shift/2*add |
| 602 | |
| Simon Pilgrim | 9929f90 | 2018-02-26 22:10:17 +0000 | [diff] [blame] | 603 | { ISD::FADD, MVT::v4f64, 1 }, // Haswell from http://www.agner.org/ |
| 604 | { ISD::FADD, MVT::v8f32, 1 }, // Haswell from http://www.agner.org/ |
| 605 | { ISD::FSUB, MVT::v4f64, 1 }, // Haswell from http://www.agner.org/ |
| 606 | { ISD::FSUB, MVT::v8f32, 1 }, // Haswell from http://www.agner.org/ |
| 607 | { ISD::FMUL, MVT::v4f64, 1 }, // Haswell from http://www.agner.org/ |
| 608 | { ISD::FMUL, MVT::v8f32, 1 }, // Haswell from http://www.agner.org/ |
| 609 | |
| Simon Pilgrim | 82e3e05 | 2017-01-07 21:47:10 +0000 | [diff] [blame] | 610 | { ISD::FDIV, MVT::f32, 7 }, // Haswell from http://www.agner.org/ |
| 611 | { ISD::FDIV, MVT::v4f32, 7 }, // Haswell from http://www.agner.org/ |
| 612 | { ISD::FDIV, MVT::v8f32, 14 }, // Haswell from http://www.agner.org/ |
| 613 | { ISD::FDIV, MVT::f64, 14 }, // Haswell from http://www.agner.org/ |
| 614 | { ISD::FDIV, MVT::v2f64, 14 }, // Haswell from http://www.agner.org/ |
| 615 | { ISD::FDIV, MVT::v4f64, 28 }, // Haswell from http://www.agner.org/ |
| 616 | }; |
| 617 | |
| 618 | // Look for AVX2 lowering tricks for custom cases. |
| 619 | if (ST->hasAVX2()) |
| 620 | if (const auto *Entry = CostTableLookup(AVX2CostTable, ISD, LT.second)) |
| 621 | return LT.first * Entry->Cost; |
| 622 | |
| Simon Pilgrim | 100eae1 | 2017-01-07 17:03:51 +0000 | [diff] [blame] | 623 | static const CostTblEntry AVX1CostTable[] = { |
| 624 | // We don't have to scalarize unsupported ops. We can issue two half-sized |
| 625 | // operations and we only need to extract the upper YMM half. |
| 626 | // Two ops + 1 extract + 1 insert = 4. |
| Simon Pilgrim | 7259971 | 2017-01-07 18:19:25 +0000 | [diff] [blame] | 627 | { ISD::MUL, MVT::v16i16, 4 }, |
| 628 | { ISD::MUL, MVT::v8i32, 4 }, |
| 629 | { ISD::SUB, MVT::v32i8, 4 }, |
| 630 | { ISD::ADD, MVT::v32i8, 4 }, |
| 631 | { ISD::SUB, MVT::v16i16, 4 }, |
| 632 | { ISD::ADD, MVT::v16i16, 4 }, |
| 633 | { ISD::SUB, MVT::v8i32, 4 }, |
| 634 | { ISD::ADD, MVT::v8i32, 4 }, |
| 635 | { ISD::SUB, MVT::v4i64, 4 }, |
| 636 | { ISD::ADD, MVT::v4i64, 4 }, |
| Simon Pilgrim | 100eae1 | 2017-01-07 17:03:51 +0000 | [diff] [blame] | 637 | |
| 638 | // A v4i64 multiply is custom lowered as two split v2i64 vectors that then |
| 639 | // are lowered as a series of long multiplies(3), shifts(3) and adds(2) |
| 640 | // Because we believe v4i64 to be a legal type, we must also include the |
| 641 | // extract+insert in the cost table. Therefore, the cost here is 18 |
| 642 | // instead of 8. |
| Simon Pilgrim | 7259971 | 2017-01-07 18:19:25 +0000 | [diff] [blame] | 643 | { ISD::MUL, MVT::v4i64, 18 }, |
| 644 | |
| 645 | { ISD::MUL, MVT::v32i8, 26 }, // extend/pmullw/trunc sequence. |
| 646 | |
| 647 | { ISD::FDIV, MVT::f32, 14 }, // SNB from http://www.agner.org/ |
| 648 | { ISD::FDIV, MVT::v4f32, 14 }, // SNB from http://www.agner.org/ |
| 649 | { ISD::FDIV, MVT::v8f32, 28 }, // SNB from http://www.agner.org/ |
| 650 | { ISD::FDIV, MVT::f64, 22 }, // SNB from http://www.agner.org/ |
| 651 | { ISD::FDIV, MVT::v2f64, 22 }, // SNB from http://www.agner.org/ |
| 652 | { ISD::FDIV, MVT::v4f64, 44 }, // SNB from http://www.agner.org/ |
| 653 | |
| 654 | // Vectorizing division is a bad idea. See the SSE2 table for more comments. |
| 655 | { ISD::SDIV, MVT::v32i8, 32*20 }, |
| 656 | { ISD::SDIV, MVT::v16i16, 16*20 }, |
| 657 | { ISD::SDIV, MVT::v8i32, 8*20 }, |
| 658 | { ISD::SDIV, MVT::v4i64, 4*20 }, |
| 659 | { ISD::UDIV, MVT::v32i8, 32*20 }, |
| 660 | { ISD::UDIV, MVT::v16i16, 16*20 }, |
| 661 | { ISD::UDIV, MVT::v8i32, 8*20 }, |
| 662 | { ISD::UDIV, MVT::v4i64, 4*20 }, |
| Simon Pilgrim | 100eae1 | 2017-01-07 17:03:51 +0000 | [diff] [blame] | 663 | }; |
| 664 | |
| Simon Pilgrim | df7de7a | 2017-01-07 17:27:39 +0000 | [diff] [blame] | 665 | if (ST->hasAVX()) |
| Simon Pilgrim | 100eae1 | 2017-01-07 17:03:51 +0000 | [diff] [blame] | 666 | if (const auto *Entry = CostTableLookup(AVX1CostTable, ISD, LT.second)) |
| 667 | return LT.first * Entry->Cost; |
| 668 | |
| Simon Pilgrim | 5b06e4d | 2017-01-05 19:19:39 +0000 | [diff] [blame] | 669 | static const CostTblEntry SSE42CostTable[] = { |
| Simon Pilgrim | 9929f90 | 2018-02-26 22:10:17 +0000 | [diff] [blame] | 670 | { ISD::FADD, MVT::f64, 1 }, // Nehalem from http://www.agner.org/ |
| 671 | { ISD::FADD, MVT::f32, 1 }, // Nehalem from http://www.agner.org/ |
| 672 | { ISD::FADD, MVT::v2f64, 1 }, // Nehalem from http://www.agner.org/ |
| 673 | { ISD::FADD, MVT::v4f32, 1 }, // Nehalem from http://www.agner.org/ |
| 674 | |
| 675 | { ISD::FSUB, MVT::f64, 1 }, // Nehalem from http://www.agner.org/ |
| 676 | { ISD::FSUB, MVT::f32 , 1 }, // Nehalem from http://www.agner.org/ |
| 677 | { ISD::FSUB, MVT::v2f64, 1 }, // Nehalem from http://www.agner.org/ |
| 678 | { ISD::FSUB, MVT::v4f32, 1 }, // Nehalem from http://www.agner.org/ |
| 679 | |
| 680 | { ISD::FMUL, MVT::f64, 1 }, // Nehalem from http://www.agner.org/ |
| 681 | { ISD::FMUL, MVT::f32, 1 }, // Nehalem from http://www.agner.org/ |
| 682 | { ISD::FMUL, MVT::v2f64, 1 }, // Nehalem from http://www.agner.org/ |
| 683 | { ISD::FMUL, MVT::v4f32, 1 }, // Nehalem from http://www.agner.org/ |
| 684 | |
| Simon Pilgrim | 5b06e4d | 2017-01-05 19:19:39 +0000 | [diff] [blame] | 685 | { ISD::FDIV, MVT::f32, 14 }, // Nehalem from http://www.agner.org/ |
| 686 | { ISD::FDIV, MVT::v4f32, 14 }, // Nehalem from http://www.agner.org/ |
| 687 | { ISD::FDIV, MVT::f64, 22 }, // Nehalem from http://www.agner.org/ |
| 688 | { ISD::FDIV, MVT::v2f64, 22 }, // Nehalem from http://www.agner.org/ |
| 689 | }; |
| 690 | |
| 691 | if (ST->hasSSE42()) |
| 692 | if (const auto *Entry = CostTableLookup(SSE42CostTable, ISD, LT.second)) |
| 693 | return LT.first * Entry->Cost; |
| 694 | |
| Simon Pilgrim | 6ac1e98 | 2016-10-23 16:49:04 +0000 | [diff] [blame] | 695 | static const CostTblEntry SSE41CostTable[] = { |
| Simon Pilgrim | d0ef9d8 | 2017-05-14 20:52:11 +0000 | [diff] [blame] | 696 | { ISD::SHL, MVT::v16i8, 11 }, // pblendvb sequence. |
| 697 | { ISD::SHL, MVT::v32i8, 2*11+2 }, // pblendvb sequence + split. |
| 698 | { ISD::SHL, MVT::v8i16, 14 }, // pblendvb sequence. |
| 699 | { ISD::SHL, MVT::v16i16, 2*14+2 }, // pblendvb sequence + split. |
| 700 | { ISD::SHL, MVT::v4i32, 4 }, // pslld/paddd/cvttps2dq/pmulld |
| 701 | { ISD::SHL, MVT::v8i32, 2*4+2 }, // pslld/paddd/cvttps2dq/pmulld + split |
| Simon Pilgrim | 6ac1e98 | 2016-10-23 16:49:04 +0000 | [diff] [blame] | 702 | |
| Simon Pilgrim | d0ef9d8 | 2017-05-14 20:52:11 +0000 | [diff] [blame] | 703 | { ISD::SRL, MVT::v16i8, 12 }, // pblendvb sequence. |
| 704 | { ISD::SRL, MVT::v32i8, 2*12+2 }, // pblendvb sequence + split. |
| 705 | { ISD::SRL, MVT::v8i16, 14 }, // pblendvb sequence. |
| 706 | { ISD::SRL, MVT::v16i16, 2*14+2 }, // pblendvb sequence + split. |
| 707 | { ISD::SRL, MVT::v4i32, 11 }, // Shift each lane + blend. |
| 708 | { ISD::SRL, MVT::v8i32, 2*11+2 }, // Shift each lane + blend + split. |
| Simon Pilgrim | 6ac1e98 | 2016-10-23 16:49:04 +0000 | [diff] [blame] | 709 | |
| Simon Pilgrim | d0ef9d8 | 2017-05-14 20:52:11 +0000 | [diff] [blame] | 710 | { ISD::SRA, MVT::v16i8, 24 }, // pblendvb sequence. |
| 711 | { ISD::SRA, MVT::v32i8, 2*24+2 }, // pblendvb sequence + split. |
| 712 | { ISD::SRA, MVT::v8i16, 14 }, // pblendvb sequence. |
| 713 | { ISD::SRA, MVT::v16i16, 2*14+2 }, // pblendvb sequence + split. |
| 714 | { ISD::SRA, MVT::v4i32, 12 }, // Shift each lane + blend. |
| 715 | { ISD::SRA, MVT::v8i32, 2*12+2 }, // Shift each lane + blend + split. |
| Simon Pilgrim | 4c050c21 | 2017-01-05 19:42:43 +0000 | [diff] [blame] | 716 | |
| Simon Pilgrim | cb9a02f6 | 2018-02-10 19:27:10 +0000 | [diff] [blame] | 717 | { ISD::MUL, MVT::v4i32, 2 } // pmulld (Nehalem from agner.org) |
| Simon Pilgrim | 6ac1e98 | 2016-10-23 16:49:04 +0000 | [diff] [blame] | 718 | }; |
| 719 | |
| Simon Pilgrim | aa186c6 | 2017-01-05 22:48:02 +0000 | [diff] [blame] | 720 | if (ST->hasSSE41()) |
| Simon Pilgrim | 6ac1e98 | 2016-10-23 16:49:04 +0000 | [diff] [blame] | 721 | if (const auto *Entry = CostTableLookup(SSE41CostTable, ISD, LT.second)) |
| 722 | return LT.first * Entry->Cost; |
| Simon Pilgrim | 6ac1e98 | 2016-10-23 16:49:04 +0000 | [diff] [blame] | 723 | |
| Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 724 | static const CostTblEntry SSE2CostTable[] = { |
| Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 725 | // We don't correctly identify costs of casts because they are marked as |
| 726 | // custom. |
| Simon Pilgrim | d0ef9d8 | 2017-05-14 20:52:11 +0000 | [diff] [blame] | 727 | { ISD::SHL, MVT::v16i8, 26 }, // cmpgtb sequence. |
| 728 | { ISD::SHL, MVT::v8i16, 32 }, // cmpgtb sequence. |
| 729 | { ISD::SHL, MVT::v4i32, 2*5 }, // We optimized this using mul. |
| 730 | { ISD::SHL, MVT::v2i64, 4 }, // splat+shuffle sequence. |
| 731 | { ISD::SHL, MVT::v4i64, 2*4+2 }, // splat+shuffle sequence + split. |
| NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 732 | |
| Simon Pilgrim | d0ef9d8 | 2017-05-14 20:52:11 +0000 | [diff] [blame] | 733 | { ISD::SRL, MVT::v16i8, 26 }, // cmpgtb sequence. |
| 734 | { ISD::SRL, MVT::v8i16, 32 }, // cmpgtb sequence. |
| 735 | { ISD::SRL, MVT::v4i32, 16 }, // Shift each lane + blend. |
| 736 | { ISD::SRL, MVT::v2i64, 4 }, // splat+shuffle sequence. |
| 737 | { ISD::SRL, MVT::v4i64, 2*4+2 }, // splat+shuffle sequence + split. |
| NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 738 | |
| Simon Pilgrim | d0ef9d8 | 2017-05-14 20:52:11 +0000 | [diff] [blame] | 739 | { ISD::SRA, MVT::v16i8, 54 }, // unpacked cmpgtb sequence. |
| 740 | { ISD::SRA, MVT::v8i16, 32 }, // cmpgtb sequence. |
| 741 | { ISD::SRA, MVT::v4i32, 16 }, // Shift each lane + blend. |
| 742 | { ISD::SRA, MVT::v2i64, 12 }, // srl/xor/sub sequence. |
| 743 | { ISD::SRA, MVT::v4i64, 2*12+2 }, // srl/xor/sub sequence+split. |
| NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 744 | |
| Simon Pilgrim | d0ef9d8 | 2017-05-14 20:52:11 +0000 | [diff] [blame] | 745 | { ISD::MUL, MVT::v16i8, 12 }, // extend/pmullw/trunc sequence. |
| 746 | { ISD::MUL, MVT::v8i16, 1 }, // pmullw |
| 747 | { ISD::MUL, MVT::v4i32, 6 }, // 3*pmuludq/4*shuffle |
| 748 | { ISD::MUL, MVT::v2i64, 8 }, // 3*pmuludq/3*shift/2*add |
| Simon Pilgrim | 779da8e | 2016-11-14 15:54:24 +0000 | [diff] [blame] | 749 | |
| Simon Pilgrim | d0ef9d8 | 2017-05-14 20:52:11 +0000 | [diff] [blame] | 750 | { ISD::FDIV, MVT::f32, 23 }, // Pentium IV from http://www.agner.org/ |
| 751 | { ISD::FDIV, MVT::v4f32, 39 }, // Pentium IV from http://www.agner.org/ |
| 752 | { ISD::FDIV, MVT::f64, 38 }, // Pentium IV from http://www.agner.org/ |
| 753 | { ISD::FDIV, MVT::v2f64, 69 }, // Pentium IV from http://www.agner.org/ |
| Alexey Bataev | d07c731 | 2016-10-31 12:10:53 +0000 | [diff] [blame] | 754 | |
| NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 755 | // 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] | 756 | // in the process we will often end up having to spilling regular |
| 757 | // registers. The overhead of division is going to dominate most kernels |
| 758 | // anyways so try hard to prevent vectorization of division - it is |
| 759 | // generally a bad idea. Assume somewhat arbitrarily that we have to be able |
| 760 | // to hide "20 cycles" for each lane. |
| 761 | { ISD::SDIV, MVT::v16i8, 16*20 }, |
| Simon Pilgrim | e70644d | 2017-01-07 21:33:00 +0000 | [diff] [blame] | 762 | { ISD::SDIV, MVT::v8i16, 8*20 }, |
| 763 | { ISD::SDIV, MVT::v4i32, 4*20 }, |
| 764 | { ISD::SDIV, MVT::v2i64, 2*20 }, |
| Arnold Schwaighofer | a04b9ef | 2013-06-25 19:14:09 +0000 | [diff] [blame] | 765 | { ISD::UDIV, MVT::v16i8, 16*20 }, |
| Simon Pilgrim | e70644d | 2017-01-07 21:33:00 +0000 | [diff] [blame] | 766 | { ISD::UDIV, MVT::v8i16, 8*20 }, |
| 767 | { ISD::UDIV, MVT::v4i32, 4*20 }, |
| 768 | { ISD::UDIV, MVT::v2i64, 2*20 }, |
| Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 769 | }; |
| 770 | |
| Simon Pilgrim | aa186c6 | 2017-01-05 22:48:02 +0000 | [diff] [blame] | 771 | if (ST->hasSSE2()) |
| Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 772 | if (const auto *Entry = CostTableLookup(SSE2CostTable, ISD, LT.second)) |
| 773 | return LT.first * Entry->Cost; |
| Arnold Schwaighofer | e9b5016 | 2013-04-03 21:46:05 +0000 | [diff] [blame] | 774 | |
| Simon Pilgrim | aa186c6 | 2017-01-05 22:48:02 +0000 | [diff] [blame] | 775 | static const CostTblEntry SSE1CostTable[] = { |
| Alexey Bataev | d07c731 | 2016-10-31 12:10:53 +0000 | [diff] [blame] | 776 | { ISD::FDIV, MVT::f32, 17 }, // Pentium III from http://www.agner.org/ |
| 777 | { ISD::FDIV, MVT::v4f32, 34 }, // Pentium III from http://www.agner.org/ |
| 778 | }; |
| 779 | |
| 780 | if (ST->hasSSE1()) |
| Simon Pilgrim | aa186c6 | 2017-01-05 22:48:02 +0000 | [diff] [blame] | 781 | if (const auto *Entry = CostTableLookup(SSE1CostTable, ISD, LT.second)) |
| Alexey Bataev | d07c731 | 2016-10-31 12:10:53 +0000 | [diff] [blame] | 782 | return LT.first * Entry->Cost; |
| Simon Pilgrim | aa186c6 | 2017-01-05 22:48:02 +0000 | [diff] [blame] | 783 | |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 784 | // Fallback to the default implementation. |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 785 | return BaseT::getArithmeticInstrCost(Opcode, Ty, Op1Info, Op2Info); |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 786 | } |
| 787 | |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 788 | int X86TTIImpl::getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, |
| 789 | Type *SubTp) { |
| Simon Pilgrim | a62395a | 2017-01-05 14:33:32 +0000 | [diff] [blame] | 790 | // 64-bit packed float vectors (v2f32) are widened to type v4f32. |
| 791 | // 64-bit packed integer vectors (v2i32) are promoted to type v2i64. |
| 792 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Tp); |
| Karthik Bhat | e03a25d | 2014-06-20 04:32:48 +0000 | [diff] [blame] | 793 | |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 794 | // For Broadcasts we are splatting the first element from the first input |
| 795 | // register, so only need to reference that input and all the output |
| 796 | // registers are the same. |
| 797 | if (Kind == TTI::SK_Broadcast) |
| 798 | LT.first = 1; |
| Simon Pilgrim | bca02f9 | 2017-01-05 15:56:08 +0000 | [diff] [blame] | 799 | |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 800 | // We are going to permute multiple sources and the result will be in multiple |
| 801 | // destinations. Providing an accurate cost only for splits where the element |
| 802 | // type remains the same. |
| 803 | if (Kind == TTI::SK_PermuteSingleSrc && LT.first != 1) { |
| 804 | MVT LegalVT = LT.second; |
| Alexey Bataev | 771ec9f | 2018-01-09 19:08:22 +0000 | [diff] [blame] | 805 | if (LegalVT.isVector() && |
| 806 | LegalVT.getVectorElementType().getSizeInBits() == |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 807 | Tp->getVectorElementType()->getPrimitiveSizeInBits() && |
| 808 | LegalVT.getVectorNumElements() < Tp->getVectorNumElements()) { |
| Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 809 | |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 810 | unsigned VecTySize = DL.getTypeStoreSize(Tp); |
| 811 | unsigned LegalVTSize = LegalVT.getStoreSize(); |
| 812 | // Number of source vectors after legalization: |
| 813 | unsigned NumOfSrcs = (VecTySize + LegalVTSize - 1) / LegalVTSize; |
| 814 | // Number of destination vectors after legalization: |
| 815 | unsigned NumOfDests = LT.first; |
| Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 816 | |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 817 | Type *SingleOpTy = VectorType::get(Tp->getVectorElementType(), |
| 818 | LegalVT.getVectorNumElements()); |
| Simon Pilgrim | bca02f9 | 2017-01-05 15:56:08 +0000 | [diff] [blame] | 819 | |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 820 | unsigned NumOfShuffles = (NumOfSrcs - 1) * NumOfDests; |
| 821 | return NumOfShuffles * |
| 822 | getShuffleCost(TTI::SK_PermuteTwoSrc, SingleOpTy, 0, nullptr); |
| 823 | } |
| Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 824 | |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 825 | return BaseT::getShuffleCost(Kind, Tp, Index, SubTp); |
| 826 | } |
| Andrea Di Biagio | c8e8bda | 2014-07-03 22:24:18 +0000 | [diff] [blame] | 827 | |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 828 | // For 2-input shuffles, we must account for splitting the 2 inputs into many. |
| 829 | if (Kind == TTI::SK_PermuteTwoSrc && LT.first != 1) { |
| Elena Demikhovsky | 21706cb | 2017-01-02 10:37:52 +0000 | [diff] [blame] | 830 | // We assume that source and destination have the same vector type. |
| Elena Demikhovsky | 21706cb | 2017-01-02 10:37:52 +0000 | [diff] [blame] | 831 | int NumOfDests = LT.first; |
| 832 | int NumOfShufflesPerDest = LT.first * 2 - 1; |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 833 | LT.first = NumOfDests * NumOfShufflesPerDest; |
| Karthik Bhat | e03a25d | 2014-06-20 04:32:48 +0000 | [diff] [blame] | 834 | } |
| 835 | |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 836 | static const CostTblEntry AVX512VBMIShuffleTbl[] = { |
| 837 | { TTI::SK_Reverse, MVT::v64i8, 1 }, // vpermb |
| 838 | { TTI::SK_Reverse, MVT::v32i8, 1 }, // vpermb |
| 839 | |
| 840 | { TTI::SK_PermuteSingleSrc, MVT::v64i8, 1 }, // vpermb |
| 841 | { TTI::SK_PermuteSingleSrc, MVT::v32i8, 1 }, // vpermb |
| 842 | |
| 843 | { TTI::SK_PermuteTwoSrc, MVT::v64i8, 1 }, // vpermt2b |
| 844 | { TTI::SK_PermuteTwoSrc, MVT::v32i8, 1 }, // vpermt2b |
| 845 | { TTI::SK_PermuteTwoSrc, MVT::v16i8, 1 } // vpermt2b |
| 846 | }; |
| 847 | |
| 848 | if (ST->hasVBMI()) |
| 849 | if (const auto *Entry = |
| 850 | CostTableLookup(AVX512VBMIShuffleTbl, Kind, LT.second)) |
| 851 | return LT.first * Entry->Cost; |
| 852 | |
| 853 | static const CostTblEntry AVX512BWShuffleTbl[] = { |
| 854 | { TTI::SK_Broadcast, MVT::v32i16, 1 }, // vpbroadcastw |
| 855 | { TTI::SK_Broadcast, MVT::v64i8, 1 }, // vpbroadcastb |
| 856 | |
| 857 | { TTI::SK_Reverse, MVT::v32i16, 1 }, // vpermw |
| 858 | { TTI::SK_Reverse, MVT::v16i16, 1 }, // vpermw |
| Simon Pilgrim | a1b8e2c | 2017-01-07 15:37:50 +0000 | [diff] [blame] | 859 | { TTI::SK_Reverse, MVT::v64i8, 2 }, // pshufb + vshufi64x2 |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 860 | |
| 861 | { TTI::SK_PermuteSingleSrc, MVT::v32i16, 1 }, // vpermw |
| 862 | { TTI::SK_PermuteSingleSrc, MVT::v16i16, 1 }, // vpermw |
| 863 | { TTI::SK_PermuteSingleSrc, MVT::v8i16, 1 }, // vpermw |
| 864 | { TTI::SK_PermuteSingleSrc, MVT::v64i8, 8 }, // extend to v32i16 |
| 865 | { TTI::SK_PermuteSingleSrc, MVT::v32i8, 3 }, // vpermw + zext/trunc |
| 866 | |
| 867 | { TTI::SK_PermuteTwoSrc, MVT::v32i16, 1 }, // vpermt2w |
| 868 | { TTI::SK_PermuteTwoSrc, MVT::v16i16, 1 }, // vpermt2w |
| 869 | { TTI::SK_PermuteTwoSrc, MVT::v8i16, 1 }, // vpermt2w |
| 870 | { TTI::SK_PermuteTwoSrc, MVT::v32i8, 3 }, // zext + vpermt2w + trunc |
| 871 | { TTI::SK_PermuteTwoSrc, MVT::v64i8, 19 }, // 6 * v32i8 + 1 |
| 872 | { TTI::SK_PermuteTwoSrc, MVT::v16i8, 3 } // zext + vpermt2w + trunc |
| 873 | }; |
| 874 | |
| 875 | if (ST->hasBWI()) |
| 876 | if (const auto *Entry = |
| 877 | CostTableLookup(AVX512BWShuffleTbl, Kind, LT.second)) |
| 878 | return LT.first * Entry->Cost; |
| 879 | |
| 880 | static const CostTblEntry AVX512ShuffleTbl[] = { |
| 881 | { TTI::SK_Broadcast, MVT::v8f64, 1 }, // vbroadcastpd |
| 882 | { TTI::SK_Broadcast, MVT::v16f32, 1 }, // vbroadcastps |
| 883 | { TTI::SK_Broadcast, MVT::v8i64, 1 }, // vpbroadcastq |
| 884 | { TTI::SK_Broadcast, MVT::v16i32, 1 }, // vpbroadcastd |
| 885 | |
| 886 | { TTI::SK_Reverse, MVT::v8f64, 1 }, // vpermpd |
| 887 | { TTI::SK_Reverse, MVT::v16f32, 1 }, // vpermps |
| 888 | { TTI::SK_Reverse, MVT::v8i64, 1 }, // vpermq |
| 889 | { TTI::SK_Reverse, MVT::v16i32, 1 }, // vpermd |
| 890 | |
| 891 | { TTI::SK_PermuteSingleSrc, MVT::v8f64, 1 }, // vpermpd |
| 892 | { TTI::SK_PermuteSingleSrc, MVT::v4f64, 1 }, // vpermpd |
| 893 | { TTI::SK_PermuteSingleSrc, MVT::v2f64, 1 }, // vpermpd |
| 894 | { TTI::SK_PermuteSingleSrc, MVT::v16f32, 1 }, // vpermps |
| 895 | { TTI::SK_PermuteSingleSrc, MVT::v8f32, 1 }, // vpermps |
| 896 | { TTI::SK_PermuteSingleSrc, MVT::v4f32, 1 }, // vpermps |
| 897 | { TTI::SK_PermuteSingleSrc, MVT::v8i64, 1 }, // vpermq |
| 898 | { TTI::SK_PermuteSingleSrc, MVT::v4i64, 1 }, // vpermq |
| 899 | { TTI::SK_PermuteSingleSrc, MVT::v2i64, 1 }, // vpermq |
| 900 | { TTI::SK_PermuteSingleSrc, MVT::v16i32, 1 }, // vpermd |
| 901 | { TTI::SK_PermuteSingleSrc, MVT::v8i32, 1 }, // vpermd |
| 902 | { TTI::SK_PermuteSingleSrc, MVT::v4i32, 1 }, // vpermd |
| 903 | { TTI::SK_PermuteSingleSrc, MVT::v16i8, 1 }, // pshufb |
| 904 | |
| 905 | { TTI::SK_PermuteTwoSrc, MVT::v8f64, 1 }, // vpermt2pd |
| 906 | { TTI::SK_PermuteTwoSrc, MVT::v16f32, 1 }, // vpermt2ps |
| 907 | { TTI::SK_PermuteTwoSrc, MVT::v8i64, 1 }, // vpermt2q |
| 908 | { TTI::SK_PermuteTwoSrc, MVT::v16i32, 1 }, // vpermt2d |
| 909 | { TTI::SK_PermuteTwoSrc, MVT::v4f64, 1 }, // vpermt2pd |
| 910 | { TTI::SK_PermuteTwoSrc, MVT::v8f32, 1 }, // vpermt2ps |
| 911 | { TTI::SK_PermuteTwoSrc, MVT::v4i64, 1 }, // vpermt2q |
| 912 | { TTI::SK_PermuteTwoSrc, MVT::v8i32, 1 }, // vpermt2d |
| 913 | { TTI::SK_PermuteTwoSrc, MVT::v2f64, 1 }, // vpermt2pd |
| 914 | { TTI::SK_PermuteTwoSrc, MVT::v4f32, 1 }, // vpermt2ps |
| 915 | { TTI::SK_PermuteTwoSrc, MVT::v2i64, 1 }, // vpermt2q |
| 916 | { TTI::SK_PermuteTwoSrc, MVT::v4i32, 1 } // vpermt2d |
| 917 | }; |
| 918 | |
| 919 | if (ST->hasAVX512()) |
| 920 | if (const auto *Entry = CostTableLookup(AVX512ShuffleTbl, Kind, LT.second)) |
| 921 | return LT.first * Entry->Cost; |
| 922 | |
| 923 | static const CostTblEntry AVX2ShuffleTbl[] = { |
| 924 | { TTI::SK_Broadcast, MVT::v4f64, 1 }, // vbroadcastpd |
| 925 | { TTI::SK_Broadcast, MVT::v8f32, 1 }, // vbroadcastps |
| 926 | { TTI::SK_Broadcast, MVT::v4i64, 1 }, // vpbroadcastq |
| 927 | { TTI::SK_Broadcast, MVT::v8i32, 1 }, // vpbroadcastd |
| 928 | { TTI::SK_Broadcast, MVT::v16i16, 1 }, // vpbroadcastw |
| 929 | { TTI::SK_Broadcast, MVT::v32i8, 1 }, // vpbroadcastb |
| 930 | |
| 931 | { TTI::SK_Reverse, MVT::v4f64, 1 }, // vpermpd |
| 932 | { TTI::SK_Reverse, MVT::v8f32, 1 }, // vpermps |
| 933 | { TTI::SK_Reverse, MVT::v4i64, 1 }, // vpermq |
| 934 | { TTI::SK_Reverse, MVT::v8i32, 1 }, // vpermd |
| 935 | { TTI::SK_Reverse, MVT::v16i16, 2 }, // vperm2i128 + pshufb |
| 936 | { TTI::SK_Reverse, MVT::v32i8, 2 }, // vperm2i128 + pshufb |
| 937 | |
| 938 | { TTI::SK_Alternate, MVT::v16i16, 1 }, // vpblendw |
| Michael Kuperstein | e6d59fd | 2017-02-02 20:27:13 +0000 | [diff] [blame] | 939 | { TTI::SK_Alternate, MVT::v32i8, 1 }, // vpblendvb |
| 940 | |
| Simon Pilgrim | 702e5fa | 2017-08-10 17:27:20 +0000 | [diff] [blame] | 941 | { TTI::SK_PermuteSingleSrc, MVT::v4f64, 1 }, // vpermpd |
| 942 | { TTI::SK_PermuteSingleSrc, MVT::v8f32, 1 }, // vpermps |
| Michael Kuperstein | e6d59fd | 2017-02-02 20:27:13 +0000 | [diff] [blame] | 943 | { TTI::SK_PermuteSingleSrc, MVT::v4i64, 1 }, // vpermq |
| 944 | { TTI::SK_PermuteSingleSrc, MVT::v8i32, 1 }, // vpermd |
| Simon Pilgrim | ac2e50a | 2017-08-10 18:29:34 +0000 | [diff] [blame] | 945 | { TTI::SK_PermuteSingleSrc, MVT::v16i16, 4 }, // vperm2i128 + 2*vpshufb |
| Michael Kuperstein | e6d59fd | 2017-02-02 20:27:13 +0000 | [diff] [blame] | 946 | // + vpblendvb |
| Simon Pilgrim | ac2e50a | 2017-08-10 18:29:34 +0000 | [diff] [blame] | 947 | { TTI::SK_PermuteSingleSrc, MVT::v32i8, 4 }, // vperm2i128 + 2*vpshufb |
| 948 | // + vpblendvb |
| 949 | |
| 950 | { TTI::SK_PermuteTwoSrc, MVT::v4f64, 3 }, // 2*vpermpd + vblendpd |
| 951 | { TTI::SK_PermuteTwoSrc, MVT::v8f32, 3 }, // 2*vpermps + vblendps |
| 952 | { TTI::SK_PermuteTwoSrc, MVT::v4i64, 3 }, // 2*vpermq + vpblendd |
| 953 | { TTI::SK_PermuteTwoSrc, MVT::v8i32, 3 }, // 2*vpermd + vpblendd |
| 954 | { TTI::SK_PermuteTwoSrc, MVT::v16i16, 7 }, // 2*vperm2i128 + 4*vpshufb |
| 955 | // + vpblendvb |
| 956 | { TTI::SK_PermuteTwoSrc, MVT::v32i8, 7 }, // 2*vperm2i128 + 4*vpshufb |
| Michael Kuperstein | e6d59fd | 2017-02-02 20:27:13 +0000 | [diff] [blame] | 957 | // + vpblendvb |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 958 | }; |
| 959 | |
| 960 | if (ST->hasAVX2()) |
| 961 | if (const auto *Entry = CostTableLookup(AVX2ShuffleTbl, Kind, LT.second)) |
| 962 | return LT.first * Entry->Cost; |
| 963 | |
| Simon Pilgrim | c63f93a | 2017-08-16 13:50:20 +0000 | [diff] [blame] | 964 | static const CostTblEntry XOPShuffleTbl[] = { |
| 965 | { TTI::SK_PermuteSingleSrc, MVT::v4f64, 2 }, // vperm2f128 + vpermil2pd |
| 966 | { TTI::SK_PermuteSingleSrc, MVT::v8f32, 2 }, // vperm2f128 + vpermil2ps |
| 967 | { TTI::SK_PermuteSingleSrc, MVT::v4i64, 2 }, // vperm2f128 + vpermil2pd |
| 968 | { TTI::SK_PermuteSingleSrc, MVT::v8i32, 2 }, // vperm2f128 + vpermil2ps |
| 969 | { TTI::SK_PermuteSingleSrc, MVT::v16i16, 4 }, // vextractf128 + 2*vpperm |
| 970 | // + vinsertf128 |
| 971 | { TTI::SK_PermuteSingleSrc, MVT::v32i8, 4 }, // vextractf128 + 2*vpperm |
| 972 | // + vinsertf128 |
| 973 | |
| 974 | { TTI::SK_PermuteTwoSrc, MVT::v16i16, 9 }, // 2*vextractf128 + 6*vpperm |
| 975 | // + vinsertf128 |
| 976 | { TTI::SK_PermuteTwoSrc, MVT::v8i16, 1 }, // vpperm |
| 977 | { TTI::SK_PermuteTwoSrc, MVT::v32i8, 9 }, // 2*vextractf128 + 6*vpperm |
| 978 | // + vinsertf128 |
| 979 | { TTI::SK_PermuteTwoSrc, MVT::v16i8, 1 }, // vpperm |
| 980 | }; |
| 981 | |
| 982 | if (ST->hasXOP()) |
| 983 | if (const auto *Entry = CostTableLookup(XOPShuffleTbl, Kind, LT.second)) |
| 984 | return LT.first * Entry->Cost; |
| 985 | |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 986 | static const CostTblEntry AVX1ShuffleTbl[] = { |
| 987 | { TTI::SK_Broadcast, MVT::v4f64, 2 }, // vperm2f128 + vpermilpd |
| 988 | { TTI::SK_Broadcast, MVT::v8f32, 2 }, // vperm2f128 + vpermilps |
| 989 | { TTI::SK_Broadcast, MVT::v4i64, 2 }, // vperm2f128 + vpermilpd |
| 990 | { TTI::SK_Broadcast, MVT::v8i32, 2 }, // vperm2f128 + vpermilps |
| 991 | { TTI::SK_Broadcast, MVT::v16i16, 3 }, // vpshuflw + vpshufd + vinsertf128 |
| 992 | { TTI::SK_Broadcast, MVT::v32i8, 2 }, // vpshufb + vinsertf128 |
| 993 | |
| 994 | { TTI::SK_Reverse, MVT::v4f64, 2 }, // vperm2f128 + vpermilpd |
| 995 | { TTI::SK_Reverse, MVT::v8f32, 2 }, // vperm2f128 + vpermilps |
| 996 | { TTI::SK_Reverse, MVT::v4i64, 2 }, // vperm2f128 + vpermilpd |
| 997 | { TTI::SK_Reverse, MVT::v8i32, 2 }, // vperm2f128 + vpermilps |
| 998 | { TTI::SK_Reverse, MVT::v16i16, 4 }, // vextractf128 + 2*pshufb |
| 999 | // + vinsertf128 |
| 1000 | { TTI::SK_Reverse, MVT::v32i8, 4 }, // vextractf128 + 2*pshufb |
| 1001 | // + vinsertf128 |
| 1002 | |
| 1003 | { TTI::SK_Alternate, MVT::v4i64, 1 }, // vblendpd |
| 1004 | { TTI::SK_Alternate, MVT::v4f64, 1 }, // vblendpd |
| 1005 | { TTI::SK_Alternate, MVT::v8i32, 1 }, // vblendps |
| 1006 | { TTI::SK_Alternate, MVT::v8f32, 1 }, // vblendps |
| 1007 | { TTI::SK_Alternate, MVT::v16i16, 3 }, // vpand + vpandn + vpor |
| Simon Pilgrim | 702e5fa | 2017-08-10 17:27:20 +0000 | [diff] [blame] | 1008 | { TTI::SK_Alternate, MVT::v32i8, 3 }, // vpand + vpandn + vpor |
| 1009 | |
| 1010 | { TTI::SK_PermuteSingleSrc, MVT::v4f64, 3 }, // 2*vperm2f128 + vshufpd |
| 1011 | { TTI::SK_PermuteSingleSrc, MVT::v4i64, 3 }, // 2*vperm2f128 + vshufpd |
| 1012 | { TTI::SK_PermuteSingleSrc, MVT::v8f32, 4 }, // 2*vperm2f128 + 2*vshufps |
| 1013 | { TTI::SK_PermuteSingleSrc, MVT::v8i32, 4 }, // 2*vperm2f128 + 2*vshufps |
| 1014 | { TTI::SK_PermuteSingleSrc, MVT::v16i16, 8 }, // vextractf128 + 4*pshufb |
| 1015 | // + 2*por + vinsertf128 |
| 1016 | { TTI::SK_PermuteSingleSrc, MVT::v32i8, 8 }, // vextractf128 + 4*pshufb |
| 1017 | // + 2*por + vinsertf128 |
| Simon Pilgrim | 7354531 | 2017-08-10 19:02:51 +0000 | [diff] [blame] | 1018 | |
| 1019 | { TTI::SK_PermuteTwoSrc, MVT::v4f64, 4 }, // 2*vperm2f128 + 2*vshufpd |
| 1020 | { TTI::SK_PermuteTwoSrc, MVT::v8f32, 4 }, // 2*vperm2f128 + 2*vshufps |
| 1021 | { TTI::SK_PermuteTwoSrc, MVT::v4i64, 4 }, // 2*vperm2f128 + 2*vshufpd |
| 1022 | { TTI::SK_PermuteTwoSrc, MVT::v8i32, 4 }, // 2*vperm2f128 + 2*vshufps |
| 1023 | { TTI::SK_PermuteTwoSrc, MVT::v16i16, 15 }, // 2*vextractf128 + 8*pshufb |
| 1024 | // + 4*por + vinsertf128 |
| 1025 | { TTI::SK_PermuteTwoSrc, MVT::v32i8, 15 }, // 2*vextractf128 + 8*pshufb |
| 1026 | // + 4*por + vinsertf128 |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 1027 | }; |
| 1028 | |
| 1029 | if (ST->hasAVX()) |
| 1030 | if (const auto *Entry = CostTableLookup(AVX1ShuffleTbl, Kind, LT.second)) |
| 1031 | return LT.first * Entry->Cost; |
| 1032 | |
| 1033 | static const CostTblEntry SSE41ShuffleTbl[] = { |
| 1034 | { TTI::SK_Alternate, MVT::v2i64, 1 }, // pblendw |
| 1035 | { TTI::SK_Alternate, MVT::v2f64, 1 }, // movsd |
| 1036 | { TTI::SK_Alternate, MVT::v4i32, 1 }, // pblendw |
| 1037 | { TTI::SK_Alternate, MVT::v4f32, 1 }, // blendps |
| 1038 | { TTI::SK_Alternate, MVT::v8i16, 1 }, // pblendw |
| 1039 | { TTI::SK_Alternate, MVT::v16i8, 1 } // pblendvb |
| 1040 | }; |
| 1041 | |
| 1042 | if (ST->hasSSE41()) |
| 1043 | if (const auto *Entry = CostTableLookup(SSE41ShuffleTbl, Kind, LT.second)) |
| 1044 | return LT.first * Entry->Cost; |
| 1045 | |
| 1046 | static const CostTblEntry SSSE3ShuffleTbl[] = { |
| 1047 | { TTI::SK_Broadcast, MVT::v8i16, 1 }, // pshufb |
| 1048 | { TTI::SK_Broadcast, MVT::v16i8, 1 }, // pshufb |
| 1049 | |
| 1050 | { TTI::SK_Reverse, MVT::v8i16, 1 }, // pshufb |
| 1051 | { TTI::SK_Reverse, MVT::v16i8, 1 }, // pshufb |
| 1052 | |
| Simon Pilgrim | 702e5fa | 2017-08-10 17:27:20 +0000 | [diff] [blame] | 1053 | { TTI::SK_Alternate, MVT::v8i16, 3 }, // 2*pshufb + por |
| 1054 | { TTI::SK_Alternate, MVT::v16i8, 3 }, // 2*pshufb + por |
| Michael Kuperstein | e6d59fd | 2017-02-02 20:27:13 +0000 | [diff] [blame] | 1055 | |
| 1056 | { TTI::SK_PermuteSingleSrc, MVT::v8i16, 1 }, // pshufb |
| Simon Pilgrim | 702e5fa | 2017-08-10 17:27:20 +0000 | [diff] [blame] | 1057 | { TTI::SK_PermuteSingleSrc, MVT::v16i8, 1 }, // pshufb |
| 1058 | |
| 1059 | { TTI::SK_PermuteTwoSrc, MVT::v8i16, 3 }, // 2*pshufb + por |
| 1060 | { TTI::SK_PermuteTwoSrc, MVT::v16i8, 3 }, // 2*pshufb + por |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 1061 | }; |
| 1062 | |
| 1063 | if (ST->hasSSSE3()) |
| 1064 | if (const auto *Entry = CostTableLookup(SSSE3ShuffleTbl, Kind, LT.second)) |
| 1065 | return LT.first * Entry->Cost; |
| 1066 | |
| 1067 | static const CostTblEntry SSE2ShuffleTbl[] = { |
| 1068 | { TTI::SK_Broadcast, MVT::v2f64, 1 }, // shufpd |
| 1069 | { TTI::SK_Broadcast, MVT::v2i64, 1 }, // pshufd |
| 1070 | { TTI::SK_Broadcast, MVT::v4i32, 1 }, // pshufd |
| Simon Pilgrim | 702e5fa | 2017-08-10 17:27:20 +0000 | [diff] [blame] | 1071 | { TTI::SK_Broadcast, MVT::v8i16, 2 }, // pshuflw + pshufd |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 1072 | { TTI::SK_Broadcast, MVT::v16i8, 3 }, // unpck + pshuflw + pshufd |
| 1073 | |
| 1074 | { TTI::SK_Reverse, MVT::v2f64, 1 }, // shufpd |
| 1075 | { TTI::SK_Reverse, MVT::v2i64, 1 }, // pshufd |
| 1076 | { TTI::SK_Reverse, MVT::v4i32, 1 }, // pshufd |
| Simon Pilgrim | 702e5fa | 2017-08-10 17:27:20 +0000 | [diff] [blame] | 1077 | { TTI::SK_Reverse, MVT::v8i16, 3 }, // pshuflw + pshufhw + pshufd |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 1078 | { TTI::SK_Reverse, MVT::v16i8, 9 }, // 2*pshuflw + 2*pshufhw |
| 1079 | // + 2*pshufd + 2*unpck + packus |
| 1080 | |
| 1081 | { TTI::SK_Alternate, MVT::v2i64, 1 }, // movsd |
| 1082 | { TTI::SK_Alternate, MVT::v2f64, 1 }, // movsd |
| 1083 | { TTI::SK_Alternate, MVT::v4i32, 2 }, // 2*shufps |
| 1084 | { TTI::SK_Alternate, MVT::v8i16, 3 }, // pand + pandn + por |
| Michael Kuperstein | e6d59fd | 2017-02-02 20:27:13 +0000 | [diff] [blame] | 1085 | { TTI::SK_Alternate, MVT::v16i8, 3 }, // pand + pandn + por |
| 1086 | |
| Simon Pilgrim | 702e5fa | 2017-08-10 17:27:20 +0000 | [diff] [blame] | 1087 | { TTI::SK_PermuteSingleSrc, MVT::v2f64, 1 }, // shufpd |
| 1088 | { TTI::SK_PermuteSingleSrc, MVT::v2i64, 1 }, // pshufd |
| 1089 | { TTI::SK_PermuteSingleSrc, MVT::v4i32, 1 }, // pshufd |
| 1090 | { TTI::SK_PermuteSingleSrc, MVT::v8i16, 5 }, // 2*pshuflw + 2*pshufhw |
| 1091 | // + pshufd/unpck |
| 1092 | { TTI::SK_PermuteSingleSrc, MVT::v16i8, 10 }, // 2*pshuflw + 2*pshufhw |
| 1093 | // + 2*pshufd + 2*unpck + 2*packus |
| 1094 | |
| 1095 | { TTI::SK_PermuteTwoSrc, MVT::v2f64, 1 }, // shufpd |
| 1096 | { TTI::SK_PermuteTwoSrc, MVT::v2i64, 1 }, // shufpd |
| 1097 | { TTI::SK_PermuteTwoSrc, MVT::v4i32, 2 }, // 2*{unpck,movsd,pshufd} |
| Simon Pilgrim | b59c2d9 | 2017-08-10 19:32:35 +0000 | [diff] [blame] | 1098 | { TTI::SK_PermuteTwoSrc, MVT::v8i16, 8 }, // blend+permute |
| 1099 | { TTI::SK_PermuteTwoSrc, MVT::v16i8, 13 }, // blend+permute |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 1100 | }; |
| 1101 | |
| 1102 | if (ST->hasSSE2()) |
| 1103 | if (const auto *Entry = CostTableLookup(SSE2ShuffleTbl, Kind, LT.second)) |
| 1104 | return LT.first * Entry->Cost; |
| 1105 | |
| 1106 | static const CostTblEntry SSE1ShuffleTbl[] = { |
| Simon Pilgrim | 702e5fa | 2017-08-10 17:27:20 +0000 | [diff] [blame] | 1107 | { TTI::SK_Broadcast, MVT::v4f32, 1 }, // shufps |
| 1108 | { TTI::SK_Reverse, MVT::v4f32, 1 }, // shufps |
| 1109 | { TTI::SK_Alternate, MVT::v4f32, 2 }, // 2*shufps |
| 1110 | { TTI::SK_PermuteSingleSrc, MVT::v4f32, 1 }, // shufps |
| 1111 | { TTI::SK_PermuteTwoSrc, MVT::v4f32, 2 }, // 2*shufps |
| Simon Pilgrim | f74700a | 2017-01-05 17:56:19 +0000 | [diff] [blame] | 1112 | }; |
| 1113 | |
| 1114 | if (ST->hasSSE1()) |
| 1115 | if (const auto *Entry = CostTableLookup(SSE1ShuffleTbl, Kind, LT.second)) |
| 1116 | return LT.first * Entry->Cost; |
| 1117 | |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1118 | return BaseT::getShuffleCost(Kind, Tp, Index, SubTp); |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
| Jonas Paulsson | fccc7d6 | 2017-04-12 11:49:08 +0000 | [diff] [blame] | 1121 | int X86TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, |
| 1122 | const Instruction *I) { |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1123 | int ISD = TLI->InstructionOpcodeToISD(Opcode); |
| 1124 | assert(ISD && "Invalid opcode"); |
| 1125 | |
| Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 1126 | // FIXME: Need a better design of the cost table to handle non-simple types of |
| 1127 | // potential massive combinations (elem_num x src_type x dst_type). |
| 1128 | |
| Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 1129 | static const TypeConversionCostTblEntry AVX512DQConversionTbl[] = { |
| Simon Pilgrim | 841d7ca | 2016-11-24 14:46:55 +0000 | [diff] [blame] | 1130 | { ISD::SINT_TO_FP, MVT::v2f32, MVT::v2i64, 1 }, |
| 1131 | { ISD::SINT_TO_FP, MVT::v2f64, MVT::v2i64, 1 }, |
| Simon Pilgrim | 4e9b9cb | 2016-11-23 14:01:18 +0000 | [diff] [blame] | 1132 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i64, 1 }, |
| 1133 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i64, 1 }, |
| Simon Pilgrim | 03cd8f8 | 2016-11-23 13:42:09 +0000 | [diff] [blame] | 1134 | { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i64, 1 }, |
| 1135 | { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i64, 1 }, |
| 1136 | |
| Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 1137 | { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i64, 1 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1138 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, 1 }, |
| Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 1139 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i64, 1 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1140 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i64, 1 }, |
| Simon Pilgrim | 285d9e4 | 2016-07-17 19:02:27 +0000 | [diff] [blame] | 1141 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i64, 1 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1142 | { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i64, 1 }, |
| Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 1143 | |
| Simon Pilgrim | 841d7ca | 2016-11-24 14:46:55 +0000 | [diff] [blame] | 1144 | { ISD::FP_TO_SINT, MVT::v2i64, MVT::v2f32, 1 }, |
| Simon Pilgrim | 4e9b9cb | 2016-11-23 14:01:18 +0000 | [diff] [blame] | 1145 | { ISD::FP_TO_SINT, MVT::v4i64, MVT::v4f32, 1 }, |
| Simon Pilgrim | 03cd8f8 | 2016-11-23 13:42:09 +0000 | [diff] [blame] | 1146 | { ISD::FP_TO_SINT, MVT::v8i64, MVT::v8f32, 1 }, |
| Simon Pilgrim | 841d7ca | 2016-11-24 14:46:55 +0000 | [diff] [blame] | 1147 | { ISD::FP_TO_SINT, MVT::v2i64, MVT::v2f64, 1 }, |
| Simon Pilgrim | 4e9b9cb | 2016-11-23 14:01:18 +0000 | [diff] [blame] | 1148 | { ISD::FP_TO_SINT, MVT::v4i64, MVT::v4f64, 1 }, |
| Simon Pilgrim | 03cd8f8 | 2016-11-23 13:42:09 +0000 | [diff] [blame] | 1149 | { ISD::FP_TO_SINT, MVT::v8i64, MVT::v8f64, 1 }, |
| 1150 | |
| 1151 | { ISD::FP_TO_UINT, MVT::v2i64, MVT::v2f32, 1 }, |
| 1152 | { ISD::FP_TO_UINT, MVT::v4i64, MVT::v4f32, 1 }, |
| 1153 | { ISD::FP_TO_UINT, MVT::v8i64, MVT::v8f32, 1 }, |
| 1154 | { ISD::FP_TO_UINT, MVT::v2i64, MVT::v2f64, 1 }, |
| 1155 | { ISD::FP_TO_UINT, MVT::v4i64, MVT::v4f64, 1 }, |
| 1156 | { ISD::FP_TO_UINT, MVT::v8i64, MVT::v8f64, 1 }, |
| Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 1157 | }; |
| 1158 | |
| Michael Kuperstein | f0c5933 | 2016-07-11 21:39:44 +0000 | [diff] [blame] | 1159 | // TODO: For AVX512DQ + AVX512VL, we also have cheap casts for 128-bit and |
| 1160 | // 256-bit wide vectors. |
| 1161 | |
| Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 1162 | static const TypeConversionCostTblEntry AVX512FConversionTbl[] = { |
| Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 1163 | { ISD::FP_EXTEND, MVT::v8f64, MVT::v8f32, 1 }, |
| 1164 | { ISD::FP_EXTEND, MVT::v8f64, MVT::v16f32, 3 }, |
| 1165 | { ISD::FP_ROUND, MVT::v8f32, MVT::v8f64, 1 }, |
| Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 1166 | |
| 1167 | { ISD::TRUNCATE, MVT::v16i8, MVT::v16i32, 1 }, |
| 1168 | { ISD::TRUNCATE, MVT::v16i16, MVT::v16i32, 1 }, |
| 1169 | { ISD::TRUNCATE, MVT::v8i16, MVT::v8i64, 1 }, |
| 1170 | { ISD::TRUNCATE, MVT::v8i32, MVT::v8i64, 1 }, |
| Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 1171 | |
| 1172 | // v16i1 -> v16i32 - load + broadcast |
| 1173 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i1, 2 }, |
| 1174 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i1, 2 }, |
| Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 1175 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i8, 1 }, |
| 1176 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i8, 1 }, |
| 1177 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i16, 1 }, |
| 1178 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i16, 1 }, |
| Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 1179 | { ISD::ZERO_EXTEND, MVT::v8i64, MVT::v8i16, 1 }, |
| 1180 | { ISD::SIGN_EXTEND, MVT::v8i64, MVT::v8i16, 1 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1181 | { ISD::SIGN_EXTEND, MVT::v8i64, MVT::v8i32, 1 }, |
| 1182 | { ISD::ZERO_EXTEND, MVT::v8i64, MVT::v8i32, 1 }, |
| Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 1183 | |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1184 | { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i1, 4 }, |
| Elena Demikhovsky | d5e95b5 | 2014-11-13 11:46:16 +0000 | [diff] [blame] | 1185 | { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i1, 3 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1186 | { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i8, 2 }, |
| Elena Demikhovsky | d5e95b5 | 2014-11-13 11:46:16 +0000 | [diff] [blame] | 1187 | { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i8, 2 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1188 | { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i16, 2 }, |
| Elena Demikhovsky | d5e95b5 | 2014-11-13 11:46:16 +0000 | [diff] [blame] | 1189 | { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i16, 2 }, |
| 1190 | { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i32, 1 }, |
| Elena Demikhovsky | d5e95b5 | 2014-11-13 11:46:16 +0000 | [diff] [blame] | 1191 | { ISD::SINT_TO_FP, MVT::v8f64, MVT::v8i32, 1 }, |
| Michael Kuperstein | f0c5933 | 2016-07-11 21:39:44 +0000 | [diff] [blame] | 1192 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i64, 26 }, |
| 1193 | { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i64, 26 }, |
| Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 1194 | |
| Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 1195 | { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i1, 4 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1196 | { ISD::UINT_TO_FP, MVT::v16f32, MVT::v16i1, 3 }, |
| Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 1197 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i8, 2 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1198 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i8, 2 }, |
| 1199 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i8, 2 }, |
| 1200 | { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i8, 2 }, |
| 1201 | { ISD::UINT_TO_FP, MVT::v16f32, MVT::v16i8, 2 }, |
| Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 1202 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i16, 5 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1203 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i16, 2 }, |
| 1204 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i16, 2 }, |
| 1205 | { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i16, 2 }, |
| 1206 | { ISD::UINT_TO_FP, MVT::v16f32, MVT::v16i16, 2 }, |
| Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 1207 | { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i32, 2 }, |
| Simon Pilgrim | 285d9e4 | 2016-07-17 19:02:27 +0000 | [diff] [blame] | 1208 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i32, 1 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1209 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, 1 }, |
| 1210 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i32, 1 }, |
| 1211 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i32, 1 }, |
| 1212 | { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i32, 1 }, |
| 1213 | { ISD::UINT_TO_FP, MVT::v16f32, MVT::v16i32, 1 }, |
| Simon Pilgrim | 285d9e4 | 2016-07-17 19:02:27 +0000 | [diff] [blame] | 1214 | { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i64, 5 }, |
| Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 1215 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, 5 }, |
| 1216 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i64, 12 }, |
| 1217 | { ISD::UINT_TO_FP, MVT::v8f64, MVT::v8i64, 26 }, |
| 1218 | |
| 1219 | { ISD::FP_TO_UINT, MVT::v2i32, MVT::v2f32, 1 }, |
| 1220 | { ISD::FP_TO_UINT, MVT::v4i32, MVT::v4f32, 1 }, |
| 1221 | { ISD::FP_TO_UINT, MVT::v8i32, MVT::v8f32, 1 }, |
| Zvi Rackover | 25799d9 | 2017-09-07 07:40:34 +0000 | [diff] [blame] | 1222 | { ISD::FP_TO_UINT, MVT::v8i16, MVT::v8f64, 2 }, |
| 1223 | { ISD::FP_TO_UINT, MVT::v8i8, MVT::v8f64, 2 }, |
| Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 1224 | { ISD::FP_TO_UINT, MVT::v16i32, MVT::v16f32, 1 }, |
| Zvi Rackover | 25799d9 | 2017-09-07 07:40:34 +0000 | [diff] [blame] | 1225 | { ISD::FP_TO_UINT, MVT::v16i16, MVT::v16f32, 2 }, |
| 1226 | { ISD::FP_TO_UINT, MVT::v16i8, MVT::v16f32, 2 }, |
| Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 1227 | }; |
| 1228 | |
| Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 1229 | static const TypeConversionCostTblEntry AVX2ConversionTbl[] = { |
| Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 1230 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i1, 3 }, |
| 1231 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i1, 3 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1232 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i1, 3 }, |
| 1233 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i1, 3 }, |
| Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 1234 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i8, 3 }, |
| 1235 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i8, 3 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1236 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i8, 3 }, |
| 1237 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i8, 3 }, |
| 1238 | { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i8, 1 }, |
| 1239 | { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i8, 1 }, |
| Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 1240 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i16, 3 }, |
| 1241 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i16, 3 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1242 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, 1 }, |
| 1243 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, 1 }, |
| Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 1244 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, 1 }, |
| 1245 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, 1 }, |
| 1246 | |
| 1247 | { ISD::TRUNCATE, MVT::v4i8, MVT::v4i64, 2 }, |
| 1248 | { ISD::TRUNCATE, MVT::v4i16, MVT::v4i64, 2 }, |
| 1249 | { ISD::TRUNCATE, MVT::v4i32, MVT::v4i64, 2 }, |
| 1250 | { ISD::TRUNCATE, MVT::v8i8, MVT::v8i32, 2 }, |
| 1251 | { ISD::TRUNCATE, MVT::v8i16, MVT::v8i32, 2 }, |
| 1252 | { ISD::TRUNCATE, MVT::v8i32, MVT::v8i64, 4 }, |
| Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 1253 | |
| 1254 | { ISD::FP_EXTEND, MVT::v8f64, MVT::v8f32, 3 }, |
| 1255 | { ISD::FP_ROUND, MVT::v8f32, MVT::v8f64, 3 }, |
| Quentin Colombet | 360460b | 2014-11-11 02:23:47 +0000 | [diff] [blame] | 1256 | |
| 1257 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i32, 8 }, |
| Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 1258 | }; |
| 1259 | |
| Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 1260 | static const TypeConversionCostTblEntry AVXConversionTbl[] = { |
| Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 1261 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i1, 6 }, |
| 1262 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i1, 4 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1263 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i1, 7 }, |
| 1264 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i1, 4 }, |
| Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 1265 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i8, 6 }, |
| 1266 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i8, 4 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1267 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i8, 7 }, |
| 1268 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i8, 4 }, |
| 1269 | { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i8, 4 }, |
| 1270 | { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i8, 4 }, |
| Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 1271 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i16, 6 }, |
| 1272 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i16, 3 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1273 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, 4 }, |
| 1274 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, 4 }, |
| Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 1275 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, 4 }, |
| 1276 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, 4 }, |
| 1277 | |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1278 | { ISD::TRUNCATE, MVT::v16i8, MVT::v16i16, 4 }, |
| 1279 | { ISD::TRUNCATE, MVT::v8i8, MVT::v8i32, 4 }, |
| 1280 | { ISD::TRUNCATE, MVT::v8i16, MVT::v8i32, 5 }, |
| Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 1281 | { ISD::TRUNCATE, MVT::v4i8, MVT::v4i64, 4 }, |
| 1282 | { ISD::TRUNCATE, MVT::v4i16, MVT::v4i64, 4 }, |
| 1283 | { ISD::TRUNCATE, MVT::v4i32, MVT::v4i64, 4 }, |
| Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 1284 | { ISD::TRUNCATE, MVT::v8i32, MVT::v8i64, 9 }, |
| Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 1285 | |
| Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 1286 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i1, 3 }, |
| Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 1287 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i1, 3 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1288 | { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i1, 8 }, |
| 1289 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i8, 3 }, |
| Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 1290 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i8, 3 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1291 | { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i8, 8 }, |
| 1292 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i16, 3 }, |
| Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 1293 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i16, 3 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1294 | { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i16, 5 }, |
| 1295 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i32, 1 }, |
| Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 1296 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i32, 1 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1297 | { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i32, 1 }, |
| Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 1298 | |
| Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 1299 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i1, 7 }, |
| Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 1300 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i1, 7 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1301 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i1, 6 }, |
| 1302 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i8, 2 }, |
| Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 1303 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i8, 2 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1304 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i8, 5 }, |
| 1305 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i16, 2 }, |
| Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 1306 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i16, 2 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1307 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i16, 5 }, |
| Michael Kuperstein | f0c5933 | 2016-07-11 21:39:44 +0000 | [diff] [blame] | 1308 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i32, 6 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1309 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, 6 }, |
| Benjamin Kramer | 52ceb44 | 2013-04-01 10:23:49 +0000 | [diff] [blame] | 1310 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i32, 6 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1311 | { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i32, 9 }, |
| Quentin Colombet | 85b904d | 2014-03-27 22:27:41 +0000 | [diff] [blame] | 1312 | // The generic code to compute the scalar overhead is currently broken. |
| 1313 | // Workaround this limitation by estimating the scalarization overhead |
| 1314 | // here. We have roughly 10 instructions per scalar element. |
| 1315 | // Multiply that by the vector width. |
| 1316 | // FIXME: remove that when PR19268 is fixed. |
| Michael Kuperstein | f0c5933 | 2016-07-11 21:39:44 +0000 | [diff] [blame] | 1317 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, 10 }, |
| 1318 | { ISD::UINT_TO_FP, MVT::v4f64, MVT::v4i64, 20 }, |
| 1319 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i64, 13 }, |
| 1320 | { ISD::SINT_TO_FP, MVT::v4f64, MVT::v4i64, 13 }, |
| Simon Pilgrim | 285d9e4 | 2016-07-17 19:02:27 +0000 | [diff] [blame] | 1321 | |
| Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 1322 | { ISD::FP_TO_SINT, MVT::v4i8, MVT::v4f32, 1 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1323 | { ISD::FP_TO_SINT, MVT::v8i8, MVT::v8f32, 7 }, |
| Adam Nemet | 6dafe97 | 2014-03-30 18:07:13 +0000 | [diff] [blame] | 1324 | // This node is expanded into scalarized operations but BasicTTI is overly |
| 1325 | // optimistic estimating its cost. It computes 3 per element (one |
| 1326 | // vector-extract, one scalar conversion and one vector-insert). The |
| 1327 | // problem is that the inserts form a read-modify-write chain so latency |
| 1328 | // should be factored in too. Inflating the cost per element by 1. |
| 1329 | { ISD::FP_TO_UINT, MVT::v8i32, MVT::v8f32, 8*4 }, |
| Adam Nemet | 10c4ce2 | 2014-03-31 21:54:48 +0000 | [diff] [blame] | 1330 | { ISD::FP_TO_UINT, MVT::v4i32, MVT::v4f64, 4*4 }, |
| Michael Kuperstein | f0c5933 | 2016-07-11 21:39:44 +0000 | [diff] [blame] | 1331 | |
| 1332 | { ISD::FP_EXTEND, MVT::v4f64, MVT::v4f32, 1 }, |
| 1333 | { ISD::FP_ROUND, MVT::v4f32, MVT::v4f64, 1 }, |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1334 | }; |
| 1335 | |
| Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 1336 | static const TypeConversionCostTblEntry SSE41ConversionTbl[] = { |
| Michael Kuperstein | 9a0542a | 2016-06-10 17:01:05 +0000 | [diff] [blame] | 1337 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i8, 2 }, |
| 1338 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i8, 2 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1339 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i16, 2 }, |
| 1340 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i16, 2 }, |
| 1341 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, 2 }, |
| 1342 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, 2 }, |
| Michael Kuperstein | 9a0542a | 2016-06-10 17:01:05 +0000 | [diff] [blame] | 1343 | |
| Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 1344 | { ISD::ZERO_EXTEND, MVT::v4i16, MVT::v4i8, 1 }, |
| 1345 | { ISD::SIGN_EXTEND, MVT::v4i16, MVT::v4i8, 2 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1346 | { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v4i8, 1 }, |
| 1347 | { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v4i8, 1 }, |
| 1348 | { ISD::ZERO_EXTEND, MVT::v8i16, MVT::v8i8, 1 }, |
| 1349 | { ISD::SIGN_EXTEND, MVT::v8i16, MVT::v8i8, 1 }, |
| 1350 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i8, 2 }, |
| 1351 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i8, 2 }, |
| 1352 | { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i8, 2 }, |
| 1353 | { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i8, 2 }, |
| 1354 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i8, 4 }, |
| 1355 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i8, 4 }, |
| 1356 | { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v4i16, 1 }, |
| 1357 | { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v4i16, 1 }, |
| 1358 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, 2 }, |
| 1359 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, 2 }, |
| 1360 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i16, 4 }, |
| 1361 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i16, 4 }, |
| Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 1362 | |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1363 | { ISD::TRUNCATE, MVT::v4i8, MVT::v4i16, 2 }, |
| 1364 | { ISD::TRUNCATE, MVT::v8i8, MVT::v8i16, 1 }, |
| 1365 | { ISD::TRUNCATE, MVT::v4i8, MVT::v4i32, 1 }, |
| Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 1366 | { ISD::TRUNCATE, MVT::v4i16, MVT::v4i32, 1 }, |
| Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 1367 | { ISD::TRUNCATE, MVT::v8i8, MVT::v8i32, 3 }, |
| Simon Pilgrim | 285d9e4 | 2016-07-17 19:02:27 +0000 | [diff] [blame] | 1368 | { ISD::TRUNCATE, MVT::v8i16, MVT::v8i32, 3 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1369 | { ISD::TRUNCATE, MVT::v16i16, MVT::v16i32, 6 }, |
| 1370 | |
| Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 1371 | }; |
| 1372 | |
| 1373 | static const TypeConversionCostTblEntry SSE2ConversionTbl[] = { |
| Simon Pilgrim | e2c244f | 2015-07-19 15:36:12 +0000 | [diff] [blame] | 1374 | // These are somewhat magic numbers justified by looking at the output of |
| 1375 | // Intel's IACA, running some kernels and making sure when we take |
| 1376 | // legalization into account the throughput will be overestimated. |
| Simon Pilgrim | e2c244f | 2015-07-19 15:36:12 +0000 | [diff] [blame] | 1377 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v16i8, 8 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1378 | { ISD::SINT_TO_FP, MVT::v2f64, MVT::v16i8, 16*10 }, |
| 1379 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v8i16, 15 }, |
| 1380 | { ISD::SINT_TO_FP, MVT::v2f64, MVT::v8i16, 8*10 }, |
| Sanjay Patel | 04b3496 | 2016-07-06 19:15:54 +0000 | [diff] [blame] | 1381 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i32, 5 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1382 | { ISD::SINT_TO_FP, MVT::v2f64, MVT::v4i32, 4*10 }, |
| 1383 | { ISD::SINT_TO_FP, MVT::v4f32, MVT::v2i64, 15 }, |
| 1384 | { ISD::SINT_TO_FP, MVT::v2f64, MVT::v2i64, 2*10 }, |
| Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 1385 | |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1386 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v16i8, 16*10 }, |
| 1387 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v16i8, 8 }, |
| 1388 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v8i16, 15 }, |
| 1389 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v8i16, 8*10 }, |
| 1390 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v4i32, 4*10 }, |
| 1391 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, 8 }, |
| 1392 | { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, 2*10 }, |
| 1393 | { ISD::UINT_TO_FP, MVT::v4f32, MVT::v2i64, 15 }, |
| Michael Kuperstein | 9a0542a | 2016-06-10 17:01:05 +0000 | [diff] [blame] | 1394 | |
| Simon Pilgrim | 4ddc92b | 2016-10-18 07:42:15 +0000 | [diff] [blame] | 1395 | { ISD::FP_TO_SINT, MVT::v2i32, MVT::v2f64, 3 }, |
| 1396 | |
| Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 1397 | { ISD::ZERO_EXTEND, MVT::v4i16, MVT::v4i8, 1 }, |
| 1398 | { ISD::SIGN_EXTEND, MVT::v4i16, MVT::v4i8, 6 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1399 | { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v4i8, 2 }, |
| 1400 | { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v4i8, 3 }, |
| 1401 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i8, 4 }, |
| 1402 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i8, 8 }, |
| 1403 | { ISD::ZERO_EXTEND, MVT::v8i16, MVT::v8i8, 1 }, |
| 1404 | { ISD::SIGN_EXTEND, MVT::v8i16, MVT::v8i8, 2 }, |
| 1405 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i8, 6 }, |
| 1406 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i8, 6 }, |
| 1407 | { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i8, 3 }, |
| 1408 | { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i8, 4 }, |
| 1409 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i8, 9 }, |
| 1410 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i8, 12 }, |
| 1411 | { ISD::ZERO_EXTEND, MVT::v4i32, MVT::v4i16, 1 }, |
| 1412 | { ISD::SIGN_EXTEND, MVT::v4i32, MVT::v4i16, 2 }, |
| 1413 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i16, 3 }, |
| 1414 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i16, 10 }, |
| 1415 | { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, 3 }, |
| 1416 | { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, 4 }, |
| 1417 | { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i16, 6 }, |
| Simon Pilgrim | 285d9e4 | 2016-07-17 19:02:27 +0000 | [diff] [blame] | 1418 | { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i16, 8 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1419 | { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, 3 }, |
| 1420 | { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, 5 }, |
| Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 1421 | |
| Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 1422 | { ISD::TRUNCATE, MVT::v4i8, MVT::v4i16, 4 }, |
| Michael Kuperstein | 1b62e0e | 2016-07-06 18:26:48 +0000 | [diff] [blame] | 1423 | { ISD::TRUNCATE, MVT::v8i8, MVT::v8i16, 2 }, |
| 1424 | { ISD::TRUNCATE, MVT::v16i8, MVT::v16i16, 3 }, |
| 1425 | { ISD::TRUNCATE, MVT::v4i8, MVT::v4i32, 3 }, |
| 1426 | { ISD::TRUNCATE, MVT::v4i16, MVT::v4i32, 3 }, |
| 1427 | { ISD::TRUNCATE, MVT::v8i8, MVT::v8i32, 4 }, |
| 1428 | { ISD::TRUNCATE, MVT::v16i8, MVT::v16i32, 7 }, |
| 1429 | { ISD::TRUNCATE, MVT::v8i16, MVT::v8i32, 5 }, |
| 1430 | { ISD::TRUNCATE, MVT::v16i16, MVT::v16i32, 10 }, |
| Simon Pilgrim | e2c244f | 2015-07-19 15:36:12 +0000 | [diff] [blame] | 1431 | }; |
| 1432 | |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1433 | std::pair<int, MVT> LTSrc = TLI->getTypeLegalizationCost(DL, Src); |
| 1434 | std::pair<int, MVT> LTDest = TLI->getTypeLegalizationCost(DL, Dst); |
| Simon Pilgrim | e2c244f | 2015-07-19 15:36:12 +0000 | [diff] [blame] | 1435 | |
| 1436 | if (ST->hasSSE2() && !ST->hasAVX()) { |
| Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 1437 | if (const auto *Entry = ConvertCostTableLookup(SSE2ConversionTbl, ISD, |
| Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 1438 | LTDest.second, LTSrc.second)) |
| 1439 | return LTSrc.first * Entry->Cost; |
| Simon Pilgrim | e2c244f | 2015-07-19 15:36:12 +0000 | [diff] [blame] | 1440 | } |
| 1441 | |
| Simon Pilgrim | e2c244f | 2015-07-19 15:36:12 +0000 | [diff] [blame] | 1442 | EVT SrcTy = TLI->getValueType(DL, Src); |
| 1443 | EVT DstTy = TLI->getValueType(DL, Dst); |
| 1444 | |
| 1445 | // The function getSimpleVT only handles simple value types. |
| 1446 | if (!SrcTy.isSimple() || !DstTy.isSimple()) |
| 1447 | return BaseT::getCastInstrCost(Opcode, Dst, Src); |
| 1448 | |
| Elena Demikhovsky | a1a40cc | 2015-12-02 08:59:47 +0000 | [diff] [blame] | 1449 | if (ST->hasDQI()) |
| 1450 | if (const auto *Entry = ConvertCostTableLookup(AVX512DQConversionTbl, ISD, |
| 1451 | DstTy.getSimpleVT(), |
| 1452 | SrcTy.getSimpleVT())) |
| 1453 | return Entry->Cost; |
| 1454 | |
| 1455 | if (ST->hasAVX512()) |
| 1456 | if (const auto *Entry = ConvertCostTableLookup(AVX512FConversionTbl, ISD, |
| 1457 | DstTy.getSimpleVT(), |
| 1458 | SrcTy.getSimpleVT())) |
| 1459 | return Entry->Cost; |
| 1460 | |
| Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 1461 | if (ST->hasAVX2()) { |
| Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 1462 | if (const auto *Entry = ConvertCostTableLookup(AVX2ConversionTbl, ISD, |
| 1463 | DstTy.getSimpleVT(), |
| 1464 | SrcTy.getSimpleVT())) |
| 1465 | return Entry->Cost; |
| Tim Northover | f0e2161 | 2014-02-06 18:18:36 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1468 | if (ST->hasAVX()) { |
| Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 1469 | if (const auto *Entry = ConvertCostTableLookup(AVXConversionTbl, ISD, |
| 1470 | DstTy.getSimpleVT(), |
| 1471 | SrcTy.getSimpleVT())) |
| 1472 | return Entry->Cost; |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1473 | } |
| 1474 | |
| Cong Hou | 59898d8 | 2015-12-11 00:31:39 +0000 | [diff] [blame] | 1475 | if (ST->hasSSE41()) { |
| 1476 | if (const auto *Entry = ConvertCostTableLookup(SSE41ConversionTbl, ISD, |
| 1477 | DstTy.getSimpleVT(), |
| 1478 | SrcTy.getSimpleVT())) |
| 1479 | return Entry->Cost; |
| 1480 | } |
| 1481 | |
| 1482 | if (ST->hasSSE2()) { |
| 1483 | if (const auto *Entry = ConvertCostTableLookup(SSE2ConversionTbl, ISD, |
| 1484 | DstTy.getSimpleVT(), |
| 1485 | SrcTy.getSimpleVT())) |
| 1486 | return Entry->Cost; |
| 1487 | } |
| 1488 | |
| Alexey Bataev | e25a6fd | 2017-11-07 14:23:44 +0000 | [diff] [blame] | 1489 | return BaseT::getCastInstrCost(Opcode, Dst, Src, I); |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
| Jonas Paulsson | fccc7d6 | 2017-04-12 11:49:08 +0000 | [diff] [blame] | 1492 | int X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, |
| 1493 | const Instruction *I) { |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1494 | // Legalize the type. |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1495 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, ValTy); |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1496 | |
| 1497 | MVT MTy = LT.second; |
| 1498 | |
| 1499 | int ISD = TLI->InstructionOpcodeToISD(Opcode); |
| 1500 | assert(ISD && "Invalid opcode"); |
| 1501 | |
| Simon Pilgrim | eec3a95 | 2016-05-09 21:14:38 +0000 | [diff] [blame] | 1502 | static const CostTblEntry SSE2CostTbl[] = { |
| 1503 | { ISD::SETCC, MVT::v2i64, 8 }, |
| 1504 | { ISD::SETCC, MVT::v4i32, 1 }, |
| 1505 | { ISD::SETCC, MVT::v8i16, 1 }, |
| 1506 | { ISD::SETCC, MVT::v16i8, 1 }, |
| 1507 | }; |
| 1508 | |
| Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 1509 | static const CostTblEntry SSE42CostTbl[] = { |
| Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 1510 | { ISD::SETCC, MVT::v2f64, 1 }, |
| 1511 | { ISD::SETCC, MVT::v4f32, 1 }, |
| 1512 | { ISD::SETCC, MVT::v2i64, 1 }, |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1513 | }; |
| 1514 | |
| Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 1515 | static const CostTblEntry AVX1CostTbl[] = { |
| Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 1516 | { ISD::SETCC, MVT::v4f64, 1 }, |
| 1517 | { ISD::SETCC, MVT::v8f32, 1 }, |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1518 | // AVX1 does not support 8-wide integer compare. |
| Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 1519 | { ISD::SETCC, MVT::v4i64, 4 }, |
| 1520 | { ISD::SETCC, MVT::v8i32, 4 }, |
| 1521 | { ISD::SETCC, MVT::v16i16, 4 }, |
| 1522 | { ISD::SETCC, MVT::v32i8, 4 }, |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1523 | }; |
| 1524 | |
| Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 1525 | static const CostTblEntry AVX2CostTbl[] = { |
| Renato Golin | e1fb059 | 2013-01-20 20:57:20 +0000 | [diff] [blame] | 1526 | { ISD::SETCC, MVT::v4i64, 1 }, |
| 1527 | { ISD::SETCC, MVT::v8i32, 1 }, |
| 1528 | { ISD::SETCC, MVT::v16i16, 1 }, |
| 1529 | { ISD::SETCC, MVT::v32i8, 1 }, |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1530 | }; |
| 1531 | |
| Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 1532 | static const CostTblEntry AVX512CostTbl[] = { |
| Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 1533 | { ISD::SETCC, MVT::v8i64, 1 }, |
| 1534 | { ISD::SETCC, MVT::v16i32, 1 }, |
| 1535 | { ISD::SETCC, MVT::v8f64, 1 }, |
| 1536 | { ISD::SETCC, MVT::v16f32, 1 }, |
| 1537 | }; |
| 1538 | |
| Simon Pilgrim | 80ce1dd | 2018-04-07 13:24:33 +0000 | [diff] [blame] | 1539 | static const CostTblEntry AVX512BWCostTbl[] = { |
| 1540 | { ISD::SETCC, MVT::v32i16, 1 }, |
| 1541 | { ISD::SETCC, MVT::v64i8, 1 }, |
| 1542 | }; |
| 1543 | |
| 1544 | if (ST->hasBWI()) |
| 1545 | if (const auto *Entry = CostTableLookup(AVX512BWCostTbl, ISD, MTy)) |
| 1546 | return LT.first * Entry->Cost; |
| 1547 | |
| Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 1548 | if (ST->hasAVX512()) |
| 1549 | if (const auto *Entry = CostTableLookup(AVX512CostTbl, ISD, MTy)) |
| 1550 | return LT.first * Entry->Cost; |
| Elena Demikhovsky | 2701247 | 2014-09-16 07:57:37 +0000 | [diff] [blame] | 1551 | |
| Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 1552 | if (ST->hasAVX2()) |
| 1553 | if (const auto *Entry = CostTableLookup(AVX2CostTbl, ISD, MTy)) |
| 1554 | return LT.first * Entry->Cost; |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1555 | |
| Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 1556 | if (ST->hasAVX()) |
| 1557 | if (const auto *Entry = CostTableLookup(AVX1CostTbl, ISD, MTy)) |
| 1558 | return LT.first * Entry->Cost; |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1559 | |
| Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 1560 | if (ST->hasSSE42()) |
| 1561 | if (const auto *Entry = CostTableLookup(SSE42CostTbl, ISD, MTy)) |
| 1562 | return LT.first * Entry->Cost; |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1563 | |
| Simon Pilgrim | eec3a95 | 2016-05-09 21:14:38 +0000 | [diff] [blame] | 1564 | if (ST->hasSSE2()) |
| 1565 | if (const auto *Entry = CostTableLookup(SSE2CostTbl, ISD, MTy)) |
| 1566 | return LT.first * Entry->Cost; |
| 1567 | |
| Jonas Paulsson | fccc7d6 | 2017-04-12 11:49:08 +0000 | [diff] [blame] | 1568 | return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, I); |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1569 | } |
| 1570 | |
| Anna Thomas | b2a212c | 2017-06-06 16:45:25 +0000 | [diff] [blame] | 1571 | unsigned X86TTIImpl::getAtomicMemIntrinsicMaxElementSize() const { return 16; } |
| 1572 | |
| Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 1573 | int X86TTIImpl::getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, |
| Jonas Paulsson | a48ea23 | 2017-03-14 06:35:36 +0000 | [diff] [blame] | 1574 | ArrayRef<Type *> Tys, FastMathFlags FMF, |
| 1575 | unsigned ScalarizationCostPassed) { |
| Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1576 | // Costs should match the codegen from: |
| 1577 | // BITREVERSE: llvm\test\CodeGen\X86\vector-bitreverse.ll |
| 1578 | // BSWAP: llvm\test\CodeGen\X86\bswap-vector.ll |
| Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1579 | // CTLZ: llvm\test\CodeGen\X86\vector-lzcnt-*.ll |
| Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1580 | // CTPOP: llvm\test\CodeGen\X86\vector-popcnt-*.ll |
| Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1581 | // CTTZ: llvm\test\CodeGen\X86\vector-tzcnt-*.ll |
| Simon Pilgrim | 23ef267 | 2017-05-17 21:02:18 +0000 | [diff] [blame] | 1582 | static const CostTblEntry AVX512CDCostTbl[] = { |
| 1583 | { ISD::CTLZ, MVT::v8i64, 1 }, |
| 1584 | { ISD::CTLZ, MVT::v16i32, 1 }, |
| 1585 | { ISD::CTLZ, MVT::v32i16, 8 }, |
| 1586 | { ISD::CTLZ, MVT::v64i8, 20 }, |
| 1587 | { ISD::CTLZ, MVT::v4i64, 1 }, |
| 1588 | { ISD::CTLZ, MVT::v8i32, 1 }, |
| 1589 | { ISD::CTLZ, MVT::v16i16, 4 }, |
| 1590 | { ISD::CTLZ, MVT::v32i8, 10 }, |
| 1591 | { ISD::CTLZ, MVT::v2i64, 1 }, |
| 1592 | { ISD::CTLZ, MVT::v4i32, 1 }, |
| 1593 | { ISD::CTLZ, MVT::v8i16, 4 }, |
| 1594 | { ISD::CTLZ, MVT::v16i8, 4 }, |
| 1595 | }; |
| Simon Pilgrim | a9a92a1 | 2017-05-17 19:20:20 +0000 | [diff] [blame] | 1596 | static const CostTblEntry AVX512BWCostTbl[] = { |
| 1597 | { ISD::BITREVERSE, MVT::v8i64, 5 }, |
| 1598 | { ISD::BITREVERSE, MVT::v16i32, 5 }, |
| 1599 | { ISD::BITREVERSE, MVT::v32i16, 5 }, |
| 1600 | { ISD::BITREVERSE, MVT::v64i8, 5 }, |
| Simon Pilgrim | 23ef267 | 2017-05-17 21:02:18 +0000 | [diff] [blame] | 1601 | { ISD::CTLZ, MVT::v8i64, 23 }, |
| 1602 | { ISD::CTLZ, MVT::v16i32, 22 }, |
| 1603 | { ISD::CTLZ, MVT::v32i16, 18 }, |
| 1604 | { ISD::CTLZ, MVT::v64i8, 17 }, |
| Simon Pilgrim | 6bba606 | 2017-05-18 10:42:34 +0000 | [diff] [blame] | 1605 | { ISD::CTPOP, MVT::v8i64, 7 }, |
| 1606 | { ISD::CTPOP, MVT::v16i32, 11 }, |
| 1607 | { ISD::CTPOP, MVT::v32i16, 9 }, |
| 1608 | { ISD::CTPOP, MVT::v64i8, 6 }, |
| Simon Pilgrim | d036596 | 2017-05-17 20:22:54 +0000 | [diff] [blame] | 1609 | { ISD::CTTZ, MVT::v8i64, 10 }, |
| 1610 | { ISD::CTTZ, MVT::v16i32, 14 }, |
| 1611 | { ISD::CTTZ, MVT::v32i16, 12 }, |
| 1612 | { ISD::CTTZ, MVT::v64i8, 9 }, |
| Simon Pilgrim | a9a92a1 | 2017-05-17 19:20:20 +0000 | [diff] [blame] | 1613 | }; |
| 1614 | static const CostTblEntry AVX512CostTbl[] = { |
| 1615 | { ISD::BITREVERSE, MVT::v8i64, 36 }, |
| 1616 | { ISD::BITREVERSE, MVT::v16i32, 24 }, |
| Simon Pilgrim | 23ef267 | 2017-05-17 21:02:18 +0000 | [diff] [blame] | 1617 | { ISD::CTLZ, MVT::v8i64, 29 }, |
| 1618 | { ISD::CTLZ, MVT::v16i32, 35 }, |
| Simon Pilgrim | 6bba606 | 2017-05-18 10:42:34 +0000 | [diff] [blame] | 1619 | { ISD::CTPOP, MVT::v8i64, 16 }, |
| 1620 | { ISD::CTPOP, MVT::v16i32, 24 }, |
| Simon Pilgrim | d036596 | 2017-05-17 20:22:54 +0000 | [diff] [blame] | 1621 | { ISD::CTTZ, MVT::v8i64, 20 }, |
| 1622 | { ISD::CTTZ, MVT::v16i32, 28 }, |
| Simon Pilgrim | a9a92a1 | 2017-05-17 19:20:20 +0000 | [diff] [blame] | 1623 | }; |
| Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 1624 | static const CostTblEntry XOPCostTbl[] = { |
| 1625 | { ISD::BITREVERSE, MVT::v4i64, 4 }, |
| 1626 | { ISD::BITREVERSE, MVT::v8i32, 4 }, |
| 1627 | { ISD::BITREVERSE, MVT::v16i16, 4 }, |
| 1628 | { ISD::BITREVERSE, MVT::v32i8, 4 }, |
| 1629 | { ISD::BITREVERSE, MVT::v2i64, 1 }, |
| 1630 | { ISD::BITREVERSE, MVT::v4i32, 1 }, |
| 1631 | { ISD::BITREVERSE, MVT::v8i16, 1 }, |
| 1632 | { ISD::BITREVERSE, MVT::v16i8, 1 }, |
| 1633 | { ISD::BITREVERSE, MVT::i64, 3 }, |
| 1634 | { ISD::BITREVERSE, MVT::i32, 3 }, |
| 1635 | { ISD::BITREVERSE, MVT::i16, 3 }, |
| 1636 | { ISD::BITREVERSE, MVT::i8, 3 } |
| 1637 | }; |
| Simon Pilgrim | 3fc09f7 | 2016-06-11 19:23:02 +0000 | [diff] [blame] | 1638 | static const CostTblEntry AVX2CostTbl[] = { |
| 1639 | { ISD::BITREVERSE, MVT::v4i64, 5 }, |
| 1640 | { ISD::BITREVERSE, MVT::v8i32, 5 }, |
| 1641 | { ISD::BITREVERSE, MVT::v16i16, 5 }, |
| Simon Pilgrim | 356e823 | 2016-06-20 23:08:21 +0000 | [diff] [blame] | 1642 | { ISD::BITREVERSE, MVT::v32i8, 5 }, |
| 1643 | { ISD::BSWAP, MVT::v4i64, 1 }, |
| 1644 | { ISD::BSWAP, MVT::v8i32, 1 }, |
| Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1645 | { ISD::BSWAP, MVT::v16i16, 1 }, |
| Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1646 | { ISD::CTLZ, MVT::v4i64, 23 }, |
| 1647 | { ISD::CTLZ, MVT::v8i32, 18 }, |
| 1648 | { ISD::CTLZ, MVT::v16i16, 14 }, |
| 1649 | { ISD::CTLZ, MVT::v32i8, 9 }, |
| Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1650 | { ISD::CTPOP, MVT::v4i64, 7 }, |
| 1651 | { ISD::CTPOP, MVT::v8i32, 11 }, |
| 1652 | { ISD::CTPOP, MVT::v16i16, 9 }, |
| Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1653 | { ISD::CTPOP, MVT::v32i8, 6 }, |
| 1654 | { ISD::CTTZ, MVT::v4i64, 10 }, |
| 1655 | { ISD::CTTZ, MVT::v8i32, 14 }, |
| 1656 | { ISD::CTTZ, MVT::v16i16, 12 }, |
| Alexey Bataev | d07c731 | 2016-10-31 12:10:53 +0000 | [diff] [blame] | 1657 | { ISD::CTTZ, MVT::v32i8, 9 }, |
| 1658 | { ISD::FSQRT, MVT::f32, 7 }, // Haswell from http://www.agner.org/ |
| 1659 | { ISD::FSQRT, MVT::v4f32, 7 }, // Haswell from http://www.agner.org/ |
| 1660 | { ISD::FSQRT, MVT::v8f32, 14 }, // Haswell from http://www.agner.org/ |
| 1661 | { ISD::FSQRT, MVT::f64, 14 }, // Haswell from http://www.agner.org/ |
| 1662 | { ISD::FSQRT, MVT::v2f64, 14 }, // Haswell from http://www.agner.org/ |
| 1663 | { ISD::FSQRT, MVT::v4f64, 28 }, // Haswell from http://www.agner.org/ |
| Simon Pilgrim | 3fc09f7 | 2016-06-11 19:23:02 +0000 | [diff] [blame] | 1664 | }; |
| 1665 | static const CostTblEntry AVX1CostTbl[] = { |
| Simon Pilgrim | 2d1c6d6 | 2017-05-07 20:58:55 +0000 | [diff] [blame] | 1666 | { ISD::BITREVERSE, MVT::v4i64, 12 }, // 2 x 128-bit Op + extract/insert |
| 1667 | { ISD::BITREVERSE, MVT::v8i32, 12 }, // 2 x 128-bit Op + extract/insert |
| 1668 | { ISD::BITREVERSE, MVT::v16i16, 12 }, // 2 x 128-bit Op + extract/insert |
| 1669 | { ISD::BITREVERSE, MVT::v32i8, 12 }, // 2 x 128-bit Op + extract/insert |
| Simon Pilgrim | 356e823 | 2016-06-20 23:08:21 +0000 | [diff] [blame] | 1670 | { ISD::BSWAP, MVT::v4i64, 4 }, |
| 1671 | { ISD::BSWAP, MVT::v8i32, 4 }, |
| Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1672 | { ISD::BSWAP, MVT::v16i16, 4 }, |
| Simon Pilgrim | 2d1c6d6 | 2017-05-07 20:58:55 +0000 | [diff] [blame] | 1673 | { ISD::CTLZ, MVT::v4i64, 48 }, // 2 x 128-bit Op + extract/insert |
| 1674 | { ISD::CTLZ, MVT::v8i32, 38 }, // 2 x 128-bit Op + extract/insert |
| 1675 | { ISD::CTLZ, MVT::v16i16, 30 }, // 2 x 128-bit Op + extract/insert |
| 1676 | { ISD::CTLZ, MVT::v32i8, 20 }, // 2 x 128-bit Op + extract/insert |
| 1677 | { ISD::CTPOP, MVT::v4i64, 16 }, // 2 x 128-bit Op + extract/insert |
| 1678 | { ISD::CTPOP, MVT::v8i32, 24 }, // 2 x 128-bit Op + extract/insert |
| 1679 | { ISD::CTPOP, MVT::v16i16, 20 }, // 2 x 128-bit Op + extract/insert |
| 1680 | { ISD::CTPOP, MVT::v32i8, 14 }, // 2 x 128-bit Op + extract/insert |
| 1681 | { ISD::CTTZ, MVT::v4i64, 22 }, // 2 x 128-bit Op + extract/insert |
| 1682 | { ISD::CTTZ, MVT::v8i32, 30 }, // 2 x 128-bit Op + extract/insert |
| 1683 | { ISD::CTTZ, MVT::v16i16, 26 }, // 2 x 128-bit Op + extract/insert |
| 1684 | { ISD::CTTZ, MVT::v32i8, 20 }, // 2 x 128-bit Op + extract/insert |
| Alexey Bataev | d07c731 | 2016-10-31 12:10:53 +0000 | [diff] [blame] | 1685 | { ISD::FSQRT, MVT::f32, 14 }, // SNB from http://www.agner.org/ |
| 1686 | { ISD::FSQRT, MVT::v4f32, 14 }, // SNB from http://www.agner.org/ |
| 1687 | { ISD::FSQRT, MVT::v8f32, 28 }, // SNB from http://www.agner.org/ |
| 1688 | { ISD::FSQRT, MVT::f64, 21 }, // SNB from http://www.agner.org/ |
| 1689 | { ISD::FSQRT, MVT::v2f64, 21 }, // SNB from http://www.agner.org/ |
| 1690 | { ISD::FSQRT, MVT::v4f64, 43 }, // SNB from http://www.agner.org/ |
| 1691 | }; |
| Craig Topper | a985919 | 2018-03-25 15:58:12 +0000 | [diff] [blame] | 1692 | static const CostTblEntry GLMCostTbl[] = { |
| 1693 | { ISD::FSQRT, MVT::f32, 19 }, // sqrtss |
| 1694 | { ISD::FSQRT, MVT::v4f32, 37 }, // sqrtps |
| 1695 | { ISD::FSQRT, MVT::f64, 34 }, // sqrtsd |
| 1696 | { ISD::FSQRT, MVT::v2f64, 67 }, // sqrtpd |
| 1697 | }; |
| 1698 | static const CostTblEntry SLMCostTbl[] = { |
| 1699 | { ISD::FSQRT, MVT::f32, 20 }, // sqrtss |
| 1700 | { ISD::FSQRT, MVT::v4f32, 40 }, // sqrtps |
| 1701 | { ISD::FSQRT, MVT::f64, 35 }, // sqrtsd |
| 1702 | { ISD::FSQRT, MVT::v2f64, 70 }, // sqrtpd |
| 1703 | }; |
| Alexey Bataev | d07c731 | 2016-10-31 12:10:53 +0000 | [diff] [blame] | 1704 | static const CostTblEntry SSE42CostTbl[] = { |
| Simon Pilgrim | a0b0b74 | 2017-03-15 11:57:42 +0000 | [diff] [blame] | 1705 | { ISD::FSQRT, MVT::f32, 18 }, // Nehalem from http://www.agner.org/ |
| 1706 | { ISD::FSQRT, MVT::v4f32, 18 }, // Nehalem from http://www.agner.org/ |
| Simon Pilgrim | 3fc09f7 | 2016-06-11 19:23:02 +0000 | [diff] [blame] | 1707 | }; |
| 1708 | static const CostTblEntry SSSE3CostTbl[] = { |
| 1709 | { ISD::BITREVERSE, MVT::v2i64, 5 }, |
| 1710 | { ISD::BITREVERSE, MVT::v4i32, 5 }, |
| 1711 | { ISD::BITREVERSE, MVT::v8i16, 5 }, |
| Simon Pilgrim | 356e823 | 2016-06-20 23:08:21 +0000 | [diff] [blame] | 1712 | { ISD::BITREVERSE, MVT::v16i8, 5 }, |
| 1713 | { ISD::BSWAP, MVT::v2i64, 1 }, |
| 1714 | { ISD::BSWAP, MVT::v4i32, 1 }, |
| Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1715 | { ISD::BSWAP, MVT::v8i16, 1 }, |
| Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1716 | { ISD::CTLZ, MVT::v2i64, 23 }, |
| 1717 | { ISD::CTLZ, MVT::v4i32, 18 }, |
| 1718 | { ISD::CTLZ, MVT::v8i16, 14 }, |
| 1719 | { ISD::CTLZ, MVT::v16i8, 9 }, |
| Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1720 | { ISD::CTPOP, MVT::v2i64, 7 }, |
| 1721 | { ISD::CTPOP, MVT::v4i32, 11 }, |
| 1722 | { ISD::CTPOP, MVT::v8i16, 9 }, |
| Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1723 | { ISD::CTPOP, MVT::v16i8, 6 }, |
| 1724 | { ISD::CTTZ, MVT::v2i64, 10 }, |
| 1725 | { ISD::CTTZ, MVT::v4i32, 14 }, |
| 1726 | { ISD::CTTZ, MVT::v8i16, 12 }, |
| 1727 | { ISD::CTTZ, MVT::v16i8, 9 } |
| Simon Pilgrim | 356e823 | 2016-06-20 23:08:21 +0000 | [diff] [blame] | 1728 | }; |
| 1729 | static const CostTblEntry SSE2CostTbl[] = { |
| Simon Pilgrim | 06c70ad | 2017-03-15 19:34:55 +0000 | [diff] [blame] | 1730 | { ISD::BITREVERSE, MVT::v2i64, 29 }, |
| 1731 | { ISD::BITREVERSE, MVT::v4i32, 27 }, |
| 1732 | { ISD::BITREVERSE, MVT::v8i16, 27 }, |
| 1733 | { ISD::BITREVERSE, MVT::v16i8, 20 }, |
| Simon Pilgrim | 356e823 | 2016-06-20 23:08:21 +0000 | [diff] [blame] | 1734 | { ISD::BSWAP, MVT::v2i64, 7 }, |
| 1735 | { ISD::BSWAP, MVT::v4i32, 7 }, |
| Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1736 | { ISD::BSWAP, MVT::v8i16, 7 }, |
| Simon Pilgrim | d02c552 | 2016-11-08 14:10:28 +0000 | [diff] [blame] | 1737 | { ISD::CTLZ, MVT::v2i64, 25 }, |
| 1738 | { ISD::CTLZ, MVT::v4i32, 26 }, |
| 1739 | { ISD::CTLZ, MVT::v8i16, 20 }, |
| 1740 | { ISD::CTLZ, MVT::v16i8, 17 }, |
| Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1741 | { ISD::CTPOP, MVT::v2i64, 12 }, |
| 1742 | { ISD::CTPOP, MVT::v4i32, 15 }, |
| 1743 | { ISD::CTPOP, MVT::v8i16, 13 }, |
| Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1744 | { ISD::CTPOP, MVT::v16i8, 10 }, |
| 1745 | { ISD::CTTZ, MVT::v2i64, 14 }, |
| 1746 | { ISD::CTTZ, MVT::v4i32, 18 }, |
| 1747 | { ISD::CTTZ, MVT::v8i16, 16 }, |
| Alexey Bataev | d07c731 | 2016-10-31 12:10:53 +0000 | [diff] [blame] | 1748 | { ISD::CTTZ, MVT::v16i8, 13 }, |
| 1749 | { ISD::FSQRT, MVT::f64, 32 }, // Nehalem from http://www.agner.org/ |
| 1750 | { ISD::FSQRT, MVT::v2f64, 32 }, // Nehalem from http://www.agner.org/ |
| 1751 | }; |
| 1752 | static const CostTblEntry SSE1CostTbl[] = { |
| Simon Pilgrim | a0b0b74 | 2017-03-15 11:57:42 +0000 | [diff] [blame] | 1753 | { ISD::FSQRT, MVT::f32, 28 }, // Pentium III from http://www.agner.org/ |
| 1754 | { ISD::FSQRT, MVT::v4f32, 56 }, // Pentium III from http://www.agner.org/ |
| Simon Pilgrim | 3fc09f7 | 2016-06-11 19:23:02 +0000 | [diff] [blame] | 1755 | }; |
| Simon Pilgrim | 06c70ad | 2017-03-15 19:34:55 +0000 | [diff] [blame] | 1756 | static const CostTblEntry X64CostTbl[] = { // 64-bit targets |
| 1757 | { ISD::BITREVERSE, MVT::i64, 14 } |
| 1758 | }; |
| 1759 | static const CostTblEntry X86CostTbl[] = { // 32 or 64-bit targets |
| 1760 | { ISD::BITREVERSE, MVT::i32, 14 }, |
| 1761 | { ISD::BITREVERSE, MVT::i16, 14 }, |
| 1762 | { ISD::BITREVERSE, MVT::i8, 11 } |
| 1763 | }; |
| Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 1764 | |
| 1765 | unsigned ISD = ISD::DELETED_NODE; |
| 1766 | switch (IID) { |
| 1767 | default: |
| 1768 | break; |
| 1769 | case Intrinsic::bitreverse: |
| 1770 | ISD = ISD::BITREVERSE; |
| 1771 | break; |
| Simon Pilgrim | 356e823 | 2016-06-20 23:08:21 +0000 | [diff] [blame] | 1772 | case Intrinsic::bswap: |
| 1773 | ISD = ISD::BSWAP; |
| 1774 | break; |
| Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1775 | case Intrinsic::ctlz: |
| 1776 | ISD = ISD::CTLZ; |
| 1777 | break; |
| Simon Pilgrim | 1b4f511 | 2016-07-20 10:41:28 +0000 | [diff] [blame] | 1778 | case Intrinsic::ctpop: |
| 1779 | ISD = ISD::CTPOP; |
| 1780 | break; |
| Simon Pilgrim | 5d5ca9c | 2016-08-04 10:51:41 +0000 | [diff] [blame] | 1781 | case Intrinsic::cttz: |
| 1782 | ISD = ISD::CTTZ; |
| 1783 | break; |
| Alexey Bataev | d07c731 | 2016-10-31 12:10:53 +0000 | [diff] [blame] | 1784 | case Intrinsic::sqrt: |
| 1785 | ISD = ISD::FSQRT; |
| 1786 | break; |
| Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | // Legalize the type. |
| 1790 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, RetTy); |
| 1791 | MVT MTy = LT.second; |
| 1792 | |
| 1793 | // Attempt to lookup cost. |
| Craig Topper | a985919 | 2018-03-25 15:58:12 +0000 | [diff] [blame] | 1794 | if (ST->isGLM()) |
| 1795 | if (const auto *Entry = CostTableLookup(GLMCostTbl, ISD, MTy)) |
| 1796 | return LT.first * Entry->Cost; |
| 1797 | |
| 1798 | if (ST->isSLM()) |
| 1799 | if (const auto *Entry = CostTableLookup(SLMCostTbl, ISD, MTy)) |
| 1800 | return LT.first * Entry->Cost; |
| 1801 | |
| Simon Pilgrim | 23ef267 | 2017-05-17 21:02:18 +0000 | [diff] [blame] | 1802 | if (ST->hasCDI()) |
| 1803 | if (const auto *Entry = CostTableLookup(AVX512CDCostTbl, ISD, MTy)) |
| 1804 | return LT.first * Entry->Cost; |
| 1805 | |
| Simon Pilgrim | a9a92a1 | 2017-05-17 19:20:20 +0000 | [diff] [blame] | 1806 | if (ST->hasBWI()) |
| 1807 | if (const auto *Entry = CostTableLookup(AVX512BWCostTbl, ISD, MTy)) |
| 1808 | return LT.first * Entry->Cost; |
| 1809 | |
| 1810 | if (ST->hasAVX512()) |
| 1811 | if (const auto *Entry = CostTableLookup(AVX512CostTbl, ISD, MTy)) |
| 1812 | return LT.first * Entry->Cost; |
| 1813 | |
| Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 1814 | if (ST->hasXOP()) |
| 1815 | if (const auto *Entry = CostTableLookup(XOPCostTbl, ISD, MTy)) |
| 1816 | return LT.first * Entry->Cost; |
| 1817 | |
| Simon Pilgrim | 3fc09f7 | 2016-06-11 19:23:02 +0000 | [diff] [blame] | 1818 | if (ST->hasAVX2()) |
| 1819 | if (const auto *Entry = CostTableLookup(AVX2CostTbl, ISD, MTy)) |
| 1820 | return LT.first * Entry->Cost; |
| 1821 | |
| 1822 | if (ST->hasAVX()) |
| 1823 | if (const auto *Entry = CostTableLookup(AVX1CostTbl, ISD, MTy)) |
| 1824 | return LT.first * Entry->Cost; |
| 1825 | |
| Alexey Bataev | d07c731 | 2016-10-31 12:10:53 +0000 | [diff] [blame] | 1826 | if (ST->hasSSE42()) |
| 1827 | if (const auto *Entry = CostTableLookup(SSE42CostTbl, ISD, MTy)) |
| 1828 | return LT.first * Entry->Cost; |
| 1829 | |
| Simon Pilgrim | 3fc09f7 | 2016-06-11 19:23:02 +0000 | [diff] [blame] | 1830 | if (ST->hasSSSE3()) |
| 1831 | if (const auto *Entry = CostTableLookup(SSSE3CostTbl, ISD, MTy)) |
| 1832 | return LT.first * Entry->Cost; |
| 1833 | |
| Simon Pilgrim | 356e823 | 2016-06-20 23:08:21 +0000 | [diff] [blame] | 1834 | if (ST->hasSSE2()) |
| 1835 | if (const auto *Entry = CostTableLookup(SSE2CostTbl, ISD, MTy)) |
| 1836 | return LT.first * Entry->Cost; |
| 1837 | |
| Alexey Bataev | d07c731 | 2016-10-31 12:10:53 +0000 | [diff] [blame] | 1838 | if (ST->hasSSE1()) |
| 1839 | if (const auto *Entry = CostTableLookup(SSE1CostTbl, ISD, MTy)) |
| 1840 | return LT.first * Entry->Cost; |
| 1841 | |
| Simon Pilgrim | 06c70ad | 2017-03-15 19:34:55 +0000 | [diff] [blame] | 1842 | if (ST->is64Bit()) |
| 1843 | if (const auto *Entry = CostTableLookup(X64CostTbl, ISD, MTy)) |
| 1844 | return LT.first * Entry->Cost; |
| 1845 | |
| 1846 | if (const auto *Entry = CostTableLookup(X86CostTbl, ISD, MTy)) |
| 1847 | return LT.first * Entry->Cost; |
| 1848 | |
| Jonas Paulsson | a48ea23 | 2017-03-14 06:35:36 +0000 | [diff] [blame] | 1849 | return BaseT::getIntrinsicInstrCost(IID, RetTy, Tys, FMF, ScalarizationCostPassed); |
| Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | int X86TTIImpl::getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, |
| Jonas Paulsson | a48ea23 | 2017-03-14 06:35:36 +0000 | [diff] [blame] | 1853 | ArrayRef<Value *> Args, FastMathFlags FMF, unsigned VF) { |
| 1854 | return BaseT::getIntrinsicInstrCost(IID, RetTy, Args, FMF, VF); |
| Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 1855 | } |
| 1856 | |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1857 | int X86TTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) { |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1858 | assert(Val->isVectorTy() && "This must be a vector type"); |
| 1859 | |
| Sanjay Patel | aedc347 | 2016-05-25 17:27:54 +0000 | [diff] [blame] | 1860 | Type *ScalarType = Val->getScalarType(); |
| 1861 | |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1862 | if (Index != -1U) { |
| 1863 | // Legalize the type. |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1864 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Val); |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1865 | |
| 1866 | // This type is legalized to a scalar type. |
| 1867 | if (!LT.second.isVector()) |
| 1868 | return 0; |
| 1869 | |
| 1870 | // The type may be split. Normalize the index to the new type. |
| 1871 | unsigned Width = LT.second.getVectorNumElements(); |
| 1872 | Index = Index % Width; |
| 1873 | |
| 1874 | // Floating point scalars are already located in index #0. |
| Sanjay Patel | aedc347 | 2016-05-25 17:27:54 +0000 | [diff] [blame] | 1875 | if (ScalarType->isFloatingPointTy() && Index == 0) |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1876 | return 0; |
| 1877 | } |
| 1878 | |
| Sanjay Patel | aedc347 | 2016-05-25 17:27:54 +0000 | [diff] [blame] | 1879 | // Add to the base cost if we know that the extracted element of a vector is |
| 1880 | // destined to be moved to and used in the integer register file. |
| 1881 | int RegisterFileMoveCost = 0; |
| 1882 | if (Opcode == Instruction::ExtractElement && ScalarType->isPointerTy()) |
| 1883 | RegisterFileMoveCost = 1; |
| 1884 | |
| 1885 | return BaseT::getVectorInstrCost(Opcode, Val, Index) + RegisterFileMoveCost; |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1888 | int X86TTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, |
| Jonas Paulsson | fccc7d6 | 2017-04-12 11:49:08 +0000 | [diff] [blame] | 1889 | unsigned AddressSpace, const Instruction *I) { |
| Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 1890 | // Handle non-power-of-two vectors such as <3 x float> |
| Nadav Rotem | f9ecbcb | 2013-06-27 17:52:04 +0000 | [diff] [blame] | 1891 | if (VectorType *VTy = dyn_cast<VectorType>(Src)) { |
| 1892 | unsigned NumElem = VTy->getVectorNumElements(); |
| 1893 | |
| 1894 | // Handle a few common cases: |
| 1895 | // <3 x float> |
| 1896 | if (NumElem == 3 && VTy->getScalarSizeInBits() == 32) |
| 1897 | // Cost = 64 bit store + extract + 32 bit store. |
| 1898 | return 3; |
| 1899 | |
| 1900 | // <3 x double> |
| 1901 | if (NumElem == 3 && VTy->getScalarSizeInBits() == 64) |
| 1902 | // Cost = 128 bit store + unpack + 64 bit store. |
| 1903 | return 3; |
| 1904 | |
| Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 1905 | // Assume that all other non-power-of-two numbers are scalarized. |
| Nadav Rotem | f9ecbcb | 2013-06-27 17:52:04 +0000 | [diff] [blame] | 1906 | if (!isPowerOf2_32(NumElem)) { |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1907 | int Cost = BaseT::getMemoryOpCost(Opcode, VTy->getScalarType(), Alignment, |
| 1908 | AddressSpace); |
| 1909 | int SplitCost = getScalarizationOverhead(Src, Opcode == Instruction::Load, |
| 1910 | Opcode == Instruction::Store); |
| Nadav Rotem | f9ecbcb | 2013-06-27 17:52:04 +0000 | [diff] [blame] | 1911 | return NumElem * Cost + SplitCost; |
| 1912 | } |
| 1913 | } |
| 1914 | |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1915 | // Legalize the type. |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1916 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Src); |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1917 | assert((Opcode == Instruction::Load || Opcode == Instruction::Store) && |
| 1918 | "Invalid Opcode"); |
| 1919 | |
| 1920 | // Each load/store unit costs 1. |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1921 | int Cost = LT.first * 1; |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1922 | |
| Sanjay Patel | 9f6c4d5 | 2016-03-09 22:23:33 +0000 | [diff] [blame] | 1923 | // This isn't exactly right. We're using slow unaligned 32-byte accesses as a |
| 1924 | // proxy for a double-pumped AVX memory interface such as on Sandybridge. |
| 1925 | if (LT.second.getStoreSize() == 32 && ST->isUnalignedMem32Slow()) |
| 1926 | Cost *= 2; |
| Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 1927 | |
| 1928 | return Cost; |
| 1929 | } |
| Arnold Schwaighofer | 6042a26 | 2013-07-12 19:16:07 +0000 | [diff] [blame] | 1930 | |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1931 | int X86TTIImpl::getMaskedMemoryOpCost(unsigned Opcode, Type *SrcTy, |
| 1932 | unsigned Alignment, |
| 1933 | unsigned AddressSpace) { |
| Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 1934 | VectorType *SrcVTy = dyn_cast<VectorType>(SrcTy); |
| 1935 | if (!SrcVTy) |
| 1936 | // To calculate scalar take the regular cost, without mask |
| 1937 | return getMemoryOpCost(Opcode, SrcTy, Alignment, AddressSpace); |
| 1938 | |
| 1939 | unsigned NumElem = SrcVTy->getVectorNumElements(); |
| 1940 | VectorType *MaskTy = |
| Mehdi Amini | 867e914 | 2016-04-14 04:36:40 +0000 | [diff] [blame] | 1941 | VectorType::get(Type::getInt8Ty(SrcVTy->getContext()), NumElem); |
| Elena Demikhovsky | 20662e3 | 2015-10-19 07:43:38 +0000 | [diff] [blame] | 1942 | if ((Opcode == Instruction::Load && !isLegalMaskedLoad(SrcVTy)) || |
| 1943 | (Opcode == Instruction::Store && !isLegalMaskedStore(SrcVTy)) || |
| Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 1944 | !isPowerOf2_32(NumElem)) { |
| 1945 | // Scalarization |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1946 | int MaskSplitCost = getScalarizationOverhead(MaskTy, false, true); |
| 1947 | int ScalarCompareCost = getCmpSelInstrCost( |
| Mehdi Amini | 867e914 | 2016-04-14 04:36:40 +0000 | [diff] [blame] | 1948 | Instruction::ICmp, Type::getInt8Ty(SrcVTy->getContext()), nullptr); |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1949 | int BranchCost = getCFInstrCost(Instruction::Br); |
| 1950 | int MaskCmpCost = NumElem * (BranchCost + ScalarCompareCost); |
| Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 1951 | |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1952 | int ValueSplitCost = getScalarizationOverhead( |
| 1953 | SrcVTy, Opcode == Instruction::Load, Opcode == Instruction::Store); |
| 1954 | int MemopCost = |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1955 | NumElem * BaseT::getMemoryOpCost(Opcode, SrcVTy->getScalarType(), |
| 1956 | Alignment, AddressSpace); |
| Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 1957 | return MemopCost + ValueSplitCost + MaskSplitCost + MaskCmpCost; |
| 1958 | } |
| 1959 | |
| 1960 | // Legalize the type. |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1961 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, SrcVTy); |
| Cong Hou | da4e8ae | 2015-10-28 18:15:46 +0000 | [diff] [blame] | 1962 | auto VT = TLI->getValueType(DL, SrcVTy); |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 1963 | int Cost = 0; |
| Cong Hou | da4e8ae | 2015-10-28 18:15:46 +0000 | [diff] [blame] | 1964 | if (VT.isSimple() && LT.second != VT.getSimpleVT() && |
| Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 1965 | LT.second.getVectorNumElements() == NumElem) |
| 1966 | // Promotion requires expand/truncate for data and a shuffle for mask. |
| Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 1967 | Cost += getShuffleCost(TTI::SK_Alternate, SrcVTy, 0, nullptr) + |
| 1968 | getShuffleCost(TTI::SK_Alternate, MaskTy, 0, nullptr); |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1969 | |
| Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 1970 | else if (LT.second.getVectorNumElements() > NumElem) { |
| 1971 | VectorType *NewMaskTy = VectorType::get(MaskTy->getVectorElementType(), |
| 1972 | LT.second.getVectorNumElements()); |
| 1973 | // Expanding requires fill mask with zeroes |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1974 | Cost += getShuffleCost(TTI::SK_InsertSubvector, NewMaskTy, 0, MaskTy); |
| Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 1975 | } |
| 1976 | if (!ST->hasAVX512()) |
| 1977 | return Cost + LT.first*4; // Each maskmov costs 4 |
| 1978 | |
| 1979 | // AVX-512 masked load/store is cheapper |
| 1980 | return Cost+LT.first; |
| 1981 | } |
| 1982 | |
| Mohammed Agabaria | 23599ba | 2017-01-05 14:03:41 +0000 | [diff] [blame] | 1983 | int X86TTIImpl::getAddressComputationCost(Type *Ty, ScalarEvolution *SE, |
| 1984 | const SCEV *Ptr) { |
| Arnold Schwaighofer | 6042a26 | 2013-07-12 19:16:07 +0000 | [diff] [blame] | 1985 | // Address computations in vectorized code with non-consecutive addresses will |
| 1986 | // likely result in more instructions compared to scalar code where the |
| 1987 | // computation can more often be merged into the index mode. The resulting |
| 1988 | // extra micro-ops can significantly decrease throughput. |
| 1989 | unsigned NumVectorInstToHideOverhead = 10; |
| 1990 | |
| Mohammed Agabaria | 23599ba | 2017-01-05 14:03:41 +0000 | [diff] [blame] | 1991 | // Cost modeling of Strided Access Computation is hidden by the indexing |
| 1992 | // modes of X86 regardless of the stride value. We dont believe that there |
| 1993 | // is a difference between constant strided access in gerenal and constant |
| 1994 | // strided value which is less than or equal to 64. |
| 1995 | // Even in the case of (loop invariant) stride whose value is not known at |
| 1996 | // compile time, the address computation will not incur more than one extra |
| 1997 | // ADD instruction. |
| 1998 | if (Ty->isVectorTy() && SE) { |
| 1999 | if (!BaseT::isStridedAccess(Ptr)) |
| 2000 | return NumVectorInstToHideOverhead; |
| 2001 | if (!BaseT::getConstantStrideStep(SE, Ptr)) |
| 2002 | return 1; |
| 2003 | } |
| Arnold Schwaighofer | 6042a26 | 2013-07-12 19:16:07 +0000 | [diff] [blame] | 2004 | |
| Mohammed Agabaria | 23599ba | 2017-01-05 14:03:41 +0000 | [diff] [blame] | 2005 | return BaseT::getAddressComputationCost(Ty, SE, Ptr); |
| Arnold Schwaighofer | 6042a26 | 2013-07-12 19:16:07 +0000 | [diff] [blame] | 2006 | } |
| Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 2007 | |
| Alexey Bataev | 3e9b3eb | 2017-07-31 14:19:32 +0000 | [diff] [blame] | 2008 | int X86TTIImpl::getArithmeticReductionCost(unsigned Opcode, Type *ValTy, |
| 2009 | bool IsPairwise) { |
| Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 2010 | |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 2011 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, ValTy); |
| Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 2012 | |
| Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 2013 | MVT MTy = LT.second; |
| Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 2014 | |
| Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 2015 | int ISD = TLI->InstructionOpcodeToISD(Opcode); |
| 2016 | assert(ISD && "Invalid opcode"); |
| Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 2017 | |
| 2018 | // We use the Intel Architecture Code Analyzer(IACA) to measure the throughput |
| 2019 | // and make it as the cost. |
| 2020 | |
| Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 2021 | static const CostTblEntry SSE42CostTblPairWise[] = { |
| Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 2022 | { ISD::FADD, MVT::v2f64, 2 }, |
| 2023 | { ISD::FADD, MVT::v4f32, 4 }, |
| 2024 | { ISD::ADD, MVT::v2i64, 2 }, // The data reported by the IACA tool is "1.6". |
| 2025 | { ISD::ADD, MVT::v4i32, 3 }, // The data reported by the IACA tool is "3.5". |
| 2026 | { ISD::ADD, MVT::v8i16, 5 }, |
| 2027 | }; |
| Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 2028 | |
| Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 2029 | static const CostTblEntry AVX1CostTblPairWise[] = { |
| Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 2030 | { ISD::FADD, MVT::v4f32, 4 }, |
| 2031 | { ISD::FADD, MVT::v4f64, 5 }, |
| 2032 | { ISD::FADD, MVT::v8f32, 7 }, |
| 2033 | { ISD::ADD, MVT::v2i64, 1 }, // The data reported by the IACA tool is "1.5". |
| 2034 | { ISD::ADD, MVT::v4i32, 3 }, // The data reported by the IACA tool is "3.5". |
| 2035 | { ISD::ADD, MVT::v4i64, 5 }, // The data reported by the IACA tool is "4.8". |
| 2036 | { ISD::ADD, MVT::v8i16, 5 }, |
| 2037 | { ISD::ADD, MVT::v8i32, 5 }, |
| 2038 | }; |
| 2039 | |
| Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 2040 | static const CostTblEntry SSE42CostTblNoPairWise[] = { |
| Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 2041 | { ISD::FADD, MVT::v2f64, 2 }, |
| 2042 | { ISD::FADD, MVT::v4f32, 4 }, |
| 2043 | { ISD::ADD, MVT::v2i64, 2 }, // The data reported by the IACA tool is "1.6". |
| 2044 | { ISD::ADD, MVT::v4i32, 3 }, // The data reported by the IACA tool is "3.3". |
| 2045 | { ISD::ADD, MVT::v8i16, 4 }, // The data reported by the IACA tool is "4.3". |
| 2046 | }; |
| Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 2047 | |
| Craig Topper | 4b27576 | 2015-10-28 04:02:12 +0000 | [diff] [blame] | 2048 | static const CostTblEntry AVX1CostTblNoPairWise[] = { |
| Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 2049 | { ISD::FADD, MVT::v4f32, 3 }, |
| 2050 | { ISD::FADD, MVT::v4f64, 3 }, |
| 2051 | { ISD::FADD, MVT::v8f32, 4 }, |
| 2052 | { ISD::ADD, MVT::v2i64, 1 }, // The data reported by the IACA tool is "1.5". |
| 2053 | { ISD::ADD, MVT::v4i32, 3 }, // The data reported by the IACA tool is "2.8". |
| 2054 | { ISD::ADD, MVT::v4i64, 3 }, |
| 2055 | { ISD::ADD, MVT::v8i16, 4 }, |
| 2056 | { ISD::ADD, MVT::v8i32, 5 }, |
| 2057 | }; |
| Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 2058 | |
| Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 2059 | if (IsPairwise) { |
| Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 2060 | if (ST->hasAVX()) |
| 2061 | if (const auto *Entry = CostTableLookup(AVX1CostTblPairWise, ISD, MTy)) |
| 2062 | return LT.first * Entry->Cost; |
| Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 2063 | |
| Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 2064 | if (ST->hasSSE42()) |
| 2065 | if (const auto *Entry = CostTableLookup(SSE42CostTblPairWise, ISD, MTy)) |
| 2066 | return LT.first * Entry->Cost; |
| Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 2067 | } else { |
| Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 2068 | if (ST->hasAVX()) |
| 2069 | if (const auto *Entry = CostTableLookup(AVX1CostTblNoPairWise, ISD, MTy)) |
| 2070 | return LT.first * Entry->Cost; |
| Michael Liao | 5bf9578 | 2014-12-04 05:20:33 +0000 | [diff] [blame] | 2071 | |
| Craig Topper | ee0c859 | 2015-10-27 04:14:24 +0000 | [diff] [blame] | 2072 | if (ST->hasSSE42()) |
| 2073 | if (const auto *Entry = CostTableLookup(SSE42CostTblNoPairWise, ISD, MTy)) |
| 2074 | return LT.first * Entry->Cost; |
| Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 2075 | } |
| 2076 | |
| Alexey Bataev | 3e9b3eb | 2017-07-31 14:19:32 +0000 | [diff] [blame] | 2077 | return BaseT::getArithmeticReductionCost(Opcode, ValTy, IsPairwise); |
| Yi Jiang | 5c343de | 2013-09-19 17:48:48 +0000 | [diff] [blame] | 2078 | } |
| 2079 | |
| Alexey Bataev | 6dd29fc | 2017-09-08 13:49:36 +0000 | [diff] [blame] | 2080 | int X86TTIImpl::getMinMaxReductionCost(Type *ValTy, Type *CondTy, |
| 2081 | bool IsPairwise, bool IsUnsigned) { |
| 2082 | std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, ValTy); |
| 2083 | |
| 2084 | MVT MTy = LT.second; |
| 2085 | |
| 2086 | int ISD; |
| 2087 | if (ValTy->isIntOrIntVectorTy()) { |
| 2088 | ISD = IsUnsigned ? ISD::UMIN : ISD::SMIN; |
| 2089 | } else { |
| 2090 | assert(ValTy->isFPOrFPVectorTy() && |
| 2091 | "Expected float point or integer vector type."); |
| 2092 | ISD = ISD::FMINNUM; |
| 2093 | } |
| 2094 | |
| 2095 | // We use the Intel Architecture Code Analyzer(IACA) to measure the throughput |
| 2096 | // and make it as the cost. |
| 2097 | |
| 2098 | static const CostTblEntry SSE42CostTblPairWise[] = { |
| 2099 | {ISD::FMINNUM, MVT::v2f64, 3}, |
| 2100 | {ISD::FMINNUM, MVT::v4f32, 2}, |
| 2101 | {ISD::SMIN, MVT::v2i64, 7}, // The data reported by the IACA is "6.8" |
| 2102 | {ISD::UMIN, MVT::v2i64, 8}, // The data reported by the IACA is "8.6" |
| 2103 | {ISD::SMIN, MVT::v4i32, 1}, // The data reported by the IACA is "1.5" |
| 2104 | {ISD::UMIN, MVT::v4i32, 2}, // The data reported by the IACA is "1.8" |
| 2105 | {ISD::SMIN, MVT::v8i16, 2}, |
| 2106 | {ISD::UMIN, MVT::v8i16, 2}, |
| 2107 | }; |
| 2108 | |
| 2109 | static const CostTblEntry AVX1CostTblPairWise[] = { |
| 2110 | {ISD::FMINNUM, MVT::v4f32, 1}, |
| 2111 | {ISD::FMINNUM, MVT::v4f64, 1}, |
| 2112 | {ISD::FMINNUM, MVT::v8f32, 2}, |
| 2113 | {ISD::SMIN, MVT::v2i64, 3}, |
| 2114 | {ISD::UMIN, MVT::v2i64, 3}, |
| 2115 | {ISD::SMIN, MVT::v4i32, 1}, |
| 2116 | {ISD::UMIN, MVT::v4i32, 1}, |
| 2117 | {ISD::SMIN, MVT::v8i16, 1}, |
| 2118 | {ISD::UMIN, MVT::v8i16, 1}, |
| 2119 | {ISD::SMIN, MVT::v8i32, 3}, |
| 2120 | {ISD::UMIN, MVT::v8i32, 3}, |
| 2121 | }; |
| 2122 | |
| 2123 | static const CostTblEntry AVX2CostTblPairWise[] = { |
| 2124 | {ISD::SMIN, MVT::v4i64, 2}, |
| 2125 | {ISD::UMIN, MVT::v4i64, 2}, |
| 2126 | {ISD::SMIN, MVT::v8i32, 1}, |
| 2127 | {ISD::UMIN, MVT::v8i32, 1}, |
| 2128 | {ISD::SMIN, MVT::v16i16, 1}, |
| 2129 | {ISD::UMIN, MVT::v16i16, 1}, |
| 2130 | {ISD::SMIN, MVT::v32i8, 2}, |
| 2131 | {ISD::UMIN, MVT::v32i8, 2}, |
| 2132 | }; |
| 2133 | |
| 2134 | static const CostTblEntry AVX512CostTblPairWise[] = { |
| 2135 | {ISD::FMINNUM, MVT::v8f64, 1}, |
| 2136 | {ISD::FMINNUM, MVT::v16f32, 2}, |
| 2137 | {ISD::SMIN, MVT::v8i64, 2}, |
| 2138 | {ISD::UMIN, MVT::v8i64, 2}, |
| 2139 | {ISD::SMIN, MVT::v16i32, 1}, |
| 2140 | {ISD::UMIN, MVT::v16i32, 1}, |
| 2141 | }; |
| 2142 | |
| 2143 | static const CostTblEntry SSE42CostTblNoPairWise[] = { |
| 2144 | {ISD::FMINNUM, MVT::v2f64, 3}, |
| 2145 | {ISD::FMINNUM, MVT::v4f32, 3}, |
| 2146 | {ISD::SMIN, MVT::v2i64, 7}, // The data reported by the IACA is "6.8" |
| 2147 | {ISD::UMIN, MVT::v2i64, 9}, // The data reported by the IACA is "8.6" |
| 2148 | {ISD::SMIN, MVT::v4i32, 1}, // The data reported by the IACA is "1.5" |
| 2149 | {ISD::UMIN, MVT::v4i32, 2}, // The data reported by the IACA is "1.8" |
| 2150 | {ISD::SMIN, MVT::v8i16, 1}, // The data reported by the IACA is "1.5" |
| 2151 | {ISD::UMIN, MVT::v8i16, 2}, // The data reported by the IACA is "1.8" |
| 2152 | }; |
| 2153 | |
| 2154 | static const CostTblEntry AVX1CostTblNoPairWise[] = { |
| 2155 | {ISD::FMINNUM, MVT::v4f32, 1}, |
| 2156 | {ISD::FMINNUM, MVT::v4f64, 1}, |
| 2157 | {ISD::FMINNUM, MVT::v8f32, 1}, |
| 2158 | {ISD::SMIN, MVT::v2i64, 3}, |
| 2159 | {ISD::UMIN, MVT::v2i64, 3}, |
| 2160 | {ISD::SMIN, MVT::v4i32, 1}, |
| 2161 | {ISD::UMIN, MVT::v4i32, 1}, |
| 2162 | {ISD::SMIN, MVT::v8i16, 1}, |
| 2163 | {ISD::UMIN, MVT::v8i16, 1}, |
| 2164 | {ISD::SMIN, MVT::v8i32, 2}, |
| 2165 | {ISD::UMIN, MVT::v8i32, 2}, |
| 2166 | }; |
| 2167 | |
| 2168 | static const CostTblEntry AVX2CostTblNoPairWise[] = { |
| 2169 | {ISD::SMIN, MVT::v4i64, 1}, |
| 2170 | {ISD::UMIN, MVT::v4i64, 1}, |
| 2171 | {ISD::SMIN, MVT::v8i32, 1}, |
| 2172 | {ISD::UMIN, MVT::v8i32, 1}, |
| 2173 | {ISD::SMIN, MVT::v16i16, 1}, |
| 2174 | {ISD::UMIN, MVT::v16i16, 1}, |
| 2175 | {ISD::SMIN, MVT::v32i8, 1}, |
| 2176 | {ISD::UMIN, MVT::v32i8, 1}, |
| 2177 | }; |
| 2178 | |
| 2179 | static const CostTblEntry AVX512CostTblNoPairWise[] = { |
| 2180 | {ISD::FMINNUM, MVT::v8f64, 1}, |
| 2181 | {ISD::FMINNUM, MVT::v16f32, 2}, |
| 2182 | {ISD::SMIN, MVT::v8i64, 1}, |
| 2183 | {ISD::UMIN, MVT::v8i64, 1}, |
| 2184 | {ISD::SMIN, MVT::v16i32, 1}, |
| 2185 | {ISD::UMIN, MVT::v16i32, 1}, |
| 2186 | }; |
| 2187 | |
| 2188 | if (IsPairwise) { |
| 2189 | if (ST->hasAVX512()) |
| 2190 | if (const auto *Entry = CostTableLookup(AVX512CostTblPairWise, ISD, MTy)) |
| 2191 | return LT.first * Entry->Cost; |
| 2192 | |
| 2193 | if (ST->hasAVX2()) |
| 2194 | if (const auto *Entry = CostTableLookup(AVX2CostTblPairWise, ISD, MTy)) |
| 2195 | return LT.first * Entry->Cost; |
| 2196 | |
| 2197 | if (ST->hasAVX()) |
| 2198 | if (const auto *Entry = CostTableLookup(AVX1CostTblPairWise, ISD, MTy)) |
| 2199 | return LT.first * Entry->Cost; |
| 2200 | |
| 2201 | if (ST->hasSSE42()) |
| 2202 | if (const auto *Entry = CostTableLookup(SSE42CostTblPairWise, ISD, MTy)) |
| 2203 | return LT.first * Entry->Cost; |
| 2204 | } else { |
| 2205 | if (ST->hasAVX512()) |
| 2206 | if (const auto *Entry = |
| 2207 | CostTableLookup(AVX512CostTblNoPairWise, ISD, MTy)) |
| 2208 | return LT.first * Entry->Cost; |
| 2209 | |
| 2210 | if (ST->hasAVX2()) |
| 2211 | if (const auto *Entry = CostTableLookup(AVX2CostTblNoPairWise, ISD, MTy)) |
| 2212 | return LT.first * Entry->Cost; |
| 2213 | |
| 2214 | if (ST->hasAVX()) |
| 2215 | if (const auto *Entry = CostTableLookup(AVX1CostTblNoPairWise, ISD, MTy)) |
| 2216 | return LT.first * Entry->Cost; |
| 2217 | |
| 2218 | if (ST->hasSSE42()) |
| 2219 | if (const auto *Entry = CostTableLookup(SSE42CostTblNoPairWise, ISD, MTy)) |
| 2220 | return LT.first * Entry->Cost; |
| 2221 | } |
| 2222 | |
| 2223 | return BaseT::getMinMaxReductionCost(ValTy, CondTy, IsPairwise, IsUnsigned); |
| 2224 | } |
| 2225 | |
| Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 2226 | /// \brief Calculate the cost of materializing a 64-bit value. This helper |
| 2227 | /// method might only calculate a fraction of a larger immediate. Therefore it |
| 2228 | /// is valid to return a cost of ZERO. |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 2229 | int X86TTIImpl::getIntImmCost(int64_t Val) { |
| Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 2230 | if (Val == 0) |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2231 | return TTI::TCC_Free; |
| Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 2232 | |
| 2233 | if (isInt<32>(Val)) |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2234 | return TTI::TCC_Basic; |
| Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 2235 | |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2236 | return 2 * TTI::TCC_Basic; |
| Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 2237 | } |
| 2238 | |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 2239 | int X86TTIImpl::getIntImmCost(const APInt &Imm, Type *Ty) { |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2240 | assert(Ty->isIntegerTy()); |
| 2241 | |
| 2242 | unsigned BitSize = Ty->getPrimitiveSizeInBits(); |
| 2243 | if (BitSize == 0) |
| 2244 | return ~0U; |
| 2245 | |
| Juergen Ributzka | 4317617 | 2014-05-19 21:00:53 +0000 | [diff] [blame] | 2246 | // Never hoist constants larger than 128bit, because this might lead to |
| 2247 | // incorrect code generation or assertions in codegen. |
| 2248 | // Fixme: Create a cost model for types larger than i128 once the codegen |
| 2249 | // issues have been fixed. |
| 2250 | if (BitSize > 128) |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2251 | return TTI::TCC_Free; |
| Juergen Ributzka | 4317617 | 2014-05-19 21:00:53 +0000 | [diff] [blame] | 2252 | |
| Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 2253 | if (Imm == 0) |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2254 | return TTI::TCC_Free; |
| Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 2255 | |
| Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 2256 | // Sign-extend all constants to a multiple of 64-bit. |
| 2257 | APInt ImmVal = Imm; |
| 2258 | if (BitSize & 0x3f) |
| 2259 | ImmVal = Imm.sext((BitSize + 63) & ~0x3fU); |
| 2260 | |
| 2261 | // Split the constant into 64-bit chunks and calculate the cost for each |
| 2262 | // chunk. |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 2263 | int Cost = 0; |
| Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 2264 | for (unsigned ShiftVal = 0; ShiftVal < BitSize; ShiftVal += 64) { |
| 2265 | APInt Tmp = ImmVal.ashr(ShiftVal).sextOrTrunc(64); |
| 2266 | int64_t Val = Tmp.getSExtValue(); |
| 2267 | Cost += getIntImmCost(Val); |
| 2268 | } |
| Sanjay Patel | 4c7d094 | 2016-04-05 19:27:39 +0000 | [diff] [blame] | 2269 | // We need at least one instruction to materialize the constant. |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 2270 | return std::max(1, Cost); |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2271 | } |
| 2272 | |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 2273 | int X86TTIImpl::getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, |
| 2274 | Type *Ty) { |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2275 | assert(Ty->isIntegerTy()); |
| 2276 | |
| 2277 | unsigned BitSize = Ty->getPrimitiveSizeInBits(); |
| Juergen Ributzka | 4317617 | 2014-05-19 21:00:53 +0000 | [diff] [blame] | 2278 | // There is no cost model for constants with a bit size of 0. Return TCC_Free |
| 2279 | // here, so that constant hoisting will ignore this constant. |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2280 | if (BitSize == 0) |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2281 | return TTI::TCC_Free; |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2282 | |
| Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 2283 | unsigned ImmIdx = ~0U; |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2284 | switch (Opcode) { |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2285 | default: |
| 2286 | return TTI::TCC_Free; |
| Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 2287 | case Instruction::GetElementPtr: |
| Juergen Ributzka | 27435b3 | 2014-04-02 21:45:36 +0000 | [diff] [blame] | 2288 | // Always hoist the base address of a GetElementPtr. This prevents the |
| 2289 | // creation of new constants for every base constant that gets constant |
| 2290 | // folded with the offset. |
| Juergen Ributzka | 631c491 | 2014-03-25 18:01:25 +0000 | [diff] [blame] | 2291 | if (Idx == 0) |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2292 | return 2 * TTI::TCC_Basic; |
| 2293 | return TTI::TCC_Free; |
| Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 2294 | case Instruction::Store: |
| 2295 | ImmIdx = 0; |
| 2296 | break; |
| Craig Topper | 074e845 | 2015-12-20 18:41:54 +0000 | [diff] [blame] | 2297 | case Instruction::ICmp: |
| 2298 | // This is an imperfect hack to prevent constant hoisting of |
| 2299 | // compares that might be trying to check if a 64-bit value fits in |
| 2300 | // 32-bits. The backend can optimize these cases using a right shift by 32. |
| 2301 | // Ideally we would check the compare predicate here. There also other |
| 2302 | // similar immediates the backend can use shifts for. |
| 2303 | if (Idx == 1 && Imm.getBitWidth() == 64) { |
| 2304 | uint64_t ImmVal = Imm.getZExtValue(); |
| 2305 | if (ImmVal == 0x100000000ULL || ImmVal == 0xffffffff) |
| 2306 | return TTI::TCC_Free; |
| 2307 | } |
| 2308 | ImmIdx = 1; |
| 2309 | break; |
| Craig Topper | 79dd1bf | 2015-10-06 02:50:24 +0000 | [diff] [blame] | 2310 | case Instruction::And: |
| 2311 | // We support 64-bit ANDs with immediates with 32-bits of leading zeroes |
| 2312 | // by using a 32-bit operation with implicit zero extension. Detect such |
| 2313 | // immediates here as the normal path expects bit 31 to be sign extended. |
| 2314 | if (Idx == 1 && Imm.getBitWidth() == 64 && isUInt<32>(Imm.getZExtValue())) |
| 2315 | return TTI::TCC_Free; |
| Justin Bogner | b03fd12 | 2016-08-17 05:10:15 +0000 | [diff] [blame] | 2316 | LLVM_FALLTHROUGH; |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2317 | case Instruction::Add: |
| 2318 | case Instruction::Sub: |
| 2319 | case Instruction::Mul: |
| 2320 | case Instruction::UDiv: |
| 2321 | case Instruction::SDiv: |
| 2322 | case Instruction::URem: |
| 2323 | case Instruction::SRem: |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2324 | case Instruction::Or: |
| 2325 | case Instruction::Xor: |
| Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 2326 | ImmIdx = 1; |
| 2327 | break; |
| Michael Zolotukhin | 1f4a960 | 2014-04-30 19:17:32 +0000 | [diff] [blame] | 2328 | // Always return TCC_Free for the shift value of a shift instruction. |
| 2329 | case Instruction::Shl: |
| 2330 | case Instruction::LShr: |
| 2331 | case Instruction::AShr: |
| 2332 | if (Idx == 1) |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2333 | return TTI::TCC_Free; |
| Michael Zolotukhin | 1f4a960 | 2014-04-30 19:17:32 +0000 | [diff] [blame] | 2334 | break; |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2335 | case Instruction::Trunc: |
| 2336 | case Instruction::ZExt: |
| 2337 | case Instruction::SExt: |
| 2338 | case Instruction::IntToPtr: |
| 2339 | case Instruction::PtrToInt: |
| 2340 | case Instruction::BitCast: |
| Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 2341 | case Instruction::PHI: |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2342 | case Instruction::Call: |
| 2343 | case Instruction::Select: |
| 2344 | case Instruction::Ret: |
| 2345 | case Instruction::Load: |
| Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 2346 | break; |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2347 | } |
| Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 2348 | |
| Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 2349 | if (Idx == ImmIdx) { |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 2350 | int NumConstants = (BitSize + 63) / 64; |
| 2351 | int Cost = X86TTIImpl::getIntImmCost(Imm, Ty); |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2352 | return (Cost <= NumConstants * TTI::TCC_Basic) |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 2353 | ? static_cast<int>(TTI::TCC_Free) |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2354 | : Cost; |
| Juergen Ributzka | b2e4edb | 2014-06-10 00:32:29 +0000 | [diff] [blame] | 2355 | } |
| Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 2356 | |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2357 | return X86TTIImpl::getIntImmCost(Imm, Ty); |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2358 | } |
| 2359 | |
| Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 2360 | int X86TTIImpl::getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, |
| 2361 | Type *Ty) { |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2362 | assert(Ty->isIntegerTy()); |
| 2363 | |
| 2364 | unsigned BitSize = Ty->getPrimitiveSizeInBits(); |
| Juergen Ributzka | 4317617 | 2014-05-19 21:00:53 +0000 | [diff] [blame] | 2365 | // There is no cost model for constants with a bit size of 0. Return TCC_Free |
| 2366 | // here, so that constant hoisting will ignore this constant. |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2367 | if (BitSize == 0) |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2368 | return TTI::TCC_Free; |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2369 | |
| 2370 | switch (IID) { |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2371 | default: |
| 2372 | return TTI::TCC_Free; |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2373 | case Intrinsic::sadd_with_overflow: |
| 2374 | case Intrinsic::uadd_with_overflow: |
| 2375 | case Intrinsic::ssub_with_overflow: |
| 2376 | case Intrinsic::usub_with_overflow: |
| 2377 | case Intrinsic::smul_with_overflow: |
| 2378 | case Intrinsic::umul_with_overflow: |
| Juergen Ributzka | f0dff49 | 2014-03-21 06:04:45 +0000 | [diff] [blame] | 2379 | if ((Idx == 1) && Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue())) |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2380 | return TTI::TCC_Free; |
| Juergen Ributzka | 5eef98c | 2014-03-25 18:01:23 +0000 | [diff] [blame] | 2381 | break; |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2382 | case Intrinsic::experimental_stackmap: |
| Juergen Ributzka | 5eef98c | 2014-03-25 18:01:23 +0000 | [diff] [blame] | 2383 | if ((Idx < 2) || (Imm.getBitWidth() <= 64 && isInt<64>(Imm.getSExtValue()))) |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2384 | return TTI::TCC_Free; |
| Juergen Ributzka | 5eef98c | 2014-03-25 18:01:23 +0000 | [diff] [blame] | 2385 | break; |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2386 | case Intrinsic::experimental_patchpoint_void: |
| 2387 | case Intrinsic::experimental_patchpoint_i64: |
| Juergen Ributzka | 5eef98c | 2014-03-25 18:01:23 +0000 | [diff] [blame] | 2388 | if ((Idx < 4) || (Imm.getBitWidth() <= 64 && isInt<64>(Imm.getSExtValue()))) |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2389 | return TTI::TCC_Free; |
| Juergen Ributzka | 5eef98c | 2014-03-25 18:01:23 +0000 | [diff] [blame] | 2390 | break; |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2391 | } |
| Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 2392 | return X86TTIImpl::getIntImmCost(Imm, Ty); |
| Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 2393 | } |
| NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 2394 | |
| Elena Demikhovsky | f58f838 | 2017-08-20 12:34:29 +0000 | [diff] [blame] | 2395 | unsigned X86TTIImpl::getUserCost(const User *U, |
| 2396 | ArrayRef<const Value *> Operands) { |
| 2397 | if (isa<StoreInst>(U)) { |
| 2398 | Value *Ptr = U->getOperand(1); |
| 2399 | // Store instruction with index and scale costs 2 Uops. |
| 2400 | // Check the preceding GEP to identify non-const indices. |
| 2401 | if (auto GEP = dyn_cast<GetElementPtrInst>(Ptr)) { |
| 2402 | if (!all_of(GEP->indices(), [](Value *V) { return isa<Constant>(V); })) |
| 2403 | return TTI::TCC_Basic * 2; |
| 2404 | } |
| 2405 | return TTI::TCC_Basic; |
| 2406 | } |
| 2407 | return BaseT::getUserCost(U, Operands); |
| 2408 | } |
| 2409 | |
| Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 2410 | // Return an average cost of Gather / Scatter instruction, maybe improved later |
| 2411 | int X86TTIImpl::getGSVectorCost(unsigned Opcode, Type *SrcVTy, Value *Ptr, |
| 2412 | unsigned Alignment, unsigned AddressSpace) { |
| 2413 | |
| 2414 | assert(isa<VectorType>(SrcVTy) && "Unexpected type in getGSVectorCost"); |
| 2415 | unsigned VF = SrcVTy->getVectorNumElements(); |
| 2416 | |
| 2417 | // Try to reduce index size from 64 bit (default for GEP) |
| 2418 | // to 32. It is essential for VF 16. If the index can't be reduced to 32, the |
| 2419 | // operation will use 16 x 64 indices which do not fit in a zmm and needs |
| 2420 | // to split. Also check that the base pointer is the same for all lanes, |
| 2421 | // and that there's at most one variable index. |
| 2422 | auto getIndexSizeInBits = [](Value *Ptr, const DataLayout& DL) { |
| 2423 | unsigned IndexSize = DL.getPointerSizeInBits(); |
| 2424 | GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr); |
| 2425 | if (IndexSize < 64 || !GEP) |
| 2426 | return IndexSize; |
| Simon Pilgrim | 14000b3 | 2016-05-24 08:17:50 +0000 | [diff] [blame] | 2427 | |
| Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 2428 | unsigned NumOfVarIndices = 0; |
| 2429 | Value *Ptrs = GEP->getPointerOperand(); |
| 2430 | if (Ptrs->getType()->isVectorTy() && !getSplatValue(Ptrs)) |
| 2431 | return IndexSize; |
| 2432 | for (unsigned i = 1; i < GEP->getNumOperands(); ++i) { |
| 2433 | if (isa<Constant>(GEP->getOperand(i))) |
| 2434 | continue; |
| 2435 | Type *IndxTy = GEP->getOperand(i)->getType(); |
| 2436 | if (IndxTy->isVectorTy()) |
| 2437 | IndxTy = IndxTy->getVectorElementType(); |
| 2438 | if ((IndxTy->getPrimitiveSizeInBits() == 64 && |
| 2439 | !isa<SExtInst>(GEP->getOperand(i))) || |
| 2440 | ++NumOfVarIndices > 1) |
| 2441 | return IndexSize; // 64 |
| 2442 | } |
| 2443 | return (unsigned)32; |
| 2444 | }; |
| 2445 | |
| 2446 | |
| 2447 | // Trying to reduce IndexSize to 32 bits for vector 16. |
| 2448 | // By default the IndexSize is equal to pointer size. |
| Mohammed Agabaria | 115f68e | 2017-11-20 08:18:12 +0000 | [diff] [blame] | 2449 | unsigned IndexSize = (ST->hasAVX512() && VF >= 16) |
| 2450 | ? getIndexSizeInBits(Ptr, DL) |
| 2451 | : DL.getPointerSizeInBits(); |
| Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 2452 | |
| Mehdi Amini | 867e914 | 2016-04-14 04:36:40 +0000 | [diff] [blame] | 2453 | Type *IndexVTy = VectorType::get(IntegerType::get(SrcVTy->getContext(), |
| Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 2454 | IndexSize), VF); |
| 2455 | std::pair<int, MVT> IdxsLT = TLI->getTypeLegalizationCost(DL, IndexVTy); |
| 2456 | std::pair<int, MVT> SrcLT = TLI->getTypeLegalizationCost(DL, SrcVTy); |
| 2457 | int SplitFactor = std::max(IdxsLT.first, SrcLT.first); |
| 2458 | if (SplitFactor > 1) { |
| 2459 | // Handle splitting of vector of pointers |
| 2460 | Type *SplitSrcTy = VectorType::get(SrcVTy->getScalarType(), VF / SplitFactor); |
| 2461 | return SplitFactor * getGSVectorCost(Opcode, SplitSrcTy, Ptr, Alignment, |
| 2462 | AddressSpace); |
| 2463 | } |
| 2464 | |
| 2465 | // The gather / scatter cost is given by Intel architects. It is a rough |
| 2466 | // number since we are looking at one instruction in a time. |
| Mohammed Agabaria | 115f68e | 2017-11-20 08:18:12 +0000 | [diff] [blame] | 2467 | const int GSOverhead = (Opcode == Instruction::Load) |
| 2468 | ? ST->getGatherOverhead() |
| 2469 | : ST->getScatterOverhead(); |
| Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 2470 | return GSOverhead + VF * getMemoryOpCost(Opcode, SrcVTy->getScalarType(), |
| 2471 | Alignment, AddressSpace); |
| 2472 | } |
| 2473 | |
| 2474 | /// Return the cost of full scalarization of gather / scatter operation. |
| 2475 | /// |
| 2476 | /// Opcode - Load or Store instruction. |
| 2477 | /// SrcVTy - The type of the data vector that should be gathered or scattered. |
| 2478 | /// VariableMask - The mask is non-constant at compile time. |
| 2479 | /// Alignment - Alignment for one element. |
| 2480 | /// AddressSpace - pointer[s] address space. |
| 2481 | /// |
| 2482 | int X86TTIImpl::getGSScalarCost(unsigned Opcode, Type *SrcVTy, |
| 2483 | bool VariableMask, unsigned Alignment, |
| 2484 | unsigned AddressSpace) { |
| 2485 | unsigned VF = SrcVTy->getVectorNumElements(); |
| 2486 | |
| 2487 | int MaskUnpackCost = 0; |
| 2488 | if (VariableMask) { |
| 2489 | VectorType *MaskTy = |
| Mehdi Amini | 867e914 | 2016-04-14 04:36:40 +0000 | [diff] [blame] | 2490 | VectorType::get(Type::getInt1Ty(SrcVTy->getContext()), VF); |
| Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 2491 | MaskUnpackCost = getScalarizationOverhead(MaskTy, false, true); |
| 2492 | int ScalarCompareCost = |
| Mehdi Amini | 867e914 | 2016-04-14 04:36:40 +0000 | [diff] [blame] | 2493 | getCmpSelInstrCost(Instruction::ICmp, Type::getInt1Ty(SrcVTy->getContext()), |
| Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 2494 | nullptr); |
| 2495 | int BranchCost = getCFInstrCost(Instruction::Br); |
| 2496 | MaskUnpackCost += VF * (BranchCost + ScalarCompareCost); |
| 2497 | } |
| 2498 | |
| 2499 | // The cost of the scalar loads/stores. |
| 2500 | int MemoryOpCost = VF * getMemoryOpCost(Opcode, SrcVTy->getScalarType(), |
| 2501 | Alignment, AddressSpace); |
| 2502 | |
| 2503 | int InsertExtractCost = 0; |
| 2504 | if (Opcode == Instruction::Load) |
| 2505 | for (unsigned i = 0; i < VF; ++i) |
| 2506 | // Add the cost of inserting each scalar load into the vector |
| 2507 | InsertExtractCost += |
| 2508 | getVectorInstrCost(Instruction::InsertElement, SrcVTy, i); |
| 2509 | else |
| 2510 | for (unsigned i = 0; i < VF; ++i) |
| 2511 | // Add the cost of extracting each element out of the data vector |
| 2512 | InsertExtractCost += |
| 2513 | getVectorInstrCost(Instruction::ExtractElement, SrcVTy, i); |
| 2514 | |
| 2515 | return MemoryOpCost + MaskUnpackCost + InsertExtractCost; |
| 2516 | } |
| 2517 | |
| 2518 | /// Calculate the cost of Gather / Scatter operation |
| 2519 | int X86TTIImpl::getGatherScatterOpCost(unsigned Opcode, Type *SrcVTy, |
| 2520 | Value *Ptr, bool VariableMask, |
| 2521 | unsigned Alignment) { |
| 2522 | assert(SrcVTy->isVectorTy() && "Unexpected data type for Gather/Scatter"); |
| 2523 | unsigned VF = SrcVTy->getVectorNumElements(); |
| 2524 | PointerType *PtrTy = dyn_cast<PointerType>(Ptr->getType()); |
| 2525 | if (!PtrTy && Ptr->getType()->isVectorTy()) |
| 2526 | PtrTy = dyn_cast<PointerType>(Ptr->getType()->getVectorElementType()); |
| 2527 | assert(PtrTy && "Unexpected type for Ptr argument"); |
| 2528 | unsigned AddressSpace = PtrTy->getAddressSpace(); |
| 2529 | |
| 2530 | bool Scalarize = false; |
| 2531 | if ((Opcode == Instruction::Load && !isLegalMaskedGather(SrcVTy)) || |
| 2532 | (Opcode == Instruction::Store && !isLegalMaskedScatter(SrcVTy))) |
| 2533 | Scalarize = true; |
| 2534 | // Gather / Scatter for vector 2 is not profitable on KNL / SKX |
| 2535 | // Vector-4 of gather/scatter instruction does not exist on KNL. |
| 2536 | // We can extend it to 8 elements, but zeroing upper bits of |
| 2537 | // 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] | 2538 | // cost of vector-4 for KNL. TODO: Check, maybe the gather/scatter instruction |
| 2539 | // is better in the VariableMask case. |
| Mohammed Agabaria | 115f68e | 2017-11-20 08:18:12 +0000 | [diff] [blame] | 2540 | if (ST->hasAVX512() && (VF == 2 || (VF == 4 && !ST->hasVLX()))) |
| Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 2541 | Scalarize = true; |
| 2542 | |
| 2543 | if (Scalarize) |
| Elena Demikhovsky | 21706cb | 2017-01-02 10:37:52 +0000 | [diff] [blame] | 2544 | return getGSScalarCost(Opcode, SrcVTy, VariableMask, Alignment, |
| 2545 | AddressSpace); |
| Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 2546 | |
| 2547 | return getGSVectorCost(Opcode, SrcVTy, Ptr, Alignment, AddressSpace); |
| 2548 | } |
| 2549 | |
| Evgeny Stupachenko | c675290 | 2017-08-07 19:56:34 +0000 | [diff] [blame] | 2550 | bool X86TTIImpl::isLSRCostLess(TargetTransformInfo::LSRCost &C1, |
| 2551 | TargetTransformInfo::LSRCost &C2) { |
| 2552 | // X86 specific here are "instruction number 1st priority". |
| 2553 | return std::tie(C1.Insns, C1.NumRegs, C1.AddRecCost, |
| 2554 | C1.NumIVMuls, C1.NumBaseAdds, |
| 2555 | C1.ScaleCost, C1.ImmCost, C1.SetupCost) < |
| 2556 | std::tie(C2.Insns, C2.NumRegs, C2.AddRecCost, |
| 2557 | C2.NumIVMuls, C2.NumBaseAdds, |
| 2558 | C2.ScaleCost, C2.ImmCost, C2.SetupCost); |
| 2559 | } |
| 2560 | |
| Sanjay Patel | d7c702b | 2018-02-05 23:43:05 +0000 | [diff] [blame] | 2561 | bool X86TTIImpl::canMacroFuseCmp() { |
| 2562 | return ST->hasMacroFusion(); |
| 2563 | } |
| 2564 | |
| Elena Demikhovsky | 20662e3 | 2015-10-19 07:43:38 +0000 | [diff] [blame] | 2565 | bool X86TTIImpl::isLegalMaskedLoad(Type *DataTy) { |
| Craig Topper | 46a5d58 | 2017-11-16 06:02:05 +0000 | [diff] [blame] | 2566 | // The backend can't handle a single element vector. |
| 2567 | if (isa<VectorType>(DataTy) && DataTy->getVectorNumElements() == 1) |
| 2568 | return false; |
| Elena Demikhovsky | 20662e3 | 2015-10-19 07:43:38 +0000 | [diff] [blame] | 2569 | Type *ScalarTy = DataTy->getScalarType(); |
| Elena Demikhovsky | 1ca72e1 | 2015-11-19 07:17:16 +0000 | [diff] [blame] | 2570 | int DataWidth = isa<PointerType>(ScalarTy) ? |
| 2571 | DL.getPointerSizeInBits() : ScalarTy->getPrimitiveSizeInBits(); |
| NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 2572 | |
| Igor Breger | f44b79d | 2016-08-02 09:15:28 +0000 | [diff] [blame] | 2573 | return ((DataWidth == 32 || DataWidth == 64) && ST->hasAVX()) || |
| 2574 | ((DataWidth == 8 || DataWidth == 16) && ST->hasBWI()); |
| NAKAMURA Takumi | 0b305db | 2015-07-14 04:03:49 +0000 | [diff] [blame] | 2575 | } |
| Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 2576 | |
| Elena Demikhovsky | 20662e3 | 2015-10-19 07:43:38 +0000 | [diff] [blame] | 2577 | bool X86TTIImpl::isLegalMaskedStore(Type *DataType) { |
| 2578 | return isLegalMaskedLoad(DataType); |
| Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 2579 | } |
| 2580 | |
| Elena Demikhovsky | 0928585 | 2015-10-25 15:37:55 +0000 | [diff] [blame] | 2581 | bool X86TTIImpl::isLegalMaskedGather(Type *DataTy) { |
| 2582 | // This function is called now in two cases: from the Loop Vectorizer |
| 2583 | // and from the Scalarizer. |
| 2584 | // When the Loop Vectorizer asks about legality of the feature, |
| 2585 | // the vectorization factor is not calculated yet. The Loop Vectorizer |
| 2586 | // sends a scalar type and the decision is based on the width of the |
| 2587 | // scalar element. |
| 2588 | // Later on, the cost model will estimate usage this intrinsic based on |
| 2589 | // the vector type. |
| 2590 | // The Scalarizer asks again about legality. It sends a vector type. |
| 2591 | // In this case we can reject non-power-of-2 vectors. |
| Craig Topper | 46a5d58 | 2017-11-16 06:02:05 +0000 | [diff] [blame] | 2592 | // We also reject single element vectors as the type legalizer can't |
| 2593 | // scalarize it. |
| 2594 | if (isa<VectorType>(DataTy)) { |
| 2595 | unsigned NumElts = DataTy->getVectorNumElements(); |
| 2596 | if (NumElts == 1 || !isPowerOf2_32(NumElts)) |
| 2597 | return false; |
| 2598 | } |
| Elena Demikhovsky | 0928585 | 2015-10-25 15:37:55 +0000 | [diff] [blame] | 2599 | Type *ScalarTy = DataTy->getScalarType(); |
| Elena Demikhovsky | 1ca72e1 | 2015-11-19 07:17:16 +0000 | [diff] [blame] | 2600 | int DataWidth = isa<PointerType>(ScalarTy) ? |
| 2601 | DL.getPointerSizeInBits() : ScalarTy->getPrimitiveSizeInBits(); |
| Elena Demikhovsky | 0928585 | 2015-10-25 15:37:55 +0000 | [diff] [blame] | 2602 | |
| Craig Topper | ea37e20 | 2017-11-25 18:09:37 +0000 | [diff] [blame] | 2603 | // Some CPUs have better gather performance than others. |
| 2604 | // TODO: Remove the explicit ST->hasAVX512()?, That would mean we would only |
| 2605 | // enable gather with a -march. |
| 2606 | return (DataWidth == 32 || DataWidth == 64) && |
| Craig Topper | 0d797a3 | 2018-01-20 00:26:08 +0000 | [diff] [blame] | 2607 | (ST->hasAVX512() || (ST->hasFastGather() && ST->hasAVX2())); |
| Elena Demikhovsky | 0928585 | 2015-10-25 15:37:55 +0000 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | bool X86TTIImpl::isLegalMaskedScatter(Type *DataType) { |
| Mohammed Agabaria | 115f68e | 2017-11-20 08:18:12 +0000 | [diff] [blame] | 2611 | // AVX2 doesn't support scatter |
| 2612 | if (!ST->hasAVX512()) |
| 2613 | return false; |
| Elena Demikhovsky | 0928585 | 2015-10-25 15:37:55 +0000 | [diff] [blame] | 2614 | return isLegalMaskedGather(DataType); |
| 2615 | } |
| 2616 | |
| Sanjay Patel | 6fd4391 | 2017-09-09 13:38:18 +0000 | [diff] [blame] | 2617 | bool X86TTIImpl::hasDivRemOp(Type *DataType, bool IsSigned) { |
| 2618 | EVT VT = TLI->getValueType(DL, DataType); |
| 2619 | return TLI->isOperationLegal(IsSigned ? ISD::SDIVREM : ISD::UDIVREM, VT); |
| 2620 | } |
| 2621 | |
| Sanjay Patel | 0de1a4b | 2017-11-27 21:15:43 +0000 | [diff] [blame] | 2622 | bool X86TTIImpl::isFCmpOrdCheaperThanFCmpZero(Type *Ty) { |
| 2623 | return false; |
| 2624 | } |
| 2625 | |
| Eric Christopher | d566fb1 | 2015-07-29 22:09:48 +0000 | [diff] [blame] | 2626 | bool X86TTIImpl::areInlineCompatible(const Function *Caller, |
| 2627 | const Function *Callee) const { |
| Eric Christopher | e100226 | 2015-07-02 01:11:50 +0000 | [diff] [blame] | 2628 | const TargetMachine &TM = getTLI()->getTargetMachine(); |
| 2629 | |
| 2630 | // Work this as a subsetting of subtarget features. |
| 2631 | const FeatureBitset &CallerBits = |
| 2632 | TM.getSubtargetImpl(*Caller)->getFeatureBits(); |
| 2633 | const FeatureBitset &CalleeBits = |
| 2634 | TM.getSubtargetImpl(*Callee)->getFeatureBits(); |
| 2635 | |
| 2636 | // FIXME: This is likely too limiting as it will include subtarget features |
| 2637 | // that we might not care about for inlining, but it is conservatively |
| 2638 | // correct. |
| 2639 | return (CallerBits & CalleeBits) == CalleeBits; |
| 2640 | } |
| Michael Kuperstein | b2443ed | 2016-10-20 21:04:31 +0000 | [diff] [blame] | 2641 | |
| Clement Courbet | b2c3eb8 | 2017-10-30 14:19:33 +0000 | [diff] [blame] | 2642 | const X86TTIImpl::TTI::MemCmpExpansionOptions * |
| 2643 | X86TTIImpl::enableMemCmpExpansion(bool IsZeroCmp) const { |
| 2644 | // Only enable vector loads for equality comparison. |
| 2645 | // Right now the vector version is not as fast, see #33329. |
| 2646 | static const auto ThreeWayOptions = [this]() { |
| 2647 | TTI::MemCmpExpansionOptions Options; |
| 2648 | if (ST->is64Bit()) { |
| 2649 | Options.LoadSizes.push_back(8); |
| 2650 | } |
| 2651 | Options.LoadSizes.push_back(4); |
| 2652 | Options.LoadSizes.push_back(2); |
| 2653 | Options.LoadSizes.push_back(1); |
| 2654 | return Options; |
| 2655 | }(); |
| 2656 | static const auto EqZeroOptions = [this]() { |
| 2657 | TTI::MemCmpExpansionOptions Options; |
| 2658 | // TODO: enable AVX512 when the DAG is ready. |
| 2659 | // if (ST->hasAVX512()) Options.LoadSizes.push_back(64); |
| 2660 | if (ST->hasAVX2()) Options.LoadSizes.push_back(32); |
| 2661 | if (ST->hasSSE2()) Options.LoadSizes.push_back(16); |
| 2662 | if (ST->is64Bit()) { |
| 2663 | Options.LoadSizes.push_back(8); |
| 2664 | } |
| 2665 | Options.LoadSizes.push_back(4); |
| 2666 | Options.LoadSizes.push_back(2); |
| 2667 | Options.LoadSizes.push_back(1); |
| 2668 | return Options; |
| 2669 | }(); |
| 2670 | return IsZeroCmp ? &EqZeroOptions : &ThreeWayOptions; |
| Sanjay Patel | 0656629 | 2017-06-20 15:58:30 +0000 | [diff] [blame] | 2671 | } |
| 2672 | |
| Michael Kuperstein | b2443ed | 2016-10-20 21:04:31 +0000 | [diff] [blame] | 2673 | bool X86TTIImpl::enableInterleavedAccessVectorization() { |
| 2674 | // TODO: We expect this to be beneficial regardless of arch, |
| 2675 | // but there are currently some unexplained performance artifacts on Atom. |
| 2676 | // As a temporary solution, disable on Atom. |
| Mohammed Agabaria | 20caee9 | 2017-01-25 09:14:48 +0000 | [diff] [blame] | 2677 | return !(ST->isAtom()); |
| Michael Kuperstein | b2443ed | 2016-10-20 21:04:31 +0000 | [diff] [blame] | 2678 | } |
| Elena Demikhovsky | 21706cb | 2017-01-02 10:37:52 +0000 | [diff] [blame] | 2679 | |
| Dorit Nuzman | e0e0f1d | 2017-06-25 08:26:25 +0000 | [diff] [blame] | 2680 | // Get estimation for interleaved load/store operations for AVX2. |
| 2681 | // \p Factor is the interleaved-access factor (stride) - number of |
| 2682 | // (interleaved) elements in the group. |
| 2683 | // \p Indices contains the indices for a strided load: when the |
| 2684 | // interleaved load has gaps they indicate which elements are used. |
| 2685 | // If Indices is empty (or if the number of indices is equal to the size |
| 2686 | // of the interleaved-access as given in \p Factor) the access has no gaps. |
| 2687 | // |
| 2688 | // As opposed to AVX-512, AVX2 does not have generic shuffles that allow |
| 2689 | // computing the cost using a generic formula as a function of generic |
| 2690 | // shuffles. We therefore use a lookup table instead, filled according to |
| 2691 | // the instruction sequences that codegen currently generates. |
| 2692 | int X86TTIImpl::getInterleavedMemoryOpCostAVX2(unsigned Opcode, Type *VecTy, |
| 2693 | unsigned Factor, |
| 2694 | ArrayRef<unsigned> Indices, |
| 2695 | unsigned Alignment, |
| 2696 | unsigned AddressSpace) { |
| 2697 | |
| 2698 | // We currently Support only fully-interleaved groups, with no gaps. |
| 2699 | // TODO: Support also strided loads (interleaved-groups with gaps). |
| 2700 | if (Indices.size() && Indices.size() != Factor) |
| 2701 | return BaseT::getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices, |
| 2702 | Alignment, AddressSpace); |
| 2703 | |
| 2704 | // VecTy for interleave memop is <VF*Factor x Elt>. |
| 2705 | // So, for VF=4, Interleave Factor = 3, Element type = i32 we have |
| 2706 | // VecTy = <12 x i32>. |
| 2707 | MVT LegalVT = getTLI()->getTypeLegalizationCost(DL, VecTy).second; |
| 2708 | |
| 2709 | // This function can be called with VecTy=<6xi128>, Factor=3, in which case |
| 2710 | // the VF=2, while v2i128 is an unsupported MVT vector type |
| 2711 | // (see MachineValueType.h::getVectorVT()). |
| 2712 | if (!LegalVT.isVector()) |
| 2713 | return BaseT::getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices, |
| 2714 | Alignment, AddressSpace); |
| 2715 | |
| 2716 | unsigned VF = VecTy->getVectorNumElements() / Factor; |
| 2717 | Type *ScalarTy = VecTy->getVectorElementType(); |
| Simon Pilgrim | 7b89ab5 | 2017-07-31 17:09:27 +0000 | [diff] [blame] | 2718 | |
| Dorit Nuzman | e0e0f1d | 2017-06-25 08:26:25 +0000 | [diff] [blame] | 2719 | // Calculate the number of memory operations (NumOfMemOps), required |
| 2720 | // for load/store the VecTy. |
| 2721 | unsigned VecTySize = DL.getTypeStoreSize(VecTy); |
| 2722 | unsigned LegalVTSize = LegalVT.getStoreSize(); |
| 2723 | unsigned NumOfMemOps = (VecTySize + LegalVTSize - 1) / LegalVTSize; |
| 2724 | |
| 2725 | // Get the cost of one memory operation. |
| 2726 | Type *SingleMemOpTy = VectorType::get(VecTy->getVectorElementType(), |
| 2727 | LegalVT.getVectorNumElements()); |
| 2728 | unsigned MemOpCost = |
| 2729 | getMemoryOpCost(Opcode, SingleMemOpTy, Alignment, AddressSpace); |
| Simon Pilgrim | 7b89ab5 | 2017-07-31 17:09:27 +0000 | [diff] [blame] | 2730 | |
| Dorit Nuzman | e0e0f1d | 2017-06-25 08:26:25 +0000 | [diff] [blame] | 2731 | VectorType *VT = VectorType::get(ScalarTy, VF); |
| 2732 | EVT ETy = TLI->getValueType(DL, VT); |
| 2733 | if (!ETy.isSimple()) |
| 2734 | return BaseT::getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices, |
| 2735 | Alignment, AddressSpace); |
| 2736 | |
| 2737 | // TODO: Complete for other data-types and strides. |
| 2738 | // Each combination of Stride, ElementTy and VF results in a different |
| 2739 | // sequence; The cost tables are therefore accessed with: |
| 2740 | // Factor (stride) and VectorType=VFxElemType. |
| 2741 | // The Cost accounts only for the shuffle sequence; |
| 2742 | // The cost of the loads/stores is accounted for separately. |
| 2743 | // |
| 2744 | static const CostTblEntry AVX2InterleavedLoadTbl[] = { |
| Mohammed Agabaria | 6e6d532 | 2017-11-16 09:38:32 +0000 | [diff] [blame] | 2745 | { 2, MVT::v4i64, 6 }, //(load 8i64 and) deinterleave into 2 x 4i64 |
| 2746 | { 2, MVT::v4f64, 6 }, //(load 8f64 and) deinterleave into 2 x 4f64 |
| 2747 | |
| Dorit Nuzman | e0e0f1d | 2017-06-25 08:26:25 +0000 | [diff] [blame] | 2748 | { 3, MVT::v2i8, 10 }, //(load 6i8 and) deinterleave into 3 x 2i8 |
| 2749 | { 3, MVT::v4i8, 4 }, //(load 12i8 and) deinterleave into 3 x 4i8 |
| 2750 | { 3, MVT::v8i8, 9 }, //(load 24i8 and) deinterleave into 3 x 8i8 |
| Michael Zuckerman | 4929326 | 2017-10-18 11:41:55 +0000 | [diff] [blame] | 2751 | { 3, MVT::v16i8, 11}, //(load 48i8 and) deinterleave into 3 x 16i8 |
| 2752 | { 3, MVT::v32i8, 13}, //(load 96i8 and) deinterleave into 3 x 32i8 |
| Mohammed Agabaria | 6691758 | 2017-11-06 10:56:20 +0000 | [diff] [blame] | 2753 | { 3, MVT::v8f32, 17 }, //(load 24f32 and)deinterleave into 3 x 8f32 |
| Simon Pilgrim | 7b89ab5 | 2017-07-31 17:09:27 +0000 | [diff] [blame] | 2754 | |
| Dorit Nuzman | e0e0f1d | 2017-06-25 08:26:25 +0000 | [diff] [blame] | 2755 | { 4, MVT::v2i8, 12 }, //(load 8i8 and) deinterleave into 4 x 2i8 |
| 2756 | { 4, MVT::v4i8, 4 }, //(load 16i8 and) deinterleave into 4 x 4i8 |
| 2757 | { 4, MVT::v8i8, 20 }, //(load 32i8 and) deinterleave into 4 x 8i8 |
| 2758 | { 4, MVT::v16i8, 39 }, //(load 64i8 and) deinterleave into 4 x 16i8 |
| Mohammed Agabaria | 6691758 | 2017-11-06 10:56:20 +0000 | [diff] [blame] | 2759 | { 4, MVT::v32i8, 80 }, //(load 128i8 and) deinterleave into 4 x 32i8 |
| 2760 | |
| 2761 | { 8, MVT::v8f32, 40 } //(load 64f32 and)deinterleave into 8 x 8f32 |
| Dorit Nuzman | e0e0f1d | 2017-06-25 08:26:25 +0000 | [diff] [blame] | 2762 | }; |
| 2763 | |
| 2764 | static const CostTblEntry AVX2InterleavedStoreTbl[] = { |
| Mohammed Agabaria | 6e6d532 | 2017-11-16 09:38:32 +0000 | [diff] [blame] | 2765 | { 2, MVT::v4i64, 6 }, //interleave into 2 x 4i64 into 8i64 (and store) |
| 2766 | { 2, MVT::v4f64, 6 }, //interleave into 2 x 4f64 into 8f64 (and store) |
| 2767 | |
| Dorit Nuzman | e0e0f1d | 2017-06-25 08:26:25 +0000 | [diff] [blame] | 2768 | { 3, MVT::v2i8, 7 }, //interleave 3 x 2i8 into 6i8 (and store) |
| 2769 | { 3, MVT::v4i8, 8 }, //interleave 3 x 4i8 into 12i8 (and store) |
| 2770 | { 3, MVT::v8i8, 11 }, //interleave 3 x 8i8 into 24i8 (and store) |
| Michael Zuckerman | 4929326 | 2017-10-18 11:41:55 +0000 | [diff] [blame] | 2771 | { 3, MVT::v16i8, 11 }, //interleave 3 x 16i8 into 48i8 (and store) |
| 2772 | { 3, MVT::v32i8, 13 }, //interleave 3 x 32i8 into 96i8 (and store) |
| Dorit Nuzman | e0e0f1d | 2017-06-25 08:26:25 +0000 | [diff] [blame] | 2773 | |
| 2774 | { 4, MVT::v2i8, 12 }, //interleave 4 x 2i8 into 8i8 (and store) |
| 2775 | { 4, MVT::v4i8, 9 }, //interleave 4 x 4i8 into 16i8 (and store) |
| Michael Zuckerman | 4929326 | 2017-10-18 11:41:55 +0000 | [diff] [blame] | 2776 | { 4, MVT::v8i8, 10 }, //interleave 4 x 8i8 into 32i8 (and store) |
| 2777 | { 4, MVT::v16i8, 10 }, //interleave 4 x 16i8 into 64i8 (and store) |
| 2778 | { 4, MVT::v32i8, 12 } //interleave 4 x 32i8 into 128i8 (and store) |
| Dorit Nuzman | e0e0f1d | 2017-06-25 08:26:25 +0000 | [diff] [blame] | 2779 | }; |
| 2780 | |
| 2781 | if (Opcode == Instruction::Load) { |
| 2782 | if (const auto *Entry = |
| 2783 | CostTableLookup(AVX2InterleavedLoadTbl, Factor, ETy.getSimpleVT())) |
| 2784 | return NumOfMemOps * MemOpCost + Entry->Cost; |
| 2785 | } else { |
| 2786 | assert(Opcode == Instruction::Store && |
| 2787 | "Expected Store Instruction at this point"); |
| Simon Pilgrim | 7b89ab5 | 2017-07-31 17:09:27 +0000 | [diff] [blame] | 2788 | if (const auto *Entry = |
| Dorit Nuzman | e0e0f1d | 2017-06-25 08:26:25 +0000 | [diff] [blame] | 2789 | CostTableLookup(AVX2InterleavedStoreTbl, Factor, ETy.getSimpleVT())) |
| 2790 | return NumOfMemOps * MemOpCost + Entry->Cost; |
| 2791 | } |
| 2792 | |
| 2793 | return BaseT::getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices, |
| 2794 | Alignment, AddressSpace); |
| 2795 | } |
| 2796 | |
| Elena Demikhovsky | 21706cb | 2017-01-02 10:37:52 +0000 | [diff] [blame] | 2797 | // Get estimation for interleaved load/store operations and strided load. |
| 2798 | // \p Indices contains indices for strided load. |
| 2799 | // \p Factor - the factor of interleaving. |
| 2800 | // AVX-512 provides 3-src shuffles that significantly reduces the cost. |
| 2801 | int X86TTIImpl::getInterleavedMemoryOpCostAVX512(unsigned Opcode, Type *VecTy, |
| 2802 | unsigned Factor, |
| 2803 | ArrayRef<unsigned> Indices, |
| 2804 | unsigned Alignment, |
| 2805 | unsigned AddressSpace) { |
| 2806 | |
| 2807 | // VecTy for interleave memop is <VF*Factor x Elt>. |
| 2808 | // So, for VF=4, Interleave Factor = 3, Element type = i32 we have |
| 2809 | // VecTy = <12 x i32>. |
| 2810 | |
| 2811 | // Calculate the number of memory operations (NumOfMemOps), required |
| 2812 | // for load/store the VecTy. |
| 2813 | MVT LegalVT = getTLI()->getTypeLegalizationCost(DL, VecTy).second; |
| 2814 | unsigned VecTySize = DL.getTypeStoreSize(VecTy); |
| 2815 | unsigned LegalVTSize = LegalVT.getStoreSize(); |
| 2816 | unsigned NumOfMemOps = (VecTySize + LegalVTSize - 1) / LegalVTSize; |
| 2817 | |
| 2818 | // Get the cost of one memory operation. |
| 2819 | Type *SingleMemOpTy = VectorType::get(VecTy->getVectorElementType(), |
| 2820 | LegalVT.getVectorNumElements()); |
| 2821 | unsigned MemOpCost = |
| 2822 | getMemoryOpCost(Opcode, SingleMemOpTy, Alignment, AddressSpace); |
| 2823 | |
| Michael Zuckerman | 4929326 | 2017-10-18 11:41:55 +0000 | [diff] [blame] | 2824 | unsigned VF = VecTy->getVectorNumElements() / Factor; |
| 2825 | MVT VT = MVT::getVectorVT(MVT::getVT(VecTy->getScalarType()), VF); |
| 2826 | |
| Elena Demikhovsky | 21706cb | 2017-01-02 10:37:52 +0000 | [diff] [blame] | 2827 | if (Opcode == Instruction::Load) { |
| Michael Zuckerman | 4929326 | 2017-10-18 11:41:55 +0000 | [diff] [blame] | 2828 | // The tables (AVX512InterleavedLoadTbl and AVX512InterleavedStoreTbl) |
| 2829 | // contain the cost of the optimized shuffle sequence that the |
| 2830 | // X86InterleavedAccess pass will generate. |
| 2831 | // The cost of loads and stores are computed separately from the table. |
| 2832 | |
| 2833 | // X86InterleavedAccess support only the following interleaved-access group. |
| 2834 | static const CostTblEntry AVX512InterleavedLoadTbl[] = { |
| 2835 | {3, MVT::v16i8, 12}, //(load 48i8 and) deinterleave into 3 x 16i8 |
| 2836 | {3, MVT::v32i8, 14}, //(load 96i8 and) deinterleave into 3 x 32i8 |
| 2837 | {3, MVT::v64i8, 22}, //(load 96i8 and) deinterleave into 3 x 32i8 |
| 2838 | }; |
| 2839 | |
| 2840 | if (const auto *Entry = |
| 2841 | CostTableLookup(AVX512InterleavedLoadTbl, Factor, VT)) |
| 2842 | return NumOfMemOps * MemOpCost + Entry->Cost; |
| 2843 | //If an entry does not exist, fallback to the default implementation. |
| 2844 | |
| Elena Demikhovsky | 21706cb | 2017-01-02 10:37:52 +0000 | [diff] [blame] | 2845 | // Kind of shuffle depends on number of loaded values. |
| 2846 | // If we load the entire data in one register, we can use a 1-src shuffle. |
| 2847 | // Otherwise, we'll merge 2 sources in each operation. |
| 2848 | TTI::ShuffleKind ShuffleKind = |
| 2849 | (NumOfMemOps > 1) ? TTI::SK_PermuteTwoSrc : TTI::SK_PermuteSingleSrc; |
| 2850 | |
| 2851 | unsigned ShuffleCost = |
| 2852 | getShuffleCost(ShuffleKind, SingleMemOpTy, 0, nullptr); |
| 2853 | |
| 2854 | unsigned NumOfLoadsInInterleaveGrp = |
| 2855 | Indices.size() ? Indices.size() : Factor; |
| 2856 | Type *ResultTy = VectorType::get(VecTy->getVectorElementType(), |
| 2857 | VecTy->getVectorNumElements() / Factor); |
| 2858 | unsigned NumOfResults = |
| 2859 | getTLI()->getTypeLegalizationCost(DL, ResultTy).first * |
| 2860 | NumOfLoadsInInterleaveGrp; |
| 2861 | |
| 2862 | // About a half of the loads may be folded in shuffles when we have only |
| 2863 | // one result. If we have more than one result, we do not fold loads at all. |
| 2864 | unsigned NumOfUnfoldedLoads = |
| 2865 | NumOfResults > 1 ? NumOfMemOps : NumOfMemOps / 2; |
| 2866 | |
| 2867 | // Get a number of shuffle operations per result. |
| 2868 | unsigned NumOfShufflesPerResult = |
| 2869 | std::max((unsigned)1, (unsigned)(NumOfMemOps - 1)); |
| 2870 | |
| 2871 | // The SK_MergeTwoSrc shuffle clobbers one of src operands. |
| 2872 | // When we have more than one destination, we need additional instructions |
| 2873 | // to keep sources. |
| 2874 | unsigned NumOfMoves = 0; |
| 2875 | if (NumOfResults > 1 && ShuffleKind == TTI::SK_PermuteTwoSrc) |
| 2876 | NumOfMoves = NumOfResults * NumOfShufflesPerResult / 2; |
| 2877 | |
| 2878 | int Cost = NumOfResults * NumOfShufflesPerResult * ShuffleCost + |
| 2879 | NumOfUnfoldedLoads * MemOpCost + NumOfMoves; |
| 2880 | |
| 2881 | return Cost; |
| 2882 | } |
| 2883 | |
| 2884 | // Store. |
| 2885 | assert(Opcode == Instruction::Store && |
| 2886 | "Expected Store Instruction at this point"); |
| Michael Zuckerman | 4929326 | 2017-10-18 11:41:55 +0000 | [diff] [blame] | 2887 | // X86InterleavedAccess support only the following interleaved-access group. |
| 2888 | static const CostTblEntry AVX512InterleavedStoreTbl[] = { |
| 2889 | {3, MVT::v16i8, 12}, // interleave 3 x 16i8 into 48i8 (and store) |
| 2890 | {3, MVT::v32i8, 14}, // interleave 3 x 32i8 into 96i8 (and store) |
| 2891 | {3, MVT::v64i8, 26}, // interleave 3 x 64i8 into 96i8 (and store) |
| 2892 | |
| 2893 | {4, MVT::v8i8, 10}, // interleave 4 x 8i8 into 32i8 (and store) |
| 2894 | {4, MVT::v16i8, 11}, // interleave 4 x 16i8 into 64i8 (and store) |
| 2895 | {4, MVT::v32i8, 14}, // interleave 4 x 32i8 into 128i8 (and store) |
| 2896 | {4, MVT::v64i8, 24} // interleave 4 x 32i8 into 256i8 (and store) |
| 2897 | }; |
| 2898 | |
| 2899 | if (const auto *Entry = |
| 2900 | CostTableLookup(AVX512InterleavedStoreTbl, Factor, VT)) |
| 2901 | return NumOfMemOps * MemOpCost + Entry->Cost; |
| 2902 | //If an entry does not exist, fallback to the default implementation. |
| Elena Demikhovsky | 21706cb | 2017-01-02 10:37:52 +0000 | [diff] [blame] | 2903 | |
| 2904 | // There is no strided stores meanwhile. And store can't be folded in |
| 2905 | // shuffle. |
| 2906 | unsigned NumOfSources = Factor; // The number of values to be merged. |
| 2907 | unsigned ShuffleCost = |
| 2908 | getShuffleCost(TTI::SK_PermuteTwoSrc, SingleMemOpTy, 0, nullptr); |
| 2909 | unsigned NumOfShufflesPerStore = NumOfSources - 1; |
| 2910 | |
| 2911 | // The SK_MergeTwoSrc shuffle clobbers one of src operands. |
| 2912 | // We need additional instructions to keep sources. |
| 2913 | unsigned NumOfMoves = NumOfMemOps * NumOfShufflesPerStore / 2; |
| 2914 | int Cost = NumOfMemOps * (MemOpCost + NumOfShufflesPerStore * ShuffleCost) + |
| 2915 | NumOfMoves; |
| 2916 | return Cost; |
| 2917 | } |
| 2918 | |
| 2919 | int X86TTIImpl::getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, |
| 2920 | unsigned Factor, |
| 2921 | ArrayRef<unsigned> Indices, |
| 2922 | unsigned Alignment, |
| 2923 | unsigned AddressSpace) { |
| Craig Topper | 8b0f185 | 2017-12-06 18:40:46 +0000 | [diff] [blame] | 2924 | auto isSupportedOnAVX512 = [](Type *VecTy, bool HasBW) { |
| Elena Demikhovsky | 21706cb | 2017-01-02 10:37:52 +0000 | [diff] [blame] | 2925 | Type *EltTy = VecTy->getVectorElementType(); |
| 2926 | if (EltTy->isFloatTy() || EltTy->isDoubleTy() || EltTy->isIntegerTy(64) || |
| 2927 | EltTy->isIntegerTy(32) || EltTy->isPointerTy()) |
| 2928 | return true; |
| Craig Topper | 8b0f185 | 2017-12-06 18:40:46 +0000 | [diff] [blame] | 2929 | if (EltTy->isIntegerTy(16) || EltTy->isIntegerTy(8)) |
| 2930 | return HasBW; |
| Elena Demikhovsky | 21706cb | 2017-01-02 10:37:52 +0000 | [diff] [blame] | 2931 | return false; |
| 2932 | }; |
| Craig Topper | 8b0f185 | 2017-12-06 18:40:46 +0000 | [diff] [blame] | 2933 | if (ST->hasAVX512() && isSupportedOnAVX512(VecTy, ST->hasBWI())) |
| Elena Demikhovsky | 21706cb | 2017-01-02 10:37:52 +0000 | [diff] [blame] | 2934 | return getInterleavedMemoryOpCostAVX512(Opcode, VecTy, Factor, Indices, |
| 2935 | Alignment, AddressSpace); |
| Dorit Nuzman | e0e0f1d | 2017-06-25 08:26:25 +0000 | [diff] [blame] | 2936 | if (ST->hasAVX2()) |
| 2937 | return getInterleavedMemoryOpCostAVX2(Opcode, VecTy, Factor, Indices, |
| 2938 | Alignment, AddressSpace); |
| Simon Pilgrim | 7b89ab5 | 2017-07-31 17:09:27 +0000 | [diff] [blame] | 2939 | |
| Elena Demikhovsky | 21706cb | 2017-01-02 10:37:52 +0000 | [diff] [blame] | 2940 | return BaseT::getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices, |
| 2941 | Alignment, AddressSpace); |
| 2942 | } |