LLVM 24.0.0git
llvm::vputils Namespace Reference

Namespaces

namespace  detail

Functions

bool onlyFirstLaneUsed (const VPValue *Def)
 Returns true if only the first lane of Def is used.
bool onlyFirstPartUsed (const VPValue *Def)
 Returns true if only the first part of Def is used.
bool onlyScalarValuesUsed (const VPValue *Def)
 Returns true if only scalar values of Def are used by all users.
VPValuegetOrCreateVPValueForSCEVExpr (VPlan &Plan, const SCEV *Expr)
 Get or create a VPValue that corresponds to the expansion of Expr.
const SCEVgetSCEVExprForVPValue (const VPValue *V, PredicatedScalarEvolution &PSE, const Loop *L=nullptr)
 Return the SCEV expression for V.
bool isAddressSCEVForCost (const SCEV *Addr, ScalarEvolution &SE, const Loop *L)
 Returns true if Addr is an address SCEV that can be passed to TTI::getAddressComputationCost, i.e.
bool isSingleScalar (const VPValue *VPV)
 Returns true if VPV is a single scalar, either because it produces the same value for all lanes or only has its first lane used.
bool isUniformAcrossVFsAndUFs (const VPValue *V)
 Checks if V is uniform across all VF lanes and UF parts.
bool isElementwise (const VPValue *V)
 Return true if V is elementwise, i.e. none of the lanes are permuted.
bool doesGeneratePerAllLanes (const VPRecipeBase *R)
 Returns true if R produces scalar values for all VF lanes.
VPBasicBlockgetFirstLoopHeader (VPlan &Plan, VPDominatorTree &VPDT)
 Returns the header block of the first, top-level loop, or null if none exist.
unsigned getVFScaleFactor (VPRecipeBase *R)
 Get the VF scaling factor applied to the recipe's output, if the recipe has one.
bool cannotHoistOrSinkRecipe (const VPRecipeBase &R, bool Sinking=false)
 Return true if we do not know how to (mechanically) hoist or sink R.
template<typename Ty>
Intrinsic::ID getIntrinsicID (const Ty *R)
 Return the intrinsic ID underlying a call.
unsigned getOpcode (const VPValue *V)
 Return the instruction opcode for the recipe defining V or 0 for unsupported recipes and VPValues not defined by a recipe.
std::optional< std::pair< bool, unsigned > > getOpcodeOrIntrinsicID (const VPValue *V)
 Get the instruction opcode or intrinsic ID for the recipe defining V.
std::optional< MemoryLocationgetMemoryLocation (const VPRecipeBase &R)
 Return a MemoryLocation for R with noalias metadata populated from R, if the recipe is supported and std::nullopt otherwise.
VPIRFlags getFlagsFromIndDesc (const InductionDescriptor &ID)
 Extracts and returns NoWrap and FastMath flags from the induction binop in ID.
template<typename PredT>
VPRecipeBasefindRecipe (VPValue *Start, PredT Pred)
 Search Start's users for a recipe satisfying Pred, looking through recipes with definitions.
VPInstructionfindCanonicalIVIncrement (VPlan &Plan)
 Find the canonical IV increment of Plan's vector loop region.
GEPNoWrapFlags getGEPFlagsForPtr (VPValue *Ptr)
 Returns the GEP nowrap flags for Ptr, looking through pointer casts mirroring Value::stripPointerCasts.
bool isUsedByLoadStoreAddress (const VPValue *V)
 Returns true if V is used as part of the address of another load or store.
VPInstructionfindComputeReductionResult (VPReductionPHIRecipe *PhiR)
 Find the ComputeReductionResult recipe for PhiR, looking through selects inserted for predicated reductions or tail folding.
VPValuefindIncomingAliasMask (const VPlan &Plan)
 Finds the incoming alias-mask within the vector preheader.
bool isDeadRecipe (VPRecipeBase &R)
 Returns true if R is dead, i.e.
void recursivelyDeleteDeadRecipes (VPValue *V)
 Recursively delete V and any of its operands that become dead.
