LLVM  10.0.0
ARMTargetTransformInfo.cpp
Go to the documentation of this file.
1 //===- ARMTargetTransformInfo.cpp - ARM 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 
10 #include "ARMSubtarget.h"
12 #include "llvm/ADT/APInt.h"
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/Analysis/LoopInfo.h"
15 #include "llvm/CodeGen/CostTable.h"
18 #include "llvm/IR/BasicBlock.h"
19 #include "llvm/IR/CallSite.h"
20 #include "llvm/IR/DataLayout.h"
21 #include "llvm/IR/DerivedTypes.h"
22 #include "llvm/IR/Instruction.h"
23 #include "llvm/IR/Instructions.h"
24 #include "llvm/IR/IntrinsicInst.h"
25 #include "llvm/IR/PatternMatch.h"
26 #include "llvm/IR/Type.h"
28 #include "llvm/Support/Casting.h"
31 #include <algorithm>
32 #include <cassert>
33 #include <cstdint>
34 #include <utility>
35 
36 using namespace llvm;
37 
38 #define DEBUG_TYPE "armtti"
39 
41  "enable-arm-maskedldst", cl::Hidden, cl::init(true),
42  cl::desc("Enable the generation of masked loads and stores"));
43 
45  "disable-arm-loloops", cl::Hidden, cl::init(false),
46  cl::desc("Disable the generation of low-overhead loops"));
47 
49 
51 
53  const Function *Callee) const {
54  const TargetMachine &TM = getTLI()->getTargetMachine();
55  const FeatureBitset &CallerBits =
56  TM.getSubtargetImpl(*Caller)->getFeatureBits();
57  const FeatureBitset &CalleeBits =
58  TM.getSubtargetImpl(*Callee)->getFeatureBits();
59 
60  // To inline a callee, all features not in the whitelist must match exactly.
61  bool MatchExact = (CallerBits & ~InlineFeatureWhitelist) ==
62  (CalleeBits & ~InlineFeatureWhitelist);
63  // For features in the whitelist, the callee's features must be a subset of
64  // the callers'.
65  bool MatchSubset = ((CallerBits & CalleeBits) & InlineFeatureWhitelist) ==
66  (CalleeBits & InlineFeatureWhitelist);
67  return MatchExact && MatchSubset;
68 }
69 
70 int ARMTTIImpl::getIntImmCost(const APInt &Imm, Type *Ty) {
71  assert(Ty->isIntegerTy());
72 
73  unsigned Bits = Ty->getPrimitiveSizeInBits();
74  if (Bits == 0 || Imm.getActiveBits() >= 64)
75  return 4;
76 
77  int64_t SImmVal = Imm.getSExtValue();
78  uint64_t ZImmVal = Imm.getZExtValue();
79  if (!ST->isThumb()) {
80  if ((SImmVal >= 0 && SImmVal < 65536) ||
81  (ARM_AM::getSOImmVal(ZImmVal) != -1) ||
82  (ARM_AM::getSOImmVal(~ZImmVal) != -1))
83  return 1;
84  return ST->hasV6T2Ops() ? 2 : 3;
85  }
86  if (ST->isThumb2()) {
87  if ((SImmVal >= 0 && SImmVal < 65536) ||
88  (ARM_AM::getT2SOImmVal(ZImmVal) != -1) ||
89  (ARM_AM::getT2SOImmVal(~ZImmVal) != -1))
90  return 1;
91  return ST->hasV6T2Ops() ? 2 : 3;
92  }
93  // Thumb1, any i8 imm cost 1.
94  if (Bits == 8 || (SImmVal >= 0 && SImmVal < 256))
95  return 1;
96  if ((~SImmVal < 256) || ARM_AM::isThumbImmShiftedVal(ZImmVal))
97  return 2;
98  // Load from constantpool.
99  return 3;
100 }
101 
102 // Constants smaller than 256 fit in the immediate field of
103 // Thumb1 instructions so we return a zero cost and 1 otherwise.
104 int ARMTTIImpl::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
105  const APInt &Imm, Type *Ty) {
106  if (Imm.isNonNegative() && Imm.getLimitedValue() < 256)
107  return 0;
108 
109  return 1;
110 }
111 
112 int ARMTTIImpl::getIntImmCostInst(unsigned Opcode, unsigned Idx, const APInt &Imm,
113  Type *Ty) {
114  // Division by a constant can be turned into multiplication, but only if we
115  // know it's constant. So it's not so much that the immediate is cheap (it's
116  // not), but that the alternative is worse.
117  // FIXME: this is probably unneeded with GlobalISel.
118  if ((Opcode == Instruction::SDiv || Opcode == Instruction::UDiv ||
119  Opcode == Instruction::SRem || Opcode == Instruction::URem) &&
120  Idx == 1)
121  return 0;
122 
123  if (Opcode == Instruction::And) {
124  // UXTB/UXTH
125  if (Imm == 255 || Imm == 65535)
126  return 0;
127  // Conversion to BIC is free, and means we can use ~Imm instead.
128  return std::min(getIntImmCost(Imm, Ty), getIntImmCost(~Imm, Ty));
129  }
130 
131  if (Opcode == Instruction::Add)
132  // Conversion to SUB is free, and means we can use -Imm instead.
133  return std::min(getIntImmCost(Imm, Ty), getIntImmCost(-Imm, Ty));
134 
135  if (Opcode == Instruction::ICmp && Imm.isNegative() &&
136  Ty->getIntegerBitWidth() == 32) {
137  int64_t NegImm = -Imm.getSExtValue();
138  if (ST->isThumb2() && NegImm < 1<<12)
139  // icmp X, #-C -> cmn X, #C
140  return 0;
141  if (ST->isThumb() && NegImm < 1<<8)
142  // icmp X, #-C -> adds X, #C
143  return 0;
144  }
145 
146  // xor a, -1 can always be folded to MVN
147  if (Opcode == Instruction::Xor && Imm.isAllOnesValue())
148  return 0;
149 
150  return getIntImmCost(Imm, Ty);
151 }
152 
153 int ARMTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
154  const Instruction *I) {
155  int ISD = TLI->InstructionOpcodeToISD(Opcode);
156  assert(ISD && "Invalid opcode");
157 
158  // Single to/from double precision conversions.
159  static const CostTblEntry NEONFltDblTbl[] = {
160  // Vector fptrunc/fpext conversions.
161  { ISD::FP_ROUND, MVT::v2f64, 2 },
162  { ISD::FP_EXTEND, MVT::v2f32, 2 },
163  { ISD::FP_EXTEND, MVT::v4f32, 4 }
164  };
165 
166  if (Src->isVectorTy() && ST->hasNEON() && (ISD == ISD::FP_ROUND ||
167  ISD == ISD::FP_EXTEND)) {
168  std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Src);
169  if (const auto *Entry = CostTableLookup(NEONFltDblTbl, ISD, LT.second))
170  return LT.first * Entry->Cost;
171  }
172 
173  EVT SrcTy = TLI->getValueType(DL, Src);
174  EVT DstTy = TLI->getValueType(DL, Dst);
175 
176  if (!SrcTy.isSimple() || !DstTy.isSimple())
177  return BaseT::getCastInstrCost(Opcode, Dst, Src);
178 
179  // The extend of a load is free
180  if (I && isa<LoadInst>(I->getOperand(0))) {
181  static const TypeConversionCostTblEntry LoadConversionTbl[] = {
194  };
195  if (const auto *Entry = ConvertCostTableLookup(
196  LoadConversionTbl, ISD, DstTy.getSimpleVT(), SrcTy.getSimpleVT()))
197  return Entry->Cost;
198 
199  static const TypeConversionCostTblEntry MVELoadConversionTbl[] = {
206  };
207  if (SrcTy.isVector() && ST->hasMVEIntegerOps()) {
208  if (const auto *Entry =
209  ConvertCostTableLookup(MVELoadConversionTbl, ISD,
210  DstTy.getSimpleVT(), SrcTy.getSimpleVT()))
211  return Entry->Cost;
212  }
213  }
214 
215  // Some arithmetic, load and store operations have specific instructions
216  // to cast up/down their types automatically at no extra cost.
217  // TODO: Get these tables to know at least what the related operations are.
218  static const TypeConversionCostTblEntry NEONVectorConversionTbl[] = {
225 
226  // The number of vmovl instructions for the extension.
237 
238  // Operations that we legalize using splitting.
241 
242  // Vector float <-> i32 conversions.
245 
266 
273 
274  // Vector double <-> i32 conversions.
277 
284 
291  };
292 
293  if (SrcTy.isVector() && ST->hasNEON()) {
294  if (const auto *Entry = ConvertCostTableLookup(NEONVectorConversionTbl, ISD,
295  DstTy.getSimpleVT(),
296  SrcTy.getSimpleVT()))
297  return Entry->Cost;
298  }
299 
300  // Scalar float to integer conversions.
301  static const TypeConversionCostTblEntry NEONFloatConversionTbl[] = {
322  };
323  if (SrcTy.isFloatingPoint() && ST->hasNEON()) {
324  if (const auto *Entry = ConvertCostTableLookup(NEONFloatConversionTbl, ISD,
325  DstTy.getSimpleVT(),
326  SrcTy.getSimpleVT()))
327  return Entry->Cost;
328  }
329 
330  // Scalar integer to float conversions.
331  static const TypeConversionCostTblEntry NEONIntegerConversionTbl[] = {
352  };
353 
354  if (SrcTy.isInteger() && ST->hasNEON()) {
355  if (const auto *Entry = ConvertCostTableLookup(NEONIntegerConversionTbl,
356  ISD, DstTy.getSimpleVT(),
357  SrcTy.getSimpleVT()))
358  return Entry->Cost;
359  }
360 
361  // MVE extend costs, taken from codegen tests. i8->i16 or i16->i32 is one
362  // instruction, i8->i32 is two. i64 zexts are an VAND with a constant, sext
363  // are linearised so take more.
364  static const TypeConversionCostTblEntry MVEVectorConversionTbl[] = {
377  };
378 
379  if (SrcTy.isVector() && ST->hasMVEIntegerOps()) {
380  if (const auto *Entry = ConvertCostTableLookup(MVEVectorConversionTbl,
381  ISD, DstTy.getSimpleVT(),
382  SrcTy.getSimpleVT()))
383  return Entry->Cost * ST->getMVEVectorCostFactor();
384  }
385 
386  // Scalar integer conversion costs.
387  static const TypeConversionCostTblEntry ARMIntegerConversionTbl[] = {
388  // i16 -> i64 requires two dependent operations.
390 
391  // Truncates on i64 are assumed to be free.
394  { ISD::TRUNCATE, MVT::i8, MVT::i64, 0 },
396  };
397 
398  if (SrcTy.isInteger()) {
399  if (const auto *Entry = ConvertCostTableLookup(ARMIntegerConversionTbl, ISD,
400  DstTy.getSimpleVT(),
401  SrcTy.getSimpleVT()))
402  return Entry->Cost;
403  }
404 
405  int BaseCost = ST->hasMVEIntegerOps() && Src->isVectorTy()
406  ? ST->getMVEVectorCostFactor()
407  : 1;
408  return BaseCost * BaseT::getCastInstrCost(Opcode, Dst, Src);
409 }
410 
411 int ARMTTIImpl::getVectorInstrCost(unsigned Opcode, Type *ValTy,
412  unsigned Index) {
413  // Penalize inserting into an D-subregister. We end up with a three times
414  // lower estimated throughput on swift.
415  if (ST->hasSlowLoadDSubregister() && Opcode == Instruction::InsertElement &&
416  ValTy->isVectorTy() && ValTy->getScalarSizeInBits() <= 32)
417  return 3;
418 
419  if (ST->hasNEON() && (Opcode == Instruction::InsertElement ||
420  Opcode == Instruction::ExtractElement)) {
421  // Cross-class copies are expensive on many microarchitectures,
422  // so assume they are expensive by default.
423  if (ValTy->getVectorElementType()->isIntegerTy())
424  return 3;
425 
426  // Even if it's not a cross class copy, this likely leads to mixing
427  // of NEON and VFP code and should be therefore penalized.
428  if (ValTy->isVectorTy() &&
429  ValTy->getScalarSizeInBits() <= 32)
430  return std::max(BaseT::getVectorInstrCost(Opcode, ValTy, Index), 2U);
431  }
432 
433  if (ST->hasMVEIntegerOps() && (Opcode == Instruction::InsertElement ||
434  Opcode == Instruction::ExtractElement)) {
435  // We say MVE moves costs at least the MVEVectorCostFactor, even though
436  // they are scalar instructions. This helps prevent mixing scalar and
437  // vector, to prevent vectorising where we end up just scalarising the
438  // result anyway.
439  return std::max(BaseT::getVectorInstrCost(Opcode, ValTy, Index),
440  ST->getMVEVectorCostFactor()) *
441  ValTy->getVectorNumElements() / 2;
442  }
443 
444  return BaseT::getVectorInstrCost(Opcode, ValTy, Index);
445 }
446 
447 int ARMTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
448  const Instruction *I) {
449  int ISD = TLI->InstructionOpcodeToISD(Opcode);
450  // On NEON a vector select gets lowered to vbsl.
451  if (ST->hasNEON() && ValTy->isVectorTy() && ISD == ISD::SELECT) {
452  // Lowering of some vector selects is currently far from perfect.
453  static const TypeConversionCostTblEntry NEONVectorSelectTbl[] = {
454  { ISD::SELECT, MVT::v4i1, MVT::v4i64, 4*4 + 1*2 + 1 },
455  { ISD::SELECT, MVT::v8i1, MVT::v8i64, 50 },
457  };
458 
459  EVT SelCondTy = TLI->getValueType(DL, CondTy);
460  EVT SelValTy = TLI->getValueType(DL, ValTy);
461  if (SelCondTy.isSimple() && SelValTy.isSimple()) {
462  if (const auto *Entry = ConvertCostTableLookup(NEONVectorSelectTbl, ISD,
463  SelCondTy.getSimpleVT(),
464  SelValTy.getSimpleVT()))
465  return Entry->Cost;
466  }
467 
468  std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, ValTy);
469  return LT.first;
470  }
471 
472  int BaseCost = ST->hasMVEIntegerOps() && ValTy->isVectorTy()
473  ? ST->getMVEVectorCostFactor()
474  : 1;
475  return BaseCost * BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, I);
476 }
477 
479  const SCEV *Ptr) {
480  // Address computations in vectorized code with non-consecutive addresses will
481  // likely result in more instructions compared to scalar code where the
482  // computation can more often be merged into the index mode. The resulting
483  // extra micro-ops can significantly decrease throughput.
484  unsigned NumVectorInstToHideOverhead = 10;
485  int MaxMergeDistance = 64;
486 
487  if (ST->hasNEON()) {
488  if (Ty->isVectorTy() && SE &&
489  !BaseT::isConstantStridedAccessLessThan(SE, Ptr, MaxMergeDistance + 1))
490  return NumVectorInstToHideOverhead;
491 
492  // In many cases the address computation is not merged into the instruction
493  // addressing mode.
494  return 1;
495  }
496  return BaseT::getAddressComputationCost(Ty, SE, Ptr);
497 }
498 
501  return false;
502 
503  if (auto *VecTy = dyn_cast<VectorType>(DataTy)) {
504  // Don't support v2i1 yet.
505  if (VecTy->getNumElements() == 2)
506  return false;
507 
508  // We don't support extending fp types.
509  unsigned VecWidth = DataTy->getPrimitiveSizeInBits();
510  if (VecWidth != 128 && VecTy->getElementType()->isFloatingPointTy())
511  return false;
512  }
513 
514  unsigned EltWidth = DataTy->getScalarSizeInBits();
515  return (EltWidth == 32 && (!Alignment || Alignment >= 4)) ||
516  (EltWidth == 16 && (!Alignment || Alignment >= 2)) ||
517  (EltWidth == 8);
518 }
519 
521  if (!EnableMaskedGatherScatters || !ST->hasMVEIntegerOps())
522  return false;
523 
524  // This method is called in 2 places:
525  // - from the vectorizer with a scalar type, in which case we need to get
526  // this as good as we can with the limited info we have (and rely on the cost
527  // model for the rest).
528  // - from the masked intrinsic lowering pass with the actual vector type.
529  // For MVE, we have a custom lowering pass that will already have custom
530  // legalised any gathers that we can to MVE intrinsics, and want to expand all
531  // the rest. The pass runs before the masked intrinsic lowering pass, so if we
532  // are here, we know we want to expand.
533  if (isa<VectorType>(Ty))
534  return false;
535 
536  unsigned EltWidth = Ty->getScalarSizeInBits();
537  return ((EltWidth == 32 && (!Alignment || Alignment >= 4)) ||
538  (EltWidth == 16 && (!Alignment || Alignment >= 2)) || EltWidth == 8);
539 }
540 
542  const MemCpyInst *MI = dyn_cast<MemCpyInst>(I);
543  assert(MI && "MemcpyInst expected");
545 
546  // To model the cost of a library call, we assume 1 for the call, and
547  // 3 for the argument setup.
548  const unsigned LibCallCost = 4;
549 
550  // If 'size' is not a constant, a library call will be generated.
551  if (!C)
552  return LibCallCost;
553 
554  const unsigned Size = C->getValue().getZExtValue();
555  const unsigned DstAlign = MI->getDestAlignment();
556  const unsigned SrcAlign = MI->getSourceAlignment();
557  const Function *F = I->getParent()->getParent();
558  const unsigned Limit = TLI->getMaxStoresPerMemmove(F->hasMinSize());
559  std::vector<EVT> MemOps;
560 
561  // MemOps will be poplulated with a list of data types that needs to be
562  // loaded and stored. That's why we multiply the number of elements by 2 to
563  // get the cost for this memcpy.
564  if (getTLI()->findOptimalMemOpLowering(
565  MemOps, Limit, Size, DstAlign, SrcAlign, false /*IsMemset*/,
566  false /*ZeroMemset*/, false /*MemcpyStrSrc*/, false /*AllowOverlap*/,
568  F->getAttributes()))
569  return MemOps.size() * 2;
570 
571  // If we can't find an optimal memop lowering, return the default cost
572  return LibCallCost;
573 }
574 
576  Type *SubTp) {
577  if (ST->hasNEON()) {
578  if (Kind == TTI::SK_Broadcast) {
579  static const CostTblEntry NEONDupTbl[] = {
580  // VDUP handles these cases.
587 
592 
593  std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Tp);
594 
595  if (const auto *Entry =
596  CostTableLookup(NEONDupTbl, ISD::VECTOR_SHUFFLE, LT.second))
597  return LT.first * Entry->Cost;
598  }
599  if (Kind == TTI::SK_Reverse) {
600  static const CostTblEntry NEONShuffleTbl[] = {
601  // Reverse shuffle cost one instruction if we are shuffling within a
602  // double word (vrev) or two if we shuffle a quad word (vrev, vext).
609 
614 
615  std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Tp);
616 
617  if (const auto *Entry =
618  CostTableLookup(NEONShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second))
619  return LT.first * Entry->Cost;
620  }
621  if (Kind == TTI::SK_Select) {
622  static const CostTblEntry NEONSelShuffleTbl[] = {
623  // Select shuffle cost table for ARM. Cost is the number of
624  // instructions
625  // required to create the shuffled vector.
626 
631 
635 
637 
639 
640  std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Tp);
641  if (const auto *Entry = CostTableLookup(NEONSelShuffleTbl,
642  ISD::VECTOR_SHUFFLE, LT.second))
643  return LT.first * Entry->Cost;
644  }
645  }
646  if (ST->hasMVEIntegerOps()) {
647  if (Kind == TTI::SK_Broadcast) {
648  static const CostTblEntry MVEDupTbl[] = {
649  // VDUP handles these cases.
655 
656  std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Tp);
657 
658  if (const auto *Entry = CostTableLookup(MVEDupTbl, ISD::VECTOR_SHUFFLE,
659  LT.second))
660  return LT.first * Entry->Cost * ST->getMVEVectorCostFactor();
661  }
662  }
663  int BaseCost = ST->hasMVEIntegerOps() && Tp->isVectorTy()
664  ? ST->getMVEVectorCostFactor()
665  : 1;
666  return BaseCost * BaseT::getShuffleCost(Kind, Tp, Index, SubTp);
667 }
668 
669 int ARMTTIImpl::getArithmeticInstrCost(unsigned Opcode, Type *Ty,
670  TTI::OperandValueKind Op1Info,
671  TTI::OperandValueKind Op2Info,
672  TTI::OperandValueProperties Opd1PropInfo,
673  TTI::OperandValueProperties Opd2PropInfo,
675  const Instruction *CxtI) {
676  int ISDOpcode = TLI->InstructionOpcodeToISD(Opcode);
677  std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Ty);
678 
679  if (ST->hasNEON()) {
680  const unsigned FunctionCallDivCost = 20;
681  const unsigned ReciprocalDivCost = 10;
682  static const CostTblEntry CostTbl[] = {
683  // Division.
684  // These costs are somewhat random. Choose a cost of 20 to indicate that
685  // vectorizing devision (added function call) is going to be very expensive.
686  // Double registers types.
687  { ISD::SDIV, MVT::v1i64, 1 * FunctionCallDivCost},
688  { ISD::UDIV, MVT::v1i64, 1 * FunctionCallDivCost},
689  { ISD::SREM, MVT::v1i64, 1 * FunctionCallDivCost},
690  { ISD::UREM, MVT::v1i64, 1 * FunctionCallDivCost},
691  { ISD::SDIV, MVT::v2i32, 2 * FunctionCallDivCost},
692  { ISD::UDIV, MVT::v2i32, 2 * FunctionCallDivCost},
693  { ISD::SREM, MVT::v2i32, 2 * FunctionCallDivCost},
694  { ISD::UREM, MVT::v2i32, 2 * FunctionCallDivCost},
695  { ISD::SDIV, MVT::v4i16, ReciprocalDivCost},
696  { ISD::UDIV, MVT::v4i16, ReciprocalDivCost},
697  { ISD::SREM, MVT::v4i16, 4 * FunctionCallDivCost},
698  { ISD::UREM, MVT::v4i16, 4 * FunctionCallDivCost},
699  { ISD::SDIV, MVT::v8i8, ReciprocalDivCost},
700  { ISD::UDIV, MVT::v8i8, ReciprocalDivCost},
701  { ISD::SREM, MVT::v8i8, 8 * FunctionCallDivCost},
702  { ISD::UREM, MVT::v8i8, 8 * FunctionCallDivCost},
703  // Quad register types.
704  { ISD::SDIV, MVT::v2i64, 2 * FunctionCallDivCost},
705  { ISD::UDIV, MVT::v2i64, 2 * FunctionCallDivCost},
706  { ISD::SREM, MVT::v2i64, 2 * FunctionCallDivCost},
707  { ISD::UREM, MVT::v2i64, 2 * FunctionCallDivCost},
708  { ISD::SDIV, MVT::v4i32, 4 * FunctionCallDivCost},
709  { ISD::UDIV, MVT::v4i32, 4 * FunctionCallDivCost},
710  { ISD::SREM, MVT::v4i32, 4 * FunctionCallDivCost},
711  { ISD::UREM, MVT::v4i32, 4 * FunctionCallDivCost},
712  { ISD::SDIV, MVT::v8i16, 8 * FunctionCallDivCost},
713  { ISD::UDIV, MVT::v8i16, 8 * FunctionCallDivCost},
714  { ISD::SREM, MVT::v8i16, 8 * FunctionCallDivCost},
715  { ISD::UREM, MVT::v8i16, 8 * FunctionCallDivCost},
716  { ISD::SDIV, MVT::v16i8, 16 * FunctionCallDivCost},
717  { ISD::UDIV, MVT::v16i8, 16 * FunctionCallDivCost},
718  { ISD::SREM, MVT::v16i8, 16 * FunctionCallDivCost},
719  { ISD::UREM, MVT::v16i8, 16 * FunctionCallDivCost},
720  // Multiplication.
721  };
722 
723  if (const auto *Entry = CostTableLookup(CostTbl, ISDOpcode, LT.second))
724  return LT.first * Entry->Cost;
725 
726  int Cost = BaseT::getArithmeticInstrCost(Opcode, Ty, Op1Info, Op2Info,
727  Opd1PropInfo, Opd2PropInfo);
728 
729  // This is somewhat of a hack. The problem that we are facing is that SROA
730  // creates a sequence of shift, and, or instructions to construct values.
731  // These sequences are recognized by the ISel and have zero-cost. Not so for
732  // the vectorized code. Because we have support for v2i64 but not i64 those
733  // sequences look particularly beneficial to vectorize.
734  // To work around this we increase the cost of v2i64 operations to make them
735  // seem less beneficial.
736  if (LT.second == MVT::v2i64 &&
738  Cost += 4;
739 
740  return Cost;
741  }
742 
743  // If this operation is a shift on arm/thumb2, it might well be folded into
744  // the following instruction, hence having a cost of 0.
745  auto LooksLikeAFreeShift = [&]() {
746  if (ST->isThumb1Only() || Ty->isVectorTy())
747  return false;
748 
749  if (!CxtI || !CxtI->hasOneUse() || !CxtI->isShift())
750  return false;
752  return false;
753 
754  // Folded into a ADC/ADD/AND/BIC/CMP/EOR/MVN/ORR/ORN/RSB/SBC/SUB
755  switch (cast<Instruction>(CxtI->user_back())->getOpcode()) {
756  case Instruction::Add:
757  case Instruction::Sub:
758  case Instruction::And:
759  case Instruction::Xor:
760  case Instruction::Or:
761  case Instruction::ICmp:
762  return true;
763  default:
764  return false;
765  }
766  };
767  if (LooksLikeAFreeShift())
768  return 0;
769 
770  int BaseCost = ST->hasMVEIntegerOps() && Ty->isVectorTy()
771  ? ST->getMVEVectorCostFactor()
772  : 1;
773 
774  // The rest of this mostly follows what is done in BaseT::getArithmeticInstrCost,
775  // without treating floats as more expensive that scalars or increasing the
776  // costs for custom operations. The results is also multiplied by the
777  // MVEVectorCostFactor where appropriate.
778  if (TLI->isOperationLegalOrCustomOrPromote(ISDOpcode, LT.second))
779  return LT.first * BaseCost;
780 
781  // Else this is expand, assume that we need to scalarize this op.
782  if (Ty->isVectorTy()) {
783  unsigned Num = Ty->getVectorNumElements();
784  unsigned Cost = getArithmeticInstrCost(Opcode, Ty->getScalarType());
785  // Return the cost of multiple scalar invocation plus the cost of
786  // inserting and extracting the values.
787  return BaseT::getScalarizationOverhead(Ty, Args) + Num * Cost;
788  }
789 
790  return BaseCost;
791 }
792 
793 int ARMTTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src,
794  MaybeAlign Alignment, unsigned AddressSpace,
795  const Instruction *I) {
796  std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Src);
797 
798  if (ST->hasNEON() && Src->isVectorTy() &&
799  (Alignment && *Alignment != Align(16)) &&
800  Src->getVectorElementType()->isDoubleTy()) {
801  // Unaligned loads/stores are extremely inefficient.
802  // We need 4 uops for vst.1/vld.1 vs 1uop for vldr/vstr.
803  return LT.first * 4;
804  }
805  int BaseCost = ST->hasMVEIntegerOps() && Src->isVectorTy()
806  ? ST->getMVEVectorCostFactor()
807  : 1;
808  return BaseCost * LT.first;
809 }
810 
812  unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
813  unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond,
814  bool UseMaskForGaps) {
815  assert(Factor >= 2 && "Invalid interleave factor");
816  assert(isa<VectorType>(VecTy) && "Expect a vector type");
817 
818  // vldN/vstN doesn't support vector types of i64/f64 element.
819  bool EltIs64Bits = DL.getTypeSizeInBits(VecTy->getScalarType()) == 64;
820 
821  if (Factor <= TLI->getMaxSupportedInterleaveFactor() && !EltIs64Bits &&
822  !UseMaskForCond && !UseMaskForGaps) {
823  unsigned NumElts = VecTy->getVectorNumElements();
824  auto *SubVecTy = VectorType::get(VecTy->getScalarType(), NumElts / Factor);
825 
826  // vldN/vstN only support legal vector types of size 64 or 128 in bits.
827  // Accesses having vector types that are a multiple of 128 bits can be
828  // matched to more than one vldN/vstN instruction.
829  int BaseCost = ST->hasMVEIntegerOps() ? ST->getMVEVectorCostFactor() : 1;
830  if (NumElts % Factor == 0 &&
831  TLI->isLegalInterleavedAccessType(Factor, SubVecTy, DL))
832  return Factor * BaseCost * TLI->getNumInterleavedAccesses(SubVecTy, DL);
833 
834  // Some smaller than legal interleaved patterns are cheap as we can make
835  // use of the vmovn or vrev patterns to interleave a standard load. This is
836  // true for v4i8, v8i8 and v4i16 at least (but not for v4f16 as it is
837  // promoted differently). The cost of 2 here is then a load and vrev or
838  // vmovn.
839  if (ST->hasMVEIntegerOps() && Factor == 2 && NumElts / Factor > 2 &&
840  VecTy->isIntOrIntVectorTy() && DL.getTypeSizeInBits(SubVecTy) <= 64)
841  return 2 * BaseCost;
842  }
843 
844  return BaseT::getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
845  Alignment, AddressSpace,
846  UseMaskForCond, UseMaskForGaps);
847 }
848 
850  if (!F->isIntrinsic())
852 
853  // Assume all Arm-specific intrinsics map to an instruction.
854  if (F->getName().startswith("llvm.arm"))
855  return false;
856 
857  switch (F->getIntrinsicID()) {
858  default: break;
859  case Intrinsic::powi:
860  case Intrinsic::sin:
861  case Intrinsic::cos:
862  case Intrinsic::pow:
863  case Intrinsic::log:
864  case Intrinsic::log10:
865  case Intrinsic::log2:
866  case Intrinsic::exp:
867  case Intrinsic::exp2:
868  return true;
869  case Intrinsic::sqrt:
870  case Intrinsic::fabs:
871  case Intrinsic::copysign:
872  case Intrinsic::floor:
873  case Intrinsic::ceil:
874  case Intrinsic::trunc:
875  case Intrinsic::rint:
876  case Intrinsic::nearbyint:
877  case Intrinsic::round:
878  case Intrinsic::canonicalize:
879  case Intrinsic::lround:
880  case Intrinsic::llround:
881  case Intrinsic::lrint:
882  case Intrinsic::llrint:
883  if (F->getReturnType()->isDoubleTy() && !ST->hasFP64())
884  return true;
885  if (F->getReturnType()->isHalfTy() && !ST->hasFullFP16())
886  return true;
887  // Some operations can be handled by vector instructions and assume
888  // unsupported vectors will be expanded into supported scalar ones.
889  // TODO Handle scalar operations properly.
890  return !ST->hasFPARMv8Base() && !ST->hasVFP2Base();
891  case Intrinsic::masked_store:
892  case Intrinsic::masked_load:
893  case Intrinsic::masked_gather:
894  case Intrinsic::masked_scatter:
895  return !ST->hasMVEIntegerOps();
896  case Intrinsic::sadd_with_overflow:
897  case Intrinsic::uadd_with_overflow:
898  case Intrinsic::ssub_with_overflow:
899  case Intrinsic::usub_with_overflow:
900  case Intrinsic::sadd_sat:
901  case Intrinsic::uadd_sat:
902  case Intrinsic::ssub_sat:
903  case Intrinsic::usub_sat:
904  return false;
905  }
906 
907  return BaseT::isLoweredToCall(F);
908 }
909 
911  AssumptionCache &AC,
912  TargetLibraryInfo *LibInfo,
913  HardwareLoopInfo &HWLoopInfo) {
914  // Low-overhead branches are only supported in the 'low-overhead branch'
915  // extension of v8.1-m.
916  if (!ST->hasLOB() || DisableLowOverheadLoops)
917  return false;
918 
920  return false;
921 
922  const SCEV *BackedgeTakenCount = SE.getBackedgeTakenCount(L);
923  if (isa<SCEVCouldNotCompute>(BackedgeTakenCount))
924  return false;
925 
926  const SCEV *TripCountSCEV =
927  SE.getAddExpr(BackedgeTakenCount,
928  SE.getOne(BackedgeTakenCount->getType()));
929 
930  // We need to store the trip count in LR, a 32-bit register.
931  if (SE.getUnsignedRangeMax(TripCountSCEV).getBitWidth() > 32)
932  return false;
933 
934  // Making a call will trash LR and clear LO_BRANCH_INFO, so there's little
935  // point in generating a hardware loop if that's going to happen.
936  auto MaybeCall = [this](Instruction &I) {
937  const ARMTargetLowering *TLI = getTLI();
938  unsigned ISD = TLI->InstructionOpcodeToISD(I.getOpcode());
939  EVT VT = TLI->getValueType(DL, I.getType(), true);
940  if (TLI->getOperationAction(ISD, VT) == TargetLowering::LibCall)
941  return true;
942 
943  // Check if an intrinsic will be lowered to a call and assume that any
944  // other CallInst will generate a bl.
945  if (auto *Call = dyn_cast<CallInst>(&I)) {
946  if (isa<IntrinsicInst>(Call)) {
947  if (const Function *F = Call->getCalledFunction())
948  return isLoweredToCall(F);
949  }
950  return true;
951  }
952 
953  // FPv5 provides conversions between integer, double-precision,
954  // single-precision, and half-precision formats.
955  switch (I.getOpcode()) {
956  default:
957  break;
958  case Instruction::FPToSI:
959  case Instruction::FPToUI:
960  case Instruction::SIToFP:
961  case Instruction::UIToFP:
962  case Instruction::FPTrunc:
963  case Instruction::FPExt:
964  return !ST->hasFPARMv8Base();
965  }
966 
967  // FIXME: Unfortunately the approach of checking the Operation Action does
968  // not catch all cases of Legalization that use library calls. Our
969  // Legalization step categorizes some transformations into library calls as
970  // Custom, Expand or even Legal when doing type legalization. So for now
971  // we have to special case for instance the SDIV of 64bit integers and the
972  // use of floating point emulation.
973  if (VT.isInteger() && VT.getSizeInBits() >= 64) {
974  switch (ISD) {
975  default:
976  break;
977  case ISD::SDIV:
978  case ISD::UDIV:
979  case ISD::SREM:
980  case ISD::UREM:
981  case ISD::SDIVREM:
982  case ISD::UDIVREM:
983  return true;
984  }
985  }
986 
987  // Assume all other non-float operations are supported.
988  if (!VT.isFloatingPoint())
989  return false;
990 
991  // We'll need a library call to handle most floats when using soft.
992  if (TLI->useSoftFloat()) {
993  switch (I.getOpcode()) {
994  default:
995  return true;
996  case Instruction::Alloca:
997  case Instruction::Load:
998  case Instruction::Store:
999  case Instruction::Select:
1000  case Instruction::PHI:
1001  return false;
1002  }
1003  }
1004 
1005  // We'll need a libcall to perform double precision operations on a single
1006  // precision only FPU.
1007  if (I.getType()->isDoubleTy() && !ST->hasFP64())
1008  return true;
1009 
1010  // Likewise for half precision arithmetic.
1011  if (I.getType()->isHalfTy() && !ST->hasFullFP16())
1012  return true;
1013 
1014  return false;
1015  };
1016 
1017  auto IsHardwareLoopIntrinsic = [](Instruction &I) {
1018  if (auto *Call = dyn_cast<IntrinsicInst>(&I)) {
1019  switch (Call->getIntrinsicID()) {
1020  default:
1021  break;
1022  case Intrinsic::set_loop_iterations:
1023  case Intrinsic::test_set_loop_iterations:
1024  case Intrinsic::loop_decrement:
1025  case Intrinsic::loop_decrement_reg:
1026  return true;
1027  }
1028  }
1029  return false;
1030  };
1031 
1032  // Scan the instructions to see if there's any that we know will turn into a
1033  // call or if this loop is already a low-overhead loop.
1034  auto ScanLoop = [&](Loop *L) {
1035  for (auto *BB : L->getBlocks()) {
1036  for (auto &I : *BB) {
1037  if (MaybeCall(I) || IsHardwareLoopIntrinsic(I))
1038  return false;
1039  }
1040  }
1041  return true;
1042  };
1043 
1044  // Visit inner loops.
1045  for (auto Inner : *L)
1046  if (!ScanLoop(Inner))
1047  return false;
1048 
1049  if (!ScanLoop(L))
1050  return false;
1051 
1052  // TODO: Check whether the trip count calculation is expensive. If L is the
1053  // inner loop but we know it has a low trip count, calculating that trip
1054  // count (in the parent loop) may be detrimental.
1055 
1056  LLVMContext &C = L->getHeader()->getContext();
1057  HWLoopInfo.CounterInReg = true;
1058  HWLoopInfo.IsNestingLegal = false;
1059  HWLoopInfo.PerformEntryTest = true;
1060  HWLoopInfo.CountType = Type::getInt32Ty(C);
1061  HWLoopInfo.LoopDecrement = ConstantInt::get(HWLoopInfo.CountType, 1);
1062  return true;
1063 }
1064 
1065 static bool canTailPredicateInstruction(Instruction &I, int &ICmpCount) {
1066  // We don't allow icmp's, and because we only look at single block loops,
1067  // we simply count the icmps, i.e. there should only be 1 for the backedge.
1068  if (isa<ICmpInst>(&I) && ++ICmpCount > 1)
1069  return false;
1070 
1071  if (isa<FCmpInst>(&I))
1072  return false;
1073 
1074  // We could allow extending/narrowing FP loads/stores, but codegen is
1075  // too inefficient so reject this for now.
1076  if (isa<FPExtInst>(&I) || isa<FPTruncInst>(&I))
1077  return false;
1078 
1079  // Extends have to be extending-loads
1080  if (isa<SExtInst>(&I) || isa<ZExtInst>(&I) )
1081  if (!I.getOperand(0)->hasOneUse() || !isa<LoadInst>(I.getOperand(0)))
1082  return false;
1083 
1084  // Truncs have to be narrowing-stores
1085  if (isa<TruncInst>(&I) )
1086  if (!I.hasOneUse() || !isa<StoreInst>(*I.user_begin()))
1087  return false;
1088 
1089  return true;
1090 }
1091 
1092 // To set up a tail-predicated loop, we need to know the total number of
1093 // elements processed by that loop. Thus, we need to determine the element
1094 // size and:
1095 // 1) it should be uniform for all operations in the vector loop, so we
1096 // e.g. don't want any widening/narrowing operations.
1097 // 2) it should be smaller than i64s because we don't have vector operations
1098 // that work on i64s.
1099 // 3) we don't want elements to be reversed or shuffled, to make sure the
1100 // tail-predication masks/predicates the right lanes.
1101 //
1103  const DataLayout &DL,
1104  const LoopAccessInfo *LAI) {
1105  PredicatedScalarEvolution PSE = LAI->getPSE();
1106  int ICmpCount = 0;
1107  int Stride = 0;
1108 
1109  LLVM_DEBUG(dbgs() << "tail-predication: checking allowed instructions\n");
1110  SmallVector<Instruction *, 16> LoadStores;
1111  for (BasicBlock *BB : L->blocks()) {
1112  for (Instruction &I : BB->instructionsWithoutDebug()) {
1113  if (isa<PHINode>(&I))
1114  continue;
1115  if (!canTailPredicateInstruction(I, ICmpCount)) {
1116  LLVM_DEBUG(dbgs() << "Instruction not allowed: "; I.dump());
1117  return false;
1118  }
1119 
1120  Type *T = I.getType();
1121  if (T->isPointerTy())
1122  T = T->getPointerElementType();
1123 
1124  if (T->getScalarSizeInBits() > 32) {
1125  LLVM_DEBUG(dbgs() << "Unsupported Type: "; T->dump());
1126  return false;
1127  }
1128 
1129  if (isa<StoreInst>(I) || isa<LoadInst>(I)) {
1130  Value *Ptr = isa<LoadInst>(I) ? I.getOperand(0) : I.getOperand(1);
1131  int64_t NextStride = getPtrStride(PSE, Ptr, L);
1132  // TODO: for now only allow consecutive strides of 1. We could support
1133  // other strides as long as it is uniform, but let's keep it simple for
1134  // now.
1135  if (Stride == 0 && NextStride == 1) {
1136  Stride = NextStride;
1137  continue;
1138  }
1139  if (Stride != NextStride) {
1140  LLVM_DEBUG(dbgs() << "Different strides found, can't "
1141  "tail-predicate\n.");
1142  return false;
1143  }
1144  }
1145  }
1146  }
1147 
1148  LLVM_DEBUG(dbgs() << "tail-predication: all instructions allowed!\n");
1149  return true;
1150 }
1151 
1153  ScalarEvolution &SE,
1154  AssumptionCache &AC,
1155  TargetLibraryInfo *TLI,
1156  DominatorTree *DT,
1157  const LoopAccessInfo *LAI) {
1158  if (DisableTailPredication)
1159  return false;
1160 
1161  // Creating a predicated vector loop is the first step for generating a
1162  // tail-predicated hardware loop, for which we need the MVE masked
1163  // load/stores instructions:
1164  if (!ST->hasMVEIntegerOps())
1165  return false;
1166 
1167  // For now, restrict this to single block loops.
1168  if (L->getNumBlocks() > 1) {
1169  LLVM_DEBUG(dbgs() << "preferPredicateOverEpilogue: not a single block "
1170  "loop.\n");
1171  return false;
1172  }
1173 
1174  assert(L->empty() && "preferPredicateOverEpilogue: inner-loop expected");
1175 
1176  HardwareLoopInfo HWLoopInfo(L);
1177  if (!HWLoopInfo.canAnalyze(*LI)) {
1178  LLVM_DEBUG(dbgs() << "preferPredicateOverEpilogue: hardware-loop is not "
1179  "analyzable.\n");
1180  return false;
1181  }
1182 
1183  // This checks if we have the low-overhead branch architecture
1184  // extension, and if we will create a hardware-loop:
1185  if (!isHardwareLoopProfitable(L, SE, AC, TLI, HWLoopInfo)) {
1186  LLVM_DEBUG(dbgs() << "preferPredicateOverEpilogue: hardware-loop is not "
1187  "profitable.\n");
1188  return false;
1189  }
1190 
1191  if (!HWLoopInfo.isHardwareLoopCandidate(SE, *LI, *DT)) {
1192  LLVM_DEBUG(dbgs() << "preferPredicateOverEpilogue: hardware-loop is not "
1193  "a candidate.\n");
1194  return false;
1195  }
1196 
1197  return canTailPredicateLoop(L, LI, SE, DL, LAI);
1198 }
1199 
1200 
1203  // Only currently enable these preferences for M-Class cores.
1204  if (!ST->isMClass())
1206 
1207  // Disable loop unrolling for Oz and Os.
1208  UP.OptSizeThreshold = 0;
1209  UP.PartialOptSizeThreshold = 0;
1210  if (L->getHeader()->getParent()->hasOptSize())
1211  return;
1212 
1213  // Only enable on Thumb-2 targets.
1214  if (!ST->isThumb2())
1215  return;
1216 
1217  SmallVector<BasicBlock*, 4> ExitingBlocks;
1218  L->getExitingBlocks(ExitingBlocks);
1219  LLVM_DEBUG(dbgs() << "Loop has:\n"
1220  << "Blocks: " << L->getNumBlocks() << "\n"
1221  << "Exit blocks: " << ExitingBlocks.size() << "\n");
1222 
1223  // Only allow another exit other than the latch. This acts as an early exit
1224  // as it mirrors the profitability calculation of the runtime unroller.
1225  if (ExitingBlocks.size() > 2)
1226  return;
1227 
1228  // Limit the CFG of the loop body for targets with a branch predictor.
1229  // Allowing 4 blocks permits if-then-else diamonds in the body.
1230  if (ST->hasBranchPredictor() && L->getNumBlocks() > 4)
1231  return;
1232 
1233  // Scan the loop: don't unroll loops with calls as this could prevent
1234  // inlining.
1235  unsigned Cost = 0;
1236  for (auto *BB : L->getBlocks()) {
1237  for (auto &I : *BB) {
1238  // Don't unroll vectorised loop. MVE does not benefit from it as much as
1239  // scalar code.
1240  if (I.getType()->isVectorTy())
1241  return;
1242 
1243  if (isa<CallInst>(I) || isa<InvokeInst>(I)) {
1244  ImmutableCallSite CS(&I);
1245  if (const Function *F = CS.getCalledFunction()) {
1246  if (!isLoweredToCall(F))
1247  continue;
1248  }
1249  return;
1250  }
1251 
1252  SmallVector<const Value*, 4> Operands(I.value_op_begin(),
1253  I.value_op_end());
1254  Cost += getUserCost(&I, Operands);
1255  }
1256  }
1257 
1258  LLVM_DEBUG(dbgs() << "Cost of loop: " << Cost << "\n");
1259 
1260  UP.Partial = true;
1261  UP.Runtime = true;
1262  UP.UpperBound = true;
1263  UP.UnrollRemainder = true;
1265  UP.UnrollAndJam = true;
1267 
1268  // Force unrolling small loops can be very useful because of the branch
1269  // taken cost of the backedge.
1270  if (Cost < 12)
1271  UP.Force = true;
1272 }
1273 
1274 bool ARMTTIImpl::useReductionIntrinsic(unsigned Opcode, Type *Ty,
1275  TTI::ReductionFlags Flags) const {
1276  assert(isa<VectorType>(Ty) && "Expected Ty to be a vector type");
1277  unsigned ScalarBits = Ty->getScalarSizeInBits();
1278  if (!ST->hasMVEIntegerOps())
1279  return false;
1280 
1281  switch (Opcode) {
1282  case Instruction::FAdd:
1283  case Instruction::FMul:
1284  case Instruction::And:
1285  case Instruction::Or:
1286  case Instruction::Xor:
1287  case Instruction::Mul:
1288  case Instruction::FCmp:
1289  return false;
1290  case Instruction::ICmp:
1291  case Instruction::Add:
1292  return ScalarBits < 64 && ScalarBits * Ty->getVectorNumElements() == 128;
1293  default:
1294  llvm_unreachable("Unhandled reduction opcode");
1295  }
1296  return false;
1297 }
Type * getVectorElementType() const
Definition: Type.h:376
uint64_t CallInst * C
X = FP_ROUND(Y, TRUNC) - Rounding &#39;Y&#39; from a larger floating point type down to the precision of the ...
Definition: ISDOpcodes.h:599
bool isIntrinsic() const
isIntrinsic - Returns true if the function&#39;s name starts with "llvm.".
Definition: Function.h:198
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
bool Partial
Allow partial unrolling (unrolling of loops to expand the size of the loop body, not only to eliminat...
int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, const Instruction *I=nullptr)
bool isConstantStridedAccessLessThan(ScalarEvolution *SE, const SCEV *Ptr, int64_t MergeDistance)
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1620
bool isThumb() const
Definition: ARMSubtarget.h:765
This class represents lattice values for constants.
Definition: AllocatorList.h:23
static bool canTailPredicateInstruction(Instruction &I, int &ICmpCount)
Cost tables and simple lookup functions.
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
Definition: ISDOpcodes.h:421
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
Definition: Function.h:633
unsigned getNumInterleavedAccesses(VectorType *VecTy, const DataLayout &DL) const
Returns the number of interleaved accesses that will be generated when lowering accesses of the given...
unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract)
Estimate the overhead of scalarizing an instruction.
Definition: BasicTTIImpl.h:569
int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:277
bool hasBranchPredictor() const
Definition: ARMSubtarget.h:673
The main scalar evolution driver.
unsigned PartialOptSizeThreshold
The cost threshold for the unrolled loop when optimizing for size, like OptSizeThreshold, but used for partial/runtime unrolling (set to UINT_MAX to disable).
int64_t getPtrStride(PredicatedScalarEvolution &PSE, Value *Ptr, const Loop *Lp, const ValueToValueMap &StridesMap=ValueToValueMap(), bool Assume=false, bool ShouldCheckWrap=true)
If the pointer has a constant stride return it in units of its element size.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:255
unsigned getSourceAlignment() const
FIXME: Remove this function once transition to Align is over.
static uint64_t round(uint64_t Acc, uint64_t Input)
Definition: xxhash.cpp:57
A cache of @llvm.assume calls within a function.
unsigned getSourceAddressSpace() const
bool Force
Apply loop unroll on any kind of loop (mainly to loops that fail runtime unrolling).
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:744
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition: ValueTypes.h:141
F(f)
Type Conversion Cost Table.
Definition: CostTable.h:44
bool isThumb1Only() const
Definition: ARMSubtarget.h:767
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it&#39;s an indirect...
Definition: CallSite.h:111
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:624
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:230
Value * getLength() const
bool UnrollAndJam
Allow unroll and jam. Used to enable unroll and jam for the target.
int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond=false, bool UseMaskForGaps=false)
Cost Table Entry.
Definition: CostTable.h:24
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1566
int getIntImmCostInst(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty)
bool findOptimalMemOpLowering(std::vector< EVT > &MemOps, unsigned Limit, uint64_t Size, unsigned DstAlign, unsigned SrcAlign, bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc, bool AllowOverlap, unsigned DstAS, unsigned SrcAS, const AttributeList &FuncAttributes) const
Determines the optimal series of memory ops to replace the memset / memcpy.
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition: ISDOpcodes.h:211
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
Definition: ValueTypes.h:136
bool isLoweredToCall(const Function *F)
unsigned getAddressComputationCost(Type *Ty, ScalarEvolution *, const SCEV *)
Type * getPointerElementType() const
Definition: Type.h:381
const FeatureBitset & getFeatureBits() const
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
Definition: APInt.h:368
bool preferPredicateOverEpilogue(Loop *L, LoopInfo *LI, ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *TLI, DominatorTree *DT, const LoopAccessInfo *LAI)
APInt getUnsignedRangeMax(const SCEV *S)
Determine the max of the unsigned range for a particular SCEV.
static Optional< unsigned > getOpcode(ArrayRef< VPValue *> Values)
Returns the opcode of Values or ~0 if they do not all agree.
Definition: VPlanSLP.cpp:196
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:197
unsigned getDestAlignment() const
FIXME: Remove this function once transition to Align is over.
const TypeConversionCostTblEntry * ConvertCostTableLookup(ArrayRef< TypeConversionCostTblEntry > Tbl, int ISD, MVT Dst, MVT Src)
Find in type conversion cost table, TypeTy must be comparable to CompareTy by ==. ...
Definition: CostTable.h:54
mir Rename Register Operands
This file implements a class to represent arbitrary precision integral constant values and operations...
BlockT * getHeader() const
Definition: LoopInfo.h:105
unsigned getActiveBits() const
Compute the number of active bits in the value.
Definition: APInt.h:1590
unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, const Instruction *I)
Definition: BasicTTIImpl.h:836
This file a TargetTransformInfo::Concept conforming object specific to the ARM target machine...
int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1632
unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
Definition: BasicTTIImpl.h:697
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition: ISDOpcodes.h:539
bool useReductionIntrinsic(unsigned Opcode, Type *Ty, TTI::ReductionFlags Flags) const
bool hasV6T2Ops() const
Definition: ARMSubtarget.h:574
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
Selects elements from the corresponding lane of either source operand.
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:137
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:223
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition: Type.h:203
Reverse the order of the vector.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:144
Value * getOperand(unsigned i) const
Definition: User.h:169
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition: ISDOpcodes.h:585
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return &#39;this&#39;.
Definition: Type.h:307
bool isNegative() const
Determine sign of this APInt.
Definition: APInt.h:363
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
Definition: BasicTTIImpl.h:441
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:435
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:168
bool isAllOnesValue() const
Determine if all bits are set.
Definition: APInt.h:400
const SCEV * getOne(Type *Ty)
Return a SCEV for the constant 1 of a specific type.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
bool useSoftFloat() const override
Container class for subtarget features.
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition: Type.cpp:115
Flags describing the kind of vector reduction.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:63
unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond=false, bool UseMaskForGaps=false)
Definition: BasicTTIImpl.h:915
bool isMClass() const
Definition: ARMSubtarget.h:770
bool isThumbImmShiftedVal(unsigned V)
isThumbImmShiftedVal - Return true if the specified value can be obtained by left shifting a 8-bit im...
unsigned UnrollAndJamInnerLoopThreshold
Threshold for unroll and jam, for inner loop size.
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:224
const SCEV * getAddExpr(SmallVectorImpl< const SCEV *> &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Get a canonical add expression, or something simpler if possible.
static cl::opt< bool > EnableMaskedLoadStores("enable-arm-maskedldst", cl::Hidden, cl::init(true), cl::desc("Enable the generation of masked loads and stores"))
unsigned getUserCost(const User *U, ArrayRef< const Value * > Operands)
bool isHalfTy() const
Return true if this is &#39;half&#39;, a 16-bit IEEE fp type.
Definition: Type.h:144
bool hasSlowLoadDSubregister() const
Definition: ARMSubtarget.h:660
int getT2SOImmVal(unsigned Arg)
getT2SOImmVal - Given a 32-bit immediate, if it is something that can fit into a Thumb-2 shifter_oper...
bool isOperationLegalOrCustomOrPromote(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target or can be made legal with custom lower...
const PredicatedScalarEvolution & getPSE() const
Used to add runtime SCEV checks.
cl::opt< bool > EnableMaskedGatherScatters
bool hasVFP2Base() const
Definition: ARMSubtarget.h:608
Attributes of a target dependent hardware loop.
static double log2(double V)
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition: ISDOpcodes.h:610
void getExitingBlocks(SmallVectorImpl< BlockT *> &ExitingBlocks) const
Return all blocks inside the loop that have successors outside of the loop.
Definition: LoopInfoImpl.h:34
Extended Value Type.
Definition: ValueTypes.h:34
unsigned getMVEVectorCostFactor() const
Definition: ARMSubtarget.h:880
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:298
size_t size() const
Definition: SmallVector.h:52
const TargetMachine & getTargetMachine() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
bool isLegalInterleavedAccessType(unsigned Factor, VectorType *VecTy, const DataLayout &DL) const
Returns true if VecTy is a legal interleaved access type.
void dump() const
Definition: AsmWriter.cpp:4470
OperandValueProperties
Additional properties of an operand&#39;s values.
unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
Definition: BasicTTIImpl.h:678
bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo)
int getSOImmVal(unsigned Arg)
getSOImmVal - Given a 32-bit immediate, if it is something that can fit into an shifter_operand immed...
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
Type * getType() const
Return the LLVM type of this SCEV expression.
bool hasFP64() const
Definition: ARMSubtarget.h:646
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:390
bool hasFPARMv8Base() const
Definition: ARMSubtarget.h:611
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
Definition: Type.cpp:134
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
Definition: Alignment.h:117
static bool canTailPredicateLoop(Loop *L, LoopInfo *LI, ScalarEvolution &SE, const DataLayout &DL, const LoopAccessInfo *LAI)
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
Definition: Instruction.h:63
Provides information about what library functions are available for the current target.
AddressSpace
Definition: NVPTXBaseInfo.h:21
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
int getAddressComputationCost(Type *Val, ScalarEvolution *SE, const SCEV *Ptr)
bool hasNEON() const
Definition: ARMSubtarget.h:612
LegalizeAction getOperationAction(unsigned Op, EVT VT) const
Return how this operation should be treated: either it is legal, needs to be promoted to a larger siz...
unsigned DefaultUnrollRuntimeCount
Default unroll count for loops with run-time trip count.
unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value * > Args=ArrayRef< const Value * >(), const Instruction *CxtI=nullptr)
Definition: BasicTTIImpl.h:630
Drive the analysis of memory accesses in the loop.
This class wraps the llvm.memcpy intrinsic.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:704
bool isShift() const
Definition: Instruction.h:132
bool Runtime
Allow runtime unrolling (unrolling of loops to expand the size of the loop body even when the number ...
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:193
virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const
Virtual method implemented by subclasses that returns a reference to that target&#39;s TargetSubtargetInf...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
unsigned getVectorNumElements() const
Definition: DerivedTypes.h:566
Class for arbitrary precision integers.
Definition: APInt.h:69
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:481
bool UnrollRemainder
Allow unrolling of all the iterations of the runtime loop remainder.
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:529
static cl::opt< bool > DisableLowOverheadLoops("disable-arm-loloops", cl::Hidden, cl::init(false), cl::desc("Disable the generation of low-overhead loops"))
int InstructionOpcodeToISD(unsigned Opcode) const
Get the ISD node that corresponds to the Instruction class opcode.
const SCEV * getBackedgeTakenCount(const Loop *L, ExitCountKind Kind=Exact)
If the specified loop has a predictable backedge-taken count, return it, otherwise return a SCEVCould...
int getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Op1Info=TTI::OK_AnyValue, TTI::OperandValueKind Op2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value *> Args=ArrayRef< const Value *>(), const Instruction *CxtI=nullptr)
bool isLegalMaskedGather(Type *Ty, MaybeAlign Alignment)
const CostTblEntry * CostTableLookup(ArrayRef< CostTblEntry > Tbl, int ISD, MVT Ty)
Find in cost table, TypeTy must be comparable to CompareTy by ==.
Definition: CostTable.h:31
int getMemoryOpCost(unsigned Opcode, Type *Src, MaybeAlign Alignment, unsigned AddressSpace, const Instruction *I=nullptr)
bool isThumb2() const
Definition: ARMSubtarget.h:768
unsigned getNumBlocks() const
Get the number of blocks in this loop in constant time.
Definition: LoopInfo.h:168
bool areInlineCompatible(const Function *Caller, const Function *Callee) const
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:151
int getMemcpyCost(const Instruction *I)
unsigned getDestAddressSpace() const
This class represents an analyzed expression in the program.
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:180
unsigned getIntegerBitWidth() const
Definition: DerivedTypes.h:102
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:509
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value...
Definition: APInt.h:486
ArrayRef< BlockT * > getBlocks() const
Get a list of the basic blocks which make up this loop.
Definition: LoopInfo.h:154
Parameters that control the generic loop unrolling transformation.
unsigned OptSizeThreshold
The cost threshold for the unrolled loop when optimizing for size (set to UINT_MAX to disable)...
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:614
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:215
Establish a view to a call site for examination.
Definition: CallSite.h:697
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:106
int getIntImmCost(const APInt &Imm, Type *Ty)
#define I(x, y, z)
Definition: MD5.cpp:58
bool isLegalMaskedLoad(Type *DataTy, MaybeAlign Alignment)
bool hasLOB() const
Definition: ARMSubtarget.h:619
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
Definition: Function.h:630
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:332
unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
Definition: BasicTTIImpl.h:876
uint32_t Size
Definition: Profile.cpp:46
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
bool empty() const
Definition: LoopInfo.h:151
unsigned getMaxStoresPerMemmove(bool OptSize) const
Get maximum # of store operations permitted for llvm.memmove.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
Definition: Value.h:396
cl::opt< bool > DisableTailPredication
LLVM Value Representation.
Definition: Value.h:74
int getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty)
bool hasMVEIntegerOps() const
Definition: ARMSubtarget.h:585
Broadcast element 0 to all other elements.
int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:65
bool UpperBound
Allow using trip count upper bound to unroll loops.
IRTranslator LLVM IR MI
bool hasOneUse() const
Return true if there is exactly one user of this value.
Definition: Value.h:433
OperandValueKind
Additional information about an operand&#39;s possible values.
Conversion operators.
Definition: ISDOpcodes.h:526
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:535
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition: ValueTypes.h:126
#define LLVM_DEBUG(X)
Definition: Debug.h:122
iterator_range< block_iterator > blocks() const
Definition: LoopInfo.h:161
bool isDoubleTy() const
Return true if this is &#39;double&#39;, a 64-bit IEEE fp type.
Definition: Type.h:150
bool hasLoopInvariantBackedgeTakenCount(const Loop *L)
Return true if the specified loop has an analyzable loop-invariant backedge-taken count...
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
std::pair< int, MVT > getTypeLegalizationCost(const DataLayout &DL, Type *Ty) const
Estimate the cost of type-legalization and the legalized type.
const BasicBlock * getParent() const
Definition: Instruction.h:66
ShuffleKind
The various kinds of shuffle patterns for vector queries.
bool hasFullFP16() const
Definition: ARMSubtarget.h:690