50 return TTI.getShuffleCost(Kind, DstTy, Tp,
CostKind, Mask, Index, SubTp,
55 Mask, NumSrcElts, NumSubElts, Index)) {
56 if (Index + NumSubElts > NumSrcElts &&
57 Index + NumSrcElts <=
static_cast<int>(Mask.size()))
61 return TTI.getShuffleCost(Kind, DstTy, Tp,
CostKind, Mask, Index, SubTp, Args,
65std::pair<InstructionCost, InstructionCost>
76 if (Opcode == Instruction::Load || Opcode == Instruction::Store) {
85 ScalarCost =
TTI.getPointersChainCost(
86 Ptrs, BasePtr, TTI::PointersChainInfo::getUnitStride(), ScalarTy,
90 for (
Value *V : Ptrs) {
100 if (!Ptr || !Ptr->hasOneUse())
104 if (PtrsRetainedInVecCode.
size() == Ptrs.size()) {
109 VecCost =
TTI.getPointersChainCost(PtrsRetainedInVecCode, BasePtr,
110 TTI::PointersChainInfo::getKnownStride(),
122 return Ptr && !Ptr->hasAllConstantIndices();
124 ? TTI::PointersChainInfo::getUnknownStride()
125 : TTI::PointersChainInfo::getKnownStride();
129 Type *AccessTy = ScalarTy;
132 return Ptr && Ptr->hasOneUse() &&
isa<LoadInst>(Ptr->user_back());
137 AccessTy = Ptrs.
front()->user_back()->getType();
140 TTI.getPointersChainCost(Ptrs, BasePtr, PtrsInfo, AccessTy,
CostKind);
144 if (It != Ptrs.
end())
149 VecCost =
TTI.getGEPCost(BaseGEP->getSourceElementType(),
150 BaseGEP->getPointerOperand(), Indices,
CostKind,
155 return std::make_pair(ScalarCost, VecCost);
162 return 2 *
TTI.getMemIntrinsicInstrCost(
166 TTI.getArithmeticInstrCost(Instruction::Xor, CmpTy,
CostKind) +
167 TTI.getCmpSelInstrCost(Instruction::Select, VecTy, CmpTy,
178 return TTI.getCastInstrCost(Instruction::BitCast, DstTy, SrcTy, CCH,
183 Type *IntVecTy =
DL.getIntPtrType(DstTy);
184 return TTI.getCastInstrCost(Instruction::IntToPtr, DstTy, IntVecTy, CCH,
186 TTI.getCastInstrCost(Instruction::BitCast, IntVecTy, SrcTy, CCH,
189 Type *IntVecTy =
DL.getIntPtrType(SrcTy);
190 return TTI.getCastInstrCost(Instruction::PtrToInt, IntVecTy, SrcTy, CCH,
192 TTI.getCastInstrCost(Instruction::BitCast, DstTy, IntVecTy, CCH,
197 unsigned Opcode,
Type *ScalarTy,
212 {PaddedVecTy, PaddedVecTy, MaskTy});
214 if (!MaskedCost.isValid() || MaskedCost >= DirectCost)
217 *PaddedTy = PaddedVecTy;
224 const APInt &DemandedElts,
bool Insert,
bool Extract,
228 "ScalableVectorType is not supported.");
233 assert(ReVec &&
"Only supported by REVEC.");
236 unsigned ScalarTyNumElements = VecTy->getNumElements();
239 if (!DemandedElts[
I])
243 I * ScalarTyNumElements, VecTy);
246 I * ScalarTyNumElements, VecTy);
250 return TTI.getScalarizationOverhead(Ty, DemandedElts, Insert, Extract,
257 Value *Scalar,
ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx,
259 if (Opcode == Instruction::ExtractElement) {
261 assert(ReVec &&
"Only supported by REVEC.");
265 Index * VecTy->getNumElements(), VecTy);
268 return TTI.getVectorInstrCost(Opcode, Val,
CostKind, Index, Scalar,
269 ScalarUserAndIdx, VIC);
273 bool ReVec,
unsigned Opcode,
Type *Dst,
277 assert(ReVec &&
"Only supported by REVEC.");
285 return TTI.getExtractWithExtendCost(Opcode, Dst, VecTy, Index,
CostKind);
309 return TTI.getArithmeticReductionCost(
325 const Instruction *TruncI = TruncIt == ChainInsts.
end() ? nullptr : *TruncIt;
328 const Instruction *CmpI = CmpIt == ChainInsts.
end() ? nullptr : *CmpIt;
336 return TTI.getCastInstrCost(Instruction::Trunc, I1VecTy, VecTy,
339 TTI.getCastInstrCost(Instruction::BitCast, IntTy, I1VecTy,
341 TTI.getCmpSelInstrCost(
354 "Expected and/or reduction of i1");
360 return TTI.getCastInstrCost(Instruction::BitCast, IntTy, VectorTy, Ctx,
362 TTI.getCmpSelInstrCost(Instruction::ICmp, IntTy,
368std::pair<InstructionCost, bool>
375 RdxOpcode, VectorTy, std::nullopt,
CostKind);
378 return {std::min(RdxCost, BitcastCost), BitcastCost < RdxCost};
381 "Expected add reduction of zexted i1 values");
389 TTI.getCastInstrCost(Instruction::BitCast, IntTy, VectorTy, Ctx,
391 TTI.getIntrinsicInstrCost(
393 if (IntTy != ScalarTy)
394 ExplicitCost +=
TTI.getCastInstrCost(IntTy->getBitWidth() <
397 : Instruction::Trunc,
400 TTI.getExtendedReductionCost(RdxOpcode,
true, ScalarTy,
406 TTI.getCastInstrCost(Instruction::ZExt, ExtTy, VectorTy, Ctx,
CostKind) +
407 TTI.getArithmeticReductionCost(RdxOpcode, ExtTy, std::nullopt,
CostKind);
408 return {std::min(ExtRdxCost, CtpopCost), CtpopCost <= ExtRdxCost};
418 unsigned BitWidth = SrcTy->getScalarSizeInBits();
419 unsigned NumElts = SrcTy->getNumElements();
426 [](uint64_t
A) { return A == 0 || isPowerOf2_64(A); })
435 "The byte-multiple field width divides the result bit width.");
438 unsigned MinShiftWidth = 8;
439 while (MinShiftWidth < MaxAmt + Info.FieldWidth)
443 for (
unsigned W2 = MinShiftWidth; W2 <=
BitWidth; W2 *= 2) {
446 unsigned BytesPerLane = W2 / 8;
447 unsigned InBytes = NumElts * BytesPerLane;
457 C +=
TTI.getShuffleCost(
462 0,
nullptr, {}, CtxI);
464 if (W2 !=
BitWidth && W2 != ZExtSrcWidth)
465 C +=
TTI.getCastInstrCost(Instruction::Trunc, ShiftTy, SrcTy, CCH,
467 if (Info.needsShift())
468 C +=
TTI.getArithmeticInstrCost(Instruction::LShr, ShiftTy,
CostKind,
471 if (
C.isValid() && (!NewCost.
isValid() ||
C < NewCost)) {
481 Type *WideTy,
unsigned VF,
492 Cost +=
TTI.getArithmeticInstrCost(
493 Instruction::And, NarrowVecTy,
CostKind,
500 Cost +=
TTI.getCmpSelInstrCost(
506 Instruction::BitCast, MaskTy, CmpTy,
508 if (MaskTy != WideTy)
510 TTI.getCastInstrCost(Instruction::ZExt, WideTy, MaskTy, CCH,
CostKind);
520 if (
any_of(NarrowedLeafShifts,
521 [](
const auto &
P) {
return P.second.Shift != 0; }))
522 Cost +=
TTI.getArithmeticInstrCost(
523 Instruction::Shl, WideVecTy,
CostKind, {TTI::OK_AnyValue, TTI::OP_None},
524 {TTI::OK_NonUniformConstantValue, TTI::OP_None}, {}, CtxI);
525 if (
any_of(NarrowedLeafShifts,
526 [](
const auto &
P) {
return !
P.second.Mask.isAllOnes(); }))
527 Cost +=
TTI.getArithmeticInstrCost(
528 Instruction::And, NarrowVecTy,
CostKind,
529 {TTI::OK_AnyValue, TTI::OP_None},
530 {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 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 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...
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.
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...
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