LLVM  16.0.0git
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
llvm::LoopVectorizationCostModel Class Reference

LoopVectorizationCostModel - estimates the expected speedups due to vectorization. More...

Collaboration diagram for llvm::LoopVectorizationCostModel:
Collaboration graph
[legend]

Classes

struct  RegisterUsage
 A struct that represents some properties of the register usage of a loop. More...
 

Public Types

enum  InstWidening {
  CM_Unknown, CM_Widen, CM_Widen_Reverse, CM_Interleave,
  CM_GatherScatter, CM_Scalarize
}
 Decision that was taken during cost calculation for memory instruction. More...
 
using ReductionChainMap = SmallMapVector< PHINode *, SmallVector< Instruction *, 4 >, 4 >
 A SmallMapVector to store the InLoop reduction op chains, mapping phi nodes to the chain of instructions representing the reductions. More...
 

Public Member Functions

 LoopVectorizationCostModel (ScalarEpilogueLowering SEL, Loop *L, PredicatedScalarEvolution &PSE, LoopInfo *LI, LoopVectorizationLegality *Legal, const TargetTransformInfo &TTI, const TargetLibraryInfo *TLI, DemandedBits *DB, AssumptionCache *AC, OptimizationRemarkEmitter *ORE, const Function *F, const LoopVectorizeHints *Hints, InterleavedAccessInfo &IAI)
 
FixedScalableVFPair computeMaxVF (ElementCount UserVF, unsigned UserIC)
 
bool runtimeChecksRequired ()
 
VectorizationFactor selectVectorizationFactor (const ElementCountSet &CandidateVFs)
 
VectorizationFactor selectEpilogueVectorizationFactor (const ElementCount MaxVF, const LoopVectorizationPlanner &LVP)
 
bool selectUserVectorizationFactor (ElementCount UserVF)
 Setup cost-based decisions for user vectorization factor. More...
 
std::pair< unsigned, unsigned > getSmallestAndWidestTypes ()
 
unsigned selectInterleaveCount (ElementCount VF, InstructionCost LoopCost)
 
void setCostBasedWideningDecision (ElementCount VF)
 Memory access instruction may be vectorized in more than one way. More...
 
SmallVector< RegisterUsage, 8 > calculateRegisterUsage (ArrayRef< ElementCount > VFs)
 
void collectValuesToIgnore ()
 Collect values we want to ignore in the cost model. More...
 
void collectElementTypesForWidening ()
 Collect all element types in the loop for which widening is needed. More...
 
void collectInLoopReductions ()
 Split reductions into those that happen in the loop, and those that happen outside. More...
 
bool useOrderedReductions (const RecurrenceDescriptor &RdxDesc) const
 Returns true if we should use strict in-order reductions for the given RdxDesc. More...
 
const MapVector< Instruction *, uint64_t > & getMinimalBitwidths () const
 
bool isProfitableToScalarize (Instruction *I, ElementCount VF) const
 
bool isUniformAfterVectorization (Instruction *I, ElementCount VF) const
 Returns true if I is known to be uniform after vectorization. More...
 
bool isScalarAfterVectorization (Instruction *I, ElementCount VF) const
 Returns true if I is known to be scalar after vectorization. More...
 
bool canTruncateToMinimalBitwidth (Instruction *I, ElementCount VF) const
 
void setWideningDecision (Instruction *I, ElementCount VF, InstWidening W, InstructionCost Cost)
 Save vectorization decision W and Cost taken by the cost model for instruction I and vector width VF. More...
 
void setWideningDecision (const InterleaveGroup< Instruction > *Grp, ElementCount VF, InstWidening W, InstructionCost Cost)
 Save vectorization decision W and Cost taken by the cost model for interleaving group Grp and vector width VF. More...
 
InstWidening getWideningDecision (Instruction *I, ElementCount VF) const
 Return the cost model decision for the given instruction I and vector width VF. More...
 
InstructionCost getWideningCost (Instruction *I, ElementCount VF)
 Return the vectorization cost for the given instruction I and vector width VF. More...
 
bool isOptimizableIVTruncate (Instruction *I, ElementCount VF)
 Return True if instruction I is an optimizable truncate whose operand is an induction variable. More...
 
void collectInstsToScalarize (ElementCount VF)
 Collects the instructions to scalarize for each predicated instruction in the loop. More...
 
void collectUniformsAndScalars (ElementCount VF)
 Collect Uniform and Scalar values for the given VF. More...
 
bool isLegalMaskedStore (Type *DataType, Value *Ptr, Align Alignment) const
 Returns true if the target machine supports masked store operation for the given DataType and kind of access to Ptr. More...
 
