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, /*CxtI=*/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 /*CxtI=*/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 ScalarCost =
127 TTI.getPointersChainCost(Ptrs, BasePtr, PtrsInfo, ScalarTy, CostKind);
128 auto *BaseGEP = dyn_cast<GEPOperator>(BasePtr);
129 if (!BaseGEP) {
130 auto *It = find_if(Ptrs, IsaPred<GEPOperator>);
131 if (It != Ptrs.end())
132 BaseGEP = cast<GEPOperator>(*It);
133 }
134 if (BaseGEP) {
135 SmallVector<const Value *> Indices(BaseGEP->indices());
136 VecCost = TTI.getGEPCost(BaseGEP->getSourceElementType(),
137 BaseGEP->getPointerOperand(), Indices, CostKind,
138 VecTy);
139 }
140 }
141
142 return std::make_pair(ScalarCost, VecCost);
143}
144
146 Align Alignment, unsigned AddressSpace,
148 Type *CmpTy = CmpInst::makeCmpResultType(VecTy);
149 return 2 * TTI.getMemIntrinsicInstrCost(
150 MemIntrinsicCostAttributes(Intrinsic::masked_load, VecTy,
151 Alignment, AddressSpace),
152 CostKind) +
153 TTI.getArithmeticInstrCost(Instruction::Xor, CmpTy, CostKind) +
154 TTI.getCmpSelInstrCost(Instruction::Select, VecTy, CmpTy,
156}
157
159 unsigned Opcode, Type *ScalarTy,
160 unsigned NumElts,
162 FixedVectorType **PaddedTy) {
163 FixedVectorType *PaddedVecTy =
164 getMaskedDivRemType(TTI, Opcode, ScalarTy, NumElts, ReVec);
165 if (!PaddedVecTy)
167 // One mask bit per element of the padded vector, not per padded lane.
168 auto *MaskTy =
170 PaddedVecTy->getNumElements());
171 InstructionCost DirectCost = TTI.getArithmeticInstrCost(
172 Opcode, getWidenedType(ScalarTy, NumElts), CostKind);
173 IntrinsicCostAttributes ICA(getMaskedDivRemIntrinsic(Opcode), PaddedVecTy,
174 {PaddedVecTy, PaddedVecTy, MaskTy});
175 InstructionCost MaskedCost = TTI.getIntrinsicInstrCost(ICA, CostKind);
176 if (!MaskedCost.isValid() || MaskedCost >= DirectCost)
178 if (PaddedTy)
179 *PaddedTy = PaddedVecTy;
180 return MaskedCost;
181}
182
185 Type *ScalarTy, VectorType *Ty,
186 const APInt &DemandedElts, bool Insert, bool Extract,
187 const TTI::TargetCostKind CostKind, bool ForPoisonSrc,
190 "ScalableVectorType is not supported.");
191 assert(getNumElements(ScalarTy) * DemandedElts.getBitWidth() ==
192 getNumElements(Ty) &&
193 "Incorrect usage.");
194 if (auto *VecTy = dyn_cast<FixedVectorType>(ScalarTy)) {
195 assert(ReVec && "Only supported by REVEC.");
196 // If ScalarTy is FixedVectorType, we should use CreateInsertVector instead
197 // of CreateInsertElement.
198 unsigned ScalarTyNumElements = VecTy->getNumElements();
200 for (unsigned I : seq(DemandedElts.getBitWidth())) {
201 if (!DemandedElts[I])
202 continue;
203 if (Insert)
205 I * ScalarTyNumElements, VecTy);
206 if (Extract)
208 I * ScalarTyNumElements, VecTy);
209 }
210 return Cost;
211 }
212 return TTI.getScalarizationOverhead(Ty, DemandedElts, Insert, Extract,
213 CostKind, ForPoisonSrc, VL, VIC);
214}
215
217 const TargetTransformInfo &TTI, bool ReVec, Type *ScalarTy, unsigned Opcode,
218 Type *Val, const TTI::TargetCostKind CostKind, unsigned Index,
219 Value *Scalar, ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx,
221 if (Opcode == Instruction::ExtractElement) {
222 if (auto *VecTy = dyn_cast<FixedVectorType>(ScalarTy)) {
223 assert(ReVec && "Only supported by REVEC.");
224 assert(isa<VectorType>(Val) && "Val must be a vector type.");
226 cast<VectorType>(Val), CostKind, {},
227 Index * VecTy->getNumElements(), VecTy);
228 }
229 }
230 return TTI.getVectorInstrCost(Opcode, Val, CostKind, Index, Scalar,
231 ScalarUserAndIdx, VIC);
232}
233
235 bool ReVec, unsigned Opcode, Type *Dst,
236 VectorType *VecTy, unsigned Index,
238 if (isVectorizedTy(Dst)) {
239 assert(ReVec && "Only supported by REVEC.");
240 auto *SubTp = cast<FixedVectorType>(
243 Index * getNumElements(Dst), SubTp) +
244 TTI.getCastInstrCost(Opcode, Dst, SubTp, TTI::CastContextHint::None,
245 CostKind);
246 }
247 return TTI.getExtractWithExtendCost(Opcode, Dst, VecTy, Index, CostKind);
248}
249
250/// Returns the cast context hint for the trunc of the booleanized reduction
251/// result, which inherits the uses of the reduction root \p Root.
264
266 RecurKind RdxKind,
267 FixedVectorType *VecTy,
268 const Value *Root, FastMathFlags FMF,
270 Type *I1Ty = Type::getInt1Ty(VecTy->getContext());
271 return TTI.getArithmeticReductionCost(
272 RecurrenceDescriptor::getOpcode(RdxKind), VecTy, FMF, CostKind) +
273 TTI.getCastInstrCost(Instruction::Trunc, I1Ty, VecTy->getScalarType(),
275}
276
278 RecurKind RdxKind,
279 FixedVectorType *VecTy,
280 const Value *Root,
281 ArrayRef<Instruction *> ChainInsts,
283 // The new instructions are costed in the context of the replaced cast chain
284 // instructions.
285 auto TruncIt =
286 find_if(ChainInsts, [](Instruction *I) { return isa<TruncInst>(I); });
287 const Instruction *TruncI = TruncIt == ChainInsts.end() ? nullptr : *TruncIt;
288 auto CmpIt =
289 find_if(ChainInsts, [](Instruction *I) { return isa<ICmpInst>(I); });
290 const Instruction *CmpI = CmpIt == ChainInsts.end() ? nullptr : *CmpIt;
291 unsigned VF = VecTy->getNumElements();
292 auto *I1VecTy =
294 Type *IntTy = IntegerType::get(VecTy->getContext(), VF);
295 Constant *CmpRHS = RdxKind == RecurKind::And
297 : Constant::getNullValue(IntTy);
298 return TTI.getCastInstrCost(Instruction::Trunc, I1VecTy, VecTy,
299 TTI.getCastContextHint(TruncI), CostKind,
300 TruncI) +
301 TTI.getCastInstrCost(Instruction::BitCast, IntTy, I1VecTy,
302 TTI.getCastContextHint(TruncI), CostKind) +
303 TTI.getCmpSelInstrCost(
304 Instruction::ICmp, IntTy, CmpInst::makeCmpResultType(IntTy),
306 CostKind, TTI.getOperandInfo(Root), TTI.getOperandInfo(CmpRHS),
307 CmpI);
308}
309
310static InstructionCost
314 assert((Kind == RecurKind::And || Kind == RecurKind::Or) &&
315 VectorTy->getElementType()->isIntegerTy(1) &&
316 "Expected and/or reduction of i1");
317 auto *IntTy =
318 IntegerType::get(VectorTy->getContext(), getNumElements(VectorTy));
319 CmpInst::Predicate Pred =
321 // The compare is against the all-ones (and) or zero (or) constant.
322 return TTI.getCastInstrCost(Instruction::BitCast, IntTy, VectorTy, Ctx,
323 CostKind) +
324 TTI.getCmpSelInstrCost(Instruction::ICmp, IntTy,
325 CmpInst::makeCmpResultType(IntTy), Pred,
326 CostKind, /*Op1Info=*/{},
328}
329
330std::pair<InstructionCost, bool>
332 FixedVectorType *VectorTy, Type *ScalarTy,
334 unsigned RdxOpcode = RecurrenceDescriptor::getOpcode(Kind);
335 if (Kind == RecurKind::And || Kind == RecurKind::Or) {
336 InstructionCost RdxCost = TTI.getArithmeticReductionCost(
337 RdxOpcode, VectorTy, std::nullopt, CostKind);
338 InstructionCost BitcastCost =
339 getBoolLogicRdxBitcastCost(Kind, TTI, VectorTy, Ctx, CostKind);
340 return {std::min(RdxCost, BitcastCost), BitcastCost < RdxCost};
341 }
342 assert(Kind == RecurKind::Add && !ScalarTy->isIntegerTy(1) &&
343 "Expected add reduction of zexted i1 values");
344 // The bitcast+ctpop form is estimated as the cheaper of the extended
345 // reduction cost, which models it for the zexted i1 add reduction, and the
346 // explicitly priced components, including the cast of the ctpop result to
347 // the destination type.
348 auto *IntTy =
349 IntegerType::get(VectorTy->getContext(), getNumElements(VectorTy));
350 InstructionCost ExplicitCost =
351 TTI.getCastInstrCost(Instruction::BitCast, IntTy, VectorTy, Ctx,
352 CostKind) +
353 TTI.getIntrinsicInstrCost(
354 IntrinsicCostAttributes(Intrinsic::ctpop, IntTy, {IntTy}), CostKind);
355 if (IntTy != ScalarTy)
356 ExplicitCost += TTI.getCastInstrCost(IntTy->getBitWidth() <
357 ScalarTy->getIntegerBitWidth()
358 ? Instruction::ZExt
359 : Instruction::Trunc,
360 ScalarTy, IntTy, Ctx, CostKind);
361 InstructionCost CtpopCost = std::min(
362 TTI.getExtendedReductionCost(RdxOpcode, /*IsUnsigned=*/true, ScalarTy,
363 VectorTy, std::nullopt, CostKind),
364 ExplicitCost);
365 // The plain form is the zext to the wide vector type plus the reduction.
366 auto *ExtTy = VectorType::get(ScalarTy, VectorTy);
367 InstructionCost ExtRdxCost =
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};
371}
372
374 FixedVectorType *SrcTy, Type *ResultTy,
375 const BitPackInfo &Info, unsigned ZExtSrcWidth,
378 const TargetLibraryInfo *TLI,
379 const Instruction *CxtI, unsigned &ShiftWidth) {
380 unsigned BitWidth = SrcTy->getScalarSizeInBits();
381 unsigned NumElts = SrcTy->getNumElements();
382 uint64_t MaxAmt = *max_element(Info.LShrAmts);
383 // The shift amounts form a constant vector.
384 TTI::OperandValueInfo ShiftAmtInfo = {
387 all_of(Info.LShrAmts,
388 [](uint64_t A) { return A == 0 || isPowerOf2_64(A); })
390 : TTI::OP_None};
391 // After the shift the field content of each lane sits in the low bits of
392 // the lane, so the packing is a single byte shuffle of the shifted lanes.
393 // Pick the cheapest shift width: the narrowest type still holding the field
394 // content is not always the cheapest (e.g. missing narrow variable shifts).
395 Type *Int8Ty = Type::getInt8Ty(SrcTy->getContext());
396 assert(BitWidth % 8 == 0 &&
397 "The byte-multiple field width divides the result bit width.");
398 unsigned OutBytes = BitWidth / 8;
399 auto *PackTy = FixedVectorType::get(Int8Ty, OutBytes);
400 unsigned MinShiftWidth = 8;
401 while (MinShiftWidth < MaxAmt + Info.FieldWidth)
402 MinShiftWidth *= 2;
404 ShiftWidth = 0;
405 for (unsigned W2 = MinShiftWidth; W2 <= BitWidth; W2 *= 2) {
406 auto *ShiftTy = FixedVectorType::get(
407 IntegerType::get(SrcTy->getContext(), W2), NumElts);
408 unsigned BytesPerLane = W2 / 8;
409 unsigned InBytes = NumElts * BytesPerLane;
410 SmallVector<int> Mask =
411 getBitPackMask(Info, OutBytes, NumElts, BytesPerLane);
412 InstructionCost C = TTI.getCastInstrCost(Instruction::BitCast, ResultTy,
413 PackTy, CCH, CostKind);
414 // A plain byte reversal of the shifted lanes is a bswap, no shuffle.
415 if (ShuffleVectorInst::isReverseMask(Mask, InBytes)) {
416 IntrinsicCostAttributes CostAttrs(Intrinsic::bswap, ResultTy, {ResultTy});
417 C += TTI.getIntrinsicInstrCost(CostAttrs, CostKind);
418 } else if (!ShuffleVectorInst::isIdentityMask(Mask, InBytes)) {
419 C += TTI.getShuffleCost(
420 is_contained(Info.LaneOfField, BitPackInfo::NoLane)
423 PackTy, FixedVectorType::get(Int8Ty, InBytes), CostKind, Mask,
424 /*Index=*/0, /*SubTp=*/nullptr, /*Args=*/{}, CxtI);
425 }
426 if (W2 != BitWidth && W2 != ZExtSrcWidth)
427 C += TTI.getCastInstrCost(Instruction::Trunc, ShiftTy, SrcTy, CCH,
428 CostKind);
429 if (Info.needsShift())
430 C += TTI.getArithmeticInstrCost(Instruction::LShr, ShiftTy, CostKind,
431 /*Opd1Info=*/{}, ShiftAmtInfo,
432 /*Args=*/{}, CxtI, TLI);
433 if (C.isValid() && (!NewCost.isValid() || C < NewCost)) {
434 NewCost = C;
435 ShiftWidth = W2;
436 }
437 }
438 return NewCost;
439}
440
442 bool NeedMask, Type *NarrowScalarTy,
443 Type *WideTy, unsigned VF,
444 ArrayRef<int> PermMask, const Value *Root,
446 auto *NarrowVecTy = cast<VectorType>(getWidenedType(NarrowScalarTy, VF));
447 Type *CmpTy = CmpInst::makeCmpResultType(NarrowVecTy);
448 auto *MaskTy = IntegerType::get(WideTy->getContext(), VF);
449 // The result cast inherits the uses of the reduction root.
451 const auto *CxtI = cast<Instruction>(Root);
453 if (NeedMask)
454 Cost += TTI.getArithmeticInstrCost(
455 Instruction::And, NarrowVecTy, CostKind,
458 if (!ShuffleVectorInst::isIdentityMask(PermMask, VF))
460 PermMask);
461 if (!NarrowScalarTy->isIntegerTy(1))
462 Cost += TTI.getCmpSelInstrCost(
463 Instruction::ICmp, NarrowVecTy, CmpTy, CmpInst::ICMP_NE, CostKind,
466 // Only the final cast inherits the uses of the reduction root.
467 Cost += TTI.getCastInstrCost(
468 Instruction::BitCast, MaskTy, CmpTy,
469 MaskTy == WideTy ? CCH : TTI::CastContextHint::None, CostKind);
470 if (MaskTy != WideTy)
471 Cost +=
472 TTI.getCastInstrCost(Instruction::ZExt, WideTy, MaskTy, CCH, CostKind);
473 return Cost;
474}
475
478 const SmallDenseMap<Value *, NarrowedLeafInfo> &NarrowedLeafShifts,
479 VectorType *NarrowVecTy, VectorType *WideVecTy, const Instruction *CxtI,
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);
493 return Cost;
494}
495} // 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
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.
@ None
The cast is not used with a load/store of any kind.
@ 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 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)
Definition SLPUtils.cpp:937
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:86
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.
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...
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.
Description of a bitfield packing of vector lanes into a scalar value: every lane contributes a disjo...
Definition SLPUtils.h:433
static constexpr unsigned NoLane
Definition SLPUtils.h:434