LLVM: lib/Transforms/Vectorize/VPlanTransforms.cpp File Reference (original) (raw)

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

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, DebugLoc DL, VPBuilder &Builder)
static SmallVector< VPUser * > collectUsersRecursively (VPValue *V)
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 VPWidenInductionRecipe * getOptimizableIVOf (VPValue *VPV)
Check if VPV is an untruncated wide induction, either before or after the increment.
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 void simplifyRecipe (VPRecipeBase &R, VPTypeAnalysis &TypeInfo)
Try to simplify recipe R.
static void simplifyRecipes (VPlan &Plan, Type *CanonicalIVTy)
Try to simplify the recipes in Plan.
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 void licm (VPlan &Plan)
Move loop-invariant recipes out of the vector loop region 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 VPRecipeBase * createEVLRecipe (VPValue *HeaderMask, VPRecipeBase &CurRecipe, VPTypeAnalysis &TypeInfo, VPValue &AllOneMask, VPValue &EVL)
Try to convert CurRecipe to a corresponding EVL-based recipe.
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.

addReplicateRegions()

static void addReplicateRegions ( VPlan & Plan) static

Definition at line 344 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().

addVPLaneMaskPhiAndUpdateExitBranch()

Definition at line 1490 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().

collectAllHeaderMasks()

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 1565 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()

createEVLRecipe()

Try to convert CurRecipe to a corresponding EVL-based recipe.

Returns nullptr if no EVL-based recipe could be created. HeaderMask Header Mask. CurRecipe Recipe to be transform. TypeInfo VPlan-based type analysis. AllOneMask The vector mask parameter of vector-predication intrinsics. EVL The explicit vector length parameter of vector-predication intrinsics.

Definition at line 1647 of file VPlanTransforms.cpp.

References assert(), llvm::TypeSwitch< T, ResultT >::Case(), llvm::Default, llvm::VPRecipeBase::getDebugLoc(), llvm::VPIntrinsic::getForIntrinsic(), llvm::VPIntrinsic::getForOpcode(), llvm::VPWidenMemoryRecipe::getMask(), llvm::VPIntrinsic::getMaskParamPos(), llvm::VPIntrinsic::getVectorLengthParamPos(), llvm::VPTypeAnalysis::inferScalarType(), 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(), and RHS.

Referenced by transformRecipestoEVLRecipes().

createReplicateRegion()

Definition at line 303 of file VPlanTransforms.cpp.

References assert(), llvm::VPBlockUtils::connectBlocks(), llvm::VPlan::createVPBasicBlock(), llvm::VPlan::createVPRegionBlock(), 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().

createScalarIVSteps()

Definition at line 527 of file VPlanTransforms.cpp.

References assert(), llvm::VPBuilder::createDerivedIV(), llvm::VPBuilder::createScalarCast(), llvm::VPBuilder::createScalarIVSteps(), DL, 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::Type::isIntegerTy(), and llvm::VPBuilder::setInsertPoint().

Referenced by legalizeAndOptimizeInductions().

getOptimizableIVOf()

getPredicatedMask()

getPredicatedThenBlock()

hoistPreviousBeforeFORUsers()

Try to hoist Previous and its operands before all users of FOR.

Definition at line 1112 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().

isDeadRecipe()

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). Legalize extract-from-ends using uniform VPReplicateRecipe of wide inductions to use regular VPReplicateRecipe, so the correct end value is available. 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 589 of file VPlanTransforms.cpp.

References collectUsersRecursively(), 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::vputils::isUniformAfterVectorization(), llvm::none_of(), llvm::vputils::onlyFirstLaneUsed(), llvm::VPBasicBlock::phis(), llvm::VPValue::replaceAllUsesWith(), llvm::reverse(), and Users.

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

Definition at line 219 of file VPlanTransforms.cpp.

References assert(), llvm::VPBlockUtils::connectBlocks(), llvm::SmallPtrSetImpl< PtrType >::contains(), llvm::VPBlockUtils::disconnectBlocks(), llvm::SmallPtrSetImplBase::empty(), llvm::VPlan::getEntry(), llvm::VPBasicBlock::getFirstNonPhi(), getPredicatedMask(), getPredicatedThenBlock(), llvm::VPBlockBase::getSingleSuccessor(), llvm::SmallPtrSetImpl< PtrType >::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().

recursivelyDeleteDeadRecipes()

static void recursivelyDeleteDeadRecipes ( VPValue * V) static

removeRedundantCanonicalIVs()

static void removeRedundantCanonicalIVs ( VPlan & Plan) static

removeRedundantExpandSCEVRecipes()

static void removeRedundantExpandSCEVRecipes ( VPlan & Plan) static

removeRedundantInductionCasts()

static void removeRedundantInductionCasts ( VPlan & Plan) static

simplifyRecipe()

Try to simplify recipe R.

Definition at line 834 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().

simplifyRecipes()

static void simplifyRecipes ( VPlan & Plan, Type * CanonicalIVTy ) static

sinkRecurrenceUsersAfterPrevious()

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 1057 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

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

transformRecipestoEVLRecipes()

static void transformRecipestoEVLRecipes ( VPlan & Plan, VPValue & EVL ) static

Replace recipes with their EVL variants.

Definition at line 1726 of file VPlanTransforms.cpp.

References assert(), collectAllHeaderMasks(), collectUsersRecursively(), createEVLRecipe(), llvm::VPlan::getCanonicalIV(), llvm::Type::getContext(), llvm::VPDef::getNumDefinedValues(), llvm::VPlan::getOrAddLiveIn(), llvm::VPCanonicalIVPHIRecipe::getScalarType(), llvm::ConstantInt::getTrue(), llvm::VPlan::getVF(), llvm::VPDef::getVPSingleValue(), llvm::VPRecipeBase::insertBefore(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), recursivelyDeleteDeadRecipes(), llvm::VPValue::replaceAllUsesWith(), llvm::reverse(), llvm::to_vector(), and llvm::VPValue::users().

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