LLVM 20.0.0git
Functions
VPlanTransforms.cpp File Reference

This file implements a set of utility VPlan to VPlan transformations. More...

#include "VPlanTransforms.h"
#include "VPRecipeBuilder.h"
#include "VPlanAnalysis.h"
#include "VPlanCFG.h"
#include "VPlanDominatorTree.h"
#include "VPlanPatternMatch.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Analysis/IVDescriptors.h"
#include "llvm/Analysis/VectorUtils.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/PatternMatch.h"

Go to the source code of this file.

Functions

static bool sinkScalarOperands (VPlan &Plan)
 
VPValuegetPredicatedMask (VPRegionBlock *R)
 If R is a region with a VPBranchOnMaskRecipe in the entry block, return the mask.
 
static VPBasicBlockgetPredicatedThenBlock (VPRegionBlock *R)
 If R is a triangle region, return the 'then' block of the triangle.
 
static bool mergeReplicateRegionsIntoSuccessors (VPlan &Plan)
 
static VPRegionBlockcreateReplicateRegion (VPReplicateRecipe *PredRecipe, VPlan &Plan)
 
static void addReplicateRegions (VPlan &Plan)
 
static bool mergeBlocksIntoPredecessors (VPlan &Plan)
 Remove redundant VPBasicBlocks by merging them into their predecessor if the predecessor has a single successor.
 
static void removeRedundantInductionCasts (VPlan &Plan)
 Remove redundant casts of inductions.
 
static void removeRedundantCanonicalIVs (VPlan &Plan)
 Try to replace VPWidenCanonicalIVRecipes with a widened canonical IV recipe, if it exists.
 
static bool isDeadRecipe (VPRecipeBase &R)
 Returns true if R is dead and can be removed.
 
static void removeDeadRecipes (VPlan &Plan)
 
static VPScalarIVStepsRecipecreateScalarIVSteps (VPlan &Plan, InductionDescriptor::InductionKind Kind, Instruction::BinaryOps InductionOpcode, FPMathOperator *FPBinOp, ScalarEvolution &SE, Instruction *TruncI, VPValue *StartV, VPValue *Step, VPBasicBlock::iterator IP)
 
static void legalizeAndOptimizeInductions (VPlan &Plan, ScalarEvolution &SE)
 Legalize VPWidenPointerInductionRecipe, by replacing it with a PtrAdd (IndStart, ScalarIVSteps (0, Step)) if only its scalar values are used, as VPWidenPointerInductionRecipe will generate vectors only.
 
static void removeRedundantExpandSCEVRecipes (VPlan &Plan)
 Remove redundant EpxandSCEVRecipes in Plan's entry block by replacing them with already existing recipes expanding the same SCEV expression.
 
static void recursivelyDeleteDeadRecipes (VPValue *V)
 
static VPRegionBlockGetReplicateRegion (VPRecipeBase *R)
 
static bool properlyDominates (const VPRecipeBase *A, const VPRecipeBase *B, VPDominatorTree &VPDT)
 
static bool sinkRecurrenceUsersAfterPrevious (VPFirstOrderRecurrencePHIRecipe *FOR, VPRecipeBase *Previous, VPDominatorTree &VPDT)
 Sink users of FOR after the recipe defining the previous value Previous of the recurrence.
 
static SmallVector< VPUser * > collectUsersRecursively (VPValue *V)
 
static void simplifyRecipe (VPRecipeBase &R, VPTypeAnalysis &TypeInfo)
 Try to simplify recipe R.
 
static void simplifyRecipes (VPlan &Plan, LLVMContext &Ctx)
 Try to simplify the recipes in Plan.
 
static VPActiveLaneMaskPHIRecipeaddVPLaneMaskPhiAndUpdateExitBranch (VPlan &Plan, bool DataAndControlFlowWithoutRuntimeCheck)
 