SmallVector< VPUser * > collectUsersRecursively (VPValue *V)
 Collect all users of V, looking through recipes that define other values.
VPIRValuetryToFoldLiveIns (VPSingleDefRecipe &R, ArrayRef< VPValue * > Operands, const DataLayout &DL)
 Try to fold R using InstSimplifyFolder.
template<typename Match_t, typename Builder>
void pullOutPermutations (VPlan &Plan, Match_t Perm, Builder Build)
 Removes the permutation pattern Perm from any elementwise operations in the plan, by constructing a new permutation via Build.

Function Documentation

◆ cannotHoistOrSinkRecipe()

bool llvm::vputils::cannotHoistOrSinkRecipe ( const VPRecipeBase & R,
bool Sinking = false )

Return true if we do not know how to (mechanically) hoist or sink R.

When sinking, passing Sinking = true ensures that assumes aren't sunk. Returns true for recipes that access memory.

Definition at line 545 of file VPlanUtils.cpp.

References llvm::dyn_cast(), llvm::PatternMatch::m_Intrinsic(), and llvm::SCEVPatternMatch::match().

Referenced by cannotHoistOrSinkRecipe(), hoistPreviousBeforeFORUsers(), sinkRecurrenceUsersAfterPrevious(), and sinkScalarOperands().

◆ collectUsersRecursively()

SmallVector< VPUser * > llvm::vputils::collectUsersRecursively ( VPValue * V)

Collect all users of V, looking through recipes that define other values.

Definition at line 966 of file VPlanUtils.cpp.

References llvm::cast(), llvm::VPDef::definedValues(), llvm::from_range, I, and Users.

Referenced by llvm::VPlanTransforms::clearReductionWrapFlags(), legalizeAndOptimizeInductions(), and llvm::VPlanTransforms::optimizeEVLMasks().

◆ doesGeneratePerAllLanes()

bool llvm::vputils::doesGeneratePerAllLanes ( const VPRecipeBase * R)

Returns true if R produces scalar values for all VF lanes.

Definition at line 511 of file VPlanUtils.cpp.

References llvm::dyn_cast().

Referenced by llvm::VPlanTransforms::materializePacksAndUnpacks(), and llvm::VPlanTransforms::replicateByVF().

◆ findCanonicalIVIncrement()

◆ findComputeReductionResult()

VPInstruction * llvm::vputils::findComputeReductionResult ( VPReductionPHIRecipe * PhiR)

Find the ComputeReductionResult recipe for PhiR, looking through selects inserted for predicated reductions or tail folding.

Definition at line 698 of file VPlanUtils.cpp.

References llvm::cast(), llvm::VPlanPatternMatch::findUserOf(), llvm::VPHeaderPHIRecipe::getBackedgeValue(), llvm::PatternMatch::m_Select(), and llvm::VPlanPatternMatch::m_VPValue().

Referenced by llvm::VPlanTransforms::createPartialReductions(), and llvm::VPlanTransforms::handleMaxMinNumReductions().

◆ findIncomingAliasMask()

VPValue * llvm::vputils::findIncomingAliasMask ( const VPlan & Plan)

Finds the incoming alias-mask within the vector preheader.

Definition at line 579 of file VPlanUtils.cpp.

References llvm::cast(), llvm::VPlan::getVectorPreheader(), llvm::VPlanPatternMatch::m_VPInstruction(), and llvm::PatternMatch::match().

Referenced by llvm::VPlanTransforms::materializeAliasMask().

◆ findRecipe()

template<typename PredT>
VPRecipeBase * llvm::vputils::findRecipe ( VPValue * Start,
PredT Pred )
inline

◆ getFirstLoopHeader()

VPBasicBlock * llvm::vputils::getFirstLoopHeader ( VPlan & Plan,
VPDominatorTree & VPDT )

Returns the header block of the first, top-level loop, or null if none exist.

Definition at line 521 of file VPlanUtils.cpp.

References llvm::cast(), llvm::find_if(), llvm::VPlan::getEntry(), I, llvm::VPBlockUtils::isHeader(), and llvm::vp_depth_first_shallow().

