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 Instruction;
40class IRBuilderBase;
41class LoadInst;
43class Type;
44class Value;
45} // namespace llvm
46
47namespace llvm::slpvectorizer {
48
49/// Limit of the number of uses for potentially transformed instructions/values,
50/// used in checks to avoid compile-time explode.
51inline constexpr int UsesLimit = 64;
52
53/// \returns True if the value is a constant (but not globals/constant
54/// expressions).
55bool isConstant(Value *V);
56
57/// \returns True if \p V is the integer identity constant for binary \p Opcode
58/// (e.g. 0 for add, 1 for mul, all-ones for and). Floating-point identities are
59/// excluded: a ConstantInt never matches the ConstantFP getBinOpIdentity()
60/// returns for FAdd/FMul, whose identity fast-math may break anyway.
61bool isBinOpIdentityConstant(const Value *V, unsigned Opcode);
62
63/// \returns True if \p V is an integer binary operator, which gives an undef
64/// result for the undef operands: neither a shift nor a division.
65bool isUndefTolerantBinOp(const Value *V);
66
67/// \returns the load operand of the undef tolerant binary operator \p V, if
68/// any.
70
71/// \returns the opcode of the combines emitted for a reassociated node:
72/// subtract chains regroup their positive and negative operand columns with
73/// plain adds.
74unsigned getReassocCombineOpcode(unsigned Opcode);
75
76/// \returns True if \p I can be a link of a flattenable binary chain:
77/// subtracts flatten as adds of a negated leaf, float subtracts need reassoc
78/// to allow the regrouping.
80
81/// Checks if \p V is one of vector-like instructions, i.e. undef,
82/// insertelement/extractelement with constant indices for fixed vector type
83/// or extractvalue instruction.
85
86/// \returns the number of elements for Ty.
87unsigned getNumElements(Type *Ty);
88
89/// Returns power-of-2 number of elements in a single register (part), given
90/// the total number of elements \p Size and number of registers (parts) \p
91/// NumParts.
92unsigned getPartNumElems(unsigned Size, unsigned NumParts);
93
94/// Returns correct remaining number of elements, considering total amount
95/// \p Size, (power-of-2 number) of elements in a single register
96/// \p PartNumElems and current register (part) \p Part.
97unsigned getNumElems(unsigned Size, unsigned PartNumElems, unsigned Part);
98
99#if !defined(NDEBUG)
100/// Print a short descriptor of the instruction bundle suitable for debug
101/// output.
102std::string shortBundleName(ArrayRef<Value *> VL, int Idx = -1);
103#endif
104
105/// \returns True if all of the instructions in \p VL are in the same block.
107
108/// \returns True if all of the values in \p VL are constants (but not
109/// globals/constant expressions).
111
112/// \returns True if all of the values in \p VL are identical or some of them
113/// are UndefValue.
115
116/// Checks if \p LHS and \p RHS are the same intrinsic, or one is llvm.fma
117/// and the other is llvm.fmuladd, since both lower to the same fused
118/// vector operation.
119/// \returns the intrinsic ID to use for the pair (\p RHS if the IDs match,
120/// otherwise Intrinsic::fma), or Intrinsic::not_intrinsic if they are not
121/// equivalent.
123
124/// \returns True if \p I is commutative, handles CmpInst and BinaryOperator.
125/// For BinaryOperator, it also checks if \p ValWithUses is used in specific
126/// patterns that make it effectively commutative (like equality comparisons
127/// with zero).
128/// In most cases, users should not call this function directly (since \p I and
129/// \p ValWithUses are the same). However, when analyzing interchangeable
130/// instructions, we need to use the converted opcode along with the original
131/// uses.
132/// \param I The instruction to check for commutativity
133/// \param ValWithUses The value whose uses are analyzed for special
134/// patterns
135bool isCommutative(const Instruction *I, const Value *ValWithUses,
136 bool IsCopyable = false);
137
138/// This is a helper function to check whether \p I is commutative.
139/// This is a convenience wrapper that calls the two-parameter version of
140/// isCommutative with the same instruction for both parameters. This is
141/// the common case where the instruction being checked for commutativity
142/// is the same as the instruction whose uses are analyzed for special
143/// patterns (see the two-parameter version above for details).
144/// \param I The instruction to check for commutativity
145/// \returns true if the instruction is commutative, false otherwise
146bool isCommutative(const Instruction *I);
147
148/// Checks if the operand is commutative. In commutative operations, not all
149/// operands might commutable, e.g. for fmuladd only 2 first operands are
150/// commutable.
151bool isCommutableOperand(const Instruction *I, Value *ValWithUses, unsigned Op,
152 bool IsCopyable = false);
153
154/// \returns number of operands of \p I, considering commutativity. Returns 2
155/// for commutative intrinsics.
156/// \param I The instruction to check for commutativity
158
159/// \returns inserting or extracting index of InsertElement, ExtractElement
160/// or InsertValue instruction, using \p Offset as base offset for index.
161/// \returns std::nullopt if the index is not an immediate.
162std::optional<unsigned> getElementIndex(const Value *Inst, unsigned Offset = 0);
163
164/// \returns True if all of the values in \p VL use the same opcode.
165/// For comparison instructions, also checks if predicates match.
166/// PoisonValues are considered matching. Interchangeable instructions are
167/// not considered.
169
170/// \returns Optional element Idx for Extract{Value,Element} instructions.
171std::optional<unsigned> getExtractIndex(const Instruction *E);
172
173/// Compute the inverse permutation \p Mask of \p Indices.
175
176/// Reorders the list of scalars in accordance with the given \p Mask.
178
179/// Reorders the given \p Reuses mask according to the given \p Mask. \p Reuses
180/// contains original mask for the scalars reused in the node. Procedure
181/// transform this mask in accordance with the given \p Mask.
183
184/// Reorders the given \p Order according to the given \p Mask. \p Order - is
185/// the original order of the scalars. Procedure transforms the provided order
186/// in accordance with the given \p Mask. If the resulting \p Order is just an
187/// identity order, \p Order is cleared.
189 bool BottomOrder = false);
190
191/// Check if \p Order represents reverse order.
193
194/// Checks if the given mask is a "clustered" mask with the same clusters of
195/// size \p Sz, which are not identity submasks.
197
198/// Fills unset elements of \p Order (marked with the sentinel value equal to
199/// the order size) with the corresponding elements of \p SecondaryOrder,
200/// skipping already used indices, or with the identity order if
201/// \p SecondaryOrder is empty.
203 ArrayRef<unsigned> SecondaryOrder);
204
205/// \returns True iff every value in \p VL has the same Type as the first.
207
208/// Checks if the provided value does not require scheduling. It does not
209/// require scheduling if this is not an instruction or it is an instruction
210/// that does not read/write memory and all operands are either not
211/// instructions or phi nodes or instructions from different blocks.
213
214/// Checks if the provided value does not require scheduling. It does not
215/// require scheduling if this is not an instruction or it is an instruction
216/// that does not read/write memory and all users are phi nodes or
217/// instructions from different blocks.
219
220/// Checks if the specified value does not require scheduling. It does not
221/// require scheduling if all operands and all users do not need to be
222/// scheduled in the current basic block.
224
225/// Checks if the specified array of instructions does not require scheduling.
226/// It is so if all either instructions have operands that do not require
227/// scheduling or their users do not require scheduling since they are phis or
228/// in other basic blocks.
230
231/// \returns inserting or extracting index of InsertElement / ExtractElement
232/// instruction, using \p Offset as base offset for index. Only instantiated
233/// for InsertElementInst and ExtractElementInst (see SLPUtils.cpp).
234template <typename T>
235std::optional<unsigned> getInsertExtractIndex(const Value *Inst,
236 unsigned Offset);
237
238void transformScalarShuffleIndiciesToVector(unsigned VecTyNumElements,
240
241/// \returns the number of groups of shufflevector
242/// A group has the following features
243/// 1. All of value in a group are shufflevector.
244/// 2. The mask of all shufflevector is isExtractSubvectorMask.
245/// 3. The mask of all shufflevector uses all of the elements of the source.
246/// e.g., it is 1 group (%0)
247/// %1 = shufflevector <16 x i8> %0, <16 x i8> poison,
248/// <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
249/// %2 = shufflevector <16 x i8> %0, <16 x i8> poison,
250/// <8 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
251/// it is 2 groups (%3 and %4)
252/// %5 = shufflevector <8 x i16> %3, <8 x i16> poison,
253/// <4 x i32> <i32 0, i32 1, i32 2, i32 3>
254/// %6 = shufflevector <8 x i16> %3, <8 x i16> poison,
255/// <4 x i32> <i32 4, i32 5, i32 6, i32 7>
256/// %7 = shufflevector <8 x i16> %4, <8 x i16> poison,
257/// <4 x i32> <i32 0, i32 1, i32 2, i32 3>
258/// %8 = shufflevector <8 x i16> %4, <8 x i16> poison,
259/// <4 x i32> <i32 4, i32 5, i32 6, i32 7>
260/// it is 0 group
261/// %12 = shufflevector <8 x i16> %10, <8 x i16> poison,
262/// <4 x i32> <i32 0, i32 1, i32 2, i32 3>
263/// %13 = shufflevector <8 x i16> %11, <8 x i16> poison,
264/// <4 x i32> <i32 0, i32 1, i32 2, i32 3>
266
267/// \returns a shufflevector mask which is used to vectorize shufflevectors
268/// e.g.,
269/// %5 = shufflevector <8 x i16> %3, <8 x i16> poison,
270/// <4 x i32> <i32 0, i32 1, i32 2, i32 3>
271/// %6 = shufflevector <8 x i16> %3, <8 x i16> poison,
272/// <4 x i32> <i32 4, i32 5, i32 6, i32 7>
273/// %7 = shufflevector <8 x i16> %4, <8 x i16> poison,
274/// <4 x i32> <i32 0, i32 1, i32 2, i32 3>
275/// %8 = shufflevector <8 x i16> %4, <8 x i16> poison,
276/// <4 x i32> <i32 4, i32 5, i32 6, i32 7>
277/// the result is
278/// <0, 1, 2, 3, 12, 13, 14, 15, 16, 17, 18, 19, 28, 29, 30, 31>
280
281/// Checks if the values in \p VL can be represented as a shuffle of at most
282/// two vector operands (extractelement lanes). On success, \p Mask is the
283/// equivalent shuffle mask.
284std::optional<TargetTransformInfo::ShuffleKind>
286 AssumptionCache *AC);
287
288/// Creates subvector insert. Generates shuffle using \p Generator or
289/// using default shuffle.
291 IRBuilderBase &Builder, Value *Vec, Value *V, unsigned Index,
292 function_ref<Value *(Value *, Value *, ArrayRef<int>)> Generator = {});
293
294/// Generates subvector extract.
296 unsigned SubVecVF, unsigned Index);
297
298/// Specifies the way the mask should be analyzed for undefs/poisonous elements
299/// in the shuffle mask.
300enum class UseMask {
301 FirstArg, ///< The mask is expected to be for permutation of 1-2 vectors,
302 ///< check for the mask elements for the first argument (mask
303 ///< indices are in range [0:VF)).
304 SecondArg, ///< The mask is expected to be for permutation of 2 vectors, check
305 ///< for the mask elements for the second argument (mask indices
306 ///< are in range [VF:2*VF))
307 UndefsAsMask ///< Consider undef mask elements (-1) as placeholders for
308 ///< future shuffle elements and mark them as ones as being used
309 ///< in future. Non-undef elements are considered as unused since
310 ///< they're already marked as used in the mask.
311};
312
313/// Prepares a use bitset for the given mask either for the first argument or
314/// for the second.
315SmallBitVector buildUseMask(int VF, ArrayRef<int> Mask, UseMask MaskArg);
316
317/// Checks if the given value is actually an undefined constant vector.
318/// Also, if the \p UseMask is not empty, tries to check if the non-masked
319/// elements actually mask the insertelement buildvector, if any.
320template <bool IsPoisonOnly = false>
322 const SmallBitVector &UseMask = {});
323
324/// \returns True if in-tree use also needs extract. This refers to
325/// possible scalar operand in vectorized instruction.
326bool doesInTreeUserNeedToExtract(Value *Scalar, Instruction *UserInst,
327 TargetLibraryInfo *TLI,
328 const TargetTransformInfo *TTI);
329
330/// \returns the AA location that is being access by the instruction.
331MemoryLocation getLocation(Instruction *I);
332
333/// \returns True if the instruction is not a volatile or atomic load/store.
334bool isSimple(Instruction *I);
335
336/// Checks if the loads with scalar type \p ScalarTy and pointer operands
337/// \p PointerOps are each (optionally via a constant-offset GEP) a
338/// `select Cond, A, B` picking between the same two base pointers A/B on
339/// every lane - the shape a fully unrolled `x = cond ? A[i] : B[i]` takes. On
340/// success \p TrueBase / \p FalseBase are the candidate bases and
341/// \p Conditions holds each lane's `select` condition, used to build the
342/// blend mask. Lane \p Idx must be at `Base + Idx * sizeof(ScalarTy)`; only
343/// dense, natural lane order starting at the base is recognized (reordered or
344/// partial groups fall back to Gather/Scatter).
345bool isSelectedBaseLoad(Type *ScalarTy, ArrayRef<Value *> PointerOps,
346 const DataLayout &DL, Value *&TrueBase,
347 Value *&FalseBase,
348 SmallVectorImpl<Value *> &Conditions);
349
350/// Returns the alignment of the shared base pointer of a blended load for
351/// the loads \p VL.
353 const DataLayout &DL);
354
355/// Returns the common type for the indices of the single-index GEP lanes of
356/// a GEP node with the main op \p VL0, or nullptr if no such type exists.
357/// \p IsGEPLane tells which lanes of \p VL are matching GEPs, whose index is
358/// used as is; all other lanes (copyable, poison, non-GEP pointers) are
359/// modeled as gep V, 0 and just take a zero index of the common type.
360/// The common type is the index type of \p VL0 if all matching lanes share
361/// it. Otherwise the constant indices are cast: to the pointer index type if
362/// there are no non-constant indices (or the index type of \p VL0 already is
363/// the pointer index type), or to the index type of \p VL0 if all the
364/// non-constant indices have that type and all the constants are
365/// representable in it (GEP indices are sign-extended to the pointer index
366/// width, so the value must fit as a signed number). A non-constant index of
367/// a different type cannot be cast without a new instruction, so no common
368/// type exists.
369Type *getCommonGEPIndexType(ArrayRef<Value *> VL, Instruction *VL0,
370 function_ref<bool(Value *)> IsGEPLane,
371 const DataLayout &DL);
372
373/// Checks if the pointers \p PointerOps of the gathered loads, which are not
374/// compatible in the usual sense (some of them are constant-offset pointers,
375/// some have runtime indices), still form a cheap address vector as a
376/// copyable GEP node: a splat of the common base and a vector of indices.
377/// The constant-offset lanes are the base itself or single-index GEPs of the
378/// base with a constant index (modeled as gep V, 0 or as matching lanes with
379/// constant indices), the other lanes are single-index GEPs of the base of
380/// the same shape, whose indices are affine in a single runtime value (the
381/// stride): optionally cast (all with the same cast opcode) values, each of
382/// which is the stride itself or a binary operation of the stride and a
383/// constant, like b[i * S] or b[S + i]. Duplicate lanes are not accepted:
384/// the node would be a shuffled non-full vector, gathering the loads is
385/// cheaper then.
387
388/// Shuffles \p Mask in accordance with the given \p SubMask.
389/// \param ExtendingManyInputs Supports reshuffling of the mask with not only
390/// one but two input vectors.
391void addMask(SmallVectorImpl<int> &Mask, ArrayRef<int> SubMask,
392 bool ExtendingManyInputs = false);
393
394/// Order may have elements assigned special value (size) which is out of
395/// bounds. Such indices only appear on places which correspond to undef values
396/// (see canReuseExtract for details) and used in order to avoid undef values
397/// have effect on operands ordering.
398/// The first loop below simply finds all unused indices and then the next loop
399/// nest assigns these indices for undef values positions.
400/// As an example below Order has two undef positions and they have assigned
401/// values 3 and 7 respectively:
402/// before: 6 9 5 4 9 2 1 0
403/// after: 6 3 5 4 7 2 1 0
405
406/// \returns a bitset for selecting opcodes. false for Opcode0 and true for
407/// Opcode1.
408SmallBitVector getAltInstrMask(ArrayRef<Value *> VL, Type *ScalarTy,
409 unsigned Opcode0, unsigned Opcode1);
410
411/// Replicates the given \p Val \p VF times.
413
414/// \returns the masked division/remainder intrinsic corresponding to \p
415/// Opcode. Disabled lanes of these intrinsics are poison rather than UB,
416/// unlike the plain opcode.
418
419/// Returns true if \p I forms a vectorizable bundle on its own and its single
420/// user does not tear the vector apart. Loads and addresses are excluded: the
421/// tree is built without the users, so it does not pay off the extracts. A
422/// cast, feeding a multi-used cast, is excluded for the same reason, such a
423/// user stays scalar. The fp-to-int conversions move the result to the other
424/// register domain, so the extracts are paid on top of the repacking. The
425/// values, feeding the inserts, are vectorized together with them by the
426/// dedicated attempt.
427bool isOnceUsedSeed(const Instruction *I);
428
429/// If \p V is a single-use fpext of a single-use fptrunc forming a round-trip
430/// back to the type of \p V, returns the fptrunc; the round-trip source is its
431/// operand, always an instruction of the same type as \p V. If
432/// \p MustBeElidable, matches only when the intermediate rounding may be
433/// removed: both casts must allow contraction and the widening cast cannot
434/// produce nan/inf.
435Instruction *lookThroughCastRoundTrip(Value *V, bool MustBeElidable);
436
437/// Narrow reduction leaf: the value, the shift applied after widening and
438/// the mask applied in the narrow type before widening, clearing the bits
439/// the absorbed narrow shls shift out and applying the absorbed narrow
440/// and-masks. Lossless narrow shls contribute their known-zero bits to the
441/// mask so matching lanes can form a splat. All-ones mask means nothing
442/// was absorbed and no 'and' is needed.
446
447 Value *V = nullptr;
448 unsigned Shift = 0;
450 /// Set to false, if the or chain is not disjoint
451 bool Disjoint = true;
452};
453
454/// Recursively collects the narrow leaves of the widened reduction value
455/// \p V. zext is looked through directly, same-kind binops per operand,
456/// shl of a zext - only if no bits are shifted out in the current type,
457/// shls in narrower types fold into the shift and ands with a constant into
458/// the mask applied in the narrow type. Also collects the looked-through
459/// instructions into \p ChainInsts.
460void collectNarrowedLeaves(Value *V, unsigned RdxOpcode, unsigned WideBW,
461 unsigned MaxDepth,
464
466
467/// Returns a saturating unsigned upper bound of the scalar V. The numeric
468/// bound keeps precision on arithmetic carries, where bit-wise analysis
469/// loses it.
470APInt getScalarMaxValue(const Value *V, unsigned Depth = 0);
471
472/// Checks if the values in \p VL are zero-extended sub-fields of the same
473/// wider integer scalar. Returns the source scalar, the field width and the
474/// field permutation mask. The extraction dual of the lane-packing layout.
475/// The field-to-lane mapping of the bitcast to the field vector is defined
476/// for little-endian targets only.
477std::optional<std::tuple<Value *, unsigned, SmallVector<int>>>
479
480/// Description of a bitfield packing of vector lanes into a scalar value:
481/// every lane contributes a disjoint contiguous byte field of the result.
483 static constexpr unsigned NoLane = std::numeric_limits<unsigned>::max();
484 unsigned FieldWidth = 0;
485 /// Lane covering each field, NoLane if the field is always zero.
487 /// Per-lane right-shift amounts bringing the field content to the low bits.
489
490 /// True if any lane needs a right shift to align its field content.
491 bool needsShift() const {
492 return any_of(LShrAmts, [](uint64_t A) { return A != 0; });
493 }
494};
495
496/// Computes the bitfield packing layout from the per-lane possibly set bits
497/// of the source values, the per-lane left-shift amounts and the per-lane
498/// masks (all-ones for unmasked lanes).
499std::optional<BitPackInfo> computeBitPackInfo(unsigned BitWidth,
500 ArrayRef<APInt> PossibleBits,
501 ArrayRef<uint64_t> ShlAmts,
502 ArrayRef<APInt> Masks);
503
504/// Returns the byte shuffle mask packing the per-lane fields of the shifted
505/// lanes (BytesPerLane bytes each) into the packed scalar of NumBytes bytes.
506SmallVector<int> getBitPackMask(const BitPackInfo &Info, unsigned NumBytes,
507 unsigned NumElts, unsigned BytesPerLane);
508
509/// Builds the bitfield packing of X per the layout and the shift width.
510/// \p NumInsts returns the number of emitted instructions.
511Value *buildBitPack(IRBuilderBase &Builder, Value *X, const BitPackInfo &Info,
512 unsigned ShiftWidth, unsigned &NumInsts);
513
514/// The debug values of the erased \p From are kept on its replacement \p To.
515/// A record placed before \p To is cloned right after it, while the original
516/// one is killed together with the scalar, so the variable is undefined up to
517/// \p To. The clone is skipped if it would pass a record of the same variable,
518/// otherwise the variable would show a stale value.
519void redirectDbgValues(Instruction &From, Value &To);
520
521} // namespace llvm::slpvectorizer
522
523#endif // LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPUTILS_H
unsigned 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:857
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:43
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Common base class shared among various IRBuilders.
Definition IRBuilder.h:111
An instruction for reading from memory.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
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.
A private "module" namespace for types and utilities used by this pass.
std::optional< unsigned > getExtractIndex(const Instruction *E)
Definition SLPUtils.cpp:292
Value * createInsertVector(IRBuilderBase &Builder, Value *Vec, Value *V, unsigned Index, function_ref< Value *(Value *, Value *, ArrayRef< int >)> Generator)
Creates subvector insert.
Definition SLPUtils.cpp:692
bool areAllOperandsNonInsts(Value *V)
Checks if the provided value does not require scheduling.
Definition SLPUtils.cpp:472
std::optional< unsigned > getElementIndex(const Value *Inst, unsigned Offset)
Definition SLPUtils.cpp:246
bool doesInTreeUserNeedToExtract(Value *Scalar, Instruction *UserInst, TargetLibraryInfo *TLI, const TargetTransformInfo *TTI)
Definition SLPUtils.cpp:795
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:926
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:823
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:841
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:745
Intrinsic::ID getMaskedDivRemIntrinsic(unsigned Opcode)
bool isUsedOutsideBlock(Value *V)
Checks if the provided value does not require scheduling.
Definition SLPUtils.cpp:483
bool doesNotNeedToSchedule(ArrayRef< Value * > VL)
Checks if the specified array of instructions does not require scheduling.
Definition SLPUtils.cpp:501
std::optional< unsigned > getInsertExtractIndex(const Value *Inst, unsigned Offset)
Definition SLPUtils.cpp:439
Value * buildBitPack(IRBuilderBase &Builder, Value *X, const BitPackInfo &Info, unsigned ShiftWidth, unsigned &NumInsts)
Builds the bitfield packing of X per the layout and the shift width.
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:325
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...
bool allSameType(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:432
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:410
bool allSameOpcode(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:274
bool isSplat(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:158
unsigned getNumElements(Type *Ty)
Definition SLPUtils.cpp:103
std::string shortBundleName(ArrayRef< Value * > VL, int Idx)
Print a short descriptor of the instruction bundle suitable for debug output.
Definition SLPUtils.cpp:120
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:111
bool isCommutableOperand(const Instruction *I, Value *ValWithUses, unsigned Op, bool IsCopyable)
Checks if the operand is commutative.
Definition SLPUtils.cpp:218
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:881
TargetTransformInfo::TargetCostKind getSLPCostKind(const Function *F)
bool isReverseOrder(ArrayRef< unsigned > Order)
Check if Order represents reverse order.
Definition SLPUtils.cpp:389
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:894
void transformScalarShuffleIndiciesToVector(unsigned VecTyNumElements, SmallVectorImpl< int > &Mask)
Definition SLPUtils.cpp:506
SmallVector< int > calculateShufflevectorMask(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:561
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:728
bool isCommutative(const Instruction *I, const Value *ValWithUses, bool IsCopyable)
Definition SLPUtils.cpp:181
unsigned getNumberOfPotentiallyCommutativeOps(Instruction *I)
Definition SLPUtils.cpp:236
bool allConstant(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:152
void inversePermutation(ArrayRef< unsigned > Indices, SmallVectorImpl< int > &Mask)
Compute the inverse permutation Mask of Indices.
Definition SLPUtils.cpp:316
bool allSameBlock(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:130
bool isReassocChainLink(const Instruction *I)
Definition SLPUtils.cpp:75
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:172
UseMask
Specifies the way the mask should be analyzed for undefs/poisonous elements in the shuffle mask.
Definition SLPUtils.h:300
@ SecondArg
The mask is expected to be for permutation of 2 vectors, check for the mask elements for the second a...
Definition SLPUtils.h:304
@ UndefsAsMask
Consider undef mask elements (-1) as placeholders for future shuffle elements and mark them as ones a...
Definition SLPUtils.h:307
@ FirstArg
The mask is expected to be for permutation of 1-2 vectors, check for the mask elements for the first ...
Definition SLPUtils.h:301
void reorderOrder(SmallVectorImpl< unsigned > &Order, ArrayRef< int > Mask, bool BottomOrder)
Reorders the given Order according to the given Mask.
Definition SLPUtils.cpp:345
void reorderReuses(SmallVectorImpl< int > &Reuses, ArrayRef< int > Mask)
Reorders the given Reuses mask according to the given Mask.
Definition SLPUtils.cpp:335
void addMask(SmallVectorImpl< int > &Mask, ArrayRef< int > SubMask, bool ExtendingManyInputs)
Shuffles Mask in accordance with the given SubMask.
Definition SLPUtils.cpp:983
bool isSimple(Instruction *I)
Definition SLPUtils.cpp:831
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,...
const LoadInst * getLoadOfUndefTolerantBinOp(const Value *V)
Definition SLPUtils.cpp:55
bool isBinOpIdentityConstant(const Value *V, unsigned Opcode)
Definition SLPUtils.cpp:44
bool isUndefTolerantBinOp(const Value *V)
Definition SLPUtils.cpp:49
APInt getScalarMaxValue(const Value *V, unsigned Depth)
Returns a saturating unsigned upper bound of the scalar V.
unsigned getShufflevectorNumGroups(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:521
std::optional< TargetTransformInfo::ShuffleKind > isFixedVectorShuffle(ArrayRef< Value * > VL, SmallVectorImpl< int > &Mask, AssumptionCache *AC)
Checks if the vector of instructions can be represented as a shuffle, like: x0 = extractelement <4 x ...
Definition SLPUtils.cpp:601
SmallVector< Constant * > replicateMask(ArrayRef< Constant * > Val, unsigned VF)
Replicates the given Val VF times.
unsigned getReassocCombineOpcode(unsigned Opcode)
Definition SLPUtils.cpp:64
bool isVectorLikeInstWithConstOps(Value *V)
Checks if V is one of vector-like instructions, i.e.
Definition SLPUtils.cpp:83
bool doesNotNeedToBeScheduled(Value *V)
Checks if the specified value does not require scheduling.
Definition SLPUtils.cpp:497
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:115
constexpr int UsesLimit
Limit of the number of uses for potentially transformed instructions/values, used in checks to avoid ...
Definition SLPUtils.h:51
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:398
bool isConstant(Value *V)
Definition SLPUtils.cpp:40
Value * createExtractVector(IRBuilderBase &Builder, Value *Vec, unsigned SubVecVF, unsigned Index)
Generates subvector extract.
Definition SLPUtils.cpp:721
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:482
SmallVector< unsigned, 8 > LaneOfField
Lane covering each field, NoLane if the field is always zero.
Definition SLPUtils.h:486
bool needsShift() const
True if any lane needs a right shift to align its field content.
Definition SLPUtils.h:491
static constexpr unsigned NoLane
Definition SLPUtils.h:483
SmallVector< uint64_t, 8 > LShrAmts
Per-lane right-shift amounts bringing the field content to the low bits.
Definition SLPUtils.h:488
NarrowedLeafInfo(Value *V, unsigned Shift, APInt Mask)
Definition SLPUtils.h:444
bool Disjoint
Set to false, if the or chain is not disjoint.
Definition SLPUtils.h:451