LLVM 17.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.
 

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.
 
std::pair< unsigned, unsignedgetSmallestAndWidestTypes ()
 
unsigned selectInterleaveCount (ElementCount VF, InstructionCost LoopCost)
 
void setCostBasedWideningDecision (ElementCount VF)
 Memory access instruction may be vectorized in more than one way.
 
SmallVector< RegisterUsage, 8 > calculateRegisterUsage (ArrayRef< ElementCount > VFs)
 
void collectValuesToIgnore ()
 Collect values we want to ignore in the cost model.
 
void collectElementTypesForWidening ()
 Collect all element types in the loop for which widening is needed.
 
void collectInLoopReductions ()
 Split reductions into those that happen in the loop, and those that happen outside.
 
bool useOrderedReductions (const RecurrenceDescriptor &RdxDesc) const
 Returns true if we should use strict in-order reductions for the given RdxDesc.
 
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.
 
bool isScalarAfterVectorization (Instruction *I, ElementCount VF) const
 Returns true if I is known to be scalar after vectorization.
 
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.
 
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.
 
InstWidening getWideningDecision (Instruction *I, ElementCount VF) const
 Return the cost model decision for the given instruction I and vector width VF.
 
InstructionCost getWideningCost (Instruction *I, ElementCount VF)
 Return the vectorization cost for the given instruction I and vector width VF.
 
bool isOptimizableIVTruncate (Instruction *I, ElementCount VF)
 Return True if instruction I is an optimizable truncate whose operand is an induction variable.
 
void collectInstsToScalarize (ElementCount VF)
 Collects the instructions to scalarize for each predicated instruction in the loop.
 
void collectUniformsAndScalars (ElementCount VF)
 Collect Uniform and Scalar values for the given VF.
 
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.
 
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.
 
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.
 
bool canVectorizeReductions (ElementCount VF) const
 Returns true if the target machine supports all of the reduction variables found for the given VF.
 
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.
 
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.
 
bool isPredicatedInst (Instruction *I) const
 Returns true if I is an instruction that needs to be predicated at runtime.
 
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.
 
bool memoryInstructionCanBeWidened (Instruction *I, ElementCount VF)
 Returns true if I is a memory instruction with consecutive memory access that can be widened.
 
bool interleavedAccessCanBeWidened (Instruction *I, ElementCount VF)
 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.
 
bool isAccessInterleaved (Instruction *Instr)
 Check if Instr belongs to any interleaved access group.
 
const InterleaveGroup< Instruction > * getInterleavedAccessGroup (Instruction *Instr)
 Get the interleaved access group that Instr belongs to.
 
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.
 
bool isScalarEpilogueAllowed () const
 Returns true if a scalar epilogue is not allowed due to optsize or a loop hint annotation.
 
TailFoldingStyle getTailFoldingStyle (bool IVUpdateMayOverflow=true) const
 Returns the TailFoldingStyle that is best for the current loop.
 
bool foldTailByMasking () const
 Returns true if all loop blocks should be masked to fold tail loop.
 
bool blockNeedsPredicationForAnyReason (BasicBlock *BB) const
 Returns true if the instructions in this block requires predication for any reason, e.g.
 
const ReductionChainMapgetInLoopReductionChains () const
 Return the chain of instructions representing an inloop reduction.
 
bool isInLoopReduction (PHINode *Phi) const
 Returns true if the Phi is part of an inloop reduction.
 
InstructionCost getVectorIntrinsicCost (CallInst *CI, ElementCount VF) const
 Estimate cost of an intrinsic call instruction CI if it were vectorized with factor VF.
 
InstructionCost getVectorCallCost (CallInst *CI, ElementCount VF, Function **Variant, bool *NeedsMask=nullptr) const
 Estimate cost of a call instruction CI if it were vectorized with factor VF.
 
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.
 
void invalidateCostModelingDecisions ()
 Invalidates decisions already taken by the cost model.
 
std::optional< unsignedgetVScaleForTuning () 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.
 

Public Attributes

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

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 1185 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 1596 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 1353 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 1187 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 1589 of file LoopVectorize.cpp.

References llvm::IRSimilarity::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 1346 of file LoopVectorize.cpp.

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

◆ 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 1489 of file LoopVectorize.cpp.

References llvm::all_of(), llvm::IRSimilarity::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 1448 of file LoopVectorize.cpp.

References llvm::ElementCount::isScalar().

◆ collectValuesToIgnore()

void LoopVectorizationCostModel::collectValuesToIgnore ( )

◆ computeMaxVF()

FixedScalableVFPair LoopVectorizationCostModel::computeMaxVF ( ElementCount  UserVF,
unsigned  UserIC 
)

◆ foldTailByMasking()

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

Returns true if all loop blocks should be masked to fold tail loop.