Referenced by llvm::LoopVectorizationPlanner::executePlan(), and llvm::InnerLoopVectorizer::fixVectorizedLoop().

◆ getFlagsFromIndDesc()

VPIRFlags llvm::vputils::getFlagsFromIndDesc ( const InductionDescriptor & ID)
inline

Extracts and returns NoWrap and FastMath flags from the induction binop in ID.

Definition at line 129 of file VPlanUtils.h.

References assert(), llvm::dyn_cast_if_present(), llvm::InductionDescriptor::IK_FpInduction, and llvm::InductionDescriptor::IK_IntInduction.

Referenced by createWidenInductionRecipe().

◆ getGEPFlagsForPtr()

GEPNoWrapFlags llvm::vputils::getGEPFlagsForPtr ( VPValue * Ptr)

◆ getIntrinsicID()

◆ getMemoryLocation()

std::optional< MemoryLocation > llvm::vputils::getMemoryLocation ( const VPRecipeBase & R)

Return a MemoryLocation for R with noalias metadata populated from R, if the recipe is supported and std::nullopt otherwise.

The pointer of the location is conservatively set to nullptr.

Definition at line 625 of file VPlanUtils.cpp.

References llvm::dyn_cast().

Referenced by cannotHoistOrSinkRecipe(), canSinkStoreWithNoAliasCheck(), and llvm::VPlanTransforms::hoistPredicatedLoads().

◆ getOpcode()

unsigned llvm::vputils::getOpcode ( const VPValue * V)

Return the instruction opcode for the recipe defining V or 0 for unsupported recipes and VPValues not defined by a recipe.

Definition at line 366 of file VPlanUtils.cpp.

References llvm::TypeSwitch< T, ResultT >::Case(), llvm::Default, I, and llvm::VPInstruction::OpsEnd.

Referenced by canNarrowOps(), getOpcodeOrIntrinsicID(), getVFScaleFactor(), isElementwise(), and narrowToSingleScalarRecipes().

◆ getOpcodeOrIntrinsicID()

std::optional< std::pair< bool, unsigned > > llvm::vputils::getOpcodeOrIntrinsicID ( const VPValue * V)

Get the instruction opcode or intrinsic ID for the recipe defining V.

Returns an optional pair, where the first element indicates whether it is an intrinsic ID.

Definition at line 382 of file VPlanUtils.cpp.

References getIntrinsicID(), and getOpcode().

Referenced by tryToFoldLiveIns().

◆ getOrCreateVPValueForSCEVExpr()

VPValue * llvm::vputils::getOrCreateVPValueForSCEVExpr ( VPlan & Plan,
const SCEV * Expr )

Get or create a VPValue that corresponds to the expansion of Expr.

If Expr is a SCEVConstant or SCEVUnknown, return a VPValue wrapping the live-in value. Otherwise return a VPExpandSCEVRecipe to expand Expr. If Plan's pre-header already contains a recipe expanding Expr, return it. If not, create a new one.

Definition at line 43 of file VPlanUtils.cpp.

References llvm::dyn_cast(), llvm::VPBasicBlock::end(), llvm::VPlan::getEntry(), llvm::VPBasicBlock::getFirstNonPhi(), llvm::VPlan::getOrAddLiveIn(), llvm::VPBasicBlock::insert(), and llvm::isa().

Referenced by addInitialSkeleton(), createWidenInductionRecipe(), llvm::VPlanTransforms::materializeAliasMask(), and llvm::VPlanTransforms::replaceSymbolicStrides().

◆ getSCEVExprForVPValue()

const SCEV * llvm::vputils::getSCEVExprForVPValue ( const VPValue * V,
PredicatedScalarEvolution & PSE,
const Loop * L = nullptr )

Return the SCEV expression for V.

Returns SCEVCouldNotCompute if no SCEV expression could be constructed.

Definition at line 135 of file VPlanUtils.cpp.