static SmallVector< VPValue * > collectAllHeaderMasks (VPlan &Plan)
 Collect all VPValues representing a header mask through the (ICMP_ULE, WideCanonicalIV, backedge-taken-count) pattern.
 

Detailed Description

This file implements a set of utility VPlan to VPlan transformations.

Definition in file VPlanTransforms.cpp.

Function Documentation

◆ addReplicateRegions()

static void addReplicateRegions ( VPlan Plan)
static

◆ addVPLaneMaskPhiAndUpdateExitBranch()

static VPActiveLaneMaskPHIRecipe * addVPLaneMaskPhiAndUpdateExitBranch ( VPlan Plan,
bool  DataAndControlFlowWithoutRuntimeCheck 
)
static

◆ collectAllHeaderMasks()

static SmallVector< VPValue * > collectAllHeaderMasks ( VPlan Plan)
static

Collect all VPValues representing a header mask through the (ICMP_ULE, WideCanonicalIV, backedge-taken-count) pattern.

TODO: Introduce explicit recipe for header-mask instead of searching for the header-mask pattern manually.

Definition at line 1334 of file VPlanTransforms.cpp.

References assert(), llvm::count_if(), llvm::iterator_range< IteratorT >::end(), llvm::find_if(), llvm::VPlan::getCanonicalIV(), llvm::VPBlockBase::getEntryBasicBlock(), llvm::VPlan::getVectorLoopRegion(), llvm::vputils::isHeaderMask(), llvm::VPBasicBlock::phis(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::VPValue::users().

Referenced by llvm::VPlanTransforms::addActiveLaneMask(), and llvm::VPlanTransforms::tryAddExplicitVectorLength().

◆ collectUsersRecursively()

static SmallVector< VPUser * > collectUsersRecursively ( VPValue V)
static

◆ createReplicateRegion()

static VPRegionBlock * createReplicateRegion ( VPReplicateRecipe PredRecipe,
VPlan Plan 
)
static

◆ createScalarIVSteps()

static VPScalarIVStepsRecipe * createScalarIVSteps ( VPlan Plan,
InductionDescriptor::InductionKind  Kind,
Instruction::BinaryOps  InductionOpcode,
FPMathOperator FPBinOp,
ScalarEvolution SE,
Instruction TruncI,
VPValue StartV,
VPValue Step,
VPBasicBlock::iterator  IP 
)
static

◆ getPredicatedMask()

VPValue * getPredicatedMask ( VPRegionBlock R)

If R is a region with a VPBranchOnMaskRecipe in the entry block, return the mask.

Definition at line 184 of file VPlanTransforms.cpp.

Referenced by mergeReplicateRegionsIntoSuccessors().

◆ getPredicatedThenBlock()

static VPBasicBlock * getPredicatedThenBlock ( VPRegionBlock R)
static

If R is a triangle region, return the 'then' block of the triangle.

Definition at line 194 of file VPlanTransforms.cpp.

Referenced by mergeReplicateRegionsIntoSuccessors().

◆ GetReplicateRegion()

static VPRegionBlock * GetReplicateRegion ( VPRecipeBase R)
static

Definition at line 719 of file VPlanTransforms.cpp.

References assert().

Referenced by properlyDominates().

◆ isDeadRecipe()

static bool isDeadRecipe ( VPRecipeBase R)
static

Returns true if R is dead and can be removed.

Definition at line 489 of file VPlanTransforms.cpp.

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

Referenced by recursivelyDeleteDeadRecipes(), and removeDeadRecipes().

◆ legalizeAndOptimizeInductions()

static void legalizeAndOptimizeInductions ( VPlan Plan,
ScalarEvolution SE 
)
static

Legalize VPWidenPointerInductionRecipe, by replacing it with a PtrAdd (IndStart, ScalarIVSteps (0, Step)) if only its scalar values are used, as VPWidenPointerInductionRecipe will generate vectors only.

If some users require vectors while other require scalars, the scalar uses need to extract the scalars from the generated vectors (Note that this is different to how int/fp inductions are handled). Also optimize VPWidenIntOrFpInductionRecipe, if any of its users needs scalar values, by providing them scalar steps built on the canonical scalar IV and update the original IV's users. This is an optional optimization to reduce the needs of vector extracts.

Definition at line 578 of file VPlanTransforms.cpp.

References createScalarIVSteps(), llvm::VPRecipeBase::getDebugLoc(), llvm::VPBlockBase::getEntryBasicBlock(), llvm::VPBasicBlock::getFirstNonPhi(), llvm::ElementCount::getFixed(), llvm::VPlan::getOrAddLiveIn(), llvm::VPlan::getVectorLoopRegion(), llvm::VPlan::hasScalableVF(), llvm::VPlan::hasVF(), llvm::InductionDescriptor::IK_IntInduction, llvm::none_of(), llvm::VPBasicBlock::phis(), llvm::VPInstruction::PtrAdd, and ToRemove.

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

◆ mergeBlocksIntoPredecessors()

static bool mergeBlocksIntoPredecessors ( VPlan Plan)
static

◆ mergeReplicateRegionsIntoSuccessors()

static bool mergeReplicateRegionsIntoSuccessors ( VPlan Plan)
static

◆ properlyDominates()

static bool properlyDominates ( const VPRecipeBase A,
const VPRecipeBase B,
VPDominatorTree VPDT 
)
static

◆ recursivelyDeleteDeadRecipes()

static void recursivelyDeleteDeadRecipes ( VPValue V)
static

◆ removeDeadRecipes()

static void removeDeadRecipes ( VPlan Plan)
static

◆ removeRedundantCanonicalIVs()

static void removeRedundantCanonicalIVs ( VPlan Plan)
static

◆ removeRedundantExpandSCEVRecipes()

static void removeRedundantExpandSCEVRecipes ( VPlan Plan)
static

Remove redundant EpxandSCEVRecipes in Plan's entry block by replacing them with already existing recipes expanding the same SCEV expression.

Definition at line 636 of file VPlanTransforms.cpp.

References llvm::VPlan::getEntry(), llvm::VPBlockBase::getEntryBasicBlock(), I, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), and llvm::make_early_inc_range().

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

