LLVM 20.0.0git
|
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) |
VPValue * | getPredicatedMask (VPRegionBlock *R) |
If R is a region with a VPBranchOnMaskRecipe in the entry block, return the mask. | |
static VPBasicBlock * | getPredicatedThenBlock (VPRegionBlock *R) |
If R is a triangle region, return the 'then' block of the triangle. | |
static bool | mergeReplicateRegionsIntoSuccessors (VPlan &Plan) |
static VPRegionBlock * | createReplicateRegion (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 VPScalarIVStepsRecipe * | createScalarIVSteps (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 VPActiveLaneMaskPHIRecipe * | addVPLaneMaskPhiAndUpdateExitBranch (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. | |
This file implements a set of utility VPlan to VPlan transformations.
Definition in file VPlanTransforms.cpp.
|
static |
Definition at line 341 of file VPlanTransforms.cpp.
References createReplicateRegion(), llvm::VPlan::getEntry(), llvm::Value::getName(), llvm::VPBlockBase::getParent(), llvm::BasicBlock::getParent(), llvm::Value::hasName(), llvm::VPBlockUtils::insertOnEdge(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::Value::setName(), llvm::VPBasicBlock::splitAt(), llvm::SplitBlock(), and llvm::vp_depth_first_deep().
Referenced by llvm::VPlanTransforms::createAndOptimizeReplicateRegions().
|
static |
Definition at line 1296 of file VPlanTransforms.cpp.
References llvm::VPInstruction::ActiveLaneMask, llvm::VPUser::addOperand(), llvm::VPInstruction::BranchOnCond, llvm::VPInstruction::CalculateTripCountMinusVF, llvm::VPInstruction::CanonicalIVIncrementForPart, llvm::VPBuilder::createNaryOp(), llvm::VPBuilder::createNot(), llvm::VPBuilder::createOverflowingOp(), llvm::DataAndControlFlowWithoutRuntimeCheck, DL, llvm::VPRecipeBase::eraseFromParent(), llvm::VPlan::getCanonicalIV(), llvm::VPBlockBase::getExitingBasicBlock(), llvm::VPBasicBlock::getTerminator(), llvm::VPlan::getTripCount(), llvm::VPlan::getVectorLoopRegion(), llvm::VPlan::getVectorPreheader(), and llvm::VPBuilder::setInsertPoint().
Referenced by llvm::VPlanTransforms::addActiveLaneMask().
|
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().
|
static |
Definition at line 915 of file VPlanTransforms.cpp.
References llvm::VPDef::definedValues(), I, and Users.
Referenced by llvm::VPlanTransforms::clearReductionWrapFlags(), and transformRecipestoEVLRecipes().
|
static |
Definition at line 305 of file VPlanTransforms.cpp.
References assert(), llvm::VPBlockUtils::connectBlocks(), llvm::VPRecipeBase::eraseFromParent(), llvm::VPReplicateRecipe::getMask(), llvm::VPValue::getNumUsers(), llvm::VPSingleDefRecipe::getUnderlyingInstr(), llvm::VPBlockUtils::insertTwoBlocksAfter(), llvm::VPReplicateRecipe::isUniform(), llvm::make_range(), llvm::VPUser::op_begin(), llvm::VPUser::op_end(), llvm::VPValue::replaceAllUsesWith(), and llvm::VPUser::setOperand().
Referenced by addReplicateRegions().
|
static |
Definition at line 524 of file VPlanTransforms.cpp.
References assert(), llvm::VPBuilder::createDerivedIV(), llvm::VPBuilder::createScalarCast(), llvm::VPBuilder::createScalarIVSteps(), llvm::VPlan::getCanonicalIV(), llvm::VPBlockBase::getEntryBasicBlock(), llvm::Type::getScalarSizeInBits(), llvm::VPCanonicalIVPHIRecipe::getScalarType(), llvm::VPBlockBase::getSingleHierarchicalPredecessor(), llvm::Value::getType(), llvm::VPlan::getVectorLoopRegion(), llvm::VPTypeAnalysis::inferScalarType(), llvm::VPCanonicalIVPHIRecipe::isCanonical(), llvm::Type::isIntegerTy(), and llvm::VPBuilder::setInsertPoint().
Referenced by legalizeAndOptimizeInductions().
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().
|
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().
|
static |
Try to hoist Previous
and its operands before all users of FOR
.
Definition at line 771 of file VPlanTransforms.cpp.
References A, llvm::all_of(), assert(), B, llvm::VPBasicBlock::getEnclosingLoopRegion(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::VPDef::getNumDefinedValues(), llvm::VPBlockBase::getParent(), llvm::VPRecipeBase::getParent(), llvm::VPDef::getVPSingleValue(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::VPRecipeBase::mayHaveSideEffects(), llvm::VPRecipeBase::mayReadFromMemory(), llvm::VPUser::operands(), llvm::VPDominatorTree::properlyDominates(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorBase< Size_T >::size(), and llvm::sort().
Referenced by llvm::VPlanTransforms::adjustFixedOrderRecurrences().
|
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().
|
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().
|
static |
Move loop-invariant recipes out of the vector loop region in Plan
.
Definition at line 1069 of file VPlanTransforms.cpp.
References llvm::any_of(), llvm::VPBasicBlock::end(), llvm::VPRegionBlock::getEntry(), llvm::VPlan::getVectorLoopRegion(), llvm::VPlan::getVectorPreheader(), llvm::make_early_inc_range(), and llvm::vp_depth_first_shallow().
Remove redundant VPBasicBlocks by merging them into their predecessor if the predecessor has a single successor.
Definition at line 369 of file VPlanTransforms.cpp.
References llvm::VPBlockUtils::connectBlocks(), llvm::VPBlockUtils::disconnectBlocks(), llvm::SmallVectorBase< Size_T >::empty(), llvm::VPBasicBlock::end(), llvm::VPlan::getEntry(), llvm::make_early_inc_range(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::to_vector(), and llvm::vp_depth_first_deep().
Definition at line 219 of file VPlanTransforms.cpp.
References assert(), llvm::VPBlockUtils::connectBlocks(), llvm::SetVector< T, Vector, Set, N >::contains(), llvm::VPBlockUtils::disconnectBlocks(), llvm::SetVector< T, Vector, Set, N >::empty(), llvm::VPlan::getEntry(), llvm::VPBasicBlock::getFirstNonPhi(), getPredicatedMask(), getPredicatedThenBlock(), llvm::VPBlockBase::getSingleSuccessor(), llvm::SetVector< T, Vector, Set, N >::insert(), llvm::make_early_inc_range(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::VPValue::replaceUsesWithIf(), llvm::reverse(), and llvm::vp_depth_first_deep().
Referenced by llvm::VPlanTransforms::createAndOptimizeReplicateRegions().
|
static |
Definition at line 646 of file VPlanTransforms.cpp.
References llvm::SmallVectorImpl< T >::append(), llvm::SmallVectorBase< Size_T >::empty(), llvm::VPValue::getDefiningRecipe(), llvm::SmallPtrSetImpl< PtrType >::insert(), isDeadRecipe(), llvm::SmallVectorImpl< T >::pop_back_val(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by llvm::VPlanTransforms::optimizeForVFAndUF(), simplifyRecipe(), and transformRecipestoEVLRecipes().
|
static |
Try to replace VPWidenCanonicalIVRecipes with a widened canonical IV recipe, if it exists.
Definition at line 454 of file VPlanTransforms.cpp.
References llvm::any_of(), llvm::VPRecipeBase::eraseFromParent(), llvm::VPlan::getCanonicalIV(), llvm::VPBlockBase::getEntryBasicBlock(), llvm::VPlan::getVectorLoopRegion(), llvm::vputils::onlyFirstLaneUsed(), llvm::VPBasicBlock::phis(), llvm::VPValue::replaceAllUsesWith(), and llvm::VPValue::users().
Referenced by llvm::VPlanTransforms::optimize().
|
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().
|
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().
|
static |
Try to simplify recipe R
.
Definition at line 946 of file VPlanTransforms.cpp.
References A, assert(), llvm::SmallPtrSetImpl< PtrType >::begin(), llvm::Type::getScalarSizeInBits(), I, llvm::VPTypeAnalysis::inferScalarType(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_LogicalAnd(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_ZExtOrSExt(), llvm::PatternMatch::match(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), recursivelyDeleteDeadRecipes(), llvm::VPValue::replaceAllUsesWith(), llvm::SmallPtrSetImplBase::size(), X, and Y.
Referenced by simplifyRecipes().
|
static |
Try to simplify the recipes in Plan
.
Definition at line 1103 of file VPlanTransforms.cpp.
References llvm::VPlan::getCanonicalIV(), llvm::VPlan::getEntry(), llvm::VPCanonicalIVPHIRecipe::getScalarType(), llvm::make_early_inc_range(), and simplifyRecipe().
Referenced by llvm::VPlanTransforms::optimize().
|
static |
Sink users of FOR
after the recipe defining the previous value Previous
of the recurrence.
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().
Definition at line 109 of file VPlanTransforms.cpp.
References llvm::all_of(), llvm::VPlan::getEntry(), llvm::VPBlockBase::getEntryBasicBlock(), llvm::VPBlockBase::getExitingBasicBlock(), llvm::VPBasicBlock::getFirstNonPhi(), llvm::VPRecipeBase::getParent(), llvm::VPBlockBase::getSingleSuccessor(), llvm::VPBlockBase::getSuccessors(), llvm::VPSingleDefRecipe::getUnderlyingInstr(), llvm::VPlan::hasScalarVFOnly(), I, llvm::SetVector< T, Vector, Set, N >::insert(), llvm::VPRecipeBase::mayHaveSideEffects(), llvm::VPRecipeBase::mayReadOrWriteMemory(), llvm::VPRecipeBase::moveBefore(), llvm::VPUser::operands(), llvm::VPValue::replaceUsesWithIf(), llvm::SetVector< T, Vector, Set, N >::size(), llvm::SmallVectorBase< Size_T >::size(), llvm::VPValue::users(), and llvm::vp_depth_first_deep().
Referenced by llvm::VPlanTransforms::createAndOptimizeReplicateRegions().
Replace recipes with their EVL variants.
Definition at line 1446 of file VPlanTransforms.cpp.
References assert(), llvm::TypeSwitch< T, ResultT >::Case(), collectAllHeaderMasks(), collectUsersRecursively(), llvm::Default, llvm::VPlan::getCanonicalIV(), llvm::Type::getContext(), llvm::VPRecipeBase::getDebugLoc(), llvm::VPIntrinsic::getForIntrinsic(), llvm::VPIntrinsic::getForOpcode(), llvm::Type::getInt1Ty(), llvm::VPWidenMemoryRecipe::getMask(), llvm::VPIntrinsic::getMaskParamPos(), llvm::VPDef::getNumDefinedValues(), llvm::VPWidenCastRecipe::getOpcode(), llvm::VPlan::getOrAddLiveIn(), llvm::VPCanonicalIVPHIRecipe::getScalarType(), llvm::ConstantInt::getTrue(), llvm::VPSingleDefRecipe::getUnderlyingInstr(), llvm::VPIntrinsic::getVectorLengthParamPos(), llvm::VPlan::getVF(), llvm::VPDef::getVPSingleValue(), llvm::VPTypeAnalysis::inferScalarType(), llvm::VPRecipeBase::insertBefore(), llvm::Instruction::isBinaryOp(), llvm::Instruction::isUnaryOp(), LHS, llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::match(), llvm::Intrinsic::not_intrinsic, llvm::VPUser::operands(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), recursivelyDeleteDeadRecipes(), llvm::VPValue::replaceAllUsesWith(), llvm::reverse(), RHS, and llvm::VPValue::users().
Referenced by llvm::VPlanTransforms::tryAddExplicitVectorLength().