51 return TTI.getShuffleCost(Kind, DstTy, Tp,
CostKind, Mask, Index, SubTp,
56 Mask, NumSrcElts, NumSubElts, Index)) {
57 if (Index + NumSubElts > NumSrcElts &&
58 Index + NumSrcElts <=
static_cast<int>(Mask.size()))
62 return TTI.getShuffleCost(Kind, DstTy, Tp,
CostKind, Mask, Index, SubTp, Args,
66std::pair<InstructionCost, InstructionCost>
77 if (Opcode == Instruction::Load || Opcode == Instruction::Store) {
86 ScalarCost =
TTI.getPointersChainCost(
87 Ptrs, BasePtr, TTI::PointersChainInfo::getUnitStride(), ScalarTy,
91 for (
Value *V : Ptrs) {
101 if (!Ptr || !Ptr->hasOneUse())
105 if (PtrsRetainedInVecCode.
size() == Ptrs.size()) {
110 VecCost =
TTI.getPointersChainCost(PtrsRetainedInVecCode, BasePtr,
111 TTI::PointersChainInfo::getKnownStride(),
123 return Ptr && !Ptr->hasAllConstantIndices();
125 ? TTI::PointersChainInfo::getUnknownStride()
126 : TTI::PointersChainInfo::getKnownStride();
128 const bool IsSameBase =
135 Type *AccessTy = ScalarTy;
138 return Ptr && Ptr->hasOneUse() &&
isa<LoadInst>(Ptr->user_back());
141 AccessTy = Ptrs.
front()->user_back()->getType();
144 TTI.getPointersChainCost(Ptrs, BasePtr, PtrsInfo, AccessTy,
CostKind);
148 if (It != Ptrs.
end())
155 Type *IdxTy =
DL.getIndexType(VecTy);
156 VecCost =
TTI.getArithmeticInstrCost(Instruction::Add, IdxTy,
CostKind);
157 uint64_t Stride =
DL.getTypeAllocSize(BaseGEP->getSourceElementType())
162 VecCost +=
TTI.getArithmeticInstrCost(
163 isPowerOf2_64(Stride) ? Instruction::Shl : Instruction::Mul, IdxTy,
165 }
else if (BaseGEP) {
167 VecCost =
TTI.getGEPCost(BaseGEP->getSourceElementType(),
168 BaseGEP->getPointerOperand(), Indices,
CostKind,
173 return std::make_pair(ScalarCost, VecCost);
180 return 2 *
TTI.getMemIntrinsicInstrCost(
184 TTI.getArithmeticInstrCost(Instruction::Xor, CmpTy,
CostKind) +
185 TTI.getCmpSelInstrCost(Instruction::Select, VecTy, CmpTy,
196 return TTI.getCastInstrCost(Instruction::BitCast, DstTy, SrcTy, CCH,
201 Type *IntVecTy =
DL.getIntPtrType(DstTy);
202 return TTI.getCastInstrCost(Instruction::IntToPtr, DstTy, IntVecTy, CCH,
204 TTI.getCastInstrCost(Instruction::BitCast, IntVecTy, SrcTy, CCH,
207 Type *IntVecTy =
DL.getIntPtrType(SrcTy);
208 return TTI.getCastInstrCost(Instruction::PtrToInt, IntVecTy, SrcTy, CCH,
210 TTI.getCastInstrCost(Instruction::BitCast, DstTy, IntVecTy, CCH,
215 unsigned Opcode,
Type *ScalarTy,
230 {PaddedVecTy, PaddedVecTy, MaskTy});
232 if (!MaskedCost.isValid() || MaskedCost >= DirectCost)
235 *PaddedTy = PaddedVecTy;
242 const APInt &DemandedElts,
bool Insert,
bool Extract,
246 "ScalableVectorType is not supported.");
251 assert(ReVec &&
"Only supported by REVEC.");
254 unsigned ScalarTyNumElements = VecTy->getNumElements();
257 if (!DemandedElts[
I])
261 I * ScalarTyNumElements, VecTy);
264 I * ScalarTyNumElements, VecTy);
268 return TTI.getScalarizationOverhead(Ty, DemandedElts, Insert, Extract,
275 Value *Scalar,
ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx,
277 if (Opcode == Instruction::ExtractElement) {
279 assert(ReVec &&
"Only supported by REVEC.");
283 Index * VecTy->getNumElements(), VecTy);
286 return TTI.getVectorInstrCost(Opcode, Val,
CostKind, Index, Scalar,
287 ScalarUserAndIdx, VIC);
291 bool ReVec,
unsigned Opcode,
Type *Dst,
295 assert(ReVec &&
"Only supported by REVEC.");
303 return TTI.getExtractWithExtendCost(Opcode, Dst, VecTy, Index,
CostKind);
327 return TTI.getArithmeticReductionCost(
343 const Instruction *TruncI = TruncIt == ChainInsts.
end() ? nullptr : *TruncIt;
346 const Instruction *CmpI = CmpIt == ChainInsts.
end() ? nullptr : *CmpIt;
354 return TTI.getCastInstrCost(Instruction::Trunc, I1VecTy, VecTy,
357 TTI.getCastInstrCost(Instruction::BitCast, IntTy, I1VecTy,
359 TTI.getCmpSelInstrCost(
372 "Expected and/or reduction of i1");
378 return TTI.getCastInstrCost(Instruction::BitCast, IntTy, VectorTy, Ctx,
380 TTI.getCmpSelInstrCost(Instruction::ICmp, IntTy,
386std::pair<InstructionCost, bool>
393 RdxOpcode, VectorTy, std::nullopt,
CostKind);
396 return {std::min(RdxCost, BitcastCost), BitcastCost < RdxCost};
399 "Expected add reduction of zexted i1 values");
407 TTI.getCastInstrCost(Instruction::BitCast, IntTy, VectorTy, Ctx,
409 TTI.getIntrinsicInstrCost(
411 if (IntTy != ScalarTy)
412 ExplicitCost +=
TTI.getCastInstrCost(IntTy->getBitWidth() <
415 : Instruction::Trunc,
418 TTI.getExtendedReductionCost(RdxOpcode,
true, ScalarTy,
424 TTI.getCastInstrCost(Instruction::ZExt, ExtTy, VectorTy, Ctx,
CostKind) +
425 TTI.getArithmeticReductionCost(RdxOpcode, ExtTy, std::nullopt,
CostKind);
426 return {std::min(ExtRdxCost, CtpopCost), CtpopCost <= ExtRdxCost};
436 unsigned BitWidth = SrcTy->getScalarSizeInBits();
437 unsigned NumElts = SrcTy->getNumElements();
444 [](uint64_t
A) { return A == 0 || isPowerOf2_64(A); })
453 "The byte-multiple field width divides the result bit width.");
456 unsigned MinShiftWidth = 8;
457 while (MinShiftWidth < MaxAmt + Info.FieldWidth)
465 for (
unsigned W2 = MinShiftWidth; W2 <=
BitWidth; W2 *= 2) {
468 unsigned BytesPerLane = W2 / 8;
469 unsigned InBytes = NumElts * BytesPerLane;
477 if (Info.FieldWidth < W2)
478 C +=
TTI.getCastInstrCost(Instruction::Trunc, FieldTy, ShiftTy,
480 if (IsReversed && Info.FieldWidth == 8) {
484 }
else if (IsReversed) {
494 C +=
TTI.getShuffleCost(
499 WideMask, 0,
nullptr, {}, CtxI);
500 if (InBytes > OutBytes)
503 0, PackTy, {}, CtxI);
505 if (W2 !=
BitWidth && W2 != ZExtSrcWidth)
506 C +=
TTI.getCastInstrCost(Instruction::Trunc, ShiftTy, SrcTy, CCH,
508 if (Info.needsShift())
509 C +=
TTI.getArithmeticInstrCost(Instruction::LShr, ShiftTy,
CostKind,
512 if (
C.isValid() && (!NewCost.
isValid() ||
C < NewCost)) {
522 Type *WideTy,
unsigned VF,
533 Cost +=
TTI.getArithmeticInstrCost(
534 Instruction::And, NarrowVecTy,
CostKind,
541 Cost +=
TTI.getCmpSelInstrCost(
547 Instruction::BitCast, MaskTy, CmpTy,
549 if (MaskTy != WideTy)
551 TTI.getCastInstrCost(Instruction::ZExt, WideTy, MaskTy, CCH,
CostKind);
561 if (
any_of(NarrowedLeafShifts,
562 [](
const auto &
P) {
return P.second.Shift != 0; }))
563 Cost +=
TTI.getArithmeticInstrCost(
564 Instruction::Shl, WideVecTy,
CostKind, {TTI::OK_AnyValue, TTI::OP_None},
565 {TTI::OK_NonUniformConstantValue, TTI::OP_None}, {}, CtxI);
566 if (
any_of(NarrowedLeafShifts,
567 [](
const auto &
P) {
return !
P.second.Mask.isAllOnes(); }))
568 Cost +=
TTI.getArithmeticInstrCost(
569 Instruction::And, NarrowVecTy,
CostKind,
570 {TTI::OK_AnyValue, TTI::OP_None},
571 {TTI::OK_NonUniformConstantValue, TTI::OP_None}, {}, CtxI);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static cl::opt< OutputCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(OutputCostKind::RecipThroughput), cl::values(clEnumValN(OutputCostKind::RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(OutputCostKind::Latency, "latency", "Instruction latency"), clEnumValN(OutputCostKind::CodeSize, "code-size", "Code size"), clEnumValN(OutputCostKind::SizeAndLatency, "size-latency", "Code size and latency"), clEnumValN(OutputCostKind::All, "all", "Print all cost kinds")))
Provides some synthesis utilities to produce sequences of values.
This file defines the SmallVector class.
Class for arbitrary precision integers.
unsigned getBitWidth() const
Return the number of bits in the APInt.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
const T & front() const
Get the first element.
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
This is an important base class in LLVM.
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
Convenience struct for specifying and reasoning about fast-math flags.
Class to represent fixed width SIMD vectors.
unsigned getNumElements() const
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
static InstructionCost getInvalid(CostType Val=0)
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Information for memory intrinsic cost model.
static LLVM_ABI unsigned getOpcode(RecurKind Kind)
Returns the opcode corresponding to the RecurrenceKind.
unsigned getOpcode() const
static LLVM_ABI bool isIdentityMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from exactly one source vector without lane crossin...
static LLVM_ABI bool isInsertSubvectorMask(ArrayRef< int > Mask, int NumSrcElts, int &NumSubElts, int &Index)
Return true if this shuffle mask is an insert subvector mask.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Provides information about what library functions are available for the current target.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI unsigned getIntegerBitWidth() const
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
LLVM Value Representation.
user_iterator user_begin()
bool hasOneUse() const
Return true if there is exactly one use of this value.
Base class of all SIMD vector types.
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Type * getElementType() const
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
bool match(Val *V, const Pattern &P)
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
A private "module" namespace for types and utilities used by this pass.
std::pair< InstructionCost, bool > getI1ReductionCost(RecurKind Kind, const TargetTransformInfo &TTI, FixedVectorType *VectorTy, Type *ScalarTy, TTI::CastContextHint Ctx, TTI::TargetCostKind CostKind)
i1 reductions can be emitted as the plain target reduction or in the bitcast-based form (bitcast to a...
InstructionCost getShuffleCost(const TargetTransformInfo &TTI, TTI::ShuffleKind Kind, VectorType *Tp, const TTI::TargetCostKind CostKind, ArrayRef< int > Mask, int Index, VectorType *SubTp, ArrayRef< const Value * > Args, TTI::VectorInstrContext VIC)
Returns the cost of the shuffle instructions with the given Kind, vector type Tp and optional Mask.
InstructionCost getNarrowedLeafOpsCost(const TargetTransformInfo &TTI, const SmallDenseMap< Value *, NarrowedLeafInfo > &NarrowedLeafShifts, VectorType *NarrowVecTy, VectorType *WideVecTy, const Instruction *CtxI, const TTI::TargetCostKind CostKind)
Returns the cost of the per-lane operations on the narrowed leaves NarrowedLeafShifts: the shl in the...
InstructionCost getBoolReduxBitcastCmpCost(const TargetTransformInfo &TTI, RecurKind RdxKind, FixedVectorType *VecTy, const Value *Root, ArrayRef< Instruction * > ChainInsts, const TTI::TargetCostKind CostKind)
Returns the cost of the booleanized logical and/or reduction of a vector of type VecTy with the i1 ro...
std::pair< InstructionCost, InstructionCost > getGEPCosts(const TargetTransformInfo &TTI, ArrayRef< Value * > Ptrs, Value *BasePtr, unsigned Opcode, const TTI::TargetCostKind CostKind, Type *ScalarTy, VectorType *VecTy)
Calculate the scalar and the vector costs from vectorizing set of GEPs.
Intrinsic::ID getMaskedDivRemIntrinsic(unsigned Opcode)
SmallVector< int > getBitPackMask(const BitPackInfo &Info, unsigned NumBytes, unsigned NumElts, unsigned BytesPerLane)
Returns the byte shuffle mask packing the per-lane fields of the shifted lanes (BytesPerLane bytes ea...
unsigned getNumElements(Type *Ty)
Type * getWidenedType(Type *ScalarTy, unsigned VF)
static TTI::CastContextHint getBoolReduxResultCCH(const Value *Root)
Returns the cast context hint for the trunc of the booleanized reduction result, which inherits the u...
InstructionCost getBlendedLoadCost(const TargetTransformInfo &TTI, Type *VecTy, Align Alignment, unsigned AddressSpace, const TTI::TargetCostKind CostKind)
Returns the cost of a BlendedLoadVectorize node loading VecTy: two masked loads (one per candidate ba...
FixedVectorType * getMaskedDivRemType(const TargetTransformInfo &TTI, unsigned Opcode, Type *ScalarTy, unsigned NumElts, bool ReVec)
For a non-power-of-2 NumElts-wide integer div/rem Opcode, returns the padded full-register vector typ...
InstructionCost getBoolBitmaskCost(const TargetTransformInfo &TTI, bool NeedMask, Type *NarrowScalarTy, Type *WideTy, unsigned VF, ArrayRef< int > PermMask, const Value *Root, const TTI::TargetCostKind CostKind)
Returns the cost of the boolean bitmask reduction of a vector of boolean leaves of type NarrowScalarT...
InstructionCost getBoolReduxWideRdxCost(const TargetTransformInfo &TTI, RecurKind RdxKind, FixedVectorType *VecTy, const Value *Root, FastMathFlags FMF, const TTI::TargetCostKind CostKind)
Returns the cost of the booleanized logical and/or reduction of a vector of type VecTy with the i1 ro...
InstructionCost getWidenedStridedCastCost(const TargetTransformInfo &TTI, Type *SrcTy, Type *DstTy, const DataLayout &DL, TTI::CastContextHint CCH, TTI::TargetCostKind CostKind)
Returns the cost of the cast between the widened strided access type and the entry vector type.
InstructionCost getScalarizationOverhead(const TargetTransformInfo &TTI, bool ReVec, Type *ScalarTy, VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract, const TTI::TargetCostKind CostKind, bool ForPoisonSrc, ArrayRef< Value * > VL, TTI::VectorInstrContext VIC)
This is similar to TargetTransformInfo::getScalarizationOverhead, but if ScalarTy is a FixedVectorTyp...
InstructionCost getExtractWithExtendCost(const TargetTransformInfo &TTI, bool ReVec, unsigned Opcode, Type *Dst, VectorType *VecTy, unsigned Index, const TTI::TargetCostKind CostKind)
This is similar to TargetTransformInfo::getExtractWithExtendCost, but if Dst is a FixedVectorType,...
static InstructionCost getBoolLogicRdxBitcastCost(RecurKind Kind, const TargetTransformInfo &TTI, FixedVectorType *VectorTy, TTI::CastContextHint Ctx, TTI::TargetCostKind CostKind)
InstructionCost getVectorInstrCost(const TargetTransformInfo &TTI, bool ReVec, Type *ScalarTy, unsigned Opcode, Type *Val, const TTI::TargetCostKind CostKind, unsigned Index, Value *Scalar, ArrayRef< std::tuple< Value *, User *, int > > ScalarUserAndIdx, TTI::VectorInstrContext VIC)
This is similar to TargetTransformInfo::getVectorInstrCost, but if ScalarTy is a FixedVectorType,...
InstructionCost getMaskedDivRemCost(const TargetTransformInfo &TTI, bool ReVec, unsigned Opcode, Type *ScalarTy, unsigned NumElts, const TTI::TargetCostKind CostKind, FixedVectorType **PaddedTy)
For a non-power-of-2 NumElts-wide integer div/rem Opcode, checks if padding to a full register and us...
InstructionCost getBitPackCost(const TargetTransformInfo &TTI, FixedVectorType *SrcTy, Type *ResultTy, const BitPackInfo &Info, unsigned ZExtSrcWidth, TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, const TargetLibraryInfo *TLI, const Instruction *CtxI, unsigned &ShiftWidth)
Returns the cost of the bitfield packing of SrcTy into ResultTy, picking the cheapest shift width.
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Type * toScalarizedTy(Type *Ty)
A helper for converting vectorized types to scalarized (non-vector) types.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
bool isVectorizedTy(Type *Ty)
Returns true if Ty is a vector type or a struct of vector types where all vector types share the same...
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
auto map_range(ContainerTy &&C, FuncTy F)
Return a range that applies F to the elements of C.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto reverse(ContainerTy &&C)
bool isPointerTy(const Type *T)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
constexpr int PoisonMaskElem
RecurKind
These are the kinds of recurrences that we support.
@ Or
Bitwise or logical OR of integers.
@ And
Bitwise or logical AND of integers.
auto max_element(R &&Range)
Provide wrappers to std::max_element which take ranges instead of having to pass begin/end explicitly...
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool all_equal(std::initializer_list< T > Values)
Returns true if all Values in the initializer lists are equal or the list.
bool equal(L &&LRange, R &&RRange)
Wrapper function around std::equal to detect if pair-wise elements between two ranges are the same.
constexpr detail::IsaCheckPredicate< Types... > IsaPred
Function object wrapper for the llvm::isa type check.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Description of a bitfield packing of vector lanes into a scalar value: every lane contributes a disjo...
static constexpr unsigned NoLane