LLVM 24.0.0git
VectorUtils.h
Go to the documentation of this file.
1//===- llvm/Analysis/VectorUtils.h - Vector utilities -----------*- C++ -*-===//
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// This file defines some vectorizer utilities.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_ANALYSIS_VECTORUTILS_H
14#define LLVM_ANALYSIS_VECTORUTILS_H
15
16#include "llvm/ADT/MapVector.h"
17#include "llvm/ADT/STLExtras.h"
18#include "llvm/ADT/Sequence.h"
21#include "llvm/IR/Module.h"
26
27namespace llvm {
29class IntrinsicInst;
30
31/// The Vector Function Database.
32///
33/// Helper class used to find the vector functions associated to a
34/// scalar CallInst.
36 /// The Module of the CallInst CI.
37 const Module *M;
38 /// The CallInst instance being queried for scalar to vector mappings.
39 const CallInst &CI;
40 /// List of vector functions descriptors associated to the call
41 /// instruction.
42 const SmallVector<VFInfo, 8> ScalarToVectorMappings;
43
44 /// Retrieve the scalar-to-vector mappings associated to the rule of
45 /// a vector Function ABI.
46 static void getVFABIMappings(const CallInst &CI,
47 SmallVectorImpl<VFInfo> &Mappings) {
48 if (!CI.getCalledFunction())
49 return;
50
51 const StringRef ScalarName = CI.getCalledFunction()->getName();
52
53 SmallVector<std::string, 8> ListOfStrings;
54 // The check for the vector-function-abi-variant attribute is done when
55 // retrieving the vector variant names here.
56 VFABI::getVectorVariantNames(CI, ListOfStrings);
57 if (ListOfStrings.empty())
58 return;
59 for (const auto &MangledName : ListOfStrings) {
60 const std::optional<VFInfo> Shape =
61 VFABI::tryDemangleForVFABI(MangledName, CI.getFunctionType());
62 // A match is found via scalar and vector names, and also by
63 // ensuring that the variant described in the attribute has a
64 // corresponding definition or declaration of the vector
65 // function in the Module M.
66 if (Shape && (Shape->ScalarName == ScalarName)) {
67 assert(CI.getModule()->getFunction(Shape->VectorName) &&
68 "Vector function is missing.");
69 Mappings.push_back(*Shape);
70 }
71 }
72 }
73
74public:
75 /// Retrieve all the VFInfo instances associated to the CallInst CI.
78
79 // Get mappings from the Vector Function ABI variants.
80 getVFABIMappings(CI, Ret);
81
82 // Other non-VFABI variants should be retrieved here.
83
84 return Ret;
85 }
86
87 static bool hasMaskedVariant(const CallInst &CI,
88 std::optional<ElementCount> VF = std::nullopt) {
89 // Check whether we have at least one masked vector version of a scalar
90 // function. If no VF is specified then we check for any masked variant,
91 // otherwise we look for one that matches the supplied VF.
92 auto Mappings = VFDatabase::getMappings(CI);
93 for (VFInfo Info : Mappings)
94 if (!VF || Info.Shape.VF == *VF)
95 if (Info.isMasked())
96 return true;
97
98 return false;
99 }
100
101 /// Constructor, requires a CallInst instance.
103 : M(CI.getModule()), CI(CI),
104 ScalarToVectorMappings(VFDatabase::getMappings(CI)) {}
105
106 /// \defgroup VFDatabase query interface.
107 ///
108 /// @{
109 /// Retrieve the Function with VFShape \p Shape.
111 if (Shape == VFShape::getScalarShape(CI.getFunctionType()))
112 return CI.getCalledFunction();
113
114 for (const auto &Info : ScalarToVectorMappings)
115 if (Info.Shape == Shape)
116 return M->getFunction(Info.VectorName);
117
118 return nullptr;
119 }
120 /// @}
121};
122
123struct AnalysisOptions;
124template <typename T> class ArrayRef;
125class DemandedBits;
126template <typename InstTy> class InterleaveGroup;
127class IRBuilderBase;
128class Loop;
129class TargetTransformInfo;
130class Value;
131
132namespace Intrinsic {
133typedef unsigned ID;
134}
135
136/// The kind of update operation performed on the buckets of a histogram, i.e.
137/// buckets[indices[i]] = UpdateOp(buckets[indices[i]], Val).
145
146/// Identify if the intrinsic is trivially vectorizable.
147/// This method returns true if the intrinsic's argument types are all scalars
148/// for the scalar form of the intrinsic and all vectors (or scalars handled by
149/// isVectorIntrinsicWithScalarOpAtArg) for the vector form of the intrinsic.
150///
151/// Note: isTriviallyVectorizable implies isTriviallyScalarizable.
153
154/// Identify if the intrinsic is trivially scalarizable.
155/// This method returns true following the same predicates of
156/// isTriviallyVectorizable.
157
158/// Note: There are intrinsics where implementing vectorization for the
159/// intrinsic is redundant, but we want to implement scalarization of the
160/// vector. To prevent the requirement that an intrinsic also implements
161/// vectorization we provide this separate function.
163
164/// Identifies if the vector form of the intrinsic has a scalar operand.
165/// \p TTI is used to consider target specific intrinsics, if no target specific
166/// intrinsics will be considered then it is appropriate to pass in nullptr.
167LLVM_ABI bool
168isVectorIntrinsicWithScalarOpAtArg(Intrinsic::ID ID, unsigned ScalarOpdIdx,
169 const TargetTransformInfo *TTI);
170
171/// Identifies if the vector form of the intrinsic is overloaded on the type of
172/// the operand at index \p OpdIdx, or on the return type if \p OpdIdx is -1.
173/// \p TTI is used to consider target specific intrinsics, if no target specific
174/// intrinsics will be considered then it is appropriate to pass in nullptr.
175LLVM_ABI bool
177 const TargetTransformInfo *TTI);
178
179/// Returns the argument index of the pointer parameter for the vector memory
180/// intrinsic \p ID, or `std::nullopt` if the intrinsic does not have a pointer
181/// operand.
182LLVM_ABI std::optional<unsigned>
184
185/// Returns the argument index of the data value of the vector store intrinsic
186/// \p ID, or `std::nullopt` if the intrinsic does not have a data operand.
187LLVM_ABI std::optional<unsigned>
189
190/// Returns the argument index of the mask for the vector intrinsic \p ID, or
191/// `std::nullopt` if the intrinsic does not have a mask operand.
192LLVM_ABI std::optional<unsigned> getVectorIntrinsicMaskArgIdx(Intrinsic::ID ID);
193
194/// Identifies if the vector form of the intrinsic that returns a struct is
195/// overloaded at the struct element index \p RetIdx. /// \p TTI is used to
196/// consider target specific intrinsics, if no target specific intrinsics
197/// will be considered then it is appropriate to pass in nullptr.
199 Intrinsic::ID ID, int RetIdx, const TargetTransformInfo *TTI);
200
201/// Returns intrinsic ID for call.
202/// For the input call instruction it finds mapping intrinsic and returns
203/// its intrinsic ID, in case it does not found it return not_intrinsic.
205getVectorIntrinsicIDForCall(const CallInst *CI, const TargetLibraryInfo *TLI);
206
207/// Returns true if the vector llvm.sincos with \p ScalarTy elements and \p EC
208/// element count has no vector library mapping, but both llvm.sin and llvm.cos
209/// have, so it is split into the separate vector sin and cos library calls.
210LLVM_ABI bool shouldSplitVectorSinCos(const TargetLibraryInfo &TLI,
211 Type *ScalarTy, ElementCount EC,
212 Module *M);
213
214/// Returns the corresponding factor of llvm.vector.interleaveN intrinsics.
216
217/// Returns the corresponding factor of llvm.vector.deinterleaveN intrinsics.
219
220/// Given a deinterleaveN intrinsic, return the (narrow) vector type of each
221/// factor.
223
224/// Given a vector and an element number, see if the scalar value is
225/// already around as a register, for example if it were inserted then extracted
226/// from the vector.
227LLVM_ABI Value *findScalarElement(Value *V, unsigned EltNo);
228
229/// If all non-negative \p Mask elements are the same value, return that value.
230/// If all elements are negative (undefined) or \p Mask contains different
231/// non-negative values, return -1.
232LLVM_ABI int getSplatIndex(ArrayRef<int> Mask);
233
234/// Get splat value if the input is a splat vector or return nullptr.
235/// The value may be extracted from a splat constants vector or from
236/// a sequence of instructions that broadcast a single value into a vector.
237LLVM_ABI Value *getSplatValue(const Value *V);
238
239/// Return true if each element of the vector value \p V is poisoned or equal to
240/// every other non-poisoned element. If an index element is specified, either
241/// every element of the vector is poisoned or the element at that index is not
242/// poisoned and equal to every other non-poisoned element.
243/// This may be more powerful than the related getSplatValue() because it is
244/// not limited by finding a scalar source value to a splatted vector.
245LLVM_ABI bool isSplatValue(const Value *V, int Index = -1, unsigned Depth = 0);
246
247/// Transform a shuffle mask's output demanded element mask into demanded
248/// element masks for the 2 operands, returns false if the mask isn't valid.
249/// Both \p DemandedLHS and \p DemandedRHS are initialised to [SrcWidth].
250/// \p AllowUndefElts permits "-1" indices to be treated as undef.
251LLVM_ABI bool getShuffleDemandedElts(int SrcWidth, ArrayRef<int> Mask,
252 const APInt &DemandedElts,
253 APInt &DemandedLHS, APInt &DemandedRHS,
254 bool AllowUndefElts = false);
255
256/// Does this shuffle mask represent either one slide shuffle or a pair of
257/// two slide shuffles, combined with a select on some constant vector mask?
258/// A slide is a shuffle mask which shifts some set of elements up or down
259/// the vector, with all other elements being undefined. An identity shuffle
260/// will be matched a slide by 0. The output parameter provides the source
261/// (-1 means no source), and slide direction for each slide.
262LLVM_ABI bool isMaskedSlidePair(ArrayRef<int> Mask, int NumElts,
263 std::array<std::pair<int, int>, 2> &SrcInfo);
264
265/// Replace each shuffle mask index with the scaled sequential indices for an
266/// equivalent mask of narrowed elements. Mask elements that are less than 0
267/// (sentinel values) are repeated in the output mask.
268///
269/// Example with Scale = 4:
270/// <4 x i32> <3, 2, 0, -1> -->
271/// <16 x i8> <12, 13, 14, 15, 8, 9, 10, 11, 0, 1, 2, 3, -1, -1, -1, -1>
272///
273/// This is the reverse process of widening shuffle mask elements, but it always
274/// succeeds because the indexes can always be multiplied (scaled up) to map to
275/// narrower vector elements.
276LLVM_ABI void narrowShuffleMaskElts(int Scale, ArrayRef<int> Mask,
277 SmallVectorImpl<int> &ScaledMask);
278
279/// Try to transform a shuffle mask by replacing elements with the scaled index
280/// for an equivalent mask of widened elements. If all mask elements that would
281/// map to a wider element of the new mask are the same negative number
282/// (sentinel value), that element of the new mask is the same value. If any
283/// element in a given slice is negative and some other element in that slice is
284/// not the same value, return false (partial matches with sentinel values are
285/// not allowed).
286///
287/// Example with Scale = 4:
288/// <16 x i8> <12, 13, 14, 15, 8, 9, 10, 11, 0, 1, 2, 3, -1, -1, -1, -1> -->
289/// <4 x i32> <3, 2, 0, -1>
290///
291/// This is the reverse process of narrowing shuffle mask elements if it
292/// succeeds. This transform is not always possible because indexes may not
293/// divide evenly (scale down) to map to wider vector elements.
294LLVM_ABI bool widenShuffleMaskElts(int Scale, ArrayRef<int> Mask,
295 SmallVectorImpl<int> &ScaledMask);
296
297/// A variant of the previous method which is specialized for Scale=2, and
298/// treats -1 as undef and allows widening when a wider element is partially
299/// undef in the narrow form of the mask. This transformation discards
300/// information about which bytes in the original shuffle were undef.
301LLVM_ABI bool widenShuffleMaskElts(ArrayRef<int> M,
302 SmallVectorImpl<int> &NewMask);
303
304/// Attempt to narrow/widen the \p Mask shuffle mask to the \p NumDstElts target
305/// width. Internally this will call narrowShuffleMaskElts/widenShuffleMaskElts.
306/// This will assert unless NumDstElts is a multiple of Mask.size (or
307/// vice-versa). Returns false on failure, and ScaledMask will be in an
308/// undefined state.
309LLVM_ABI bool scaleShuffleMaskElts(unsigned NumDstElts, ArrayRef<int> Mask,
310 SmallVectorImpl<int> &ScaledMask);
311
312/// Repetitively apply `widenShuffleMaskElts()` for as long as it succeeds,
313/// to get the shuffle mask with widest possible elements.
314LLVM_ABI void getShuffleMaskWithWidestElts(ArrayRef<int> Mask,
315 SmallVectorImpl<int> &ScaledMask);
316
317/// Splits and processes shuffle mask depending on the number of input and
318/// output registers. The function does 2 main things: 1) splits the
319/// source/destination vectors into real registers; 2) do the mask analysis to
320/// identify which real registers are permuted. Then the function processes
321/// resulting registers mask using provided action items. If no input register
322/// is defined, \p NoInputAction action is used. If only 1 input register is
323/// used, \p SingleInputAction is used, otherwise \p ManyInputsAction is used to
324/// process > 2 input registers and masks.
325/// \param Mask Original shuffle mask.
326/// \param NumOfSrcRegs Number of source registers.
327/// \param NumOfDestRegs Number of destination registers.
328/// \param NumOfUsedRegs Number of actually used destination registers.
330 ArrayRef<int> Mask, unsigned NumOfSrcRegs, unsigned NumOfDestRegs,
331 unsigned NumOfUsedRegs, function_ref<void()> NoInputAction,
332 function_ref<void(ArrayRef<int>, unsigned, unsigned)> SingleInputAction,
333 function_ref<void(ArrayRef<int>, unsigned, unsigned, bool)>
334 ManyInputsAction);
335
336/// Compute the demanded elements mask of horizontal binary operations. A
337/// horizontal operation combines two adjacent elements in a vector operand.
338/// This function returns a mask for the elements that correspond to the first
339/// operand of this horizontal combination. For example, for two vectors
340/// [X1, X2, X3, X4] and [Y1, Y2, Y3, Y4], the resulting mask can include the
341/// elements X1, X3, Y1, and Y3. To get the other operands, simply shift the
342/// result of this function to the left by 1.
343///
344/// \param VectorBitWidth the total bit width of the vector
345/// \param DemandedElts the demanded elements mask for the operation
346/// \param DemandedLHS the demanded elements mask for the left operand
347/// \param DemandedRHS the demanded elements mask for the right operand
348LLVM_ABI void getHorizDemandedEltsForFirstOperand(unsigned VectorBitWidth,
349 const APInt &DemandedElts,
350 APInt &DemandedLHS,
351 APInt &DemandedRHS);
352
353/// Compute a map of integer instructions to their minimum legal type
354/// size.
355///
356/// C semantics force sub-int-sized values (e.g. i8, i16) to be promoted to int
357/// type (e.g. i32) whenever arithmetic is performed on them.
358///
359/// For targets with native i8 or i16 operations, usually InstCombine can shrink
360/// the arithmetic type down again. However InstCombine refuses to create
361/// illegal types, so for targets without i8 or i16 registers, the lengthening
362/// and shrinking remains.
363///
364/// Most SIMD ISAs (e.g. NEON) however support vectors of i8 or i16 even when
365/// their scalar equivalents do not, so during vectorization it is important to
366/// remove these lengthens and truncates when deciding the profitability of
367/// vectorization.
368///
369/// This function analyzes the given range of instructions and determines the
370/// minimum type size each can be converted to. It attempts to remove or
371/// minimize type size changes across each def-use chain, so for example in the
372/// following code:
373///
374/// %1 = load i8, i8*
375/// %2 = add i8 %1, 2
376/// %3 = load i16, i16*
377/// %4 = zext i8 %2 to i32
378/// %5 = zext i16 %3 to i32
379/// %6 = add i32 %4, %5
380/// %7 = trunc i32 %6 to i16
381///
382/// Instruction %6 must be done at least in i16, so computeMinimumValueSizes
383/// will return: {%1: 16, %2: 16, %3: 16, %4: 16, %5: 16, %6: 16, %7: 16}.
384///
385/// If the optional TargetTransformInfo is provided, this function tries harder
386/// to do less work by only looking at illegal types.
387LLVM_ABI MapVector<Instruction *, uint64_t>
388computeMinimumValueSizes(ArrayRef<BasicBlock *> Blocks, DemandedBits &DB,
389 const TargetTransformInfo *TTI = nullptr);
390
391/// Compute the union of two access-group lists.
392///
393/// If the list contains just one access group, it is returned directly. If the
394/// list is empty, returns nullptr.
395LLVM_ABI MDNode *uniteAccessGroups(MDNode *AccGroups1, MDNode *AccGroups2);
396
397/// Compute the access-group list of access groups that @p Inst1 and @p Inst2
398/// are both in. If either instruction does not access memory at all, it is
399/// considered to be in every list.
400///
401/// If the list contains just one access group, it is returned directly. If the
402/// list is empty, returns nullptr.
403LLVM_ABI MDNode *intersectAccessGroups(const Instruction *Inst1,
404 const Instruction *Inst2);
405
406/// Add metadata from \p Inst to \p Metadata, if it can be preserved after
407/// vectorization. It can be preserved after vectorization if the kind is one of
408/// [MD_tbaa, MD_alias_scope, MD_noalias, MD_fpmath, MD_nontemporal,
409/// MD_access_group, MD_mmra].
411 Instruction *Inst,
412 SmallVectorImpl<std::pair<unsigned, MDNode *>> &Metadata);
413
414/// Specifically, let Kinds = [MD_tbaa, MD_alias_scope, MD_noalias, MD_fpmath,
415/// MD_nontemporal, MD_access_group, MD_mmra].
416/// For K in Kinds, we get the MDNode for K from each of the
417/// elements of VL, compute their "intersection" (i.e., the most generic
418/// metadata value that covers all of the individual values), and set I's
419/// metadata for M equal to the intersection value.
420///
421/// This function always sets a (possibly null) value for each K in Kinds.
422LLVM_ABI Instruction *propagateMetadata(Instruction *I, ArrayRef<Value *> VL);
423
424/// Create a mask that filters the members of an interleave group where there
425/// are gaps.
426///
427/// For example, the mask for \p Group with interleave-factor 3
428/// and \p VF 4, that has only its first member present is:
429///
430/// <1,0,0,1,0,0,1,0,0,1,0,0>
431///
432/// Note: The result is a mask of 0's and 1's, as opposed to the other
433/// create[*]Mask() utilities which create a shuffle mask (mask that
434/// consists of indices).
435LLVM_ABI Constant *
436createBitMaskForGaps(IRBuilderBase &Builder, unsigned VF,
437 const InterleaveGroup<Instruction> &Group);
438
439/// Create a mask with replicated elements.
440///
441/// This function creates a shuffle mask for replicating each of the \p VF
442/// elements in a vector \p ReplicationFactor times. It can be used to
443/// transform a mask of \p VF elements into a mask of
444/// \p VF * \p ReplicationFactor elements used by a predicated
445/// interleaved-group of loads/stores whose Interleaved-factor ==
446/// \p ReplicationFactor.
447///
448/// For example, the mask for \p ReplicationFactor=3 and \p VF=4 is:
449///
450/// <0,0,0,1,1,1,2,2,2,3,3,3>
452createReplicatedMask(unsigned ReplicationFactor, unsigned VF);
453
454/// Create an interleave shuffle mask.
455///
456/// This function creates a shuffle mask for interleaving \p NumVecs vectors of
457/// vectorization factor \p VF into a single wide vector. The mask is of the
458/// form:
459///
460/// <0, VF, VF * 2, ..., VF * (NumVecs - 1), 1, VF + 1, VF * 2 + 1, ...>
461///
462/// For example, the mask for VF = 4 and NumVecs = 2 is:
463///
464/// <0, 4, 1, 5, 2, 6, 3, 7>.
466 unsigned NumVecs);
467
468/// Create a stride shuffle mask.
469///
470/// This function creates a shuffle mask whose elements begin at \p Start and
471/// are incremented by \p Stride. The mask can be used to deinterleave an
472/// interleaved vector into separate vectors of vectorization factor \p VF. The
473/// mask is of the form:
474///
475/// <Start, Start + Stride, ..., Start + Stride * (VF - 1)>
476///
477/// For example, the mask for Start = 0, Stride = 2, and VF = 4 is:
478///
479/// <0, 2, 4, 6>
481createStrideMask(unsigned Start, unsigned Stride, unsigned VF);
482
483/// Create a sequential shuffle mask.
484///
485/// This function creates shuffle mask whose elements are sequential and begin
486/// at \p Start. The mask contains \p NumInts integers and is padded with \p
487/// NumUndefs undef values. The mask is of the form:
488///
489/// <Start, Start + 1, ... Start + NumInts - 1, undef_1, ... undef_NumUndefs>
490///
491/// For example, the mask for Start = 0, NumInsts = 4, and NumUndefs = 4 is:
492///
493/// <0, 1, 2, 3, undef, undef, undef, undef>
495createSequentialMask(unsigned Start, unsigned NumInts, unsigned NumUndefs);
496
497/// Given a shuffle mask for a binary shuffle, create the equivalent shuffle
498/// mask assuming both operands are identical. This assumes that the unary
499/// shuffle will use elements from operand 0 (operand 1 will be unused).
501 unsigned NumElts);
502
503/// Concatenate a list of vectors.
504///
505/// This function generates code that concatenate the vectors in \p Vecs into a
506/// single large vector. The number of vectors should be greater than one, and
507/// their element types should be the same. The number of elements in the
508/// vectors should also be the same; however, if the last vector has fewer
509/// elements, it will be padded with undefs.
510LLVM_ABI Value *concatenateVectors(IRBuilderBase &Builder,
511 ArrayRef<Value *> Vecs);
512
513/// Given a mask vector of i1, Return true if any of the elements of this
514/// predicate mask are known to be true or undef. That is, return true if at
515/// least one lane can be assumed active.
516LLVM_ABI bool maskContainsAllOneOrUndef(Value *Mask);
517
518/// Given a mask vector of the form <Y x i1>, return an APInt (of bitwidth Y)
519/// for each lane which may be active.
520LLVM_ABI APInt possiblyDemandedEltsInMask(Value *Mask);
521
522/// The group of interleaved loads/stores sharing the same stride and
523/// close to each other.
524///
525/// Each member in this group has an index starting from 0, and the largest
526/// index should be less than interleaved factor, which is equal to the absolute
527/// value of the access's stride.
528///
529/// E.g. An interleaved load group of factor 4:
530/// for (unsigned i = 0; i < 1024; i+=4) {
531/// a = A[i]; // Member of index 0
532/// b = A[i+1]; // Member of index 1
533/// d = A[i+3]; // Member of index 3
534/// ...
535/// }
536///
537/// An interleaved store group of factor 4:
538/// for (unsigned i = 0; i < 1024; i+=4) {
539/// ...
540/// A[i] = a; // Member of index 0
541/// A[i+1] = b; // Member of index 1
542/// A[i+2] = c; // Member of index 2
543/// A[i+3] = d; // Member of index 3
544/// }
545///
546/// Note: the interleaved load group could have gaps (missing members), but
547/// the interleaved store group doesn't allow gaps.
548template <typename InstTy> class InterleaveGroup {
549public:
550 InterleaveGroup(uint32_t Factor, bool Reverse, Align Alignment)
551 : Factor(Factor), Reverse(Reverse), Alignment(Alignment),
552 InsertPos(nullptr) {}
553
554 InterleaveGroup(InstTy *Instr, int32_t Stride, Align Alignment)
555 : Alignment(Alignment), InsertPos(Instr) {
556 Factor = std::abs(Stride);
557 assert(Factor > 1 && "Invalid interleave factor");
558
559 Reverse = Stride < 0;
560 Members[0] = Instr;
561 }
562
563 bool isReverse() const { return Reverse; }
564 uint32_t getFactor() const { return Factor; }
565 Align getAlign() const { return Alignment; }
566 uint32_t getNumMembers() const { return Members.size(); }
567
568 /// Try to insert a new member \p Instr with index \p Index and
569 /// alignment \p NewAlign. The index is related to the leader and it could be
570 /// negative if it is the new leader.
571 ///
572 /// \returns false if the instruction doesn't belong to the group.
573 bool insertMember(InstTy *Instr, int32_t Index, Align NewAlign) {
574 // Make sure the key fits in an int32_t.
575 std::optional<int32_t> MaybeKey = checkedAdd(Index, SmallestKey);
576 if (!MaybeKey)
577 return false;
578 int32_t Key = *MaybeKey;
579
580 // Skip if there is already a member with the same index.
581 if (Members.contains(Key))
582 return false;
583
584 if (Key > LargestKey) {
585 // The largest index is always less than the interleave factor.
586 if (Index >= static_cast<int32_t>(Factor))
587 return false;
588
589 LargestKey = Key;
590 } else if (Key < SmallestKey) {
591
592 // Make sure the largest index fits in an int32_t.
593 std::optional<int32_t> MaybeLargestIndex = checkedSub(LargestKey, Key);
594 if (!MaybeLargestIndex)
595 return false;
596
597 // The largest index is always less than the interleave factor.
598 if (*MaybeLargestIndex >= static_cast<int64_t>(Factor))
599 return false;
600
601 SmallestKey = Key;
602 }
603
604 // It's always safe to select the minimum alignment.
605 Alignment = std::min(Alignment, NewAlign);
606 Members[Key] = Instr;
607 return true;
608 }
609
610 /// Get the member with the given index \p Index
611 ///
612 /// \returns nullptr if contains no such member.
613 InstTy *getMember(uint32_t Index) const {
614 int32_t Key = SmallestKey + Index;
615 return Members.lookup(Key);
616 }
617
618 /// Return an iterator range over the non-null members of this group, in
619 /// index order.
620 auto members() const {
621 return make_filter_range(
622 map_range(seq<uint32_t>(0, Factor),
623 [this](uint32_t I) { return getMember(I); }),
624 [](InstTy *I) { return I != nullptr; });
625 }
626
627 /// Get the index for the given member. Unlike the key in the member
628 /// map, the index starts from 0.
629 uint32_t getIndex(const InstTy *Instr) const {
630 for (auto I : Members) {
631 if (I.second == Instr)
632 return I.first - SmallestKey;
633 }
634
635 llvm_unreachable("InterleaveGroup contains no such member");
636 }
637
638 InstTy *getInsertPos() const { return InsertPos; }
639 void setInsertPos(InstTy *Inst) { InsertPos = Inst; }
640
641 /// Add metadata (e.g. alias info) from the instructions in this group to \p
642 /// NewInst.
643 ///
644 /// FIXME: this function currently does not add noalias metadata a'la
645 /// addNewMedata. To do that we need to compute the intersection of the
646 /// noalias info from all members.
647 void addMetadata(InstTy *NewInst) const;
648
649 /// Returns true if this Group requires a scalar iteration to handle gaps.
651 // If the last member of the Group exists, then a scalar epilog is not
652 // needed for this group.
653 if (getMember(getFactor() - 1))
654 return false;
655
656 // We have a group with gaps. It therefore can't be a reversed access,
657 // because such groups get invalidated (TODO).
658 assert(!isReverse() && "Group should have been invalidated");
659
660 // This is a group of loads, with gaps, and without a last-member
661 return true;
662 }
663
664 /// Return true if this group is full, i.e. it has no gaps.
665 bool isFull() const { return getNumMembers() == getFactor(); }
666
667private:
668 uint32_t Factor; // Interleave Factor.
669 bool Reverse;
670 Align Alignment;
672 int32_t SmallestKey = 0;
673 int32_t LargestKey = 0;
674
675 // To avoid breaking dependences, vectorized instructions of an interleave
676 // group should be inserted at either the first load or the last store in
677 // program order.
678 //
679 // E.g. %even = load i32 // Insert Position
680 // %add = add i32 %even // Use of %even
681 // %odd = load i32
682 //
683 // store i32 %even
684 // %odd = add i32 // Def of %odd
685 // store i32 %odd // Insert Position
686 InstTy *InsertPos;
687};
688
689/// Drive the analysis of interleaved memory accesses in the loop.
690///
691/// Use this class to analyze interleaved accesses only when we can vectorize
692/// a loop. Otherwise it's meaningless to do analysis as the vectorization
693/// on interleaved accesses is unsafe.
694///
695/// The analysis collects interleave groups and records the relationships
696/// between the member and the group in a map.
698public:
700 DominatorTree *DT, LoopInfo *LI,
701 const LoopAccessInfo *LAI, bool OptForSize);
702
704
705 /// Analyze the interleaved accesses and collect them in interleave
706 /// groups. Substitute symbolic strides using \p Strides.
707 /// Consider also predicated loads/stores in the analysis if
708 /// \p EnableMaskedInterleavedGroup is true.
709 LLVM_ABI void analyzeInterleaving(bool EnableMaskedInterleavedGroup);
710
711 /// Invalidate groups, e.g., in case all blocks in loop will be predicated
712 /// contrary to original assumption. Although we currently prevent group
713 /// formation for predicated accesses, we may be able to relax this limitation
714 /// in the future once we handle more complicated blocks. Returns true if any
715 /// groups were invalidated.
717 if (InterleaveGroups.empty()) {
718 assert(
719 !RequiresScalarEpilogue &&
720 "RequiresScalarEpilog should not be set without interleave groups");
721 return false;
722 }
723
724 InterleaveGroupMap.clear();
725 for (auto *Ptr : InterleaveGroups)
726 delete Ptr;
727 InterleaveGroups.clear();
728 RequiresScalarEpilogue = false;
729 return true;
730 }
731
732 /// Check if \p Instr belongs to any interleave group.
733 bool isInterleaved(Instruction *Instr) const {
734 return InterleaveGroupMap.contains(Instr);
735 }
736
737 /// Get the interleave group that \p Instr belongs to.
738 ///
739 /// \returns nullptr if doesn't have such group.
741 getInterleaveGroup(const Instruction *Instr) const {
742 return InterleaveGroupMap.lookup(Instr);
743 }
744
747 return make_range(InterleaveGroups.begin(), InterleaveGroups.end());
748 }
749
750 /// Returns true if an interleaved group that may access memory
751 /// out-of-bounds requires a scalar epilogue iteration for correctness.
752 bool requiresScalarEpilogue() const { return RequiresScalarEpilogue; }
753
754 /// Invalidate groups that require a scalar epilogue (due to gaps). This can
755 /// happen when optimizing for size forbids a scalar epilogue, and the gap
756 /// cannot be filtered by masking the load/store.
758
759 /// Returns true if we have any interleave groups.
760 bool hasGroups() const { return !InterleaveGroups.empty(); }
761
762private:
763 const AnalysisOptions &Opts;
764
765 /// A wrapper around ScalarEvolution, used to add runtime SCEV checks.
766 /// Simplifies SCEV expressions in the context of existing SCEV assumptions.
767 /// The interleaved access analysis can also add new predicates (for example
768 /// by versioning strides of pointers).
770
771 Loop *TheLoop;
772 DominatorTree *DT;
773 LoopInfo *LI;
774 const LoopAccessInfo *LAI;
775 bool OptForSize;
776
777 /// True if the loop may contain non-reversed interleaved groups with
778 /// out-of-bounds accesses. We ensure we don't speculatively access memory
779 /// out-of-bounds by executing at least one scalar epilogue iteration.
780 bool RequiresScalarEpilogue = false;
781
782 /// Holds the relationships between the members and the interleave group.
784
785 SmallPtrSet<InterleaveGroup<Instruction> *, 4> InterleaveGroups;
786
787 /// Holds dependences among the memory accesses in the loop. It maps a source
788 /// access to a set of dependent sink accesses.
790
791 /// The descriptor for a strided memory access.
792 struct StrideDescriptor {
793 StrideDescriptor() = default;
794 StrideDescriptor(int64_t Stride, const SCEV *Scev, uint64_t Size,
795 Align Alignment)
796 : Stride(Stride), Scev(Scev), Size(Size), Alignment(Alignment) {}
797
798 // The access's stride. It is negative for a reverse access.
799 int64_t Stride = 0;
800
801 // The scalar expression of this access.
802 const SCEV *Scev = nullptr;
803
804 // The size of the memory object.
805 uint64_t Size = 0;
806
807 // The alignment of this access.
808 Align Alignment;
809 };
810
811 /// A type for holding instructions and their stride descriptors.
812 using StrideEntry = std::pair<Instruction *, StrideDescriptor>;
813
814 /// Create a new interleave group with the given instruction \p Instr,
815 /// stride \p Stride and alignment \p Align.
816 ///
817 /// \returns the newly created interleave group.
818 InterleaveGroup<Instruction> *
819 createInterleaveGroup(Instruction *Instr, int Stride, Align Alignment) {
820 auto [It, Inserted] = InterleaveGroupMap.try_emplace(Instr);
821 assert(Inserted && "Already in an interleaved access group");
822 It->second = new InterleaveGroup<Instruction>(Instr, Stride, Alignment);
823 InterleaveGroups.insert(It->second);
824 return It->second;
825 }
826
827 /// Release the group and remove all the relationships.
828 void releaseGroup(InterleaveGroup<Instruction> *Group) {
829 InterleaveGroups.erase(Group);
830 releaseGroupWithoutRemovingFromSet(Group);
831 }
832
833 /// Do everything necessary to release the group, apart from removing it from
834 /// the InterleaveGroups set.
835 void releaseGroupWithoutRemovingFromSet(InterleaveGroup<Instruction> *Group) {
836 for (unsigned i = 0; i < Group->getFactor(); i++)
837 if (Instruction *Member = Group->getMember(i))
838 InterleaveGroupMap.erase(Member);
839
840 delete Group;
841 }
842
843 /// Collect all the accesses with a constant stride in program order. Any
844 /// SCEV predicates needed to compute the strides are added to \p
845 /// Predicates if it is not nullptr.
846 void collectConstStrideAccesses(
847 MapVector<Instruction *, StrideDescriptor> &AccessStrideInfo,
848 const SymbolicStrideMap &Strides,
849 SmallVectorImpl<const SCEVPredicate *> *Predicates);
850
851 /// Returns true if \p Stride is allowed in an interleaved group.
852 LLVM_ABI bool isStrided(int Stride) const;
853
854 /// Returns true if \p BB is a predicated block.
855 bool isPredicated(BasicBlock *BB) const {
856 return LoopAccessInfo::blockNeedsPredication(BB, TheLoop, DT);
857 }
858
859 /// Returns true if LoopAccessInfo can be used for dependence queries.
860 bool areDependencesValid() const {
861 return LAI && LAI->getDepChecker().getDependences();
862 }
863
864 /// Returns true if memory accesses \p A and \p B can be reordered, if
865 /// necessary, when constructing interleaved groups.
866 ///
867 /// \p A must precede \p B in program order. We return false if reordering is
868 /// not necessary or is prevented because \p A and \p B may be dependent.
869 bool canReorderMemAccessesForInterleavedGroups(StrideEntry *A,
870 StrideEntry *B) const {
871 // Code motion for interleaved accesses can potentially hoist strided loads
872 // and sink strided stores. The code below checks the legality of the
873 // following two conditions:
874 //
875 // 1. Potentially moving a strided load (B) before any store (A) that
876 // precedes B, or
877 //
878 // 2. Potentially moving a strided store (A) after any load or store (B)
879 // that A precedes.
880 //
881 // It's legal to reorder A and B if we know there isn't a dependence from A
882 // to B. Note that this determination is conservative since some
883 // dependences could potentially be reordered safely.
884
885 // A is potentially the source of a dependence.
886 auto *Src = A->first;
887 auto SrcDes = A->second;
888
889 // B is potentially the sink of a dependence.
890 auto *Sink = B->first;
891 auto SinkDes = B->second;
892
893 // Code motion for interleaved accesses can't violate WAR dependences.
894 // Thus, reordering is legal if the source isn't a write.
895 if (!Src->mayWriteToMemory())
896 return true;
897
898 // At least one of the accesses must be strided.
899 if (!isStrided(SrcDes.Stride) && !isStrided(SinkDes.Stride))
900 return true;
901
902 // If dependence information is not available from LoopAccessInfo,
903 // conservatively assume the instructions can't be reordered.
904 if (!areDependencesValid())
905 return false;
906
907 // If we know there is a dependence from source to sink, assume the
908 // instructions can't be reordered. Otherwise, reordering is legal.
909 return !Dependences.contains(Src) || !Dependences.lookup(Src).count(Sink);
910 }
911
912 /// Collect the dependences from LoopAccessInfo.
913 ///
914 /// We process the dependences once during the interleaved access analysis to
915 /// enable constant-time dependence queries.
916 void collectDependences() {
917 if (!areDependencesValid())
918 return;
919 const auto &DepChecker = LAI->getDepChecker();
920 auto *Deps = DepChecker.getDependences();
921 for (auto Dep : *Deps)
922 Dependences[Dep.getSource(DepChecker)].insert(
923 Dep.getDestination(DepChecker));
924 }
925};
926
927} // llvm namespace
928
929#endif
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
dxil translate DXIL Translate Metadata
Module.h This file contains the declarations for the Module class.
#define I(x, y, z)
Definition MD5.cpp:57
Machine Check Debug Module
This file implements a map that provides insertion order iteration.
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.
This class represents a function call, abstracting a target machine's calling convention.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:122
const Function & getFunction() const
Definition Function.h:167
The group of interleaved loads/stores sharing the same stride and close to each other.
auto members() const
Return an iterator range over the non-null members of this group, in index order.
bool requiresScalarEpilogue() const
Returns true if this Group requires a scalar iteration to handle gaps.
uint32_t getFactor() const
InstTy * getMember(uint32_t Index) const
Get the member with the given index Index.
InterleaveGroup(uint32_t Factor, bool Reverse, Align Alignment)
bool isFull() const
Return true if this group is full, i.e. it has no gaps.
uint32_t getIndex(const InstTy *Instr) const
Get the index for the given member.
void setInsertPos(InstTy *Inst)
bool isReverse() const
InstTy * getInsertPos() const
void addMetadata(InstTy *NewInst) const
Add metadata (e.g.
Align getAlign() const
InterleaveGroup(InstTy *Instr, int32_t Stride, Align Alignment)
bool insertMember(InstTy *Instr, int32_t Index, Align NewAlign)
Try to insert a new member Instr with index Index and alignment NewAlign.
uint32_t getNumMembers() const
InterleaveGroup< Instruction > * getInterleaveGroup(const Instruction *Instr) const
Get the interleave group that Instr belongs to.
bool requiresScalarEpilogue() const
Returns true if an interleaved group that may access memory out-of-bounds requires a scalar epilogue ...
bool hasGroups() const
Returns true if we have any interleave groups.
bool isInterleaved(Instruction *Instr) const
Check if Instr belongs to any interleave group.
bool invalidateGroups()
Invalidate groups, e.g., in case all blocks in loop will be predicated contrary to original assumptio...
iterator_range< SmallPtrSetIterator< llvm::InterleaveGroup< Instruction > * > > getInterleaveGroups()
LLVM_ABI InterleavedAccessInfo(PredicatedScalarEvolution &PSE, Loop *L, DominatorTree *DT, LoopInfo *LI, const LoopAccessInfo *LAI, bool OptForSize)
LLVM_ABI void analyzeInterleaving(bool EnableMaskedInterleavedGroup)
Analyze the interleaved accesses and collect them in interleave groups.
LLVM_ABI void invalidateGroupsRequiringScalarEpilogue()
Invalidate groups that require a scalar epilogue (due to gaps).
A wrapper class for inspecting calls to intrinsic functions.
Drive the analysis of memory accesses in the loop.
static LLVM_ABI bool blockNeedsPredication(const BasicBlock *BB, const Loop *TheLoop, const DominatorTree *DT)
Return true if the block BB needs to be predicated in order for the loop to be vectorized.
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
This class represents an analyzed expression in the program.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Provides information about what library functions are available for the current target.
VFDatabase(CallInst &CI)
Constructor, requires a CallInst instance.
static bool hasMaskedVariant(const CallInst &CI, std::optional< ElementCount > VF=std::nullopt)
Definition VectorUtils.h:87
static SmallVector< VFInfo, 8 > getMappings(const CallInst &CI)
Retrieve all the VFInfo instances associated to the CallInst CI.
Definition VectorUtils.h:76
A range adaptor for a pair of iterators.
Function * getVectorizedFunction(const VFShape &Shape) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI std::optional< VFInfo > tryDemangleForVFABI(StringRef MangledName, const FunctionType *FTy)
Function to construct a VFInfo out of a mangled names in the following format:
LLVM_ABI void getVectorVariantNames(const CallInst &CI, SmallVectorImpl< std::string > &VariantMappings)
Populates a set of strings representing the Vector Function ABI variants associated to the CallInst C...
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI Intrinsic::ID getVectorIntrinsicIDForCall(const CallInst *CI, const TargetLibraryInfo *TLI)
Returns intrinsic ID for call.
LLVM_ABI APInt possiblyDemandedEltsInMask(Value *Mask)
Given a mask vector of the form <Y x i1>, return an APInt (of bitwidth Y) for each lane which may be ...
LLVM_ABI std::optional< unsigned > getVectorStoreIntrinsicDataArgIdx(Intrinsic::ID ID)
Returns the argument index of the data value of the vector store intrinsic ID, or std::nullopt if the...
LLVM_ABI llvm::SmallVector< int, 16 > createUnaryMask(ArrayRef< int > Mask, unsigned NumElts)
Given a shuffle mask for a binary shuffle, create the equivalent shuffle mask assuming both operands ...
LLVM_ABI void getMetadataToPropagate(Instruction *Inst, SmallVectorImpl< std::pair< unsigned, MDNode * > > &Metadata)
Add metadata from Inst to Metadata, if it can be preserved after vectorization.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
HistogramUpdateKind
The kind of update operation performed on the buckets of a histogram, i.e.
LLVM_ABI Value * concatenateVectors(IRBuilderBase &Builder, ArrayRef< Value * > Vecs)
Concatenate a list of vectors.
LLVM_ABI bool widenShuffleMaskElts(int Scale, ArrayRef< int > Mask, SmallVectorImpl< int > &ScaledMask)
Try to transform a shuffle mask by replacing elements with the scaled index for an equivalent mask of...
LLVM_ABI Instruction * propagateMetadata(Instruction *I, ArrayRef< Value * > VL)
Specifically, let Kinds = [MD_tbaa, MD_alias_scope, MD_noalias, MD_fpmath, MD_nontemporal,...
LLVM_ABI Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
auto map_range(ContainerTy &&C, FuncTy F)
Return a range that applies F to the elements of C.
Definition STLExtras.h:366
LLVM_ABI MDNode * intersectAccessGroups(const Instruction *Inst1, const Instruction *Inst2)
Compute the access-group list of access groups that Inst1 and Inst2 are both in.
LLVM_ABI bool getShuffleDemandedElts(int SrcWidth, ArrayRef< int > Mask, const APInt &DemandedElts, APInt &DemandedLHS, APInt &DemandedRHS, bool AllowUndefElts=false)
Transform a shuffle mask's output demanded element mask into demanded element masks for the 2 operand...
LLVM_ABI bool isSplatValue(const Value *V, int Index=-1, unsigned Depth=0)
Return true if each element of the vector value V is poisoned or equal to every other non-poisoned el...
LLVM_ABI Constant * createBitMaskForGaps(IRBuilderBase &Builder, unsigned VF, const InterleaveGroup< Instruction > &Group)
Create a mask that filters the members of an interleave group where there are gaps.
LLVM_ABI llvm::SmallVector< int, 16 > createStrideMask(unsigned Start, unsigned Stride, unsigned VF)
Create a stride shuffle mask.
LLVM_ABI void getHorizDemandedEltsForFirstOperand(unsigned VectorBitWidth, const APInt &DemandedElts, APInt &DemandedLHS, APInt &DemandedRHS)
Compute the demanded elements mask of horizontal binary operations.
LLVM_ABI llvm::SmallVector< int, 16 > createReplicatedMask(unsigned ReplicationFactor, unsigned VF)
Create a mask with replicated elements.
DenseMap< Value *, const SCEVUnknown * > SymbolicStrideMap
Maps a pointer to its symbolic (non-constant) stride.
LLVM_ABI unsigned getDeinterleaveIntrinsicFactor(Intrinsic::ID ID)
Returns the corresponding factor of llvm.vector.deinterleaveN intrinsics.
LLVM_ABI unsigned getInterleaveIntrinsicFactor(Intrinsic::ID ID)
Returns the corresponding factor of llvm.vector.interleaveN intrinsics.
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition STLExtras.h:552
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
LLVM_ABI bool isTriviallyScalarizable(Intrinsic::ID ID)
Identify if the intrinsic is trivially scalarizable.
LLVM_ABI bool isVectorIntrinsicWithStructReturnOverloadAtField(Intrinsic::ID ID, int RetIdx, const TargetTransformInfo *TTI)
Identifies if the vector form of the intrinsic that returns a struct is overloaded at the struct elem...
TargetTransformInfo TTI
LLVM_ABI void narrowShuffleMaskElts(int Scale, ArrayRef< int > Mask, SmallVectorImpl< int > &ScaledMask)
Replace each shuffle mask index with the scaled sequential indices for an equivalent mask of narrowed...
LLVM_ABI bool isMaskedSlidePair(ArrayRef< int > Mask, int NumElts, std::array< std::pair< int, int >, 2 > &SrcInfo)
Does this shuffle mask represent either one slide shuffle or a pair of two slide shuffles,...
LLVM_ABI VectorType * getDeinterleavedVectorType(IntrinsicInst *DI)
Given a deinterleaveN intrinsic, return the (narrow) vector type of each factor.
LLVM_ABI llvm::SmallVector< int, 16 > createInterleaveMask(unsigned VF, unsigned NumVecs)
Create an interleave shuffle mask.
LLVM_ABI std::optional< unsigned > getVectorMemoryIntrinsicPointerArgIdx(Intrinsic::ID ID)
Returns the argument index of the pointer parameter for the vector memory intrinsic ID,...
@ UMin
Unsigned integer min implemented in terms of select(cmp()).
@ Sub
Subtraction of integers.
@ Add
Sum of integers.
@ UMax
Unsigned integer max implemented in terms of select(cmp()).
LLVM_ABI bool isVectorIntrinsicWithScalarOpAtArg(Intrinsic::ID ID, unsigned ScalarOpdIdx, const TargetTransformInfo *TTI)
Identifies if the vector form of the intrinsic has a scalar operand.
LLVM_ABI Value * findScalarElement(Value *V, unsigned EltNo)
Given a vector and an element number, see if the scalar value is already around as a register,...
LLVM_ABI MDNode * uniteAccessGroups(MDNode *AccGroups1, MDNode *AccGroups2)
Compute the union of two access-group lists.
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI std::optional< unsigned > getVectorIntrinsicMaskArgIdx(Intrinsic::ID ID)
Returns the argument index of the mask for the vector intrinsic ID, or std::nullopt if the intrinsic ...
std::enable_if_t< std::is_signed_v< T >, std::optional< T > > checkedSub(T LHS, T RHS)
Subtract two signed integers LHS and RHS.
LLVM_ABI bool shouldSplitVectorSinCos(const TargetLibraryInfo &TLI, Type *ScalarTy, ElementCount EC, Module *M)
Returns true if the vector llvm.sincos with ScalarTy elements and EC element count has no vector libr...
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:341
LLVM_ABI void getShuffleMaskWithWidestElts(ArrayRef< int > Mask, SmallVectorImpl< int > &ScaledMask)
Repetitively apply widenShuffleMaskElts() for as long as it succeeds, to get the shuffle mask with wi...
std::enable_if_t< std::is_signed_v< T >, std::optional< T > > checkedAdd(T LHS, T RHS)
Add two signed integers LHS and RHS.
LLVM_ABI void processShuffleMasks(ArrayRef< int > Mask, unsigned NumOfSrcRegs, unsigned NumOfDestRegs, unsigned NumOfUsedRegs, function_ref< void()> NoInputAction, function_ref< void(ArrayRef< int >, unsigned, unsigned)> SingleInputAction, function_ref< void(ArrayRef< int >, unsigned, unsigned, bool)> ManyInputsAction)
Splits and processes shuffle mask depending on the number of input and output registers.
LLVM_ABI bool maskContainsAllOneOrUndef(Value *Mask)
Given a mask vector of i1, Return true if any of the elements of this predicate mask are known to be ...
LLVM_ABI bool isTriviallyVectorizable(Intrinsic::ID ID)
Identify if the intrinsic is trivially vectorizable.
LLVM_ABI llvm::SmallVector< int, 16 > createSequentialMask(unsigned Start, unsigned NumInts, unsigned NumUndefs)
Create a sequential shuffle mask.
LLVM_ABI bool isVectorIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID, int OpdIdx, const TargetTransformInfo *TTI)
Identifies if the vector form of the intrinsic is overloaded on the type of the operand at index OpdI...
LLVM_ABI MapVector< Instruction *, uint64_t > computeMinimumValueSizes(ArrayRef< BasicBlock * > Blocks, DemandedBits &DB, const TargetTransformInfo *TTI=nullptr)
Compute a map of integer instructions to their minimum legal type size.
LLVM_ABI bool scaleShuffleMaskElts(unsigned NumDstElts, ArrayRef< int > Mask, SmallVectorImpl< int > &ScaledMask)
Attempt to narrow/widen the Mask shuffle mask to the NumDstElts target width.
LLVM_ABI int getSplatIndex(ArrayRef< int > Mask)
If all non-negative Mask elements are the same value, return that value.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Holds the VFShape for a specific scalar to vector function mapping.
Contains the information about the kind of vectorization available.
static VFShape getScalarShape(const FunctionType *FTy)
Retrieve the VFShape that can be used to map a scalar function to itself, with VF = 1.