LLVM 24.0.0git
SLPUtils.cpp File Reference
#include "SLPUtils.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Sequence.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/Analysis/VectorUtils.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <numeric>
#include <string>
#include <type_traits>

Go to the source code of this file.

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.
namespace  llvm::slpvectorizer
 A private "module" namespace for types and utilities used by this pass.

Functions

bool llvm::slpvectorizer::isConstant (Value *V)
bool llvm::slpvectorizer::isBinOpIdentityConstant (const Value *V, unsigned Opcode)
unsigned llvm::slpvectorizer::getReassocCombineOpcode (unsigned Opcode)
bool llvm::slpvectorizer::isReassocChainLink (const Instruction *I)
bool llvm::slpvectorizer::isVectorLikeInstWithConstOps (Value *V)
 Checks if V is one of vector-like instructions, i.e.
unsigned llvm::slpvectorizer::getNumElements (Type *Ty)
unsigned llvm::slpvectorizer::getPartNumElems (unsigned Size, unsigned NumParts)
 Returns power-of-2 number of elements in a single register (part), given the total number of elements Size and number of registers (parts) NumParts.
unsigned llvm::slpvectorizer::getNumElems (unsigned Size, unsigned PartNumElems, unsigned Part)
 Returns correct remaining number of elements, considering total amount Size, (power-of-2 number) of elements in a single register PartNumElems and current register (part) Part.
std::string llvm::slpvectorizer::shortBundleName (ArrayRef< Value * > VL, int Idx=-1)
 Print a short descriptor of the instruction bundle suitable for debug output.
bool llvm::slpvectorizer::allSameBlock (ArrayRef< Value * > VL)
bool llvm::slpvectorizer::allConstant (ArrayRef< Value * > VL)
bool llvm::slpvectorizer::isSplat (ArrayRef< Value * > VL)
Intrinsic::ID llvm::slpvectorizer::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.fmuladd, since both lower to the same fused vector operation.
bool llvm::slpvectorizer::isCommutative (const Instruction *I, const Value *ValWithUses, bool IsCopyable)
bool llvm::slpvectorizer::isCommutative (const Instruction *I)
 This is a helper function to check whether I is commutative.
bool llvm::slpvectorizer::isCommutableOperand (const Instruction *I, Value *ValWithUses, unsigned Op, bool IsCopyable=false)
 Checks if the operand is commutative.
unsigned llvm::slpvectorizer::getNumberOfPotentiallyCommutativeOps (Instruction *I)
std::optional< unsignedllvm::slpvectorizer::getElementIndex (const Value *Inst, unsigned Offset)
bool llvm::slpvectorizer::allSameOpcode (ArrayRef< Value * > VL)
std::optional< unsignedllvm::slpvectorizer::getExtractIndex (const Instruction *E)
void llvm::slpvectorizer::inversePermutation (ArrayRef< unsigned > Indices, SmallVectorImpl< int > &Mask)
 Compute the inverse permutation Mask of Indices.
void llvm::slpvectorizer::reorderScalars (SmallVectorImpl< Value * > &Scalars, ArrayRef< int > Mask)
 Reorders the list of scalars in accordance with the given Mask.
void llvm::slpvectorizer::reorderReuses (SmallVectorImpl< int > &Reuses, ArrayRef< int > Mask)
 Reorders the given Reuses mask according to the given Mask.
void llvm::slpvectorizer::reorderOrder (SmallVectorImpl< unsigned > &Order, ArrayRef< int > Mask, bool BottomOrder=false)
 Reorders the given Order according to the given Mask.
bool llvm::slpvectorizer::isReverseOrder (ArrayRef< unsigned > Order)
 Check if Order represents reverse order.
bool llvm::slpvectorizer::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 identity submasks.
void llvm::slpvectorizer::combineOrders (MutableArrayRef< unsigned > Order, ArrayRef< unsigned > SecondaryOrder)
 Fills unset elements of Order (marked with the sentinel value equal to the order size) with the corresponding elements of SecondaryOrder, skipping already used indices, or with the identity order if SecondaryOrder is empty.
bool llvm::slpvectorizer::allSameType (ArrayRef< Value * > VL)
template<typename T>
std::optional< unsignedllvm::slpvectorizer::getInsertExtractIndex (const Value *Inst, unsigned Offset)
template std::optional< unsignedllvm::slpvectorizer::getInsertExtractIndex< InsertElementInst > (const Value *, unsigned)
template std::optional< unsignedllvm::slpvectorizer::getInsertExtractIndex< ExtractElementInst > (const Value *, unsigned)
bool llvm::slpvectorizer::areAllOperandsNonInsts (Value *V)
 Checks if the provided value does not require scheduling.
bool llvm::slpvectorizer::isUsedOutsideBlock (Value *V)
 Checks if the provided value does not require scheduling.
bool llvm::slpvectorizer::doesNotNeedToBeScheduled (Value *V)
 Checks if the specified value does not require scheduling.
bool llvm::slpvectorizer::doesNotNeedToSchedule (ArrayRef< Value * > VL)
 Checks if the specified array of instructions does not require scheduling.
