class LoopVectorizationLegality

Declaration

class LoopVectorizationLegality { /* full declaration omitted */ };

Description

LoopVectorizationLegality checks if it is legal to vectorize a loop, and to what vectorization factor. This class does not look at the profitability of vectorization, only the legality. This class has two main kinds of checks: * Memory checks - The code in canVectorizeMemory checks if vectorization will change the order of memory accesses in a way that will change the correctness of the program. * Scalars checks - The code in canVectorizeInstrs and canVectorizeMemory checks for a number of different conditions, such as the availability of a single induction variable, that all types are supported and vectorize-able, etc. This code reflects the capabilities of InnerLoopVectorizer. This class is also used by InnerLoopVectorizer for identifying induction variable and the different reduction variables.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:197

Method Overview

Methods

LoopVectorizationLegality(
    llvm::Loop* L,
    llvm::PredicatedScalarEvolution& PSE,
    llvm::DominatorTree* DT,
    llvm::TargetTransformInfo* TTI,
    llvm::TargetLibraryInfo* TLI,
    llvm::AliasAnalysis* AA,
    llvm::Function* F,
    std::function<const LoopAccessInfo&(Loop&)>*
        GetLAA,
    llvm::LoopInfo* LI,
    llvm::OptimizationRemarkEmitter* ORE,
    llvm::LoopVectorizationRequirements* R,
    llvm::LoopVectorizeHints* H,
    llvm::DemandedBits* DB,
    llvm::AssumptionCache* AC)

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:199

Parameters

llvm::Loop* L
llvm::PredicatedScalarEvolution& PSE
llvm::DominatorTree* DT
llvm::TargetTransformInfo* TTI
llvm::TargetLibraryInfo* TLI
llvm::AliasAnalysis* AA
llvm::Function* F
std::function<const LoopAccessInfo&(Loop&)>* GetLAA
llvm::LoopInfo* LI
llvm::OptimizationRemarkEmitter* ORE
llvm::LoopVectorizationRequirements* R
llvm::LoopVectorizeHints* H
llvm::DemandedBits* DB
llvm::AssumptionCache* AC

bool blockNeedsPredication(llvm::BasicBlock* BB)

Description

Return true if the block BB needs to be predicated in order for the loop to be vectorized.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:273

Parameters

llvm::BasicBlock* BB

bool canVectorize(bool UseVPlanNativePath)

Description

Returns true if it is legal to vectorize this loop. This does not mean that it is profitable to vectorize this loop, only that it is legal to do so. Temporarily taking UseVPlanNativePath parameter. If true, take the new code path being implemented for outer loop vectorization (should be functional for inner loop vectorization) based on VPlan. If false, good old LV code.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:228

Parameters

bool UseVPlanNativePath

llvm::LoopVectorizationLegality::RecurrenceSet*
getFirstOrderRecurrences()

Description

Return the first-order recurrences found in the loop.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:244

llvm::LoopVectorizationLegality::InductionList*
getInductionVars()

Description

Returns the induction variables found in the loop.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:241

const llvm::LoopAccessInfo* getLAI() const

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:295

unsigned int getMaxSafeDepDistBytes()

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:297

uint64_t getMaxSafeRegisterWidth() const

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:299

unsigned int getNumLoads() const

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:310

unsigned int getNumStores() const

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:309

llvm::PHINode* getPrimaryInduction()

Description

Returns the primary induction variable.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:235

llvm::LoopVectorizationLegality::ReductionList*
getReductionVars()

Description

Returns the reduction variables found in the loop.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:238

const llvm::RuntimePointerChecking*
getRuntimePointerChecking() const

Description

Returns the information that we collected about runtime memory check.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:291

DenseMap<llvm::Instruction*, llvm::Instruction*>&
getSinkAfter()

Description

Return the set of instructions to sink to handle first-order recurrences.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:247

llvm::Type* getWidestInductionType()

Description

Returns the widest induction type.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:250

bool hasFunNoNaNAttr() const

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:313

bool hasStride(llvm::Value* V)

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:303

Parameters

llvm::Value* V

bool isCastedInductionVariable(
    const llvm::Value* V)

Description

Returns True if V is a cast that is part of an induction def-use chain, and had been proven to be redundant under a runtime guard (in other words, the cast has the same SCEV expression as the induction phi).

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:258

Parameters

const llvm::Value* V

int isConsecutivePtr(llvm::Value* Ptr)

Description

Check if this pointer is consecutive when vectorizing. This happens when the last index of the GEP is the induction variable, or that the pointer itself is an induction variable. This check allows us to vectorize A[idx] into a wide load/store. Returns: 0 - Stride is unknown or non-consecutive. 1 - Address is consecutive. -1 - Address is consecutive, and decreasing. NOTE: This method must only be used before modifying the original scalar loop. Do not use after invoking 'createVectorizedLoopSkeleton' (PR34965).

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:285

Parameters

llvm::Value* Ptr

bool isFirstOrderRecurrence(
    const llvm::PHINode* Phi)

Description

Returns True if Phi is a first-order recurrence in this loop.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:269

Parameters

const llvm::PHINode* Phi

bool isInductionPhi(const llvm::Value* V)

Description

Returns True if V is a Phi node of an induction variable in this loop.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:253

Parameters

const llvm::Value* V

bool isInductionVariable(const llvm::Value* V)

Description

Returns True if V can be considered as an induction variable in this loop. V can be the induction phi, or some redundant cast in the def-use chain of the inducion phi.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:263

Parameters

const llvm::Value* V

bool isMaskRequired(const llvm::Instruction* I)

Description

Returns true if vector representation of the instruction \p I requires mask.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:307

Parameters

const llvm::Instruction* I

bool isReductionVariable(llvm::PHINode* PN)

Description

Returns True if PN is a reduction variable in this loop.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:266

Parameters

llvm::PHINode* PN

bool isUniform(llvm::Value* V)

Description

Returns true if the value V is uniform within the loop.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:288

Parameters

llvm::Value* V

bool prepareToFoldTailByMasking()

Description

Return true if we can vectorize this loop while folding its tail by masking, and mark all respective loads/stores for masking.

Declared at: llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h:232