47 return TTI.getShuffleCost(Kind, DstTy, Tp,
CostKind, Mask, Index, SubTp,
52 Mask, NumSrcElts, NumSubElts, Index)) {
53 if (Index + NumSubElts > NumSrcElts &&
54 Index + NumSrcElts <=
static_cast<int>(Mask.size()))
58 return TTI.getShuffleCost(Kind, DstTy, Tp,
CostKind, Mask, Index, SubTp,
62std::pair<InstructionCost, InstructionCost>
73 if (Opcode == Instruction::Load || Opcode == Instruction::Store) {
82 ScalarCost =
TTI.getPointersChainCost(
83 Ptrs, BasePtr, TTI::PointersChainInfo::getUnitStride(), ScalarTy,
87 for (
Value *V : Ptrs) {
97 if (!Ptr || !Ptr->hasOneUse())
101 if (PtrsRetainedInVecCode.
size() == Ptrs.size()) {
106 VecCost =
TTI.getPointersChainCost(PtrsRetainedInVecCode, BasePtr,
107 TTI::PointersChainInfo::getKnownStride(),
119 return Ptr && !Ptr->hasAllConstantIndices();
121 ? TTI::PointersChainInfo::getUnknownStride()
122 : TTI::PointersChainInfo::getKnownStride();
125 TTI.getPointersChainCost(Ptrs, BasePtr, PtrsInfo, ScalarTy,
CostKind);
129 if (It != Ptrs.
end())
134 VecCost =
TTI.getGEPCost(BaseGEP->getSourceElementType(),
135 BaseGEP->getPointerOperand(), Indices,
CostKind,
140 return std::make_pair(ScalarCost, VecCost);
147 return 2 *
TTI.getMemIntrinsicInstrCost(
151 TTI.getArithmeticInstrCost(Instruction::Xor, CmpTy,
CostKind) +
152 TTI.getCmpSelInstrCost(Instruction::Select, VecTy, CmpTy,
157 unsigned Opcode,
Type *ScalarTy,
172 {PaddedVecTy, PaddedVecTy, MaskTy});
174 if (!MaskedCost.isValid() || MaskedCost >= DirectCost)
177 *PaddedTy = PaddedVecTy;
184 const APInt &DemandedElts,
bool Insert,
bool Extract,
188 "ScalableVectorType is not supported.");
193 assert(ReVec &&
"Only supported by REVEC.");
196 unsigned ScalarTyNumElements = VecTy->getNumElements();
199 if (!DemandedElts[
I])
203 I * ScalarTyNumElements, VecTy);
206 I * ScalarTyNumElements, VecTy);
210 return TTI.getScalarizationOverhead(Ty, DemandedElts, Insert, Extract,
218 ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx) {
219 if (Opcode == Instruction::ExtractElement) {
221 assert(ReVec &&
"Only supported by REVEC.");
225 Index * VecTy->getNumElements(), VecTy);
228 return TTI.getVectorInstrCost(Opcode, Val,
CostKind, Index, Scalar,
233 bool ReVec,
unsigned Opcode,
Type *Dst,
237 assert(ReVec &&
"Only supported by REVEC.");
245 return TTI.getExtractWithExtendCost(Opcode, Dst, VecTy, Index,
CostKind);
269 return TTI.getArithmeticReductionCost(
285 const Instruction *TruncI = TruncIt == ChainInsts.
end() ? nullptr : *TruncIt;
288 const Instruction *CmpI = CmpIt == ChainInsts.
end() ? nullptr : *CmpIt;
296 return TTI.getCastInstrCost(Instruction::Trunc, I1VecTy, VecTy,
299 TTI.getCastInstrCost(Instruction::BitCast, IntTy, I1VecTy,
301 TTI.getCmpSelInstrCost(Instruction::ICmp, IntTy,
nullptr,
305 TTI.getOperandInfo(CmpRHS), CmpI);
315 unsigned BitWidth = SrcTy->getScalarSizeInBits();
316 unsigned NumElts = SrcTy->getNumElements();
323 [](uint64_t
A) { return A == 0 || isPowerOf2_64(A); })
332 "The byte-multiple field width divides the result bit width.");
335 unsigned MinShiftWidth = 8;
336 while (MinShiftWidth < MaxAmt + Info.FieldWidth)
340 for (
unsigned W2 = MinShiftWidth; W2 <=
BitWidth; W2 *= 2) {
343 unsigned BytesPerLane = W2 / 8;
344 unsigned InBytes = NumElts * BytesPerLane;
354 C +=
TTI.getShuffleCost(
359 0,
nullptr, {}, CxtI);
361 if (W2 !=
BitWidth && W2 != ZExtSrcWidth)
362 C +=
TTI.getCastInstrCost(Instruction::Trunc, ShiftTy, SrcTy, CCH,
364 if (Info.needsShift())
365 C +=
TTI.getArithmeticInstrCost(Instruction::LShr, ShiftTy,
CostKind,
368 if (
C.isValid() && (!NewCost.
isValid() ||
C < NewCost)) {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
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),...
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
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.
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.
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 isReverseMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask swaps the order of elements from exactly one source vector.
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.
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.
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
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...
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.
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 *CxtI, unsigned &ShiftWidth)
Returns the cost of the bitfield packing of SrcTy into ResultTy, picking the cheapest shift width.
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)
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)
Returns the cost of the shuffle instructions with the given Kind, vector type Tp and optional Mask.
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 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)
This is similar to TargetTransformInfo::getVectorInstrCost, but if ScalarTy is a FixedVectorType,...
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 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,...
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...
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...
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...
RecurKind
These are the kinds of recurrences that we support.
@ 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.
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