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