summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
AgeCommit message (Collapse)Author
2025-11-22[VPlan] Create resume phis in scalar preheader early. (NFC) (#166099)Florian Hahn
Create phi recipes for scalar resume value up front in addInitialSkeleton during initial construction. This will allow moving the remaining code dealing with resume values to VPlan transforms/construction. PR: https://github.com/llvm/llvm-project/pull/166099
2025-11-18[VPlan] Populate and use VPIRFlags from initial VPInstruction. (#168450)Florian Hahn
Update VPlan to populate VPIRFlags during VPInstruction construction and use it when creating widened recipes, instead of constructing VPIRFlags from the underlying IR instruction each time. The VPRecipeWithIRFlags constructor taking an underlying instruction and setting the flags based on it has been removed. This centralizes initial VPIRFlags creation and ensures flags are consistently available throughout VPlan transformations and makes sure we don't accidentally re-add flags from the underlying instruction that already got dropped during transformations. Follow-up to https://github.com/llvm/llvm-project/pull/167253, which did the same for VPIRMetadata. Should be NFC w.r.t. to the generated IR. PR: https://github.com/llvm/llvm-project/pull/168450
2025-11-17[VPlan] Populate and use VPIRMetadata from VPInstructions (NFC) (#167253)Florian Hahn
Update VPlan to populate VPIRMetadata during VPInstruction construction and use it when creating widened recipes, instead of constructing VPIRMetadata from the underlying IR instruction each time. This centralizes VPIRMetadata in VPInstructions and ensures metadata is consistently available throughout VPlan transformations. PR: https://github.com/llvm/llvm-project/pull/167253
2025-11-17[VPlan] Replace VPIRMetadata::addMetadata with setMetadata. (NFC)Florian Hahn
Replace addMetadata with setMetadata, which sets metadata, updating existing entries or adding a new entry otherwise. This isn't strictly needed at the moment, but will be needed for follow-up patches.
2025-11-13[VPlan] Add findComputeReductionResult helper. (NFC)Florian Hahn
Move utility to helper for re-use in follow-up patches.
2025-11-11[VPlan] Remove unneeded getDefiningRecipe with isa/cast/dyn_cast. (NFC)Florian Hahn
Classof for most recipes directly supports VPValue, so there is no need to call getDefiningRecipe when using isa/cast/dyn_cast.
2025-11-09[VPlan] Use VPInstructionWithType for casts in VPlan0. (NFC)Florian Hahn
Use VPInstructionWithType for casts in VPlan0, to enable additional analysis/transforms on VPlan0, and more accurate modeling in VPlan0.
2025-11-07[VPlan] Support multiple F(Max|Min)Num reductions. (#161735)Florian Hahn
Generalize handleMaxMinNumReductions to handle any number of F(Max|Min)Num reductions by collecting a vector of reductions to convert. We then add NaN checks for all of them, followed by adjusting the branch controlling the vector loop region, and updating the resume phis. Addresses a TODO from https://github.com/llvm/llvm-project/pull/148239 PR: https://github.com/llvm/llvm-project/pull/161735
2025-11-01[VPlan] Add getConstantInt helpers for constant int creation (NFC).Florian Hahn
Add getConstantInt helper methods to VPlan to simplify the common pattern of creating constant integer live-ins. Suggested as follow-up in https://github.com/llvm/llvm-project/pull/164127.
2025-10-21[VPlan] Clarify naming for helpers to create loop&replicate regions (NFC)Florian Hahn
Split off to clarify naming, as suggested in https://github.com/llvm/llvm-project/pull/156262.
2025-10-15[VPlan] Move getCanonicalIV to VPRegionBlock (NFC). (#163020)Florian Hahn
The canonical IV is tied to region blocks; move getCanonicalIV there and update all users. PR: https://github.com/llvm/llvm-project/pull/163020
2025-10-13[VPlan] Strip VPDT's default constructor (NFC) (#162692)Ramkumar Ramachandra
2025-10-13[VPlan] Allow zero-operand m_BranchOn(Cond|Count) (NFC) (#162721)Ramkumar Ramachandra
2025-10-08[IVDescriptors] Add isFPMinMaxNumRecurrenceKind helper (NFC).Florian Hahn
Add helper to check for FMinNum and FMaxNum recurrence kinds, as suggested in https://github.com/llvm/llvm-project/pull/161735.
2025-10-07[VPlan] Create SCEV expansion for epilogue check first.Florian Hahn
VPExpandSCEVRecipes must be at the beginning of the entry block. addMinimumEpilogueIterationCheck currently creates VPInstructions to compute the remaining iterations before potentially creating VPExpandSCEVRecipes. Fix this by first creating any SCEV expansions if needed. Fixes https://github.com/llvm/llvm-project/issues/162128.
2025-09-25[VPlan] Create epilogue minimum iteration check in VPlan. (#157545)Florian Hahn
Move creation of the minimum iteration check for the epilogue vector loop to VPlan. This is a first step towards breaking up and moving skeleton creation for epilogue vectorization to VPlan. It moves most logic out of EpilogueVectorizerEpilogueLoop: the minimum iteration check is created directly in VPlan, connecting the check blocks from the main vector loop is done as post-processing. Next steps are to move connecting and updating the branches from the check blocks to VPlan, as well as updating the incoming values for phis. Test changes are improvements due to folding of live-ins. PR: https://github.com/llvm/llvm-project/pull/157545
2025-09-08[VPlan] Don't build recipes for unconditional switches (#157323)Luke Lau
In #157322 we crash because we try to infer a type for a VPReplicate switch recipe. My understanding was that these switches should be removed by VPlanPredicator, but this switch survived through it because it was unconditional, i.e. had no cases other than the default case. This fixes #157322 by not emitting any recipes for unconditional switches to begin with, similar to how we treat unconditional branches.
2025-08-26[VPlan] Add VPlan-based addMinIterCheck, replace ILV for non-epilogue. (#153643)Florian Hahn
This patch adds a new VPlan-based addMinimumIterationCheck, which replaced the ILV version for the non-epilogue case. The VPlan-based version constructs a SCEV expression to compute the minimum iterations, use that to check if the check is known true or false. Otherwise it creates a VPExpandSCEV recipe and emits a compare-and-branch. When using epilogue vectorization, we still need to create the minimum trip-count-check during the legacy skeleton creation. The patch moves the definitions out of ILV. PR: https://github.com/llvm/llvm-project/pull/153643
2025-08-25[VPlan] Support scalar VF for ExtractLane and FirstActiveLane.Florian Hahn
Extend ExtractLane and FirstActiveLane to support scalable VFs. This allows correct handling when interleaving with VF = 1. Alive2 proofs: - Fixed codegen with this patch: https://alive2.llvm.org/ce/z/8Y5_Vc (verifies as correct) - Original codegen: https://alive2.llvm.org/ce/z/twdg3X (doesn't verify) Fixes https://github.com/llvm/llvm-project/issues/154967.
2025-08-23[VPlan] Create extracts for live-outs early (NFC).Florian Hahn
Create extracts for live-outs during skeleton construction.
2025-08-21[VPlan] Move SCEV expansion to VPlan transform. (NFCI).Florian Hahn
Move the logic to expand SCEVs directly to a late VPlan transform that expands SCEVs in the entry block. This turns VPExpandSCEVRecipe into an abstract recipe without execute, which clarifies how the recipe is handled, i.e. it is not executed like regular recipes. It also helps to simplify construction, as now scalar evolution isn't required to be passed to the recipe.
2025-08-09[VPlan] Move initial skeleton construction earlier (NFC). (#150848)Florian Hahn
Split up the not clearly named prepareForVectorization transform into buildVPlan0, which adds the vector preheader, middle and scalar preheader blocks, as well as the canonical induction recipes and sets the trip count. The new transform is run directly after building the plain CFG VPlan initially. The remaining code handling early exits and adding the branch in the middle block is renamed to handleEarlyExitsAndAddMiddleCheck and still runs at the original position. With the code movement, we only have to add the skeleton once to the initial VPlan, and cloning will take care of the rest. It will also enable moving other construction steps to work directly on VPlan0, like adding resume phis. PR: https://github.com/llvm/llvm-project/pull/150848
2025-08-06[VPlan] Use scalar VPPhi instead of VPWidenPHIRecipe in createPlainCFG. ↵Florian Hahn
(#150847) The initial VPlan closely reflects the original scalar loop, so unsing VPWidenPHIRecipe here is premature. Widened phi recipes should only be introduced together with other widened recipes. PR: https://github.com/llvm/llvm-project/pull/150847
2025-08-04[VPlan] Add VPlan::getTrue/getFalse convenience helpers (NFC).Florian Hahn
Makes it slightly more convenient to create true/false constants.
2025-08-03[VPlan] handleMaxMinNumReductions - fix gcc Wparentheses warning. NFC.Simon Pilgrim
2025-07-27[VPlan] Add getContext helper to VPlan (NFC).Florian Hahn
2025-07-27[VPlan] Retrieve latch terminator from VPlan. (NFC)Florian Hahn
Remove an unnecessary lookup via original IR loop.
2025-07-27[VPlan] Cast header and latch to VPBasicBlock early (NFC).Florian Hahn
There are only VPBasicBlocks when prepareForVectorization is called. Cast them early instead of having multiple casts later on.
2025-07-26[VPlan] Use terminator debug loc for latch BranchOnCond.Florian Hahn
Update VPlan to consistently use the latch branch debug location for the latch branch in the vector loop, if there is one.
2025-07-21[VPlan] Clarify transform name to handlMaxNumNumReductions. (NFC)Florian Hahn
Clarify name as suggested in https://github.com/llvm/llvm-project/pull/149736, as only FMaxNum and FMinNum are handled.
2025-07-20[VPlan] Remove unused IsReplicator arg from createVPRegionBlock (NFC).Florian Hahn
The argument is always true, remove it.
2025-07-18[Vectorize] Fix a warningKazu Hirata
This patch fixes: llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp:726:13: error: unused variable 'RedPhiRK' [-Werror,-Wunused-variable]
2025-07-18[LV] Vectorize maxnum/minnum w/o fast-math flags. (#148239)Florian Hahn
Update LV to vectorize maxnum/minnum reductions without fast-math flags, by adding an extra check in the loop if any inputs to maxnum/minnum are NaN, due to maxnum/minnum behavior w.r.t to signaling NaNs. Signed-zeros are already handled consistently by maxnum/minnum. If any input is NaN, *exit the vector loop, *compute the reduction result up to the vector iteration that contained NaN inputs and * resume in the scalar loop New recurrence kinds are added for reductions using maxnum/minnum without fast-math flags. PR: https://github.com/llvm/llvm-project/pull/148239
2025-07-16[VPlan] Simplify exituser handling by generating all extracts first(NFCI)Florian Hahn
Simplify the handling of exit users by generating all extracts first (safe option), and have FOR handling optimize the extracts, similar to already done for reductions and inductions. NFC modulo first-order recurrence extract order in middle block.
2025-07-13[VPlan] Move using namespace VPlanPatternMatch to top level (NFC).Florian Hahn
VPlanConstruction.cpp doesn't use IR pattern matching, so using VPlanPatternMatch can be moved to the top-level, to slightly reduce the diff in follow-up changes.
2025-07-09[VPlan] Connect (MemRuntime|SCEV)Check blocks as VPlan transform (NFC). ↵Florian Hahn
(#143879) Connect SCEV and memory runtime check block directly in VPlan as VPIRBasicBlocks, removing ILV::emitSCEVChecks and ILV::emitMemRuntimeChecks. The new logic is currently split across LoopVectorizationPlanner::addRuntimeChecks which collects a list of {Condition, CheckBlock} pairs and performs some checks and emits remarks if needed. The list of checks is then added to VPlan in VPlanTransforms::connectCheckBlocks. PR: https://github.com/llvm/llvm-project/pull/143879
2025-05-31[VPlan] Simplify branch on False in VPlan transform (NFC). (#140409)Florian Hahn
Simplify branch on false, starting with the branch from the middle block to the scalar preheader. Initially this helps simplifying the initial VPlan construction. Depends on https://github.com/llvm/llvm-project/pull/140405. PR: https://github.com/llvm/llvm-project/pull/140409
2025-05-27[VPlan] Connect Entry to scalar preheader during initial construction. (#140132)Florian Hahn
Update initial construction to connect the Plan's entry to the scalar preheader during initial construction. This moves a small part of the skeleton creation out of ILV and will also enable replacing VPInstruction::ResumePhi with regular VPPhi recipes. Resume phis need 2 incoming values to start with, the second being the bypass value from the scalar ph (and used to replicate the incoming value for other bypass blocks). Adding the extra edge ensures we incoming values for resume phis match the incoming blocks. PR: https://github.com/llvm/llvm-project/pull/140132
2025-05-22Reapply "[VPlan] Move predication to VPlanTransform (NFC). (#128420)"Florian Hahn
This reverts commit 793bb6b257fa4d9f4af169a4366cab3da01f2e1f. The recommitted version contains a fix to make sure only the original phis are processed in convertPhisToBlends nu collecting them in a vector first. This fixes a crash when no mask is needed, because there is only a single incoming value. Original message: This patch moves the logic to predicate and linearize a VPlan to a dedicated VPlan transform. It mostly ports the existing logic directly. There are a number of follow-ups planned in the near future to further improve on the implementation: * Edge and block masks are cached in VPPredicator, but the block masks are still made available to VPRecipeBuilder, so they can be accessed during recipe construction. As a follow-up, this should be replaced by adding mask operands to all VPInstructions that need them and use that during recipe construction. * The mask caching in a map also means that this map needs updating each time a new recipe replaces a VPInstruction; this would also be handled by adding mask operands. PR: https://github.com/llvm/llvm-project/pull/128420
2025-05-21Revert "[VPlan] Move predication to VPlanTransform (NFC). (#128420)"Florian Hahn
This reverts commit b263c08e1a0b54a871915930aa9a1a6ba205b099. Looks like this triggers a crash in one of the Fortran tests. Reverting while I investigate https://lab.llvm.org/buildbot/#/builders/41/builds/6825
2025-05-21[VPlan] Move predication to VPlanTransform (NFC). (#128420)Florian Hahn
This patch moves the logic to predicate and linearize a VPlan to a dedicated VPlan transform. It mostly ports the existing logic directly. There are a number of follow-ups planned in the near future to further improve on the implementation: * Edge and block masks are cached in VPPredicator, but the block masks are still made available to VPRecipeBuilder, so they can be accessed during recipe construction. As a follow-up, this should be replaced by adding mask operands to all VPInstructions that need them and use that during recipe construction. * The mask caching in a map also means that this map needs updating each time a new recipe replaces a VPInstruction; this would also be handled by adding mask operands. PR: https://github.com/llvm/llvm-project/pull/128420
2025-05-12[VPlan] Handle early exit before forming regions. (NFC) (#138393)Florian Hahn
Move early-exit handling up front to original VPlan construction, before introducing early exits. This builds on https://github.com/llvm/llvm-project/pull/137709, which adds exiting edges to the original VPlan, instead of adding exit blocks later. This retains the exit conditions early, and means we can handle early exits before forming regions, without the reliance on VPRecipeBuilder. Once we retain all exits initially, handling early exits before region construction ensures the regions are valid; otherwise we would leave edges exiting the region from elsewhere than the latch. Removing the reliance on VPRecipeBuilder removes the dependence on mapping IR BBs to VPBBs and unblocks predication as VPlan transform: https://github.com/llvm/llvm-project/pull/128420. Depends on https://github.com/llvm/llvm-project/pull/137709 (included in PR). PR: https://github.com/llvm/llvm-project/pull/138393
2025-05-10[VPlan] Sink VPB2IRBB lookups to VPRecipeBuilder (NFC).Florian Hahn
This allows migrating some more code to be based on VPBBs in VPRecipeBuilder, in preparation for https://github.com/llvm/llvm-project/pull/128420.
2025-05-08[VPlan] Retain exit conditions and edges in initial VPlan (NFC). (#137709)Florian Hahn
Update initial VPlan construction to include exit conditions and edges. The loop region is now first constructed without entry/exiting. Those are set after inserting the region in the CFG, to preserve the original predecessor/successor order of blocks. For now, all early exits are disconnected before forming the regions, but a follow-up will update uncountable exit handling to also happen here. This is required to enable VPlan predication and remove the dependence any IR BBs (https://github.com/llvm/llvm-project/pull/128420). PR: https://github.com/llvm/llvm-project/pull/137709
2025-05-06[VPlan] Construct regions from innermost to outermost (NFC).Florian Hahn
Flip the region construction order to innermost first from outermost first. This ensures we only set the final parent region for VPBBs once. Split off from https://github.com/llvm/llvm-project/pull/137709.
2025-05-06[VPlan] Remove unneeded checks from PlanCFGBuilder::isExternalDef (NFC).Florian Hahn
Remove checking if the instruction is in the preheader or exit blocks. Those checks are redundant and handled by checking if the instruction is outside the loop below. Split off as suggested from https://github.com/llvm/llvm-project/pull/137709.
2025-05-03Reapply "[VPlan] Add canonical IV during construction (NFC)."Florian Hahn
This reverts commit d431921677ae923d189ff2d6f188f676a2964ed8. Missing gtests have been updated. Original message: This addresses an existing TODO and simply moves the current code to add canonical IV recipes to the initial skeleton construction, at the same place where the corresponding region will be introduced.
2025-04-29Revert "[VPlan] Add canonical IV during construction (NFC)."Florian Hahn
This reverts commit e17122fffa8d233fcf9f717354ecda46173f1b8d. Revert as this seems to break some unit tests on some bots.
2025-04-29[VPlan] Add canonical IV during construction (NFC).Florian Hahn
This addresses an existing TODO and simply moves the current code to add canonical IV recipes to the initial skeleton construction, at the same place where the corresponding region will be introduced.
2025-04-28[VPlan] Create initial skeleton before creating regions. (NFC)Florian Hahn
Move out the logic to prepare for vectorization to a separate transform, before creating loop regions. This was discussed as follow-up in https://github.com/llvm/llvm-project/pull/136455. This just moves the existing code around slightly and will simplify follow-up patches to include the exiting edges during initial VPlan construction.