LLVM 24.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/MapVector.h"
16#include "llvm/ADT/SetVector.h"
18#include "llvm/ADT/TypeSwitch.h"
27#include "llvm/IR/Dominators.h"
30
31using namespace llvm;
32using namespace llvm::VPlanPatternMatch;
33using namespace llvm::SCEVPatternMatch;
34
36 return all_of(Def->users(),
37 [Def](const VPUser *U) { return U->usesFirstLaneOnly(Def); });
38}
39
41 return all_of(Def->users(),
42 [Def](const VPUser *U) { return U->usesFirstPartOnly(Def); });
43}
44
46 return all_of(Def->users(),
47 [Def](const VPUser *U) { return U->usesScalars(Def); });
48}
49
51 if (auto *E = dyn_cast<SCEVConstant>(Expr))
52 return Plan.getOrAddLiveIn(E->getValue());
53 // Skip SCEV expansion if Expr is a SCEVUnknown wrapping a non-instruction
54 // value. Otherwise the value may be defined in a loop and using it directly
55 // will break LCSSA form. The SCEV expansion takes care of preserving LCSSA
56 // form.
57 auto *U = dyn_cast<SCEVUnknown>(Expr);
58 if (U && !isa<Instruction>(U->getValue()))
59 return Plan.getOrAddLiveIn(U->getValue());
60 auto *Expanded = new VPExpandSCEVRecipe(Expr);
61 VPBasicBlock *EntryVPBB = Plan.getEntry();
62 auto Iter = EntryVPBB->getFirstNonPhi();
63 while (Iter != EntryVPBB->end() && isa<VPIRInstruction>(*Iter))
64 ++Iter;
65 EntryVPBB->insert(Expanded, Iter);
66 return Expanded;
67}
68
69/// Returns true if \p V being poison is guaranteed to trigger UB because it
70/// propagates to the address of a memory recipe.
71static bool poisonGuaranteesUB(const VPValue *V) {
74
75 auto PropagatesPoisonFromRecipeOp = [](const VPRecipeBase *R) {
77 return false;
78 unsigned Opcode = vputils::getOpcode(R->getVPSingleValue());
79 return Instruction::isCast(Opcode) || Opcode == Instruction::GetElementPtr;
80 };
81
82 Worklist.push_back(V);
83
84 while (!Worklist.empty()) {
85 const VPValue *Current = Worklist.pop_back_val();
86 if (!Visited.insert(Current).second)
87 continue;
88
89 for (VPUser *U : Current->users()) {
90 // Check if Current is used as an address operand for load/store.
91 auto *R = cast<VPRecipeBase>(U);
92 if (auto *MemR = dyn_cast<VPWidenMemoryRecipe>(R)) {
93 if (MemR->getAddr() == Current)
94 return true;
95 continue;
96 }
97 if (auto *Rep = dyn_cast<VPReplicateRecipe>(U)) {
98 unsigned Opcode = Rep->getOpcode();
99 if ((Opcode == Instruction::Load && Rep->getOperand(0) == Current) ||
100 (Opcode == Instruction::Store && Rep->getOperand(1) == Current))
101 return true;
102 }
103
104 // Check if poison propagates through this recipe to any of its users.
105 for (const VPValue *Op : R->operands()) {
106 if (Op == Current && PropagatesPoisonFromRecipeOp(R)) {
107 Worklist.push_back(R->getVPSingleValue());
108 break;
109 }
110 }
111 }
112 }
113
114 return false;
115}
116
118 // Like IR stripPointerCasts, look through GEPs with all-zero indices and
119 // casts to find a root GEP VPInstruction.
120 while (auto *PtrVPI = dyn_cast<VPInstruction>(Ptr)) {
121 unsigned Opcode = PtrVPI->getOpcode();
122 if (Opcode == Instruction::GetElementPtr) {
123 if (!all_of(drop_begin(PtrVPI->operands()), match_fn(m_ZeroInt())))
124 return PtrVPI->getGEPNoWrapFlags();
125 Ptr = PtrVPI->getOperand(0);
126 continue;
127 }
128 if (Opcode != Instruction::BitCast && Opcode != Instruction::AddrSpaceCast)
129 break;
130 Ptr = PtrVPI->getOperand(0);
131 }
132 return GEPNoWrapFlags::none();
133}
134
137 const Loop *L) {
138 ScalarEvolution &SE = *PSE.getSE();
139 if (auto *RV = dyn_cast<VPRegionValue>(V)) {
140 assert(RV == RV->getDefiningRegion()->getCanonicalIV() &&
141 "RegionValue must be canonical IV");
142 if (!L)
143 return SE.getCouldNotCompute();
144 return SE.getAddRecExpr(SE.getZero(RV->getType()), SE.getOne(RV->getType()),
145 L, SCEV::FlagNone);
146 }
147
149 Value *LiveIn = V->getUnderlyingValue();
150 if (LiveIn && SE.isSCEVable(LiveIn->getType()))
151 return SE.getSCEV(LiveIn);
152 return SE.getCouldNotCompute();
153 }
154
155 // Helper to create SCEVs for binary and unary operations.
156 auto CreateSCEV = [&](ArrayRef<VPValue *> Ops,
157 function_ref<const SCEV *(ArrayRef<SCEVUse>)> CreateFn)
158 -> const SCEV * {
160 for (VPValue *Op : Ops) {
161 const SCEV *S = getSCEVExprForVPValue(Op, PSE, L);
163 return SE.getCouldNotCompute();
164 SCEVOps.push_back(S);
165 }
166 return PSE.getPredicatedSCEV(CreateFn(SCEVOps));
167 };
168
169 VPValue *LHSVal, *RHSVal;
170 if (match(V, m_Add(m_VPValue(LHSVal), m_VPValue(RHSVal))))
171 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
172 return SE.getAddExpr(Ops[0], Ops[1], SCEV::FlagNone, 0);
173 });
174 if (match(V, m_BinaryOr(m_VPValue(LHSVal), m_VPValue(RHSVal))))
175 if (cast<VPRecipeWithIRFlags>(V->getDefiningRecipe())->isDisjoint())
176 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
177 return SE.getAddExpr(Ops[0], Ops[1], SCEV::FlagNone, 0);
178 });
179 if (match(V, m_Sub(m_VPValue(LHSVal), m_VPValue(RHSVal))))
180 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
181 return SE.getMinusSCEV(Ops[0], Ops[1], SCEV::FlagNone, 0);
182 });
183 if (match(V, m_Not(m_VPValue(LHSVal)))) {
184 // not X = xor X, -1 = -1 - X
185 return CreateSCEV({LHSVal}, [&](ArrayRef<SCEVUse> Ops) {
186 return SE.getMinusSCEV(SE.getMinusOne(Ops[0]->getType()), Ops[0]);
187 });
188 }
189 if (match(V, m_Mul(m_VPValue(LHSVal), m_VPValue(RHSVal))))
190 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
191 return SE.getMulExpr(Ops[0], Ops[1], SCEV::FlagNone, 0);
192 });
193 // Handle shl by constant: x << c is equivalent to x * (1 << c). A shift
194 // amount >= the bit width produces poison; do not rewrite it, as
195 // getPowerOfTwo requires the power to be in range.
196 uint64_t ShiftAmt;
197 if (match(V, m_Shl(m_VPValue(LHSVal), m_ConstantInt(ShiftAmt))) &&
198 ShiftAmt < LHSVal->getScalarType()->getScalarSizeInBits())
199 return CreateSCEV(LHSVal, [&](ArrayRef<SCEVUse> Ops) {
200 return SE.getMulExpr(Ops[0],
201 SE.getPowerOfTwo(Ops[0]->getType(), ShiftAmt));
202 });
203 if (match(V, m_LShr(m_VPValue(LHSVal), m_ConstantInt(ShiftAmt)))) {
204 Type *Ty = V->getScalarType();
205 if (ShiftAmt < SE.getTypeSizeInBits(Ty))
206 return CreateSCEV(LHSVal, [&](ArrayRef<SCEVUse> Ops) {
207 return SE.getUDivExpr(Ops[0], SE.getPowerOfTwo(Ty, ShiftAmt));
208 });
209 }
210 if (match(V, m_UDiv(m_VPValue(LHSVal), m_VPValue(RHSVal))))
211 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
212 return SE.getUDivExpr(Ops[0], Ops[1]);
213 });
214 if (match(V, m_URem(m_VPValue(LHSVal), m_VPValue(RHSVal))))
215 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
216 return SE.getURemExpr(Ops[0], Ops[1]);
217 });
218 // A SDiv with non-negative operands is equivalent to an UDiv.
219 if (match(V, m_SDiv(m_VPValue(LHSVal), m_VPValue(RHSVal)))) {
220 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
221 if (!SE.isKnownNonNegative(Ops[0]) || !SE.isKnownNonNegative(Ops[1]))
222 return SE.getCouldNotCompute();
223 return SE.getUDivExpr(Ops[0], Ops[1]);
224 });
225 }
226 // A SRem with non-negative operands is equivalent to an URem.
227 if (match(V, m_SRem(m_VPValue(LHSVal), m_VPValue(RHSVal)))) {
228 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
229 if (!SE.isKnownNonNegative(Ops[0]) || !SE.isKnownNonNegative(Ops[1]))
230 return SE.getCouldNotCompute();
231 return SE.getURemExpr(Ops[0], Ops[1]);
232 });
233 }
234 // Handle AND with constant mask: x & (2^n - 1) can be represented as x % 2^n.
235 const APInt *Mask;
236 if (match(V, m_c_BinaryAnd(m_VPValue(LHSVal), m_APInt(Mask))) &&
237 (*Mask + 1).isPowerOf2())
238 return CreateSCEV({LHSVal}, [&](ArrayRef<SCEVUse> Ops) {
239 return SE.getURemExpr(Ops[0], SE.getConstant(*Mask + 1));
240 });
241 // SCEV models ptrtoaddr, but not ptrtoint, mirroring createSCEV.
242 if (match(V, m_PtrToAddr(m_VPValue(LHSVal))))
243 return CreateSCEV({LHSVal}, [&](ArrayRef<SCEVUse> Ops) {
244 return SE.getPtrToAddrExpr(Ops[0]);
245 });
246 if (match(V, m_Trunc(m_VPValue(LHSVal)))) {
247 Type *DestTy = V->getScalarType();
248 return CreateSCEV({LHSVal}, [&](ArrayRef<SCEVUse> Ops) {
249 return SE.getTruncateExpr(Ops[0], DestTy);
250 });
251 }
252 if (match(V, m_ZExt(m_VPValue(LHSVal)))) {
253 Type *DestTy = V->getScalarType();
254 return CreateSCEV({LHSVal}, [&](ArrayRef<SCEVUse> Ops) {
255 return SE.getZeroExtendExpr(Ops[0], DestTy);
256 });
257 }
258 if (match(V, m_SExt(m_VPValue(LHSVal)))) {
259 Type *DestTy = V->getScalarType();
260
261 // Mirror SCEV's createSCEV handling for sext(sub nsw): push sign extension
262 // onto the operands before computing the subtraction.
263 VPValue *SubLHS, *SubRHS;
264 auto *SubR = dyn_cast<VPRecipeWithIRFlags>(LHSVal);
265 if (match(LHSVal, m_Sub(m_VPValue(SubLHS), m_VPValue(SubRHS))) && SubR &&
266 SubR->hasNoSignedWrap() && poisonGuaranteesUB(LHSVal)) {
267 const SCEV *V1 = getSCEVExprForVPValue(SubLHS, PSE, L);
268 const SCEV *V2 = getSCEVExprForVPValue(SubRHS, PSE, L);
270 return SE.getMinusSCEV(SE.getSignExtendExpr(V1, DestTy),
271 SE.getSignExtendExpr(V2, DestTy), SCEV::FlagNSW);
272 }
273
274 return CreateSCEV({LHSVal}, [&](ArrayRef<SCEVUse> Ops) {
275 return SE.getSignExtendExpr(Ops[0], DestTy);
276 });
277 }
278 if (match(V,
280 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
281 return SE.getUMaxExpr(Ops[0], Ops[1]);
282 });
283 if (match(V,
285 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
286 return SE.getSMaxExpr(Ops[0], Ops[1]);
287 });
288 if (match(V,
290 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
291 return SE.getUMinExpr(Ops[0], Ops[1]);
292 });
293 if (match(V,
295 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<SCEVUse> Ops) {
296 return SE.getSMinExpr(Ops[0], Ops[1]);
297 });
299 return CreateSCEV({LHSVal}, [&](ArrayRef<SCEVUse> Ops) {
300 // is_int_min_poison is local to this intrinsic: poison on INT_MIN is
301 // not proof that the input is never INT_MIN, nor that poison reaches
302 // UB. Do not translate it to SCEV's global IsNSW flag.
303 return SE.getAbsExpr(Ops[0], /*IsNSW=*/false);
304 });
305
307 Type *SourceElementType;
308 if (match(V, m_GetElementPtr(SourceElementType, Ops))) {
309 return CreateSCEV(Ops, [&](ArrayRef<SCEVUse> Ops) {
310 return SE.getGEPExpr(Ops.front(), Ops.drop_front(), SourceElementType);
311 });
312 }
313
314 // TODO: Support constructing SCEVs for more recipes as needed.
315 const VPRecipeBase *DefR = V->getDefiningRecipe();
316 const SCEV *Expr =
318 .Case([](const VPExpandSCEVRecipe *R) { return R->getSCEV(); })
319 .Case([&SE, &PSE, L](const VPWidenIntOrFpInductionRecipe *R) {
320 const SCEV *Step = getSCEVExprForVPValue(R->getStepValue(), PSE, L);
321 if (!L || isa<SCEVCouldNotCompute>(Step))
322 return SE.getCouldNotCompute();
323 const SCEV *Start =
324 getSCEVExprForVPValue(R->getStartValue(), PSE, L);
325 const SCEV *AddRec =
326 SE.getAddRecExpr(Start, Step, L, SCEV::FlagNone);
327 if (R->getTruncInst())
328 return SE.getTruncateExpr(AddRec, R->getScalarType());
329 return AddRec;
330 })
331 .Case([&SE, &PSE,
332 L](const VPWidenPointerInductionRecipe *R) -> const SCEV * {
333 const SCEV *Start =
334 getSCEVExprForVPValue(R->getStartValue(), PSE, L);
335 if (!L || isa<SCEVCouldNotCompute>(Start))
336 return SE.getCouldNotCompute();
337 const SCEV *Step = getSCEVExprForVPValue(R->getStepValue(), PSE, L);
338 if (isa<SCEVCouldNotCompute>(Step))
339 return SE.getCouldNotCompute();
340 return SE.getAddRecExpr(Start, Step, L, SCEV::FlagNone);
341 })
342 .Case([&SE, &PSE, L](const VPDerivedIVRecipe *R) -> const SCEV * {
343 const SCEV *Start = getSCEVExprForVPValue(R->getOperand(0), PSE, L);
344 const SCEV *IV = getSCEVExprForVPValue(R->getOperand(1), PSE, L);
345 const SCEV *Scale = getSCEVExprForVPValue(R->getOperand(2), PSE, L);
346 if (any_of(ArrayRef({Start, IV, Scale}),
348 return SE.getCouldNotCompute();
349
350 return SE.getAddExpr(
351 SE.getTruncateOrSignExtend(Start, IV->getType()),
352 SE.getMulExpr(
353 IV, SE.getTruncateOrSignExtend(Scale, IV->getType())));
354 })
355 .Case([&SE, &PSE, L](const VPScalarIVStepsRecipe *R) {
356 const SCEV *IV = getSCEVExprForVPValue(R->getOperand(0), PSE, L);
357 const SCEV *Step = getSCEVExprForVPValue(R->getOperand(1), PSE, L);
359 return SE.getCouldNotCompute();
360 return SE.getTruncateOrSignExtend(IV, Step->getType());
361 })
362 .Default(
363 [&SE](const VPRecipeBase *) { return SE.getCouldNotCompute(); });
364
365 return PSE.getPredicatedSCEV(Expr);
366}
367
368std::optional<int64_t>
370 PredicatedScalarEvolution &PSE, const Loop *L) {
371 assert(!hasIrregularType(AccessTy, L->getHeader()->getDataLayout()) &&
372 "should not try to widen irregular types");
373 const SCEV *AddrSCEV = getSCEVExprForVPValue(Addr, PSE, L);
374 auto *AddRec = dyn_cast<SCEVAddRecExpr>(AddrSCEV);
375 if (!AddRec)
376 return {};
377
378 return getStrideFromAddRec(AddRec, L, AccessTy, /*Ptr=*/nullptr, PSE);
379}
380
382 const Loop *L) {
383 // If address is an SCEVAddExpr, we require that all operands must be either
384 // be invariant or a (possibly sign-extend) affine AddRec.
385 if (auto *PtrAdd = dyn_cast<SCEVAddExpr>(Addr)) {
386 return all_of(PtrAdd->operands(), [&SE, L](const SCEV *Op) {
387 return SE.isLoopInvariant(Op, L) ||
388 match(Op, m_scev_SExt(m_scev_AffineAddRec(m_SCEV(), m_SCEV()))) ||
389 match(Op, m_scev_AffineAddRec(m_SCEV(), m_SCEV()));
390 });
391 }
392
393 // Otherwise, check if address is loop invariant or an affine add recurrence.
394 return SE.isLoopInvariant(Addr, L) ||
396}
397
398unsigned vputils::getOpcode(const VPValue *V) {
402 VPWidenLoadEVLRecipe>([](auto *I) { return I->getOpcode(); })
403 .Case<VPVectorPointerRecipe, VPPredInstPHIRecipe, VPScalarIVStepsRecipe>(
404 [](auto *I) {
405 // For recipes that do not directly map to LLVM IR instructions,
406 // assign opcodes after the last VPInstruction opcode (which is also
407 // after the last IR Instruction opcode), based on the VPRecipeID.
408 return VPInstruction::OpsEnd + 1 + I->getVPRecipeID();
409 })
410 .Default([](auto *) { return 0; });
411}
412
413std::optional<std::pair<bool, unsigned>>
416 return std::make_pair(true, IID);
417 if (unsigned Opcode = vputils::getOpcode(V))
418 return std::make_pair(false, Opcode);
419 return {};
420}
421
422/// Returns true if \p Opcode preserves uniformity, i.e., if all operands are
423/// uniform, the result will also be uniform.
424static bool preservesUniformity(unsigned Opcode) {
425 if (Instruction::isBinaryOp(Opcode) || Instruction::isCast(Opcode))
426 return true;
427 switch (Opcode) {
428 case Instruction::Freeze:
429 case Instruction::GetElementPtr:
430 case Instruction::ICmp:
431 case Instruction::FCmp:
432 case Instruction::Select:
437 return true;
438 default:
439 return false;
440 }
441}
442
444 // TODO: Handle more opcodes and recipes.
446 return false;
447 unsigned Opcode = getOpcode(V);
448 return Instruction::isUnaryOp(Opcode) || Instruction::isBinaryOp(Opcode);
449}
450
452 // Live-in, symbolic and canonical-IV region values are single-scalar.
453 if (auto *RV = dyn_cast<VPRegionValue>(VPV))
454 return RV == RV->getDefiningRegion()->getCanonicalIV();
456 return true;
457
458 if (auto *Rep = dyn_cast<VPReplicateRecipe>(VPV)) {
459 const VPRegionBlock *RegionOfR = Rep->getRegion();
460 // Don't consider recipes in replicate regions as uniform yet; their first
461 // lane cannot be accessed when executing the replicate region for other
462 // lanes.
463 if (RegionOfR && RegionOfR->isReplicator())
464 return false;
465 return Rep->isSingleScalar() || (preservesUniformity(Rep->getOpcode()) &&
466 all_of(Rep->operands(), isSingleScalar));
467 }
470 if (auto *WidenR = dyn_cast<VPWidenRecipe>(VPV)) {
471 return preservesUniformity(WidenR->getOpcode()) &&
472 all_of(WidenR->operands(), isSingleScalar);
473 }
474 if (auto *VPI = dyn_cast<VPInstruction>(VPV))
475 return VPI->isSingleScalar() || VPI->isVectorToScalar() ||
476 (preservesUniformity(VPI->getOpcode()) &&
477 all_of(VPI->operands(), isSingleScalar));
478 if (auto *RR = dyn_cast<VPReductionRecipe>(VPV))
479 return !RR->isPartialReduction();
481 VPV))
482 return true;
483 if (auto *Expr = dyn_cast<VPExpressionRecipe>(VPV))
484 return Expr->isVectorToScalar();
485
486 // VPExpandSCEVRecipes must be placed in the entry and are always uniform.
487 return isa<VPExpandSCEVRecipe>(VPV);
488}
489
491 // Live-ins, symbolic and canonical-IV region values are uniform.
492 if (auto *RV = dyn_cast<VPRegionValue>(V))
493 return RV == RV->getDefiningRegion()->getCanonicalIV();
495 return true;
496
497 const VPRecipeBase *R = V->getDefiningRecipe();
498 const VPBasicBlock *VPBB = R ? R->getParent() : nullptr;
499 const VPlan *Plan = VPBB ? VPBB->getPlan() : nullptr;
500 if (VPBB &&
501 (VPBB == Plan->getVectorPreheader() || VPBB == Plan->getEntry())) {
502 if (match(R,
505 return false;
506 return all_of(R->operands(), isUniformAcrossVFsAndUFs);
507 }
508
510 .Case([](const VPDerivedIVRecipe *R) { return true; })
511 .Case([](const VPReplicateRecipe *R) {
512 // Be conservative about side-effects, except for the
513 // known-side-effecting assumes and stores, which we know will be
514 // uniform. Each alloca creates a distinct allocation, so allocas are
515 // never uniform.
516 return R->isSingleScalar() && R->getOpcode() != Instruction::Alloca &&
517 (!R->mayHaveSideEffects() ||
518 isa<AssumeInst, StoreInst>(R->getUnderlyingInstr())) &&
519 all_of(R->operands(), isUniformAcrossVFsAndUFs);
520 })
521 .Case([](const VPWidenRecipe *R) {
522 return preservesUniformity(R->getOpcode()) &&
523 all_of(R->operands(), isUniformAcrossVFsAndUFs);
524 })
525 .Case([](const VPPhi *) {
526 // Bail out on VPPhi, as we can end up in infinite cycles.
527 return false;
528 })
529 .Case([](const VPInstruction *VPI) {
530 return (VPI->isSingleScalar() || VPI->isVectorToScalar() ||
533 })
534 .Case([](const VPWidenCastRecipe *R) {
535 // A cast is uniform according to its operand.
536 return isUniformAcrossVFsAndUFs(R->getOperand(0));
537 })
538 .Default([](const VPRecipeBase *) { // A value is considered non-uniform
539 // unless proven otherwise.
540 return false;
541 });
542}
543
545 if (auto *RepR = dyn_cast<VPReplicateRecipe>(R))
546 return RepR->doesGeneratePerAllLanes();
547 if (auto *VPI = dyn_cast<VPInstruction>(R))
548 return VPI->doesGeneratePerAllLanes();
549 if (auto *SIVSteps = dyn_cast<VPScalarIVStepsRecipe>(R))
550 return SIVSteps->doesGeneratePerAllLanes();
551 return false;
552}
553
555 auto DepthFirst = vp_depth_first_shallow(Plan.getEntry());
556 auto I = find_if(DepthFirst, [&VPDT](VPBlockBase *VPB) {
557 return VPBlockUtils::isHeader(VPB, VPDT);
558 });
559 return I == DepthFirst.end() ? nullptr : cast<VPBasicBlock>(*I);
560}
561
563 if (!R)
564 return 1;
565 if (auto *RR = dyn_cast<VPReductionPHIRecipe>(R))
566 return RR->getVFScaleFactor();
567 if (auto *RR = dyn_cast<VPReductionRecipe>(R))
568 return RR->getVFScaleFactor();
569 if (auto *ER = dyn_cast<VPExpressionRecipe>(R))
570 return ER->getVFScaleFactor();
571 assert(
574 "getting scaling factor of reduction-start-vector not implemented yet");
575 return 1;
576}
577
578bool vputils::cannotHoistOrSinkRecipe(const VPRecipeBase &R, bool Sinking) {
579 // Assumes don't alias anything or throw; as long as they're guaranteed to
580 // execute, they're safe to hoist. They should however not be sunk, as it
581 // would destroy information.
583 return Sinking;
584 if (R.mayHaveSideEffects() || R.mayReadFromMemory() || R.isPhi())
585 return true;
586 // Allocas cannot be hoisted.
587 auto *RepR = dyn_cast<VPReplicateRecipe>(&R);
588 return RepR && RepR->getOpcode() == Instruction::Alloca;
589}
590
593 VPBasicBlock *LastBB) {
594 assert(FirstBB->getParent() == LastBB->getParent() &&
595 "FirstBB and LastBB from different regions");
596#ifndef NDEBUG
597 bool InSingleSuccChain = false;
598 for (VPBlockBase *Succ = FirstBB; Succ; Succ = Succ->getSingleSuccessor())
599 InSingleSuccChain |= (Succ == LastBB);
600 assert(InSingleSuccChain &&
601 "LastBB unreachable from FirstBB in single-successor chain");
602#endif
603 auto Blocks = to_vector(
605 auto *LastIt = find(Blocks, LastBB);
606 assert(LastIt != Blocks.end() &&
607 "LastBB unreachable from FirstBB in depth-first traversal");
608 Blocks.erase(std::next(LastIt), Blocks.end());
609 return Blocks;
610}
611
613 for (VPRecipeBase &R : *Plan.getVectorPreheader())
615 return cast<VPInstruction>(&R);
616 return nullptr;
617}
618
620vputils::getEarlyExits(const VPlan &Plan, const VPBlockBase *MiddleVPBB) {
622 for (VPIRBasicBlock *ExitVPBB : Plan.getExitBlocks())
623 for (VPBlockBase *Pred : ExitVPBB->getPredecessors())
624 if (Pred != MiddleVPBB)
625 Exits.emplace_back(cast<VPBasicBlock>(Pred), ExitVPBB);
626 return Exits;
627}
628
631 Instruction::BinaryOps InductionOpcode, FPMathOperator *FPBinOp,
632 Instruction *TruncI, VPValue *StartV, VPValue *Step, DebugLoc DL,
633 VPBuilder &Builder, const VPIRFlags::WrapFlagsTy &Flags) {
634 VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
635 VPBasicBlock *HeaderVPBB = LoopRegion->getEntryBasicBlock();
636 VPValue *CanonicalIV = LoopRegion->getCanonicalIV();
637 VPSingleDefRecipe *BaseIV =
638 Builder.createDerivedIV(Kind, FPBinOp, StartV, CanonicalIV, Step, Flags);
639
640 // Truncate base induction if needed.
641 Type *ResultTy = BaseIV->getScalarType();
642 if (TruncI) {
643 Type *TruncTy = TruncI->getType();
644 assert(ResultTy->getScalarSizeInBits() > TruncTy->getScalarSizeInBits() &&
645 "Not truncating.");
646 assert(ResultTy->isIntegerTy() && "Truncation requires an integer type");
647 BaseIV = Builder.createScalarCast(Instruction::Trunc, BaseIV, TruncTy, DL);
648 ResultTy = TruncTy;
649 }
650
651 // Truncate step if needed.
652 Type *StepTy = Step->getScalarType();
653 if (ResultTy != StepTy) {
654 assert(StepTy->getScalarSizeInBits() > ResultTy->getScalarSizeInBits() &&
655 "Not truncating.");
656 assert(StepTy->isIntegerTy() && "Truncation requires an integer type");
657 auto *VecPreheader =
659 VPBuilder::InsertPointGuard Guard(Builder);
660 Builder.setInsertPoint(VecPreheader);
661 Step = Builder.createScalarCast(Instruction::Trunc, Step, ResultTy, DL);
662 }
663 return Builder.createScalarIVSteps(InductionOpcode, FPBinOp, BaseIV, Step,
664 &Plan.getVF(), DL);
665}
666
667VPValue *
669 VPlan &Plan, VPBuilder &Builder) {
670 const InductionDescriptor &ID = PtrIV->getInductionDescriptor();
671 VPIRValue *StartV = Plan.getZero(ID.getStep()->getType());
672 VPValue *StepV = PtrIV->getOperand(1);
674 Plan, InductionDescriptor::IK_IntInduction, Instruction::Add, nullptr,
675 nullptr, StartV, StepV, PtrIV->getDebugLoc(), Builder);
676
677 return Builder.createPtrAdd(PtrIV->getStartValue(), Steps,
678 PtrIV->getDebugLoc(), "next.gep");
679}
680
682 const VPDominatorTree &VPDT) {
683 auto *VPBB = dyn_cast<VPBasicBlock>(VPB);
684 if (!VPBB)
685 return false;
686
687 // If VPBB is in a region R, VPBB is a loop header if R is a loop region with
688 // VPBB as its entry, i.e., free of predecessors.
689 if (auto *R = VPBB->getParent())
690 return !R->isReplicator() && !VPBB->hasPredecessors();
691
692 // A header dominates its second predecessor (the latch), with the other
693 // predecessor being the preheader
694 return VPB->getPredecessors().size() == 2 &&
695 VPDT.dominates(VPB, VPB->getPredecessors()[1]);
696}
697
699 const VPDominatorTree &VPDT) {
700 // A latch has a header as its last successor, with its other successors
701 // leaving the loop. A preheader OTOH has a header as its first (and only)
702 // successor.
703 return VPB->getNumSuccessors() >= 2 &&
705}
706
707std::pair<VPBasicBlock *, VPBasicBlock *>
710 Plan.getEntry()->getNumSuccessors() == 1
711 ? Plan.getEntry()->getSingleSuccessor()
712 : Plan.getEntry()->getSuccessors()[1]->getSingleSuccessor());
713 assert(Header->getNumPredecessors() == 2 &&
714 "Header must have exactly 2 predecessors");
715 auto *Latch = cast<VPBasicBlock>(Header->getPredecessors()[1]);
716 return {Header, Latch};
717}
718
722
724 const VPPhi *PhiR) {
725 if (ID.getKind() == InductionDescriptor::IK_FpInduction)
726 return ID.getInductionBinOp()->getFastMathFlags();
727
728 // The flags only bound the induction values if the increment directly
729 // updates PhiR.
730 VPValue *Inc = PhiR->getOperand(1);
731 if (match(Inc, m_c_Add(m_Specific(PhiR), m_VPValue())))
732 return cast<VPInstruction>(Inc)->getNoWrapFlagsOrNone();
733
734 if (match(Inc, m_Sub(m_Specific(PhiR), m_VPValue()))) {
735 // The step of a sub induction is negated, so NUW cannot be preserved. NSW
736 // can, if the step is not the signed minimum.
737 ConstantInt *Step = ID.getConstIntStepValue();
738 bool NSW = cast<VPInstruction>(Inc)->getNoWrapFlagsOrNone().HasNSW &&
739 Step && !Step->isMinValue(/*IsSigned=*/true);
740 return VPIRFlags::WrapFlagsTy(/*NUW*/ false, NSW);
741 }
742
743 return VPIRFlags::WrapFlagsTy(false, false);
744}
745
746std::optional<MemoryLocation>
748 auto *M = dyn_cast<VPIRMetadata>(&R);
749 if (!M)
750 return std::nullopt;
752 // Populate noalias metadata from VPIRMetadata.
753 if (MDNode *NoAliasMD = M->getMetadata(LLVMContext::MD_noalias))
754 Loc.AATags.NoAlias = NoAliasMD;
755 if (MDNode *AliasScopeMD = M->getMetadata(LLVMContext::MD_alias_scope))
756 Loc.AATags.Scope = AliasScopeMD;
757 return Loc;
758}
759
761 VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
762 VPRegionValue *CanIV = LoopRegion->getCanonicalIV();
763 assert(CanIV && "Expected loop region to have a canonical IV");
764
765 VPSymbolicValue &VFxUF = Plan.getVFxUF();
766
767 // Check if \p Step matches the expected increment step, accounting for
768 // materialization of VFxUF and UF.
769 auto IsIncrementStep = [&](VPValue *Step) -> bool {
770 if (!VFxUF.isMaterialized())
771 return Step == &VFxUF;
772
773 VPSymbolicValue &UF = Plan.getUF();
774 if (!UF.isMaterialized())
775 return Step == &UF ||
776 match(Step, m_c_Mul(m_Specific(&Plan.getUF()), m_VScale()));
777
778 // Alias masking: step is number of active lanes of a dependence mask.
779 if (match(Step, m_ZExtOrTruncOrSelf(
781 return true;
782
783 unsigned ConcreteUF = Plan.getConcreteUF();
784 // Fixed VF: step is just the concrete UF.
785 if (match(Step, m_SpecificInt(ConcreteUF)))
786 return true;
787
788 // Scalable VF: step involves VScale.
789 if (ConcreteUF == 1)
790 return match(Step, m_VScale());
791 if (match(Step, m_c_Mul(m_SpecificInt(ConcreteUF), m_VScale())))
792 return true;
793 // mul(VScale, ConcreteUF) may have been simplified to
794 // shl(VScale, log2(ConcreteUF)) when ConcreteUF is a power of 2.
795 return isPowerOf2_32(ConcreteUF) &&
796 match(Step, m_Shl(m_VScale(), m_SpecificInt(Log2_32(ConcreteUF))));
797 };
798
799 VPInstruction *Increment = nullptr;
800 for (VPUser *U : CanIV->users()) {
801 VPValue *Step;
802 if (isa<VPInstruction>(U) &&
803 match(U, m_c_Add(m_Specific(CanIV), m_VPValue(Step))) &&
804 IsIncrementStep(Step)) {
805 assert(!Increment && "There must be a unique increment");
807 }
808 }
809
810 assert((!VFxUF.isMaterialized() || Increment) &&
811 "After materializing VFxUF, an increment must exist");
812 assert((!Increment ||
813 LoopRegion->hasCanonicalIVNUW() == Increment->hasNoUnsignedWrap()) &&
814 "NUW flag in region and increment must match");
815 return Increment;
816}
817
818/// Find the ComputeReductionResult recipe for \p PhiR, looking through selects
819/// inserted for predicated reductions or tail folding.
821 VPValue *BackedgeVal = PhiR->getBackedgeValue();
822 if (auto *Res =
824 return Res;
825
826 // Look through selects inserted for tail folding or predicated reductions.
827 VPRecipeBase *SelR =
828 findUserOf(BackedgeVal, m_Select(m_VPValue(), m_VPValue(), m_VPValue()));
829 if (!SelR)
830 return nullptr;
833}
834
837 SmallVector<const VPValue *> WorkList = {V};
838
839 while (!WorkList.empty()) {
840 const VPValue *Cur = WorkList.pop_back_val();
841 if (!Seen.insert(Cur).second)
842 continue;
843
844 auto *Blend = dyn_cast<VPBlendRecipe>(Cur);
845 // Skip blends that use V only through a compare by checking if any incoming
846 // value was already visited.
847 if (Blend && none_of(seq<unsigned>(0, Blend->getNumIncomingValues()),
848 [&](unsigned I) {
849 return Seen.contains(Blend->getIncomingValue(I));
850 }))
851 continue;
852
853 for (VPUser *U : Cur->users()) {
854 if (auto *InterleaveR = dyn_cast<VPInterleaveBase>(U))
855 if (InterleaveR->getAddr() == Cur)
856 return true;
857 // Cur is used as the pointer of a (possibly masked) load (operand 0) or
858 // store (operand 1).
861 m_Specific(Cur)))))
862 return true;
864 if (MemR->getAddr() == Cur && MemR->isConsecutive())
865 return true;
866 }
867 }
868
869 // The legacy cost model only supports scalarization loads/stores with phi
870 // addresses, if the phi is directly used as load/store address. Don't
871 // traverse further for Blends.
872 if (Blend)
873 continue;
874
875 // Only traverse further through users that also define a value (and can
876 // thus have their own users walked). Skip when Cur is only used as mask ,
877 // as well as loads: a loaded value does not depend on the load's operand.
878 for (VPUser *U : Cur->users()) {
879 auto *VPI = dyn_cast<VPInstruction>(U);
880 if (VPI && VPI->getMask() == Cur &&
881 none_of(VPI->operandsWithoutMask(), equal_to(Cur)))
882 continue;
884 continue;
885 if (auto *SDR = dyn_cast<VPSingleDefRecipe>(U))
886 WorkList.push_back(SDR);
887 }
888 }
889 return false;
890}
891
892/// Try to find a loop-invariant IR value for \p S in the plan's entry block
893/// that can be reused. Returns the corresponding live-in VPValue, or nullptr
894/// if no reusable IR value is found.
895VPValue *VPSCEVExpander::tryToReuseIRValue(const SCEV *S) {
897 return nullptr;
898 VPlan &Plan = Builder.getPlan();
899 BasicBlock *PH = cast<VPIRBasicBlock>(Plan.getEntry())->getIRBasicBlock();
900 for (Value *V : SE.getSCEVValues(S)) {
901 // Only reuse instructions in the plan's entry block, or, when a
902 // DominatorTree is available, any instruction that dominates it.
903 // Instructions in sibling branches may not dominate the entry block.
904 auto *I = dyn_cast<Instruction>(V);
905 if (!I)
906 return Plan.getOrAddLiveIn(V);
907 if (!SE.DT.dominates(I->getParent(), PH))
908 continue;
909 SmallVector<Instruction *> DropPoisonGeneratingInsts;
910 if (!SE.canReuseInstruction(S, I, DropPoisonGeneratingInsts))
911 continue;
912 for (Instruction *DropI : DropPoisonGeneratingInsts)
914 return Plan.getOrAddLiveIn(V);
915 }
916 return nullptr;
917}
918
920 if (VPValue *V = tryToReuseIRValue(S))
921 return V;
922
923 switch (S->getSCEVType()) {
924 case scConstant:
925 return Builder.getPlan().getOrAddLiveIn(cast<SCEVConstant>(S)->getValue());
926 case scUnknown:
927 return Builder.getPlan().getOrAddLiveIn(cast<SCEVUnknown>(S)->getValue());
928 case scVScale:
929 return Builder.createVScale(S->getType(), DL);
930 case scAddExpr: {
931 auto *AddE = cast<SCEVAddExpr>(S);
932 VPIRFlags::WrapFlagsTy WrapFlags(AddE->hasNoUnsignedWrap(),
933 AddE->hasNoSignedWrap());
934
935 // Expand pointer SCEVAddExpr as a ptradd of the pointer base and the
936 // integer offset, matching SCEVExpander.
937 if (S->getType()->isPointerTy()) {
938 VPValue *Base = expand(SE.getPointerBase(S));
939 VPValue *Offset = expand(SE.removePointerBase(S));
940 GEPNoWrapFlags GEPFlags = WrapFlags.HasNUW
943 return Builder.createNoWrapPtrAdd(Base, Offset, GEPFlags, DL);
944 }
945
946 // Non-constant-negative add operands are expanded negated and subtracted
947 // from the running result below, instead of being negated and added.
948 auto UseSubtract = [](const SCEV *Op) {
949 return Op->isNonConstantNegative();
950 };
951 // Iterate in reverse so that constants are emitted last, and move the
952 // subtracted operands last, matching SCEVExpander's LoopCompare, so that
953 // they don't start the running result.
954 SmallVector<const SCEV *, 2> SCEVOps(reverse(AddE->operands()));
955 stable_sort(SCEVOps, [&](const SCEV *L, const SCEV *R) {
956 return !UseSubtract(L) && UseSubtract(R);
957 });
959 for (const SCEV *Op : SCEVOps) {
960 // The first operand starts the result, so it is never subtracted.
961 bool Negate = !Ops.empty() && UseSubtract(Op);
962 Ops.push_back(expand(Negate ? SE.getNegativeSCEV(Op) : Op));
963 }
964 VPValue *Result = Ops.front();
965 for (auto [Op, OpV] : drop_begin(zip_equal(SCEVOps, Ops))) {
966 if (UseSubtract(Op)) {
967 // Result + (-Op) == Result - Op, which saves the multiply for the
968 // negation. NSW only transfers if negating Op cannot overflow, see
969 // ScalarEvolution::getMinusSCEV.
970 bool HasNSW =
971 WrapFlags.HasNSW && !SE.getSignedRangeMin(Op).isMinSignedValue();
972 Result = Builder.createOverflowingOp(Instruction::Sub, {Result, OpV},
973 {/*HasNUW=*/false, HasNSW}, DL);
974 continue;
975 }
976 Result = Builder.createOverflowingOp(Instruction::Add, {Result, OpV},
977 WrapFlags, DL);
978 }
979 return Result;
980 }
981 case scMulExpr: {
982 auto *MulE = cast<SCEVMulExpr>(S);
983 VPIRFlags::WrapFlagsTy WrapFlags(MulE->hasNoUnsignedWrap(),
984 MulE->hasNoSignedWrap());
986 for (const SCEV *Op : reverse(MulE->operands()))
987 Ops.push_back(expand(Op));
988 VPValue *Result = Ops.front();
989 for (VPValue *OpV : drop_begin(Ops)) {
990 Result = Builder.createOverflowingOp(Instruction::Mul, {Result, OpV},
991 WrapFlags, DL);
992 }
993 return Result;
994 }
995 case scUDivExpr: {
996 auto *UDiv = cast<SCEVUDivExpr>(S);
997 VPValue *LHS = expand(UDiv->getLHS());
998 const SCEV *RHSExpr = UDiv->getRHS();
999 VPValue *RHS = expand(RHSExpr);
1000 if (SafeUDivMode) {
1001 // Make sure the UDiv's divisor is guaranteed to not be zero/poison, to
1002 // avoid UB.
1003 Type *Ty = UDiv->getType();
1004 bool GuaranteedNotPoison =
1006 if (!GuaranteedNotPoison)
1007 RHS = Builder.createFreeze(RHS, DL);
1008 if (!SE.isKnownNonZero(RHSExpr) || !GuaranteedNotPoison)
1009 RHS = Builder.createScalarIntrinsic(
1010 Intrinsic::umax, {RHS, Builder.getPlan().getConstantInt(Ty, 1)}, Ty,
1011 DL);
1012 }
1013 return Builder.createNaryOp(Instruction::UDiv, {LHS, RHS},
1014 VPIRFlags::getDefaultFlags(Instruction::UDiv),
1015 DL);
1016 }
1017 case scTruncate:
1018 case scZeroExtend:
1019 case scSignExtend:
1020 case scPtrToAddr: {
1021 auto *Cast = cast<SCEVCastExpr>(S);
1022 VPValue *Op = expand(Cast->getOperand());
1023 Instruction::CastOps Opcode;
1024 switch (S->getSCEVType()) {
1025 case scTruncate:
1026 Opcode = Instruction::Trunc;
1027 break;
1028 case scZeroExtend:
1029 Opcode = Instruction::ZExt;
1030 break;
1031 case scSignExtend:
1032 Opcode = Instruction::SExt;
1033 break;
1034 case scPtrToAddr:
1035 Opcode = Instruction::PtrToAddr;
1036 break;
1037 default:
1038 llvm_unreachable("Unhandled cast SCEV");
1039 }
1040
1041 // When expanding ptrtoaddr, first check if there's an existing ptrtoint we
1042 // can reuse.
1043 if (Opcode == Instruction::PtrToAddr) {
1044 VPlan &Plan = Builder.getPlan();
1045 BasicBlock *PH = cast<VPIRBasicBlock>(Plan.getEntry())->getIRBasicBlock();
1046 if (auto *IRV = dyn_cast<VPIRValue>(Op)) {
1048 IRV->getValue(), S->getType(), PH->getDataLayout(),
1049 [&](const CastInst *CI) {
1050 return SE.DT.dominates(CI->getParent(), PH);
1051 }))
1052 return Plan.getOrAddLiveIn(CI);
1053 }
1054 }
1055
1056 std::optional<VPIRFlags> Flags;
1057 if (Opcode == Instruction::ZExt)
1058 Flags =
1059 VPIRFlags::NonNegFlagsTy(SE.isKnownNonNegative(Cast->getOperand()));
1060
1061 return Builder.createScalarCast(Opcode, Op, S->getType(), DL, Flags);
1062 }
1063 case scUMaxExpr:
1064 case scSMaxExpr:
1065 case scUMinExpr:
1066 case scSMinExpr:
1067 case scSequentialUMinExpr: {
1068 auto *MinMax = cast<SCEVNAryExpr>(S);
1069 Intrinsic::ID IntrinsicID;
1070 switch (S->getSCEVType()) {
1071 case scUMaxExpr:
1072 IntrinsicID = Intrinsic::umax;
1073 break;
1074 case scSMaxExpr:
1075 IntrinsicID = Intrinsic::smax;
1076 break;
1077 case scUMinExpr:
1079 IntrinsicID = Intrinsic::umin;
1080 break;
1081 case scSMinExpr:
1082 IntrinsicID = Intrinsic::smin;
1083 break;
1084 default:
1085 llvm_unreachable("Unexpected min/max SCEV type");
1086 }
1087 // Chain operands in reverse order matching SCEVExpander's expansion of
1088 // min/max expressions. In SafeUDivMode freeze expansion results of operands
1089 // other than the first for sequential UMins, to avoid short-circuiting
1090 // divide-by-0/poison.
1091 bool IsSequential = S->getSCEVType() == scSequentialUMinExpr;
1092 Type *ResultTy = MinMax->getType();
1093 bool PrevSafeMode = SafeUDivMode;
1095 for (const SCEV *SCEVOp : reverse(MinMax->operands())) {
1096 bool MayShortCircuit =
1097 IsSequential && Ops.size() != MinMax->getNumOperands() - 1;
1098 SafeUDivMode = MayShortCircuit || PrevSafeMode;
1099 VPValue *OpV = expand(SCEVOp);
1100 SafeUDivMode = PrevSafeMode;
1101 if (MayShortCircuit)
1102 OpV = Builder.createFreeze(OpV, DL);
1103 Ops.push_back(OpV);
1104 }
1105 VPValue *Result = Ops.front();
1106 for (VPValue *Op : drop_begin(Ops)) {
1107 if (!ResultTy->isPointerTy()) {
1108 Result = Builder.createScalarIntrinsic(IntrinsicID, {Result, Op},
1109 ResultTy, DL);
1110 continue;
1111 }
1112 // The min/max intrinsics don't support pointer operands, so expand
1113 // pointer-typed min/max as cmp + select, matching SCEVExpander.
1114 VPValue *Cmp = Builder.createICmp(
1115 MinMaxIntrinsic::getPredicate(IntrinsicID), Result, Op, DL);
1116 Result = Builder.createSelect(Cmp, Result, Op, DL);
1117 Function &F = *Builder.getPlan().getIRFunction();
1118 if (MDNode *MD =
1120 cast<VPInstruction>(Result)->setMetadata(LLVMContext::MD_prof, MD);
1121 }
1122 return Result;
1123 }
1124 case scAddRecExpr: {
1125 auto *AR = cast<SCEVAddRecExpr>(S);
1126 VPlan &Plan = Builder.getPlan();
1127 [[maybe_unused]] BasicBlock *PH =
1128 cast<VPIRBasicBlock>(Plan.getEntry())->getIRBasicBlock();
1129 assert(SE.DT.dominates(AR->getLoop()->getHeader(), PH) &&
1130 "can only expand AddRecs for loops outside VPlan's scope");
1131
1132 // Try to expand AR by re-using an existing canonical IV in the Plan's
1133 // entry. A canonical IV must be affine and integer typed.
1134 if (!AR->isAffine() || !AR->getType()->isIntegerTy())
1136 auto FoundCanIV =
1137 find_if(Plan.getEntry()->phis(), [&](const VPRecipeBase &R) {
1138 if (!SE.isSCEVable(cast<VPIRPhi>(R).getIRPhi().getType()))
1139 return false;
1140 const SCEV *Candidate = SE.getSCEV(&cast<VPIRPhi>(R).getIRPhi());
1141 return match(Candidate,
1142 m_scev_AffineAddRec(m_scev_Zero(), m_scev_One(),
1143 m_SpecificLoop(AR->getLoop()))) &&
1144 Candidate->getType() == AR->getType();
1145 });
1146 if (FoundCanIV == Plan.getEntry()->phis().end())
1148
1149 // {Start, +, Step} --> Start + IV * Step, since the AddRec is affine.
1150 // Compute Offset = IV * Step.
1151 VPValue *Start = expand(AR->getStart());
1152 Value *CanonicalIV = &cast<VPIRPhi>(FoundCanIV)->getIRPhi();
1154 SE.getMulExpr(SE.getUnknown(CanonicalIV), AR->getStepRecurrence(SE)));
1155
1156 // Compute Start + Offset with nuw from the AddRec.
1157 return Builder.createAdd(Start, Offset, DL, "",
1158 {AR->hasNoUnsignedWrap(), false});
1159 }
1160 case scCouldNotCompute:
1161 llvm_unreachable("Attempt to expand a SCEVCouldNotCompute");
1162 }
1163 llvm_unreachable("Unknown SCEV kind!");
1164}
1165
1167 // Do remove conditional assume instructions as their conditions may be
1168 // flattened.
1169 auto *RepR = dyn_cast<VPReplicateRecipe>(&R);
1170 bool IsConditionalAssume = RepR && RepR->isPredicated() &&
1172 if (IsConditionalAssume)
1173 return true;
1174
1175 if (R.mayHaveSideEffects())
1176 return false;
1177
1178 // Forbid removing trip-count expressions.
1179 if (isa<VPExpandSCEVRecipe>(R) &&
1180 R.getVPSingleValue() == R.getParent()->getPlan()->getTripCount())
1181 return false;
1182
1183 // Recipe is dead if no user keeps the recipe alive.
1184 return all_of(R.definedValues(), [](VPValue *V) { return V->user_empty(); });
1185}
1186
1188 SmallVector<VPValue *> WorkList;
1190 WorkList.push_back(V);
1191
1192 while (!WorkList.empty()) {
1193 VPValue *Cur = WorkList.pop_back_val();
1194 if (!Seen.insert(Cur).second)
1195 continue;
1196 VPRecipeBase *R = Cur->getDefiningRecipe();
1197 if (!R)
1198 continue;
1199 if (!isDeadRecipe(*R))
1200 continue;
1201 append_range(WorkList, R->operands());
1202 R->eraseFromParent();
1203 }
1204}
1205
1208 for (unsigned I = 0; I != Users.size(); ++I) {
1210 for (VPValue *V : Cur->definedValues())
1211 Users.insert_range(V->users());
1212 }
1213 return Users.takeVector();
1214}
1215
1216/// Returns \p Num / \p Denom as a BranchProbability, clamped so a ratio that is
1217/// neither zero nor one does not round to zero or one. BlockFrequencyInfo also
1218/// keeps a zero-weight edge distinguishable from an unreachable one.
1220 uint64_t Denom) {
1222 if (Num == 0 || Num == Denom)
1223 return P;
1224 return BranchProbability::getRaw(std::clamp(
1225 P.getNumerator(), 1u, BranchProbability::getDenominator() - 1));
1226}
1227
1233
1234/// Returns the probability of each successor edge of \p VPBB, computed via
1235/// BranchProbabilityInfo::getEdgeProbabilitiesFromWeights from the branch
1236/// weights recorded on its terminator, or std::nullopt if not available.
1237static std::optional<SmallVector<BranchProbability>>
1239 // With a single successor the edge is always taken and needs no weights.
1240 if (VPBB->getSingleSuccessor())
1242
1243 SmallVector<uint32_t> Weights;
1245 if (!Term || !extractBranchWeights(Term->getBranchWeights(), Weights) ||
1246 Weights.size() != VPBB->getNumSuccessors())
1247 return std::nullopt;
1249}
1250
1253 using BFIBase = BlockFrequencyInfoImplBase;
1254 assert(!Blocks.empty() && "expected at least the header block");
1255 // Distribute the header's frequency using BFI. Nodes for blocks are numbered
1256 // in reverse post-order. Edges leaving Blocks, i.e. a plain CFG's edges to
1257 // the middle block or to an exit block, exit to a node outside the loop.
1258 BFIBase BFI;
1259 BFIBase::BlockNode Header(0), Outside(Blocks.size());
1260 BFIBase::LoopData &Loop = BFI.Loops.emplace_back(nullptr, Header);
1262 for (auto [Idx, VPBB] : enumerate(Blocks)) {
1263 Nodes[VPBB] = BFIBase::BlockNode(Idx);
1264 BFI.Working.emplace_back(BFIBase::BlockNode(Idx)).Loop = &Loop;
1265 }
1266 BFI.Working.emplace_back(Outside);
1267 BFI.Working[Header.Index].getMass() = BFIBase::BlockMass::getFull();
1268
1269 // Keep track nodes reached via an edge without branch weighs or with
1270 // estimated ones
1271 SmallVector<bool> IsUnknown(Blocks.size()), IsEstimated(Blocks.size());
1272 for (auto [Idx, VPBB] : enumerate(Blocks)) {
1273 BFIBase::BlockNode Node(Idx);
1274 auto Probs = getSuccessorProbabilities(VPBB);
1275 auto *Term = dyn_cast_if_present<VPInstruction>(VPBB->getTerminator());
1276 bool TermIsEstimated = Term && Term->hasEstimatedBranchWeights();
1277 BFIBase::Distribution Dist;
1278 for (auto [SuccIdx, Succ] : enumerate(VPBB->getSuccessors())) {
1279 BFIBase::BlockNode SuccNode = Nodes.lookup_or(Succ, Outside);
1280 if (SuccNode != Header && SuccNode != Outside) {
1281 IsUnknown[SuccNode.Index] |= IsUnknown[Idx] || !Probs;
1282 IsEstimated[SuccNode.Index] |= IsEstimated[Idx] || TermIsEstimated;
1283 }
1284 if (Probs)
1285 BFI.addToDist(Dist, &Loop, Node, SuccNode,
1286 getWeightFromBranchProb((*Probs)[SuccIdx]));
1287 }
1288 if (Probs)
1289 BFI.distributeMass(Node, &Loop, Dist);
1290 }
1291
1292 // Round frequencies up to at least 1, so all edges are reached with a
1293 // non-zero frequency, to distinguish rarely executed blocks from unreachable
1294 // ones. blocks distinguishable from unreachable ones.
1296 Frequencies;
1297 for (auto [Idx, VPBB] : enumerate(Blocks)) {
1298 std::optional<VPExecutionFrequency> &Freq = Frequencies[VPBB];
1299 if (IsUnknown[Idx])
1300 continue;
1301 uint64_t Mass = BFI.Working[Idx].getMass().getMass();
1302 Freq.emplace(BlockFrequency(std::max<uint64_t>(Mass, 1)), IsEstimated[Idx]);
1303 }
1304 return Frequencies;
1305}
1306
1309 const DataLayout &DL) {
1310 auto OpcodeOrIID = getOpcodeOrIntrinsicID(&R);
1311 if (!OpcodeOrIID)
1312 return nullptr;
1313
1315 for (VPValue *Op : Operands) {
1316 VPValue *Candidate = Op;
1317 match(Op, m_Broadcast(m_VPValue(Candidate)));
1318 if (!match(Candidate, m_LiveIn()))
1319 return nullptr;
1320 Value *V = Candidate->getUnderlyingValue();
1321 if (!V)
1322 return nullptr;
1323 Ops.push_back(V);
1324 }
1325
1326 VPlan &Plan = *R.getParent()->getPlan();
1327 auto FoldToIRValue = [&]() -> Value * {
1328 InstSimplifyFolder Folder(DL);
1329 if (OpcodeOrIID->first) {
1330 // VPInstructions store the called intrinsic as last operand.
1331 if (isa<VPInstruction>(R))
1332 Ops.pop_back();
1333
1334 auto *RFlags = dyn_cast<VPRecipeWithIRFlags>(&R);
1335 return Folder.FoldIntrinsic(OpcodeOrIID->second, Ops, R.getScalarType(),
1336 RFlags ? RFlags->getFastMathFlagsOrNone()
1337 : FastMathFlags());
1338 }
1339 unsigned Opcode = OpcodeOrIID->second;
1340 if (Instruction::isBinaryOp(Opcode))
1341 return Folder.FoldBinOp(static_cast<Instruction::BinaryOps>(Opcode),
1342 Ops[0], Ops[1]);
1343 if (Instruction::isCast(Opcode))
1344 return Folder.FoldCast(static_cast<Instruction::CastOps>(Opcode), Ops[0],
1345 R.getVPSingleValue()->getScalarType());
1346 switch (Opcode) {
1347 case VPInstruction::Not:
1348 return Folder.FoldBinOp(Instruction::BinaryOps::Xor, Ops[0],
1350 case Instruction::Select:
1351 return Folder.FoldSelect(Ops[0], Ops[1], Ops[2]);
1352 case Instruction::ICmp:
1353 case Instruction::FCmp:
1354 return Folder.FoldCmp(cast<VPRecipeWithIRFlags>(R).getPredicate(), Ops[0],
1355 Ops[1]);
1356 case Instruction::GetElementPtr: {
1357 auto &RFlags = cast<VPRecipeWithIRFlags>(R);
1358 auto *GEP = cast<GetElementPtrInst>(RFlags.getUnderlyingInstr());
1359 return Folder.FoldGEP(DL, GEP->getSourceElementType(), Ops[0],
1360 drop_begin(Ops), RFlags.getGEPNoWrapFlags());
1361 }
1364 return Folder.FoldGEP(DL, IntegerType::getInt8Ty(Plan.getContext()),
1365 Ops[0], Ops[1],
1366 cast<VPRecipeWithIRFlags>(R).getGEPNoWrapFlags());
1367 // An extract of a live-in is an extract of a broadcast, so return the
1368 // broadcasted element.
1369 case Instruction::ExtractElement:
1370 assert(!Ops[0]->getType()->isVectorTy() && "Live-ins should be scalar");
1371 return Ops[0];
1374 uint64_t Multiplier = 1;
1375 if (Opcode == VPInstruction::WideActiveLaneMask) {
1376 // Optimizing WideALM can only happen after the Plan is unrolled.
1377 if (!Plan.isUnrolled())
1378 return nullptr;
1379 Multiplier = cast<ConstantInt>(Ops[2])->getZExtValue();
1380 Ops.pop_back();
1381 }
1382
1383 // We rely on the fact that different VPlans are created for the
1384 // fixed-vector and scalable-vector cases.
1385 ElementCount MaxVF =
1387 Multiplier;
1388
1389 Type *I1Ty = IntegerType::getInt1Ty(Plan.getContext());
1390 if (auto *C = dyn_cast_if_present<Constant>(Folder.FoldIntrinsic(
1391 Intrinsic::get_active_lane_mask, Ops,
1392 VectorType::get(I1Ty, MaxVF), {}, Plan.getIRFunction()))) {
1393 // We cannot handle vector constants that are not all-true or all-false,
1394 // because they would not be collapsable to a scalar constant, that
1395 // would be necessary for live-in simplification.
1396 if (C->isOneValue())
1397 return ConstantInt::getTrue(I1Ty);
1398 if (C->isNullValue())
1399 return ConstantInt::getFalse(I1Ty);
1400 }
1401 }
1402 }
1403 return nullptr;
1404 };
1405
1406 if (Value *V = FoldToIRValue())
1407 return Plan.getOrAddLiveIn(V);
1408 return nullptr;
1409}
1410
1412 VPlan &Plan, function_ref<VPValue *(VPValue *Op)> MatchPerm,
1415 vp_depth_first_deep(Plan.getEntry()))) {
1416 for (VPSingleDefRecipe &Def :
1418 if (!isElementwise(&Def))
1419 continue;
1420
1421 // At least one of the ops must be a permutation.
1422 if (none_of(Def.operands(), MatchPerm))
1423 continue;
1424
1425 // All operands must be a single-use permutation or a live in (splat).
1426 if (!all_of(Def.operands(), [&MatchPerm](VPValue *Op) {
1427 return (Op->hasOneUse() && MatchPerm(Op)) || match(Op, m_LiveIn());
1428 }))
1429 continue;
1430
1431 // Remove the inner permutations.
1432 for (unsigned I = 0, E = Def.getNumOperands(); I != E; ++I)
1433 if (VPValue *X = MatchPerm(Def.getOperand(I)))
1434 Def.setOperand(I, X);
1435
1436 VPSingleDefRecipe *Res = BuildPerm(&Def);
1437 Res->insertAfter(&Def);
1438 Def.replaceUsesWithIf(Res, [&Res](VPUser &U) { return &U != Res; });
1439 }
1440 }
1441}
1442
1443// Implements the algorithm described in "Simple and Efficient Construction of
1444// Static Single Assignment Form" by Braun et al.
1447 assert(!Defs.empty() && "Defs shouldn't be empty");
1448 assert(
1450 "VPBB isn't reachable from entry");
1451 if (VPValue *Def = Defs.lookup(VPBB))
1452 return Def;
1453 // If the entry block is reached and there's still no def, then Defs is
1454 // missing a definition that covers this path.
1455 assert(VPBB->getNumPredecessors() && "Not all paths have def");
1456
1457 if (VPBlockBase *Pred = VPBB->getSinglePredecessor())
1458 return reconstructSSA(cast<VPBasicBlock>(Pred), Defs);
1459
1460 // Multiple predecessors, create a join.
1461 Type *Ty = Defs.begin()->second->getScalarType();
1462 VPPhi *Phi = VPBuilder(VPBB, VPBB->getFirstNonPhi())
1463 .createScalarPhi({}, DebugLoc::getUnknown(), "", {}, Ty);
1464 Defs[VPBB] = Phi;
1465 for (auto *Pred : VPBB->predecessors())
1466 Phi->addIncoming(reconstructSSA(cast<VPBasicBlock>(Pred), Defs));
1467
1468 // Fold away trivial phis.
1469 // TODO: Remove phi users which have become trivial too.
1470 if (all_equal(Phi->incoming_values())) {
1471 VPValue *Common = Phi->getIncomingValue(0);
1472 Phi->replaceAllUsesWith(Common);
1473 for (auto &[_, V] : Defs)
1474 if (V == Phi)
1475 V = Common;
1476 Defs[VPBB] = Common;
1477 Phi->eraseFromParent();
1478 return Common;
1479 }
1480
1481 return Phi;
1482}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define X(NUM, ENUM, NAME)
Definition ELF.h:857
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
Hexagon Common GEP
#define _
iv Induction Variable Users
Definition IVUsers.cpp:48
static constexpr Value * getValue(Ty &ValueOrUse)
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
This file provides a LoopVectorizationPlanner class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file implements a map that provides insertion order iteration.
This file provides utility analysis objects describing memory locations.
#define P(N)
This file contains the declarations for profiling metadata utility functions.
SI Fold Operands
This file implements a set that has insertion order iteration characteristics.
This file defines less commonly used SmallVector utilities.
static unsigned getScalarSizeInBits(Type *Ty)
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
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 BranchProbability getBranchProbabilityKeepingPartial(uint64_t Num, uint64_t Denom)
Returns Num / Denom as a BranchProbability, clamped so a ratio that is neither zero nor one does not ...
static std::optional< SmallVector< BranchProbability > > getSuccessorProbabilities(const VPBasicBlock *VPBB)
Returns the probability of each successor edge of VPBB, computed via BranchProbabilityInfo::getEdgePr...
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
size_t size() const
Get the array size.
Definition ArrayRef.h:141
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
LLVM Basic Block Representation.
Definition BasicBlock.h:62
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
Base class for BlockFrequencyInfoImpl.
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
static LLVM_ABI SmallVector< BranchProbability > getEdgeProbabilitiesFromWeights(ArrayRef< uint32_t > Weights)
Returns the probabilities of edges with branch weights Weights.
static LLVM_ABI BranchProbability getBranchProbability(uint64_t Numerator, uint64_t Denominator)
static constexpr BranchProbability getOne()
static uint32_t getDenominator()
static constexpr BranchProbability getRaw(uint32_t N)
This is the base class for all instructions that perform data casts.
Definition InstrTypes.h:512
This is the shared class of boolean and integer constants.
Definition Constants.h:87
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
bool isMinValue(bool IsSigned) const
This function will return true iff this constant represents the smallest value that may be represente...
Definition Constants.h:250
static LLVM_ABI ConstantInt * getFalse(LLVMContext &Context)
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
A debug info location.
Definition DebugLoc.h:126
static DebugLoc getUnknown()
Definition DebugLoc.h:153
bool empty() const
Definition DenseMap.h:717
ValueT lookup_or(const_arg_type_t< KeyT > Val, U &&Default) const
Definition DenseMap.h:804
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
Definition DenseMap.h:794
iterator begin()
Definition DenseMap.h:683
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.
Utility class for floating point operations which can have information about relaxed accuracy require...
Definition Operator.h:202
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:23
Represents flags for the getelementptr instruction/expression.
static GEPNoWrapFlags noUnsignedWrap()
static GEPNoWrapFlags none()
A struct for saving information about induction variables.
InductionKind
This enum represents the kinds of inductions that we support.
@ IK_FpInduction
Floating point induction variable.
@ IK_IntInduction
Integer induction variable. Step = C.
InstSimplifyFolder - Use InstructionSimplify to fold operations to existing values.
bool isCast() const
bool isBinaryOp() const
bool isUnaryOp() const
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
Metadata node.
Definition Metadata.h:1081
Representation for a specific memory location.
static ICmpInst::Predicate getPredicate(Intrinsic::ID ID)
Returns the comparison predicate underlying the intrinsic.
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.
static LLVM_ABI CastInst * findReusableCastForPtrToAddr(Value *PtrOp, Type *Ty, const DataLayout &DL, function_ref< bool(const CastInst *)> Dominates)
Find an existing cast among PtrOp's users that computes the same value as a ptrtoaddr of PtrOp to Ty ...
This class represents an analyzed expression in the program.
static constexpr auto FlagNSW
Type * getType() const
Return the LLVM type of this SCEV expression.
static constexpr auto FlagNone
SCEVTypes getSCEVType() const
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 bool isKnownNonNegative(const SCEV *S)
Test if the given expression is known to be non-negative.
LLVM_ABI const SCEV * getZeroExtendExpr(SCEVUse Op, Type *Ty, unsigned Depth=0)
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 const SCEV * getMinusSCEV(SCEVUse LHS, SCEVUse RHS, SCEVFlags Flags=SCEV::FlagNone, unsigned Depth=0)
Return LHS-RHS.
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.
static LLVM_ABI bool isGuaranteedNotToBePoison(const SCEV *Op)
Returns true if Op is guaranteed to not be poison.
const SCEV * getOne(Type *Ty)
Return a SCEV for the constant 1 of a specific type.
LLVM_ABI SCEVUse getAddRecExpr(SCEVUse Start, SCEVUse Step, const Loop *L, SCEVFlagsPair Flags)
Get an add recurrence expression for the specified loop.
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 * getTruncateExpr(SCEVUse Op, Type *Ty, unsigned Depth=0)
LLVM_ABI SCEVUse getAddExpr(SmallVectorImpl< SCEVUse > &Ops, SCEVFlagsPair Flags={}, unsigned Depth=0)
Get a canonical add expression, or something simpler if possible.
LLVM_ABI bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
LLVM_ABI const SCEV * getSignExtendExpr(SCEVUse 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 SCEVUse getMulExpr(SmallVectorImpl< SCEVUse > &Ops, SCEVFlagsPair Flags={}, unsigned Depth=0)
Get a canonical multiply expression, or something simpler if possible.
const SCEV * getPowerOfTwo(Type *Ty, unsigned Power)
Return a SCEV for the constant Power of two.
LLVM_ABI const SCEV * getPtrToAddrExpr(const SCEV *Op)
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.
A vector that has set insertion semantics.
Definition SetVector.h:57
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.
reference emplace_back(ArgTypes &&... Args)
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:277
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Definition Type.cpp:297
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:363
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:222
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
Definition Type.cpp:296
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:252
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition VPlan.h:4432
iterator end()
Definition VPlan.h:4469
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
Definition VPlan.h:4520
iterator getFirstNonPhi()
Return the position of the first non-phi node recipe in the block.
Definition VPlan.cpp:233
VPRecipeBase * getTerminator()
If the block has multiple successors, return the branch recipe terminating the block.
Definition VPlan.cpp:619
void insert(VPRecipeBase *Recipe, iterator InsertPt)
Definition VPlan.h:4498
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition VPlan.h:97
VPRegionBlock * getParent()
Definition VPlan.h:195
iterator_range< VPBlockBase ** > predecessors()
Definition VPlan.h:228
size_t getNumSuccessors() const
Definition VPlan.h:245
size_t getNumPredecessors() const
Definition VPlan.h:246
const VPBlocksTy & getPredecessors() const
Definition VPlan.h:230
VPlan * getPlan()
Definition VPlan.h:199
VPBlockBase * getSinglePredecessor() const
Definition VPlan.h:241
const VPBasicBlock * getEntryBasicBlock() const
Definition VPlan.cpp:188
VPBlockBase * getSingleHierarchicalPredecessor()
Definition VPlan.h:271
VPBlockBase * getSingleSuccessor() const
Definition VPlan.h:235
const VPBlocksTy & getSuccessors() const
Definition VPlan.h:219
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:413
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.
VPPhi * createScalarPhi(ArrayRef< VPValue * > IncomingValues, DebugLoc DL=DebugLoc::getUnknown(), const Twine &Name="", std::optional< VPIRFlags > Flags=std::nullopt, Type *ResultTy=nullptr)
Create a phi with IncomingValues, using the default flags for the result type, unless Flags is set.
ArrayRef< VPRecipeValue * > definedValues()
Returns an ArrayRef of the values defined by the VPDef.
Definition VPlanValue.h:573
A recipe for converting Current into Start + Current * Step.
Definition VPlan.h:4213
Template specialization of the standard LLVM dominator tree utility for VPBlockBases.
Recipe to expand a SCEV expression.
Definition VPlan.h:4045
virtual VPValue * getBackedgeValue()
Returns the incoming value from the loop backedge.
Definition VPlan.h:2501
VPValue * getStartValue()
Returns the start value of the phi, if one is set.
Definition VPlan.h:2490
A special type of VPBasicBlock that wraps an existing IR basic block.
Definition VPlan.h:4585
Class to record and manage LLVM IR flags.
Definition VPlan.h:696
static LLVM_ABI_FOR_TEST VPIRFlags getDefaultFlags(unsigned Opcode, Type *ResultTy=nullptr)
Returns default flags for Opcode and scalar ResultTy for opcodes that support it, asserts otherwise.
This is a concrete Recipe that models a single VPlan-level instruction.
Definition VPlan.h:1303
@ ReductionStartVector
Start vector for reductions with 3 operands: the original start value, the identity value for the red...
Definition VPlan.h:1408
unsigned getOpcode() const
Definition VPlan.h:1497
bool isVectorToScalar() const
Returns true if this VPInstruction produces a scalar value from a vector, e.g.
bool isSingleScalar() const
Returns true if the recipe produces a single scalar value.
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition VPlan.h:403
DebugLoc getDebugLoc() const
Returns the debug location of the recipe.
Definition VPlan.h:553
void insertAfter(VPRecipeBase *InsertPos)
Insert an unlinked Recipe into a basic block immediately after the specified Recipe.
Type * getScalarType() const
Returns the scalar type of this VPRecipeValue.
Definition VPlanValue.h:350
A recipe for handling reduction phis.
Definition VPlan.h:2865
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition VPlan.h:4657
bool isReplicator() const
An indicator whether this region is to generate multiple replicated instances of output IR correspond...
Definition VPlan.h:4733
bool hasCanonicalIVNUW() const
Indicates if NUW is set for the canonical IV increment, for loop regions.
Definition VPlan.h:4821
VPRegionValue * getCanonicalIV()
Return the canonical induction variable of the region, null for replicating regions.
Definition VPlan.h:4777
VPValues are defined by a VPRegionBlock, like the canonical IV.
Definition VPlanValue.h:248
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition VPlan.h:3415
VPValue * expand(const SCEV *S)
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:4274
VPSingleDefRecipe is a base class for recipes that model a sequence of one or more output IR that def...
Definition VPlan.h:611
A symbolic live-in VPValue, used for values like vector trip count, VF, and VFxUF.
Definition VPlanValue.h:213
bool isMaterialized() const
Returns true if this value has been materialized.
Definition VPlanValue.h:231
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
Definition VPlanValue.h:397
operand_range operands()
Definition VPlanValue.h:473
VPValue * getOperand(unsigned N) const
Definition VPlanValue.h:438
This is the base class of the VPlan Def/Use graph, used for modeling the data flow into,...
Definition VPlanValue.h:50
Type * getScalarType() const
Returns the scalar type of this VPValue, dispatching based on the concrete subclass.
Definition VPlan.cpp:147
VPRecipeBase * getDefiningRecipe()
Returns the recipe defining this VPValue or nullptr if it is not defined by a recipe,...
Definition VPlan.cpp:128
Value * getUnderlyingValue() const
Return the underlying Value attached to this VPValue.
Definition VPlanValue.h:75
user_range users()
Definition VPlanValue.h:157
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition VPlan.h:1896
A recipe for handling GEP instructions.
Definition VPlan.h:2228
const InductionDescriptor & getInductionDescriptor() const
Returns the induction descriptor for the recipe.
Definition VPlan.h:2585
A recipe for handling phi nodes of integer and floating-point inductions, producing their vector valu...
Definition VPlan.h:2614
A recipe for widened phis.
Definition VPlan.h:2752
VPWidenRecipe is a recipe for producing a widened instruction using the opcode and operands of the re...
Definition VPlan.h:1829
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition VPlan.h:4844
LLVMContext & getContext() const
Definition VPlan.h:5054
VPBasicBlock * getEntry()
Definition VPlan.h:4940
iterator_range< SmallSetVector< ElementCount, 2 >::iterator > vectorFactors() const
Returns an iterator range over all VFs of the plan.
Definition VPlan.h:5087
VPSymbolicValue & getVFxUF()
Returns VF * UF of the vector loop region.
Definition VPlan.h:5052
ArrayRef< VPIRBasicBlock * > getExitBlocks() const
Return an ArrayRef containing VPIRBasicBlocks wrapping the exit blocks of the original scalar loop.
Definition VPlan.h:5006
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:5130
VPIRValue * getZero(Type *Ty)
Return a VPIRValue wrapping the null value of type Ty.
Definition VPlan.h:5156
bool isUnrolled() const
Returns true if the VPlan already has been unrolled, i.e.
Definition VPlan.h:5121
Function * getIRFunction() const
Definition VPlan.h:5062
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
Definition VPlan.cpp:1042
unsigned getConcreteUF() const
Returns the concrete UF of the plan, after unrolling.
Definition VPlan.h:5108
VPBasicBlock * getVectorPreheader() const
Returns the preheader of the vector loop region, if one exists, or null otherwise.
Definition VPlan.h:4945
VPSymbolicValue & getUF()
Returns the UF of the vector loop region.
Definition VPlan.h:5049
VPBasicBlock * getScalarPreheader() const
Return the VPBasicBlock for the preheader of the scalar loop.
Definition VPlan.h:4996
VPSymbolicValue & getVF()
Returns the VF of the vector loop region.
Definition VPlan.h:5045
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
static constexpr bool isKnownLT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
Definition TypeSize.h:216
An efficient, type-erasing, non-owning reference to a callable.
IteratorT end() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
CastOperator_match< OpTy, Instruction::PtrToAddr > m_PtrToAddr(const OpTy &Op)
Matches PtrToAddr.
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.
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)
auto m_VScale()
Matches a call to llvm.vscale().
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.
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(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< Instruction::Or, Op0_t, Op1_t > m_BinaryOr(const Op0_t &Op0, const Op1_t &Op1)
Match a binary OR 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)
auto m_GetElementPtr(const Op0_t &Op0, const Op1_t &Op1)
auto m_VPValue()
Match an arbitrary VPValue and ignore it.
VPInstruction_match< VPInstruction::ExtractVectorForPart, Op0_t, Op1_t > m_ExtractVectorForPart(const Op0_t &Op0, const Op1_t &Op1)
VPRecipeBase * findUserOf(VPValue *V, const MatchT &P)
If V is used by a recipe matching pattern P, return it.
VPInstruction_match< VPInstruction::Broadcast, Op0_t > m_Broadcast(const Op0_t &Op0)
match_bind< VPInstruction > m_VPInstruction(VPInstruction *&V)
Match a VPInstruction, capturing if we match.
void pullOutPermutationsImpl(VPlan &Plan, function_ref< VPValue *(VPValue *Op)> Perm, function_ref< VPSingleDefRecipe *(VPSingleDefRecipe *X)> Build)
Template-independent implementation for pullOutPermutations.
BranchProbability getExecutionProbability(BlockFrequency Freq)
Returns Freq as a BranchProbability, relative to the full mass.
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.
unsigned getOpcode(const VPValue *V)
Return the instruction opcode for the recipe defining V or 0 for unsupported recipes and VPValues not...
std::optional< int64_t > getConstantStride(VPValue *Addr, Type *AccessTy, PredicatedScalarEvolution &PSE, const Loop *L)
If the pointer operand Addr of a memory access is an affine AddRec w.r.t.
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,...
LLVM_ABI_FOR_TEST VPValue * reconstructSSA(VPBasicBlock *VPBB, DenseMap< VPBasicBlock *, VPValue * > &Defs)
Insert phis to reconstruct SSA for a single value starting from VPBB.
bool onlyFirstPartUsed(const VPValue *Def)
Returns true if only the first part of Def is used.
Intrinsic::ID getIntrinsicID(const Ty *R)
Return the intrinsic ID underlying a call.
Definition VPlanUtils.h:93
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.
VPIRValue * tryToFoldLiveIns(VPSingleDefRecipe &R, ArrayRef< VPValue * > Operands, const DataLayout &DL)
Try to fold R using InstSimplifyFolder.
SmallVector< std::pair< VPBasicBlock *, VPIRBasicBlock * > > getEarlyExits(const VPlan &Plan, const VPBlockBase *MiddleVPBB)
Returns the (early exiting block, exit block) pairs of Plan, i.e.
VPValue * findIncomingAliasMask(const VPlan &Plan)
Finds the incoming alias-mask within the vector preheader.
DenseMap< const VPBasicBlock *, std::optional< VPExecutionFrequency > > computeExecutionFrequencies(ArrayRef< VPBasicBlock * > Blocks)
Computes for each block in Blocks, which must be in reverse post-order, the frequency with which it e...
void recursivelyDeleteDeadRecipes(VPValue *V)
Recursively delete V and any of its operands that become dead.
bool doesGeneratePerAllLanes(const VPRecipeBase *R)
Returns true if R produces scalar values for all VF lanes.
VPIRFlags getFlagsForInduction(const InductionDescriptor &ID, const VPPhi *PhiR)
Extracts and returns NoWrap flags from PhiR and fast-math flags from ID.
bool isDeadRecipe(VPRecipeBase &R)
Returns true if R is dead, i.e.
bool isElementwise(const VPValue *V)
Return true if V is elementwise, i.e. none of the lanes are permuted.
bool onlyScalarValuesUsed(const VPValue *Def)
Returns true if only scalar values of Def are used by all users.
LLVM_ABI_FOR_TEST 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.
std::optional< std::pair< bool, unsigned > > getOpcodeOrIntrinsicID(const VPValue *V)
Get the instruction opcode or intrinsic ID for the recipe defining V.
VPValue * scalarizeVPWidenPointerInduction(VPWidenPointerInductionRecipe *PtrIV, VPlan &Plan, VPBuilder &Builder)
Scalarize a VPWidenPointerInductionRecipe by replacing it with a PtrAdd (IndStart,...
GEPNoWrapFlags getGEPFlagsForPtr(VPValue *Ptr)
Returns the GEP nowrap flags for Ptr, looking through pointer casts mirroring Value::stripPointerCast...
LLVM_ABI_FOR_TEST 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.
SmallVector< VPUser * > collectUsersRecursively(VPValue *V)
Collect all users of V, looking through recipes that define other values.
VPScalarIVStepsRecipe * createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind, Instruction::BinaryOps InductionOpcode, FPMathOperator *FPBinOp, Instruction *TruncI, VPValue *StartV, VPValue *Step, DebugLoc DL, VPBuilder &Builder, const VPIRFlags::WrapFlagsTy &Flags={})
Create a scalar-iv-steps recipe over Plan's canonical IV for an induction of Kind with InductionOpcod...
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:316
@ Offset
Definition DWP.cpp:577
void stable_sort(R &&Range)
Definition STLExtras.h:2132
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:1781
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:1755
uint32_t getWeightFromBranchProb(const BranchProbability Prob)
detail::zippy< detail::zip_first, T, U, Args... > zip_equal(T &&t, U &&u, Args &&...args)
zip iterator that assumes that all iteratees have the same length.
Definition STLExtras.h:856
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2570
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
VPBuilderBase<> VPBuilder
Definition VPlan.h:67
constexpr from_range_t from_range
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
Definition Casting.h:732
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2224
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:649
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:250
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:285
constexpr auto equal_to(T &&Arg)
Functor variant of std::equal_to that can be used as a UnaryPredicate in functional algorithms like a...
Definition STLExtras.h:2189
auto make_isa_range(RangeT &&Range)
Return a range over Range containing only elements for which isa<T> holds, casting each of them to T.
Definition STLExtras.h:567
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1762
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:326
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition MathExtras.h:280
bool hasIrregularType(Type *Ty, const DataLayout &DL)
A helper function that returns true if the given type is irregular.
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:1769
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
LLVM_ABI MDNode * getExplicitlyUnknownBranchWeightsIfProfiled(Function &F, StringRef PassName)
Returns a metadata node containing unknown branch weights if the function has an entry count,...
DWARFExpression::Operation Op
auto max_element(R &&Range)
Provide wrappers to std::max_element which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:2104
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI bool extractBranchWeights(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Extract branch weights from MD_prof metadata.
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:1788
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:341
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
bool all_equal(std::initializer_list< T > Values)
Returns true if all Values in the initializer lists are equal or the list.
Definition STLExtras.h:2182
LLVM_ABI std::optional< int64_t > getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy, Value *Ptr, PredicatedScalarEvolution &PSE)
If AR is an affine AddRec for Lp with a constant step, return the step in units of AccessTy's allocat...
@ Increment
Incrementally increasing token ID.
Definition AllocToken.h:26
constexpr detail::IsaCheckPredicate< Types... > IsaPred
Function object wrapper for the llvm::isa type check.
Definition Casting.h:866
A VPValue representing a live-in from the input IR or a constant.
Definition VPlanValue.h:275
A recipe for widening load operations with vector-predication intrinsics, using the address to load f...
Definition VPlan.h:3885
A recipe for widening load operations, using the address to load from and an optional mask.
Definition VPlan.h:3832