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 "VPlan.h"
#include "VPlanAnalysis.h"
#include "VPlanCFG.h"
#include "VPlanDominatorTree.h"
#include "VPlanPatternMatch.h"
#include "VPlanUtils.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/TypeSwitch.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 VPScalarIVStepsRecipecreateScalarIVSteps (VPlan &Plan, InductionDescriptor::InductionKind Kind, Instruction::BinaryOps InductionOpcode, FPMathOperator *FPBinOp, Instruction *TruncI, VPValue *StartV, VPValue *Step, VPBuilder &Builder)
 
static void legalizeAndOptimizeInductions (VPlan &Plan)
 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 bool sinkRecurrenceUsersAfterPrevious (VPFirstOrderRecurrencePHIRecipe *FOR, VPRecipeBase *Previous, VPDominatorTree &VPDT)
 Sink users of FOR after the recipe defining the previous value Previous of the recurrence.
 
static bool hoistPreviousBeforeFORUsers (VPFirstOrderRecurrencePHIRecipe *FOR, VPRecipeBase *Previous, VPDominatorTree &VPDT)
 Try to hoist Previous and its operands before all users of FOR.
 
static SmallVector< VPUser * > collectUsersRecursively (VPValue *V)
 
static void simplifyRecipe (VPRecipeBase &R, VPTypeAnalysis &TypeInfo)
 Try to simplify recipe R.
 
static void licm (VPlan &Plan)
 Move loop-invariant recipes out of the vector loop region in Plan.
 
static void simplifyRecipes (VPlan &Plan)
 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.
 
static void transformRecipestoEVLRecipes (VPlan &Plan, VPValue &EVL)
 Replace recipes with their EVL variants.
 

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 1371 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 transformRecipestoEVLRecipes().

◆ 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,
Instruction TruncI,
VPValue StartV,
VPValue Step,
VPBuilder Builder 
)
static

◆ getPredicatedMask()

VPValue * getPredicatedMask ( VPRegionBlock R)

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

Definition at line 187 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 197 of file VPlanTransforms.cpp.

Referenced by mergeReplicateRegionsIntoSuccessors().

◆ hoistPreviousBeforeFORUsers()

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

◆ isDeadRecipe()

static bool isDeadRecipe ( VPRecipeBase R)
static

Returns true if R is dead and can be removed.

Definition at line 490 of file VPlanTransforms.cpp.

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

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

◆ legalizeAndOptimizeInductions()

static void legalizeAndOptimizeInductions ( VPlan Plan)
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 573 of file VPlanTransforms.cpp.

References llvm::VPBuilder::createPtrAdd(), 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::VPValue::replaceAllUsesWith(), and ToRemove.

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

◆ licm()

static void licm ( VPlan Plan)
static

◆ mergeBlocksIntoPredecessors()

static bool mergeBlocksIntoPredecessors ( VPlan Plan)
static

◆ mergeReplicateRegionsIntoSuccessors()

static bool mergeReplicateRegionsIntoSuccessors ( VPlan Plan)
static

◆ recursivelyDeleteDeadRecipes()

static void recursivelyDeleteDeadRecipes ( VPValue V)
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 629 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 421 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)
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 716 of file VPlanTransforms.cpp.

References A, assert(), B, llvm::VPDef::getNumDefinedValues(), llvm::VPDef::getVPSingleValue(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::VPDominatorTree::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

◆ transformRecipestoEVLRecipes()

static void transformRecipestoEVLRecipes ( VPlan Plan,
VPValue EVL 
)
static