◆ removeRedundantInductionCasts()

static void removeRedundantInductionCasts ( VPlan Plan)
static

Remove redundant casts of inductions.

Such redundant casts are casts of induction variables that can be ignored, because we already proved that the casted phi is equal to the uncasted phi in the vectorized loop. There is no need to vectorize the cast - the same value can be used for both the phi and casts in the vector loop.

Definition at line 420 of file VPlanTransforms.cpp.

References llvm::VPBlockBase::getEntryBasicBlock(), llvm::VPlan::getVectorLoopRegion(), IV, llvm::VPBasicBlock::phis(), llvm::VPValue::replaceAllUsesWith(), llvm::reverse(), and llvm::VPValue::users().

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

◆ simplifyRecipe()

static void simplifyRecipe ( VPRecipeBase R,
VPTypeAnalysis TypeInfo 
)
static

◆ simplifyRecipes()

static void simplifyRecipes ( VPlan Plan,
LLVMContext Ctx 
)
static

◆ sinkRecurrenceUsersAfterPrevious()

static bool sinkRecurrenceUsersAfterPrevious ( VPFirstOrderRecurrencePHIRecipe FOR,
VPRecipeBase Previous,
VPDominatorTree VPDT 
)
static

Sink users of FOR after the recipe defining the previous value Previous of the recurrence.

Returns
true if all users of FOR could be re-arranged as needed or false if it is not possible.

Definition at line 763 of file VPlanTransforms.cpp.

References A, assert(), B, llvm::VPDef::getNumDefinedValues(), llvm::VPDef::getVPSingleValue(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), properlyDominates(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorBase< Size_T >::size(), llvm::sort(), and llvm::VPValue::users().

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

◆ sinkScalarOperands()

static bool sinkScalarOperands ( VPlan Plan)
static