Definition at line 1582 of file LoopVectorize.cpp.

Referenced by llvm::InnerLoopVectorizer::completeLoopSkeleton(), llvm::InnerLoopVectorizer::fixReduction(), and llvm::InnerLoopVectorizer::getOrCreateVectorTripCount().

◆ 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 1600 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 1547 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 1285 of file LoopVectorize.cpp.

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

◆ getSmallestAndWidestTypes()

std::pair< unsigned, unsigned > LoopVectorizationCostModel::getSmallestAndWidestTypes ( )
Returns
The size (in bits) of the smallest and widest types in the code that needs to be vectorized. We ignore values that remain scalar such as 64 bit loop indices.

Definition at line 5652 of file LoopVectorize.cpp.

References DL, llvm::MachineFunction::getDataLayout(), llvm::RecurrenceDescriptor::getMinWidthCastToRecurrenceTypeInBits(), llvm::MachineBasicBlock::getParent(), llvm::RecurrenceDescriptor::getRecurrenceType(), llvm::Type::getScalarSizeInBits(), and llvm::IRSimilarity::Legal.

Referenced by determineVPlanVF().

◆ getTailFoldingStyle()

TailFoldingStyle llvm::LoopVectorizationCostModel::getTailFoldingStyle ( bool  IVUpdateMayOverflow = true) const
inline

Returns the TailFoldingStyle that is best for the current loop.

Definition at line 1571 of file LoopVectorize.cpp.

References ForceTailFoldingStyle, and llvm::TargetTransformInfo::getPreferredTailFoldingStyle().

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

◆ getVectorCallCost()

InstructionCost LoopVectorizationCostModel::getVectorCallCost ( CallInst CI,
ElementCount  VF,
Function **  Variant,
bool NeedsMask = nullptr 
) const

◆ getVectorIntrinsicCost()

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

◆ getVScaleForTuning()

std::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 5326 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 1407 of file LoopVectorize.cpp.

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

◆ 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 1391 of file LoopVectorize.cpp.

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

◆ interleavedAccessCanBeWidened()

bool LoopVectorizationCostModel::interleavedAccessCanBeWidened ( Instruction I,
ElementCount  VF 
)

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.

Definition at line 4561 of file LoopVectorize.cpp.

References assert(), DL, llvm::getLoadStoreAlignment(), llvm::getLoadStoreType(), hasIrregularType(), I, llvm::TargetTransformInfo::isLegalMaskedLoad(), llvm::TargetTransformInfo::isLegalMaskedStore(), llvm::IRSimilarity::Legal, useMaskedInterleavedAccesses(), and llvm::InnerLoopVectorizer::VF.

◆ invalidateCostModelingDecisions()

void llvm::LoopVectorizationCostModel::invalidateCostModelingDecisions ( )
inline

Invalidates decisions already taken by the cost model.

Definition at line 1629 of file LoopVectorize.cpp.

◆ isAccessInterleaved()

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

Check if Instr belongs to any interleaved access group.

Definition at line 1541 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 1499 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 1605 of file LoopVectorize.cpp.

◆ isLegalGatherOrScatter()

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

Returns true if the target machine can represent V as a masked gather or scatter operation.

Definition at line 1473 of file LoopVectorize.cpp.

References llvm::getLoadStoreAlignment(), llvm::getLoadStoreType(), llvm::TargetTransformInfo::isLegalMaskedGather(), llvm::TargetTransformInfo::isLegalMaskedScatter(), and SI.

◆ 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 1466 of file LoopVectorize.cpp.

References llvm::TargetTransformInfo::isLegalMaskedLoad(), llvm::IRSimilarity::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 1459 of file LoopVectorize.cpp.

References llvm::TargetTransformInfo::isLegalMaskedStore(), llvm::IRSimilarity::Legal, and Ptr.

◆ isMoreProfitable()

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

Returns true if the per-lane cost of VectorizationFactor A is lower than that of B.

Definition at line 5338 of file LoopVectorize.cpp.

References A, B, llvm::divideCeil(), llvm::PredicatedScalarEvolution::getSE(), llvm::ScalarEvolution::getSmallConstantMaxTripCount(), and llvm::InnerLoopVectorizer::PSE.

◆ 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 1418 of file LoopVectorize.cpp.

References I, llvm::TargetTransformInfo::isTruncateFree(), llvm::IRSimilarity::Legal, and llvm::ToVectorTy().

◆ 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 4454 of file LoopVectorize.cpp.

References I, llvm::isSafeToSpeculativelyExecute(), and llvm::IRSimilarity::Legal.

◆ 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 1291 of file LoopVectorize.cpp.

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

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 1329 of file LoopVectorize.cpp.

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

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 1565 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 4418 of file LoopVectorize.cpp.

