LLVM 24.0.0git
SLPUtils.h
Go to the documentation of this file.
1//===- SLPUtils.h - SLP Vectorizer free utility helpers --------*- 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// Internal header used by SLPVectorizer.cpp. It declares free helper
10// functions that do not depend on BoUpSLP, InstructionsState, or any other
11// SLP-private type. Splitting them out keeps SLPVectorizer.cpp focused on
12// the build / legality / cost / codegen pipeline.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPUTILS_H
17#define LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPUTILS_H
18
19#include "llvm/ADT/APInt.h"
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/STLExtras.h"
27#include "llvm/IR/Intrinsics.h"
28
29#include <cstdint>
30#include <limits>
31#include <optional>
32#include <string>
33#include <tuple>
34
35namespace llvm {
36class AssumptionCache;
37class Constant;
38class DataLayout;
39class DebugLoc;
41class Instruction;
42class IRBuilderBase;
43class LoadInst;
44class Loop;
45class PHINode;
46class ScalarEvolution;
47class SelectInst;
49class Type;
50class Value;
51} // namespace llvm
52
53namespace llvm::slpvectorizer {
54
56
57/// Limit of the number of uses for potentially transformed instructions/values,
58/// used in checks to avoid compile-time explode.
59inline constexpr int UsesLimit = 64;
60
61/// \returns True if the value is a constant (but not globals/constant
62/// expressions).
63bool isConstant(Value *V);
64
65/// \returns True if \p V is the integer identity constant for binary \p Opcode
66/// (e.g. 0 for add, 1 for mul, all-ones for and). Floating-point identities are
67/// excluded: a ConstantInt never matches the ConstantFP getBinOpIdentity()
68/// returns for FAdd/FMul, whose identity fast-math may break anyway.
69bool isBinOpIdentityConstant(const Value *V, unsigned Opcode);
70
71/// \returns True if \p V is an integer binary operator, which gives an undef
72/// result for the undef operands: neither a shift nor a division.
73bool isUndefTolerantBinOp(const Value *V);
74
75/// \returns the load operand of the undef tolerant binary operator \p V, if
76/// any.
78
79/// \returns the opcode of the combines emitted for a reassociated node:
80/// subtract chains regroup their positive and negative operand columns with
81/// plain adds.
82unsigned getReassocCombineOpcode(unsigned Opcode);
83
84/// \returns True if \p I can be a link of a flattenable binary chain:
85/// subtracts flatten as adds of a negated leaf, float subtracts need reassoc
86/// to allow the regrouping.
88
89/// Checks if \p V is one of vector-like instructions, i.e. undef,
90/// insertelement/extractelement with constant indices for fixed vector type
91/// or extractvalue instruction.
93
94/// \returns the number of elements for Ty.
95unsigned getNumElements(Type *Ty);
96
97/// Returns power-of-2 number of elements in a single register (part), given
98/// the total number of elements \p Size and number of registers (parts) \p
99/// NumParts.
100unsigned getPartNumElems(unsigned Size, unsigned NumParts);
101
102/// Returns correct remaining number of elements, considering total amount
103/// \p Size, (power-of-2 number) of elements in a single register
104/// \p PartNumElems and current register (part) \p Part.
105unsigned getNumElems(unsigned Size, unsigned PartNumElems, unsigned Part);
106
107#if !defined(NDEBUG)
108/// Print a short descriptor of the instruction bundle suitable for debug
109/// output.
110std::string shortBundleName(ArrayRef<Value *> VL, int Idx = -1);
111#endif
112
113/// \returns True if all of the instructions in \p VL are in the same block.
115
116/// \returns True if all of the values in \p VL are constants (but not
117/// globals/constant expressions).
119
120/// \returns True if all of the values in \p VL are identical or some of them
121/// are UndefValue.
123
124/// Checks if \p LHS and \p RHS are the same intrinsic, or one is llvm.fma
125/// and the other is llvm.fmuladd, since both lower to the same fused
126/// vector operation.
127/// \returns the intrinsic ID to use for the pair (\p RHS if the IDs match,
128/// otherwise Intrinsic::fma), or Intrinsic::not_intrinsic if they are not
129/// equivalent.
131
132/// \returns True if \p I is commutative, handles CmpInst and BinaryOperator.
133/// For BinaryOperator, it also checks if \p ValWithUses is used in specific
134/// patterns that make it effectively commutative (like equality comparisons
135/// with zero).
136/// In most cases, users should not call this function directly (since \p I and
137/// \p ValWithUses are the same). However, when analyzing interchangeable
138/// instructions, we need to use the converted opcode along with the original
139/// uses.
140/// \param I The instruction to check for commutativity
141/// \param ValWithUses The value whose uses are analyzed for special
142/// patterns
143bool isCommutative(const Instruction *I, const Value *ValWithUses,
144 bool IsCopyable = false);
145
146/// This is a helper function to check whether \p I is commutative.
147/// This is a convenience wrapper that calls the two-parameter version of
148/// isCommutative with the same instruction for both parameters. This is
149/// the common case where the instruction being checked for commutativity
150/// is the same as the instruction whose uses are analyzed for special
151/// patterns (see the two-parameter version above for details).
152/// \param I The instruction to check for commutativity
153/// \returns true if the instruction is commutative, false otherwise
154bool isCommutative(const Instruction *I);
155
156/// Checks if the operand is commutative. In commutative operations, not all
157/// operands might commutable, e.g. for fmuladd only 2 first operands are
158/// commutable.
159bool isCommutableOperand(const Instruction *I, Value *ValWithUses, unsigned Op,
160 bool IsCopyable = false);
161
162/// \returns number of operands of \p I, considering commutativity. Returns 2
163/// for commutative intrinsics.
164/// \param I The instruction to check for commutativity
166
167/// \returns inserting or extracting index of InsertElement, ExtractElement
168/// or InsertValue instruction, using \p Offset as base offset for index.
169/// \returns std::nullopt if the index is not an immediate.
170std::optional<unsigned> getElementIndex(const Value *Inst, unsigned Offset = 0);
171
172/// \returns True if all of the values in \p VL use the same opcode.
173/// For comparison instructions, also checks if predicates match.
174/// PoisonValues are considered matching. Interchangeable instructions are
175/// not considered.
177
178/// \returns Optional element Idx for Extract{Value,Element} instructions.
179std::optional<unsigned> getExtractIndex(const Instruction *E);
180
181/// Compute the inverse permutation \p Mask of \p Indices.
183
184/// Reorders the list of scalars in accordance with the given \p Mask.
186
187/// Reorders the given \p Reuses mask according to the given \p Mask. \p Reuses
188/// contains original mask for the scalars reused in the node. Procedure
189/// transform this mask in accordance with the given \p Mask.
191
192/// Reorders the given \p Order according to the given \p Mask. \p Order - is
193/// the original order of the scalars. Procedure transforms the provided order
194/// in accordance with the given \p Mask. If the resulting \p Order is just an
195/// identity order, \p Order is cleared.
197 bool BottomOrder = false);
198
199/// Check if \p Order represents reverse order.
201
202/// Checks if the given mask is a "clustered" mask with the same clusters of
203/// size \p Sz, which are not identity submasks.
205
206/// Fills unset elements of \p Order (marked with the sentinel value equal to
207/// the order size) with the corresponding elements of \p SecondaryOrder,
208/// skipping already used indices, or with the identity order if
209/// \p SecondaryOrder is empty.
211 ArrayRef<unsigned> SecondaryOrder);
212
213/// \returns True iff every value in \p VL has the same Type as the first.
215
216/// Checks if the provided value does not require scheduling. It does not
217/// require scheduling if this is not an instruction or it is an instruction
218/// that does not read/write memory and all operands are either not
219/// instructions or phi nodes or instructions from different blocks.
221
222/// Checks if the provided value does not require scheduling. It does not
223/// require scheduling if this is not an instruction or it is an instruction
224/// that does not read/write memory and all users are phi nodes or
225/// instructions from different blocks.
227
228/// Checks if the specified value does not require scheduling. It does not
229/// require scheduling if all operands and all users do not need to be
230/// scheduled in the current basic block.
232
233/// Checks if the specified array of instructions does not require scheduling.
234/// It is so if all either instructions have operands that do not require
235/// scheduling or their users do not require scheduling since they are phis or
236/// in other basic blocks.
238
239/// \returns inserting or extracting index of InsertElement / ExtractElement
240/// instruction, using \p Offset as base offset for index. Only instantiated
241/// for InsertElementInst and ExtractElementInst (see SLPUtils.cpp).
242template <typename T>
243std::optional<unsigned> getInsertExtractIndex(const Value *Inst,
244 unsigned Offset);
245
246void transformScalarShuffleIndiciesToVector(unsigned VecTyNumElements,
248
249/// \returns the number of groups of shufflevector
250/// A group has the following features
251/// 1. All of value in a group are shufflevector.
252/// 2. The mask of all shufflevector is isExtractSubvectorMask.
253/// 3. The mask of all shufflevector uses all of the elements of the source.
254/// e.g., it is 1 group (%0)
255/// %1 = shufflevector <16 x i8> %0, <16 x i8> poison,
256/// <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
257/// %2 = shufflevector <16 x i8> %0, <16 x i8> poison,
258/// <8 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
259/// it is 2 groups (%3 and %4)
260/// %5 = shufflevector <8 x i16> %3, <8 x i16> poison,
261/// <4 x i32> <i32 0, i32 1, i32 2, i32 3>
262/// %6 = shufflevector <8 x i16> %3, <8 x i16> poison,
263/// <4 x i32> <i32 4, i32 5, i32 6, i32 7>
264/// %7 = shufflevector <8 x i16> %4, <8 x i16> poison,
265/// <4 x i32> <i32 0, i32 1, i32 2, i32 3>
266/// %8 = shufflevector <8 x i16> %4, <8 x i16> poison,
267/// <4 x i32> <i32 4, i32 5, i32 6, i32 7>
268/// it is 0 group
269/// %12 = shufflevector <8 x i16> %10, <8 x i16> poison,
270/// <4 x i32> <i32 0, i32 1, i32 2, i32 3>
271/// %13 = shufflevector <8 x i16> %11, <8 x i16> poison,
272/// <4 x i32> <i32 0, i32 1, i32 2, i32 3>
274
275/// \returns a shufflevector mask which is used to vectorize shufflevectors
276/// e.g.,
277/// %5 = shufflevector <8 x i16> %3, <8 x i16> poison,
278/// <4 x i32> <i32 0, i32 1, i32 2, i32 3>
279/// %6 = shufflevector <8 x i16> %3, <8 x i16> poison,
280/// <4 x i32> <i32 4, i32 5, i32 6, i32 7>
281/// %7 = shufflevector <8 x i16> %4, <8 x i16> poison,
282/// <4 x i32> <i32 0, i32 1, i32 2, i32 3>
283/// %8 = shufflevector <8 x i16> %4, <8 x i16> poison,
284/// <4 x i32> <i32 4, i32 5, i32 6, i32 7>
285/// the result is
286/// <0, 1, 2, 3, 12, 13, 14, 15, 16, 17, 18, 19, 28, 29, 30, 31>
288
289/// Checks if the values in \p VL can be represented as a shuffle of at most
290/// two vector operands (extractelement lanes). On success, \p Mask is the
291/// equivalent shuffle mask.
292std::optional<TargetTransformInfo::ShuffleKind>
295
296/// Creates subvector insert. Generates shuffle using \p Generator or
297/// using default shuffle.
299 IRBuilderBase &Builder, Value *Vec, Value *V, unsigned Index,
300 function_ref<Value *(Value *, Value *, ArrayRef<int>)> Generator = {});
301
302/// Generates subvector extract.
304 unsigned SubVecVF, unsigned Index);
305
306/// Specifies the way the mask should be analyzed for undefs/poisonous elements
307/// in the shuffle mask.
308enum class UseMask {
309 FirstArg, ///< The mask is expected to be for permutation of 1-2 vectors,
310 ///< check for the mask elements for the first argument (mask
311 ///< indices are in range [0:VF)).
312 SecondArg, ///< The mask is expected to be for permutation of 2 vectors, check
313 ///< for the mask elements for the second argument (mask indices
314 ///< are in range [VF:2*VF))
315 UndefsAsMask ///< Consider undef mask elements (-1) as placeholders for
316 ///< future shuffle elements and mark them as ones as being used
317 ///< in future. Non-undef elements are considered as unused since
318 ///< they're already marked as used in the mask.
319};
320
321/// Prepares a use bitset for the given mask either for the first argument or
322/// for the second.
323SmallBitVector buildUseMask(int VF, ArrayRef<int> Mask, UseMask MaskArg);
324
325/// Checks if the given value is actually an undefined constant vector.
326/// Also, if the \p UseMask is not empty, tries to check if the non-masked
327/// elements actually mask the insertelement buildvector, if any.
328template <bool IsPoisonOnly = false>
330 const SmallBitVector &UseMask = {});
331
332/// \returns True if in-tree use also needs extract. This refers to
333/// possible scalar operand in vectorized instruction.
334bool doesInTreeUserNeedToExtract(Value *Scalar, Instruction *UserInst,
335 TargetLibraryInfo *TLI,
336 const TargetTransformInfo *TTI);
337
338/// \returns the AA location that is being access by the instruction.
339MemoryLocation getLocation(Instruction *I);
340
341/// \returns True if the instruction is not a volatile or atomic load/store.
342bool isSimple(Instruction *I);
343
344/// Checks if the loads with scalar type \p ScalarTy and pointer operands
345/// \p PointerOps are each (optionally via a constant-offset GEP) a
346/// `select Cond, A, B` picking between the same two base pointers A/B on
347/// every lane - the shape a fully unrolled `x = cond ? A[i] : B[i]` takes. On
348/// success \p TrueBase / \p FalseBase are the candidate bases and
349/// \p Conditions holds each lane's `select` condition, used to build the
350/// blend mask. Lane \p Idx must be at `Base + Idx * sizeof(ScalarTy)`; only
351/// dense, natural lane order starting at the base is recognized (reordered or
352/// partial groups fall back to Gather/Scatter).
353bool isSelectedBaseLoad(Type *ScalarTy, ArrayRef<Value *> PointerOps,
354 const DataLayout &DL, Value *&TrueBase,
355 Value *&FalseBase,
356 SmallVectorImpl<Value *> &Conditions);
357
358/// Returns the alignment of the shared base pointer of a blended load for
359/// the loads \p VL.
361 const DataLayout &DL);
362
363/// Returns the select instruction picking between the candidate base pointers
364/// of the blended loads \p VL.
366
367/// Returns the common type for the indices of the single-index GEP lanes of
368/// a GEP node with the main op \p VL0, or nullptr if no such type exists.
369/// \p IsGEPLane tells which lanes of \p VL are matching GEPs, whose index is
370/// used as is; all other lanes (copyable, poison, non-GEP pointers) are
371/// modeled as gep V, 0 and just take a zero index of the common type.
372/// The common type is the index type of \p VL0 if all matching lanes share
373/// it. Otherwise the constant indices are cast: to the pointer index type if
374/// there are no non-constant indices (or the index type of \p VL0 already is
375/// the pointer index type), or to the index type of \p VL0 if all the
376/// non-constant indices have that type and all the constants are
377/// representable in it (GEP indices are sign-extended to the pointer index
378/// width, so the value must fit as a signed number). A non-constant index of
379/// a different type cannot be cast without a new instruction, so no common
380/// type exists.
381Type *getCommonGEPIndexType(ArrayRef<Value *> VL, Instruction *VL0,
382 function_ref<bool(Value *)> IsGEPLane,
383 const DataLayout &DL);
384
385/// Checks if the pointers \p PointerOps of the gathered loads, which are not
386/// compatible in the usual sense (some of them are constant-offset pointers,
387/// some have runtime indices), still form a cheap address vector as a
388/// copyable GEP node: a splat of the common base and a vector of indices.
389/// The constant-offset lanes are the base itself or single-index GEPs of the
390/// base with a constant index (modeled as gep V, 0 or as matching lanes with
391/// constant indices), the other lanes are single-index GEPs of the base of
392/// the same shape, whose indices are affine in a single runtime value (the
393/// stride): optionally cast (all with the same cast opcode) values, each of
394/// which is the stride itself or a binary operation of the stride and a
395/// constant, like b[i * S] or b[S + i]. Duplicate lanes are not accepted:
396/// the node would be a shuffled non-full vector, gathering the loads is
397/// cheaper then.
399
400/// Shuffles \p Mask in accordance with the given \p SubMask.
401/// \param ExtendingManyInputs Supports reshuffling of the mask with not only
402/// one but two input vectors.
403void addMask(SmallVectorImpl<int> &Mask, ArrayRef<int> SubMask,
404 bool ExtendingManyInputs = false);
405
406/// Order may have elements assigned special value (size) which is out of
407/// bounds. Such indices only appear on places which correspond to undef values
408/// (see canReuseExtract for details) and used in order to avoid undef values
409/// have effect on operands ordering.
410/// The first loop below simply finds all unused indices and then the next loop
411/// nest assigns these indices for undef values positions.
412/// As an example below Order has two undef positions and they have assigned
413/// values 3 and 7 respectively:
414/// before: 6 9 5 4 9 2 1 0
415/// after: 6 3 5 4 7 2 1 0
417
418/// \returns a bitset for selecting opcodes. false for Opcode0 and true for
419/// Opcode1.
420SmallBitVector getAltInstrMask(ArrayRef<Value *> VL, Type *ScalarTy,
421 unsigned Opcode0, unsigned Opcode1);
422
423/// Replicates the given \p Val \p VF times.
425
426/// \returns the masked division/remainder intrinsic corresponding to \p
427/// Opcode. Disabled lanes of these intrinsics are poison rather than UB,
428/// unlike the plain opcode.
430
431/// Returns true if \p I forms a vectorizable bundle on its own and its single
432/// user does not tear the vector apart. Loads and addresses are excluded: the
433/// tree is built without the users, so it does not pay off the extracts. A
434/// cast, feeding a multi-used cast, is excluded for the same reason, such a
435/// user stays scalar. The fp-to-int conversions move the result to the other
436/// register domain, so the extracts are paid on top of the repacking. The
437/// values, feeding the inserts, are vectorized together with them by the
438/// dedicated attempt.
439bool isOnceUsedSeed(const Instruction *I);
440
441/// If \p V is a single-use fpext of a single-use fptrunc forming a round-trip
442/// back to the type of \p V, returns the fptrunc; the round-trip source is its
443/// operand, always an instruction of the same type as \p V. If
444/// \p MustBeElidable, matches only when the intermediate rounding may be
445/// removed: both casts must allow contraction and the widening cast cannot
446/// produce nan/inf.
447Instruction *lookThroughCastRoundTrip(Value *V, bool MustBeElidable);
448
449/// Narrow reduction leaf: the value, the shift applied after widening and
450/// the mask applied in the narrow type before widening, clearing the bits
451/// the absorbed narrow shls shift out and applying the absorbed narrow
452/// and-masks. Lossless narrow shls contribute their known-zero bits to the
453/// mask so matching lanes can form a splat. All-ones mask means nothing
454/// was absorbed and no 'and' is needed.
458
459 Value *V = nullptr;
460 unsigned Shift = 0;
462 /// Set to false, if the or chain is not disjoint
463 bool Disjoint = true;
464};
465
466/// Recursively collects the narrow leaves of the widened reduction value
467/// \p V. zext is looked through directly, same-kind binops per operand,
468/// shl of a zext - only if no bits are shifted out in the current type,
469/// shls in narrower types fold into the shift and ands with a constant into
470/// the mask applied in the narrow type. Also collects the looked-through
471/// instructions into \p ChainInsts.
472void collectNarrowedLeaves(Value *V, unsigned RdxOpcode, unsigned WideBW,
473 unsigned MaxDepth,
476
478
479/// Returns a saturating unsigned upper bound of the scalar V. The numeric
480/// bound keeps precision on arithmetic carries, where bit-wise analysis
481/// loses it.
482APInt getScalarMaxValue(const Value *V, unsigned Depth = 0);
483
484/// Checks if the values in \p VL are zero-extended sub-fields of the same
485/// wider integer scalar. Returns the source scalar, the field width and the
486/// field permutation mask. The extraction dual of the lane-packing layout.
487/// The field-to-lane mapping of the bitcast to the field vector is defined
488/// for little-endian targets only.
489std::optional<std::tuple<Value *, unsigned, SmallVector<int>>>
491
492/// Description of a bitfield packing of vector lanes into a scalar value:
493/// every lane contributes a disjoint contiguous byte field of the result.
495 static constexpr unsigned NoLane = std::numeric_limits<unsigned>::max();
496 unsigned FieldWidth = 0;
497 /// Lane covering each field, NoLane if the field is always zero.
499 /// Per-lane right-shift amounts bringing the field content to the low bits.
501
502 /// True if any lane needs a right shift to align its field content.
503 bool needsShift() const {
504 return any_of(LShrAmts, [](uint64_t A) { return A != 0; });
505 }
506};
507
508/// Computes the bitfield packing layout from the per-lane possibly set bits
509/// of the source values, the per-lane left-shift amounts and the per-lane
510/// masks (all-ones for unmasked lanes).
511std::optional<BitPackInfo> computeBitPackInfo(unsigned BitWidth,
512 ArrayRef<APInt> PossibleBits,
513 ArrayRef<uint64_t> ShlAmts,
514 ArrayRef<APInt> Masks);
515
516/// Returns the byte shuffle mask packing the per-lane fields of the shifted
517/// lanes (BytesPerLane bytes each) into the packed scalar of NumBytes bytes.
518SmallVector<int> getBitPackMask(const BitPackInfo &Info, unsigned NumBytes,
519 unsigned NumElts, unsigned BytesPerLane);
520
521/// Builds the bitfield packing of X into \p ResultTy per the layout and the
522/// shift width. \p NumInsts returns the number of emitted instructions.
523Value *buildBitPack(IRBuilderBase &Builder, Value *X, const BitPackInfo &Info,
524 Type *ResultTy, unsigned ShiftWidth, unsigned &NumInsts);
525
526/// The debug values of the erased \p From are kept on its replacement \p To.
527/// A record placed before \p To is cloned right after it, while the original
528/// one is killed together with the scalar, so the variable is undefined up to
529/// \p To. The clone is skipped if it would pass a record of the same variable,
530/// otherwise the variable would show a stale value.
531void redirectDbgValues(Instruction &From, Value &To);
532/// \returns true if \p IE1 is inserted before \p IE2 in their build-vector
533/// chain. Both must have constant insert indices and belong to one chain.
535 const InsertElementInst *IE2);
536
537/// \returns the debug location of \p PN, or an unknown location if it has
538/// none.
540
541/// \returns the number of elements of the homogeneous aggregate built by
542/// \p InsertInst (insertelement or insertvalue), or std::nullopt if it is not
543/// a homogeneous aggregate.
544std::optional<unsigned> getAggregateSize(Instruction *InsertInst);
545
546/// \returns the innermost loop starting from \p L for which at least one value
547/// in \p VL is not loop-invariant.
549
550/// \returns an estimated trip count for \p L, bounded by the loop-aware budget
551/// \p LoopAwareTripCount. Returns 1 when the budget is 0.
552unsigned getLoopTripCount(const Loop *L, ScalarEvolution &SE,
553 unsigned LoopAwareTripCount);
554
555} // namespace llvm::slpvectorizer
556
557#endif // LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPUTILS_H
uint64_t uint64_t
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file provides utility analysis objects describing memory locations.
This file contains some templates that are useful if you are working with the STL at all.
This file implements the SmallBitVector class.
This file defines the SmallVector class.
This pass exposes codegen information to IR-level passes.
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition APInt.h:78
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A cache of @llvm.assume calls within a function.
This is an important base class in LLVM.
Definition Constant.h:44
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
A debug info location.
Definition DebugLoc.h:126
Common base class shared among various IRBuilders.
Definition IRBuilder.h:111
This instruction inserts a single (scalar) element into a VectorType value.
An instruction for reading from memory.
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
The main scalar evolution driver.
This class represents the LLVM 'select' instruction.
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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.
TargetCostKind
The kind of cost model.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
An efficient, type-erasing, non-owning reference to a callable.
Caches the results of the expensive analyses that are queried repeatedly for the same values while th...
A private "module" namespace for types and utilities used by this pass.
std::optional< unsigned > getExtractIndex(const Instruction *E)
Definition SLPUtils.cpp:300
Value * createInsertVector(IRBuilderBase &Builder, Value *Vec, Value *V, unsigned Index, function_ref< Value *(Value *, Value *, ArrayRef< int >)> Generator)
Creates subvector insert.
Definition SLPUtils.cpp:706
bool areAllOperandsNonInsts(Value *V)
Checks if the provided value does not require scheduling.
Definition SLPUtils.cpp:480
std::optional< unsigned > getElementIndex(const Value *Inst, unsigned Offset)
Definition SLPUtils.cpp:254
DebugLoc getDebugLocFromPHI(const PHINode &PN)
bool doesInTreeUserNeedToExtract(Value *Scalar, Instruction *UserInst, TargetLibraryInfo *TLI, const TargetTransformInfo *TTI)
Definition SLPUtils.cpp:809
bool isCopyableGEPAddressVector(ArrayRef< Value * > PointerOps)
Checks if the pointers PointerOps of the gathered loads, which are not compatible in the usual sense ...
Definition SLPUtils.cpp:947
std::optional< std::tuple< Value *, unsigned, SmallVector< int > > > matchGatheredExtractedFields(ArrayRef< Value * > VL, const DataLayout &DL)
Checks if the values in VL are zero-extended sub-fields of the same wider integer scalar.
MemoryLocation getLocation(Instruction *I)
Definition SLPUtils.cpp:837
std::optional< BitPackInfo > computeBitPackInfo(unsigned BitWidth, ArrayRef< APInt > PossibleBits, ArrayRef< uint64_t > ShlAmts, ArrayRef< APInt > Masks)
Computes the bitfield packing layout from the per-lane possibly set bits of the source values,...
bool isSelectedBaseLoad(Type *ScalarTy, ArrayRef< Value * > PointerOps, const DataLayout &DL, Value *&TrueBase, Value *&FalseBase, SmallVectorImpl< Value * > &Conditions)
Checks if the loads with scalar type ScalarTy and pointer operands PointerOps are each (optionally vi...
Definition SLPUtils.cpp:855
SmallBitVector getAltInstrMask(ArrayRef< Value * > VL, Type *ScalarTy, unsigned Opcode0, unsigned Opcode1)
SmallBitVector isUndefVector(const Value *V, const SmallBitVector &UseMask)
Checks if the given value is actually an undefined constant vector.
Definition SLPUtils.cpp:759
Intrinsic::ID getMaskedDivRemIntrinsic(unsigned Opcode)
bool isUsedOutsideBlock(Value *V)
Checks if the provided value does not require scheduling.
Definition SLPUtils.cpp:491
bool doesNotNeedToSchedule(ArrayRef< Value * > VL)
Checks if the specified array of instructions does not require scheduling.
Definition SLPUtils.cpp:508
std::optional< unsigned > getInsertExtractIndex(const Value *Inst, unsigned Offset)
Definition SLPUtils.cpp:447
void redirectDbgValues(Instruction &From, Value &To)
The debug values of the erased From are kept on its replacement To.
void reorderScalars(SmallVectorImpl< Value * > &Scalars, ArrayRef< int > Mask)
Reorders the list of scalars in accordance with the given Mask.
Definition SLPUtils.cpp:333
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...
SelectInst * getBlendedLoadSelect(ArrayRef< Value * > VL)
Returns the select instruction picking between the candidate base pointers of the blended loads VL.
Definition SLPUtils.cpp:908
bool allSameType(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:440
void combineOrders(MutableArrayRef< unsigned > Order, ArrayRef< unsigned > SecondaryOrder)
Fills unset elements of Order (marked with the sentinel value equal to the order size) with the corre...
Definition SLPUtils.cpp:418
bool allSameOpcode(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:282
bool isSplat(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:165
unsigned getNumElements(Type *Ty)
Definition SLPUtils.cpp:110
std::string shortBundleName(ArrayRef< Value * > VL, int Idx)
Print a short descriptor of the instruction bundle suitable for debug output.
Definition SLPUtils.cpp:127
unsigned getLoopTripCount(const Loop *L, ScalarEvolution &SE, unsigned LoopAwareTripCount)
bool isOnceUsedSeed(const Instruction *I)
Returns true if I forms a vectorizable bundle on its own and its single user does not tear the vector...
unsigned getPartNumElems(unsigned Size, unsigned NumParts)
Returns power-of-2 number of elements in a single register (part), given the total number of elements...
Definition SLPUtils.cpp:118
bool isCommutableOperand(const Instruction *I, Value *ValWithUses, unsigned Op, bool IsCopyable)
Checks if the operand is commutative.
Definition SLPUtils.cpp:226
Align computeBlendedLoadBaseAlignment(ArrayRef< Value * > VL, const DataLayout &DL)
Returns the alignment of the shared base pointer of a blended load for the loads VL.
Definition SLPUtils.cpp:895
TargetTransformInfo::TargetCostKind getSLPCostKind(const Function *F)
bool isReverseOrder(ArrayRef< unsigned > Order)
Check if Order represents reverse order.
Definition SLPUtils.cpp:397
Type * getCommonGEPIndexType(ArrayRef< Value * > VL, Instruction *VL0, function_ref< bool(Value *)> IsGEPLane, const DataLayout &DL)
Returns the common type for the indices of the single-index GEP lanes of a GEP node with the main op ...
Definition SLPUtils.cpp:915
void transformScalarShuffleIndiciesToVector(unsigned VecTyNumElements, SmallVectorImpl< int > &Mask)
Definition SLPUtils.cpp:513
SmallVector< int > calculateShufflevectorMask(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:568
SmallBitVector buildUseMask(int VF, ArrayRef< int > Mask, UseMask MaskArg)
Prepares a use bitset for the given mask either for the first argument or for the second.
Definition SLPUtils.cpp:742
bool isCommutative(const Instruction *I, const Value *ValWithUses, bool IsCopyable)
Definition SLPUtils.cpp:188
unsigned getNumberOfPotentiallyCommutativeOps(Instruction *I)
Definition SLPUtils.cpp:244
bool allConstant(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:159
void inversePermutation(ArrayRef< unsigned > Indices, SmallVectorImpl< int > &Mask)
Compute the inverse permutation Mask of Indices.
Definition SLPUtils.cpp:324
bool allSameBlock(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:137
bool isReassocChainLink(const Instruction *I)
Definition SLPUtils.cpp:82
Intrinsic::ID isEquivalentIntrinsicID(Intrinsic::ID LHS, Intrinsic::ID RHS)
Checks if LHS and RHS are the same intrinsic, or one is llvm.fma and the other is llvm....
Definition SLPUtils.cpp:179
std::optional< TargetTransformInfo::ShuffleKind > isFixedVectorShuffle(ArrayRef< Value * > VL, SmallVectorImpl< int > &Mask, AssumptionCache *AC, SLPAnalysisCache &Cache)
Checks if the vector of instructions can be represented as a shuffle, like: x0 = extractelement <4 x ...
Definition SLPUtils.cpp:608
UseMask
Specifies the way the mask should be analyzed for undefs/poisonous elements in the shuffle mask.
Definition SLPUtils.h:308
@ SecondArg
The mask is expected to be for permutation of 2 vectors, check for the mask elements for the second a...
Definition SLPUtils.h:312
@ UndefsAsMask
Consider undef mask elements (-1) as placeholders for future shuffle elements and mark them as ones a...
Definition SLPUtils.h:315
@ FirstArg
The mask is expected to be for permutation of 1-2 vectors, check for the mask elements for the first ...
Definition SLPUtils.h:309
void reorderOrder(SmallVectorImpl< unsigned > &Order, ArrayRef< int > Mask, bool BottomOrder)
Reorders the given Order according to the given Mask.
Definition SLPUtils.cpp:353
void reorderReuses(SmallVectorImpl< int > &Reuses, ArrayRef< int > Mask)
Reorders the given Reuses mask according to the given Mask.
Definition SLPUtils.cpp:343
void addMask(SmallVectorImpl< int > &Mask, ArrayRef< int > SubMask, bool ExtendingManyInputs)
Shuffles Mask in accordance with the given SubMask.
bool isSimple(Instruction *I)
Definition SLPUtils.cpp:845
Instruction * lookThroughCastRoundTrip(Value *V, bool MustBeElidable)
If V is a single-use fpext of a single-use fptrunc forming a round-trip back to the type of V,...
std::optional< unsigned > getAggregateSize(Instruction *InsertInst)
const LoadInst * getLoadOfUndefTolerantBinOp(const Value *V)
Definition SLPUtils.cpp:62
bool isBinOpIdentityConstant(const Value *V, unsigned Opcode)
Definition SLPUtils.cpp:51
bool isUndefTolerantBinOp(const Value *V)
Definition SLPUtils.cpp:56
APInt getScalarMaxValue(const Value *V, unsigned Depth)
Returns a saturating unsigned upper bound of the scalar V.
Value * buildBitPack(IRBuilderBase &Builder, Value *X, const BitPackInfo &Info, Type *ResultTy, unsigned ShiftWidth, unsigned &NumInsts)
Builds the bitfield packing of X into ResultTy per the layout and the shift width.
unsigned getShufflevectorNumGroups(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:528
const Loop * findInnermostNonInvariantLoop(const Loop *L, ArrayRef< Value * > VL)
SmallVector< Constant * > replicateMask(ArrayRef< Constant * > Val, unsigned VF)
Replicates the given Val VF times.
unsigned getReassocCombineOpcode(unsigned Opcode)
Definition SLPUtils.cpp:71
bool isVectorLikeInstWithConstOps(Value *V)
Checks if V is one of vector-like instructions, i.e.
Definition SLPUtils.cpp:90
bool doesNotNeedToBeScheduled(Value *V)
Checks if the specified value does not require scheduling.
Definition SLPUtils.cpp:504
unsigned getNumElems(unsigned Size, unsigned PartNumElems, unsigned Part)
Returns correct remaining number of elements, considering total amount Size, (power-of-2 number) of e...
Definition SLPUtils.cpp:122
constexpr int UsesLimit
Limit of the number of uses for potentially transformed instructions/values, used in checks to avoid ...
Definition SLPUtils.h:59
bool isFirstInsertElement(const InsertElementInst *IE1, const InsertElementInst *IE2)
void collectNarrowedLeaves(Value *V, unsigned RdxOpcode, unsigned WideBW, unsigned MaxDepth, SmallVectorImpl< NarrowedLeafInfo > &Leaves, SmallVectorImpl< Instruction * > &ChainInsts)
Recursively collects the narrow leaves of the widened reduction value V.
bool isRepeatedNonIdentityClusteredMask(ArrayRef< int > Mask, unsigned Sz)
Checks if the given mask is a "clustered" mask with the same clusters of size Sz, which are not ident...
Definition SLPUtils.cpp:406
bool isConstant(Value *V)
Definition SLPUtils.cpp:47
Value * createExtractVector(IRBuilderBase &Builder, Value *Vec, unsigned SubVecVF, unsigned Index)
Generates subvector extract.
Definition SLPUtils.cpp:735
void fixupOrderingIndices(MutableArrayRef< unsigned > Order)
Order may have elements assigned special value (size) which is out of bounds.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
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
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
TargetTransformInfo TTI
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr unsigned BitWidth
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1933
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:878
Description of a bitfield packing of vector lanes into a scalar value: every lane contributes a disjo...
Definition SLPUtils.h:494
SmallVector< unsigned, 8 > LaneOfField
Lane covering each field, NoLane if the field is always zero.
Definition SLPUtils.h:498
bool needsShift() const
True if any lane needs a right shift to align its field content.
Definition SLPUtils.h:503
static constexpr unsigned NoLane
Definition SLPUtils.h:495
SmallVector< uint64_t, 8 > LShrAmts
Per-lane right-shift amounts bringing the field content to the low bits.
Definition SLPUtils.h:500
NarrowedLeafInfo(Value *V, unsigned Shift, APInt Mask)
Definition SLPUtils.h:456
bool Disjoint
Set to false, if the or chain is not disjoint.
Definition SLPUtils.h:463