LLVM 23.0.0git
VPlanTransforms.h
Go to the documentation of this file.
1//===- VPlanTransforms.h - Utility VPlan to VPlan transforms --------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file provides utility VPlan to VPlan transformations.
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_TRANSFORMS_VECTORIZE_VPLANTRANSFORMS_H
14#define LLVM_TRANSFORMS_VECTORIZE_VPLANTRANSFORMS_H
15
16#include "VPlan.h"
17#include "VPlanVerifier.h"
21
22namespace llvm {
23
25class Instruction;
26class LoopVersioning;
27class PHINode;
28class ScalarEvolution;
31class VPBuilder;
32class VPRecipeBuilder;
33struct VFRange;
34
37
39 /// Helper to run a VPlan transform \p Transform on \p VPlan, forwarding extra
40 /// arguments to the transform. Returns the boolean returned by the transform.
41 template <typename... ArgsTy>
42 static bool runPass(bool (*Transform)(VPlan &, ArgsTy...), VPlan &Plan,
43 typename std::remove_reference<ArgsTy>::type &...Args) {
44 bool Res = Transform(Plan, Args...);
47 return Res;
48 }
49 /// Helper to run a VPlan transform \p Transform on \p VPlan, forwarding extra
50 /// arguments to the transform.
51 template <typename... ArgsTy>
52 static void runPass(void (*Fn)(VPlan &, ArgsTy...), VPlan &Plan,
53 typename std::remove_reference<ArgsTy>::type &...Args) {
54 Fn(Plan, Args...);
57 }
58
59 /// Create a base VPlan0, serving as the common starting point for all later
60 /// candidates. It consists of an initial plain CFG loop with loop blocks from
61 /// \p TheLoop being directly translated to VPBasicBlocks with VPInstruction
62 /// corresponding to the input IR.
63 ///
64 /// The created loop is wrapped in an initial skeleton to facilitate
65 /// vectorization, consisting of a vector pre-header, an exit block for the
66 /// main vector loop (middle.block) and a new block as preheader of the scalar
67 /// loop (scalar.ph). See below for an illustration. It also adds a canonical
68 /// IV and its increment, using \p InductionTy and \p IVDL, and creates a
69 /// VPValue expression for the original trip count.
70 ///
71 /// [ ] <-- Plan's entry VPIRBasicBlock, wrapping the original loop's
72 /// / \ old preheader. Will contain iteration number check and SCEV
73 /// | | expansions.
74 /// | |
75 /// / v
76 /// | [ ] <-- vector loop bypass (may consist of multiple blocks) will be
77 /// | / | added later.
78 /// | / v
79 /// || [ ] <-- vector pre header.
80 /// |/ |
81 /// | v
82 /// | [ ] \ <-- plain CFG loop wrapping original loop to be vectorized.
83 /// | [ ]_|
84 /// | |
85 /// | v
86 /// | [ ] <--- middle-block with the branch to successors
87 /// | / |
88 /// | / |
89 /// | | v
90 /// \--->[ ] <--- scalar preheader (initial a VPBasicBlock, which will be
91 /// | | replaced later by a VPIRBasicBlock wrapping the scalar
92 /// | | preheader basic block.
93 /// | |
94 /// v <-- edge from middle to exit iff epilogue is not required.
95 /// | [ ] \
96 /// | [ ]_| <-- old scalar loop to handle remainder (scalar epilogue,
97 /// | | header wrapped in VPIRBasicBlock).
98 /// \ |
99 /// \ v
100 /// >[ ] <-- original loop exit block(s), wrapped in VPIRBasicBlocks.
101 LLVM_ABI_FOR_TEST static std::unique_ptr<VPlan>
102 buildVPlan0(Loop *TheLoop, LoopInfo &LI, Type *InductionTy, DebugLoc IVDL,
103 PredicatedScalarEvolution &PSE, LoopVersioning *LVer = nullptr);
104
105 /// Replace VPPhi recipes in \p Plan's header with corresponding
106 /// VPHeaderPHIRecipe subclasses for inductions, reductions, and
107 /// fixed-order recurrences. This processes all header phis and creates
108 /// the appropriate widened recipe for each one.
109 static void createHeaderPhiRecipes(
110 VPlan &Plan, PredicatedScalarEvolution &PSE, Loop &OrigLoop,
113 const SmallPtrSetImpl<const PHINode *> &FixedOrderRecurrences,
114 const SmallPtrSetImpl<PHINode *> &InLoopReductions, bool AllowReordering);
115
116 /// Create VPReductionRecipes for in-loop reductions. This processes chains
117 /// of operations contributing to in-loop reductions and creates appropriate
118 /// VPReductionRecipe instances. Block masks from \p BlockMaskCache are used
119 /// to add predication for blocks in \p BlocksNeedingPredication.
121 VPlan &Plan, const DenseMap<VPBasicBlock *, VPValue *> &BlockMaskCache,
122 const DenseSet<BasicBlock *> &BlocksNeedingPredication,
123 ElementCount MinVF);
124
125 /// Update \p Plan to account for all early exits.
126 LLVM_ABI_FOR_TEST static void handleEarlyExits(VPlan &Plan,
127 bool HasUncountableExit);
128
129 /// If a check is needed to guard executing the scalar epilogue loop, it will
130 /// be added to the middle block.
131 LLVM_ABI_FOR_TEST static void addMiddleCheck(VPlan &Plan,
132 bool RequiresScalarEpilogueCheck,
133 bool TailFolded);
134
135 // Create a check to \p Plan to see if the vector loop should be executed.
136 static void
137 addMinimumIterationCheck(VPlan &Plan, ElementCount VF, unsigned UF,
138 ElementCount MinProfitableTripCount,
139 bool RequiresScalarEpilogue, bool TailFolded,
140 bool CheckNeededWithTailFolding, Loop *OrigLoop,
143
144 /// Add a check to \p Plan to see if the epilogue vector loop should be
145 /// executed.
147 VPlan &Plan, Value *TripCount, Value *VectorTripCount,
148 bool RequiresScalarEpilogue, ElementCount EpilogueVF, unsigned EpilogueUF,
149 unsigned MainLoopStep, unsigned EpilogueLoopStep, ScalarEvolution &SE);
150
151 /// Replace loops in \p Plan's flat CFG with VPRegionBlocks, turning \p Plan's
152 /// flat CFG into a hierarchical CFG.
153 LLVM_ABI_FOR_TEST static void createLoopRegions(VPlan &Plan);
154
155 /// Wrap runtime check block \p CheckBlock in a VPIRBB and \p Cond in a
156 /// VPValue and connect the block to \p Plan, using the VPValue as branch
157 /// condition.
158 static void attachCheckBlock(VPlan &Plan, Value *Cond, BasicBlock *CheckBlock,
159 bool AddBranchWeights);
160
161 /// Replaces the VPInstructions in \p Plan with corresponding
162 /// widen recipes. Returns false if any VPInstructions could not be converted
163 /// to a wide recipe if needed.
164 LLVM_ABI_FOR_TEST static bool
166 const TargetLibraryInfo &TLI);
167
168 /// Try to legalize reductions with multiple in-loop uses. Currently only
169 /// min/max reductions used by FindLastIV reductions are supported. Otherwise
170 /// return false.
171 static bool handleMultiUseReductions(VPlan &Plan);
172
173 /// Try to have all users of fixed-order recurrences appear after the recipe
174 /// defining their previous value, by either sinking users or hoisting recipes
175 /// defining their previous value (and its operands). Then introduce
176 /// FirstOrderRecurrenceSplice VPInstructions to combine the value from the
177 /// recurrence phis and previous values.
178 /// \returns true if all users of fixed-order recurrences could be re-arranged
179 /// as needed or false if it is not possible. In the latter case, \p Plan is
180 /// not valid.
181 static bool adjustFixedOrderRecurrences(VPlan &Plan, VPBuilder &Builder);
182
183 /// Check if \p Plan contains any FMaxNum or FMinNum reductions. If they do,
184 /// try to update the vector loop to exit early if any input is NaN and resume
185 /// executing in the scalar loop to handle the NaNs there. Return false if
186 /// this attempt was unsuccessful.
187 static bool handleMaxMinNumReductions(VPlan &Plan);
188
189 /// Check if \p Plan contains any FindLast reductions. If it does, try to
190 /// update the vector loop to save the appropriate state using selects
191 /// for entire vectors for both the latest mask containing at least one active
192 /// element and the corresponding data vector. Return false if this attempt
193 /// was unsuccessful.
194 static bool handleFindLastReductions(VPlan &Plan);
195
196 /// Clear NSW/NUW flags from reduction instructions if necessary.
197 static void clearReductionWrapFlags(VPlan &Plan);
198
199 /// Explicitly unroll \p Plan by \p UF.
200 static void unrollByUF(VPlan &Plan, unsigned UF);
201
202 /// Replace each replicating VPReplicateRecipe and VPInstruction outside of
203 /// any replicate region in \p Plan with \p VF single-scalar recipes.
204 /// TODO: Also replicate VPScalarIVSteps and VPReplicateRecipes inside
205 /// replicate regions, thereby dissolving the latter.
206 static void replicateByVF(VPlan &Plan, ElementCount VF);
207
208 /// Optimize \p Plan based on \p BestVF and \p BestUF. This may restrict the
209 /// resulting plan to \p BestVF and \p BestUF.
210 static void optimizeForVFAndUF(VPlan &Plan, ElementCount BestVF,
211 unsigned BestUF,
213
214 /// Apply VPlan-to-VPlan optimizations to \p Plan, including induction recipe
215 /// optimizations, dead recipe removal, replicate region optimizations and
216 /// block merging.
217 LLVM_ABI_FOR_TEST static void optimize(VPlan &Plan);
218
219 /// Wrap predicated VPReplicateRecipes with a mask operand in an if-then
220 /// region block and remove the mask operand. Optimize the created regions by
221 /// iteratively sinking scalar operands into the region, followed by merging
222 /// regions until no improvements are remaining.
223 static void createAndOptimizeReplicateRegions(VPlan &Plan);
224
225 /// Replace (ICMP_ULE, wide canonical IV, backedge-taken-count) checks with an
226 /// (active-lane-mask recipe, wide canonical IV, trip-count). If \p
227 /// UseActiveLaneMaskForControlFlow is true, introduce an
228 /// VPActiveLaneMaskPHIRecipe. If \p DataAndControlFlowWithoutRuntimeCheck is
229 /// true, no minimum-iteration runtime check will be created (during skeleton
230 /// creation) and instead it is handled using active-lane-mask. \p
231 /// DataAndControlFlowWithoutRuntimeCheck implies \p
232 /// UseActiveLaneMaskForControlFlow.
233 static void addActiveLaneMask(VPlan &Plan,
234 bool UseActiveLaneMaskForControlFlow,
236
237 /// Insert truncates and extends for any truncated recipe. Redundant casts
238 /// will be folded later.
239 static void
242
243 /// Replace symbolic strides from \p StridesMap in \p Plan with constants when
244 /// possible.
245 static void
247 const DenseMap<Value *, const SCEV *> &StridesMap);
248
249 /// Drop poison flags from recipes that may generate a poison value that is
250 /// used after vectorization, even when their operands are not poison. Those
251 /// recipes meet the following conditions:
252 /// * Contribute to the address computation of a recipe generating a widen
253 /// memory load/store (VPWidenMemoryInstructionRecipe or
254 /// VPInterleaveRecipe).
255 /// * Such a widen memory load/store has at least one underlying Instruction
256 /// that is in a basic block that needs predication and after vectorization
257 /// the generated instruction won't be predicated.
258 /// Uses \p BlockNeedsPredication to check if a block needs predicating.
259 /// TODO: Replace BlockNeedsPredication callback with retrieving info from
260 /// VPlan directly.
261 static void dropPoisonGeneratingRecipes(
262 VPlan &Plan,
263 const std::function<bool(BasicBlock *)> &BlockNeedsPredication);
264
265 /// Add a VPEVLBasedIVPHIRecipe and related recipes to \p Plan and
266 /// replaces all uses except the canonical IV increment of
267 /// VPCanonicalIVPHIRecipe with a VPEVLBasedIVPHIRecipe.
268 /// VPCanonicalIVPHIRecipe is only used to control the loop after
269 /// this transformation.
270 static void
272 const std::optional<unsigned> &MaxEVLSafeElements);
273
274 /// Optimize recipes which use an EVL-based header mask to VP intrinsics, for
275 /// example:
276 ///
277 /// %mask = icmp ult step-vector, EVL
278 /// %load = load %ptr, %mask
279 /// -->
280 /// %load = vp.load %ptr, EVL
281 static void optimizeEVLMasks(VPlan &Plan);
282
283 // For each Interleave Group in \p InterleaveGroups replace the Recipes
284 // widening its memory instructions with a single VPInterleaveRecipe at its
285 // insertion point.
286 static void createInterleaveGroups(
287 VPlan &Plan,
289 &InterleaveGroups,
290 VPRecipeBuilder &RecipeBuilder, const bool &ScalarEpilogueAllowed);
291
292 /// Remove dead recipes from \p Plan.
293 static void removeDeadRecipes(VPlan &Plan);
294
295 /// Update \p Plan to account for the uncountable early exit from \p
296 /// EarlyExitingVPBB to \p EarlyExitVPBB by introducing a BranchOnTwoConds
297 /// terminator in the latch that handles the early exit and the latch exit
298 /// condition.
299 static void handleUncountableEarlyExit(VPBasicBlock *EarlyExitingVPBB,
300 VPBasicBlock *EarlyExitVPBB,
301 VPlan &Plan, VPBasicBlock *HeaderVPBB,
302 VPBasicBlock *LatchVPBB);
303
304 /// Replace loop regions with explicit CFG.
305 static void dissolveLoopRegions(VPlan &Plan);
306
307 /// Expand BranchOnTwoConds instructions into explicit CFG with
308 /// BranchOnCond instructions. Should be called after dissolveLoopRegions.
309 static void expandBranchOnTwoConds(VPlan &Plan);
310
311 /// Transform EVL loops to use variable-length stepping after region
312 /// dissolution.
313 ///
314 /// Once loop regions are replaced with explicit CFG, EVL loops can step with
315 /// variable vector lengths instead of fixed lengths. This transformation:
316 /// * Makes EVL-Phi concrete.
317 // * Removes CanonicalIV and increment.
318 /// * Replaces the exit condition from
319 /// (branch-on-count CanonicalIVInc, VectorTripCount)
320 /// to
321 /// (branch-on-cond eq AVLNext, 0)
322 static void canonicalizeEVLLoops(VPlan &Plan);
323
324 /// Lower abstract recipes to concrete ones, that can be codegen'd.
325 static void convertToConcreteRecipes(VPlan &Plan);
326
327 /// This function converts initial recipes to the abstract recipes and clamps
328 /// \p Range based on cost model for following optimizations and cost
329 /// estimations. The converted abstract recipes will lower to concrete
330 /// recipes before codegen.
331 static void convertToAbstractRecipes(VPlan &Plan, VPCostContext &Ctx,
332 VFRange &Range);
333
334 /// Perform instcombine-like simplifications on recipes in \p Plan.
335 static void simplifyRecipes(VPlan &Plan);
336
337 /// Remove BranchOnCond recipes with true or false conditions together with
338 /// removing dead edges to their successors.
339 static void removeBranchOnConst(VPlan &Plan);
340
341 /// Perform common-subexpression-elimination on \p Plan.
342 static void cse(VPlan &Plan);
343
344 /// If there's a single exit block, optimize its phi recipes that use exiting
345 /// IV values by feeding them precomputed end values instead, possibly taken
346 /// one step backwards.
347 static void
351
352 /// Add explicit broadcasts for live-ins and VPValues defined in \p Plan's entry block if they are used as vectors.
353 static void materializeBroadcasts(VPlan &Plan);
354
355 /// Hoist single-scalar loads with invariant addresses out of the vector loop
356 /// to the preheader, if they are proven not to alias with any stores in the
357 /// plan using noalias metadata.
358 static void hoistInvariantLoads(VPlan &Plan);
359
360 /// Hoist predicated loads from the same address to the loop entry block, if
361 /// they are guaranteed to execute on both paths (i.e., in replicate regions
362 /// with complementary masks P and NOT P).
364 const Loop *L);
365
366 /// Sink predicated stores to the same address with complementary predicates
367 /// (P and NOT P) to an unconditional store with select recipes for the
368 /// stored values. This eliminates branching overhead when all paths
369 /// unconditionally store to the same location.
371 const Loop *L);
372
373 // Materialize vector trip counts for constants early if it can simply be
374 // computed as (Original TC / VF * UF) * VF * UF.
375 static void
377 unsigned BestUF,
379
380 /// Materialize vector trip count computations to a set of VPInstructions.
381 static void materializeVectorTripCount(VPlan &Plan,
382 VPBasicBlock *VectorPHVPBB,
383 bool TailByMasking,
384 bool RequiresScalarEpilogue);
385
386 /// Materialize the backedge-taken count to be computed explicitly using
387 /// VPInstructions.
388 static void materializeBackedgeTakenCount(VPlan &Plan,
389 VPBasicBlock *VectorPH);
390
391 /// Add explicit Build[Struct]Vector recipes to Pack multiple scalar values
392 /// into vectors and Unpack recipes to extract scalars from vectors as
393 /// needed.
394 static void materializePacksAndUnpacks(VPlan &Plan);
395
396 /// Materialize VF and VFxUF to be computed explicitly using VPInstructions.
397 static void materializeVFAndVFxUF(VPlan &Plan, VPBasicBlock *VectorPH,
398 ElementCount VF);
399
400 /// Expand VPExpandSCEVRecipes in \p Plan's entry block. Each
401 /// VPExpandSCEVRecipe is replaced with a live-in wrapping the expanded IR
402 /// value. A mapping from SCEV expressions to their expanded IR value is
403 /// returned.
405 ScalarEvolution &SE);
406
407 /// Try to convert a plan with interleave groups with VF elements to a plan
408 /// with the interleave groups replaced by wide loads and stores processing VF
409 /// elements, if all transformed interleave groups access the full vector
410 /// width (checked via \o VectorRegWidth). This effectively is a very simple
411 /// form of loop-aware SLP, where we use interleave groups to identify
412 /// candidates.
413 static void narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
414 TypeSize VectorRegWidth);
415
416 /// Predicate and linearize the control-flow in the only loop region of
417 /// \p Plan. If \p FoldTail is true, create a mask guarding the loop
418 /// header, otherwise use all-true for the header mask. Masks for blocks are
419 /// added to a block-to-mask map which is returned in order to be used later
420 /// for wide recipe construction. This argument is temporary and will be
421 /// removed in the future.
423 introduceMasksAndLinearize(VPlan &Plan, bool FoldTail);
424
425 /// Add branch weight metadata, if the \p Plan's middle block is terminated by
426 /// a BranchOnCond recipe.
427 static void
429 std::optional<unsigned> VScaleForTuning);
430
431 /// Update the resume phis in the scalar preheader after creating wide recipes
432 /// for first-order recurrences, reductions and inductions. End values for
433 /// inductions are added to \p IVEndValues.
434 static void
436 DenseMap<VPValue *, VPValue *> &IVEndValues);
437
438 /// Handle users in the exit block for first order reductions in the original
439 /// exit block. The penultimate value of recurrences is fed to their LCSSA phi
440 /// users in the original exit block using the VPIRInstruction wrapping to the
441 /// LCSSA phi.
443};
444
445} // namespace llvm
446
447#endif // LLVM_TRANSFORMS_VECTORIZE_VPLANTRANSFORMS_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_ABI_FOR_TEST
Definition Compiler.h:218
static constexpr uint32_t MinItersBypassWeights[]
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
const SmallVectorImpl< MachineOperand > & Cond
This file declares the class VPlanVerifier, which contains utility functions to check the consistency...
This file contains the declarations of the Vectorization Plan base classes:
LLVM Basic Block Representation.
Definition BasicBlock.h:62
A debug info location.
Definition DebugLoc.h:123
Implements a dense probed hash-table based set.
Definition DenseSet.h:279
A struct for saving information about induction variables.
The group of interleaved loads/stores sharing the same stride and close to each other.
This class emits a version of the loop where run-time checks ensure that may-alias pointers can't ove...
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
This class implements a map that also provides access to all stored values in a deterministic order.
Definition MapVector.h:36
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
The main scalar evolution driver.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Provides information about what library functions are available for the current target.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition VPlan.h:4009
VPlan-based builder utility analogous to IRBuilder.
Helper class to create VPRecipies from IR instructions.
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition VPlan.h:4327
LLVM Value Representation.
Definition Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
LLVM_ABI_FOR_TEST cl::opt< bool > VerifyEachVPlan
LLVM_ABI_FOR_TEST bool verifyVPlanIsValid(const VPlan &Plan, bool VerifyLate=false)
Verify invariants for general VPlans.
LLVM_ABI_FOR_TEST cl::opt< bool > EnableWideActiveLaneMask
@ DataAndControlFlowWithoutRuntimeCheck
Use predicate to control both data and control flow, but modify the trip count so that a runtime over...
A range of powers-of-2 vectorization factors with fixed start and adjustable end.
Struct to hold various analysis needed for cost computations.
static LLVM_ABI_FOR_TEST bool tryToConvertVPInstructionsToVPRecipes(VPlan &Plan, const TargetLibraryInfo &TLI)
Replaces the VPInstructions in Plan with corresponding widen recipes.
static void materializeBroadcasts(VPlan &Plan)
Add explicit broadcasts for live-ins and VPValues defined in Plan's entry block if they are used as v...
static void materializePacksAndUnpacks(VPlan &Plan)
Add explicit Build[Struct]Vector recipes to Pack multiple scalar values into vectors and Unpack recip...
static bool handleMultiUseReductions(VPlan &Plan)
Try to legalize reductions with multiple in-loop uses.
static LLVM_ABI_FOR_TEST std::unique_ptr< VPlan > buildVPlan0(Loop *TheLoop, LoopInfo &LI, Type *InductionTy, DebugLoc IVDL, PredicatedScalarEvolution &PSE, LoopVersioning *LVer=nullptr)
Create a base VPlan0, serving as the common starting point for all later candidates.
static void optimizeInductionExitUsers(VPlan &Plan, DenseMap< VPValue *, VPValue * > &EndValues, PredicatedScalarEvolution &PSE)
If there's a single exit block, optimize its phi recipes that use exiting IV values by feeding them p...
static void materializeBackedgeTakenCount(VPlan &Plan, VPBasicBlock *VectorPH)
Materialize the backedge-taken count to be computed explicitly using VPInstructions.
static void hoistInvariantLoads(VPlan &Plan)
Hoist single-scalar loads with invariant addresses out of the vector loop to the preheader,...
static LLVM_ABI_FOR_TEST void handleEarlyExits(VPlan &Plan, bool HasUncountableExit)
Update Plan to account for all early exits.
static void canonicalizeEVLLoops(VPlan &Plan)
Transform EVL loops to use variable-length stepping after region dissolution.
static void createInLoopReductionRecipes(VPlan &Plan, const DenseMap< VPBasicBlock *, VPValue * > &BlockMaskCache, const DenseSet< BasicBlock * > &BlocksNeedingPredication, ElementCount MinVF)
Create VPReductionRecipes for in-loop reductions.
static void dropPoisonGeneratingRecipes(VPlan &Plan, const std::function< bool(BasicBlock *)> &BlockNeedsPredication)
Drop poison flags from recipes that may generate a poison value that is used after vectorization,...
static void addMinimumIterationCheck(VPlan &Plan, ElementCount VF, unsigned UF, ElementCount MinProfitableTripCount, bool RequiresScalarEpilogue, bool TailFolded, bool CheckNeededWithTailFolding, Loop *OrigLoop, const uint32_t *MinItersBypassWeights, DebugLoc DL, PredicatedScalarEvolution &PSE)
static void createAndOptimizeReplicateRegions(VPlan &Plan)
Wrap predicated VPReplicateRecipes with a mask operand in an if-then region block and remove the mask...
static void createInterleaveGroups(VPlan &Plan, const SmallPtrSetImpl< const InterleaveGroup< Instruction > * > &InterleaveGroups, VPRecipeBuilder &RecipeBuilder, const bool &ScalarEpilogueAllowed)
static bool runPass(bool(*Transform)(VPlan &, ArgsTy...), VPlan &Plan, typename std::remove_reference< ArgsTy >::type &...Args)
Helper to run a VPlan transform Transform on VPlan, forwarding extra arguments to the transform.
static void addBranchWeightToMiddleTerminator(VPlan &Plan, ElementCount VF, std::optional< unsigned > VScaleForTuning)
Add branch weight metadata, if the Plan's middle block is terminated by a BranchOnCond recipe.
static bool handleFindLastReductions(VPlan &Plan)
Check if Plan contains any FindLast reductions.
static void narrowInterleaveGroups(VPlan &Plan, ElementCount VF, TypeSize VectorRegWidth)
Try to convert a plan with interleave groups with VF elements to a plan with the interleave groups re...
static void unrollByUF(VPlan &Plan, unsigned UF)
Explicitly unroll Plan by UF.
static DenseMap< const SCEV *, Value * > expandSCEVs(VPlan &Plan, ScalarEvolution &SE)
Expand VPExpandSCEVRecipes in Plan's entry block.
static void convertToConcreteRecipes(VPlan &Plan)
Lower abstract recipes to concrete ones, that can be codegen'd.
static void runPass(void(*Fn)(VPlan &, ArgsTy...), VPlan &Plan, typename std::remove_reference< ArgsTy >::type &...Args)
Helper to run a VPlan transform Transform on VPlan, forwarding extra arguments to the transform.
static void expandBranchOnTwoConds(VPlan &Plan)
Expand BranchOnTwoConds instructions into explicit CFG with BranchOnCond instructions.
static void hoistPredicatedLoads(VPlan &Plan, PredicatedScalarEvolution &PSE, const Loop *L)
Hoist predicated loads from the same address to the loop entry block, if they are guaranteed to execu...
static void convertToAbstractRecipes(VPlan &Plan, VPCostContext &Ctx, VFRange &Range)
This function converts initial recipes to the abstract recipes and clamps Range based on cost model f...
static void materializeConstantVectorTripCount(VPlan &Plan, ElementCount BestVF, unsigned BestUF, PredicatedScalarEvolution &PSE)
static void addExitUsersForFirstOrderRecurrences(VPlan &Plan, VFRange &Range)
Handle users in the exit block for first order reductions in the original exit block.
static void createHeaderPhiRecipes(VPlan &Plan, PredicatedScalarEvolution &PSE, Loop &OrigLoop, const MapVector< PHINode *, InductionDescriptor > &Inductions, const MapVector< PHINode *, RecurrenceDescriptor > &Reductions, const SmallPtrSetImpl< const PHINode * > &FixedOrderRecurrences, const SmallPtrSetImpl< PHINode * > &InLoopReductions, bool AllowReordering)
Replace VPPhi recipes in Plan's header with corresponding VPHeaderPHIRecipe subclasses for inductions...
static DenseMap< VPBasicBlock *, VPValue * > introduceMasksAndLinearize(VPlan &Plan, bool FoldTail)
Predicate and linearize the control-flow in the only loop region of Plan.
static void addExplicitVectorLength(VPlan &Plan, const std::optional< unsigned > &MaxEVLSafeElements)
Add a VPEVLBasedIVPHIRecipe and related recipes to Plan and replaces all uses except the canonical IV...
static void optimizeEVLMasks(VPlan &Plan)
Optimize recipes which use an EVL-based header mask to VP intrinsics, for example:
static void replaceSymbolicStrides(VPlan &Plan, PredicatedScalarEvolution &PSE, const DenseMap< Value *, const SCEV * > &StridesMap)
Replace symbolic strides from StridesMap in Plan with constants when possible.
static bool handleMaxMinNumReductions(VPlan &Plan)
Check if Plan contains any FMaxNum or FMinNum reductions.
static void removeBranchOnConst(VPlan &Plan)
Remove BranchOnCond recipes with true or false conditions together with removing dead edges to their ...
static LLVM_ABI_FOR_TEST void createLoopRegions(VPlan &Plan)
Replace loops in Plan's flat CFG with VPRegionBlocks, turning Plan's flat CFG into a hierarchical CFG...
static void removeDeadRecipes(VPlan &Plan)
Remove dead recipes from Plan.
static void attachCheckBlock(VPlan &Plan, Value *Cond, BasicBlock *CheckBlock, bool AddBranchWeights)
Wrap runtime check block CheckBlock in a VPIRBB and Cond in a VPValue and connect the block to Plan,...
static void materializeVectorTripCount(VPlan &Plan, VPBasicBlock *VectorPHVPBB, bool TailByMasking, bool RequiresScalarEpilogue)
Materialize vector trip count computations to a set of VPInstructions.
static void simplifyRecipes(VPlan &Plan)
Perform instcombine-like simplifications on recipes in Plan.
static void sinkPredicatedStores(VPlan &Plan, PredicatedScalarEvolution &PSE, const Loop *L)
Sink predicated stores to the same address with complementary predicates (P and NOT P) to an uncondit...
static void handleUncountableEarlyExit(VPBasicBlock *EarlyExitingVPBB, VPBasicBlock *EarlyExitVPBB, VPlan &Plan, VPBasicBlock *HeaderVPBB, VPBasicBlock *LatchVPBB)
Update Plan to account for the uncountable early exit from EarlyExitingVPBB to EarlyExitVPBB by intro...
static void replicateByVF(VPlan &Plan, ElementCount VF)
Replace each replicating VPReplicateRecipe and VPInstruction outside of any replicate region in Plan ...
static void clearReductionWrapFlags(VPlan &Plan)
Clear NSW/NUW flags from reduction instructions if necessary.
static void cse(VPlan &Plan)
Perform common-subexpression-elimination on Plan.
static void addActiveLaneMask(VPlan &Plan, bool UseActiveLaneMaskForControlFlow, bool DataAndControlFlowWithoutRuntimeCheck)
Replace (ICMP_ULE, wide canonical IV, backedge-taken-count) checks with an (active-lane-mask recipe,...
static LLVM_ABI_FOR_TEST void optimize(VPlan &Plan)
Apply VPlan-to-VPlan optimizations to Plan, including induction recipe optimizations,...
static void dissolveLoopRegions(VPlan &Plan)
Replace loop regions with explicit CFG.
static void truncateToMinimalBitwidths(VPlan &Plan, const MapVector< Instruction *, uint64_t > &MinBWs)
Insert truncates and extends for any truncated recipe.
static bool adjustFixedOrderRecurrences(VPlan &Plan, VPBuilder &Builder)
Try to have all users of fixed-order recurrences appear after the recipe defining their previous valu...
static void optimizeForVFAndUF(VPlan &Plan, ElementCount BestVF, unsigned BestUF, PredicatedScalarEvolution &PSE)
Optimize Plan based on BestVF and BestUF.
static void materializeVFAndVFxUF(VPlan &Plan, VPBasicBlock *VectorPH, ElementCount VF)
Materialize VF and VFxUF to be computed explicitly using VPInstructions.
static void addMinimumVectorEpilogueIterationCheck(VPlan &Plan, Value *TripCount, Value *VectorTripCount, bool RequiresScalarEpilogue, ElementCount EpilogueVF, unsigned EpilogueUF, unsigned MainLoopStep, unsigned EpilogueLoopStep, ScalarEvolution &SE)
Add a check to Plan to see if the epilogue vector loop should be executed.
static void updateScalarResumePhis(VPlan &Plan, DenseMap< VPValue *, VPValue * > &IVEndValues)
Update the resume phis in the scalar preheader after creating wide recipes for first-order recurrence...
static LLVM_ABI_FOR_TEST void addMiddleCheck(VPlan &Plan, bool RequiresScalarEpilogueCheck, bool TailFolded)
If a check is needed to guard executing the scalar epilogue loop, it will be added to the middle bloc...