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