49 return TTI.getShuffleCost(Kind, DstTy, Tp,
CostKind, Mask, Index, SubTp,
54 Mask, NumSrcElts, NumSubElts, Index)) {
55 if (Index + NumSubElts > NumSrcElts &&
56 Index + NumSrcElts <=
static_cast<int>(Mask.size()))
60 return TTI.getShuffleCost(Kind, DstTy, Tp,
CostKind, Mask, Index, SubTp, Args,
64std::pair<InstructionCost, InstructionCost>
75 if (Opcode == Instruction::Load || Opcode == Instruction::Store) {
84 ScalarCost =
TTI.getPointersChainCost(
85 Ptrs, BasePtr, TTI::PointersChainInfo::getUnitStride(), ScalarTy,
89 for (
Value *V : Ptrs) {
99 if (!Ptr || !Ptr->hasOneUse())
103 if (PtrsRetainedInVecCode.
size() == Ptrs.size()) {
108 VecCost =
TTI.getPointersChainCost(PtrsRetainedInVecCode, BasePtr,
109 TTI::PointersChainInfo::getKnownStride(),
121 return Ptr && !Ptr->hasAllConstantIndices();
123 ? TTI::PointersChainInfo::getUnknownStride()
124 : TTI::PointersChainInfo::getKnownStride();
127 TTI.getPointersChainCost(Ptrs, BasePtr, PtrsInfo, ScalarTy,
CostKind);
131 if (It != Ptrs.
end())
136 VecCost =
TTI.getGEPCost(BaseGEP->getSourceElementType(),
137 BaseGEP->getPointerOperand(), Indices,
CostKind,
142 return std::make_pair(ScalarCost, VecCost);
149 return 2 *
TTI.getMemIntrinsicInstrCost(
153 TTI.getArithmeticInstrCost(Instruction::Xor, CmpTy,
CostKind) +
154 TTI.getCmpSelInstrCost(Instruction::Select, VecTy, CmpTy,
159 unsigned Opcode,
Type *ScalarTy,
174 {PaddedVecTy, PaddedVecTy, MaskTy});
176 if (!MaskedCost.isValid() || MaskedCost >= DirectCost)
179 *PaddedTy = PaddedVecTy;
186 const APInt &DemandedElts,
bool Insert,
bool Extract,
190 "ScalableVectorType is not supported.");
195 assert(ReVec &&
"Only supported by REVEC.");
198 unsigned ScalarTyNumElements = VecTy->getNumElements();
201 if (!DemandedElts[
I])
205 I * ScalarTyNumElements, VecTy);
208 I * ScalarTyNumElements, VecTy);
212 return TTI.getScalarizationOverhead(Ty, DemandedElts, Insert, Extract,
219 Value *Scalar,
ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx,
221 if (Opcode == Instruction::ExtractElement) {
223 assert(ReVec &&
"Only supported by REVEC.");
227 Index * VecTy->getNumElements(), VecTy);
230 return TTI.getVectorInstrCost(Opcode, Val,
CostKind, Index, Scalar,
231 ScalarUserAndIdx, VIC);
235 bool ReVec,
unsigned Opcode,
Type *Dst,
239 assert(ReVec &&
"Only supported by REVEC.");
247 return TTI.getExtractWithExtendCost(Opcode, Dst, VecTy, Index,
CostKind);
271 return TTI.getArithmeticReductionCost(
287 const Instruction *TruncI = TruncIt == ChainInsts.
end() ? nullptr : *TruncIt;
290 const Instruction *CmpI = CmpIt == ChainInsts.
end() ? nullptr : *CmpIt;
298 return TTI.getCastInstrCost(Instruction::Trunc, I1VecTy, VecTy,
301 TTI.getCastInstrCost(Instruction::BitCast, IntTy, I1VecTy,
303 TTI.getCmpSelInstrCost(
316 "Expected and/or reduction of i1");
322 return TTI.getCastInstrCost(Instruction::BitCast, IntTy, VectorTy, Ctx,
324 TTI.getCmpSelInstrCost(Instruction::ICmp, IntTy,
330std::pair<InstructionCost, bool>
337 RdxOpcode, VectorTy, std::nullopt,
CostKind);
340 return {std::min(RdxCost, BitcastCost), BitcastCost < RdxCost};
343 "Expected add reduction of zexted i1 values");
351 TTI.getCastInstrCost(Instruction::BitCast, IntTy, VectorTy, Ctx,
353 TTI.getIntrinsicInstrCost(
355 if (IntTy != ScalarTy)
356 ExplicitCost +=
TTI.getCastInstrCost(IntTy->getBitWidth() <
359 : Instruction::Trunc,
362 TTI.getExtendedReductionCost(RdxOpcode,
true, ScalarTy,
368 TTI.getCastInstrCost(Instruction::ZExt, ExtTy, VectorTy, Ctx,
CostKind) +
369 TTI.getArithmeticReductionCost(RdxOpcode, ExtTy, std::nullopt,
CostKind);
370 return {std::min(ExtRdxCost, CtpopCost), CtpopCost <= ExtRdxCost};
380 unsigned BitWidth = SrcTy->getScalarSizeInBits();
381 unsigned NumElts = SrcTy->getNumElements();
388 [](uint64_t
A) { return A == 0 || isPowerOf2_64(A); })
397 "The byte-multiple field width divides the result bit width.");
400 unsigned MinShiftWidth = 8;
401 while (MinShiftWidth < MaxAmt + Info.FieldWidth)
405 for (
unsigned W2 = MinShiftWidth; W2 <=
BitWidth; W2 *= 2) {
408 unsigned BytesPerLane = W2 / 8;
409 unsigned InBytes = NumElts * BytesPerLane;
419 C +=
TTI.getShuffleCost(
424 0,
nullptr, {}, CxtI);
426 if (W2 !=
BitWidth && W2 != ZExtSrcWidth)
427 C +=
TTI.getCastInstrCost(Instruction::Trunc, ShiftTy, SrcTy, CCH,
429 if (Info.needsShift())
430 C +=
TTI.getArithmeticInstrCost(Instruction::LShr, ShiftTy,
CostKind,
433 if (
C.isValid() && (!NewCost.
isValid() ||
C < NewCost)) {
443 Type *WideTy,
unsigned VF,
454 Cost +=
TTI.getArithmeticInstrCost(
455 Instruction::And, NarrowVecTy,
CostKind,
462 Cost +=
TTI.getCmpSelInstrCost(
468 Instruction::BitCast, MaskTy, CmpTy,
470 if (MaskTy != WideTy)
472 TTI.getCastInstrCost(Instruction::ZExt, WideTy, MaskTy, CCH,
CostKind);
482 if (
any_of(NarrowedLeafShifts,
483 [](
const auto &
P) {
return P.second.Shift != 0; }))
484 Cost +=
TTI.getArithmeticInstrCost(
485 Instruction::Shl, WideVecTy,
CostKind, {TTI::OK_AnyValue, TTI::OP_None},
486 {TTI::OK_NonUniformConstantValue, TTI::OP_None}, {}, CxtI);
487 if (
any_of(NarrowedLeafShifts,
488 [](
const auto &
P) {
return !
P.second.Mask.isAllOnes(); }))
489 Cost +=
TTI.getArithmeticInstrCost(
490 Instruction::And, NarrowVecTy,
CostKind,
491 {TTI::OK_AnyValue, TTI::OP_None},
492 {TTI::OK_NonUniformConstantValue, TTI::OP_None}, {}, CxtI);
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.
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.
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 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.
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.
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 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)
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 getNarrowedLeafOpsCost(const TargetTransformInfo &TTI, const SmallDenseMap< Value *, NarrowedLeafInfo > &NarrowedLeafShifts, VectorType *NarrowVecTy, VectorType *WideVecTy, const Instruction *CxtI, const TTI::TargetCostKind CostKind)
Returns the cost of the per-lane operations on the narrowed leaves NarrowedLeafShifts: the shl in the...
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...
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 any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
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.
@ 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.
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