LLVM 24.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"
19#include "llvm/ADT/ScopeExit.h"
23#include "llvm/Support/Regex.h"
24
25namespace llvm {
26
29class Instruction;
30class Loop;
31class LoopVersioning;
33class PHINode;
34class ScalarEvolution;
38class VPRecipeBuilder;
39struct VFRange;
40
42
43#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
49#endif
50
52 /// Helper to run a VPlan pass \p Pass on \p VPlan, forwarding extra arguments
53 /// to the pass. Performs verification/printing after each VPlan pass if
54 /// requested via command line options.
55 template <bool EnableVerify = true, typename PassTy, typename... ArgsTy>
56 static decltype(auto) runPass(StringRef PassName, PassTy &&Pass, VPlan &Plan,
57 ArgsTy &&...Args) {
58#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
59 static DenseMap<std::pair<Function *, StringRef /* Pass */>, unsigned>
60 PassCounter;
62 // Computing these is expensive, so only do it if any VPlan printing has
63 // been requested.
64 unsigned Instance;
65 std::string NumberedPassName;
66
68 !VPlanPrintBeforePasses.empty() || !VPlanPrintAfterPasses.empty()) {
69 Instance = ++PassCounter[{Fn, PassName}];
70
71 NumberedPassName = Instance == 1
72 ? PassName.str()
73 : (PassName + "@" + Twine(Instance)).str();
74 }
75
76 auto PrintPlan = [&](StringRef BeforeOrAfterStr) {
77 dbgs() << "VPlan for loop in '" << Fn->getName() << "' "
78 << BeforeOrAfterStr << " " << NumberedPassName << '\n';
81 else
82 dbgs() << Plan << '\n';
83 };
84
85 auto MatchesPassListOption = [&](const cl::list<std::string> &ListOpt) {
86 return (ListOpt.getNumOccurrences() > 0 &&
87 any_of(ListOpt, [&](StringRef Entry) {
88 return Regex(Entry).match(NumberedPassName);
89 }));
90 };
91
92 if (VPlanPrintBeforeAll || MatchesPassListOption(VPlanPrintBeforePasses))
93 PrintPlan("before");
94#endif
95
96 scope_exit PostTransformActions{[&]() {
97#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
98 // Make sure to print before verification, so that output is more useful
99 // in case of failures:
100 if (VPlanPrintAfterAll || MatchesPassListOption(VPlanPrintAfterPasses))
101 PrintPlan("after");
102#endif
103 if (VerifyEachVPlan && EnableVerify) {
104 if (!verifyVPlanIsValid(Plan))
105 report_fatal_error("Broken VPlan found, compilation aborted!");
106 }
107 }};
108
109 return std::forward<PassTy>(Pass)(Plan, std::forward<ArgsTy>(Args)...);
110 }
111#define RUN_VPLAN_PASS(PASS, ...) \
112 llvm::VPlanTransforms::runPass(#PASS, PASS, __VA_ARGS__)
113#define RUN_VPLAN_PASS_NO_VERIFY(PASS, ...) \
114 llvm::VPlanTransforms::runPass<false>(#PASS, PASS, __VA_ARGS__)
115
116 /// Create a base VPlan0, serving as the common starting point for all later
117 /// candidates. It consists of an initial plain CFG loop with loop blocks from
118 /// \p TheLoop being directly translated to VPBasicBlocks with VPInstruction
119 /// corresponding to the input IR.
120 ///
121 /// The created loop is wrapped in an initial skeleton to facilitate
122 /// vectorization, consisting of a vector pre-header, an exit block for the
123 /// main vector loop (middle.block) and a new block as preheader of the scalar
124 /// loop (scalar.ph). See below for an illustration. It also creates a
125 /// VPValue expression for the original trip count.
126 ///
127 /// [ ] <-- Plan's entry VPIRBasicBlock, wrapping the original loop's
128 /// / \ old preheader. Will contain iteration number check and SCEV
129 /// | | expansions.
130 /// | |
131 /// / v
132 /// | [ ] <-- vector loop bypass (may consist of multiple blocks) will be
133 /// | / | added later.
134 /// | / v
135 /// || [ ] <-- vector pre header.
136 /// |/ |
137 /// | v
138 /// | [ ] \ <-- plain CFG loop wrapping original loop to be vectorized.
139 /// | [ ]_|
140 /// | |
141 /// | v
142 /// | [ ] <--- middle-block with the branch to successors
143 /// | / |
144 /// | / |
145 /// | | v
146 /// \--->[ ] <--- scalar preheader (initial a VPBasicBlock, which will be
147 /// | | replaced later by a VPIRBasicBlock wrapping the scalar
148 /// | | preheader basic block.
149 /// | |
150 /// v <-- edge from middle to exit iff epilogue is not required.
151 /// | [ ] \
152 /// | [ ]_| <-- old scalar loop to handle remainder (scalar epilogue,
153 /// | | header wrapped in VPIRBasicBlock).
154 /// \ |
155 /// \ v
156 /// >[ ] <-- original loop exit block(s), wrapped in VPIRBasicBlocks.
157 LLVM_ABI_FOR_TEST static std::unique_ptr<VPlan>
158 buildVPlan0(Loop *TheLoop, LoopInfo &LI, Type *InductionTy,
159 PredicatedScalarEvolution &PSE, LoopVersioning *LVer = nullptr,
160 function_ref<const BranchProbabilityInfo &()> GetBPI = nullptr);
161
162 /// Add execution frequencies to each recipe in the loop body of \p Plan.
163 /// Frequencies are computed from the branch weights in \p Plan.
164 static void recordExecutionFrequencies(VPlan &Plan);
165
166 /// Replace VPPhi recipes in \p Plan's header with corresponding
167 /// VPHeaderPHIRecipe subclasses for inductions, reductions, and
168 /// fixed-order recurrences. This processes all header phis and creates
169 /// the appropriate widened recipe for each one. For fixed-order
170 /// recurrences, also creates FirstOrderRecurrenceSplice instructions and
171 /// sinks/hoists users as needed. Returns false if any fixed-order
172 /// recurrence cannot be handled.
174 VPlan &Plan, PredicatedScalarEvolution &PSE, Loop &OrigLoop,
175 const VPDominatorTree &VPDT,
176 const MapVector<PHINode *, InductionDescriptor> &Inductions,
177 const MapVector<PHINode *, RecurrenceDescriptor> &Reductions,
178 const SmallPtrSetImpl<const PHINode *> &FixedOrderRecurrences,
179 const SmallPtrSetImpl<PHINode *> &InLoopReductions, bool AllowReordering);
180
181 /// Finalize SCEV predicates by adding induction predicates from \p Plan to
182 /// \p PSE and checking constraints. Returns false if predicated IVs have
183 /// outside-loop uses via ExitingIVValue, if SCEV predicate complexity exceeds
184 /// \p SCEVCheckThreshold, or if predicates are needed but \p OptForSize is
185 /// true.
186 static bool
187 finalizeSCEVPredicates(VPlan &Plan, PredicatedScalarEvolution &PSE,
188 bool OptForSize, unsigned SCEVCheckThreshold,
189 OptimizationRemarkEmitter *ORE, Loop *TheLoop);
190
191 /// Create VPReductionRecipes for in-loop reductions. This processes chains
192 /// of operations contributing to in-loop reductions and creates appropriate
193 /// VPReductionRecipe instances.
194 static void createInLoopReductionRecipes(VPlan &Plan, ElementCount MinVF);
195
196 /// If a check is needed to guard executing the scalar epilogue loop, it will
197 /// be added to the middle block.
198 LLVM_ABI_FOR_TEST static void addMiddleCheck(VPlan &Plan);
199
200 // Create a check in \p CheckBlock to see if the vector loop should be
201 // executed. May create VPExpandSCEV recipes in the plan's entry block.
202 static void addMinimumIterationCheck(
203 VPlan &Plan, ElementCount VF, unsigned UF,
204 ElementCount MinProfitableTripCount, bool RequiresScalarEpilogue,
205 bool TailFolded, Loop *OrigLoop, const uint32_t *MinItersBypassWeights,
206 DebugLoc DL, PredicatedScalarEvolution &PSE, VPBasicBlock *CheckBlock);
207
208 /// Add a new check block before the vector preheader to \p Plan to check if
209 /// the main vector loop should be executed (TC >= VF * UF).
210 static void
211 addIterationCountCheckBlock(VPlan &Plan, ElementCount VF, unsigned UF,
212 bool RequiresScalarEpilogue, Loop *OrigLoop,
214 DebugLoc DL, PredicatedScalarEvolution &PSE);
215
216 /// Add a check to \p Plan to see if the epilogue vector loop should be
217 /// executed.
219 VPlan &Plan, Value *VectorTripCount, bool RequiresScalarEpilogue,
220 ElementCount EpilogueVF, unsigned MainLoopStep, unsigned EpilogueLoopStep,
221 ScalarEvolution &SE);
222
223 /// Replace loops in \p Plan's flat CFG with VPRegionBlocks, turning \p Plan's
224 /// flat CFG into a hierarchical CFG. For the outermost loop, also create the
225 /// canonical IV's increment and adjust the latch terminator: replace
226 /// BranchOnCond with BranchOnCount, using \p DL for the canonical IV.
227 LLVM_ABI_FOR_TEST static void createLoopRegions(VPlan &Plan, DebugLoc DL);
228
229 /// Connect \p CheckBlock to \p Plan, branching on \p Cond.
230 static void attachVPCheckBlock(VPlan &Plan, VPValue *Cond,
231 VPBasicBlock *CheckBlock,
232 bool AddBranchWeights);
233 static void attachCheckBlock(VPlan &Plan, Value *Cond, BasicBlock *CheckBlock,
234 bool AddBranchWeights);
235
236 /// Generate \p Checks as recipes and attach the check block to \p Plan.
237 static void attachMemoryChecks(VPlan &Plan,
239 ScalarEvolution &SE, DebugLoc DL,
240 bool AddBranchWeights);
241
242 /// Model the blocks the executed \p MainPlan generated for the main vector
243 /// loop in \p EpiPlan during epilogue vectorization, wrapping each in a
244 /// VPIRBasicBlock, with \p EnteredFrom the block \p EpiPlan is entered from.
245 /// Edges from blocks bypassing both vector loops are redirected to \p
246 /// EpiPlan's scalar preheader, all others are mirrored.
247 static void modelGeneratedMainLoopBlocks(VPlan &EpiPlan, VPlan &MainPlan,
248 VPIRBasicBlock *EnteredFrom);
249
250 /// Replaces the VPInstructions in \p Plan with corresponding
251 /// widen recipes. Returns false if any VPInstructions could not be converted
252 /// to a wide recipe if needed. Uses \p PSE to detect contiguous memory
253 /// accesses w.r.t. the \p OuterLoop induction variable.
255 VPlan &Plan, const TargetLibraryInfo &TLI, PredicatedScalarEvolution &PSE,
256 Loop *OuterLoop);
257
258 /// Try to legalize reductions with multiple in-loop uses. Currently only
259 /// strict and non-strict min/max reductions used by FindLastIV reductions are
260 /// supported, corresponding to computing the first and last argmin/argmax,
261 /// respectively. Otherwise return false.
262 static bool handleMultiUseReductions(VPlan &Plan,
263 OptimizationRemarkEmitter *ORE,
264 Loop *TheLoop);
265
266 /// Check if \p Plan contains any FMaxNum or FMinNum reductions. If they do,
267 /// try to update the vector loop to exit early if any input is NaN and resume
268 /// executing in the scalar loop to handle the NaNs there. Return false if
269 /// this attempt was unsuccessful.
270 static bool handleMaxMinNumReductions(VPlan &Plan);
271
272 /// Check if \p Plan contains any FindLast reductions. If it does, try to
273 /// update the vector loop to save the appropriate state using selects
274 /// for entire vectors for both the latest mask containing at least one active
275 /// element and the corresponding data vector. Return false if this attempt
276 /// was unsuccessful.
277 static bool handleFindLastReductions(VPlan &Plan);
278
279 /// Clear NSW/NUW flags from reduction instructions if necessary.
280 static void clearReductionWrapFlags(VPlan &Plan);
281
282 /// Explicitly unroll \p Plan by \p UF.
283 static void unrollByUF(VPlan &Plan, unsigned UF);
284
285 /// Replace replicating VPReplicateRecipe, VPScalarIVStepsRecipe and
286 /// VPInstruction in \p Plan with \p VF single-scalar recipes. Replicate
287 /// regions are dissolved by replicating their blocks and their recipes \p VF
288 /// times.
289 /// TODO: Also dissolve replicate regions with live outs.
290 static void replicateByVF(VPlan &Plan, ElementCount VF);
291
292 /// Optimize \p Plan based on \p BestVF and \p BestUF. This may restrict the
293 /// resulting plan to \p BestVF and \p BestUF.
294 static void optimizeForVFAndUF(VPlan &Plan, ElementCount BestVF,
295 unsigned BestUF,
296 PredicatedScalarEvolution &PSE);
297
298 /// Try to simplify VPInstruction::ExplicitVectorLength recipes when the AVL
299 /// is known to be <= VF, replacing them with the AVL directly.
300 static bool simplifyKnownEVL(VPlan &Plan, ElementCount VF,
301 PredicatedScalarEvolution &PSE);
302
303 /// Apply VPlan-to-VPlan optimizations to \p Plan, including induction recipe
304 /// optimizations, dead recipe removal, replicate region optimizations and
305 /// block merging.
306 LLVM_ABI_FOR_TEST static void optimize(VPlan &Plan);
307
308 /// Remove redundant VPBasicBlocks by merging them into their single
309 /// predecessor if the latter has a single successor.
310 static bool mergeBlocksIntoPredecessors(VPlan &Plan);
311
312 /// Wrap predicated VPReplicateRecipes with a mask operand in an if-then
313 /// region block and remove the mask operand. Optimize the created regions by
314 /// iteratively sinking scalar operands into the region, followed by merging
315 /// regions until no improvements are remaining.
316 static void createAndOptimizeReplicateRegions(VPlan &Plan);
317
318 /// Materialize the abstract header mask of the loop region into concrete
319 /// recipes: an active-lane-mask if \p UseActiveLaneMask (with a PHI if \p
320 /// UseActiveLaneMaskForControlFlow), else (WideCanonicalIV icmp ule BTC).
321 static void materializeHeaderMask(VPlan &Plan, bool UseActiveLaneMask,
322 bool UseActiveLaneMaskForControlFlow);
323
324 /// Insert truncates and extends for any truncated recipe. Redundant casts
325 /// will be folded later.
326 static void
327 truncateToMinimalBitwidths(VPlan &Plan,
328 const MapVector<Instruction *, uint64_t> &MinBWs);
329
330 /// Check \p Plan's live-ins and replace them with constants, if they can be
331 /// simplified via SCEV.
332 static void simplifyLiveInsWithSCEV(VPlan &Plan,
333 PredicatedScalarEvolution &PSE);
334
335 /// Replace symbolic strides from \p StridesMap in \p Plan with constants when
336 /// possible.
337 static void replaceSymbolicStrides(VPlan &Plan,
338 PredicatedScalarEvolution &PSE,
339 const SymbolicStrideMap &StridesMap,
340 const VPDominatorTree &VPDT);
341
342 /// Drop poison flags from recipes that may generate a poison value that is
343 /// used after vectorization, even when their operands are not poison. Those
344 /// recipes meet the following conditions:
345 /// * Contribute to the address computation of a recipe generating a widen
346 /// memory load/store (VPWidenMemoryInstructionRecipe or
347 /// VPInterleaveRecipe).
348 /// * Such a widen memory load/store is masked, but not with the header mask.
349 static void dropPoisonGeneratingRecipes(VPlan &Plan);
350
351 /// Add a VPCurrentIterationPHIRecipe and related recipes to \p Plan and
352 /// replaces all uses of the canonical IV except for the canonical IV
353 /// increment with a VPCurrentIterationPHIRecipe. The canonical IV is only
354 /// used to control the loop after this transformation.
355 static void
356 addExplicitVectorLength(VPlan &Plan,
357 const std::optional<unsigned> &MaxEVLSafeElements);
358
359 /// Optimize recipes which use an EVL-based header mask to VP intrinsics, for
360 /// example:
361 ///
362 /// %mask = icmp ult step-vector, EVL
363 /// %load = load %ptr, %mask
364 /// -->
365 /// %load = vp.load %ptr, EVL
366 static void optimizeEVLMasks(VPlan &Plan);
367
368 // For each Interleave Group in \p InterleaveGroups replace the Recipes
369 // widening its memory instructions with a single VPInterleaveRecipe at its
370 // insertion point.
371 static void createInterleaveGroups(
372 VPlan &Plan,
373 const SmallPtrSetImpl<const InterleaveGroup<Instruction> *>
374 &InterleaveGroups,
375 const bool &EpilogueAllowed);
376
377 /// Transform widen memory recipes into strided access recipes when legal
378 /// and profitable. Clamps \p Range to maintain consistency with widen
379 /// decisions of \p Plan, and uses \p Ctx to evaluate the cost.
380 static void convertToStridedAccesses(VPlan &Plan,
381 PredicatedScalarEvolution &PSE, Loop &L,
382 VPCostContext &Ctx, VFRange &Range);
383
384 /// Remove dead recipes from \p Plan.
385 static void removeDeadRecipes(VPlan &Plan);
386
387 /// Check if all loads in the loop are dereferenceable. Iterates over the
388 /// loop body blocks reachable from \p HeaderVPBB. Returns false if any
389 /// non-dereferenceable load is found.
390 static bool areAllLoadsDereferenceable(VPBasicBlock *HeaderVPBB,
391 Loop *TheLoop,
392 PredicatedScalarEvolution &PSE,
393 DominatorTree &DT,
394 AssumptionCache *AC);
395
396 /// Update \p Plan to account for uncountable early exits by introducing
397 /// appropriate branching logic in the latch that handles early exits and the
398 /// latch exit condition. Multiple exits are handled with a dispatch block
399 /// that determines which exit to take based on lane-by-lane semantics.
400 LLVM_ABI_FOR_TEST static bool
401 handleUncountableEarlyExits(VPlan &Plan, OptimizationRemarkEmitter *ORE,
402 Loop *TheLoop, PredicatedScalarEvolution &PSE,
403 DominatorTree &DT, AssumptionCache *AC,
405
406 /// Disconnect countable early exits from the loop.
407 LLVM_ABI_FOR_TEST static void handleCountableEarlyExits(VPlan &Plan);
408
409 /// Replaces the exit condition from
410 /// (branch-on-cond eq CanonicalIVInc, VectorTripCount)
411 /// to
412 /// (branch-on-cond eq AVLNext, 0)
413 static void convertEVLExitCond(VPlan &Plan);
414
415 /// Replace loop regions with explicit CFG.
416 static void dissolveLoopRegions(VPlan &Plan);
417
418 /// Expand BranchOnTwoConds instructions into explicit CFG with
419 /// BranchOnCond instructions. Should be called after dissolveLoopRegions.
420 static void expandBranchOnTwoConds(VPlan &Plan);
421
422 /// Transform loops with variable-length stepping after region
423 /// dissolution.
424 ///
425 /// Once loop regions are replaced with explicit CFG, loops can step with
426 /// variable vector lengths instead of fixed lengths. This transformation:
427 /// * Makes CurrentIteration-Phi concrete.
428 // * Removes CanonicalIV and increment.
429 static void convertToVariableLengthStep(VPlan &Plan);
430
431 /// Lower abstract recipes to concrete ones, that can be codegen'd.
432 static void convertToConcreteRecipes(VPlan &Plan);
433
434 /// This function converts initial recipes to the abstract recipes and clamps
435 /// \p Range based on cost model for following optimizations and cost
436 /// estimations. The converted abstract recipes will lower to concrete
437 /// recipes before codegen.
438 static void convertToAbstractRecipes(VPlan &Plan, VPCostContext &Ctx,
439 VFRange &Range);
440
441 /// Perform instcombine-like simplifications on recipes in \p Plan.
442 static void combineRecipes(VPlan &Plan);
443
444 /// Cancel out redundant reverses in \p Plan, e.g. reverse(reverse(x)) -> x.
445 static void simplifyReverses(VPlan &Plan);
446
447 /// Remove BranchOnCond recipes with true or false conditions together with
448 /// removing dead edges to their successors. If \p OnlyLatches is true, only
449 /// process loop latches. Returns true if incoming values from any phi-like
450 /// recipe have been removed.
451 static bool removeBranchOnConst(VPlan &Plan, bool OnlyLatches = false);
452
453 /// Perform common-subexpression-elimination on \p Plan.
454 static void cse(VPlan &Plan);
455
456 /// If there's a single exit block, optimize its phi recipes that use exiting
457 /// IV values by feeding them precomputed end values instead, possibly taken
458 /// one step backwards.
459 static void optimizeInductionLiveOutUsers(VPlan &Plan,
460 PredicatedScalarEvolution &PSE,
461 const Loop *L);
462
463 /// Add explicit broadcasts for live-ins and VPValues defined in \p Plan's entry block if they are used as vectors.
464 static void materializeBroadcasts(VPlan &Plan);
465
466 /// Hoist predicated loads from the same address to the loop entry block, if
467 /// they are guaranteed to execute on both paths (i.e., in replicate regions
468 /// with complementary masks P and NOT P).
469 static void hoistPredicatedLoads(VPlan &Plan, PredicatedScalarEvolution &PSE,
470 const Loop *L);
471
472 /// Sink predicated stores to the same address with complementary predicates
473 /// (P and NOT P) to an unconditional store with select recipes for the
474 /// stored values. This eliminates branching overhead when all paths
475 /// unconditionally store to the same location.
476 static void sinkPredicatedStores(VPlan &Plan, PredicatedScalarEvolution &PSE,
477 const Loop *L);
478
479 // Materialize vector trip counts for constants early if it can simply be
480 // computed as (Original TC / VF * UF) * VF * UF.
481 static void
482 materializeConstantVectorTripCount(VPlan &Plan, ElementCount BestVF,
483 unsigned BestUF,
484 PredicatedScalarEvolution &PSE);
485
486 /// Materialize vector trip count computations to a set of VPInstructions.
487 /// \p Step is used as the step value for the trip count computation.
488 /// \p MaxRuntimeStep is the maximum possible runtime value of Step, used to
489 /// prove the trip count is divisible by the step for scalable VFs.
490 static void materializeVectorTripCount(
491 VPlan &Plan, VPBasicBlock *VectorPHVPBB, bool TailByMasking,
492 bool RequiresScalarEpilogue, VPValue *Step,
493 std::optional<uint64_t> MaxRuntimeStep = std::nullopt);
494
495 /// Materialize the backedge-taken count to be computed explicitly using
496 /// VPInstructions.
497 static void materializeBackedgeTakenCount(VPlan &Plan,
498 VPBasicBlock *VectorPH);
499
500 /// Add explicit Build[Struct]Vector recipes to Pack multiple scalar values
501 /// into vectors and Unpack recipes to extract scalars from vectors as
502 /// needed.
503 static void materializePacksAndUnpacks(VPlan &Plan);
504
505 /// Materialize UF, VF and VFxUF to be computed explicitly using
506 /// VPInstructions.
507 static void materializeFactors(VPlan &Plan, VPBasicBlock *VectorPH,
508 ElementCount VF);
509
510 /// Attaches the alias-mask to the existing header-mask.
511 static void attachAliasMaskToHeaderMask(VPlan &Plan);
512
513 /// Materializes within the \p AliasCheckVPBB block. Updates the header mask
514 /// of the loop to use the alias mask. Returns the clamped VF.
515 static VPValue *materializeAliasMask(VPlan &Plan,
516 VPBasicBlock *AliasCheckVPBB,
517 ArrayRef<PointerDiffInfo> DiffChecks);
518
519 /// Materializes the alias mask within a check block before the loop. The
520 /// vector loop will only be entered if the clamped VF from the alias mask
521 /// is not scalar.
523 VPlan &Plan, ArrayRef<PointerDiffInfo> DiffChecks, bool HasBranchWeights);
524
525 /// Expand VPExpandSCEVRecipes in \p Plan's entry block to VPInstructions.
526 /// Recipes wrapping a SCEVAddRecExpr are kept for later IR-level expansion.
527 static void expandSCEVsToVPInstructions(VPlan &Plan, ScalarEvolution &SE);
528
529 /// Expand remaining VPExpandSCEVRecipes in \p Plan's entry block using
530 /// SCEVExpander. Each VPExpandSCEVRecipe is replaced with a live-in wrapping
531 /// the expanded IR value. A mapping from SCEV expressions to their expanded
532 /// IR value is returned.
533 static DenseMap<const SCEV *, Value *> expandSCEVs(VPlan &Plan,
534 ScalarEvolution &SE);
535
536 /// Try to find a single VF among \p Plan's VFs for which all interleave
537 /// groups (with known minimum VF elements) can be replaced by wide loads and
538 /// stores processing VF elements, if all transformed interleave groups access
539 /// the full vector width (checked via the maximum vector register width). If
540 /// the transformation can be applied, the original \p Plan will be split in
541 /// 2:
542 /// 1. The original Plan with the single VF containing the optimized recipes
543 /// using wide loads instead of interleave groups.
544 /// 2. A new clone which contains all VFs of Plan except the optimized VF.
545 ///
546 /// This effectively is a very simple form of loop-aware SLP, where we use
547 /// interleave groups to identify candidates.
548 static std::unique_ptr<VPlan>
549 narrowInterleaveGroups(VPlan &Plan, const TargetTransformInfo &TTI);
550
551 /// Adapts the vector loop region for tail folding by introducing a header
552 /// mask and conditionally executing the content of the region:
553 ///
554 /// Vector loop region before:
555 /// +-------------------------------------------+
556 /// |%iv = ... |
557 /// |... |
558 /// |%iv.next = add %iv, vfxuf |
559 /// |branch-on-count %iv.next, vector-trip-count|
560 /// +-------------------------------------------+
561 ///
562 /// Vector loop region after:
563 /// +-------------------------------------------+
564 /// |%iv = ... |
565 /// |%wide.iv = widen-canonical-iv ... |
566 /// |%header-mask = icmp ule %wide.iv, BTC |
567 /// |branch-on-cond %header-mask |---+
568 /// +-------------------------------------------+ |
569 /// | |
570 /// v |
571 /// +-------------------------------------------+ |
572 /// | ... | |
573 /// +-------------------------------------------+ |
574 /// | |
575 /// v |
576 /// +-------------------------------------------+ |
577 /// |<phis> = phi [..., ...], [poison, header] |
578 /// |%iv.next = add %iv, vfxuf |<--+
579 /// |branch-on-count %iv.next, vector-trip-count|
580 /// +-------------------------------------------+
581 ///
582 /// Any VPInstruction::ExtractLastLanes are also updated to extract from the
583 /// last active lane of the header mask.
584 static void foldTailByMasking(VPlan &Plan);
585
586 /// Predicate and linearize the control-flow in the only loop region of
587 /// \p Plan.
588 static void introduceMasksAndLinearize(VPlan &Plan);
589
590 /// Replace a VPWidenCanonicalIVRecipe if it is present in \p Plan, with a
591 /// VPWidenIntOrFpInductionRecipe, provided it would not cause additional
592 /// spills for \p VF at unroll factor \p UF.
593 static void
594 replaceWideCanonicalIVWithWideIV(VPlan &Plan, ScalarEvolution &SE,
595 const TargetTransformInfo &TTI,
597 ElementCount VF, unsigned UF);
598
599 /// Add branch weight metadata, if the \p Plan's middle block is terminated by
600 /// a BranchOnCond recipe.
601 static void
602 addBranchWeightToMiddleTerminator(VPlan &Plan, ElementCount VF,
603 std::optional<unsigned> VScaleForTuning);
604
605 /// Adjust first-order recurrence users in the middle block: create
606 /// penultimate element extracts for LCSSA phi users, and handle penultimate
607 /// extracts of the last active lane edge.
608 static void adjustFirstOrderRecurrenceMiddleUsers(VPlan &Plan,
609 VFRange &Range);
610
611 /// Optimize FindLast reductions selecting IVs (or expressions of IVs) by
612 /// converting them to FindIV reductions, if their IV range excludes a
613 /// suitable sentinel value. For expressions of IVs, the expression is sunk
614 /// to the middle block. The decision is based on SCEV expressions for \p L,
615 /// so this must run before any transform that changes the plan's iteration
616 /// space relative to \p L.
617 static void optimizeFindIVReductions(VPlan &Plan,
618 PredicatedScalarEvolution &PSE, Loop &L);
619
620 /// Detect and create partial reduction recipes for scaled or unordered
621 /// reductions in \p Plan. Must be called after recipe construction. If
622 /// partial reductions are only valid for a subset of VFs in Range, Range.End
623 /// is updated.
624 static void createPartialReductions(VPlan &Plan, VPCostContext &CostCtx,
625 VFRange &Range);
626
627 /// Convert load/store VPInstructions in \p Plan into widened or replicate
628 /// recipes. Non load/store input instructions are left unchanged.
629 static void makeMemOpWideningDecisions(VPlan &Plan, VFRange &Range,
630 VPRecipeBuilder &RecipeBuilder,
631 VPCostContext &CostCtx);
632
633 /// Make VPlan-based scalarization decision prior to delegating to the ones
634 /// made by the legacy CM. Only transforms "usesFirstLaneOnly` def-use chains
635 /// enabled by prior widening of consecutive memory operations for now.
636 static void makeScalarizationDecisions(VPlan &Plan, VFRange &Range);
637
638 /// Convert call VPInstructions in \p Plan into widened call, vector
639 /// intrinsic or replicate recipes based on a cost comparison via \p CostCtx.
640 static void makeCallWideningDecisions(VPlan &Plan, VFRange &Range,
641 VPRecipeBuilder &RecipeBuilder,
642 VPCostContext &CostCtx);
643
644 /// Replace truncates of a wide induction, or of that induction's increment,
645 /// by a VPWidenIntOrFpInductionRecipe producing the truncated type directly.
646 /// The canonical induction is narrowed even when the target reports the
647 /// truncate as free. If narrowing is only profitable for a subset of VFs in
648 /// \p Range, Range.End is updated.
649 static void narrowInductionTruncates(VPlan &Plan, VFRange &Range,
650 const TargetTransformInfo &TTI,
651 PredicatedScalarEvolution &PSE);
652};
653
654} // namespace llvm
655
656#endif // LLVM_TRANSFORMS_VECTORIZE_VPLANTRANSFORMS_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_ABI_FOR_TEST
Definition Compiler.h:220
static cl::opt< OutputCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(OutputCostKind::RecipThroughput), cl::values(clEnumValN(OutputCostKind::RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(OutputCostKind::Latency, "latency", "Instruction latency"), clEnumValN(OutputCostKind::CodeSize, "code-size", "Code size"), clEnumValN(OutputCostKind::SizeAndLatency, "size-latency", "Code size and latency"), clEnumValN(OutputCostKind::All, "all", "Print all cost kinds")))
static constexpr uint32_t MinItersBypassWeights[]
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
const SmallVectorImpl< MachineOperand > & Cond
This file defines the scope_exit class, which executes user-defined cleanup logic at scope exit.
This pass exposes codegen information to IR-level passes.
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:
static const char PassName[]
const Function * getParent() const
Return the enclosing method, or null if none.
Definition BasicBlock.h:213
Analysis providing branch probability information.
A struct for saving information about induction variables.
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
The optimization diagnostic interface.
Pass interface - Implemented by all 'passes'.
Definition Pass.h:99
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
LLVM_ABI bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr, std::string *Error=nullptr) const
matches - Match the regex against a given String.
Definition Regex.cpp:84
The main scalar evolution driver.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Provides information about what library functions are available for the current target.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
TargetCostKind
The kind of cost model.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
BasicBlock * getIRBasicBlock() const
Definition VPlan.h:4584
Helper class to create VPRecipies from IR instructions.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print this VPRegionBlock to O (recursively), prefixing all lines with Indent.
Definition VPlan.cpp:811
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition VPlan.h:4819
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
Definition VPlan.cpp:1042
VPIRBasicBlock * getScalarHeader() const
Return the VPIRBasicBlock wrapping the header of the scalar loop.
Definition VPlan.h:4977
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:319
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI_FOR_TEST cl::opt< bool > VerifyEachVPlan
LLVM_ABI_FOR_TEST cl::opt< bool > VPlanPrintAfterAll
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1762
DenseMap< Value *, const SCEVUnknown * > SymbolicStrideMap
Maps a pointer to its symbolic (non-constant) stride.
UncountableExitStyle
Different methods of handling early exits.
Definition VPlan.h:83
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
LLVM_ABI_FOR_TEST cl::list< std::string > VPlanPrintAfterPasses
TargetTransformInfo TTI
LLVM_ABI_FOR_TEST cl::list< std::string > VPlanPrintBeforePasses
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI_FOR_TEST cl::opt< bool > VPlanPrintBeforeAll
LLVM_ABI_FOR_TEST bool verifyVPlanIsValid(const VPlan &Plan)
Verify invariants for general VPlans.
LLVM_ABI_FOR_TEST cl::opt< bool > VPlanPrintVectorRegionScope
A range of powers-of-2 vectorization factors with fixed start and adjustable end.
static void simplifyLiveInsWithSCEV(VPlan &Plan, PredicatedScalarEvolution &PSE)
Check Plan's live-ins and replace them with constants, if they can be simplified via SCEV.
static VPValue * materializeAliasMask(VPlan &Plan, VPBasicBlock *AliasCheckVPBB, ArrayRef< PointerDiffInfo > DiffChecks)
Materializes within the AliasCheckVPBB block.
static decltype(auto) runPass(StringRef PassName, PassTy &&Pass, VPlan &Plan, ArgsTy &&...Args)
Helper to run a VPlan pass Pass on VPlan, forwarding extra arguments to the pass.
static void expandSCEVsToVPInstructions(VPlan &Plan, ScalarEvolution &SE)
Expand VPExpandSCEVRecipes in Plan's entry block to VPInstructions.
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 void createInterleaveGroups(VPlan &Plan, const SmallPtrSetImpl< const InterleaveGroup< Instruction > * > &InterleaveGroups, const bool &EpilogueAllowed)
static LLVM_ABI_FOR_TEST bool handleUncountableEarlyExits(VPlan &Plan, OptimizationRemarkEmitter *ORE, Loop *TheLoop, PredicatedScalarEvolution &PSE, DominatorTree &DT, AssumptionCache *AC, UncountableExitStyle Style)
Update Plan to account for uncountable early exits by introducing appropriate branching logic in the ...
static bool simplifyKnownEVL(VPlan &Plan, ElementCount VF, PredicatedScalarEvolution &PSE)
Try to simplify VPInstruction::ExplicitVectorLength recipes when the AVL is known to be <= VF,...
static void introduceMasksAndLinearize(VPlan &Plan)
Predicate and linearize the control-flow in the only loop region of Plan.
static void materializeFactors(VPlan &Plan, VPBasicBlock *VectorPH, ElementCount VF)
Materialize UF, VF and VFxUF to be computed explicitly using VPInstructions.
static void foldTailByMasking(VPlan &Plan)
Adapts the vector loop region for tail folding by introducing a header mask and conditionally executi...
static void materializeBackedgeTakenCount(VPlan &Plan, VPBasicBlock *VectorPH)
Materialize the backedge-taken count to be computed explicitly using VPInstructions.
static LLVM_ABI_FOR_TEST bool tryToConvertVPInstructionsToVPRecipes(VPlan &Plan, const TargetLibraryInfo &TLI, PredicatedScalarEvolution &PSE, Loop *OuterLoop)
Replaces the VPInstructions in Plan with corresponding widen recipes.
static bool handleMultiUseReductions(VPlan &Plan, OptimizationRemarkEmitter *ORE, Loop *TheLoop)
Try to legalize reductions with multiple in-loop uses.
static void createAndOptimizeReplicateRegions(VPlan &Plan)
Wrap predicated VPReplicateRecipes with a mask operand in an if-then region block and remove the mask...
static void convertToVariableLengthStep(VPlan &Plan)
Transform loops with variable-length stepping after region dissolution.
static void materializeHeaderMask(VPlan &Plan, bool UseActiveLaneMask, bool UseActiveLaneMaskForControlFlow)
Materialize the abstract header mask of the loop region into concrete recipes: an active-lane-mask if...
static void recordExecutionFrequencies(VPlan &Plan)
Add execution frequencies to each recipe in the loop body of Plan.
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 std::unique_ptr< VPlan > narrowInterleaveGroups(VPlan &Plan, const TargetTransformInfo &TTI)
Try to find a single VF among Plan's VFs for which all interleave groups (with known minimum VF eleme...
static bool handleFindLastReductions(VPlan &Plan)
Check if Plan contains any FindLast reductions.
static void createInLoopReductionRecipes(VPlan &Plan, ElementCount MinVF)
Create VPReductionRecipes for in-loop reductions.
static void materializeAliasMaskCheckBlock(VPlan &Plan, ArrayRef< PointerDiffInfo > DiffChecks, bool HasBranchWeights)
Materializes the alias mask within a check block before the loop.
static void modelGeneratedMainLoopBlocks(VPlan &EpiPlan, VPlan &MainPlan, VPIRBasicBlock *EnteredFrom)
Model the blocks the executed MainPlan generated for the main vector loop in EpiPlan during epilogue ...
static void unrollByUF(VPlan &Plan, unsigned UF)
Explicitly unroll Plan by UF.
static DenseMap< const SCEV *, Value * > expandSCEVs(VPlan &Plan, ScalarEvolution &SE)
Expand remaining VPExpandSCEVRecipes in Plan's entry block using SCEVExpander.
static void convertToConcreteRecipes(VPlan &Plan)
Lower abstract recipes to concrete ones, that can be codegen'd.
static LLVM_ABI_FOR_TEST void createLoopRegions(VPlan &Plan, DebugLoc DL)
Replace loops in Plan's flat CFG with VPRegionBlocks, turning Plan's flat CFG into a hierarchical CFG...
static void makeMemOpWideningDecisions(VPlan &Plan, VFRange &Range, VPRecipeBuilder &RecipeBuilder, VPCostContext &CostCtx)
Convert load/store VPInstructions in Plan into widened or replicate recipes.
static LLVM_ABI_FOR_TEST void addMiddleCheck(VPlan &Plan)
If a check is needed to guard executing the scalar epilogue loop, it will be added to the middle bloc...
static void narrowInductionTruncates(VPlan &Plan, VFRange &Range, const TargetTransformInfo &TTI, PredicatedScalarEvolution &PSE)
Replace truncates of a wide induction, or of that induction's increment, by a VPWidenIntOrFpInduction...
static LLVM_ABI_FOR_TEST bool createHeaderPhiRecipes(VPlan &Plan, PredicatedScalarEvolution &PSE, Loop &OrigLoop, const VPDominatorTree &VPDT, 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 void expandBranchOnTwoConds(VPlan &Plan)
Expand BranchOnTwoConds instructions into explicit CFG with BranchOnCond instructions.
static void materializeVectorTripCount(VPlan &Plan, VPBasicBlock *VectorPHVPBB, bool TailByMasking, bool RequiresScalarEpilogue, VPValue *Step, std::optional< uint64_t > MaxRuntimeStep=std::nullopt)
Materialize vector trip count computations to a set of VPInstructions.
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 bool mergeBlocksIntoPredecessors(VPlan &Plan)
Remove redundant VPBasicBlocks by merging them into their single predecessor if the latter has a sing...
static void attachAliasMaskToHeaderMask(VPlan &Plan)
Attaches the alias-mask to the existing header-mask.
static void optimizeFindIVReductions(VPlan &Plan, PredicatedScalarEvolution &PSE, Loop &L)
Optimize FindLast reductions selecting IVs (or expressions of IVs) by converting them to FindIV reduc...
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 makeScalarizationDecisions(VPlan &Plan, VFRange &Range)
Make VPlan-based scalarization decision prior to delegating to the ones made by the legacy CM.
static bool areAllLoadsDereferenceable(VPBasicBlock *HeaderVPBB, Loop *TheLoop, PredicatedScalarEvolution &PSE, DominatorTree &DT, AssumptionCache *AC)
Check if all loads in the loop are dereferenceable.
static void replaceWideCanonicalIVWithWideIV(VPlan &Plan, ScalarEvolution &SE, const TargetTransformInfo &TTI, TargetTransformInfo::TargetCostKind CostKind, ElementCount VF, unsigned UF)
Replace a VPWidenCanonicalIVRecipe if it is present in Plan, with a VPWidenIntOrFpInductionRecipe,...
static LLVM_ABI_FOR_TEST std::unique_ptr< VPlan > buildVPlan0(Loop *TheLoop, LoopInfo &LI, Type *InductionTy, PredicatedScalarEvolution &PSE, LoopVersioning *LVer=nullptr, function_ref< const BranchProbabilityInfo &()> GetBPI=nullptr)
Create a base VPlan0, serving as the common starting point for all later candidates.
static void optimizeInductionLiveOutUsers(VPlan &Plan, PredicatedScalarEvolution &PSE, const Loop *L)
If there's a single exit block, optimize its phi recipes that use exiting IV values by feeding them p...
static void addExplicitVectorLength(VPlan &Plan, const std::optional< unsigned > &MaxEVLSafeElements)
Add a VPCurrentIterationPHIRecipe and related recipes to Plan and replaces all uses of the canonical ...
static void simplifyReverses(VPlan &Plan)
Cancel out redundant reverses in Plan, e.g. reverse(reverse(x)) -> x.
static void makeCallWideningDecisions(VPlan &Plan, VFRange &Range, VPRecipeBuilder &RecipeBuilder, VPCostContext &CostCtx)
Convert call VPInstructions in Plan into widened call, vector intrinsic or replicate recipes based on...
static void adjustFirstOrderRecurrenceMiddleUsers(VPlan &Plan, VFRange &Range)
Adjust first-order recurrence users in the middle block: create penultimate element extracts for LCSS...
static void optimizeEVLMasks(VPlan &Plan)
Optimize recipes which use an EVL-based header mask to VP intrinsics, for example:
static bool handleMaxMinNumReductions(VPlan &Plan)
Check if Plan contains any FMaxNum or FMinNum reductions.
static void removeDeadRecipes(VPlan &Plan)
Remove dead recipes from Plan.
static void attachCheckBlock(VPlan &Plan, Value *Cond, BasicBlock *CheckBlock, bool AddBranchWeights)
static LLVM_ABI_FOR_TEST void handleCountableEarlyExits(VPlan &Plan)
Disconnect countable early exits from the loop.
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 bool finalizeSCEVPredicates(VPlan &Plan, PredicatedScalarEvolution &PSE, bool OptForSize, unsigned SCEVCheckThreshold, OptimizationRemarkEmitter *ORE, Loop *TheLoop)
Finalize SCEV predicates by adding induction predicates from Plan to PSE and checking constraints.
static void replicateByVF(VPlan &Plan, ElementCount VF)
Replace replicating VPReplicateRecipe, VPScalarIVStepsRecipe and VPInstruction in Plan with VF single...
static bool removeBranchOnConst(VPlan &Plan, bool OnlyLatches=false)
Remove BranchOnCond recipes with true or false conditions together with removing dead edges to their ...
static void convertToStridedAccesses(VPlan &Plan, PredicatedScalarEvolution &PSE, Loop &L, VPCostContext &Ctx, VFRange &Range)
Transform widen memory recipes into strided access recipes when legal and profitable.
static void addIterationCountCheckBlock(VPlan &Plan, ElementCount VF, unsigned UF, bool RequiresScalarEpilogue, Loop *OrigLoop, const uint32_t *MinItersBypassWeights, DebugLoc DL, PredicatedScalarEvolution &PSE)
Add a new check block before the vector preheader to Plan to check if the main vector loop should be ...
static void clearReductionWrapFlags(VPlan &Plan)
Clear NSW/NUW flags from reduction instructions if necessary.
static void createPartialReductions(VPlan &Plan, VPCostContext &CostCtx, VFRange &Range)
Detect and create partial reduction recipes for scaled or unordered reductions in Plan.
static void addMinimumIterationCheck(VPlan &Plan, ElementCount VF, unsigned UF, ElementCount MinProfitableTripCount, bool RequiresScalarEpilogue, bool TailFolded, Loop *OrigLoop, const uint32_t *MinItersBypassWeights, DebugLoc DL, PredicatedScalarEvolution &PSE, VPBasicBlock *CheckBlock)
static void cse(VPlan &Plan)
Perform common-subexpression-elimination on Plan.
static void replaceSymbolicStrides(VPlan &Plan, PredicatedScalarEvolution &PSE, const SymbolicStrideMap &StridesMap, const VPDominatorTree &VPDT)
Replace symbolic strides from StridesMap in Plan with constants when possible.
static void attachVPCheckBlock(VPlan &Plan, VPValue *Cond, VPBasicBlock *CheckBlock, bool AddBranchWeights)
Connect CheckBlock to Plan, branching on Cond.
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 void dropPoisonGeneratingRecipes(VPlan &Plan)
Drop poison flags from recipes that may generate a poison value that is used after vectorization,...
static void optimizeForVFAndUF(VPlan &Plan, ElementCount BestVF, unsigned BestUF, PredicatedScalarEvolution &PSE)
Optimize Plan based on BestVF and BestUF.
static void convertEVLExitCond(VPlan &Plan)
Replaces the exit condition from (branch-on-cond eq CanonicalIVInc, VectorTripCount) to (branch-on-co...
static void addMinimumVectorEpilogueIterationCheck(VPlan &Plan, Value *VectorTripCount, bool RequiresScalarEpilogue, ElementCount EpilogueVF, unsigned MainLoopStep, unsigned EpilogueLoopStep, ScalarEvolution &SE)
Add a check to Plan to see if the epilogue vector loop should be executed.
static void attachMemoryChecks(VPlan &Plan, ArrayRef< RuntimePointerCheck > Checks, ScalarEvolution &SE, DebugLoc DL, bool AddBranchWeights)
Generate Checks as recipes and attach the check block to Plan.
static void combineRecipes(VPlan &Plan)
Perform instcombine-like simplifications on recipes in Plan.