1 //===-- AArch64TargetTransformInfo.cpp - AArch64 specific TTI -------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "AArch64ExpandImm.h" 10 #include "AArch64TargetTransformInfo.h" 11 #include "MCTargetDesc/AArch64AddressingModes.h" 12 #include "llvm/Analysis/LoopInfo.h" 13 #include "llvm/Analysis/TargetTransformInfo.h" 14 #include "llvm/CodeGen/BasicTTIImpl.h" 15 #include "llvm/CodeGen/CostTable.h" 16 #include "llvm/CodeGen/TargetLowering.h" 17 #include "llvm/IR/IntrinsicInst.h" 18 #include "llvm/Support/Debug.h" 19 #include <algorithm> 20 using namespace llvm; 21 22 #define DEBUG_TYPE "aarch64tti" 23 24 static cl::opt<bool> EnableFalkorHWPFUnrollFix("enable-falkor-hwpf-unroll-fix", 25 cl::init(true), cl::Hidden); 26 27 bool AArch64TTIImpl::areInlineCompatible(const Function *Caller, 28 const Function *Callee) const { 29 const TargetMachine &TM = getTLI()->getTargetMachine(); 30 31 const FeatureBitset &CallerBits = 32 TM.getSubtargetImpl(*Caller)->getFeatureBits(); 33 const FeatureBitset &CalleeBits = 34 TM.getSubtargetImpl(*Callee)->getFeatureBits(); 35 36 // Inline a callee if its target-features are a subset of the callers 37 // target-features. 38 return (CallerBits & CalleeBits) == CalleeBits; 39 } 40 41 /// Calculate the cost of materializing a 64-bit value. This helper 42 /// method might only calculate a fraction of a larger immediate. Therefore it 43 /// is valid to return a cost of ZERO. 44 int AArch64TTIImpl::getIntImmCost(int64_t Val) { 45 // Check if the immediate can be encoded within an instruction. 46 if (Val == 0 || AArch64_AM::isLogicalImmediate(Val, 64)) 47 return 0; 48 49 if (Val < 0) 50 Val = ~Val; 51 52 // Calculate how many moves we will need to materialize this constant. 53 SmallVector<AArch64_IMM::ImmInsnModel, 4> Insn; 54 AArch64_IMM::expandMOVImm(Val, 64, Insn); 55 return Insn.size(); 56 } 57 58 /// Calculate the cost of materializing the given constant. 59 int AArch64TTIImpl::getIntImmCost(const APInt &Imm, Type *Ty) { 60 assert(Ty->isIntegerTy()); 61 62 unsigned BitSize = Ty->getPrimitiveSizeInBits(); 63 if (BitSize == 0) 64 return ~0U; 65 66 // Sign-extend all constants to a multiple of 64-bit. 67 APInt ImmVal = Imm; 68 if (BitSize & 0x3f) 69 ImmVal = Imm.sext((BitSize + 63) & ~0x3fU); 70 71 // Split the constant into 64-bit chunks and calculate the cost for each 72 // chunk. 73 int Cost = 0; 74 for (unsigned ShiftVal = 0; ShiftVal < BitSize; ShiftVal += 64) { 75 APInt Tmp = ImmVal.ashr(ShiftVal).sextOrTrunc(64); 76 int64_t Val = Tmp.getSExtValue(); 77 Cost += getIntImmCost(Val); 78 } 79 // We need at least one instruction to materialze the constant. 80 return std::max(1, Cost); 81 } 82 83 int AArch64TTIImpl::getIntImmCost(unsigned Opcode, unsigned Idx, 84 const APInt &Imm, Type *Ty) { 85 assert(Ty->isIntegerTy()); 86 87 unsigned BitSize = Ty->getPrimitiveSizeInBits(); 88 // There is no cost model for constants with a bit size of 0. Return TCC_Free 89 // here, so that constant hoisting will ignore this constant. 90 if (BitSize == 0) 91 return TTI::TCC_Free; 92 93 unsigned ImmIdx = ~0U; 94 switch (Opcode) { 95 default: 96 return TTI::TCC_Free; 97 case Instruction::GetElementPtr: 98 // Always hoist the base address of a GetElementPtr. 99 if (Idx == 0) 100 return 2 * TTI::TCC_Basic; 101 return TTI::TCC_Free; 102 case Instruction::Store: 103 ImmIdx = 0; 104 break; 105 case Instruction::Add: 106 case Instruction::Sub: 107 case Instruction::Mul: 108 case Instruction::UDiv: 109 case Instruction::SDiv: 110 case Instruction::URem: 111 case Instruction::SRem: 112 case Instruction::And: 113 case Instruction::Or: 114 case Instruction::Xor: 115 case Instruction::ICmp: 116 ImmIdx = 1; 117 break; 118 // Always return TCC_Free for the shift value of a shift instruction. 119 case Instruction::Shl: 120 case Instruction::LShr: 121 case Instruction::AShr: 122 if (Idx == 1) 123 return TTI::TCC_Free; 124 break; 125 case Instruction::Trunc: 126 case Instruction::ZExt: 127 case Instruction::SExt: 128 case Instruction::IntToPtr: 129 case Instruction::PtrToInt: 130 case Instruction::BitCast: 131 case Instruction::PHI: 132 case Instruction::Call: 133 case Instruction::Select: 134 case Instruction::Ret: 135 case Instruction::Load: 136 break; 137 } 138 139 if (Idx == ImmIdx) { 140 int NumConstants = (BitSize + 63) / 64; 141 int Cost = AArch64TTIImpl::getIntImmCost(Imm, Ty); 142 return (Cost <= NumConstants * TTI::TCC_Basic) 143 ? static_cast<int>(TTI::TCC_Free) 144 : Cost; 145 } 146 return AArch64TTIImpl::getIntImmCost(Imm, Ty); 147 } 148 149 int AArch64TTIImpl::getIntImmCost(Intrinsic::ID IID, unsigned Idx, 150 const APInt &Imm, Type *Ty) { 151 assert(Ty->isIntegerTy()); 152 153 unsigned BitSize = Ty->getPrimitiveSizeInBits(); 154 // There is no cost model for constants with a bit size of 0. Return TCC_Free 155 // here, so that constant hoisting will ignore this constant. 156 if (BitSize == 0) 157 return TTI::TCC_Free; 158 159 // Most (all?) AArch64 intrinsics do not support folding immediates into the 160 // selected instruction, so we compute the materialization cost for the 161 // immediate directly. 162 if (IID >= Intrinsic::aarch64_addg && IID <= Intrinsic::aarch64_udiv) 163 return AArch64TTIImpl::getIntImmCost(Imm, Ty); 164 165 switch (IID) { 166 default: 167 return TTI::TCC_Free; 168 case Intrinsic::sadd_with_overflow: 169 case Intrinsic::uadd_with_overflow: 170 case Intrinsic::ssub_with_overflow: 171 case Intrinsic::usub_with_overflow: 172 case Intrinsic::smul_with_overflow: 173 case Intrinsic::umul_with_overflow: 174 if (Idx == 1) { 175 int NumConstants = (BitSize + 63) / 64; 176 int Cost = AArch64TTIImpl::getIntImmCost(Imm, Ty); 177 return (Cost <= NumConstants * TTI::TCC_Basic) 178 ? static_cast<int>(TTI::TCC_Free) 179 : Cost; 180 } 181 break; 182 case Intrinsic::experimental_stackmap: 183 if ((Idx < 2) || (Imm.getBitWidth() <= 64 && isInt<64>(Imm.getSExtValue()))) 184 return TTI::TCC_Free; 185 break; 186 case Intrinsic::experimental_patchpoint_void: 187 case Intrinsic::experimental_patchpoint_i64: 188 if ((Idx < 4) || (Imm.getBitWidth() <= 64 && isInt<64>(Imm.getSExtValue()))) 189 return TTI::TCC_Free; 190 break; 191 } 192 return AArch64TTIImpl::getIntImmCost(Imm, Ty); 193 } 194 195 TargetTransformInfo::PopcntSupportKind 196 AArch64TTIImpl::getPopcntSupport(unsigned TyWidth) { 197 assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2"); 198 if (TyWidth == 32 || TyWidth == 64) 199 return TTI::PSK_FastHardware; 200 // TODO: AArch64TargetLowering::LowerCTPOP() supports 128bit popcount. 201 return TTI::PSK_Software; 202 } 203 204 bool AArch64TTIImpl::isWideningInstruction(Type *DstTy, unsigned Opcode, 205 ArrayRef<const Value *> Args) { 206 207 // A helper that returns a vector type from the given type. The number of 208 // elements in type Ty determine the vector width. 209 auto toVectorTy = [&](Type *ArgTy) { 210 return VectorType::get(ArgTy->getScalarType(), 211 DstTy->getVectorNumElements()); 212 }; 213 214 // Exit early if DstTy is not a vector type whose elements are at least 215 // 16-bits wide. 216 if (!DstTy->isVectorTy() || DstTy->getScalarSizeInBits() < 16) 217 return false; 218 219 // Determine if the operation has a widening variant. We consider both the 220 // "long" (e.g., usubl) and "wide" (e.g., usubw) versions of the 221 // instructions. 222 // 223 // TODO: Add additional widening operations (e.g., mul, shl, etc.) once we 224 // verify that their extending operands are eliminated during code 225 // generation. 226 switch (Opcode) { 227 case Instruction::Add: // UADDL(2), SADDL(2), UADDW(2), SADDW(2). 228 case Instruction::Sub: // USUBL(2), SSUBL(2), USUBW(2), SSUBW(2). 229 break; 230 default: 231 return false; 232 } 233 234 // To be a widening instruction (either the "wide" or "long" versions), the 235 // second operand must be a sign- or zero extend having a single user. We 236 // only consider extends having a single user because they may otherwise not 237 // be eliminated. 238 if (Args.size() != 2 || 239 (!isa<SExtInst>(Args[1]) && !isa<ZExtInst>(Args[1])) || 240 !Args[1]->hasOneUse()) 241 return false; 242 auto *Extend = cast<CastInst>(Args[1]); 243 244 // Legalize the destination type and ensure it can be used in a widening 245 // operation. 246 auto DstTyL = TLI->getTypeLegalizationCost(DL, DstTy); 247 unsigned DstElTySize = DstTyL.second.getScalarSizeInBits(); 248 if (!DstTyL.second.isVector() || DstElTySize != DstTy->getScalarSizeInBits()) 249 return false; 250 251 // Legalize the source type and ensure it can be used in a widening 252 // operation. 253 Type *SrcTy = toVectorTy(Extend->getSrcTy()); 254 auto SrcTyL = TLI->getTypeLegalizationCost(DL, SrcTy); 255 unsigned SrcElTySize = SrcTyL.second.getScalarSizeInBits(); 256 if (!SrcTyL.second.isVector() || SrcElTySize != SrcTy->getScalarSizeInBits()) 257 return false; 258 259 // Get the total number of vector elements in the legalized types. 260 unsigned NumDstEls = DstTyL.first * DstTyL.second.getVectorNumElements(); 261 unsigned NumSrcEls = SrcTyL.first * SrcTyL.second.getVectorNumElements(); 262 263 // Return true if the legalized types have the same number of vector elements 264 // and the destination element type size is twice that of the source type. 265 return NumDstEls == NumSrcEls && 2 * SrcElTySize == DstElTySize; 266 } 267 268 int AArch64TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, 269 const Instruction *I) { 270 int ISD = TLI->InstructionOpcodeToISD(Opcode); 271 assert(ISD && "Invalid opcode"); 272 273 // If the cast is observable, and it is used by a widening instruction (e.g., 274 // uaddl, saddw, etc.), it may be free. 275 if (I && I->hasOneUse()) { 276 auto *SingleUser = cast<Instruction>(*I->user_begin()); 277 SmallVector<const Value *, 4> Operands(SingleUser->operand_values()); 278 if (isWideningInstruction(Dst, SingleUser->getOpcode(), Operands)) { 279 // If the cast is the second operand, it is free. We will generate either 280 // a "wide" or "long" version of the widening instruction. 281 if (I == SingleUser->getOperand(1)) 282 return 0; 283 // If the cast is not the second operand, it will be free if it looks the 284 // same as the second operand. In this case, we will generate a "long" 285 // version of the widening instruction. 286 if (auto *Cast = dyn_cast<CastInst>(SingleUser->getOperand(1))) 287 if (I->getOpcode() == unsigned(Cast->getOpcode()) && 288 cast<CastInst>(I)->getSrcTy() == Cast->getSrcTy()) 289 return 0; 290 } 291 } 292 293 EVT SrcTy = TLI->getValueType(DL, Src); 294 EVT DstTy = TLI->getValueType(DL, Dst); 295 296 if (!SrcTy.isSimple() || !DstTy.isSimple()) 297 return BaseT::getCastInstrCost(Opcode, Dst, Src); 298 299 static const TypeConversionCostTblEntry 300 ConversionTbl[] = { 301 { ISD::TRUNCATE, MVT::v4i16, MVT::v4i32, 1 }, 302 { ISD::TRUNCATE, MVT::v4i32, MVT::v4i64, 0 }, 303 { ISD::TRUNCATE, MVT::v8i8, MVT::v8i32, 3 }, 304 { ISD::TRUNCATE, MVT::v16i8, MVT::v16i32, 6 }, 305 306 // The number of shll instructions for the extension. 307 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i16, 3 }, 308 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i16, 3 }, 309 { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, 2 }, 310 { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, 2 }, 311 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i8, 3 }, 312 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i8, 3 }, 313 { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, 2 }, 314 { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, 2 }, 315 { ISD::SIGN_EXTEND, MVT::v8i64, MVT::v8i8, 7 }, 316 { ISD::ZERO_EXTEND, MVT::v8i64, MVT::v8i8, 7 }, 317 { ISD::SIGN_EXTEND, MVT::v8i64, MVT::v8i16, 6 }, 318 { ISD::ZERO_EXTEND, MVT::v8i64, MVT::v8i16, 6 }, 319 { ISD::SIGN_EXTEND, MVT::v16i16, MVT::v16i8, 2 }, 320 { ISD::ZERO_EXTEND, MVT::v16i16, MVT::v16i8, 2 }, 321 { ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i8, 6 }, 322 { ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i8, 6 }, 323 324 // LowerVectorINT_TO_FP: 325 { ISD::SINT_TO_FP, MVT::v2f32, MVT::v2i32, 1 }, 326 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i32, 1 }, 327 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v2i64, 1 }, 328 { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i32, 1 }, 329 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, 1 }, 330 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i64, 1 }, 331 332 // Complex: to v2f32 333 { ISD::SINT_TO_FP, MVT::v2f32, MVT::v2i8, 3 }, 334 { ISD::SINT_TO_FP, MVT::v2f32, MVT::v2i16, 3 }, 335 { ISD::SINT_TO_FP, MVT::v2f32, MVT::v2i64, 2 }, 336 { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i8, 3 }, 337 { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i16, 3 }, 338 { ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i64, 2 }, 339 340 // Complex: to v4f32 341 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i8, 4 }, 342 { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i16, 2 }, 343 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i8, 3 }, 344 { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i16, 2 }, 345 346 // Complex: to v8f32 347 { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i8, 10 }, 348 { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i16, 4 }, 349 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i8, 10 }, 350 { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i16, 4 }, 351 352 // Complex: to v16f32 353 { ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i8, 21 }, 354 { ISD::UINT_TO_FP, MVT::v16f32, MVT::v16i8, 21 }, 355 356 // Complex: to v2f64 357 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v2i8, 4 }, 358 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v2i16, 4 }, 359 { ISD::SINT_TO_FP, MVT::v2f64, MVT::v2i32, 2 }, 360 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i8, 4 }, 361 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i16, 4 }, 362 { ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i32, 2 }, 363 364 365 // LowerVectorFP_TO_INT 366 { ISD::FP_TO_SINT, MVT::v2i32, MVT::v2f32, 1 }, 367 { ISD::FP_TO_SINT, MVT::v4i32, MVT::v4f32, 1 }, 368 { ISD::FP_TO_SINT, MVT::v2i64, MVT::v2f64, 1 }, 369 { ISD::FP_TO_UINT, MVT::v2i32, MVT::v2f32, 1 }, 370 { ISD::FP_TO_UINT, MVT::v4i32, MVT::v4f32, 1 }, 371 { ISD::FP_TO_UINT, MVT::v2i64, MVT::v2f64, 1 }, 372 373 // Complex, from v2f32: legal type is v2i32 (no cost) or v2i64 (1 ext). 374 { ISD::FP_TO_SINT, MVT::v2i64, MVT::v2f32, 2 }, 375 { ISD::FP_TO_SINT, MVT::v2i16, MVT::v2f32, 1 }, 376 { ISD::FP_TO_SINT, MVT::v2i8, MVT::v2f32, 1 }, 377 { ISD::FP_TO_UINT, MVT::v2i64, MVT::v2f32, 2 }, 378 { ISD::FP_TO_UINT, MVT::v2i16, MVT::v2f32, 1 }, 379 { ISD::FP_TO_UINT, MVT::v2i8, MVT::v2f32, 1 }, 380 381 // Complex, from v4f32: legal type is v4i16, 1 narrowing => ~2 382 { ISD::FP_TO_SINT, MVT::v4i16, MVT::v4f32, 2 }, 383 { ISD::FP_TO_SINT, MVT::v4i8, MVT::v4f32, 2 }, 384 { ISD::FP_TO_UINT, MVT::v4i16, MVT::v4f32, 2 }, 385 { ISD::FP_TO_UINT, MVT::v4i8, MVT::v4f32, 2 }, 386 387 // Complex, from v2f64: legal type is v2i32, 1 narrowing => ~2. 388 { ISD::FP_TO_SINT, MVT::v2i32, MVT::v2f64, 2 }, 389 { ISD::FP_TO_SINT, MVT::v2i16, MVT::v2f64, 2 }, 390 { ISD::FP_TO_SINT, MVT::v2i8, MVT::v2f64, 2 }, 391 { ISD::FP_TO_UINT, MVT::v2i32, MVT::v2f64, 2 }, 392 { ISD::FP_TO_UINT, MVT::v2i16, MVT::v2f64, 2 }, 393 { ISD::FP_TO_UINT, MVT::v2i8, MVT::v2f64, 2 }, 394 }; 395 396 if (const auto *Entry = ConvertCostTableLookup(ConversionTbl, ISD, 397 DstTy.getSimpleVT(), 398 SrcTy.getSimpleVT())) 399 return Entry->Cost; 400 401 return BaseT::getCastInstrCost(Opcode, Dst, Src); 402 } 403 404 int AArch64TTIImpl::getExtractWithExtendCost(unsigned Opcode, Type *Dst, 405 VectorType *VecTy, 406 unsigned Index) { 407 408 // Make sure we were given a valid extend opcode. 409 assert((Opcode == Instruction::SExt || Opcode == Instruction::ZExt) && 410 "Invalid opcode"); 411 412 // We are extending an element we extract from a vector, so the source type 413 // of the extend is the element type of the vector. 414 auto *Src = VecTy->getElementType(); 415 416 // Sign- and zero-extends are for integer types only. 417 assert(isa<IntegerType>(Dst) && isa<IntegerType>(Src) && "Invalid type"); 418 419 // Get the cost for the extract. We compute the cost (if any) for the extend 420 // below. 421 auto Cost = getVectorInstrCost(Instruction::ExtractElement, VecTy, Index); 422 423 // Legalize the types. 424 auto VecLT = TLI->getTypeLegalizationCost(DL, VecTy); 425 auto DstVT = TLI->getValueType(DL, Dst); 426 auto SrcVT = TLI->getValueType(DL, Src); 427 428 // If the resulting type is still a vector and the destination type is legal, 429 // we may get the extension for free. If not, get the default cost for the 430 // extend. 431 if (!VecLT.second.isVector() || !TLI->isTypeLegal(DstVT)) 432 return Cost + getCastInstrCost(Opcode, Dst, Src); 433 434 // The destination type should be larger than the element type. If not, get 435 // the default cost for the extend. 436 if (DstVT.getSizeInBits() < SrcVT.getSizeInBits()) 437 return Cost + getCastInstrCost(Opcode, Dst, Src); 438 439 switch (Opcode) { 440 default: 441 llvm_unreachable("Opcode should be either SExt or ZExt"); 442 443 // For sign-extends, we only need a smov, which performs the extension 444 // automatically. 445 case Instruction::SExt: 446 return Cost; 447 448 // For zero-extends, the extend is performed automatically by a umov unless 449 // the destination type is i64 and the element type is i8 or i16. 450 case Instruction::ZExt: 451 if (DstVT.getSizeInBits() != 64u || SrcVT.getSizeInBits() == 32u) 452 return Cost; 453 } 454 455 // If we are unable to perform the extend for free, get the default cost. 456 return Cost + getCastInstrCost(Opcode, Dst, Src); 457 } 458 459 int AArch64TTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val, 460 unsigned Index) { 461 assert(Val->isVectorTy() && "This must be a vector type"); 462 463 if (Index != -1U) { 464 // Legalize the type. 465 std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Val); 466 467 // This type is legalized to a scalar type. 468 if (!LT.second.isVector()) 469 return 0; 470 471 // The type may be split. Normalize the index to the new type. 472 unsigned Width = LT.second.getVectorNumElements(); 473 Index = Index % Width; 474 475 // The element at index zero is already inside the vector. 476 if (Index == 0) 477 return 0; 478 } 479 480 // All other insert/extracts cost this much. 481 return ST->getVectorInsertExtractBaseCost(); 482 } 483 484 int AArch64TTIImpl::getArithmeticInstrCost( 485 unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info, 486 TTI::OperandValueKind Opd2Info, TTI::OperandValueProperties Opd1PropInfo, 487 TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args) { 488 // Legalize the type. 489 std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Ty); 490 491 // If the instruction is a widening instruction (e.g., uaddl, saddw, etc.), 492 // add in the widening overhead specified by the sub-target. Since the 493 // extends feeding widening instructions are performed automatically, they 494 // aren't present in the generated code and have a zero cost. By adding a 495 // widening overhead here, we attach the total cost of the combined operation 496 // to the widening instruction. 497 int Cost = 0; 498 if (isWideningInstruction(Ty, Opcode, Args)) 499 Cost += ST->getWideningBaseCost(); 500 501 int ISD = TLI->InstructionOpcodeToISD(Opcode); 502 503 switch (ISD) { 504 default: 505 return Cost + BaseT::getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info, 506 Opd1PropInfo, Opd2PropInfo); 507 case ISD::SDIV: 508 if (Opd2Info == TargetTransformInfo::OK_UniformConstantValue && 509 Opd2PropInfo == TargetTransformInfo::OP_PowerOf2) { 510 // On AArch64, scalar signed division by constants power-of-two are 511 // normally expanded to the sequence ADD + CMP + SELECT + SRA. 512 // The OperandValue properties many not be same as that of previous 513 // operation; conservatively assume OP_None. 514 Cost += getArithmeticInstrCost(Instruction::Add, Ty, Opd1Info, Opd2Info, 515 TargetTransformInfo::OP_None, 516 TargetTransformInfo::OP_None); 517 Cost += getArithmeticInstrCost(Instruction::Sub, Ty, Opd1Info, Opd2Info, 518 TargetTransformInfo::OP_None, 519 TargetTransformInfo::OP_None); 520 Cost += getArithmeticInstrCost(Instruction::Select, Ty, Opd1Info, Opd2Info, 521 TargetTransformInfo::OP_None, 522 TargetTransformInfo::OP_None); 523 Cost += getArithmeticInstrCost(Instruction::AShr, Ty, Opd1Info, Opd2Info, 524 TargetTransformInfo::OP_None, 525 TargetTransformInfo::OP_None); 526 return Cost; 527 } 528 LLVM_FALLTHROUGH; 529 case ISD::UDIV: 530 if (Opd2Info == TargetTransformInfo::OK_UniformConstantValue) { 531 auto VT = TLI->getValueType(DL, Ty); 532 if (TLI->isOperationLegalOrCustom(ISD::MULHU, VT)) { 533 // Vector signed division by constant are expanded to the 534 // sequence MULHS + ADD/SUB + SRA + SRL + ADD, and unsigned division 535 // to MULHS + SUB + SRL + ADD + SRL. 536 int MulCost = getArithmeticInstrCost(Instruction::Mul, Ty, Opd1Info, 537 Opd2Info, 538 TargetTransformInfo::OP_None, 539 TargetTransformInfo::OP_None); 540 int AddCost = getArithmeticInstrCost(Instruction::Add, Ty, Opd1Info, 541 Opd2Info, 542 TargetTransformInfo::OP_None, 543 TargetTransformInfo::OP_None); 544 int ShrCost = getArithmeticInstrCost(Instruction::AShr, Ty, Opd1Info, 545 Opd2Info, 546 TargetTransformInfo::OP_None, 547 TargetTransformInfo::OP_None); 548 return MulCost * 2 + AddCost * 2 + ShrCost * 2 + 1; 549 } 550 } 551 552 Cost += BaseT::getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info, 553 Opd1PropInfo, Opd2PropInfo); 554 if (Ty->isVectorTy()) { 555 // On AArch64, vector divisions are not supported natively and are 556 // expanded into scalar divisions of each pair of elements. 557 Cost += getArithmeticInstrCost(Instruction::ExtractElement, Ty, Opd1Info, 558 Opd2Info, Opd1PropInfo, Opd2PropInfo); 559 Cost += getArithmeticInstrCost(Instruction::InsertElement, Ty, Opd1Info, 560 Opd2Info, Opd1PropInfo, Opd2PropInfo); 561 // TODO: if one of the arguments is scalar, then it's not necessary to 562 // double the cost of handling the vector elements. 563 Cost += Cost; 564 } 565 return Cost; 566 567 case ISD::ADD: 568 case ISD::MUL: 569 case ISD::XOR: 570 case ISD::OR: 571 case ISD::AND: 572 // These nodes are marked as 'custom' for combining purposes only. 573 // We know that they are legal. See LowerAdd in ISelLowering. 574 return (Cost + 1) * LT.first; 575 } 576 } 577 578 int AArch64TTIImpl::getAddressComputationCost(Type *Ty, ScalarEvolution *SE, 579 const SCEV *Ptr) { 580 // Address computations in vectorized code with non-consecutive addresses will 581 // likely result in more instructions compared to scalar code where the 582 // computation can more often be merged into the index mode. The resulting 583 // extra micro-ops can significantly decrease throughput. 584 unsigned NumVectorInstToHideOverhead = 10; 585 int MaxMergeDistance = 64; 586 587 if (Ty->isVectorTy() && SE && 588 !BaseT::isConstantStridedAccessLessThan(SE, Ptr, MaxMergeDistance + 1)) 589 return NumVectorInstToHideOverhead; 590 591 // In many cases the address computation is not merged into the instruction 592 // addressing mode. 593 return 1; 594 } 595 596 int AArch64TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, 597 Type *CondTy, const Instruction *I) { 598 599 int ISD = TLI->InstructionOpcodeToISD(Opcode); 600 // We don't lower some vector selects well that are wider than the register 601 // width. 602 if (ValTy->isVectorTy() && ISD == ISD::SELECT) { 603 // We would need this many instructions to hide the scalarization happening. 604 const int AmortizationCost = 20; 605 static const TypeConversionCostTblEntry 606 VectorSelectTbl[] = { 607 { ISD::SELECT, MVT::v16i1, MVT::v16i16, 16 }, 608 { ISD::SELECT, MVT::v8i1, MVT::v8i32, 8 }, 609 { ISD::SELECT, MVT::v16i1, MVT::v16i32, 16 }, 610 { ISD::SELECT, MVT::v4i1, MVT::v4i64, 4 * AmortizationCost }, 611 { ISD::SELECT, MVT::v8i1, MVT::v8i64, 8 * AmortizationCost }, 612 { ISD::SELECT, MVT::v16i1, MVT::v16i64, 16 * AmortizationCost } 613 }; 614 615 EVT SelCondTy = TLI->getValueType(DL, CondTy); 616 EVT SelValTy = TLI->getValueType(DL, ValTy); 617 if (SelCondTy.isSimple() && SelValTy.isSimple()) { 618 if (const auto *Entry = ConvertCostTableLookup(VectorSelectTbl, ISD, 619 SelCondTy.getSimpleVT(), 620 SelValTy.getSimpleVT())) 621 return Entry->Cost; 622 } 623 } 624 return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, I); 625 } 626 627 AArch64TTIImpl::TTI::MemCmpExpansionOptions 628 AArch64TTIImpl::enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const { 629 TTI::MemCmpExpansionOptions Options; 630 Options.AllowOverlappingLoads = !ST->requiresStrictAlign(); 631 Options.MaxNumLoads = TLI->getMaxExpandSizeMemcmp(OptSize); 632 Options.NumLoadsPerBlock = Options.MaxNumLoads; 633 // TODO: Though vector loads usually perform well on AArch64, in some targets 634 // they may wake up the FP unit, which raises the power consumption. Perhaps 635 // they could be used with no holds barred (-O3). 636 Options.LoadSizes = {8, 4, 2, 1}; 637 return Options; 638 } 639 640 int AArch64TTIImpl::getMemoryOpCost(unsigned Opcode, Type *Ty, 641 MaybeAlign Alignment, unsigned AddressSpace, 642 const Instruction *I) { 643 auto LT = TLI->getTypeLegalizationCost(DL, Ty); 644 645 if (ST->isMisaligned128StoreSlow() && Opcode == Instruction::Store && 646 LT.second.is128BitVector() && (!Alignment || *Alignment < Align(16))) { 647 // Unaligned stores are extremely inefficient. We don't split all 648 // unaligned 128-bit stores because the negative impact that has shown in 649 // practice on inlined block copy code. 650 // We make such stores expensive so that we will only vectorize if there 651 // are 6 other instructions getting vectorized. 652 const int AmortizationCost = 6; 653 654 return LT.first * 2 * AmortizationCost; 655 } 656 657 if (Ty->isVectorTy() && Ty->getVectorElementType()->isIntegerTy(8)) { 658 unsigned ProfitableNumElements; 659 if (Opcode == Instruction::Store) 660 // We use a custom trunc store lowering so v.4b should be profitable. 661 ProfitableNumElements = 4; 662 else 663 // We scalarize the loads because there is not v.4b register and we 664 // have to promote the elements to v.2. 665 ProfitableNumElements = 8; 666 667 if (Ty->getVectorNumElements() < ProfitableNumElements) { 668 unsigned NumVecElts = Ty->getVectorNumElements(); 669 unsigned NumVectorizableInstsToAmortize = NumVecElts * 2; 670 // We generate 2 instructions per vector element. 671 return NumVectorizableInstsToAmortize * NumVecElts * 2; 672 } 673 } 674 675 return LT.first; 676 } 677 678 int AArch64TTIImpl::getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, 679 unsigned Factor, 680 ArrayRef<unsigned> Indices, 681 unsigned Alignment, 682 unsigned AddressSpace, 683 bool UseMaskForCond, 684 bool UseMaskForGaps) { 685 assert(Factor >= 2 && "Invalid interleave factor"); 686 assert(isa<VectorType>(VecTy) && "Expect a vector type"); 687 688 if (!UseMaskForCond && !UseMaskForGaps && 689 Factor <= TLI->getMaxSupportedInterleaveFactor()) { 690 unsigned NumElts = VecTy->getVectorNumElements(); 691 auto *SubVecTy = VectorType::get(VecTy->getScalarType(), NumElts / Factor); 692 693 // ldN/stN only support legal vector types of size 64 or 128 in bits. 694 // Accesses having vector types that are a multiple of 128 bits can be 695 // matched to more than one ldN/stN instruction. 696 if (NumElts % Factor == 0 && 697 TLI->isLegalInterleavedAccessType(SubVecTy, DL)) 698 return Factor * TLI->getNumInterleavedAccesses(SubVecTy, DL); 699 } 700 701 return BaseT::getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices, 702 Alignment, AddressSpace, 703 UseMaskForCond, UseMaskForGaps); 704 } 705 706 int AArch64TTIImpl::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) { 707 int Cost = 0; 708 for (auto *I : Tys) { 709 if (!I->isVectorTy()) 710 continue; 711 if (I->getScalarSizeInBits() * I->getVectorNumElements() == 128) 712 Cost += getMemoryOpCost(Instruction::Store, I, Align(128), 0) + 713 getMemoryOpCost(Instruction::Load, I, Align(128), 0); 714 } 715 return Cost; 716 } 717 718 unsigned AArch64TTIImpl::getMaxInterleaveFactor(unsigned VF) { 719 return ST->getMaxInterleaveFactor(); 720 } 721 722 // For Falkor, we want to avoid having too many strided loads in a loop since 723 // that can exhaust the HW prefetcher resources. We adjust the unroller 724 // MaxCount preference below to attempt to ensure unrolling doesn't create too 725 // many strided loads. 726 static void 727 getFalkorUnrollingPreferences(Loop *L, ScalarEvolution &SE, 728 TargetTransformInfo::UnrollingPreferences &UP) { 729 enum { MaxStridedLoads = 7 }; 730 auto countStridedLoads = [](Loop *L, ScalarEvolution &SE) { 731 int StridedLoads = 0; 732 // FIXME? We could make this more precise by looking at the CFG and 733 // e.g. not counting loads in each side of an if-then-else diamond. 734 for (const auto BB : L->blocks()) { 735 for (auto &I : *BB) { 736 LoadInst *LMemI = dyn_cast<LoadInst>(&I); 737 if (!LMemI) 738 continue; 739 740 Value *PtrValue = LMemI->getPointerOperand(); 741 if (L->isLoopInvariant(PtrValue)) 742 continue; 743 744 const SCEV *LSCEV = SE.getSCEV(PtrValue); 745 const SCEVAddRecExpr *LSCEVAddRec = dyn_cast<SCEVAddRecExpr>(LSCEV); 746 if (!LSCEVAddRec || !LSCEVAddRec->isAffine()) 747 continue; 748 749 // FIXME? We could take pairing of unrolled load copies into account 750 // by looking at the AddRec, but we would probably have to limit this 751 // to loops with no stores or other memory optimization barriers. 752 ++StridedLoads; 753 // We've seen enough strided loads that seeing more won't make a 754 // difference. 755 if (StridedLoads > MaxStridedLoads / 2) 756 return StridedLoads; 757 } 758 } 759 return StridedLoads; 760 }; 761 762 int StridedLoads = countStridedLoads(L, SE); 763 LLVM_DEBUG(dbgs() << "falkor-hwpf: detected " << StridedLoads 764 << " strided loads\n"); 765 // Pick the largest power of 2 unroll count that won't result in too many 766 // strided loads. 767 if (StridedLoads) { 768 UP.MaxCount = 1 << Log2_32(MaxStridedLoads / StridedLoads); 769 LLVM_DEBUG(dbgs() << "falkor-hwpf: setting unroll MaxCount to " 770 << UP.MaxCount << '\n'); 771 } 772 } 773 774 void AArch64TTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE, 775 TTI::UnrollingPreferences &UP) { 776 // Enable partial unrolling and runtime unrolling. 777 BaseT::getUnrollingPreferences(L, SE, UP); 778 779 // For inner loop, it is more likely to be a hot one, and the runtime check 780 // can be promoted out from LICM pass, so the overhead is less, let's try 781 // a larger threshold to unroll more loops. 782 if (L->getLoopDepth() > 1) 783 UP.PartialThreshold *= 2; 784 785 // Disable partial & runtime unrolling on -Os. 786 UP.PartialOptSizeThreshold = 0; 787 788 if (ST->getProcFamily() == AArch64Subtarget::Falkor && 789 EnableFalkorHWPFUnrollFix) 790 getFalkorUnrollingPreferences(L, SE, UP); 791 } 792 793 Value *AArch64TTIImpl::getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst, 794 Type *ExpectedType) { 795 switch (Inst->getIntrinsicID()) { 796 default: 797 return nullptr; 798 case Intrinsic::aarch64_neon_st2: 799 case Intrinsic::aarch64_neon_st3: 800 case Intrinsic::aarch64_neon_st4: { 801 // Create a struct type 802 StructType *ST = dyn_cast<StructType>(ExpectedType); 803 if (!ST) 804 return nullptr; 805 unsigned NumElts = Inst->getNumArgOperands() - 1; 806 if (ST->getNumElements() != NumElts) 807 return nullptr; 808 for (unsigned i = 0, e = NumElts; i != e; ++i) { 809 if (Inst->getArgOperand(i)->getType() != ST->getElementType(i)) 810 return nullptr; 811 } 812 Value *Res = UndefValue::get(ExpectedType); 813 IRBuilder<> Builder(Inst); 814 for (unsigned i = 0, e = NumElts; i != e; ++i) { 815 Value *L = Inst->getArgOperand(i); 816 Res = Builder.CreateInsertValue(Res, L, i); 817 } 818 return Res; 819 } 820 case Intrinsic::aarch64_neon_ld2: 821 case Intrinsic::aarch64_neon_ld3: 822 case Intrinsic::aarch64_neon_ld4: 823 if (Inst->getType() == ExpectedType) 824 return Inst; 825 return nullptr; 826 } 827 } 828 829 bool AArch64TTIImpl::getTgtMemIntrinsic(IntrinsicInst *Inst, 830 MemIntrinsicInfo &Info) { 831 switch (Inst->getIntrinsicID()) { 832 default: 833 break; 834 case Intrinsic::aarch64_neon_ld2: 835 case Intrinsic::aarch64_neon_ld3: 836 case Intrinsic::aarch64_neon_ld4: 837 Info.ReadMem = true; 838 Info.WriteMem = false; 839 Info.PtrVal = Inst->getArgOperand(0); 840 break; 841 case Intrinsic::aarch64_neon_st2: 842 case Intrinsic::aarch64_neon_st3: 843 case Intrinsic::aarch64_neon_st4: 844 Info.ReadMem = false; 845 Info.WriteMem = true; 846 Info.PtrVal = Inst->getArgOperand(Inst->getNumArgOperands() - 1); 847 break; 848 } 849 850 switch (Inst->getIntrinsicID()) { 851 default: 852 return false; 853 case Intrinsic::aarch64_neon_ld2: 854 case Intrinsic::aarch64_neon_st2: 855 Info.MatchingId = VECTOR_LDST_TWO_ELEMENTS; 856 break; 857 case Intrinsic::aarch64_neon_ld3: 858 case Intrinsic::aarch64_neon_st3: 859 Info.MatchingId = VECTOR_LDST_THREE_ELEMENTS; 860 break; 861 case Intrinsic::aarch64_neon_ld4: 862 case Intrinsic::aarch64_neon_st4: 863 Info.MatchingId = VECTOR_LDST_FOUR_ELEMENTS; 864 break; 865 } 866 return true; 867 } 868 869 /// See if \p I should be considered for address type promotion. We check if \p 870 /// I is a sext with right type and used in memory accesses. If it used in a 871 /// "complex" getelementptr, we allow it to be promoted without finding other 872 /// sext instructions that sign extended the same initial value. A getelementptr 873 /// is considered as "complex" if it has more than 2 operands. 874 bool AArch64TTIImpl::shouldConsiderAddressTypePromotion( 875 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) { 876 bool Considerable = false; 877 AllowPromotionWithoutCommonHeader = false; 878 if (!isa<SExtInst>(&I)) 879 return false; 880 Type *ConsideredSExtType = 881 Type::getInt64Ty(I.getParent()->getParent()->getContext()); 882 if (I.getType() != ConsideredSExtType) 883 return false; 884 // See if the sext is the one with the right type and used in at least one 885 // GetElementPtrInst. 886 for (const User *U : I.users()) { 887 if (const GetElementPtrInst *GEPInst = dyn_cast<GetElementPtrInst>(U)) { 888 Considerable = true; 889 // A getelementptr is considered as "complex" if it has more than 2 890 // operands. We will promote a SExt used in such complex GEP as we 891 // expect some computation to be merged if they are done on 64 bits. 892 if (GEPInst->getNumOperands() > 2) { 893 AllowPromotionWithoutCommonHeader = true; 894 break; 895 } 896 } 897 } 898 return Considerable; 899 } 900 901 bool AArch64TTIImpl::useReductionIntrinsic(unsigned Opcode, Type *Ty, 902 TTI::ReductionFlags Flags) const { 903 assert(isa<VectorType>(Ty) && "Expected Ty to be a vector type"); 904 unsigned ScalarBits = Ty->getScalarSizeInBits(); 905 switch (Opcode) { 906 case Instruction::FAdd: 907 case Instruction::FMul: 908 case Instruction::And: 909 case Instruction::Or: 910 case Instruction::Xor: 911 case Instruction::Mul: 912 return false; 913 case Instruction::Add: 914 return ScalarBits * Ty->getVectorNumElements() >= 128; 915 case Instruction::ICmp: 916 return (ScalarBits < 64) && 917 (ScalarBits * Ty->getVectorNumElements() >= 128); 918 case Instruction::FCmp: 919 return Flags.NoNaN; 920 default: 921 llvm_unreachable("Unhandled reduction opcode"); 922 } 923 return false; 924 } 925 926 int AArch64TTIImpl::getArithmeticReductionCost(unsigned Opcode, Type *ValTy, 927 bool IsPairwiseForm) { 928 929 if (IsPairwiseForm) 930 return BaseT::getArithmeticReductionCost(Opcode, ValTy, IsPairwiseForm); 931 932 std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, ValTy); 933 MVT MTy = LT.second; 934 int ISD = TLI->InstructionOpcodeToISD(Opcode); 935 assert(ISD && "Invalid opcode"); 936 937 // Horizontal adds can use the 'addv' instruction. We model the cost of these 938 // instructions as normal vector adds. This is the only arithmetic vector 939 // reduction operation for which we have an instruction. 940 static const CostTblEntry CostTblNoPairwise[]{ 941 {ISD::ADD, MVT::v8i8, 1}, 942 {ISD::ADD, MVT::v16i8, 1}, 943 {ISD::ADD, MVT::v4i16, 1}, 944 {ISD::ADD, MVT::v8i16, 1}, 945 {ISD::ADD, MVT::v4i32, 1}, 946 }; 947 948 if (const auto *Entry = CostTableLookup(CostTblNoPairwise, ISD, MTy)) 949 return LT.first * Entry->Cost; 950 951 return BaseT::getArithmeticReductionCost(Opcode, ValTy, IsPairwiseForm); 952 } 953 954 int AArch64TTIImpl::getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, 955 Type *SubTp) { 956 if (Kind == TTI::SK_Broadcast || Kind == TTI::SK_Transpose || 957 Kind == TTI::SK_Select || Kind == TTI::SK_PermuteSingleSrc) { 958 static const CostTblEntry ShuffleTbl[] = { 959 // Broadcast shuffle kinds can be performed with 'dup'. 960 { TTI::SK_Broadcast, MVT::v8i8, 1 }, 961 { TTI::SK_Broadcast, MVT::v16i8, 1 }, 962 { TTI::SK_Broadcast, MVT::v4i16, 1 }, 963 { TTI::SK_Broadcast, MVT::v8i16, 1 }, 964 { TTI::SK_Broadcast, MVT::v2i32, 1 }, 965 { TTI::SK_Broadcast, MVT::v4i32, 1 }, 966 { TTI::SK_Broadcast, MVT::v2i64, 1 }, 967 { TTI::SK_Broadcast, MVT::v2f32, 1 }, 968 { TTI::SK_Broadcast, MVT::v4f32, 1 }, 969 { TTI::SK_Broadcast, MVT::v2f64, 1 }, 970 // Transpose shuffle kinds can be performed with 'trn1/trn2' and 971 // 'zip1/zip2' instructions. 972 { TTI::SK_Transpose, MVT::v8i8, 1 }, 973 { TTI::SK_Transpose, MVT::v16i8, 1 }, 974 { TTI::SK_Transpose, MVT::v4i16, 1 }, 975 { TTI::SK_Transpose, MVT::v8i16, 1 }, 976 { TTI::SK_Transpose, MVT::v2i32, 1 }, 977 { TTI::SK_Transpose, MVT::v4i32, 1 }, 978 { TTI::SK_Transpose, MVT::v2i64, 1 }, 979 { TTI::SK_Transpose, MVT::v2f32, 1 }, 980 { TTI::SK_Transpose, MVT::v4f32, 1 }, 981 { TTI::SK_Transpose, MVT::v2f64, 1 }, 982 // Select shuffle kinds. 983 // TODO: handle vXi8/vXi16. 984 { TTI::SK_Select, MVT::v2i32, 1 }, // mov. 985 { TTI::SK_Select, MVT::v4i32, 2 }, // rev+trn (or similar). 986 { TTI::SK_Select, MVT::v2i64, 1 }, // mov. 987 { TTI::SK_Select, MVT::v2f32, 1 }, // mov. 988 { TTI::SK_Select, MVT::v4f32, 2 }, // rev+trn (or similar). 989 { TTI::SK_Select, MVT::v2f64, 1 }, // mov. 990 // PermuteSingleSrc shuffle kinds. 991 // TODO: handle vXi8/vXi16. 992 { TTI::SK_PermuteSingleSrc, MVT::v2i32, 1 }, // mov. 993 { TTI::SK_PermuteSingleSrc, MVT::v4i32, 3 }, // perfectshuffle worst case. 994 { TTI::SK_PermuteSingleSrc, MVT::v2i64, 1 }, // mov. 995 { TTI::SK_PermuteSingleSrc, MVT::v2f32, 1 }, // mov. 996 { TTI::SK_PermuteSingleSrc, MVT::v4f32, 3 }, // perfectshuffle worst case. 997 { TTI::SK_PermuteSingleSrc, MVT::v2f64, 1 }, // mov. 998 }; 999 std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Tp); 1000 if (const auto *Entry = CostTableLookup(ShuffleTbl, Kind, LT.second)) 1001 return LT.first * Entry->Cost; 1002 } 1003 1004 return BaseT::getShuffleCost(Kind, Tp, Index, SubTp); 1005 } 1006