void llvm::slpvectorizer::transformScalarShuffleIndiciesToVector (unsigned VecTyNumElements, SmallVectorImpl< int > &Mask)
unsigned llvm::slpvectorizer::getShufflevectorNumGroups (ArrayRef< Value * > VL)
SmallVector< int > llvm::slpvectorizer::calculateShufflevectorMask (ArrayRef< Value * > VL)
std::optional< TargetTransformInfo::ShuffleKindllvm::slpvectorizer::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 i8> x, i32 0 x3 = extractelement <4 x i8> x, i32 3 y1 = extractelement <4 x i8> y, i32 1 y2 = extractelement <4 x i8> y, i32 2 x0x0 = mul i8 x0, x0 x3x3 = mul i8 x3, x3 y1y1 = mul i8 y1, y1 y2y2 = mul i8 y2, y2 ins1 = insertelement <4 x i8> poison, i8 x0x0, i32 0 ins2 = insertelement <4 x i8> ins1, i8 x3x3, i32 1 ins3 = insertelement <4 x i8> ins2, i8 y1y1, i32 2 ins4 = insertelement <4 x i8> ins3, i8 y2y2, i32 3 ret <4 x i8> ins4 can be transformed into: %1 = shufflevector <4 x i8> x, <4 x i8> y, <4 x i32> <i32 0, i32 3, i32 5, i32 6> %2 = mul <4 x i8> %1, %1 ret <4 x i8> %2 Mask will return the Shuffle Mask equivalent to the extracted elements.
Valuellvm::slpvectorizer::createInsertVector (IRBuilderBase &Builder, Value *Vec, Value *V, unsigned Index, function_ref< Value *(Value *, Value *, ArrayRef< int >)> Generator={})
 Creates subvector insert.
Valuellvm::slpvectorizer::createExtractVector (IRBuilderBase &Builder, Value *Vec, unsigned SubVecVF, unsigned Index)
 Generates subvector extract using Generator or using default shuffle.
SmallBitVector llvm::slpvectorizer::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.
template<bool IsPoisonOnly>
SmallBitVector llvm::slpvectorizer::isUndefVector (const Value *V, const SmallBitVector &UseMask={})
 Checks if the given value is actually an undefined constant vector.
template SmallBitVector llvm::slpvectorizer::isUndefVector< false > (const Value *, const SmallBitVector &)
template SmallBitVector llvm::slpvectorizer::isUndefVector< true > (const Value *, const SmallBitVector &)
bool llvm::slpvectorizer::doesInTreeUserNeedToExtract (Value *Scalar, Instruction *UserInst, TargetLibraryInfo *TLI, const TargetTransformInfo *TTI)
MemoryLocation llvm::slpvectorizer::getLocation (Instruction *I)
bool llvm::slpvectorizer::isSimple (Instruction *I)
bool llvm::slpvectorizer::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 via a constant-offset GEP) a select Cond, A, B picking between the same two base pointers A/B on every lane - the shape a fully unrolled x = cond ?
void llvm::slpvectorizer::addMask (SmallVectorImpl< int > &Mask, ArrayRef< int > SubMask, bool ExtendingManyInputs=false)
 Shuffles Mask in accordance with the given SubMask.
void llvm::slpvectorizer::fixupOrderingIndices (MutableArrayRef< unsigned > Order)
 Order may have elements assigned special value (size) which is out of bounds.
SmallBitVector llvm::slpvectorizer::getAltInstrMask (ArrayRef< Value * > VL, Type *ScalarTy, unsigned Opcode0, unsigned Opcode1)
SmallVector< Constant * > llvm::slpvectorizer::replicateMask (ArrayRef< Constant * > Val, unsigned VF)
 Replicates the given Val VF times.
Intrinsic::ID llvm::slpvectorizer::getMaskedDivRemIntrinsic (unsigned Opcode)
static bool llvm::slpvectorizer::isNonProfitableIndex (const Instruction *I)
 Returns true if I is a part of a single-use chain, computing an address, which does not pay off the vectorization: a constant table is accessed by a gather, while the indices, unrelated between the lanes, require a full buildvector, unlike the ones, shifted by a constant from a common base.
bool llvm::slpvectorizer::isOnceUsedSeed (const Instruction *I)
 Returns true if I forms a vectorizable bundle on its own and its single user does not tear the vector apart.
Instructionllvm::slpvectorizer::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, returns the fptrunc; the round-trip source is its operand, always an instruction of the same type as V.
static void llvm::slpvectorizer::collectNarrowedLeavesImpl (Value *V, unsigned RdxOpcode, unsigned WideBW, NarrowedChainState S, unsigned Depth, unsigned MaxDepth, SmallVectorImpl< NarrowedLeafInfo > &Leaves, SmallVectorImpl< Instruction * > &ChainInsts)
void llvm::slpvectorizer::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.
TargetTransformInfo::TargetCostKind llvm::slpvectorizer::getSLPCostKind (const Function *F)