LLVM 23.0.0git
VPlanUtils.cpp
Go to the documentation of this file.
1//===- VPlanUtils.cpp - VPlan-related utilities ---------------------------===//
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#include "VPlanUtils.h"
11#include "VPlanAnalysis.h"
12#include "VPlanCFG.h"
13#include "VPlanDominatorTree.h"
14#include "VPlanPatternMatch.h"
15#include "llvm/ADT/TypeSwitch.h"
19#include "llvm/IR/Dominators.h"
21
22using namespace llvm;
23using namespace llvm::VPlanPatternMatch;
24using namespace llvm::SCEVPatternMatch;
25
27 return all_of(Def->users(),
28 [Def](const VPUser *U) { return U->usesFirstLaneOnly(Def); });
29}
30
32 return all_of(Def->users(),
33 [Def](const VPUser *U) { return U->usesFirstPartOnly(Def); });
34}
35
37 return all_of(Def->users(),
38 [Def](const VPUser *U) { return U->usesScalars(Def); });
39}
40
42 if (auto *E = dyn_cast<SCEVConstant>(Expr))
43 return Plan.getOrAddLiveIn(E->getValue());
44 // Skip SCEV expansion if Expr is a SCEVUnknown wrapping a non-instruction
45 // value. Otherwise the value may be defined in a loop and using it directly
46 // will break LCSSA form. The SCEV expansion takes care of preserving LCSSA
47 // form.
48 auto *U = dyn_cast<SCEVUnknown>(Expr);
49 if (U && !isa<Instruction>(U->getValue()))
50 return Plan.getOrAddLiveIn(U->getValue());
51 auto *Expanded = new VPExpandSCEVRecipe(Expr);
52 VPBasicBlock *EntryVPBB = Plan.getEntry();
53 auto Iter = EntryVPBB->getFirstNonPhi();
54 while (Iter != EntryVPBB->end() && isa<VPIRInstruction>(*Iter))
55 ++Iter;
56 EntryVPBB->insert(Expanded, Iter);
57 return Expanded;
58}
59
60bool vputils::isHeaderMask(const VPValue *V, const VPlan &Plan) {
62 return true;
63
64 VPValue *A, *B;
65
66 auto m_CanonicalScalarIVSteps = m_ScalarIVSteps(
69 m_One(), m_Specific(&Plan.getVF()));
70
71 // A wide canonical IV is either an explicit VPWidenCanonicalIVRecipe or a
72 // canonical VPWidenIntOrFpInductionRecipe.
73 auto m_WideCanonicalIV =
75
77 return B == Plan.getTripCount() &&
78 (match(A, m_CanonicalScalarIVSteps) || match(A, m_WideCanonicalIV));
79
80 // For scalar plans, the header mask uses the scalar steps.
81 if (match(V, m_ICmp(m_CanonicalScalarIVSteps,
83 assert(Plan.hasScalarVFOnly() &&
84 "Non-scalar VF using scalar IV steps for header mask?");
85 return true;
86 }
87
88 auto MaskMatch = m_ICmp(m_VPValue(A), m_VPValue(B));
89 if (match(V, m_CombineOr(MaskMatch, m_Reverse(MaskMatch))))
90 return match(A, m_WideCanonicalIV) && B == Plan.getBackedgeTakenCount();
91
92 return match(
95}
96
97/// Returns true if \p R propagates poison from any operand to its result.
101 [](const VPRecipeBase *) { return true; })
102 .Case([](const VPReplicateRecipe *Rep) {
103 // GEP and casts propagate poison from all operands.
104 unsigned Opcode = Rep->getOpcode();
105 return Opcode == Instruction::GetElementPtr ||
106 Instruction::isCast(Opcode);
107 })
108 .Default([](const VPRecipeBase *) { return false; });
109}
110
111/// Returns true if \p V being poison is guaranteed to trigger UB because it
112/// propagates to the address of a memory recipe.
113static bool poisonGuaranteesUB(const VPValue *V) {
116
117 Worklist.push_back(V);
118
119 while (!Worklist.empty()) {
120 const VPValue *Current = Worklist.pop_back_val();
121 if (!Visited.insert(Current).second)
122 continue;
123
124 for (VPUser *U : Current->users()) {
125 // Check if Current is used as an address operand for load/store.
127 if (MemR->getAddr() == Current)
128 return true;
129 continue;
130 }
131 if (auto *Rep = dyn_cast<VPReplicateRecipe>(U)) {
132 unsigned Opcode = Rep->getOpcode();
133 if ((Opcode == Instruction::Load && Rep->getOperand(0) == Current) ||
134 (Opcode == Instruction::Store && Rep->getOperand(1) == Current))
135 return true;
136 }
137
138 // Check if poison propagates through this recipe to any of its users.
139 auto *R = cast<VPRecipeBase>(U);
140 for (const VPValue *Op : R->operands()) {
141 if (Op == Current && propagatesPoisonFromRecipeOp(R)) {
142 Worklist.push_back(R->getVPSingleValue());
143 break;
144 }
145 }
146 }
147 }
148
149 return false;
150}
151
153 // Like IR stripPointerCasts, look through GEPs with all-zero indices and
154 // casts to find a root GEP VPInstruction.
155 while (auto *PtrVPI = dyn_cast<VPInstruction>(Ptr)) {
156 unsigned Opcode = PtrVPI->getOpcode();
157 if (Opcode == Instruction::GetElementPtr) {
158 if (!all_of(drop_begin(PtrVPI->operands()), match_fn(m_ZeroInt())))
159 return PtrVPI->getGEPNoWrapFlags();
160 Ptr = PtrVPI->getOperand(0);
161 continue;
162 }
163 if (Opcode != Instruction::BitCast && Opcode != Instruction::AddrSpaceCast)
164 break;
165 Ptr = PtrVPI->getOperand(0);
166 }
167 return GEPNoWrapFlags::none();
168}
169
172 const Loop *L) {
173 ScalarEvolution &SE = *PSE.getSE();
175 Value *LiveIn = V->getUnderlyingValue();
176 if (LiveIn && SE.isSCEVable(LiveIn->getType()))
177 return SE.getSCEV(LiveIn);
178 return SE.getCouldNotCompute();
179 }
180
181 if (auto *RV = dyn_cast<VPRegionValue>(V)) {
182 assert(RV == RV->getDefiningRegion()->getCanonicalIV() &&
183 "RegionValue must be canonical IV");
184 if (!L)
185 return SE.getCouldNotCompute();
186 return SE.getAddRecExpr(SE.getZero(RV->getType()), SE.getOne(RV->getType()),
188 }
189
190 // Helper to create SCEVs for binary and unary operations.
191 auto CreateSCEV = [&](ArrayRef<VPValue *> Ops,
192 function_ref<const SCEV *(ArrayRef<SCEVUse>)> CreateFn)
193 -> const SCEV * {
195 for (VPValue *Op : Ops) {
196 const SCEV *S = getSCEVExprForVPValue(Op, PSE, L);
198 return SE.getCouldNotCompute();
199 SCEVOps.push_back(S);
200 }
201 return PSE.getPredicatedSCEV(CreateFn(SCEVOps));
202 };
203
204 VPValue *LHSVal, *RHSVal;
205 if (match(V, m_Add(m_VPValue(LHSVal), m_VPValue(RHSVal))))
206 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
207 return SE.getAddExpr(Ops[0], Ops[1], SCEV::FlagAnyWrap, 0);
208 });
209 if (match(V, m_Sub(m_VPValue(LHSVal), m_VPValue(RHSVal))))
210 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
211 return SE.getMinusSCEV(Ops[0], Ops[1], SCEV::FlagAnyWrap, 0);
212 });
213 if (match(V, m_Not(m_VPValue(LHSVal)))) {
214 // not X = xor X, -1 = -1 - X
215 return CreateSCEV({LHSVal}, [&](ArrayRef<SCEVUse> Ops) {
216 return SE.getMinusSCEV(SE.getMinusOne(Ops[0]->getType()), Ops[0]);
217 });
218 }
219 if (match(V, m_Mul(m_VPValue(LHSVal), m_VPValue(RHSVal))))
220 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
221 return SE.getMulExpr(Ops[0], Ops[1], SCEV::FlagAnyWrap, 0);
222 });
223 // Handle shl by constant: x << c is equivalent to x * (1 << c). A shift
224 // amount >= the bit width produces poison; do not rewrite it, as
225 // getPowerOfTwo requires the power to be in range.
226 uint64_t ShiftAmt;
227 if (match(V, m_Shl(m_VPValue(LHSVal), m_ConstantInt(ShiftAmt))) &&
228 ShiftAmt < LHSVal->getScalarType()->getScalarSizeInBits())
229 return CreateSCEV(LHSVal, [&](ArrayRef<SCEVUse> Ops) {
230 return SE.getMulExpr(Ops[0],
231 SE.getPowerOfTwo(Ops[0]->getType(), ShiftAmt));
232 });
233 if (match(V, m_LShr(m_VPValue(LHSVal), m_ConstantInt(ShiftAmt)))) {
234 Type *Ty = V->getScalarType();
235 if (ShiftAmt < SE.getTypeSizeInBits(Ty))
236 return CreateSCEV(LHSVal, [&](ArrayRef<SCEVUse> Ops) {
237 return SE.getUDivExpr(Ops[0], SE.getPowerOfTwo(Ty, ShiftAmt));
238 });
239 }
240 if (match(V, m_UDiv(m_VPValue(LHSVal), m_VPValue(RHSVal))))
241 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
242 return SE.getUDivExpr(Ops[0], Ops[1]);
243 });
244 if (match(V, m_URem(m_VPValue(LHSVal), m_VPValue(RHSVal))))
245 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
246 return SE.getURemExpr(Ops[0], Ops[1]);
247 });
248 // Handle AND with constant mask: x & (2^n - 1) can be represented as x % 2^n.
249 const APInt *Mask;
250 if (match(V, m_c_BinaryAnd(m_VPValue(LHSVal), m_APInt(Mask))) &&
251 (*Mask + 1).isPowerOf2())
252 return CreateSCEV({LHSVal}, [&](ArrayRef<SCEVUse> Ops) {
253 return SE.getURemExpr(Ops[0], SE.getConstant(*Mask + 1));
254 });
255 if (match(V, m_Trunc(m_VPValue(LHSVal)))) {
256 Type *DestTy = V->getScalarType();
257 return CreateSCEV({LHSVal}, [&](ArrayRef<SCEVUse> Ops) {
258 return SE.getTruncateExpr(Ops[0], DestTy);
259 });
260 }
261 if (match(V, m_ZExt(m_VPValue(LHSVal)))) {
262 Type *DestTy = V->getScalarType();
263 return CreateSCEV({LHSVal}, [&](ArrayRef<SCEVUse> Ops) {
264 return SE.getZeroExtendExpr(Ops[0], DestTy);
265 });
266 }
267 if (match(V, m_SExt(m_VPValue(LHSVal)))) {
268 Type *DestTy = V->getScalarType();
269
270 // Mirror SCEV's createSCEV handling for sext(sub nsw): push sign extension
271 // onto the operands before computing the subtraction.
272 VPValue *SubLHS, *SubRHS;
273 auto *SubR = dyn_cast<VPRecipeWithIRFlags>(LHSVal);
274 if (match(LHSVal, m_Sub(m_VPValue(SubLHS), m_VPValue(SubRHS))) && SubR &&
275 SubR->hasNoSignedWrap() && poisonGuaranteesUB(LHSVal)) {
276 const SCEV *V1 = getSCEVExprForVPValue(SubLHS, PSE, L);
277 const SCEV *V2 = getSCEVExprForVPValue(SubRHS, PSE, L);
279 return SE.getMinusSCEV(SE.getSignExtendExpr(V1, DestTy),
280 SE.getSignExtendExpr(V2, DestTy), SCEV::FlagNSW);
281 }
282
283 return CreateSCEV({LHSVal}, [&](ArrayRef<SCEVUse> Ops) {
284 return SE.getSignExtendExpr(Ops[0], DestTy);
285 });
286 }
287 if (match(V,
289 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
290 return SE.getUMaxExpr(Ops[0], Ops[1]);
291 });
292 if (match(V,
294 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
295 return SE.getSMaxExpr(Ops[0], Ops[1]);
296 });
297 if (match(V,
299 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
300 return SE.getUMinExpr(Ops[0], Ops[1]);
301 });
302 if (match(V,
304 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
305 return SE.getSMinExpr(Ops[0], Ops[1]);
306 });
308 return CreateSCEV({LHSVal}, [&](ArrayRef<SCEVUse> Ops) {
309 // is_int_min_poison is local to this intrinsic: poison on INT_MIN is
310 // not proof that the input is never INT_MIN, nor that poison reaches
311 // UB. Do not translate it to SCEV's global IsNSW flag.
312 return SE.getAbsExpr(Ops[0], /*IsNSW=*/false);
313 });
314
316 Type *SourceElementType;
317 if (match(V, m_GetElementPtr(SourceElementType, Ops))) {
318 return CreateSCEV(Ops, [&](ArrayRef<SCEVUse> Ops) {
319 return SE.getGEPExpr(Ops.front(), Ops.drop_front(), SourceElementType);
320 });
321 }
322
323 // TODO: Support constructing SCEVs for more recipes as needed.
324 const VPRecipeBase *DefR = V->getDefiningRecipe();
325 const SCEV *Expr =
327 .Case([](const VPExpandSCEVRecipe *R) { return R->getSCEV(); })
328 .Case([&SE, &PSE, L](const VPWidenIntOrFpInductionRecipe *R) {
329 const SCEV *Step = getSCEVExprForVPValue(R->getStepValue(), PSE, L);
330 if (!L || isa<SCEVCouldNotCompute>(Step))
331 return SE.getCouldNotCompute();
332 const SCEV *Start =
333 getSCEVExprForVPValue(R->getStartValue(), PSE, L);
334 const SCEV *AddRec =
335 SE.getAddRecExpr(Start, Step, L, SCEV::FlagAnyWrap);
336 if (R->getTruncInst())
337 return SE.getTruncateExpr(AddRec, R->getScalarType());
338 return AddRec;
339 })
340 .Case([&SE, &PSE, L](const VPWidenPointerInductionRecipe *R) {
341 const SCEV *Start =
342 getSCEVExprForVPValue(R->getStartValue(), PSE, L);
343 if (!L || isa<SCEVCouldNotCompute>(Start))
344 return SE.getCouldNotCompute();
345 const SCEV *Step = getSCEVExprForVPValue(R->getStepValue(), PSE, L);
346 if (isa<SCEVCouldNotCompute>(Step))
347 return SE.getCouldNotCompute();
348 return SE.getAddRecExpr(Start, Step, L, SCEV::FlagAnyWrap);
349 })
350 .Case([&SE, &PSE, L](const VPDerivedIVRecipe *R) {
351 const SCEV *Start = getSCEVExprForVPValue(R->getOperand(0), PSE, L);
352 const SCEV *IV = getSCEVExprForVPValue(R->getOperand(1), PSE, L);
353 const SCEV *Scale = getSCEVExprForVPValue(R->getOperand(2), PSE, L);
354 if (any_of(ArrayRef({Start, IV, Scale}),
356 return SE.getCouldNotCompute();
357
358 return SE.getAddExpr(
359 SE.getTruncateOrSignExtend(Start, IV->getType()),
360 SE.getMulExpr(
361 IV, SE.getTruncateOrSignExtend(Scale, IV->getType())));
362 })
363 .Case([&SE, &PSE, L](const VPScalarIVStepsRecipe *R) {
364 const SCEV *IV = getSCEVExprForVPValue(R->getOperand(0), PSE, L);
365 const SCEV *Step = getSCEVExprForVPValue(R->getOperand(1), PSE, L);
367 return SE.getCouldNotCompute();
368 return SE.getTruncateOrSignExtend(IV, Step->getType());
369 })
370 .Default(
371 [&SE](const VPRecipeBase *) { return SE.getCouldNotCompute(); });
372
373 return PSE.getPredicatedSCEV(Expr);
374}
375
377 const Loop *L) {
378 // If address is an SCEVAddExpr, we require that all operands must be either
379 // be invariant or a (possibly sign-extend) affine AddRec.
380 if (auto *PtrAdd = dyn_cast<SCEVAddExpr>(Addr)) {
381 return all_of(PtrAdd->operands(), [&SE, L](const SCEV *Op) {
382 return SE.isLoopInvariant(Op, L) ||
383 match(Op, m_scev_SExt(m_scev_AffineAddRec(m_SCEV(), m_SCEV()))) ||
384 match(Op, m_scev_AffineAddRec(m_SCEV(), m_SCEV()));
385 });
386 }
387
388 // Otherwise, check if address is loop invariant or an affine add recurrence.
389 return SE.isLoopInvariant(Addr, L) ||
391}
392
393/// Returns true if \p Opcode preserves uniformity, i.e., if all operands are
394/// uniform, the result will also be uniform.
395static bool preservesUniformity(unsigned Opcode) {
396 if (Instruction::isBinaryOp(Opcode) || Instruction::isCast(Opcode))
397 return true;
398 switch (Opcode) {
399 case Instruction::Freeze:
400 case Instruction::GetElementPtr:
401 case Instruction::ICmp:
402 case Instruction::FCmp:
403 case Instruction::Select:
408 return true;
409 default:
410 return false;
411 }
412}
413
415 // Live-in, symbolic and region-values represent single-scalar values.
417 return true;
418
419 if (auto *Rep = dyn_cast<VPReplicateRecipe>(VPV)) {
420 const VPRegionBlock *RegionOfR = Rep->getRegion();
421 // Don't consider recipes in replicate regions as uniform yet; their first
422 // lane cannot be accessed when executing the replicate region for other
423 // lanes.
424 if (RegionOfR && RegionOfR->isReplicator())
425 return false;
426 return Rep->isSingleScalar() || (preservesUniformity(Rep->getOpcode()) &&
427 all_of(Rep->operands(), isSingleScalar));
428 }
431 if (auto *WidenR = dyn_cast<VPWidenRecipe>(VPV)) {
432 return preservesUniformity(WidenR->getOpcode()) &&
433 all_of(WidenR->operands(), isSingleScalar);
434 }
435 if (auto *VPI = dyn_cast<VPInstruction>(VPV))
436 return VPI->isSingleScalar() || VPI->isVectorToScalar() ||
437 (preservesUniformity(VPI->getOpcode()) &&
438 all_of(VPI->operands(), isSingleScalar));
439 if (auto *RR = dyn_cast<VPReductionRecipe>(VPV))
440 return !RR->isPartialReduction();
442 VPV))
443 return true;
444 if (auto *Expr = dyn_cast<VPExpressionRecipe>(VPV))
445 return Expr->isVectorToScalar();
446
447 // VPExpandSCEVRecipes must be placed in the entry and are always uniform.
448 return isa<VPExpandSCEVRecipe>(VPV);
449}
450
452 // Live-ins and region values are uniform.
454 return true;
455
456 const VPRecipeBase *R = V->getDefiningRecipe();
457 const VPBasicBlock *VPBB = R ? R->getParent() : nullptr;
458 const VPlan *Plan = VPBB ? VPBB->getPlan() : nullptr;
459 if (VPBB) {
460 if ((VPBB == Plan->getVectorPreheader() || VPBB == Plan->getEntry())) {
461 if (match(V->getDefiningRecipe(),
463 return false;
464 return all_of(R->operands(), isUniformAcrossVFsAndUFs);
465 }
466 }
467
469 .Case([](const VPDerivedIVRecipe *R) { return true; })
470 .Case([](const VPReplicateRecipe *R) {
471 // Be conservative about side-effects, except for the
472 // known-side-effecting assumes and stores, which we know will be
473 // uniform.
474 return R->isSingleScalar() &&
475 (!R->mayHaveSideEffects() ||
476 isa<AssumeInst, StoreInst>(R->getUnderlyingInstr())) &&
477 all_of(R->operands(), isUniformAcrossVFsAndUFs);
478 })
479 .Case([](const VPWidenRecipe *R) {
480 return preservesUniformity(R->getOpcode()) &&
481 all_of(R->operands(), isUniformAcrossVFsAndUFs);
482 })
483 .Case([](const VPPhi *) {
484 // Bail out on VPPhi, as we can end up in infinite cycles.
485 return false;
486 })
487 .Case([](const VPInstruction *VPI) {
488 return (VPI->isSingleScalar() || VPI->isVectorToScalar() ||
491 })
492 .Case([](const VPWidenCastRecipe *R) {
493 // A cast is uniform according to its operand.
494 return isUniformAcrossVFsAndUFs(R->getOperand(0));
495 })
496 .Default([](const VPRecipeBase *) { // A value is considered non-uniform
497 // unless proven otherwise.
498 return false;
499 });
500}
501
503 auto DepthFirst = vp_depth_first_shallow(Plan.getEntry());
504 auto I = find_if(DepthFirst, [&VPDT](VPBlockBase *VPB) {
505 return VPBlockUtils::isHeader(VPB, VPDT);
506 });
507 return I == DepthFirst.end() ? nullptr : cast<VPBasicBlock>(*I);
508}
509
511 if (!R)
512 return 1;
513 if (auto *RR = dyn_cast<VPReductionPHIRecipe>(R))
514 return RR->getVFScaleFactor();
515 if (auto *RR = dyn_cast<VPReductionRecipe>(R))
516 return RR->getVFScaleFactor();
517 if (auto *ER = dyn_cast<VPExpressionRecipe>(R))
518 return ER->getVFScaleFactor();
519 assert(
520 (!isa<VPInstruction>(R) || cast<VPInstruction>(R)->getOpcode() !=
522 "getting scaling factor of reduction-start-vector not implemented yet");
523 return 1;
524}
525
526bool vputils::cannotHoistOrSinkRecipe(const VPRecipeBase &R, bool Sinking) {
527 // Assumes don't alias anything or throw; as long as they're guaranteed to
528 // execute, they're safe to hoist. They should however not be sunk, as it
529 // would destroy information.
531 return Sinking;
532 if (R.mayHaveSideEffects() || R.mayReadFromMemory() || R.isPhi())
533 return true;
534 // Allocas cannot be hoisted.
535 auto *RepR = dyn_cast<VPReplicateRecipe>(&R);
536 return RepR && RepR->getOpcode() == Instruction::Alloca;
537}
538
540 if (VPValue *AliasMask = findIncomingAliasMask(Plan)) {
541 assert(match(AliasMask->getSingleUser(),
542 m_c_BinaryAnd(m_VPValue(), m_Specific(AliasMask))) &&
543 "AliasMask must only be used with the original header mask");
544 return cast<VPSingleDefRecipe>(AliasMask->getSingleUser());
545 }
546
547 VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
548 SmallVector<VPValue *> WideCanonicalIVs;
549 auto *WideCanonicalIV =
551 assert(count_if(LoopRegion->getCanonicalIV()->users(),
553 "Must have at most one VPWideCanonicalIVRecipe");
554 if (WideCanonicalIV)
555 WideCanonicalIVs.push_back(WideCanonicalIV);
556
557 // Also include VPWidenIntOrFpInductionRecipes that represent a widened
558 // version of the canonical induction.
559 VPBasicBlock *HeaderVPBB = LoopRegion->getEntryBasicBlock();
560 for (VPRecipeBase &Phi : HeaderVPBB->phis()) {
562 if (match(&Phi, m_CanonicalWidenIV(WidenIV)))
563 WideCanonicalIVs.push_back(WidenIV);
564 }
565
566 // Walk users of wide canonical IVs and find the single compare of the form
567 // (ICMP_ULE, WideCanonicalIV, backedge-taken-count).
568 VPSingleDefRecipe *HeaderMask = nullptr;
569 for (auto *Wide : WideCanonicalIVs) {
570 for (VPUser *U : Wide->users()) {
571 auto *VPI = dyn_cast<VPInstruction>(U);
572 if (!VPI || !vputils::isHeaderMask(VPI, Plan))
573 continue;
574
575 assert(VPI->getOperand(0) == Wide &&
576 "WidenCanonicalIV must be the first operand of the compare");
577 assert(!HeaderMask && "Multiple header masks found?");
578 HeaderMask = VPI;
579 }
580 }
581
582 for (VPRecipeBase &R : LoopRegion->getEntryBasicBlock()->phis()) {
583 auto *Def = cast<VPSingleDefRecipe>(&R);
584 if (vputils::isHeaderMask(Def, Plan)) {
585 assert(!HeaderMask && "Multiple header masks found?");
586 HeaderMask = Def;
587 }
588 }
589
590 return HeaderMask;
591}
592
595 VPBasicBlock *LastBB) {
596 assert(FirstBB->getParent() == LastBB->getParent() &&
597 "FirstBB and LastBB from different regions");
598#ifndef NDEBUG
599 bool InSingleSuccChain = false;
600 for (VPBlockBase *Succ = FirstBB; Succ; Succ = Succ->getSingleSuccessor())
601 InSingleSuccChain |= (Succ == LastBB);
602 assert(InSingleSuccChain &&
603 "LastBB unreachable from FirstBB in single-successor chain");
604#endif
605 auto Blocks = to_vector(
607 auto *LastIt = find(Blocks, LastBB);
608 assert(LastIt != Blocks.end() &&
609 "LastBB unreachable from FirstBB in depth-first traversal");
610 Blocks.erase(std::next(LastIt), Blocks.end());
611 return Blocks;
612}
613
615 for (VPRecipeBase &R : *Plan.getVectorPreheader())
617 return cast<VPInstruction>(&R);
618 return nullptr;
619}
620
622 const VPDominatorTree &VPDT) {
623 auto *VPBB = dyn_cast<VPBasicBlock>(VPB);
624 if (!VPBB)
625 return false;
626
627 // If VPBB is in a region R, VPBB is a loop header if R is a loop region with
628 // VPBB as its entry, i.e., free of predecessors.
629 if (auto *R = VPBB->getParent())
630 return !R->isReplicator() && !VPBB->hasPredecessors();
631
632 // A header dominates its second predecessor (the latch), with the other
633 // predecessor being the preheader
634 return VPB->getPredecessors().size() == 2 &&
635 VPDT.dominates(VPB, VPB->getPredecessors()[1]);
636}
637
639 const VPDominatorTree &VPDT) {
640 // A latch has a header as its last successor, with its other successors
641 // leaving the loop. A preheader OTOH has a header as its first (and only)
642 // successor.
643 return VPB->getNumSuccessors() >= 2 &&
645}
646
647std::pair<VPBasicBlock *, VPBasicBlock *>
649 auto *Header = cast<VPBasicBlock>(
650 Plan.getEntry()->getSuccessors()[1]->getSingleSuccessor());
651 auto *Latch = cast<VPBasicBlock>(Header->getPredecessors()[1]);
652 return {Header, Latch};
653}
654
658
659std::optional<MemoryLocation>
661 auto *M = dyn_cast<VPIRMetadata>(&R);
662 if (!M)
663 return std::nullopt;
665 // Populate noalias metadata from VPIRMetadata.
666 if (MDNode *NoAliasMD = M->getMetadata(LLVMContext::MD_noalias))
667 Loc.AATags.NoAlias = NoAliasMD;
668 if (MDNode *AliasScopeMD = M->getMetadata(LLVMContext::MD_alias_scope))
669 Loc.AATags.Scope = AliasScopeMD;
670 return Loc;
671}
672
674 VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
675 VPRegionValue *CanIV = LoopRegion->getCanonicalIV();
676 assert(CanIV && "Expected loop region to have a canonical IV");
677
678 VPSymbolicValue &VFxUF = Plan.getVFxUF();
679
680 // Check if \p Step matches the expected increment step, accounting for
681 // materialization of VFxUF and UF.
682 auto IsIncrementStep = [&](VPValue *Step) -> bool {
683 if (!VFxUF.isMaterialized())
684 return Step == &VFxUF;
685
686 VPSymbolicValue &UF = Plan.getUF();
687 if (!UF.isMaterialized())
688 return Step == &UF ||
689 match(Step, m_c_Mul(m_Specific(&Plan.getUF()),
691
692 // Alias masking: step is number of active lanes of a dependence mask.
693 if (match(Step, m_ZExtOrTruncOrSelf(
695 return true;
696
697 unsigned ConcreteUF = Plan.getConcreteUF();
698 // Fixed VF: step is just the concrete UF.
699 if (match(Step, m_SpecificInt(ConcreteUF)))
700 return true;
701
702 // Scalable VF: step involves VScale.
703 if (ConcreteUF == 1)
705 if (match(Step, m_c_Mul(m_SpecificInt(ConcreteUF),
707 return true;
708 // mul(VScale, ConcreteUF) may have been simplified to
709 // shl(VScale, log2(ConcreteUF)) when ConcreteUF is a power of 2.
710 return isPowerOf2_32(ConcreteUF) &&
712 m_SpecificInt(Log2_32(ConcreteUF))));
713 };
714
715 VPInstruction *Increment = nullptr;
716 for (VPUser *U : CanIV->users()) {
717 VPValue *Step;
718 if (isa<VPInstruction>(U) &&
719 match(U, m_c_Add(m_Specific(CanIV), m_VPValue(Step))) &&
720 IsIncrementStep(Step)) {
721 assert(!Increment && "There must be a unique increment");
723 }
724 }
725
726 assert((!VFxUF.isMaterialized() || Increment) &&
727 "After materializing VFxUF, an increment must exist");
728 assert((!Increment ||
729 LoopRegion->hasCanonicalIVNUW() == Increment->hasNoUnsignedWrap()) &&
730 "NUW flag in region and increment must match");
731 return Increment;
732}
733
734/// Find the ComputeReductionResult recipe for \p PhiR, looking through selects
735/// inserted for predicated reductions or tail folding.
737 VPValue *BackedgeVal = PhiR->getBackedgeValue();
738 if (auto *Res =
740 return Res;
741
742 // Look through selects inserted for tail folding or predicated reductions.
743 VPRecipeBase *SelR =
744 findUserOf(BackedgeVal, m_Select(m_VPValue(), m_VPValue(), m_VPValue()));
745 if (!SelR)
746 return nullptr;
749}
750
753 SmallVector<const VPValue *> WorkList = {V};
754
755 while (!WorkList.empty()) {
756 const VPValue *Cur = WorkList.pop_back_val();
757 if (!Seen.insert(Cur).second)
758 continue;
759
760 auto *Blend = dyn_cast<VPBlendRecipe>(Cur);
761 // Skip blends that use V only through a compare by checking if any incoming
762 // value was already visited.
763 if (Blend && none_of(seq<unsigned>(0, Blend->getNumIncomingValues()),
764 [&](unsigned I) {
765 return Seen.contains(Blend->getIncomingValue(I));
766 }))
767 continue;
768
769 for (VPUser *U : Cur->users()) {
770 if (auto *InterleaveR = dyn_cast<VPInterleaveBase>(U))
771 if (InterleaveR->getAddr() == Cur)
772 return true;
773 // Cur is used as the pointer of a (possibly masked) load (operand 0) or
774 // store (operand 1).
777 m_Specific(Cur)))))
778 return true;
780 if (MemR->getAddr() == Cur && MemR->isConsecutive())
781 return true;
782 }
783 }
784
785 // The legacy cost model only supports scalarization loads/stores with phi
786 // addresses, if the phi is directly used as load/store address. Don't
787 // traverse further for Blends.
788 if (Blend)
789 continue;
790
791 // Only traverse further through users that also define a value (and can
792 // thus have their own users walked).
793 for (VPUser *U : Cur->users())
794 if (auto *SDR = dyn_cast<VPSingleDefRecipe>(U))
795 WorkList.push_back(SDR);
796 }
797 return false;
798}
799
800/// Try to find a loop-invariant IR value for \p S in the plan's entry block
801/// that can be reused. Returns the corresponding live-in VPValue, or nullptr
802/// if no reusable IR value is found.
803VPValue *VPSCEVExpander::tryToReuseIRValue(const SCEV *S) {
805 return nullptr;
806 VPlan &Plan = Builder.getPlan();
807 BasicBlock *PH = cast<VPIRBasicBlock>(Plan.getEntry())->getIRBasicBlock();
808 for (Value *V : SE.getSCEVValues(S)) {
809 // Only reuse instructions in the plan's entry block, or, when a
810 // DominatorTree is available, any instruction that dominates it.
811 // Instructions in sibling branches may not dominate the entry block.
812 auto *I = dyn_cast<Instruction>(V);
813 if (!I)
814 return Plan.getOrAddLiveIn(V);
815 if (!SE.DT.dominates(I->getParent(), PH))
816 continue;
817 SmallVector<Instruction *> DropPoisonGeneratingInsts;
818 if (!SE.canReuseInstruction(S, I, DropPoisonGeneratingInsts))
819 continue;
820 for (Instruction *DropI : DropPoisonGeneratingInsts)
822 return Plan.getOrAddLiveIn(V);
823 }
824 return nullptr;
825}
826
828 if (VPValue *V = tryToReuseIRValue(S))
829 return V;
830
831 switch (S->getSCEVType()) {
832 case scConstant:
833 return Builder.getPlan().getOrAddLiveIn(cast<SCEVConstant>(S)->getValue());
834 case scUnknown:
835 return Builder.getPlan().getOrAddLiveIn(cast<SCEVUnknown>(S)->getValue());
836 case scVScale:
837 return Builder.createNaryOp(VPInstruction::VScale, {}, S->getType());
838 case scAddExpr:
839 case scMulExpr: {
840 if (S->getType()->isPointerTy())
841 return nullptr;
842 auto *NAry = cast<SCEVNAryExpr>(S);
843 unsigned Opcode =
844 S->getSCEVType() == scAddExpr ? Instruction::Add : Instruction::Mul;
845 // Iterate in reverse so that constants are emitted last.
847 for (const SCEVUse &Op : reverse(NAry->operands())) {
848 VPValue *OpV = tryToExpand(Op);
849 if (!OpV)
850 return nullptr;
851 Ops.push_back(OpV);
852 }
853 VPIRFlags::WrapFlagsTy WrapFlags(NAry->hasNoUnsignedWrap(),
854 NAry->hasNoSignedWrap());
855 VPValue *Result = Ops.front();
856 for (VPValue *Op : drop_begin(Ops))
857 Result = Builder.createOverflowingOp(Opcode, {Result, Op}, WrapFlags, DL);
858 return Result;
859 }
860 case scUDivExpr: {
861 auto *UDiv = cast<SCEVUDivExpr>(S);
862 VPValue *LHS = tryToExpand(UDiv->getLHS());
863 if (!LHS)
864 return nullptr;
865 VPValue *RHS = tryToExpand(UDiv->getRHS());
866 if (!RHS)
867 return nullptr;
868 return Builder.createNaryOp(Instruction::UDiv, {LHS, RHS},
869 VPIRFlags::getDefaultFlags(Instruction::UDiv),
870 DL);
871 }
872 default:
873 return nullptr;
874 }
875}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static constexpr Value * getValue(Ty &ValueOrUse)
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
This file provides a LoopVectorizationPlanner class.
#define I(x, y, z)
Definition MD5.cpp:57
This file provides utility analysis objects describing memory locations.
static unsigned getScalarSizeInBits(Type *Ty)
This file implements the TypeSwitch template, which mimics a switch() statement whose cases are type ...
This file implements dominator tree analysis for a single level of a VPlan's H-CFG.
static bool propagatesPoisonFromRecipeOp(const VPRecipeBase *R)
Returns true if R propagates poison from any operand to its result.
static bool preservesUniformity(unsigned Opcode)
Returns true if Opcode preserves uniformity, i.e., if all operands are uniform, the result will also ...
static bool poisonGuaranteesUB(const VPValue *V)
Returns true if V being poison is guaranteed to trigger UB because it propagates to the address of a ...
static const uint32_t IV[8]
Definition blake3_impl.h:83
Class for arbitrary precision integers.
Definition APInt.h:78
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
LLVM Basic Block Representation.
Definition BasicBlock.h:62
bool dominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
dominates - Returns true iff A dominates B.
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
Represents flags for the getelementptr instruction/expression.
static GEPNoWrapFlags none()
bool isCast() const
bool isBinaryOp() const
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
Metadata node.
Definition Metadata.h:1069
Representation for a specific memory location.
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.
LLVM_ABI const SCEV * getPredicatedSCEV(const SCEV *Expr)
Returns the rewritten SCEV for Expr in the context of the current SCEV predicate.
static LLVM_ABI void dropPoisonGeneratingAnnotationsAndReinfer(ScalarEvolution &SE, Instruction *I)
Drop poison-generating flags from I, then try re-infer via SCEV.
This class represents an analyzed expression in the program.
static constexpr auto FlagAnyWrap
static constexpr auto FlagNSW
SCEVTypes getSCEVType() const
LLVM_ABI Type * getType() const
Return the LLVM type of this SCEV expression.
The main scalar evolution driver.
LLVM_ABI const SCEV * getUDivExpr(SCEVUse LHS, SCEVUse RHS)
Get a canonical unsigned division expression, or something simpler if possible.
LLVM_ABI const SCEV * getAbsExpr(const SCEV *Op, bool IsNSW)
LLVM_ABI const SCEV * getURemExpr(SCEVUse LHS, SCEVUse RHS)
Represents an unsigned remainder expression based on unsigned division.
LLVM_ABI const SCEV * getSMinExpr(SCEVUse LHS, SCEVUse RHS)
const SCEV * getZero(Type *Ty)
Return a SCEV for the constant 0 of a specific type.
LLVM_ABI uint64_t getTypeSizeInBits(Type *Ty) const
Return the size in bits of the specified type, for which isSCEVable must return true.
LLVM_ABI const SCEV * getConstant(ConstantInt *V)
LLVM_ABI const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
LLVM_ABI const SCEV * getMinusSCEV(SCEVUse LHS, SCEVUse RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Return LHS-RHS.
LLVM_ABI const SCEV * getAddRecExpr(SCEVUse Start, SCEVUse Step, const Loop *L, SCEV::NoWrapFlags Flags)
Get an add recurrence expression for the specified loop.
const SCEV * getOne(Type *Ty)
Return a SCEV for the constant 1 of a specific type.
LLVM_ABI bool isLoopInvariant(const SCEV *S, const Loop *L)
Return true if the value of the given SCEV is unchanging in the specified loop.
LLVM_ABI const SCEV * getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth=0)
LLVM_ABI bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
LLVM_ABI const SCEV * getTruncateExpr(const SCEV *Op, Type *Ty, unsigned Depth=0)
LLVM_ABI const SCEV * getUMaxExpr(SCEVUse LHS, SCEVUse RHS)
const SCEV * getMinusOne(Type *Ty)
Return a SCEV for the constant -1 of a specific type.
LLVM_ABI const SCEV * getCouldNotCompute()
LLVM_ABI const SCEV * getMulExpr(SmallVectorImpl< SCEVUse > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Get a canonical multiply expression, or something simpler if possible.
LLVM_ABI const SCEV * getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth=0)
const SCEV * getPowerOfTwo(Type *Ty, unsigned Power)
Return a SCEV for the constant Power of two.
LLVM_ABI const SCEV * getAddExpr(SmallVectorImpl< SCEVUse > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Get a canonical add expression, or something simpler if possible.
LLVM_ABI const SCEV * getSMaxExpr(SCEVUse LHS, SCEVUse RHS)
LLVM_ABI bool canReuseInstruction(const SCEV *S, Instruction *I, SmallVectorImpl< Instruction * > &DropPoisonGeneratingInsts)
Check whether it is poison-safe to represent the expression S using the instruction I.
LLVM_ABI const SCEV * getGEPExpr(GEPOperator *GEP, ArrayRef< SCEVUse > IndexExprs)
Returns an expression for a GEP.
LLVM_ABI const SCEV * getUMinExpr(SCEVUse LHS, SCEVUse RHS, bool Sequential=false)
LLVM_ABI const SCEV * getTruncateOrSignExtend(const SCEV *V, Type *Ty, unsigned Depth=0)
Return a SCEV corresponding to a conversion of the input value to the specified type.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class implements a switch-like dispatch statement for a value of 'T' using dyn_cast functionalit...
Definition TypeSwitch.h:89
TypeSwitch< T, ResultT > & Case(CallableT &&caseFn)
Add a case on the given type.
Definition TypeSwitch.h:98
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:282
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:368
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition VPlan.h:4407
iterator end()
Definition VPlan.h:4444
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
Definition VPlan.h:4495
iterator getFirstNonPhi()
Return the position of the first non-phi node recipe in the block.
Definition VPlan.cpp:266
void insert(VPRecipeBase *Recipe, iterator InsertPt)
Definition VPlan.h:4473
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition VPlan.h:94
VPRegionBlock * getParent()
Definition VPlan.h:186
size_t getNumSuccessors() const
Definition VPlan.h:237
const VPBlocksTy & getPredecessors() const
Definition VPlan.h:222
VPlan * getPlan()
Definition VPlan.cpp:211
const VPBasicBlock * getEntryBasicBlock() const
Definition VPlan.cpp:216
VPBlockBase * getSingleSuccessor() const
Definition VPlan.h:227
const VPBlocksTy & getSuccessors() const
Definition VPlan.h:211
static bool isLatch(const VPBlockBase *VPB, const VPDominatorTree &VPDT)
Returns true if VPB is a loop latch, using isHeader().
static VPBasicBlock * getPlainCFGMiddleBlock(const VPlan &Plan)
Returns the middle block of Plan in plain CFG form (before regions are formed).
static bool isHeader(const VPBlockBase *VPB, const VPDominatorTree &VPDT)
Returns true if VPB is a loop header, based on regions or VPDT in their absence.
static auto blocksOnly(T &&Range)
Return an iterator range over Range which only includes BlockTy blocks.
Definition VPlanUtils.h:312
static std::pair< VPBasicBlock *, VPBasicBlock * > getPlainCFGHeaderAndLatch(const VPlan &Plan)
Returns the header and latch of the outermost loop of Plan in plain CFG form (before regions are form...
static SmallVector< VPBasicBlock * > blocksInSingleSuccessorChainBetween(VPBasicBlock *FirstBB, VPBasicBlock *LastBB)
Returns the blocks between FirstBB and LastBB, where FirstBB to LastBB forms a single-sucessor chain.
A recipe for converting the input value IV value to the corresponding value of an IV with different s...
Definition VPlan.h:4188
Template specialization of the standard LLVM dominator tree utility for VPBlockBases.
Recipe to expand a SCEV expression.
Definition VPlan.h:4020
virtual VPValue * getBackedgeValue()
Returns the incoming value from the loop backedge.
Definition VPlan.h:2483
static VPIRFlags getDefaultFlags(unsigned Opcode)
Returns default flags for Opcode for opcodes that support it, asserts otherwise.
This is a concrete Recipe that models a single VPlan-level instruction.
Definition VPlan.h:1226
@ ReductionStartVector
Start vector for reductions with 3 operands: the original start value, the identity value for the red...
Definition VPlan.h:1315
@ VScale
Returns the value for vscale.
Definition VPlan.h:1348
unsigned getOpcode() const
Definition VPlan.h:1417
bool isVectorToScalar() const
Returns true if this VPInstruction produces a scalar value from a vector, e.g.
bool isSingleScalar() const
Returns true if this VPInstruction's operands are single scalars and the result is also a single scal...
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition VPlan.h:402
A recipe for handling reduction phis.
Definition VPlan.h:2864
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition VPlan.h:4617
bool isReplicator() const
An indicator whether this region is to generate multiple replicated instances of output IR correspond...
Definition VPlan.h:4693
bool hasCanonicalIVNUW() const
Indicates if NUW is set for the canonical IV increment, for loop regions.
Definition VPlan.h:4742
VPRegionValue * getCanonicalIV()
Return the canonical induction variable of the region, null for replicating regions.
Definition VPlan.h:4729
VPValues defined by a VPRegionBlock, like the canonical IV.
Definition VPlanValue.h:216
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition VPlan.h:3398
unsigned getOpcode() const
Definition VPlan.h:3491
VPValue * tryToExpand(const SCEV *S)
Try to expand S into recipes and live-ins using the builder.
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
Definition VPlan.h:4255
VPSingleDefRecipe is a base class for recipes that model a sequence of one or more output IR that def...
Definition VPlan.h:609
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
Definition VPlanValue.h:385
operand_range operands()
Definition VPlanValue.h:458
This is the base class of the VPlan Def/Use graph, used for modeling the data flow into,...
Definition VPlanValue.h:50
VPRecipeBase * getDefiningRecipe()
Returns the recipe defining this VPValue or nullptr if it is not defined by a recipe,...
Definition VPlan.cpp:130
user_range users()
Definition VPlanValue.h:157
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition VPlan.h:1878
A recipe for handling GEP instructions.
Definition VPlan.h:2206
A recipe for handling phi nodes of integer and floating-point inductions, producing their vector valu...
Definition VPlan.h:2623
VPWidenRecipe is a recipe for producing a widened instruction using the opcode and operands of the re...
Definition VPlan.h:1817
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition VPlan.h:4765
VPBasicBlock * getEntry()
Definition VPlan.h:4861
VPValue * getTripCount() const
The trip count of the original loop.
Definition VPlan.h:4920
VPSymbolicValue & getVFxUF()
Returns VF * UF of the vector loop region.
Definition VPlan.h:4960
VPValue * getBackedgeTakenCount() const
Definition VPlan.h:4947
VPIRValue * getOrAddLiveIn(Value *V)
Gets the live-in VPIRValue for V or adds a new live-in (if none exists yet) for V.
Definition VPlan.h:5034
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
Definition VPlan.cpp:1053
unsigned getConcreteUF() const
Returns the concrete UF of the plan, after unrolling.
Definition VPlan.h:5012
VPBasicBlock * getVectorPreheader() const
Returns the preheader of the vector loop region, if one exists, or null otherwise.
Definition VPlan.h:4866
VPSymbolicValue & getUF()
Returns the UF of the vector loop region.
Definition VPlan.h:4957
bool hasScalarVFOnly() const
Definition VPlan.h:5002
VPBasicBlock * getScalarPreheader() const
Return the VPBasicBlock for the preheader of the scalar loop.
Definition VPlan.h:4904
VPSymbolicValue & getVF()
Returns the VF of the vector loop region.
Definition VPlan.h:4953
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:255
An efficient, type-erasing, non-owning reference to a callable.
SpecificConstantMatch m_ZeroInt()
Convenience matchers for specific integer values.
BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)
Matches a register not-ed by a G_XOR.
match_combine_or< Ty... > m_CombineOr(const Ty &...Ps)
Combine pattern matchers matching any of Ps patterns.
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
CastInst_match< OpTy, TruncInst > m_Trunc(const OpTy &Op)
Matches Trunc.
specific_intval< false > m_SpecificInt(const APInt &V)
Match a specific integer value or vector with all elements equal to the value.
bool match(Val *V, const Pattern &P)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
auto match_fn(const Pattern &P)
A match functor that can be used as a UnaryPredicate in functional algorithms like all_of.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
IntrinsicID_match m_Intrinsic()
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
CastInst_match< OpTy, ZExtInst > m_ZExt(const OpTy &Op)
Matches ZExt.
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
auto m_ZExtOrTruncOrSelf(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::Add, true > m_c_Add(const LHS &L, const RHS &R)
Matches a Add with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
CastInst_match< OpTy, SExtInst > m_SExt(const OpTy &Op)
Matches SExt.
BinaryOp_match< LHS, RHS, Instruction::Mul, true > m_c_Mul(const LHS &L, const RHS &R)
Matches a Mul with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
auto m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
bool match(const SCEV *S, const Pattern &P)
SCEVAffineAddRec_match< Op0_t, Op1_t, match_isa< const Loop > > m_scev_AffineAddRec(const Op0_t &Op0, const Op1_t &Op1)
AllRecipe_commutative_match< Instruction::And, Op0_t, Op1_t > m_c_BinaryAnd(const Op0_t &Op0, const Op1_t &Op1)
Match a binary AND operation.
AllRecipe_match< Opcode, Op0_t, Op1_t > m_Binary(const Op0_t &Op0, const Op1_t &Op1)
AllRecipe_match< Opcode, Op0_t > m_Unary(const Op0_t &Op0)
canonical_widen_iv_match m_CanonicalWidenIV()
VPInstruction_match< VPInstruction::ActiveLaneMask, Op0_t, Op1_t, Op2_t > m_ActiveLaneMask(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2)
auto m_GetElementPtr(const Op0_t &Op0, const Op1_t &Op1)
canonical_iv_match m_CanonicalIV()
auto m_VPValue()
Match an arbitrary VPValue and ignore it.
match_bind< VPInstruction > m_VPInstruction(VPInstruction *&V)
Match a VPInstruction, capturing if we match.
auto m_DerivedIV(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2)
static VPRecipeBase * findUserOf(VPValue *V, const MatchT &P)
If V is used by a recipe matching pattern P, return it.
auto m_ScalarIVSteps(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2)
VPInstruction_match< VPInstruction::Reverse, Op0_t > m_Reverse(const Op0_t &Op0)
bool isSingleScalar(const VPValue *VPV)
Returns true if VPV is a single scalar, either because it produces the same value for all lanes or on...
VPValue * getOrCreateVPValueForSCEVExpr(VPlan &Plan, const SCEV *Expr)
Get or create a VPValue that corresponds to the expansion of Expr.
bool cannotHoistOrSinkRecipe(const VPRecipeBase &R, bool Sinking=false)
Return true if we do not know how to (mechanically) hoist or sink R.
VPBasicBlock * getFirstLoopHeader(VPlan &Plan, VPDominatorTree &VPDT)
Returns the header block of the first, top-level loop, or null if none exist.
bool isAddressSCEVForCost(const SCEV *Addr, ScalarEvolution &SE, const Loop *L)
Returns true if Addr is an address SCEV that can be passed to TTI::getAddressComputationCost,...
bool onlyFirstPartUsed(const VPValue *Def)
Returns true if only the first part of Def is used.
VPInstruction * findComputeReductionResult(VPReductionPHIRecipe *PhiR)
Find the ComputeReductionResult recipe for PhiR, looking through selects inserted for predicated redu...
VPInstruction * findCanonicalIVIncrement(VPlan &Plan)
Find the canonical IV increment of Plan's vector loop region.
std::optional< MemoryLocation > getMemoryLocation(const VPRecipeBase &R)
Return a MemoryLocation for R with noalias metadata populated from R, if the recipe is supported and ...
bool onlyFirstLaneUsed(const VPValue *Def)
Returns true if only the first lane of Def is used.
VPValue * findIncomingAliasMask(const VPlan &Plan)
Finds the incoming alias-mask within the vector preheader.
VPSingleDefRecipe * findHeaderMask(VPlan &Plan)
Collect the header mask with the pattern: (ICMP_ULE, WideCanonicalIV, backedge-taken-count) Note: If ...
bool onlyScalarValuesUsed(const VPValue *Def)
Returns true if only scalar values of Def are used by all users.
bool isUniformAcrossVFsAndUFs(const VPValue *V)
Checks if V is uniform across all VF lanes and UF parts.
bool isUsedByLoadStoreAddress(const VPValue *V)
Returns true if V is used as part of the address of another load or store.
GEPNoWrapFlags getGEPFlagsForPtr(VPValue *Ptr)
Returns the GEP nowrap flags for Ptr, looking through pointer casts mirroring Value::stripPointerCast...
const SCEV * getSCEVExprForVPValue(const VPValue *V, PredicatedScalarEvolution &PSE, const Loop *L=nullptr)
Return the SCEV expression for V.
unsigned getVFScaleFactor(VPRecipeBase *R)
Get the VF scaling factor applied to the recipe's output, if the recipe has one.
bool isHeaderMask(const VPValue *V, const VPlan &Plan)
Return true if V is a header mask in Plan.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition STLExtras.h:315
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1765
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:1739
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
iterator_range< df_iterator< VPBlockShallowTraversalWrapper< VPBlockBase * > > > vp_depth_first_shallow(VPBlockBase *G)
Returns an iterator range to traverse the graph starting at G in depth-first order.
Definition VPlanCFG.h:253
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:288
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:1746
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition MathExtras.h:331
auto reverse(ContainerTy &&C)
Definition STLExtras.h:407
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition MathExtras.h:279
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:1753
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...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
Definition STLExtras.h:2019
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1772
auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:305
@ Increment
Incrementally increasing token ID.
Definition AllocToken.h:26
@ Default
The result value is uniform if and only if all operands are uniform.
Definition Uniformity.h:20
constexpr detail::IsaCheckPredicate< Types... > IsaPred
Function object wrapper for the llvm::isa type check.
Definition Casting.h:866
SCEVUseT< const SCEV * > SCEVUse
A symbolic live-in VPValue, used for values like vector trip count, VF, and VFxUF.
Definition VPlanValue.h:287
bool isMaterialized() const
Returns true if this symbolic value has been materialized.
Definition VPlanValue.h:298