bool isLegalMaskedLoad (Type *DataType, Value *Ptr, Align Alignment) const
 Returns true if the target machine supports masked load operation for the given DataType and kind of access to Ptr. More...
 
bool isLegalGatherOrScatter (Value *V, ElementCount VF=ElementCount::getFixed(1))
 Returns true if the target machine can represent V as a masked gather or scatter operation. More...
 
bool canVectorizeReductions (ElementCount VF) const
 Returns true if the target machine supports all of the reduction variables found for the given VF. More...
 
bool isDivRemScalarWithPredication (InstructionCost ScalarCost, InstructionCost SafeDivisorCost) const
 Given costs for both strategies, return true if the scalar predication lowering should be used for div/rem. More...
 
bool isScalarWithPredication (Instruction *I, ElementCount VF) const
 Returns true if I is an instruction which requires predication and for which our chosen predication strategy is scalarization (i.e. More...
 
bool isPredicatedInst (Instruction *I) const
 Returns true if I is an instruction that needs to be predicated at runtime. More...
 
std::pair< InstructionCost, InstructionCostgetDivRemSpeculationCost (Instruction *I, ElementCount VF) const
 Return the costs for our two available strategies for lowering a div/rem operation which requires speculating at least one lane. More...
 
bool memoryInstructionCanBeWidened (Instruction *I, ElementCount VF=ElementCount::getFixed(1))
 Returns true if I is a memory instruction with consecutive memory access that can be widened. More...
 
bool interleavedAccessCanBeWidened (Instruction *I, ElementCount VF=ElementCount::getFixed(1))
 Returns true if I is a memory instruction in an interleaved-group of memory accesses that can be vectorized with wide vector loads/stores and shuffles. More...
 
bool isAccessInterleaved (Instruction *Instr)
 Check if Instr belongs to any interleaved access group. More...
 
const InterleaveGroup< Instruction > * getInterleavedAccessGroup (Instruction *Instr)
 Get the interleaved access group that Instr belongs to. More...
 
bool requiresScalarEpilogue (ElementCount VF) const
 Returns true if we're required to use a scalar epilogue for at least the final iteration of the original loop. More...
 
bool isScalarEpilogueAllowed () const
 Returns true if a scalar epilogue is not allowed due to optsize or a loop hint annotation. More...
 
bool foldTailByMasking () const
 Returns true if all loop blocks should be masked to fold tail loop. More...
 
bool useActiveLaneMaskForControlFlow () const
 Returns true if were tail-folding and want to use the active lane mask for vector loop control flow. More...
 
bool blockNeedsPredicationForAnyReason (BasicBlock *BB) const
 Returns true if the instructions in this block requires predication for any reason, e.g. More...
 
const ReductionChainMapgetInLoopReductionChains () const
 Return the chain of instructions representing an inloop reduction. More...
 
bool isInLoopReduction (PHINode *Phi) const
 Returns true if the Phi is part of an inloop reduction. More...
 
InstructionCost getVectorIntrinsicCost (CallInst *CI, ElementCount VF) const
 Estimate cost of an intrinsic call instruction CI if it were vectorized with factor VF. More...
 
InstructionCost getVectorCallCost (CallInst *CI, ElementCount VF, bool &NeedToScalarize) const
 Estimate cost of a call instruction CI if it were vectorized with factor VF. More...
 
bool isMoreProfitable (const VectorizationFactor &A, const VectorizationFactor &B) const
 Returns true if the per-lane cost of VectorizationFactor A is lower than that of B. More...
 
void invalidateCostModelingDecisions ()
 Invalidates decisions already taken by the cost model. More...
 
Optional< unsigned > getVScaleForTuning () const
 Convenience function that returns the value of vscale_range iff vscale_range.min == vscale_range.max or otherwise returns the value returned by the corresponding TLI method. More...
 

Public Attributes

LoopTheLoop
 The loop that we evaluate. More...
 
PredicatedScalarEvolutionPSE
 Predicated scalar evolution analysis. More...
 
LoopInfoLI
 Loop Info analysis. More...
 
LoopVectorizationLegalityLegal
 Vectorization legality. More...
 
const TargetTransformInfoTTI
 Vector target information. More...
 
const TargetLibraryInfoTLI
 Target Library Info. More...
 
DemandedBitsDB
 Demanded bits analysis. More...
 
AssumptionCacheAC
 Assumption cache. More...
 
OptimizationRemarkEmitterORE
 Interface to emit optimization remarks. More...
 
const FunctionTheFunction
 
const LoopVectorizeHintsHints
 Loop Vectorize Hint. More...
 
InterleavedAccessInfoInterleaveInfo
 The interleave access information contains groups of interleaved accesses with the same stride and close to each other. More...
 
SmallPtrSet< const Value *, 16 > ValuesToIgnore
 Values to ignore in the cost model. More...
 
SmallPtrSet< const Value *, 16 > VecValuesToIgnore
 Values to ignore in the cost model when VF > 1. More...
 
SmallPtrSet< Type *, 16 > ElementTypesInLoop
 All element types found in the loop. More...
 
SmallVector< VectorizationFactor, 8 > ProfitableVFs
 Profitable vector factors. More...
 

Detailed Description

LoopVectorizationCostModel - estimates the expected speedups due to vectorization.

In many cases vectorization is not profitable. This can happen because of a number of reasons. In this class we mainly attempt to predict the expected speedup/slowdowns due to the supported instruction set. We use the TargetTransformInfo to query the different backends for the cost of different operations.

Definition at line 1134 of file LoopVectorize.cpp.

Member Typedef Documentation

◆ ReductionChainMap

A SmallMapVector to store the InLoop reduction op chains, mapping phi nodes to the chain of instructions representing the reductions.

Uses a MapVector to ensure deterministic iteration order.

Definition at line 1537 of file LoopVectorize.cpp.

Member Enumeration Documentation

◆ InstWidening

Decision that was taken during cost calculation for memory instruction.

Enumerator
CM_Unknown 
CM_Widen 
CM_Widen_Reverse 
CM_Interleave 
CM_GatherScatter 
CM_Scalarize 

Definition at line 1296 of file LoopVectorize.cpp.

Constructor & Destructor Documentation

◆ LoopVectorizationCostModel()

llvm::LoopVectorizationCostModel::LoopVectorizationCostModel ( ScalarEpilogueLowering  SEL,
Loop L,
PredicatedScalarEvolution PSE,
LoopInfo LI,
LoopVectorizationLegality Legal,
const TargetTransformInfo TTI,
const TargetLibraryInfo TLI,
DemandedBits DB,
AssumptionCache AC,
OptimizationRemarkEmitter ORE,
const Function F,
const LoopVectorizeHints Hints,
InterleavedAccessInfo IAI 
)
inline

Definition at line 1136 of file LoopVectorize.cpp.

Member Function Documentation

◆ blockNeedsPredicationForAnyReason()

bool llvm::LoopVectorizationCostModel::blockNeedsPredicationForAnyReason ( BasicBlock BB) const
inline

Returns true if the instructions in this block requires predication for any reason, e.g.

because tail folding now requires a predicate or because the block in the original loop was predicated.

Definition at line 1529 of file LoopVectorize.cpp.

References BB, llvm::LoopVectorizationLegality::blockNeedsPredication(), and llvm::InnerLoopVectorizer::Legal.

◆ calculateRegisterUsage()

SmallVector< LoopVectorizationCostModel::RegisterUsage, 8 > LoopVectorizationCostModel::calculateRegisterUsage ( ArrayRef< ElementCount VFs)

◆ canTruncateToMinimalBitwidth()

bool llvm::LoopVectorizationCostModel::canTruncateToMinimalBitwidth ( Instruction I,
ElementCount  VF 
) const
inline
Returns
True if instruction I can be truncated to a smaller bitwidth for vectorization factor VF.

Definition at line 1289 of file LoopVectorize.cpp.

References I, llvm::ElementCount::isVector(), and llvm::InnerLoopVectorizer::VF.

◆ canVectorizeReductions()

bool llvm::LoopVectorizationCostModel::canVectorizeReductions ( ElementCount  VF) const
inline

Returns true if the target machine supports all of the reduction variables found for the given VF.

Definition at line 1432 of file LoopVectorize.cpp.

References llvm::all_of(), llvm::LoopVectorizationLegality::getReductionVars(), llvm::InnerLoopVectorizer::Legal, and Reduction.

◆ collectElementTypesForWidening()

void LoopVectorizationCostModel::collectElementTypesForWidening ( )

◆ collectInLoopReductions()

void LoopVectorizationCostModel::collectInLoopReductions ( )

◆ collectInstsToScalarize()

void LoopVectorizationCostModel::collectInstsToScalarize ( ElementCount  VF)

◆ collectUniformsAndScalars()

void llvm::LoopVectorizationCostModel::collectUniformsAndScalars ( ElementCount  VF)
inline

Collect Uniform and Scalar values for the given VF.

The sets depend on CM decision for Load/Store instructions that may be vectorized as interleave, gather-scatter or scalarized.

Definition at line 1391 of file LoopVectorize.cpp.

References llvm::ElementCount::isScalar(), and llvm::InnerLoopVectorizer::VF.

◆ collectValuesToIgnore()

void LoopVectorizationCostModel::collectValuesToIgnore ( )

◆ computeMaxVF()

FixedScalableVFPair LoopVectorizationCostModel::computeMaxVF ( ElementCount  UserVF,
unsigned  UserIC 
)
Returns
An upper bound for the vectorization factors (both fixed and scalable). If the factors are 0, vectorization and interleaving should be avoided up front.

Definition at line 5022 of file LoopVectorize.cpp.

References llvm::ScalarEvolution::applyLoopGuards(), assert(), llvm::CM_ScalarEpilogueAllowed, llvm::CM_ScalarEpilogueNotAllowedLowTripLoop, llvm::CM_ScalarEpilogueNotAllowedOptSize, llvm::CM_ScalarEpilogueNotAllowedUsePredicate, llvm::CM_ScalarEpilogueNotNeededUsePredicate, llvm::dbgs(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::empty(), llvm::FixedScalableVFPair::FixedVF, llvm::ScalarEvolution::getAddExpr(), llvm::PredicatedScalarEvolution::getBackedgeTakenCount(), llvm::ScalarEvolution::getConstant(), llvm::LinearPolySize< LeafTy >::getFixedValue(), llvm::FixedScalableVFPair::getNone(), llvm::ScalarEvolution::getOne(), llvm::LoopVectorizationLegality::getRuntimePointerChecking(), llvm::PredicatedScalarEvolution::getSE(), llvm::ScalarEvolution::getSmallConstantTripCount(), llvm::SCEV::getType(), llvm::ScalarEvolution::getURemExpr(), llvm::TargetTransformInfo::hasBranchDivergence(), llvm::UnivariateLinearPolyBase< LeafTy >::isNonZero(), llvm::isPowerOf2_32(), llvm::ElementCount::isVector(), llvm::SCEV::isZero(), llvm::InnerLoopVectorizer::Legal, LLVM_DEBUG, llvm::RuntimePointerChecking::Need, llvm::InnerLoopVectorizer::ORE, llvm::LoopVectorizationLegality::prepareToFoldTailByMasking(), llvm::InnerLoopVectorizer::PSE, llvm::reportVectorizationFailure(), llvm::FixedScalableVFPair::ScalableVF, and useMaskedInterleavedAccesses().

◆ foldTailByMasking()

bool llvm::LoopVectorizationCostModel::foldTailByMasking ( ) const
inline

◆ getDivRemSpeculationCost()

std::pair< InstructionCost, InstructionCost > LoopVectorizationCostModel::getDivRemSpeculationCost ( Instruction I,
ElementCount  VF 
) const

◆ getInLoopReductionChains()

const ReductionChainMap& llvm::LoopVectorizationCostModel::getInLoopReductionChains ( ) const
inline

Return the chain of instructions representing an inloop reduction.

Definition at line 1540 of file LoopVectorize.cpp.

◆ getInterleavedAccessGroup()

const InterleaveGroup<Instruction>* llvm::LoopVectorizationCostModel::getInterleavedAccessGroup ( Instruction Instr)
inline

Get the interleaved access group that Instr belongs to.

Definition at line 1494 of file LoopVectorize.cpp.

◆ getMinimalBitwidths()

const MapVector<Instruction *, uint64_t>& llvm::LoopVectorizationCostModel::getMinimalBitwidths ( ) const
inline
Returns
The smallest bitwidth each instruction can be represented with. The vector equivalents of these instructions should be truncated to this type.

Definition at line 1234 of file LoopVectorize.cpp.

Referenced by llvm::InnerLoopVectorizer::truncateToMinimalBitwidths().

◆ getSmallestAndWidestTypes()

std::pair< unsigned, unsigned > LoopVectorizationCostModel::getSmallestAndWidestTypes ( )

◆ getVectorCallCost()

InstructionCost LoopVectorizationCostModel::getVectorCallCost ( CallInst CI,
ElementCount  VF,
bool &  NeedToScalarize 
) const

Estimate cost of a call instruction CI if it were vectorized with factor VF.

Return the cost of the instruction, including scalarization overhead if it's needed. The flag NeedToScalarize shows if the call needs to be scalarized - i.e. either vector version isn't available, or is too expensive.

Definition at line 3427 of file LoopVectorize.cpp.

References llvm::CallBase::args(), llvm::InnerLoopVectorizer::Cost, F, llvm::VFShape::get(), llvm::CallBase::getCalledFunction(), llvm::TargetTransformInfo::getCallInstrCost(), llvm::LinearPolySize< LeafTy >::getKnownMinValue(), llvm::Value::getType(), llvm::VFDatabase::getVectorizedFunction(), llvm::CallBase::isNoBuiltin(), llvm::ElementCount::isScalar(), llvm::TargetTransformInfo::TCK_RecipThroughput, llvm::InnerLoopVectorizer::TLI, llvm::ToVectorTy(), and llvm::InnerLoopVectorizer::VF.

◆ getVectorIntrinsicCost()

InstructionCost LoopVectorizationCostModel::getVectorIntrinsicCost ( CallInst CI,
ElementCount  VF 
) const

◆ getVScaleForTuning()

Optional< unsigned > LoopVectorizationCostModel::getVScaleForTuning ( ) const

Convenience function that returns the value of vscale_range iff vscale_range.min == vscale_range.max or otherwise returns the value returned by the corresponding TLI method.

Definition at line 5263 of file LoopVectorize.cpp.

References llvm::TargetTransformInfo::getVScaleForTuning().

Referenced by llvm::LoopVectorizePass::processLoop().

◆ getWideningCost()

InstructionCost llvm::LoopVectorizationCostModel::getWideningCost ( Instruction I,
ElementCount  VF 
)
inline

Return the vectorization cost for the given instruction I and vector width VF.

Definition at line 1350 of file LoopVectorize.cpp.

References assert(), I, llvm::ElementCount::isVector(), and llvm::InnerLoopVectorizer::VF.

◆ getWideningDecision()

InstWidening llvm::LoopVectorizationCostModel::getWideningDecision ( Instruction I,
ElementCount  VF 
) const
inline

Return the cost model decision for the given instruction I and vector width VF.

Return CM_Unknown if this instruction did not pass through the cost modeling.

Definition at line 1334 of file LoopVectorize.cpp.

References assert(), EnableVPlanNativePath, I, llvm::ElementCount::isVector(), and llvm::InnerLoopVectorizer::VF.

◆ interleavedAccessCanBeWidened()

bool LoopVectorizationCostModel::interleavedAccessCanBeWidened ( Instruction I,
ElementCount  VF = ElementCount::getFixed(1) 
)

◆ invalidateCostModelingDecisions()

void llvm::LoopVectorizationCostModel::invalidateCostModelingDecisions ( )
inline

Invalidates decisions already taken by the cost model.

Definition at line 1568 of file LoopVectorize.cpp.

◆ isAccessInterleaved()

bool llvm::LoopVectorizationCostModel::isAccessInterleaved ( Instruction Instr)
inline

Check if Instr belongs to any interleaved access group.

Definition at line 1488 of file LoopVectorize.cpp.

◆ isDivRemScalarWithPredication()

bool llvm::LoopVectorizationCostModel::isDivRemScalarWithPredication ( InstructionCost  ScalarCost,
InstructionCost  SafeDivisorCost 
) const
inline

Given costs for both strategies, return true if the scalar predication lowering should be used for div/rem.

This incorporates an override option so it is not simply a cost comparison.

Definition at line 1442 of file LoopVectorize.cpp.

References llvm::cl::BOU_FALSE, llvm::cl::BOU_TRUE, llvm::cl::BOU_UNSET, ForceSafeDivisor, and llvm_unreachable.

◆ isInLoopReduction()

bool llvm::LoopVectorizationCostModel::isInLoopReduction ( PHINode Phi) const
inline

Returns true if the Phi is part of an inloop reduction.

Definition at line 1545 of file LoopVectorize.cpp.

◆ isLegalGatherOrScatter()

bool llvm::LoopVectorizationCostModel::isLegalGatherOrScatter ( Value V,
ElementCount  VF = ElementCount::getFixed(1) 
)
inline

◆ isLegalMaskedLoad()

bool llvm::LoopVectorizationCostModel::isLegalMaskedLoad ( Type DataType,
Value Ptr,
Align  Alignment 
) const
inline

Returns true if the target machine supports masked load operation for the given DataType and kind of access to Ptr.

Definition at line 1409 of file LoopVectorize.cpp.

References llvm::LoopVectorizationLegality::isConsecutivePtr(), llvm::TargetTransformInfo::isLegalMaskedLoad(), llvm::InnerLoopVectorizer::Legal, and Ptr.

◆ isLegalMaskedStore()

bool llvm::LoopVectorizationCostModel::isLegalMaskedStore ( Type DataType,
Value Ptr,
Align  Alignment 
) const
inline

Returns true if the target machine supports masked store operation for the given DataType and kind of access to Ptr.

Definition at line 1402 of file LoopVectorize.cpp.

References llvm::LoopVectorizationLegality::isConsecutivePtr(), llvm::TargetTransformInfo::isLegalMaskedStore(), llvm::InnerLoopVectorizer::Legal, and Ptr.

◆ isMoreProfitable()

bool LoopVectorizationCostModel::isMoreProfitable ( const VectorizationFactor A,
const VectorizationFactor B 
) const

◆ isOptimizableIVTruncate()

bool llvm::LoopVectorizationCostModel::isOptimizableIVTruncate ( Instruction I,
ElementCount  VF 
)
inline

Return True if instruction I is an optimizable truncate whose operand is an induction variable.

Such a truncate will be removed by adding a new induction variable with the destination type.

Definition at line 1361 of file LoopVectorize.cpp.

References llvm::LoopVectorizationLegality::getPrimaryInduction(), I, llvm::LoopVectorizationLegality::isInductionPhi(), llvm::TargetTransformInfo::isTruncateFree(), llvm::InnerLoopVectorizer::Legal, llvm::ToVectorTy(), and llvm::InnerLoopVectorizer::VF.

◆ isPredicatedInst()

bool LoopVectorizationCostModel::isPredicatedInst ( Instruction I) const

Returns true if I is an instruction that needs to be predicated at runtime.

The result is independent of the predication mechanism. Superset of instructions that return true for isScalarWithPredication.

Definition at line 4403 of file LoopVectorize.cpp.

References llvm::LoopVectorizationLegality::blockNeedsPredication(), I, llvm::LoopVectorizationLegality::isMaskRequired(), llvm::isSafeToSpeculativelyExecute(), llvm::LoopVectorizationLegality::isUniformMemOp(), llvm::InnerLoopVectorizer::Legal, llvm::SPII::Load, and llvm::SPII::Store.

◆ isProfitableToScalarize()

bool llvm::LoopVectorizationCostModel::isProfitableToScalarize ( Instruction I,
ElementCount  VF 
) const
inline
Returns
True if it is more profitable to scalarize instruction I for vectorization factor VF.

Definition at line 1240 of file LoopVectorize.cpp.

References assert(), EnableVPlanNativePath, I, llvm::ElementCount::isVector(), and llvm::InnerLoopVectorizer::VF.

Referenced by createWidenInductionRecipes().

◆ isScalarAfterVectorization()

bool llvm::LoopVectorizationCostModel::isScalarAfterVectorization ( Instruction I,
ElementCount  VF 
) const
inline

Returns true if I is known to be scalar after vectorization.

Definition at line 1272 of file LoopVectorize.cpp.

References assert(), EnableVPlanNativePath, I, llvm::ElementCount::isScalar(), and llvm::InnerLoopVectorizer::VF.

Referenced by createWidenInductionRecipes().

◆ isScalarEpilogueAllowed()

bool llvm::LoopVectorizationCostModel::isScalarEpilogueAllowed ( ) const
inline

Returns true if a scalar epilogue is not allowed due to optsize or a loop hint annotation.

Definition at line 1512 of file LoopVectorize.cpp.

References llvm::CM_ScalarEpilogueAllowed.

Referenced by llvm::InnerLoopVectorizer::vectorizeInterleaveGroup().

◆ isScalarWithPredication()

bool LoopVectorizationCostModel::isScalarWithPredication ( Instruction I,
ElementCount  VF 
) const

Returns true if I is an instruction which requires predication and for which our chosen predication strategy is scalarization (i.e.

we don't have an alternate strategy such as masking available). VF is the vectorization factor that will be used to vectorize I.

Definition at line 4367 of file LoopVectorize.cpp.

References llvm::VectorType::get(), llvm::getLoadStoreAlignment(), llvm::getLoadStorePointerOperand(), llvm::getLoadStoreType(), I, llvm::TargetTransformInfo::isLegalMaskedGather(), llvm::TargetTransformInfo::isLegalMaskedScatter(), llvm::ElementCount::isVector(), llvm::SPII::Load, Ptr, llvm::SPII::Store, and llvm::InnerLoopVectorizer::VF.

◆ isUniformAfterVectorization()

bool llvm::LoopVectorizationCostModel::isUniformAfterVectorization ( Instruction I,
ElementCount  VF 
) const
inline

Returns true if I is known to be uniform after vectorization.

Definition at line 1256 of file LoopVectorize.cpp.

References assert(), EnableVPlanNativePath, I, llvm::ElementCount::isScalar(), and llvm::InnerLoopVectorizer::VF.

◆ memoryInstructionCanBeWidened()

bool LoopVectorizationCostModel::memoryInstructionCanBeWidened ( Instruction I,
ElementCount  VF = ElementCount::getFixed(1) 
)

Returns true if I is a memory instruction with consecutive memory access that can be widened.

Definition at line 4577 of file LoopVectorize.cpp.

References assert(), DL, llvm::getLoadStorePointerOperand(), llvm::getLoadStoreType(), hasIrregularType(), I, llvm::LoopVectorizationLegality::isConsecutivePtr(), llvm::InnerLoopVectorizer::Legal, Ptr, and llvm::InnerLoopVectorizer::VF.

◆ requiresScalarEpilogue()

bool llvm::LoopVectorizationCostModel::requiresScalarEpilogue ( ElementCount  VF) const
inline

◆ runtimeChecksRequired()

bool LoopVectorizationCostModel::runtimeChecksRequired ( )

◆ selectEpilogueVectorizationFactor()

VectorizationFactor LoopVectorizationCostModel::selectEpilogueVectorizationFactor ( const ElementCount  MaxVF,
const LoopVectorizationPlanner LVP 
)

◆ selectInterleaveCount()

unsigned LoopVectorizationCostModel::selectInterleaveCount ( ElementCount  VF,
InstructionCost  LoopCost 
)
Returns
The desired interleave count. If interleave count has been specified by metadata it will be returned. Otherwise, the interleave count is computed and returned. VF and LoopCost are the selected vectorization factor and the cost of the selected VF.

Definition at line 5661 of file LoopVectorize.cpp.

References llvm::any_of(), assert(), BB, llvm::dbgs(), llvm::MapVector< KeyT, ValueT, MapType, VectorType >::empty(), llvm::TargetTransformInfo::enableAggressiveInterleaving(), EnableIndVarRegisterHeur, EnableLoadStoreRuntimeInterleave, F, ForceTargetMaxScalarInterleaveFactor, ForceTargetMaxVectorInterleaveFactor, ForceTargetNumScalarRegs, ForceTargetNumVectorRegs, llvm::LinearPolySize< LeafTy >::getKnownMinValue(), llvm::TargetTransformInfo::getMaxInterleaveFactor(), llvm::LoopVectorizationLegality::getMaxSafeDepDistBytes(), llvm::TargetTransformInfo::getNumberOfRegisters(), llvm::LoopVectorizationLegality::getNumLoads(), llvm::LoopVectorizationLegality::getNumStores(), llvm::LoopVectorizationLegality::getReductionVars(), llvm::TargetTransformInfo::getRegisterClassName(), llvm::LoopVectorizationLegality::getRuntimePointerChecking(), llvm::PredicatedScalarEvolution::getSE(), getSmallBestKnownTC(), llvm::InstructionCost::getValue(), InterleaveSmallLoopScalarReduction, llvm::ElementCount::isScalar(), llvm::InstructionCost::isValid(), llvm::ElementCount::isVector(), llvm::InnerLoopVectorizer::Legal, LLVM_DEBUG, llvm::max(), MaxNestedScalarReductionIC, llvm::min(), llvm::RuntimePointerChecking::Need, llvm::PowerOf2Floor(), llvm::InnerLoopVectorizer::PSE, Reduction, SmallLoopCost, TinyTripCountInterleaveThreshold, and llvm::InnerLoopVectorizer::VF.

Referenced by llvm::LoopVectorizePass::processLoop().

◆ selectUserVectorizationFactor()

bool llvm::LoopVectorizationCostModel::selectUserVectorizationFactor ( ElementCount  UserVF)
inline

Setup cost-based decisions for user vectorization factor.

Returns
true if the UserVF is a feasible VF to be chosen.

Definition at line 1171 of file LoopVectorize.cpp.

◆ selectVectorizationFactor()

VectorizationFactor LoopVectorizationCostModel::selectVectorizationFactor ( const ElementCountSet CandidateVFs)

◆ setCostBasedWideningDecision()

void LoopVectorizationCostModel::setCostBasedWideningDecision ( ElementCount  VF)

◆ setWideningDecision() [1/2]

void llvm::LoopVectorizationCostModel::setWideningDecision ( const InterleaveGroup< Instruction > *  Grp,
ElementCount  VF,
InstWidening  W,
InstructionCost  Cost 
)
inline

Save vectorization decision W and Cost taken by the cost model for interleaving group Grp and vector width VF.

Broadcast this decicion to all instructions inside the group. But the cost will be assigned to one instruction only.

Definition at line 1315 of file LoopVectorize.cpp.

References assert(), llvm::InnerLoopVectorizer::Cost, llvm::InterleaveGroup< InstTy >::getFactor(), llvm::InterleaveGroup< InstTy >::getInsertPos(), llvm::InterleaveGroup< InstTy >::getMember(), i, I, llvm::ElementCount::isVector(), llvm::InnerLoopVectorizer::VF, and llvm::RISCVFenceField::W.

◆ setWideningDecision() [2/2]

void llvm::LoopVectorizationCostModel::setWideningDecision ( Instruction I,
ElementCount  VF,
InstWidening  W,
InstructionCost  Cost 
)
inline

Save vectorization decision W and Cost taken by the cost model for instruction I and vector width VF.

Definition at line 1307 of file LoopVectorize.cpp.

References assert(), llvm::InnerLoopVectorizer::Cost, I, llvm::ElementCount::isVector(), llvm::InnerLoopVectorizer::VF, and llvm::RISCVFenceField::W.

◆ useActiveLaneMaskForControlFlow()

bool llvm::LoopVectorizationCostModel::useActiveLaneMaskForControlFlow ( ) const
inline

Returns true if were tail-folding and want to use the active lane mask for vector loop control flow.

Definition at line 1521 of file LoopVectorize.cpp.

References llvm::DataAndControlFlow, and llvm::TargetTransformInfo::emitGetActiveLaneMask().

◆ useOrderedReductions()

bool llvm::LoopVectorizationCostModel::useOrderedReductions ( const RecurrenceDescriptor RdxDesc) const
inline

Returns true if we should use strict in-order reductions for the given RdxDesc.

This is true if the -enable-strict-reductions flag is passed, the IsOrdered flag of RdxDesc is set and we do not allow reordering of FP operations.

Definition at line 1227 of file LoopVectorize.cpp.

References llvm::RecurrenceDescriptor::isOrdered().

Referenced by llvm::InnerLoopVectorizer::useOrderedReductions().

Member Data Documentation

◆ AC

AssumptionCache* llvm::LoopVectorizationCostModel::AC

Assumption cache.

Definition at line 1818 of file LoopVectorize.cpp.

◆ DB

DemandedBits* llvm::LoopVectorizationCostModel::DB

Demanded bits analysis.

Definition at line 1815 of file LoopVectorize.cpp.

◆ ElementTypesInLoop

SmallPtrSet<Type *, 16> llvm::LoopVectorizationCostModel::ElementTypesInLoop

All element types found in the loop.

Definition at line 1839 of file LoopVectorize.cpp.

◆ Hints

const LoopVectorizeHints* llvm::LoopVectorizationCostModel::Hints

◆ InterleaveInfo

InterleavedAccessInfo& llvm::LoopVectorizationCostModel::InterleaveInfo

The interleave access information contains groups of interleaved accesses with the same stride and close to each other.

Definition at line 1830 of file LoopVectorize.cpp.

◆ Legal

LoopVectorizationLegality* llvm::LoopVectorizationCostModel::Legal

Vectorization legality.

Definition at line 1806 of file LoopVectorize.cpp.

◆ LI

LoopInfo* llvm::LoopVectorizationCostModel::LI

Loop Info analysis.

Definition at line 1803 of file LoopVectorize.cpp.

◆ ORE

OptimizationRemarkEmitter* llvm::LoopVectorizationCostModel::ORE

Interface to emit optimization remarks.

Definition at line 1821 of file LoopVectorize.cpp.

◆ ProfitableVFs

SmallVector<VectorizationFactor, 8> llvm::LoopVectorizationCostModel::ProfitableVFs

Profitable vector factors.

Definition at line 1842 of file LoopVectorize.cpp.

◆ PSE

PredicatedScalarEvolution& llvm::LoopVectorizationCostModel::PSE

Predicated scalar evolution analysis.

Definition at line 1800 of file LoopVectorize.cpp.

◆ TheFunction

const Function* llvm::LoopVectorizationCostModel::TheFunction

Definition at line 1823 of file LoopVectorize.cpp.

◆ TheLoop

Loop* llvm::LoopVectorizationCostModel::TheLoop

The loop that we evaluate.

Definition at line 1797 of file LoopVectorize.cpp.

◆ TLI

const TargetLibraryInfo* llvm::LoopVectorizationCostModel::TLI

Target Library Info.

Definition at line 1812 of file LoopVectorize.cpp.

◆ TTI

const TargetTransformInfo& llvm::LoopVectorizationCostModel::TTI

Vector target information.

Definition at line 1809 of file LoopVectorize.cpp.

◆ ValuesToIgnore

SmallPtrSet<const Value *, 16> llvm::LoopVectorizationCostModel::ValuesToIgnore

Values to ignore in the cost model.

Definition at line 1833 of file LoopVectorize.cpp.

◆ VecValuesToIgnore

SmallPtrSet<const Value *, 16> llvm::LoopVectorizationCostModel::VecValuesToIgnore

Values to ignore in the cost model when VF > 1.

Definition at line 1836 of file LoopVectorize.cpp.


The documentation for this class was generated from the following file: