LLVM 17.0.0git
VPlanTransforms.cpp
Go to the documentation of this file.
1//===-- VPlanTransforms.cpp - 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 implements a set of utility VPlan to VPlan transformations.
11///
12//===----------------------------------------------------------------------===//
13
14#include "VPlanTransforms.h"
15#include "VPlanDominatorTree.h"
16#include "VPRecipeBuilder.h"
17#include "VPlanCFG.h"
19#include "llvm/ADT/SetVector.h"
22#include "llvm/IR/Intrinsics.h"
23
24using namespace llvm;
25
27 VPlanPtr &Plan,
29 GetIntOrFpInductionDescriptor,
30 ScalarEvolution &SE, const TargetLibraryInfo &TLI) {
31
33 Plan->getEntry());
34 for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
35 VPRecipeBase *Term = VPBB->getTerminator();
36 auto EndIter = Term ? Term->getIterator() : VPBB->end();
37 // Introduce each ingredient into VPlan.
38 for (VPRecipeBase &Ingredient :
39 make_early_inc_range(make_range(VPBB->begin(), EndIter))) {
40
41 VPValue *VPV = Ingredient.getVPSingleValue();
42 Instruction *Inst = cast<Instruction>(VPV->getUnderlyingValue());
43
44 VPRecipeBase *NewRecipe = nullptr;
45 if (auto *VPPhi = dyn_cast<VPWidenPHIRecipe>(&Ingredient)) {
46 auto *Phi = cast<PHINode>(VPPhi->getUnderlyingValue());
47 if (const auto *II = GetIntOrFpInductionDescriptor(Phi)) {
48 VPValue *Start = Plan->getVPValueOrAddLiveIn(II->getStartValue());
49 VPValue *Step =
50 vputils::getOrCreateVPValueForSCEVExpr(*Plan, II->getStep(), SE);
51 NewRecipe = new VPWidenIntOrFpInductionRecipe(Phi, Start, Step, *II);
52 } else {
53 Plan->addVPValue(Phi, VPPhi);
54 continue;
55 }
56 } else {
57 assert(isa<VPInstruction>(&Ingredient) &&
58 "only VPInstructions expected here");
59 assert(!isa<PHINode>(Inst) && "phis should be handled above");
60 // Create VPWidenMemoryInstructionRecipe for loads and stores.
61 if (LoadInst *Load = dyn_cast<LoadInst>(Inst)) {
62 NewRecipe = new VPWidenMemoryInstructionRecipe(
63 *Load, Ingredient.getOperand(0), nullptr /*Mask*/,
64 false /*Consecutive*/, false /*Reverse*/);
65 } else if (StoreInst *Store = dyn_cast<StoreInst>(Inst)) {
66 NewRecipe = new VPWidenMemoryInstructionRecipe(
67 *Store, Ingredient.getOperand(1), Ingredient.getOperand(0),
68 nullptr /*Mask*/, false /*Consecutive*/, false /*Reverse*/);
69 } else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Inst)) {
70 NewRecipe = new VPWidenGEPRecipe(GEP, Ingredient.operands());
71 } else if (CallInst *CI = dyn_cast<CallInst>(Inst)) {
72 NewRecipe =
73 new VPWidenCallRecipe(*CI, drop_end(Ingredient.operands()),
75 } else if (SelectInst *SI = dyn_cast<SelectInst>(Inst)) {
76 NewRecipe = new VPWidenSelectRecipe(*SI, Ingredient.operands());
77 } else if (auto *CI = dyn_cast<CastInst>(Inst)) {
78 NewRecipe = new VPWidenCastRecipe(
79 CI->getOpcode(), Ingredient.getOperand(0), CI->getType(), CI);
80 } else {
81 NewRecipe = new VPWidenRecipe(*Inst, Ingredient.operands());
82 }
83 }
84
85 NewRecipe->insertBefore(&Ingredient);
86 if (NewRecipe->getNumDefinedValues() == 1)
87 VPV->replaceAllUsesWith(NewRecipe->getVPSingleValue());
88 else
89 assert(NewRecipe->getNumDefinedValues() == 0 &&
90 "Only recpies with zero or one defined values expected");
91 Ingredient.eraseFromParent();
92 }
93 }
94}
95
96static bool sinkScalarOperands(VPlan &Plan) {
97 auto Iter = vp_depth_first_deep(Plan.getEntry());
98 bool Changed = false;
99 // First, collect the operands of all recipes in replicate blocks as seeds for
100 // sinking.
102 for (VPRegionBlock *VPR : VPBlockUtils::blocksOnly<VPRegionBlock>(Iter)) {
103 VPBasicBlock *EntryVPBB = VPR->getEntryBasicBlock();
104 if (!VPR->isReplicator() || EntryVPBB->getSuccessors().size() != 2)
105 continue;
106 VPBasicBlock *VPBB = dyn_cast<VPBasicBlock>(EntryVPBB->getSuccessors()[0]);
107 if (!VPBB || VPBB->getSingleSuccessor() != VPR->getExitingBasicBlock())
108 continue;
109 for (auto &Recipe : *VPBB) {
110 for (VPValue *Op : Recipe.operands())
111 if (auto *Def = Op->getDefiningRecipe())
112 WorkList.insert(std::make_pair(VPBB, Def));
113 }
114 }
115
116 bool ScalarVFOnly = Plan.hasScalarVFOnly();
117 // Try to sink each replicate or scalar IV steps recipe in the worklist.
118 for (unsigned I = 0; I != WorkList.size(); ++I) {
119 VPBasicBlock *SinkTo;
120 VPRecipeBase *SinkCandidate;
121 std::tie(SinkTo, SinkCandidate) = WorkList[I];
122 if (SinkCandidate->getParent() == SinkTo ||
123 SinkCandidate->mayHaveSideEffects() ||
124 SinkCandidate->mayReadOrWriteMemory())
125 continue;
126 if (auto *RepR = dyn_cast<VPReplicateRecipe>(SinkCandidate)) {
127 if (!ScalarVFOnly && RepR->isUniform())
128 continue;
129 } else if (!isa<VPScalarIVStepsRecipe>(SinkCandidate))
130 continue;
131
132 bool NeedsDuplicating = false;
133 // All recipe users of the sink candidate must be in the same block SinkTo
134 // or all users outside of SinkTo must be uniform-after-vectorization (
135 // i.e., only first lane is used) . In the latter case, we need to duplicate
136 // SinkCandidate.
137 auto CanSinkWithUser = [SinkTo, &NeedsDuplicating,
138 SinkCandidate](VPUser *U) {
139 auto *UI = dyn_cast<VPRecipeBase>(U);
140 if (!UI)
141 return false;
142 if (UI->getParent() == SinkTo)
143 return true;
144 NeedsDuplicating =
145 UI->onlyFirstLaneUsed(SinkCandidate->getVPSingleValue());
146 // We only know how to duplicate VPRecipeRecipes for now.
147 return NeedsDuplicating && isa<VPReplicateRecipe>(SinkCandidate);
148 };
149 if (!all_of(SinkCandidate->getVPSingleValue()->users(), CanSinkWithUser))
150 continue;
151
152 if (NeedsDuplicating) {
153 if (ScalarVFOnly)
154 continue;
155 Instruction *I = cast<Instruction>(
156 cast<VPReplicateRecipe>(SinkCandidate)->getUnderlyingValue());
157 auto *Clone = new VPReplicateRecipe(I, SinkCandidate->operands(), true);
158 // TODO: add ".cloned" suffix to name of Clone's VPValue.
159
160 Clone->insertBefore(SinkCandidate);
161 for (auto *U : to_vector(SinkCandidate->getVPSingleValue()->users())) {
162 auto *UI = cast<VPRecipeBase>(U);
163 if (UI->getParent() == SinkTo)
164 continue;
165
166 for (unsigned Idx = 0; Idx != UI->getNumOperands(); Idx++) {
167 if (UI->getOperand(Idx) != SinkCandidate->getVPSingleValue())
168 continue;
169 UI->setOperand(Idx, Clone);
170 }
171 }
172 }
173 SinkCandidate->moveBefore(*SinkTo, SinkTo->getFirstNonPhi());
174 for (VPValue *Op : SinkCandidate->operands())
175 if (auto *Def = Op->getDefiningRecipe())
176 WorkList.insert(std::make_pair(SinkTo, Def));
177 Changed = true;
178 }
179 return Changed;
180}
181
182/// If \p R is a region with a VPBranchOnMaskRecipe in the entry block, return
183/// the mask.
185 auto *EntryBB = dyn_cast<VPBasicBlock>(R->getEntry());
186 if (!EntryBB || EntryBB->size() != 1 ||
187 !isa<VPBranchOnMaskRecipe>(EntryBB->begin()))
188 return nullptr;
189
190 return cast<VPBranchOnMaskRecipe>(&*EntryBB->begin())->getOperand(0);
191}
192
193/// If \p R is a triangle region, return the 'then' block of the triangle.
195 auto *EntryBB = cast<VPBasicBlock>(R->getEntry());
196 if (EntryBB->getNumSuccessors() != 2)
197 return nullptr;
198
199 auto *Succ0 = dyn_cast<VPBasicBlock>(EntryBB->getSuccessors()[0]);
200 auto *Succ1 = dyn_cast<VPBasicBlock>(EntryBB->getSuccessors()[1]);
201 if (!Succ0 || !Succ1)
202 return nullptr;
203
204 if (Succ0->getNumSuccessors() + Succ1->getNumSuccessors() != 1)
205 return nullptr;
206 if (Succ0->getSingleSuccessor() == Succ1)
207 return Succ0;
208 if (Succ1->getSingleSuccessor() == Succ0)
209 return Succ1;
210 return nullptr;
211}
212
213// Merge replicate regions in their successor region, if a replicate region
214// is connected to a successor replicate region with the same predicate by a
215// single, empty VPBasicBlock.
217 SetVector<VPRegionBlock *> DeletedRegions;
218
219 // Collect replicate regions followed by an empty block, followed by another
220 // replicate region with matching masks to process front. This is to avoid
221 // iterator invalidation issues while merging regions.
223 for (VPRegionBlock *Region1 : VPBlockUtils::blocksOnly<VPRegionBlock>(
224 vp_depth_first_deep(Plan.getEntry()))) {
225 if (!Region1->isReplicator())
226 continue;
227 auto *MiddleBasicBlock =
228 dyn_cast_or_null<VPBasicBlock>(Region1->getSingleSuccessor());
229 if (!MiddleBasicBlock || !MiddleBasicBlock->empty())
230 continue;
231
232 auto *Region2 =
233 dyn_cast_or_null<VPRegionBlock>(MiddleBasicBlock->getSingleSuccessor());
234 if (!Region2 || !Region2->isReplicator())
235 continue;
236
237 VPValue *Mask1 = getPredicatedMask(Region1);
238 VPValue *Mask2 = getPredicatedMask(Region2);
239 if (!Mask1 || Mask1 != Mask2)
240 continue;
241
242 assert(Mask1 && Mask2 && "both region must have conditions");
243 WorkList.push_back(Region1);
244 }
245
246 // Move recipes from Region1 to its successor region, if both are triangles.
247 for (VPRegionBlock *Region1 : WorkList) {
248 if (DeletedRegions.contains(Region1))
249 continue;
250 auto *MiddleBasicBlock = cast<VPBasicBlock>(Region1->getSingleSuccessor());
251 auto *Region2 = cast<VPRegionBlock>(MiddleBasicBlock->getSingleSuccessor());
252
253 VPBasicBlock *Then1 = getPredicatedThenBlock(Region1);
254 VPBasicBlock *Then2 = getPredicatedThenBlock(Region2);
255 if (!Then1 || !Then2)
256 continue;
257
258 // Note: No fusion-preventing memory dependencies are expected in either
259 // region. Such dependencies should be rejected during earlier dependence
260 // checks, which guarantee accesses can be re-ordered for vectorization.
261 //
262 // Move recipes to the successor region.
263 for (VPRecipeBase &ToMove : make_early_inc_range(reverse(*Then1)))
264 ToMove.moveBefore(*Then2, Then2->getFirstNonPhi());
265
266 auto *Merge1 = cast<VPBasicBlock>(Then1->getSingleSuccessor());
267 auto *Merge2 = cast<VPBasicBlock>(Then2->getSingleSuccessor());
268
269 // Move VPPredInstPHIRecipes from the merge block to the successor region's
270 // merge block. Update all users inside the successor region to use the
271 // original values.
272 for (VPRecipeBase &Phi1ToMove : make_early_inc_range(reverse(*Merge1))) {
273 VPValue *PredInst1 =
274 cast<VPPredInstPHIRecipe>(&Phi1ToMove)->getOperand(0);
275 VPValue *Phi1ToMoveV = Phi1ToMove.getVPSingleValue();
276 for (VPUser *U : to_vector(Phi1ToMoveV->users())) {
277 auto *UI = dyn_cast<VPRecipeBase>(U);
278 if (!UI || UI->getParent() != Then2)
279 continue;
280 for (unsigned I = 0, E = U->getNumOperands(); I != E; ++I) {
281 if (Phi1ToMoveV != U->getOperand(I))
282 continue;
283 U->setOperand(I, PredInst1);
284 }
285 }
286
287 Phi1ToMove.moveBefore(*Merge2, Merge2->begin());
288 }
289
290 // Finally, remove the first region.
291 for (VPBlockBase *Pred : make_early_inc_range(Region1->getPredecessors())) {
292 VPBlockUtils::disconnectBlocks(Pred, Region1);
293 VPBlockUtils::connectBlocks(Pred, MiddleBasicBlock);
294 }
295 VPBlockUtils::disconnectBlocks(Region1, MiddleBasicBlock);
296 DeletedRegions.insert(Region1);
297 }
298
299 for (VPRegionBlock *ToDelete : DeletedRegions)
300 delete ToDelete;
301 return !DeletedRegions.empty();
302}
303
305 VPlan &Plan) {
306 Instruction *Instr = PredRecipe->getUnderlyingInstr();
307 // Build the triangular if-then region.
308 std::string RegionName = (Twine("pred.") + Instr->getOpcodeName()).str();
309 assert(Instr->getParent() && "Predicated instruction not in any basic block");
310 auto *BlockInMask = PredRecipe->getMask();
311 auto *BOMRecipe = new VPBranchOnMaskRecipe(BlockInMask);
312 auto *Entry = new VPBasicBlock(Twine(RegionName) + ".entry", BOMRecipe);
313
314 // Replace predicated replicate recipe with a replicate recipe without a
315 // mask but in the replicate region.
316 auto *RecipeWithoutMask = new VPReplicateRecipe(
317 PredRecipe->getUnderlyingInstr(),
318 make_range(PredRecipe->op_begin(), std::prev(PredRecipe->op_end())),
319 PredRecipe->isUniform());
320 auto *Pred = new VPBasicBlock(Twine(RegionName) + ".if", RecipeWithoutMask);
321
322 VPPredInstPHIRecipe *PHIRecipe = nullptr;
323 if (PredRecipe->getNumUsers() != 0) {
324 PHIRecipe = new VPPredInstPHIRecipe(RecipeWithoutMask);
325 PredRecipe->replaceAllUsesWith(PHIRecipe);
326 PHIRecipe->setOperand(0, RecipeWithoutMask);
327 }
328 PredRecipe->eraseFromParent();
329 auto *Exiting = new VPBasicBlock(Twine(RegionName) + ".continue", PHIRecipe);
330 VPRegionBlock *Region = new VPRegionBlock(Entry, Exiting, RegionName, true);
331
332 // Note: first set Entry as region entry and then connect successors starting
333 // from it in order, to propagate the "parent" of each VPBasicBlock.
334 VPBlockUtils::insertTwoBlocksAfter(Pred, Exiting, Entry);
335 VPBlockUtils::connectBlocks(Pred, Exiting);
336
337 return Region;
338}
339
340static void addReplicateRegions(VPlan &Plan) {
342 for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
343 vp_depth_first_deep(Plan.getEntry()))) {
344 for (VPRecipeBase &R : *VPBB)
345 if (auto *RepR = dyn_cast<VPReplicateRecipe>(&R)) {
346 if (RepR->isPredicated())
347 WorkList.push_back(RepR);
348 }
349 }
350
351 unsigned BBNum = 0;
352 for (VPReplicateRecipe *RepR : WorkList) {
353 VPBasicBlock *CurrentBlock = RepR->getParent();
354 VPBasicBlock *SplitBlock = CurrentBlock->splitAt(RepR->getIterator());
355
356 BasicBlock *OrigBB = RepR->getUnderlyingInstr()->getParent();
358 OrigBB->hasName() ? OrigBB->getName() + "." + Twine(BBNum++) : "");
359 // Record predicated instructions for above packing optimizations.
361 Region->setParent(CurrentBlock->getParent());
363 VPBlockUtils::connectBlocks(CurrentBlock, Region);
365 }
366}
367
369 // Convert masked VPReplicateRecipes to if-then region blocks.
371
372 bool ShouldSimplify = true;
373 while (ShouldSimplify) {
374 ShouldSimplify = sinkScalarOperands(Plan);
375 ShouldSimplify |= mergeReplicateRegionsIntoSuccessors(Plan);
376 ShouldSimplify |= VPlanTransforms::mergeBlocksIntoPredecessors(Plan);
377 }
378}
381 for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
382 vp_depth_first_deep(Plan.getEntry()))) {
383 auto *PredVPBB =
384 dyn_cast_or_null<VPBasicBlock>(VPBB->getSinglePredecessor());
385 if (PredVPBB && PredVPBB->getNumSuccessors() == 1)
386 WorkList.push_back(VPBB);
387 }
388
389 for (VPBasicBlock *VPBB : WorkList) {
390 VPBasicBlock *PredVPBB = cast<VPBasicBlock>(VPBB->getSinglePredecessor());
391 for (VPRecipeBase &R : make_early_inc_range(*VPBB))
392 R.moveBefore(*PredVPBB, PredVPBB->end());
393 VPBlockUtils::disconnectBlocks(PredVPBB, VPBB);
394 auto *ParentRegion = cast_or_null<VPRegionBlock>(VPBB->getParent());
395 if (ParentRegion && ParentRegion->getExiting() == VPBB)
396 ParentRegion->setExiting(PredVPBB);
397 for (auto *Succ : to_vector(VPBB->successors())) {
399 VPBlockUtils::connectBlocks(PredVPBB, Succ);
400 }
401 delete VPBB;
402 }
403 return !WorkList.empty();
404}
405
407 for (auto &Phi : Plan.getVectorLoopRegion()->getEntryBasicBlock()->phis()) {
408 auto *IV = dyn_cast<VPWidenIntOrFpInductionRecipe>(&Phi);
409 if (!IV || IV->getTruncInst())
410 continue;
411
412 // A sequence of IR Casts has potentially been recorded for IV, which
413 // *must be bypassed* when the IV is vectorized, because the vectorized IV
414 // will produce the desired casted value. This sequence forms a def-use
415 // chain and is provided in reverse order, ending with the cast that uses
416 // the IV phi. Search for the recipe of the last cast in the chain and
417 // replace it with the original IV. Note that only the final cast is
418 // expected to have users outside the cast-chain and the dead casts left
419 // over will be cleaned up later.
420 auto &Casts = IV->getInductionDescriptor().getCastInsts();
421 VPValue *FindMyCast = IV;
422 for (Instruction *IRCast : reverse(Casts)) {
423 VPRecipeBase *FoundUserCast = nullptr;
424 for (auto *U : FindMyCast->users()) {
425 auto *UserCast = cast<VPRecipeBase>(U);
426 if (UserCast->getNumDefinedValues() == 1 &&
427 UserCast->getVPSingleValue()->getUnderlyingValue() == IRCast) {
428 FoundUserCast = UserCast;
429 break;
430 }
431 }
432 FindMyCast = FoundUserCast->getVPSingleValue();
433 }
434 FindMyCast->replaceAllUsesWith(IV);
435 }
436}
437
439 VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
440 VPWidenCanonicalIVRecipe *WidenNewIV = nullptr;
441 for (VPUser *U : CanonicalIV->users()) {
442 WidenNewIV = dyn_cast<VPWidenCanonicalIVRecipe>(U);
443 if (WidenNewIV)
444 break;
445 }
446
447 if (!WidenNewIV)
448 return;
449
451 for (VPRecipeBase &Phi : HeaderVPBB->phis()) {
452 auto *WidenOriginalIV = dyn_cast<VPWidenIntOrFpInductionRecipe>(&Phi);
453
454 if (!WidenOriginalIV || !WidenOriginalIV->isCanonical() ||
455 WidenOriginalIV->getScalarType() != WidenNewIV->getScalarType())
456 continue;
457
458 // Replace WidenNewIV with WidenOriginalIV if WidenOriginalIV provides
459 // everything WidenNewIV's users need. That is, WidenOriginalIV will
460 // generate a vector phi or all users of WidenNewIV demand the first lane
461 // only.
462 if (any_of(WidenOriginalIV->users(),
463 [WidenOriginalIV](VPUser *U) {
464 return !U->usesScalars(WidenOriginalIV);
465 }) ||
466 vputils::onlyFirstLaneUsed(WidenNewIV)) {
467 WidenNewIV->replaceAllUsesWith(WidenOriginalIV);
468 WidenNewIV->eraseFromParent();
469 return;
470 }
471 }
472}
473
476 Plan.getEntry());
477
478 for (VPBasicBlock *VPBB : reverse(VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT))) {
479 // The recipes in the block are processed in reverse order, to catch chains
480 // of dead recipes.
481 for (VPRecipeBase &R : make_early_inc_range(reverse(*VPBB))) {
482 if (R.mayHaveSideEffects() || any_of(R.definedValues(), [](VPValue *V) {
483 return V->getNumUsers() > 0;
484 }))
485 continue;
486 R.eraseFromParent();
487 }
488 }
489}
490
494 bool HasOnlyVectorVFs = !Plan.hasVF(ElementCount::getFixed(1));
495 for (VPRecipeBase &Phi : HeaderVPBB->phis()) {
496 auto *WideIV = dyn_cast<VPWidenIntOrFpInductionRecipe>(&Phi);
497 if (!WideIV)
498 continue;
499 if (HasOnlyVectorVFs && none_of(WideIV->users(), [WideIV](VPUser *U) {
500 return U->usesScalars(WideIV);
501 }))
502 continue;
503
504 auto IP = HeaderVPBB->getFirstNonPhi();
505 VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
506 Type *ResultTy = WideIV->getPHINode()->getType();
507 if (Instruction *TruncI = WideIV->getTruncInst())
508 ResultTy = TruncI->getType();
509 const InductionDescriptor &ID = WideIV->getInductionDescriptor();
510 VPValue *Step =
511 vputils::getOrCreateVPValueForSCEVExpr(Plan, ID.getStep(), SE);
512 VPValue *BaseIV = CanonicalIV;
513 if (!CanonicalIV->isCanonical(ID.getKind(), WideIV->getStartValue(), Step,
514 ResultTy)) {
515 BaseIV = new VPDerivedIVRecipe(ID, WideIV->getStartValue(), CanonicalIV,
516 Step, ResultTy);
517 HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
518 }
519
520 VPScalarIVStepsRecipe *Steps = new VPScalarIVStepsRecipe(ID, BaseIV, Step);
521 HeaderVPBB->insert(Steps, IP);
522
523 // Update scalar users of IV to use Step instead. Use SetVector to ensure
524 // the list of users doesn't contain duplicates.
525 SetVector<VPUser *> Users(WideIV->user_begin(), WideIV->user_end());
526 for (VPUser *U : Users) {
527 if (HasOnlyVectorVFs && !U->usesScalars(WideIV))
528 continue;
529 for (unsigned I = 0, E = U->getNumOperands(); I != E; I++) {
530 if (U->getOperand(I) != WideIV)
531 continue;
532 U->setOperand(I, Steps);
533 }
534 }
535 }
536}
537
540
541 for (VPRecipeBase &R :
543 auto *ExpR = dyn_cast<VPExpandSCEVRecipe>(&R);
544 if (!ExpR)
545 continue;
546
547 auto I = SCEV2VPV.insert({ExpR->getSCEV(), ExpR});
548 if (I.second)
549 continue;
550 ExpR->replaceAllUsesWith(I.first->second);
551 ExpR->eraseFromParent();
552 }
553}
554
556 VPInstruction *Not = dyn_cast<VPInstruction>(Term->getOperand(0));
557 if (!Not || Not->getOpcode() != VPInstruction::Not)
558 return false;
559
560 VPInstruction *ALM = dyn_cast<VPInstruction>(Not->getOperand(0));
561 return ALM && ALM->getOpcode() == VPInstruction::ActiveLaneMask;
562}
563
565 unsigned BestUF,
567 assert(Plan.hasVF(BestVF) && "BestVF is not available in Plan");
568 assert(Plan.hasUF(BestUF) && "BestUF is not available in Plan");
569 VPBasicBlock *ExitingVPBB =
571 auto *Term = dyn_cast<VPInstruction>(&ExitingVPBB->back());
572 // Try to simplify the branch condition if TC <= VF * UF when preparing to
573 // execute the plan for the main vector loop. We only do this if the
574 // terminator is:
575 // 1. BranchOnCount, or
576 // 2. BranchOnCond where the input is Not(ActiveLaneMask).
577 if (!Term || (Term->getOpcode() != VPInstruction::BranchOnCount &&
578 (Term->getOpcode() != VPInstruction::BranchOnCond ||
580 return;
581
582 Type *IdxTy =
584 const SCEV *TripCount = createTripCountSCEV(IdxTy, PSE);
585 ScalarEvolution &SE = *PSE.getSE();
586 const SCEV *C =
587 SE.getConstant(TripCount->getType(), BestVF.getKnownMinValue() * BestUF);
588 if (TripCount->isZero() ||
589 !SE.isKnownPredicate(CmpInst::ICMP_ULE, TripCount, C))
590 return;
591
592 LLVMContext &Ctx = SE.getContext();
593 auto *BOC = new VPInstruction(
596 Term->eraseFromParent();
597 ExitingVPBB->appendRecipe(BOC);
598 Plan.setVF(BestVF);
599 Plan.setUF(BestUF);
600 // TODO: Further simplifications are possible
601 // 1. Replace inductions with constants.
602 // 2. Replace vector loop region with VPBasicBlock.
603}
604
605#ifndef NDEBUG
607 auto *Region = dyn_cast_or_null<VPRegionBlock>(R->getParent()->getParent());
608 if (Region && Region->isReplicator()) {
609 assert(Region->getNumSuccessors() == 1 &&
610 Region->getNumPredecessors() == 1 && "Expected SESE region!");
611 assert(R->getParent()->size() == 1 &&
612 "A recipe in an original replicator region must be the only "
613 "recipe in its block");
614 return Region;
615 }
616 return nullptr;
617}
618#endif
619
620static bool properlyDominates(const VPRecipeBase *A, const VPRecipeBase *B,
621 VPDominatorTree &VPDT) {
622 if (A == B)
623 return false;
624
625 auto LocalComesBefore = [](const VPRecipeBase *A, const VPRecipeBase *B) {
626 for (auto &R : *A->getParent()) {
627 if (&R == A)
628 return true;
629 if (&R == B)
630 return false;
631 }
632 llvm_unreachable("recipe not found");
633 };
634 const VPBlockBase *ParentA = A->getParent();
635 const VPBlockBase *ParentB = B->getParent();
636 if (ParentA == ParentB)
637 return LocalComesBefore(A, B);
638
639 assert(!GetReplicateRegion(const_cast<VPRecipeBase *>(A)) &&
640 "No replicate regions expected at this point");
641 assert(!GetReplicateRegion(const_cast<VPRecipeBase *>(B)) &&
642 "No replicate regions expected at this point");
643 return VPDT.properlyDominates(ParentA, ParentB);
644}
645
646/// Sink users of \p FOR after the recipe defining the previous value \p
647/// Previous of the recurrence. \returns true if all users of \p FOR could be
648/// re-arranged as needed or false if it is not possible.
649static bool
651 VPRecipeBase *Previous,
652 VPDominatorTree &VPDT) {
653 // Collect recipes that need sinking.
656 Seen.insert(Previous);
657 auto TryToPushSinkCandidate = [&](VPRecipeBase *SinkCandidate) {
658 // The previous value must not depend on the users of the recurrence phi. In
659 // that case, FOR is not a fixed order recurrence.
660 if (SinkCandidate == Previous)
661 return false;
662
663 if (isa<VPHeaderPHIRecipe>(SinkCandidate) ||
664 !Seen.insert(SinkCandidate).second ||
665 properlyDominates(Previous, SinkCandidate, VPDT))
666 return true;
667
668 WorkList.push_back(SinkCandidate);
669 return true;
670 };
671
672 // Recursively sink users of FOR after Previous.
673 WorkList.push_back(FOR);
674 for (unsigned I = 0; I != WorkList.size(); ++I) {
675 VPRecipeBase *Current = WorkList[I];
676 assert(Current->getNumDefinedValues() == 1 &&
677 "only recipes with a single defined value expected");
678 for (VPUser *User : Current->getVPSingleValue()->users()) {
679 if (auto *R = dyn_cast<VPRecipeBase>(User))
680 if (!TryToPushSinkCandidate(R))
681 return false;
682 }
683 }
684
685 // Keep recipes to sink ordered by dominance so earlier instructions are
686 // processed first.
687 sort(WorkList, [&VPDT](const VPRecipeBase *A, const VPRecipeBase *B) {
688 return properlyDominates(A, B, VPDT);
689 });
690
691 for (VPRecipeBase *SinkCandidate : WorkList) {
692 if (SinkCandidate == FOR)
693 continue;
694
695 SinkCandidate->moveAfter(Previous);
696 Previous = SinkCandidate;
697 }
698 return true;
699}
700
702 VPBuilder &Builder) {
703 VPDominatorTree VPDT;
704 VPDT.recalculate(Plan);
705
707 for (VPRecipeBase &R :
709 if (auto *FOR = dyn_cast<VPFirstOrderRecurrencePHIRecipe>(&R))
710 RecurrencePhis.push_back(FOR);
711
712 for (VPFirstOrderRecurrencePHIRecipe *FOR : RecurrencePhis) {
714 VPRecipeBase *Previous = FOR->getBackedgeValue()->getDefiningRecipe();
715 // Fixed-order recurrences do not contain cycles, so this loop is guaranteed
716 // to terminate.
717 while (auto *PrevPhi =
718 dyn_cast_or_null<VPFirstOrderRecurrencePHIRecipe>(Previous)) {
719 assert(PrevPhi->getParent() == FOR->getParent());
720 assert(SeenPhis.insert(PrevPhi).second);
721 Previous = PrevPhi->getBackedgeValue()->getDefiningRecipe();
722 }
723
724 if (!sinkRecurrenceUsersAfterPrevious(FOR, Previous, VPDT))
725 return false;
726
727 // Introduce a recipe to combine the incoming and previous values of a
728 // fixed-order recurrence.
729 VPBasicBlock *InsertBlock = Previous->getParent();
730 if (isa<VPHeaderPHIRecipe>(Previous))
731 Builder.setInsertPoint(InsertBlock, InsertBlock->getFirstNonPhi());
732 else
733 Builder.setInsertPoint(InsertBlock, std::next(Previous->getIterator()));
734
735 auto *RecurSplice = cast<VPInstruction>(
737 {FOR, FOR->getBackedgeValue()}));
738
739 FOR->replaceAllUsesWith(RecurSplice);
740 // Set the first operand of RecurSplice to FOR again, after replacing
741 // all users.
742 RecurSplice->setOperand(0, FOR);
743 }
744 return true;
745}
ReachingDefAnalysis InstSet & ToRemove
assume Assume Builder
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Hexagon Common GEP
iv Induction Variable Users
Definition: IVUsers.cpp:48
#define I(x, y, z)
Definition: MD5.cpp:58
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
@ SI
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
This file implements dominator tree analysis for a single level of a VPlan's H-CFG.
static bool canSimplifyBranchOnCond(VPInstruction *Term)
static bool sinkScalarOperands(VPlan &Plan)
static bool sinkRecurrenceUsersAfterPrevious(VPFirstOrderRecurrencePHIRecipe *FOR, VPRecipeBase *Previous, VPDominatorTree &VPDT)
Sink users of FOR after the recipe defining the previous value Previous of the recurrence.
static bool mergeReplicateRegionsIntoSuccessors(VPlan &Plan)
static void addReplicateRegions(VPlan &Plan)
static VPRegionBlock * GetReplicateRegion(VPRecipeBase *R)
static bool properlyDominates(const VPRecipeBase *A, const VPRecipeBase *B, VPDominatorTree &VPDT)
static VPRegionBlock * createReplicateRegion(VPReplicateRecipe *PredRecipe, VPlan &Plan)
static VPBasicBlock * getPredicatedThenBlock(VPRegionBlock *R)
If R is a triangle region, return the 'then' block of the triangle.
VPValue * getPredicatedMask(VPRegionBlock *R)
If R is a region with a VPBranchOnMaskRecipe in the entry block, return the mask.
This file provides utility VPlan to VPlan transformations.
static const uint32_t IV[8]
Definition: blake3_impl.h:77
LLVM Basic Block Representation.
Definition: BasicBlock.h:56
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:112
This class represents a function call, abstracting a target machine's calling convention.
@ ICMP_ULE
unsigned less or equal
Definition: InstrTypes.h:737
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:833
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:220
Core dominator tree base class.
void recalculate(ParentType &Func)
recalculate - compute a dominator tree for the given function
bool properlyDominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
properlyDominates - Returns true iff A dominates B and A != B.
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition: TypeSize.h:291
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Definition: Instructions.h:940
A struct for saving information about induction variables.
const BasicBlock * getParent() const
Definition: Instruction.h:90
const char * getOpcodeName() const
Definition: Instruction.h:170
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
An instruction for reading from memory.
Definition: Instructions.h:177
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
ScalarEvolution * getSE() const
Returns the ScalarEvolution analysis used.
This class represents an analyzed expression in the program.
bool isZero() const
Return true if the expression is a constant zero.
Type * getType() const
Return the LLVM type of this SCEV expression.
The main scalar evolution driver.
const SCEV * getConstant(ConstantInt *V)
bool isKnownPredicate(ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS)
Test if the given expression is known to satisfy the condition described by Pred, LHS,...
LLVMContext & getContext() const
This class represents the LLVM 'select' instruction.
A vector that has set insertion semantics.
Definition: SetVector.h:51
size_type size() const
Determine the number of elements in the SetVector.
Definition: SetVector.h:88
bool contains(const key_type &key) const
Check if the SetVector contains the given key.
Definition: SetVector.h:213
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:152
bool empty() const
Determine if the SetVector is empty or not.
Definition: SetVector.h:83
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:365
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:450
bool empty() const
Definition: SmallVector.h:94
size_t size() const
Definition: SmallVector.h:91
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
An instruction for storing to memory.
Definition: Instructions.h:301
Provides information about what library functions are available for the current target.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
op_range operands()
Definition: User.h:242
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:2192
void appendRecipe(VPRecipeBase *Recipe)
Augment the existing recipes of a VPBasicBlock with an additional Recipe as the last recipe.
Definition: VPlan.h:2260
iterator end()
Definition: VPlan.h:2223
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
Definition: VPlan.h:2270
iterator getFirstNonPhi()
Return the position of the first non-phi node recipe in the block.
Definition: VPlan.cpp:208
VPBasicBlock * splitAt(iterator SplitAt)
Split current block at SplitAt by inserting a new block between the current block and its successors ...
Definition: VPlan.cpp:411
const VPRecipeBase & back() const
Definition: VPlan.h:2235
void insert(VPRecipeBase *Recipe, iterator InsertPt)
Definition: VPlan.h:2251
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:418
VPRegionBlock * getParent()
Definition: VPlan.h:490
const VPBasicBlock * getExitingBasicBlock() const
Definition: VPlan.cpp:173
const VPBasicBlock * getEntryBasicBlock() const
Definition: VPlan.cpp:151
VPBlockBase * getSingleSuccessor() const
Definition: VPlan.h:525
const VPBlocksTy & getSuccessors() const
Definition: VPlan.h:515
static void insertTwoBlocksAfter(VPBlockBase *IfTrue, VPBlockBase *IfFalse, VPBlockBase *BlockPtr)
Insert disconnected VPBlockBases IfTrue and IfFalse after BlockPtr.
Definition: VPlan.h:2771
static void disconnectBlocks(VPBlockBase *From, VPBlockBase *To)
Disconnect VPBlockBases From and To bi-directionally.
Definition: VPlan.h:2799
static void connectBlocks(VPBlockBase *From, VPBlockBase *To)
Connect VPBlockBases From and To bi-directionally.
Definition: VPlan.h:2788
A recipe for generating conditional branches on the bits of a mask.
Definition: VPlan.h:1807
VPlan-based builder utility analogous to IRBuilder.
Canonical scalar induction phi of the vector loop.
Definition: VPlan.h:2009
bool isCanonical(InductionDescriptor::InductionKind Kind, VPValue *Start, VPValue *Step, Type *Ty) const
Check if the induction described by Kind, /p Start and Step is canonical, i.e.
unsigned getNumDefinedValues() const
Returns the number of values defined by the VPDef.
Definition: VPlanValue.h:415
VPValue * getVPSingleValue()
Returns the only VPValue defined by the VPDef.
Definition: VPlanValue.h:388
A recipe for converting the canonical IV value to the corresponding value of an IV with different sta...
Definition: VPlan.h:2114
VPValue * getStartValue()
Returns the start value of the phi, if one is set.
Definition: VPlan.h:1314
This is a concrete Recipe that models a single VPlan-level instruction.
Definition: VPlan.h:816
unsigned getOpcode() const
Definition: VPlan.h:874
@ FirstOrderRecurrenceSplice
Definition: VPlan.h:822
VPPredInstPHIRecipe is a recipe for generating the phi nodes needed when control converges back from ...
Definition: VPlan.h:1854
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition: VPlan.h:703
bool mayReadOrWriteMemory() const
Returns true if the recipe may read from or write to memory.
Definition: VPlan.h:790
bool mayHaveSideEffects() const
Returns true if the recipe may have side-effects.
Instruction * getUnderlyingInstr()
Returns the underlying instruction, if the recipe is a VPValue or nullptr otherwise.
Definition: VPlan.h:758
VPBasicBlock * getParent()
Definition: VPlan.h:720
void moveBefore(VPBasicBlock &BB, iplist< VPRecipeBase >::iterator I)
Unlink this recipe and insert into BB before I.
void insertBefore(VPRecipeBase *InsertPos)
Insert an unlinked recipe into a basic block immediately before the specified recipe.
iplist< VPRecipeBase >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition: VPlan.h:2316
const VPBlockBase * getEntry() const
Definition: VPlan.h:2355
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition: VPlan.h:1744
bool isUniform() const
Definition: VPlan.h:1776
VPValue * getMask()
Return the mask of a predicated VPReplicateRecipe.
Definition: VPlan.h:1800
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
Definition: VPlan.h:2157
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
Definition: VPlanValue.h:204
operand_range operands()
Definition: VPlanValue.h:279
void setOperand(unsigned I, VPValue *New)
Definition: VPlanValue.h:259
operand_iterator op_end()
Definition: VPlanValue.h:277
operand_iterator op_begin()
Definition: VPlanValue.h:275
VPValue * getOperand(unsigned N) const
Definition: VPlanValue.h:254
Value * getUnderlyingValue()
Return the underlying Value attached to this VPValue.
Definition: VPlanValue.h:84
VPRecipeBase * getDefiningRecipe()
Returns the recipe defining this VPValue or nullptr if it is not defined by a recipe,...
Definition: VPlan.cpp:116
void replaceAllUsesWith(VPValue *New)
Definition: VPlan.cpp:1022
unsigned getNumUsers() const
Definition: VPlanValue.h:119
Value * getLiveInIRValue()
Returns the underlying IR value, if this VPValue is defined outside the scope of VPlan.
Definition: VPlanValue.h:180
user_range users()
Definition: VPlanValue.h:147
A recipe for widening Call instructions.
Definition: VPlan.h:1162
A Recipe for widening the canonical induction variable of the vector loop.
Definition: VPlan.h:2083
const Type * getScalarType() const
Returns the scalar type of the induction.
Definition: VPlan.h:2105
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition: VPlan.h:1124
A recipe for handling GEP instructions.
Definition: VPlan.h:1223
A recipe for handling phi nodes of integer and floating-point inductions, producing their vector valu...
Definition: VPlan.h:1338
A Recipe for widening load/store operations.
Definition: VPlan.h:1887
VPWidenRecipe is a recipe for producing a copy of vector type its ingredient.
Definition: VPlan.h:1102
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition: VPlan.h:2413
VPBasicBlock * getEntry()
Definition: VPlan.h:2505
VPValue * getVPValueOrAddLiveIn(Value *V)
Gets the VPValue for V or adds a new live-in (if none exists yet) for V.
Definition: VPlan.h:2574
VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
Definition: VPlan.h:2613
bool hasVF(ElementCount VF)
Definition: VPlan.h:2536
bool hasUF(unsigned UF) const
Definition: VPlan.h:2540
void setVF(ElementCount VF)
Definition: VPlan.h:2530
bool hasScalarVFOnly() const
Definition: VPlan.h:2538
VPCanonicalIVPHIRecipe * getCanonicalIV()
Returns the canonical induction recipe of the vector loop.
Definition: VPlan.h:2621
void setUF(unsigned UF)
Definition: VPlan.h:2542
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:378
bool hasName() const
Definition: Value.h:261
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition: TypeSize.h:163
An efficient, type-erasing, non-owning reference to a callable.
self_iterator getIterator()
Definition: ilist_node.h:82
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
VPValue * getOrCreateVPValueForSCEVExpr(VPlan &Plan, const SCEV *Expr, ScalarEvolution &SE)
Get or create a VPValue that corresponds to the expansion of Expr.
Definition: VPlan.cpp:1141
bool onlyFirstLaneUsed(VPValue *Def)
Returns true if only the first lane of Def is used.
Definition: VPlan.cpp:1136
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1819
Intrinsic::ID getVectorIntrinsicIDForCall(const CallInst *CI, const TargetLibraryInfo *TLI)
Returns intrinsic ID for call.
const SCEV * createTripCountSCEV(Type *IdxTy, PredicatedScalarEvolution &PSE, Loop *OrigLoop)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition: STLExtras.h:748
iterator_range< df_iterator< VPBlockDeepTraversalWrapper< VPBlockBase * > > > vp_depth_first_deep(VPBlockBase *G)
Returns an iterator range to traverse the graph starting at G in depth-first order while traversing t...
Definition: VPlanCFG.h:226
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:1826
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:511
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1744
std::unique_ptr< VPlan > VPlanPtr
Definition: VPlan.h:132
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1833
SmallVector< ValueTypeFromRangeType< R >, Size > to_vector(R &&Range)
Given a range of type R, iterate the entire range and return a SmallVector with elements of the vecto...
Definition: SmallVector.h:1303
auto drop_end(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the last N elements excluded.
Definition: STLExtras.h:420
BasicBlock * SplitBlock(BasicBlock *Old, Instruction *SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="", bool Before=false)
Split the specified block at the specified instruction.
A recipe for handling first-order recurrence phis.
Definition: VPlan.h:1493
A recipe for widening select instructions.
Definition: VPlan.h:1195
static void createAndOptimizeReplicateRegions(VPlan &Plan)
Wrap predicated VPReplicateRecipes with a mask operand in an if-then region block and remove the mask...
static void removeRedundantInductionCasts(VPlan &Plan)
Remove redundant casts of inductions.
static void optimizeInductions(VPlan &Plan, ScalarEvolution &SE)
If any user of a VPWidenIntOrFpInductionRecipe needs scalar values, provide them by building scalar s...
static bool mergeBlocksIntoPredecessors(VPlan &Plan)
Remove redundant VPBasicBlocks by merging them into their predecessor if the predecessor has a single...
static void removeRedundantExpandSCEVRecipes(VPlan &Plan)
Remove redundant EpxandSCEVRecipes in Plan's entry block by replacing them with already existing reci...
static void removeRedundantCanonicalIVs(VPlan &Plan)
Try to replace VPWidenCanonicalIVRecipes with a widened canonical IV recipe, if it exists.
static void removeDeadRecipes(VPlan &Plan)
static void VPInstructionsToVPRecipes(VPlanPtr &Plan, function_ref< const InductionDescriptor *(PHINode *)> GetIntOrFpInductionDescriptor, ScalarEvolution &SE, const TargetLibraryInfo &TLI)
Replaces the VPInstructions in Plan with corresponding widen recipes.
static bool adjustFixedOrderRecurrences(VPlan &Plan, VPBuilder &Builder)
Sink users of fixed-order recurrences after the recipe defining their previous value.
static void optimizeForVFAndUF(VPlan &Plan, ElementCount BestVF, unsigned BestUF, PredicatedScalarEvolution &PSE)
Optimize Plan based on BestVF and BestUF.