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