References AbstractManglingParser< Derived, Alloc >::Ops, llvm::any_of(), llvm::ArrayRef(), assert(), llvm::TypeSwitch< T, ResultT >::Case(), llvm::Default, llvm::dyn_cast(), llvm::SCEV::FlagAnyWrap, llvm::SCEV::FlagNSW, llvm::ScalarEvolution::getAbsExpr(), llvm::ScalarEvolution::getAddExpr(), llvm::ScalarEvolution::getAddRecExpr(), llvm::ScalarEvolution::getConstant(), llvm::ScalarEvolution::getCouldNotCompute(), llvm::ScalarEvolution::getGEPExpr(), llvm::ScalarEvolution::getMinusOne(), llvm::ScalarEvolution::getMinusSCEV(), llvm::ScalarEvolution::getMulExpr(), llvm::ScalarEvolution::getOne(), llvm::ScalarEvolution::getPowerOfTwo(), llvm::PredicatedScalarEvolution::getPredicatedSCEV(), getScalarSizeInBits(), llvm::Type::getScalarType(), llvm::ScalarEvolution::getSCEV(), getSCEVExprForVPValue(), llvm::PredicatedScalarEvolution::getSE(), llvm::ScalarEvolution::getSignExtendExpr(), llvm::ScalarEvolution::getSMaxExpr(), llvm::ScalarEvolution::getSMinExpr(), llvm::ScalarEvolution::getTruncateExpr(), llvm::ScalarEvolution::getTruncateOrSignExtend(), llvm::SCEV::getType(), llvm::Value::getType(), llvm::ScalarEvolution::getTypeSizeInBits(), llvm::ScalarEvolution::getUDivExpr(), llvm::ScalarEvolution::getUMaxExpr(), llvm::ScalarEvolution::getUMinExpr(), llvm::ScalarEvolution::getURemExpr(), llvm::ScalarEvolution::getZero(), llvm::ScalarEvolution::getZeroExtendExpr(), llvm::isa(), llvm::IsaPred, llvm::ScalarEvolution::isKnownNonNegative(), llvm::ScalarEvolution::isSCEVable(), IV, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_APInt(), llvm::VPlanPatternMatch::m_c_BinaryAnd(), llvm::PatternMatch::m_ConstantInt(), llvm::VPlanPatternMatch::m_GetElementPtr(), llvm::PatternMatch::m_Intrinsic(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Mul(), llvm::MIPatternMatch::m_Not(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_SRem(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_UDiv(), llvm::PatternMatch::m_URem(), llvm::VPlanPatternMatch::m_VPValue(), llvm::PatternMatch::m_ZExt(), llvm::SCEVPatternMatch::match(), poisonGuaranteesUB(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::V1.

Referenced by llvm::VPlanTransforms::addMinimumIterationCheck(), areAllLoadsDereferenceable(), collectGroupedReplicateMemOps(), llvm::VPlanTransforms::convertToStridedAccesses(), createWidenInductionRecipe(), getAddressAccessSCEV(), getConstantStride(), getOptimizableIVOf(), getSCEVExprForVPValue(), handleUncountableExitsWithSideEffects(), isConditionTrueViaVFAndUF(), llvm::VPlanTransforms::makeMemOpWideningDecisions(), llvm::VPlanTransforms::optimizeFindIVReductions(), llvm::LoopVectorizationPlanner::selectBestEpiloguePlan(), simplifyBranchConditionForVFAndUF(), llvm::VPlanTransforms::simplifyKnownEVL(), and simplifyLiveInsWithSCEV().

◆ getVFScaleFactor()

unsigned llvm::vputils::getVFScaleFactor ( VPRecipeBase * R)

Get the VF scaling factor applied to the recipe's output, if the recipe has one.

Definition at line 529 of file VPlanUtils.cpp.

References assert(), llvm::cast(), llvm::dyn_cast(), getOpcode(), llvm::isa(), and llvm::VPInstruction::ReductionStartVector.

Referenced by llvm::calculateRegisterUsageForPlan().

◆ isAddressSCEVForCost()

bool llvm::vputils::isAddressSCEVForCost ( const SCEV * Addr,
ScalarEvolution & SE,
const Loop * L )

Returns true if Addr is an address SCEV that can be passed to TTI::getAddressComputationCost, i.e.

the address SCEV is loop invariant, an affine AddRec (i.e. induction ), or an add expression of such operands or a sign-extended AddRec.

Definition at line 349 of file VPlanUtils.cpp.

References llvm::all_of(), llvm::dyn_cast(), llvm::ScalarEvolution::isLoopInvariant(), llvm::SCEVPatternMatch::m_SCEV(), llvm::SCEVPatternMatch::m_scev_AffineAddRec(), and llvm::SCEVPatternMatch::match().

Referenced by getAddressAccessSCEV(), and getAddressAccessSCEV().

◆ isDeadRecipe()

bool llvm::vputils::isDeadRecipe ( VPRecipeBase & R)

Returns true if R is dead, i.e.

none of its defined values are used and it has no side effects (with the exception of conditional assumes, which are considered dead as their conditions may be flattened).

Definition at line 931 of file VPlanUtils.cpp.

References llvm::all_of(), llvm::dyn_cast(), llvm::PatternMatch::m_Intrinsic(), and llvm::PatternMatch::match().

Referenced by narrowToSingleScalarRecipes(), recursivelyDeleteDeadRecipes(), and llvm::VPlanTransforms::removeDeadRecipes().

◆ isElementwise()

bool llvm::vputils::isElementwise ( const VPValue * V)

Return true if V is elementwise, i.e. none of the lanes are permuted.

Definition at line 411 of file VPlanUtils.cpp.

References getOpcode(), llvm::isa(), llvm::Instruction::isBinaryOp(), and llvm::Instruction::isUnaryOp().

Referenced by llvm::vputils::detail::pullOutPermutationsImpl().

◆ isSingleScalar()

◆ isUniformAcrossVFsAndUFs()

bool llvm::vputils::isUniformAcrossVFsAndUFs ( const VPValue * V)

Checks if V is uniform across all VF lanes and UF parts.

It is considered as such if it is either loop invariant (defined outside the vector region) or its operands are known to be uniform across all VFs and UFs (e.g. VPDerivedIV or the canonical IV).

Definition at line 458 of file VPlanUtils.cpp.

References llvm::all_of(), llvm::TypeSwitch< T, ResultT >::Case(), llvm::Default, llvm::dyn_cast(), llvm::VPlan::getEntry(), llvm::VPInstruction::getOpcode(), llvm::VPBlockBase::getPlan(), llvm::VPlan::getVectorPreheader(), llvm::isa(), llvm::VPInstruction::isSingleScalar(), isUniformAcrossVFsAndUFs(), llvm::VPInstruction::isVectorToScalar(), llvm::VPlanPatternMatch::m_VPInstruction(), llvm::SCEVPatternMatch::match(), llvm::VPUser::operands(), and preservesUniformity().

Referenced by isKnownMonotonic(), isUniformAcrossVFsAndUFs(), narrowToSingleScalarRecipes(), and simplifyRecipe().

◆ isUsedByLoadStoreAddress()

◆ onlyFirstLaneUsed()

◆ onlyFirstPartUsed()

bool llvm::vputils::onlyFirstPartUsed ( const VPValue * Def)

Returns true if only the first part of Def is used.

Definition at line 33 of file VPlanUtils.cpp.

References llvm::all_of().

Referenced by llvm::VPInstruction::usesFirstPartOnly().

◆ onlyScalarValuesUsed()

◆ pullOutPermutations()

template<typename Match_t, typename Builder>
void llvm::vputils::pullOutPermutations ( VPlan & Plan,
Match_t Perm,
Builder Build )

Removes the permutation pattern Perm from any elementwise operations in the plan, by constructing a new permutation via Build.

e.g. binop(perm(x), perm(y)) -> perm(binop(x,y)).

Definition at line 212 of file VPlanUtils.h.

References llvm::PatternMatch::match(), llvm::vputils::detail::pullOutPermutationsImpl(), and X.

Referenced by llvm::VPlanTransforms::optimizeEVLMasks(), and llvm::VPlanTransforms::simplifyReverses().

◆ recursivelyDeleteDeadRecipes()

◆ tryToFoldLiveIns()