LLVM 24.0.0git
SLPCostAnalysis.cpp
Go to the documentation of this file.
1//===- SLPCostAnalysis.cpp - SLP Vectorizer free cost helpers -------------===//
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
9#include "SLPCostAnalysis.h"
10#include "SLPTypeUtils.h"
11#include "SLPUtils.h"
12
13#include "llvm/ADT/APInt.h"
14#include "llvm/ADT/STLExtras.h"
15#include "llvm/ADT/Sequence.h"
18#include "llvm/IR/Constants.h"
22#include "llvm/IR/Intrinsics.h"
23#include "llvm/IR/Operator.h"
25#include "llvm/IR/Type.h"
26#include "llvm/IR/Value.h"
29
30#include <cassert>
31#include <utility>
32
33using namespace llvm;
34using namespace llvm::PatternMatch;
35
36namespace llvm::slpvectorizer {
37
41 ArrayRef<int> Mask, int Index, VectorType *SubTp,
44 VectorType *DstTy = Tp;
45 if (!Mask.empty())
46 DstTy = FixedVectorType::get(Tp->getScalarType(), Mask.size());
47
48 if (Kind != TTI::SK_PermuteTwoSrc)
49 return TTI.getShuffleCost(Kind, DstTy, Tp, CostKind, Mask, Index, SubTp,
50 Args, /*CtxI=*/nullptr, VIC);
51 int NumSrcElts = Tp->getElementCount().getKnownMinValue();
52 int NumSubElts;
53 if (Mask.size() > 2 && ShuffleVectorInst::isInsertSubvectorMask(
54 Mask, NumSrcElts, NumSubElts, Index)) {
55 if (Index + NumSubElts > NumSrcElts &&
56 Index + NumSrcElts <= static_cast<int>(Mask.size()))
57 return TTI.getShuffleCost(TTI::SK_InsertSubvector, DstTy, Tp, CostKind,
58 Mask, Index, Tp);
59 }
60 return TTI.getShuffleCost(Kind, DstTy, Tp, CostKind, Mask, Index, SubTp, Args,
61 /*CtxI=*/nullptr, VIC);
62}
63
64std::pair<InstructionCost, InstructionCost>
66 Value *BasePtr, unsigned Opcode, const TTI::TargetCostKind CostKind,
67 Type *ScalarTy, VectorType *VecTy) {
68 InstructionCost ScalarCost = 0;
69 InstructionCost VecCost = 0;
70 // Here we differentiate two cases: (1) when Ptrs represent a regular
71 // vectorization tree node (as they are pointer arguments of scattered
72 // loads) or (2) when Ptrs are the arguments of loads or stores being
73 // vectorized as plane wide unit-stride load/store since all the
74 // loads/stores are known to be from/to adjacent locations.
75 if (Opcode == Instruction::Load || Opcode == Instruction::Store) {
76 // Case 2: estimate costs for pointer related costs when vectorizing to
77 // a wide load/store.
78 // Scalar cost is estimated as a set of pointers with known relationship
79 // between them.
80 // For vector code we will use BasePtr as argument for the wide load/store
81 // but we also need to account all the instructions which are going to
82 // stay in vectorized code due to uses outside of these scalar
83 // loads/stores.
84 ScalarCost = TTI.getPointersChainCost(
85 Ptrs, BasePtr, TTI::PointersChainInfo::getUnitStride(), ScalarTy,
86 CostKind);
87
88 SmallVector<const Value *> PtrsRetainedInVecCode;
89 for (Value *V : Ptrs) {
90 if (V == BasePtr) {
91 PtrsRetainedInVecCode.push_back(V);
92 continue;
93 }
94 auto *Ptr = dyn_cast<GetElementPtrInst>(V);
95 // For simplicity assume Ptr to stay in vectorized code if it's not a
96 // GEP instruction. We don't care since it's cost considered free.
97 // TODO: We should check for any uses outside of vectorizable tree
98 // rather than just single use.
99 if (!Ptr || !Ptr->hasOneUse())
100 PtrsRetainedInVecCode.push_back(V);
101 }
102
103 if (PtrsRetainedInVecCode.size() == Ptrs.size()) {
104 // If all pointers stay in vectorized code then we don't have
105 // any savings on that.
106 return std::make_pair(TTI::TCC_Free, TTI::TCC_Free);
107 }
108 VecCost = TTI.getPointersChainCost(PtrsRetainedInVecCode, BasePtr,
109 TTI::PointersChainInfo::getKnownStride(),
110 VecTy, CostKind);
111 } else {
112 // Case 1: Ptrs are the arguments of loads that we are going to transform
113 // into masked gather load intrinsic.
114 // All the scalar GEPs will be removed as a result of vectorization.
115 // For any external uses of some lanes extract element instructions will
116 // be generated (which cost is estimated separately).
117 TTI::PointersChainInfo PtrsInfo =
118 all_of(Ptrs,
119 [](const Value *V) {
120 auto *Ptr = dyn_cast<GetElementPtrInst>(V);
121 return Ptr && !Ptr->hasAllConstantIndices();
122 })
123 ? TTI::PointersChainInfo::getUnknownStride()
124 : TTI::PointersChainInfo::getKnownStride();
125
126 // The GEPs of the masked gather loads are accessed with the loaded type
127 // and form a chain only if the lanes share the base.
128 Type *AccessTy = ScalarTy;
129 if (all_of(Ptrs, [](const Value *V) {
130 auto *Ptr = dyn_cast<GetElementPtrInst>(V);
131 return Ptr && Ptr->hasOneUse() && isa<LoadInst>(Ptr->user_back());
132 })) {
133 PtrsInfo.IsSameBaseAddress = all_equal(map_range(Ptrs, [](Value *V) {
134 return cast<GetElementPtrInst>(V)->getPointerOperand();
135 }));
136 AccessTy = Ptrs.front()->user_back()->getType();
137 }
138 ScalarCost =
139 TTI.getPointersChainCost(Ptrs, BasePtr, PtrsInfo, AccessTy, CostKind);
140 auto *BaseGEP = dyn_cast<GEPOperator>(BasePtr);
141 if (!BaseGEP) {
142 auto *It = find_if(Ptrs, IsaPred<GEPOperator>);
143 if (It != Ptrs.end())
144 BaseGEP = cast<GEPOperator>(*It);
145 }
146 if (BaseGEP) {
147 SmallVector<const Value *> Indices(BaseGEP->indices());
148 VecCost = TTI.getGEPCost(BaseGEP->getSourceElementType(),
149 BaseGEP->getPointerOperand(), Indices, CostKind,
150 VecTy);
151 }
152 }
153
154 return std::make_pair(ScalarCost, VecCost);
155}
156
158 Align Alignment, unsigned AddressSpace,
160 Type *CmpTy = CmpInst::makeCmpResultType(VecTy);
161 return 2 * TTI.getMemIntrinsicInstrCost(
162 MemIntrinsicCostAttributes(Intrinsic::masked_load, VecTy,
163 Alignment, AddressSpace),
164 CostKind) +
165 TTI.getArithmeticInstrCost(Instruction::Xor, CmpTy, CostKind) +
166 TTI.getCmpSelInstrCost(Instruction::Select, VecTy, CmpTy,
168}
169
171 unsigned Opcode, Type *ScalarTy,
172 unsigned NumElts,
174 FixedVectorType **PaddedTy) {
175 FixedVectorType *PaddedVecTy =
176 getMaskedDivRemType(TTI, Opcode, ScalarTy, NumElts, ReVec);
177 if (!PaddedVecTy)
179 // One mask bit per element of the padded vector, not per padded lane.
180 auto *MaskTy =
182 PaddedVecTy->getNumElements());
183 InstructionCost DirectCost = TTI.getArithmeticInstrCost(
184 Opcode, getWidenedType(ScalarTy, NumElts), CostKind);
185 IntrinsicCostAttributes ICA(getMaskedDivRemIntrinsic(Opcode), PaddedVecTy,
186 {PaddedVecTy, PaddedVecTy, MaskTy});
187 InstructionCost MaskedCost = TTI.getIntrinsicInstrCost(ICA, CostKind);
188 if (!MaskedCost.isValid() || MaskedCost >= DirectCost)
190 if (PaddedTy)
191 *PaddedTy = PaddedVecTy;
192 return MaskedCost;
193}
194
197 Type *ScalarTy, VectorType *Ty,
198 const APInt &DemandedElts, bool Insert, bool Extract,
199 const TTI::TargetCostKind CostKind, bool ForPoisonSrc,
202 "ScalableVectorType is not supported.");
203 assert(getNumElements(ScalarTy) * DemandedElts.getBitWidth() ==
204 getNumElements(Ty) &&
205 "Incorrect usage.");
206 if (auto *VecTy = dyn_cast<FixedVectorType>(ScalarTy)) {
207 assert(ReVec && "Only supported by REVEC.");
208 // If ScalarTy is FixedVectorType, we should use CreateInsertVector instead
209 // of CreateInsertElement.
210 unsigned ScalarTyNumElements = VecTy->getNumElements();
212 for (unsigned I : seq(DemandedElts.getBitWidth())) {
213 if (!DemandedElts[I])
214 continue;
215 if (Insert)
217 I * ScalarTyNumElements, VecTy);
218 if (Extract)
220 I * ScalarTyNumElements, VecTy);
221 }
222 return Cost;
223 }
224 return TTI.getScalarizationOverhead(Ty, DemandedElts, Insert, Extract,
225 CostKind, ForPoisonSrc, VL, VIC);
226}
227
229 const TargetTransformInfo &TTI, bool ReVec, Type *ScalarTy, unsigned Opcode,
230 Type *Val, const TTI::TargetCostKind CostKind, unsigned Index,
231 Value *Scalar, ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx,
233 if (Opcode == Instruction::ExtractElement) {
234 if (auto *VecTy = dyn_cast<FixedVectorType>(ScalarTy)) {
235 assert(ReVec && "Only supported by REVEC.");
236 assert(isa<VectorType>(Val) && "Val must be a vector type.");
238 cast<VectorType>(Val), CostKind, {},
239 Index * VecTy->getNumElements(), VecTy);
240 }
241 }
242 return TTI.getVectorInstrCost(Opcode, Val, CostKind, Index, Scalar,
243 ScalarUserAndIdx, VIC);
244}
245
247 bool ReVec, unsigned Opcode, Type *Dst,
248 VectorType *VecTy, unsigned Index,
250 if (isVectorizedTy(Dst)) {
251 assert(ReVec && "Only supported by REVEC.");
252 auto *SubTp = cast<FixedVectorType>(
255 Index * getNumElements(Dst), SubTp) +
256 TTI.getCastInstrCost(Opcode, Dst, SubTp, TTI::CastContextHint::None,
257 CostKind);
258 }
259 return TTI.getExtractWithExtendCost(Opcode, Dst, VecTy, Index, CostKind);
260}
261
262/// Returns the cast context hint for the trunc of the booleanized reduction
263/// result, which inherits the uses of the reduction root \p Root.
276
278 RecurKind RdxKind,
279 FixedVectorType *VecTy,
280 const Value *Root, FastMathFlags FMF,
282 Type *I1Ty = Type::getInt1Ty(VecTy->getContext());
283 return TTI.getArithmeticReductionCost(
284 RecurrenceDescriptor::getOpcode(RdxKind), VecTy, FMF, CostKind) +
285 TTI.getCastInstrCost(Instruction::Trunc, I1Ty, VecTy->getScalarType(),
287}
288
290 RecurKind RdxKind,
291 FixedVectorType *VecTy,
292 const Value *Root,
293 ArrayRef<Instruction *> ChainInsts,
295 // The new instructions are costed in the context of the replaced cast chain
296 // instructions.
297 auto TruncIt =
298 find_if(ChainInsts, [](Instruction *I) { return isa<TruncInst>(I); });
299 const Instruction *TruncI = TruncIt == ChainInsts.end() ? nullptr : *TruncIt;
300 auto CmpIt =
301 find_if(ChainInsts, [](Instruction *I) { return isa<ICmpInst>(I); });
302 const Instruction *CmpI = CmpIt == ChainInsts.end() ? nullptr : *CmpIt;
303 unsigned VF = VecTy->getNumElements();
304 auto *I1VecTy =
306 Type *IntTy = IntegerType::get(VecTy->getContext(), VF);
307 Constant *CmpRHS = RdxKind == RecurKind::And
309 : Constant::getNullValue(IntTy);
310 return TTI.getCastInstrCost(Instruction::Trunc, I1VecTy, VecTy,
311 TTI.getCastContextHint(TruncI), CostKind,
312 TruncI) +
313 TTI.getCastInstrCost(Instruction::BitCast, IntTy, I1VecTy,
314 TTI.getCastContextHint(TruncI), CostKind) +
315 TTI.getCmpSelInstrCost(
316 Instruction::ICmp, IntTy, CmpInst::makeCmpResultType(IntTy),
318 CostKind, TTI.getOperandInfo(Root), TTI.getOperandInfo(CmpRHS),
319 CmpI);
320}
321
322static InstructionCost
326 assert((Kind == RecurKind::And || Kind == RecurKind::Or) &&
327 VectorTy->getElementType()->isIntegerTy(1) &&
328 "Expected and/or reduction of i1");
329 auto *IntTy =
330 IntegerType::get(VectorTy->getContext(), getNumElements(VectorTy));
331 CmpInst::Predicate Pred =
333 // The compare is against the all-ones (and) or zero (or) constant.
334 return TTI.getCastInstrCost(Instruction::BitCast, IntTy, VectorTy, Ctx,
335 CostKind) +
336 TTI.getCmpSelInstrCost(Instruction::ICmp, IntTy,
337 CmpInst::makeCmpResultType(IntTy), Pred,
338 CostKind, /*Op1Info=*/{},
340}
341
342std::pair<InstructionCost, bool>
344 FixedVectorType *VectorTy, Type *ScalarTy,
346 unsigned RdxOpcode = RecurrenceDescriptor::getOpcode(Kind);
347 if (Kind == RecurKind::And || Kind == RecurKind::Or) {
348 InstructionCost RdxCost = TTI.getArithmeticReductionCost(
349 RdxOpcode, VectorTy, std::nullopt, CostKind);
350 InstructionCost BitcastCost =
351 getBoolLogicRdxBitcastCost(Kind, TTI, VectorTy, Ctx, CostKind);
352 return {std::min(RdxCost, BitcastCost), BitcastCost < RdxCost};
353 }
354 assert(Kind == RecurKind::Add && !ScalarTy->isIntegerTy(1) &&
355 "Expected add reduction of zexted i1 values");
356 // The bitcast+ctpop form is estimated as the cheaper of the extended
357 // reduction cost, which models it for the zexted i1 add reduction, and the
358 // explicitly priced components, including the cast of the ctpop result to
359 // the destination type.
360 auto *IntTy =
361 IntegerType::get(VectorTy->getContext(), getNumElements(VectorTy));
362 InstructionCost ExplicitCost =
363 TTI.getCastInstrCost(Instruction::BitCast, IntTy, VectorTy, Ctx,
364 CostKind) +
365 TTI.getIntrinsicInstrCost(
366 IntrinsicCostAttributes(Intrinsic::ctpop, IntTy, {IntTy}), CostKind);
367 if (IntTy != ScalarTy)
368 ExplicitCost += TTI.getCastInstrCost(IntTy->getBitWidth() <
369 ScalarTy->getIntegerBitWidth()
370 ? Instruction::ZExt
371 : Instruction::Trunc,
372 ScalarTy, IntTy, Ctx, CostKind);
373 InstructionCost CtpopCost = std::min(
374 TTI.getExtendedReductionCost(RdxOpcode, /*IsUnsigned=*/true, ScalarTy,
375 VectorTy, std::nullopt, CostKind),
376 ExplicitCost);
377 // The plain form is the zext to the wide vector type plus the reduction.
378 auto *ExtTy = VectorType::get(ScalarTy, VectorTy);
379 InstructionCost ExtRdxCost =
380 TTI.getCastInstrCost(Instruction::ZExt, ExtTy, VectorTy, Ctx, CostKind) +
381 TTI.getArithmeticReductionCost(RdxOpcode, ExtTy, std::nullopt, CostKind);
382 return {std::min(ExtRdxCost, CtpopCost), CtpopCost <= ExtRdxCost};
383}
384
386 FixedVectorType *SrcTy, Type *ResultTy,
387 const BitPackInfo &Info, unsigned ZExtSrcWidth,
390 const TargetLibraryInfo *TLI,
391 const Instruction *CtxI, unsigned &ShiftWidth) {
392 unsigned BitWidth = SrcTy->getScalarSizeInBits();
393 unsigned NumElts = SrcTy->getNumElements();
394 uint64_t MaxAmt = *max_element(Info.LShrAmts);
395 // The shift amounts form a constant vector.
396 TTI::OperandValueInfo ShiftAmtInfo = {
399 all_of(Info.LShrAmts,
400 [](uint64_t A) { return A == 0 || isPowerOf2_64(A); })
402 : TTI::OP_None};
403 // After the shift the field content of each lane sits in the low bits of
404 // the lane, so the packing is a single byte shuffle of the shifted lanes.
405 // Pick the cheapest shift width: the narrowest type still holding the field
406 // content is not always the cheapest (e.g. missing narrow variable shifts).
407 Type *Int8Ty = Type::getInt8Ty(SrcTy->getContext());
408 assert(BitWidth % 8 == 0 &&
409 "The byte-multiple field width divides the result bit width.");
410 unsigned OutBytes = BitWidth / 8;
411 auto *PackTy = FixedVectorType::get(Int8Ty, OutBytes);
412 unsigned MinShiftWidth = 8;
413 while (MinShiftWidth < MaxAmt + Info.FieldWidth)
414 MinShiftWidth *= 2;
416 ShiftWidth = 0;
417 for (unsigned W2 = MinShiftWidth; W2 <= BitWidth; W2 *= 2) {
418 auto *ShiftTy = FixedVectorType::get(
419 IntegerType::get(SrcTy->getContext(), W2), NumElts);
420 unsigned BytesPerLane = W2 / 8;
421 unsigned InBytes = NumElts * BytesPerLane;
422 SmallVector<int> Mask =
423 getBitPackMask(Info, OutBytes, NumElts, BytesPerLane);
424 InstructionCost C = TTI.getCastInstrCost(Instruction::BitCast, ResultTy,
425 PackTy, CCH, CostKind);
426 // A plain byte reversal of the shifted lanes is a bswap, no shuffle.
427 if (ShuffleVectorInst::isReverseMask(Mask, InBytes)) {
428 IntrinsicCostAttributes CostAttrs(Intrinsic::bswap, ResultTy, {ResultTy});
429 C += TTI.getIntrinsicInstrCost(CostAttrs, CostKind);
430 } else if (!ShuffleVectorInst::isIdentityMask(Mask, InBytes)) {
431 C += TTI.getShuffleCost(
432 is_contained(Info.LaneOfField, BitPackInfo::NoLane)
435 PackTy, FixedVectorType::get(Int8Ty, InBytes), CostKind, Mask,
436 /*Index=*/0, /*SubTp=*/nullptr, /*Args=*/{}, CtxI);
437 }
438 if (W2 != BitWidth && W2 != ZExtSrcWidth)
439 C += TTI.getCastInstrCost(Instruction::Trunc, ShiftTy, SrcTy, CCH,
440 CostKind);
441 if (Info.needsShift())
442 C += TTI.getArithmeticInstrCost(Instruction::LShr, ShiftTy, CostKind,
443 /*Opd1Info=*/{}, ShiftAmtInfo,
444 /*Args=*/{}, CtxI, TLI);
445 if (C.isValid() && (!NewCost.isValid() || C < NewCost)) {
446 NewCost = C;
447 ShiftWidth = W2;
448 }
449 }
450 return NewCost;
451}
452
454 bool NeedMask, Type *NarrowScalarTy,
455 Type *WideTy, unsigned VF,
456 ArrayRef<int> PermMask, const Value *Root,
458 auto *NarrowVecTy = cast<VectorType>(getWidenedType(NarrowScalarTy, VF));
459 Type *CmpTy = CmpInst::makeCmpResultType(NarrowVecTy);
460 auto *MaskTy = IntegerType::get(WideTy->getContext(), VF);
461 // The result cast inherits the uses of the reduction root.
463 const auto *CtxI = cast<Instruction>(Root);
465 if (NeedMask)
466 Cost += TTI.getArithmeticInstrCost(
467 Instruction::And, NarrowVecTy, CostKind,
470 if (!ShuffleVectorInst::isIdentityMask(PermMask, VF))
472 PermMask);
473 if (!NarrowScalarTy->isIntegerTy(1))
474 Cost += TTI.getCmpSelInstrCost(
475 Instruction::ICmp, NarrowVecTy, CmpTy, CmpInst::ICMP_NE, CostKind,
478 // Only the final cast inherits the uses of the reduction root.
479 Cost += TTI.getCastInstrCost(
480 Instruction::BitCast, MaskTy, CmpTy,
481 MaskTy == WideTy ? CCH : TTI::CastContextHint::None, CostKind);
482 if (MaskTy != WideTy)
483 Cost +=
484 TTI.getCastInstrCost(Instruction::ZExt, WideTy, MaskTy, CCH, CostKind);
485 return Cost;
486}
487
490 const SmallDenseMap<Value *, NarrowedLeafInfo> &NarrowedLeafShifts,
491 VectorType *NarrowVecTy, VectorType *WideVecTy, const Instruction *CtxI,
494 if (any_of(NarrowedLeafShifts,
495 [](const auto &P) { return P.second.Shift != 0; }))
496 Cost += TTI.getArithmeticInstrCost(
497 Instruction::Shl, WideVecTy, CostKind, {TTI::OK_AnyValue, TTI::OP_None},
498 {TTI::OK_NonUniformConstantValue, TTI::OP_None}, {}, CtxI);
499 if (any_of(NarrowedLeafShifts,
500 [](const auto &P) { return !P.second.Mask.isAllOnes(); }))
501 Cost += TTI.getArithmeticInstrCost(
502 Instruction::And, NarrowVecTy, CostKind,
503 {TTI::OK_AnyValue, TTI::OP_None},
504 {TTI::OK_NonUniformConstantValue, TTI::OP_None}, {}, CtxI);
505 return Cost;
506}
507} // namespace llvm::slpvectorizer
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")))
#define I(x, y, z)
Definition MD5.cpp:57
#define P(N)
This file contains some templates that are useful if you are working with the STL at all.
Provides some synthesis utilities to produce sequences of values.
This file defines the SmallVector class.
Class for arbitrary precision integers.
Definition APInt.h:78
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1508
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
const T & front() const
Get the first element.
Definition ArrayRef.h:144
iterator end() const
Definition ArrayRef.h:130
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
@ ICMP_NE
not equal
Definition InstrTypes.h:762
This is an important base class in LLVM.
Definition Constant.h:43
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.
Definition FMF.h:23
Class to represent fixed width SIMD vectors.
unsigned getNumElements() const
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:843
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.
Definition Type.cpp:338
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.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
TargetCostKind
The kind of cost model.
llvm::VectorInstrContext VectorInstrContext
@ TCC_Free
Expected to fold away in lowering.
ShuffleKind
The various kinds of shuffle patterns for vector queries.
@ SK_InsertSubvector
InsertSubvector. Index indicates start offset.
@ SK_PermuteSingleSrc
Shuffle elements of single source vector with any shuffle mask.
@ SK_PermuteTwoSrc
Merge elements from two source vectors into one with any shuffle mask.
@ SK_ExtractSubvector
ExtractSubvector Index indicates start offset.
CastContextHint
Represents a hint about the context in which a cast is used.
@ Masked
The cast is used with a masked load/store.
@ Normal
The cast is used with a normal load/store.
@ GatherScatter
The cast is used with a gather/scatter.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM_ABI unsigned getIntegerBitWidth() const
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Definition Type.cpp:297
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:363
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition Type.h:130
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
Definition Type.cpp:296
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:252
LLVM Value Representation.
Definition Value.h:75
user_iterator user_begin()
Definition Value.h:404
bool hasOneUse() const
Return true if there is exactly one use of this value.
Definition Value.h:441
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.
Definition TypeSize.h:165
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)
Definition SLPUtils.cpp:88
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 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.
Definition STLExtras.h:1755
InstructionCost Cost
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.
Definition Casting.h:643
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.
Definition STLExtras.h:366
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1762
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...
Definition Casting.h:547
TargetTransformInfo TTI
RecurKind
These are the kinds of recurrences that we support.
@ Or
Bitwise or logical OR of integers.
@ And
Bitwise or logical AND of integers.
@ Add
Sum of integers.
auto max_element(R &&Range)
Provide wrappers to std::max_element which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:2104
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1788
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:341
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
bool all_equal(std::initializer_list< T > Values)
Returns true if all Values in the initializer lists are equal or the list.
Definition STLExtras.h:2182
constexpr detail::IsaCheckPredicate< Types... > IsaPred
Function object wrapper for the llvm::isa type check.
Definition Casting.h:866
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Describe known properties for a set of pointers.
unsigned IsSameBaseAddress
All the GEPs in a set have same base address.
Description of a bitfield packing of vector lanes into a scalar value: every lane contributes a disjo...
Definition SLPUtils.h:466
static constexpr unsigned NoLane
Definition SLPUtils.h:467