References llvm::VectorType::get(), llvm::getLoadStoreAlignment(), llvm::getLoadStorePointerOperand(), llvm::getLoadStoreType(), I, llvm::TargetTransformInfo::isLegalMaskedGather(), llvm::TargetTransformInfo::isLegalMaskedScatter(), llvm::ElementCount::isVector(), Ptr, 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 1307 of file LoopVectorize.cpp.

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

◆ memoryInstructionCanBeWidened()

bool LoopVectorizationCostModel::memoryInstructionCanBeWidened ( Instruction I,
ElementCount  VF 
)

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

Definition at line 4630 of file LoopVectorize.cpp.

References assert(), DL, llvm::getLoadStorePointerOperand(), llvm::getLoadStoreType(), hasIrregularType(), I, llvm::IRSimilarity::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 
)

◆ 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 1222 of file LoopVectorize.cpp.

◆ selectVectorizationFactor()

VectorizationFactor LoopVectorizationCostModel::selectVectorizationFactor ( const ElementCountSet CandidateVFs)

◆ setCostBasedWideningDecision()

void LoopVectorizationCostModel::setCostBasedWideningDecision ( ElementCount  VF)

Memory access instruction may be vectorized in more than one way.

Form of instruction after vectorization depends on cost. This function takes cost-based decisions for Load/Store instructions and collects them in a map. This decisions map is used for building the lists of loop-uniform and loop-scalar instructions. The calculated cost is saved with widening decision in order to avoid redundant calculations.

Definition at line 6880 of file LoopVectorize.cpp.

References llvm::append_range(), assert(), llvm::InnerLoopVectorizer::Cost, llvm::SmallVectorBase< Size_T >::empty(), llvm::ElementCount::getFixed(), llvm::InstructionCost::getInvalid(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::getKnownMinValue(), llvm::getLoadStorePointerOperand(), llvm::getLoadStoreType(), I, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::isScalable(), llvm::ElementCount::isScalar(), llvm::IRSimilarity::Legal, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::TargetTransformInfo::prefersVectorizedAddressing(), Ptr, llvm::SmallVectorTemplateBase< T, bool >::push_back(), SI, and llvm::InnerLoopVectorizer::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 1372 of file LoopVectorize.cpp.

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

◆ 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 1364 of file LoopVectorize.cpp.

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

◆ 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 1278 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 1877 of file LoopVectorize.cpp.

◆ DB

DemandedBits* llvm::LoopVectorizationCostModel::DB

Demanded bits analysis.

Definition at line 1874 of file LoopVectorize.cpp.

◆ ElementTypesInLoop

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

All element types found in the loop.

Definition at line 1898 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 1889 of file LoopVectorize.cpp.

◆ Legal

LoopVectorizationLegality* llvm::LoopVectorizationCostModel::Legal

Vectorization legality.

Definition at line 1865 of file LoopVectorize.cpp.

Referenced by isIndvarOverflowCheckKnownFalse().

◆ LI

LoopInfo* llvm::LoopVectorizationCostModel::LI

Loop Info analysis.

Definition at line 1862 of file LoopVectorize.cpp.

◆ ORE

OptimizationRemarkEmitter* llvm::LoopVectorizationCostModel::ORE

Interface to emit optimization remarks.

Definition at line 1880 of file LoopVectorize.cpp.

◆ ProfitableVFs

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

Profitable vector factors.

Definition at line 1901 of file LoopVectorize.cpp.

◆ PSE

PredicatedScalarEvolution& llvm::LoopVectorizationCostModel::PSE

Predicated scalar evolution analysis.

Definition at line 1859 of file LoopVectorize.cpp.

Referenced by isIndvarOverflowCheckKnownFalse().

◆ TheFunction

const Function* llvm::LoopVectorizationCostModel::TheFunction

Definition at line 1882 of file LoopVectorize.cpp.

Referenced by isIndvarOverflowCheckKnownFalse().

◆ TheLoop

Loop* llvm::LoopVectorizationCostModel::TheLoop

The loop that we evaluate.

Definition at line 1856 of file LoopVectorize.cpp.

Referenced by isIndvarOverflowCheckKnownFalse().

◆ TLI

const TargetLibraryInfo* llvm::LoopVectorizationCostModel::TLI

Target Library Info.

Definition at line 1871 of file LoopVectorize.cpp.

◆ TTI

const TargetTransformInfo& llvm::LoopVectorizationCostModel::TTI

Vector target information.

Definition at line 1868 of file LoopVectorize.cpp.

Referenced by isIndvarOverflowCheckKnownFalse().

◆ ValuesToIgnore

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

Values to ignore in the cost model.

Definition at line 1892 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 1895 of file LoopVectorize.cpp.


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