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