39#define LV_NAME "loop-vectorize"
40#define DEBUG_TYPE LV_NAME
44 cl::desc(
"Enable if-conversion during vectorization."));
48 cl::desc(
"Enable recognition of non-constant strided "
49 "pointer induction variables."));
53 cl::desc(
"Allow enabling loop hints to reorder "
54 "FP operations during vectorization."));
60 cl::desc(
"Control whether the compiler can use scalable vectors to "
64 "Scalable vectorization is disabled."),
67 "Scalable vectorization is available and favored when the "
68 "cost is inconclusive."),
71 "Scalable vectorization is available and favored when the "
72 "cost is inconclusive."),
75 "Scalable vectorization is available and always favored when "
80 cl::desc(
"Enables autovectorization of some loops containing histograms"));
87bool LoopVectorizeHints::Hint::validate(
unsigned Val) {
95 return (Val == 0 || Val == 1);
101 bool InterleaveOnlyWhenForced,
104 : Width(
"vectorize.width",
106 Interleave(
"interleave.count", InterleaveOnlyWhenForced, HK_INTERLEAVE),
107 Force(
FK_Undefined), IsVectorized(
"isvectorized", 0, HK_ISVECTORIZED),
109 Scalable(
"vectorize.scalable.enable",
SK_Unspecified, HK_SCALABLE),
110 TheLoop(L), ORE(ORE) {
112 getHintsFromMetadata();
150 if (IsVectorized.Value != 1)
157 <<
"LV: Interleaving disabled by the pass manager\n");
161 TheLoop->addIntLoopAttribute(
"llvm.loop.isvectorized", 1,
162 {
Twine(Prefix(),
"vectorize.").
str(),
163 Twine(Prefix(),
"interleave.").
str()});
166 IsVectorized.Value = 1;
169void LoopVectorizeHints::reportDisallowedVectorization(
172 LLVM_DEBUG(
dbgs() <<
"LV: Not vectorizing: " << DebugMsg <<
".\n");
175 <<
"loop not vectorized: " << RemarkMsg);
182 reportDisallowedVectorization(
"#pragma vectorize disable",
183 "MissedExplicitlyDisabled",
184 "vectorization is explicitly disabled", L);
186 reportDisallowedVectorization(
"loop hasDisableAllTransformsHint",
187 "MissedTransformsDisabled",
188 "loop transformations are disabled", L);
196 reportDisallowedVectorization(
197 "VectorizeOnlyWhenForced is set, and no #pragma vectorize enable",
198 "MissedForceOnly",
"only vectorizing loops that explicitly request it",
204 LLVM_DEBUG(
dbgs() <<
"LV: Not vectorizing: Disabled/already vectorized.\n");
210 L->getStartLoc(), L->getHeader())
211 <<
"loop not vectorized: vectorization and interleaving are "
212 "explicitly disabled, or the loop has already been "
227 TheLoop->getStartLoc(),
228 TheLoop->getHeader())
229 <<
"loop not vectorized: vectorization is explicitly disabled";
232 TheLoop->getHeader());
233 R <<
"loop not vectorized";
235 R <<
" (Force=" << NV(
"Force",
true);
236 if (Width.Value != 0)
237 R <<
", Vector Width=" << NV(
"VectorWidth",
getWidth());
239 R <<
", Interleave Count=" << NV(
"InterleaveCount",
getInterleave());
252 EC.getKnownMinValue() > 1);
255void LoopVectorizeHints::getHintsFromMetadata() {
271 if (!MD || MD->getNumOperands() == 0)
274 for (
unsigned Idx = 1; Idx < MD->getNumOperands(); ++Idx)
275 Args.push_back(MD->getOperand(Idx));
278 assert(Args.size() == 0 &&
"too many arguments for MDString");
288 if (Name ==
"llvm.loop.vectorize.enable")
290 else if (Name ==
"llvm.loop.vectorize.disable")
292 else if (Name ==
"llvm.loop.vectorize.predicate.enable")
294 else if (Name ==
"llvm.loop.vectorize.predicate.disable")
298 if (
Args.size() == 1)
299 setHint(Name, Args[0]);
304 if (!
Name.consume_front(Prefix()))
310 unsigned Val =
C->getZExtValue();
314 Hint *Hints[] = {&Width, &Interleave, &IsVectorized, &Scalable};
315 for (
auto *
H : Hints) {
316 if (Name ==
H->Name) {
317 if (
H->validate(Val))
320 LLVM_DEBUG(
dbgs() <<
"LV: ignoring invalid hint '" << Name <<
"'\n");
376 dbgs() <<
"LV: Loop latch condition is not a compare instruction.\n");
380 Value *CondOp0 = LatchCmp->getOperand(0);
381 Value *CondOp1 = LatchCmp->getOperand(1);
382 Value *IVUpdate =
IV->getIncomingValueForBlock(Latch);
385 LLVM_DEBUG(
dbgs() <<
"LV: Loop latch condition is not uniform.\n");
399 for (
Loop *SubLp : *Lp)
407 assert(Ty->isIntOrPtrTy() &&
"Expected integer or pointer type");
409 if (Ty->isPointerTy())
410 return DL.getIntPtrType(Ty->getContext(), Ty->getPointerAddressSpace());
414 if (Ty->getScalarSizeInBits() < 32)
435 Value *APtr =
A->getPointerOperand();
436 Value *BPtr =
B->getPointerOperand();
445 if (!AllowRuntimeSCEVChecks || !TheLoop->isInnermost())
462 const auto &Strides = LAI && AllowRuntimeSCEVChecks
463 ? LAI->getSymbolicStrides()
466 int Stride =
getPtrStride(PSE, AccessTy, Ptr, TheLoop, *DT, Strides,
false,
467 AllowRuntimeSCEVChecks ? &Predicates :
nullptr)
469 if (Stride != 1 && Stride != -1)
471 PSE.addPredicates(Predicates);
476 return LAI->isInvariant(V);
486class SCEVAddRecForUniformityRewriter
489 unsigned StepMultiplier;
498 bool CannotAnalyze =
false;
500 bool canAnalyze()
const {
return !CannotAnalyze; }
503 SCEVAddRecForUniformityRewriter(
ScalarEvolution &SE,
unsigned StepMultiplier,
508 const SCEV *visitAddRecExpr(
const SCEVAddRecExpr *Expr) {
510 "addrec outside of TheLoop must be invariant and should have been "
516 if (!SE.isLoopInvariant(Step, TheLoop)) {
517 CannotAnalyze =
true;
520 const SCEV *NewStep =
521 SE.getMulExpr(Step, SE.getConstant(Ty, StepMultiplier));
522 const SCEV *ScaledOffset = SE.getMulExpr(Step, SE.getConstant(Ty, Offset));
523 const SCEV *NewStart =
528 const SCEV *
visit(
const SCEV *S) {
529 if (CannotAnalyze || SE.isLoopInvariant(S, TheLoop))
534 const SCEV *visitUnknown(
const SCEVUnknown *S) {
535 if (SE.isLoopInvariant(S, TheLoop))
538 CannotAnalyze =
true;
542 const SCEV *visitCouldNotCompute(
const SCEVCouldNotCompute *S) {
544 CannotAnalyze =
true;
548 static const SCEV *rewrite(
const SCEV *S, ScalarEvolution &SE,
549 unsigned StepMultiplier,
unsigned Offset,
559 SCEVAddRecForUniformityRewriter
Rewriter(SE, StepMultiplier, Offset,
572 Value *V, std::optional<ElementCount> VF)
const {
575 if (!VF || VF->isScalable())
582 auto *SE = PSE.getSE();
589 unsigned FixedVF = VF->getKnownMinValue();
590 const SCEV *FirstLaneExpr =
591 SCEVAddRecForUniformityRewriter::rewrite(S, *SE, FixedVF, 0, TheLoop);
599 const SCEV *IthLaneExpr =
600 SCEVAddRecForUniformityRewriter::rewrite(S, *SE, FixedVF,
I, TheLoop);
601 return FirstLaneExpr == IthLaneExpr;
617bool LoopVectorizationLegality::canVectorizeOuterLoop() {
630 "Unsupported basic block terminator",
631 "loop control flow is not understood by vectorizer",
632 "CFGNotUnderstood", ORE, TheLoop);
650 "Unsupported conditional branch",
651 "loop control flow is not understood by vectorizer",
652 "CFGNotUnderstood", ORE, TheLoop);
665 "Outer loop contains divergent loops",
666 "loop control flow is not understood by vectorizer",
"CFGNotUnderstood",
675 if (!setupOuterLoopInductions()) {
677 "UnsupportedPhi", ORE, TheLoop);
687void LoopVectorizationLegality::addInductionPhi(
PHINode *Phi,
689 Inductions[
Phi] =
ID;
697 InductionCastsToIgnore.insert(*Casts.
begin());
700 const DataLayout &
DL =
Phi->getDataLayout();
703 "Expected int, ptr, or FP induction phi type");
715 ID.getConstIntStepValue() &&
ID.getConstIntStepValue()->isOne() &&
723 if (!PrimaryInduction || PhiTy == WidestIndTy)
724 PrimaryInduction =
Phi;
730bool LoopVectorizationLegality::setupOuterLoopInductions() {
734 auto IsSupportedPhi = [&](PHINode &
Phi) ->
bool {
735 InductionDescriptor
ID;
738 addInductionPhi(&Phi, ID);
744 dbgs() <<
"LV: Found unsupported PHI for outer loop vectorization.\n");
767 TLI.
getWidestVF(ScalarName, WidestFixedVF, WidestScalableVF);
775 "Caller may decide to scalarize a variant using a scalable VF");
780bool LoopVectorizationLegality::canVectorizeInstrs() {
788 Result &= canVectorizeInstr(
I);
789 if (!DoExtraAnalysis && !Result)
794 if (!PrimaryInduction) {
795 if (Inductions.empty()) {
797 "Did not find one integer induction var",
798 "loop induction variable could not be identified",
799 "NoInductionVariable", ORE, TheLoop);
804 "Did not find one integer induction var",
805 "integer loop induction variable could not be identified",
806 "NoIntegerInductionVariable", ORE, TheLoop);
809 LLVM_DEBUG(
dbgs() <<
"LV: Did not find one integer induction var.\n");
815 if (PrimaryInduction && WidestIndTy != PrimaryInduction->getType())
816 PrimaryInduction =
nullptr;
821bool LoopVectorizationLegality::canVectorizeInstr(
Instruction &
I) {
831 "Found a non-int non-pointer PHI",
832 "loop control flow is not understood by vectorizer",
833 "CFGNotUnderstood", ORE, TheLoop);
848 if (
Phi->getNumIncomingValues() != 2) {
850 "Found an invalid PHI",
851 "loop control flow is not understood by vectorizer",
852 "CFGNotUnderstood", ORE, TheLoop, Phi);
856 RecurrenceDescriptor RedDes;
860 Reductions[
Phi] = std::move(RedDes);
864 "Only min/max recurrences are allowed to have multiple uses "
873 auto IsDisallowedStridedPointerInduction =
874 [](
const InductionDescriptor &
ID) {
878 ID.getConstIntStepValue() ==
nullptr;
881 InductionDescriptor
ID;
883 !IsDisallowedStridedPointerInduction(ID)) {
884 addInductionPhi(Phi, ID);
885 Requirements->addExactFPMathInst(
ID.getExactFPMathInst());
890 FixedOrderRecurrences.insert(Phi);
897 !IsDisallowedStridedPointerInduction(ID)) {
898 addInductionPhi(Phi, ID);
903 "value that could not be identified as "
904 "reduction is used outside the loop",
905 "NonReductionValueUsedOutsideLoop", ORE, TheLoop,
916 !(CI->getCalledFunction() && TLI &&
922 TLI && CI->getCalledFunction() && CI->getType()->isFloatingPointTy() &&
923 TLI->getLibFunc(CI->getCalledFunction()->getName(), Func) &&
924 TLI->hasOptimizedCodeGen(Func);
932 "Found a non-intrinsic callsite",
933 "library call cannot be vectorized. "
934 "Try compiling with -fno-math-errno, -ffast-math, "
936 "CantVectorizeLibcall", ORE, TheLoop, CI);
939 "call instruction cannot be vectorized",
940 "CantVectorizeLibcall", ORE, TheLoop, CI);
948 auto *SE = PSE.getSE();
950 for (
unsigned Idx = 0; Idx < CI->arg_size(); ++Idx)
954 "Found unvectorizable intrinsic",
955 "intrinsic instruction cannot be vectorized",
956 "CantVectorizeIntrinsic", ORE, TheLoop, CI);
965 VecCallVariantsFound =
true;
967 auto CanWidenInstructionTy = [](
Instruction const &Inst) {
968 Type *InstTy = Inst.getType();
982 if (!CanWidenInstructionTy(
I) ||
987 "instruction return type cannot be vectorized",
988 "CantVectorizeInstructionReturnType", ORE,
995 Type *
T =
ST->getValueOperand()->getType();
998 "CantVectorizeStore", ORE, TheLoop, ST);
1004 if (
ST->getMetadata(LLVMContext::MD_nontemporal)) {
1007 assert(VecTy &&
"did not find vectorized version of stored type");
1008 if (!TTI->isLegalNTStore(VecTy,
ST->getAlign())) {
1010 "nontemporal store instruction cannot be vectorized",
1011 "CantVectorizeNontemporalStore", ORE, TheLoop, ST);
1017 if (
LD->getMetadata(LLVMContext::MD_nontemporal)) {
1021 assert(VecTy &&
"did not find vectorized version of load type");
1022 if (!TTI->isLegalNTLoad(VecTy,
LD->getAlign())) {
1024 "nontemporal load instruction cannot be vectorized",
1025 "CantVectorizeNontemporalLoad", ORE, TheLoop, LD);
1035 }
else if (
I.getType()->isFloatingPointTy() && (CI ||
I.isBinaryOp()) &&
1038 Hints->setPotentiallyUnsafe();
1071 Value *HIncVal =
nullptr;
1086 Value *HIdx =
nullptr;
1087 for (
Value *Index :
GEP->indices()) {
1110 if (!AR || AR->getLoop() != TheLoop)
1120 LLVM_DEBUG(
dbgs() <<
"LV: Found histogram for: " << *HSt <<
"\n");
1127bool LoopVectorizationLegality::canVectorizeIndirectUnsafeDependences() {
1167 LLVM_DEBUG(
dbgs() <<
"LV: Checking for a histogram on: " << *SI <<
"\n");
1168 return findHistogram(LI, SI, TheLoop, LAI->getPSE(), Histograms);
1171bool LoopVectorizationLegality::canVectorizeMemory() {
1172 LAI = &LAIs.getInfo(*TheLoop);
1173 const OptimizationRemarkAnalysis *LAR = LAI->getReport();
1176 return OptimizationRemarkAnalysis(
LV_NAME,
"loop not vectorized: ", *LAR);
1180 if (!LAI->canVectorizeMemory()) {
1183 "Cannot vectorize unsafe dependencies in uncountable exit loop with "
1185 "CantVectorizeUnsafeDependencyForEELoopWithSideEffects", ORE,
1190 return canVectorizeIndirectUnsafeDependences();
1193 if (LAI->hasLoadStoreDependenceInvolvingLoopInvariantAddress()) {
1195 "write to a loop invariant address could not "
1197 "CantVectorizeStoreToLoopInvariantAddress", ORE,
1206 if (!LAI->getStoresToInvariantAddresses().empty()) {
1209 for (StoreInst *SI : LAI->getStoresToInvariantAddresses()) {
1215 "We don't allow storing to uniform addresses",
1216 "write of conditional recurring variant value to a loop "
1217 "invariant address could not be vectorized",
1218 "CantVectorizeStoreToLoopInvariantAddress", ORE, TheLoop);
1226 if (TheLoop->contains(Ptr)) {
1228 "Invariant address is calculated inside the loop",
1229 "write to a loop invariant address could not "
1231 "CantVectorizeStoreToLoopInvariantAddress", ORE, TheLoop);
1237 if (LAI->hasStoreStoreDependenceInvolvingLoopInvariantAddress()) {
1243 ScalarEvolution *SE = PSE.getSE();
1245 for (StoreInst *SI : LAI->getStoresToInvariantAddresses()) {
1257 erase_if(UnhandledStores, [SE, SI](StoreInst *
I) {
1259 I->getValueOperand()->getType() ==
1260 SI->getValueOperand()->getType();
1267 bool IsOK = UnhandledStores.
empty();
1271 "We don't allow storing to uniform addresses",
1272 "write to a loop invariant address could not "
1274 "CantVectorizeStoreToLoopInvariantAddress", ORE, TheLoop);
1280 PSE.addPredicate(LAI->getPSE().getPredicate());
1285 bool EnableStrictReductions) {
1288 if (!Requirements->getExactFPInst() || Hints->allowReordering())
1294 if (!EnableStrictReductions ||
1325 return V == InvariantAddress ||
1336 return Inductions.count(PN);
1340 const Value *V)
const {
1342 return (Inst && InductionCastsToIgnore.count(Inst));
1351 return FixedOrderRecurrences.count(Phi);
1362 !canVectorizeLoopCFG(TheLoop,
false) &&
1363 "Loop shape should have been rejected by earlier checks");
1376bool LoopVectorizationLegality::blockCanBePredicated(
1405 if (!SafePtrs.
count(LI->getPointerOperand()))
1420 if (
I.mayReadFromMemory() ||
I.mayWriteToMemory() ||
I.mayThrow())
1427bool LoopVectorizationLegality::canVectorizeWithIfConvert() {
1430 "IfConversionDisabled", ORE, TheLoop);
1434 assert(TheLoop->getNumBlocks() > 1 &&
"Single block loops are vectorizable");
1441 SmallPtrSet<Value *, 8> SafePointers;
1444 for (BasicBlock *BB : TheLoop->blocks()) {
1446 for (Instruction &
I : *BB)
1448 SafePointers.
insert(Ptr);
1457 ScalarEvolution &SE = *PSE.getSE();
1459 for (Instruction &
I : *BB) {
1469 auto CanSpeculatePointerOp = [
this](
Value *Ptr) {
1471 SmallPtrSet<Value *, 4> Visited;
1472 while (!Worklist.
empty()) {
1474 if (!Visited.
insert(CurrV).second)
1478 if (!CurrI || !TheLoop->contains(CurrI)) {
1479 BasicBlock *LoopPred = TheLoop->getLoopPredecessor();
1482 "Loop with multiple predecessors should have been rejected "
1507 CanSpeculatePointerOp(LI->getPointerOperand()) &&
1510 SafePointers.
insert(LI->getPointerOperand());
1516 for (BasicBlock *BB : TheLoop->blocks()) {
1520 if (TheLoop->isLoopExiting(BB)) {
1522 "LoopContainsUnsupportedSwitch", ORE,
1523 TheLoop, BB->getTerminator());
1528 "LoopContainsUnsupportedTerminator", ORE,
1529 TheLoop, BB->getTerminator());
1535 !blockCanBePredicated(BB, SafePointers, ConditionallyExecutedOps)) {
1537 "Control flow cannot be substituted for a select",
"NoCFGForSelect",
1538 ORE, TheLoop, BB->getTerminator());
1548bool LoopVectorizationLegality::canVectorizeLoopCFG(
1549 Loop *Lp,
bool UseVPlanNativePath)
const {
1551 "VPlan-native path is not enabled.");
1561 bool DoExtraAnalysis = ORE->allowExtraAnalysis(
DEBUG_TYPE);
1567 "Loop doesn't have a legal pre-header",
1568 "loop control flow is not understood by vectorizer",
"CFGNotUnderstood",
1570 if (DoExtraAnalysis)
1579 "The loop must have a single backedge",
1580 "loop control flow is not understood by vectorizer",
"CFGNotUnderstood",
1582 if (DoExtraAnalysis)
1592 "The loop latch terminator is not a UncondBrInst/CondBrInst",
1593 "loop control flow is not understood by vectorizer",
"CFGNotUnderstood",
1595 if (DoExtraAnalysis)
1604bool LoopVectorizationLegality::canVectorizeLoopNestCFG(
1605 Loop *Lp,
bool UseVPlanNativePath) {
1609 bool DoExtraAnalysis = ORE->allowExtraAnalysis(
DEBUG_TYPE);
1610 if (!canVectorizeLoopCFG(Lp, UseVPlanNativePath)) {
1611 if (DoExtraAnalysis)
1619 for (Loop *SubLp : *Lp)
1620 if (!canVectorizeLoopNestCFG(SubLp, UseVPlanNativePath)) {
1621 if (DoExtraAnalysis)
1630bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
1631 BasicBlock *LatchBB = TheLoop->getLoopLatch();
1634 "Cannot vectorize early exit loop",
1635 "NoLatchEarlyExit", ORE, TheLoop);
1639 if (Reductions.size() || FixedOrderRecurrences.size()) {
1641 "Found reductions or recurrences in early-exit loop",
1642 "Cannot vectorize early exit loop with reductions or recurrences",
1643 "RecurrencesInEarlyExitLoop", ORE, TheLoop);
1647 SmallVector<BasicBlock *, 8> ExitingBlocks;
1648 TheLoop->getExitingBlocks(ExitingBlocks);
1653 for (BasicBlock *BB : ExitingBlocks) {
1655 PSE.getSE()->getPredicatedExitCount(TheLoop, BB, &Predicates);
1659 "Early exiting block does not have exactly two successors",
1660 "Incorrect number of successors from early exiting block",
1661 "EarlyExitTooManySuccessors", ORE, TheLoop);
1667 CountableExitingBlocks.push_back(BB);
1675 if (UncountableExitingBlocks.
empty()) {
1676 LLVM_DEBUG(
dbgs() <<
"LV: Could not find any uncountable exits");
1682 PSE.getSE()->getPredicatedExitCount(TheLoop, LatchBB, &Predicates))) {
1684 "Cannot determine exact exit count for latch block",
1685 "Cannot vectorize early exit loop",
1686 "UnknownLatchExitCountEarlyExitLoop", ORE, TheLoop);
1690 "Latch block not found in list of countable exits!");
1695 switch (
I->getOpcode()) {
1696 case Instruction::Load:
1697 case Instruction::Store:
1698 case Instruction::PHI:
1699 case Instruction::UncondBr:
1700 case Instruction::CondBr:
1708 bool HasSideEffects =
false;
1709 for (
auto *BB : TheLoop->blocks())
1710 for (
auto &
I : *BB) {
1711 if (
I.mayWriteToMemory()) {
1713 HasSideEffects =
true;
1719 "Complex writes to memory unsupported in early exit loops",
1720 "Cannot vectorize early exit loop with complex writes to memory",
1721 "WritesInEarlyExitLoop", ORE, TheLoop);
1725 if (!IsSafeOperation(&
I)) {
1727 "cannot be speculatively executed",
1728 "UnsafeOperationsEarlyExitLoop", ORE,
1736 if (!HasSideEffects) {
1742 "Loop may fault",
"Cannot vectorize non-read-only early exit loop",
1743 "NonReadOnlyEarlyExitLoop", ORE, TheLoop);
1748 for (BasicBlock *ExitingBB : UncountableExitingBlocks) {
1749 if (!canUncountableExitConditionLoadBeMoved(ExitingBB))
1755 for (LoadInst *LI : NonDerefLoads) {
1760 "Loop contains potentially faulting strided load",
1761 "Cannot vectorize early exit loop with "
1762 "strided fault-only-first load",
1763 "EarlyExitLoopWithStridedFaultOnlyFirstLoad", ORE, TheLoop);
1768 [[maybe_unused]]
const SCEV *SymbolicMaxBTC =
1769 PSE.getSymbolicMaxBackedgeTakenCount();
1773 "Failed to get symbolic expression for backedge taken count");
1774 LLVM_DEBUG(
dbgs() <<
"LV: Found an early exit loop with symbolic max "
1775 "backedge taken count: "
1776 << *SymbolicMaxBTC <<
'\n');
1782bool LoopVectorizationLegality::canUncountableExitConditionLoadBeMoved(
1793 using namespace llvm::PatternMatch;
1795 Value *Ptr =
nullptr;
1798 if (!
match(Br->getCondition(),
1802 "Early exit loop with store but no supported condition load",
1803 "NoConditionLoadForEarlyExitLoop", ORE, TheLoop);
1807 if (!TheLoop->isLoopInvariant(R)) {
1809 "Early exit loop with store but no supported condition load",
1810 "NoConditionLoadForEarlyExitLoop", ORE, TheLoop);
1817 if (!AR || AR->getLoop() != TheLoop || !AR->isAffine()) {
1819 "Uncountable exit condition depends on load with an address that is "
1820 "not an add recurrence in the loop",
1821 "EarlyExitLoadInvariantAddress", ORE, TheLoop);
1825 ICFLoopSafetyInfo SafetyInfo;
1832 "Load for uncountable exit not guaranteed to execute",
1833 "ConditionalUncountableExitLoad", ORE, TheLoop);
1840 for (
auto *BB : TheLoop->blocks()) {
1841 for (
auto &
I : *BB) {
1845 if (
I.mayReadOrWriteMemory()) {
1847 ConditionallyExecutedOps.insert(&
I);
1851 AliasResult AR = AA->alias(Ptr,
SI->getPointerOperand());
1857 "Cannot determine whether critical uncountable exit load address "
1858 "does not alias with a memory write",
1859 "CantVectorizeAliasWithCriticalUncountableExitLoad", ORE, TheLoop);
1873 bool DoExtraAnalysis = ORE->allowExtraAnalysis(
DEBUG_TYPE);
1876 if (!canVectorizeLoopNestCFG(TheLoop, UseVPlanNativePath)) {
1877 if (DoExtraAnalysis) {
1886 LLVM_DEBUG(
dbgs() <<
"LV: Found a loop: " << TheLoop->getHeader()->getName()
1891 if (!TheLoop->isInnermost()) {
1892 assert(UseVPlanNativePath &&
"VPlan-native path is not enabled.");
1894 if (!canVectorizeOuterLoop()) {
1896 "UnsupportedOuterLoop", ORE, TheLoop);
1906 assert(TheLoop->isInnermost() &&
"Inner loop expected.");
1908 unsigned NumBlocks = TheLoop->getNumBlocks();
1909 if (NumBlocks != 1 && !canVectorizeWithIfConvert()) {
1911 if (DoExtraAnalysis)
1918 if (!canVectorizeInstrs()) {
1919 LLVM_DEBUG(
dbgs() <<
"LV: Can't vectorize the instructions or CFG\n");
1920 if (DoExtraAnalysis)
1927 if (TheLoop->getExitingBlock()) {
1929 "UnsupportedUncountableLoop", ORE, TheLoop);
1930 if (DoExtraAnalysis)
1935 if (!isVectorizableEarlyExitLoop()) {
1937 "Must be false without vectorizable early-exit loop");
1938 if (DoExtraAnalysis)
1947 if (!canVectorizeMemory()) {
1948 LLVM_DEBUG(
dbgs() <<
"LV: Can't vectorize due to memory conflicts\n");
1949 if (DoExtraAnalysis)
1957 !LAI->getStoresToInvariantAddresses().empty()) {
1958 LLVM_DEBUG(
dbgs() <<
"LV: Cannot vectorize early exit loops with stores to "
1959 "loop-invariant addresses\n");
1961 "to loop-invariant addresses",
1962 "LoopInvariantStoresInEELoop", ORE, TheLoop);
1968 << (LAI->getRuntimePointerChecking()->Need
1969 ?
" (with a runtime bound check)"
1986 if (TheLoop->getExitingBlock() != TheLoop->getLoopLatch()) {
1989 <<
"LV: Cannot fold tail by masking. Requires a singe latch exit\n");
1993 LLVM_DEBUG(
dbgs() <<
"LV: checking if tail can be folded by masking.\n");
2002 if (!blockCanBePredicated(BB, SafePointers, TmpMaskedOp)) {
2021 [[maybe_unused]]
bool R =
2022 blockCanBePredicated(BB, SafePointers, TailFoldedMaskedOp);
2023 assert(R &&
"Must be able to predicate block when tail-folding.");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
static cl::opt< bool > HintsAllowReordering("hints-allow-reordering", cl::init(true), cl::Hidden, cl::desc("Allow enabling loop hints to reorder " "FP operations during vectorization."))
static const unsigned MaxInterleaveFactor
Maximum vectorization interleave count.
static cl::opt< bool > AllowStridedPointerIVs("lv-strided-pointer-ivs", cl::init(false), cl::Hidden, cl::desc("Enable recognition of non-constant strided " "pointer induction variables."))
static cl::opt< LoopVectorizeHints::ScalableForceKind > ForceScalableVectorization("scalable-vectorization", cl::init(LoopVectorizeHints::SK_Unspecified), cl::Hidden, cl::desc("Control whether the compiler can use scalable vectors to " "vectorize a loop"), cl::values(clEnumValN(LoopVectorizeHints::SK_FixedWidthOnly, "off", "Scalable vectorization is disabled."), clEnumValN(LoopVectorizeHints::SK_PreferScalable, "preferred", "Scalable vectorization is available and favored when the " "cost is inconclusive."), clEnumValN(LoopVectorizeHints::SK_PreferScalable, "on", "Scalable vectorization is available and favored when the " "cost is inconclusive."), clEnumValN(LoopVectorizeHints::SK_AlwaysScalable, "always", "Scalable vectorization is available and always favored when " "feasible")))
static cl::opt< bool > EnableHistogramVectorization("enable-histogram-loop-vectorization", cl::init(false), cl::Hidden, cl::desc("Enables autovectorization of some loops containing histograms"))
static cl::opt< bool > EnableIfConversion("enable-if-conversion", cl::init(true), cl::Hidden, cl::desc("Enable if-conversion during vectorization."))
This file defines the LoopVectorizationLegality class.
This file provides a LoopVectorizationPlanner class.
Contains a collection of routines for determining if a given instruction is guaranteed to execute if ...
static void visit(BasicBlock &Start, std::function< bool(BasicBlock *)> op)
Virtual Register Rewriter
static const uint32_t IV[8]
@ NoAlias
The two locations do not alias at all.
bool empty() const
Check if the array is empty.
LLVM Basic Block Representation.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
This class represents a function call, abstracting a target machine's calling convention.
A parsed version of the target data layout string in and methods for querying it.
static constexpr ElementCount getScalable(ScalarTy MinVal)
static constexpr ElementCount getFixed(ScalarTy MinVal)
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
bool isGuaranteedToExecute(const Instruction &Inst, const DominatorTree *DT, const Loop *CurLoop) const override
Returns true if the instruction in a loop is guaranteed to execute at least once (under the assumptio...
void computeLoopSafetyInfo(const Loop *CurLoop) override
Computes safety information for a loop checks loop body & header for the possibility of may throw exc...
A struct for saving information about induction variables.
static LLVM_ABI bool isInductionPHI(PHINode *Phi, const Loop *L, ScalarEvolution *SE, InductionDescriptor &D, ArrayRef< const SCEVPredicate * > NoWrapPreds={}, const SCEV *Expr=nullptr, SmallVectorImpl< Instruction * > *CastsToIgnore=nullptr)
Returns true if Phi is an induction in the loop L.
@ IK_PtrInduction
Pointer induction var. Step = C.
@ IK_IntInduction
Integer induction variable. Step = C.
Instruction * getExactFPMathInst()
Returns floating-point induction operator that does not allow reassociation (transforming the inducti...
Class to represent integer types.
An instruction for reading from memory.
const MemoryDepChecker & getDepChecker() const
the Memory Dependence Checker which can determine the loop-independent and loop-carried dependences b...
static LLVM_ABI bool blockNeedsPredication(const BasicBlock *BB, const Loop *TheLoop, const DominatorTree *DT)
Return true if the block BB needs to be predicated in order for the loop to be vectorized.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within this loop.
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
bool isInnermost() const
Return true if the loop does not contain any (natural) loops.
unsigned getNumBackEdges() const
Calculate the number of back edges to the loop header.
iterator_range< block_iterator > blocks() const
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
bool isLoopHeader(const BlockT *BB) const
LLVM_ABI bool isInvariantStoreOfReduction(StoreInst *SI)
Returns True if given store is a final invariant store of one of the reductions found in the loop.
LLVM_ABI void collectUnitStridePredicates() const
Add unit stride predicates for memory accesses to PSE, if runtime checks are allowed and an inner loo...
LLVM_ABI bool isInvariantAddressOfReduction(Value *V)
Returns True if given address is invariant and is used to store recurrent expression.
LLVM_ABI bool canVectorize(bool UseVPlanNativePath)
Returns true if it is legal to vectorize this loop.
LLVM_ABI bool blockNeedsPredication(const BasicBlock *BB) const
Return true if the block BB needs to be predicated in order for the loop to be vectorized.
LLVM_ABI int isConsecutivePtr(Type *AccessTy, Value *Ptr) const
Check if this pointer is consecutive when vectorizing.
bool hasUncountableExitWithSideEffects() const
Returns true if this is an early exit loop with state-changing or potentially-faulting operations and...
LLVM_ABI bool canVectorizeFPMath(bool EnableStrictReductions)
Returns true if it is legal to vectorize the FP math operations in this loop.
LLVM_ABI bool isFixedOrderRecurrence(const PHINode *Phi) const
Returns True if Phi is a fixed-order recurrence in this loop.
LLVM_ABI bool isInductionPhi(const Value *V) const
Returns True if V is a Phi node of an induction variable in this loop.
const InductionList & getInductionVars() const
Returns the induction variables found in the loop.
LLVM_ABI bool isInvariant(Value *V) const
Returns true if V is invariant across all loop iterations according to SCEV.
const ReductionList & getReductionVars() const
Returns the reduction variables found in the loop.
LLVM_ABI bool canFoldTailByMasking() const
Return true if we can vectorize this loop while folding its tail by masking.
LLVM_ABI void prepareToFoldTailByMasking()
Mark all respective loads/stores for masking.
bool hasUncountableEarlyExit() const
Returns true if the loop has uncountable early exits, i.e.
LLVM_ABI bool isUniformMemOp(Instruction &I, std::optional< ElementCount > VF) const
A uniform memory op is a load or store which accesses the same memory location on all VF lanes,...
LLVM_ABI bool isUniform(Value *V, std::optional< ElementCount > VF) const
Returns true if value V is uniform across VF lanes, when VF is provided, and otherwise if V is invari...
LLVM_ABI bool isInductionVariable(const Value *V) const
Returns True if V can be considered as an induction variable in this loop.
LLVM_ABI bool isCastedInductionVariable(const Value *V) const
Returns True if V is a cast that is part of an induction def-use chain, and had been proven to be red...
@ SK_PreferScalable
Vectorize loops using scalable vectors or fixed-width vectors, but favor scalable vectors when the co...
@ SK_AlwaysScalable
Always vectorize loops using scalable vectors if feasible (i.e.
@ SK_Unspecified
Not selected.
@ SK_FixedWidthOnly
Disables vectorization with scalable vectors.
enum ForceKind getForce() const
LLVM_ABI bool allowVectorization(Function *F, Loop *L, bool VectorizeOnlyWhenForced) const
LLVM_ABI bool allowReordering() const
When enabling loop hints are provided we allow the vectorizer to change the order of operations that ...
LLVM_ABI void emitRemarkWithHints() const
Dumps all the hint information.
ElementCount getWidth() const
@ FK_Enabled
Forcing enabled.
@ FK_Undefined
Not selected.
@ FK_Disabled
Forcing disabled.
LLVM_ABI void setAlreadyVectorized()
Mark the loop L as already vectorized by setting the width to 1.
LLVM_ABI LoopVectorizeHints(const Loop *L, bool InterleaveOnlyWhenForced, OptimizationRemarkEmitter &ORE, const TargetTransformInfo *TTI=nullptr)
unsigned getInterleave() const
unsigned getIsVectorized() const
Represents a single loop in the control flow graph.
bool isLoopInvariant(const Value *V) const
Return true if the specified value is loop invariant.
PHINode * getCanonicalInductionVariable() const
Check to see if the loop has a canonical induction variable: an integer recurrence that starts at 0 a...
MDNode * getLoopID() const
Return the llvm.loop loop id metadata node for this loop if it is present.
const MDOperand & getOperand(unsigned I) const
ArrayRef< MDOperand > operands() const
unsigned getNumOperands() const
Return number of MDNode operands.
Tracking metadata reference owned by Metadata.
LLVM_ABI StringRef getString() const
Checks memory dependences among accesses to the same underlying object to determine whether there vec...
const SmallVectorImpl< Dependence > * getDependences() const
Returns the memory dependences.
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.
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
Instruction * getExactFPMathInst() const
Returns 1st non-reassociative FP instruction in the PHI node's use-chain.
static LLVM_ABI bool isFixedOrderRecurrence(PHINode *Phi, Loop *TheLoop, DominatorTree *DT)
Returns true if Phi is a fixed-order recurrence.
bool hasExactFPMath() const
Returns true if the recurrence has floating-point math that requires precise (ordered) operations.
static LLVM_ABI bool isReductionPHI(PHINode *Phi, Loop *TheLoop, RecurrenceDescriptor &RedDes, DemandedBits *DB=nullptr, AssumptionCache *AC=nullptr, DominatorTree *DT=nullptr, ScalarEvolution *SE=nullptr)
Returns true if Phi is a reduction in TheLoop.
bool hasUsesOutsideReductionChain() const
Returns true if the reduction PHI has any uses outside the reduction chain.
RecurKind getRecurrenceKind() const
bool isOrdered() const
Expose an ordered FP reduction to the instance users.
StoreInst * IntermediateStore
Reductions may store temporary or final result to an invariant address.
static bool isMinMaxRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is any min/max kind.
const Loop * getLoop() const
SCEVUse getStepRecurrence(ScalarEvolution &SE) const
Constructs and returns the recurrence indicating how much this expression steps by.
This visitor recursively visits a SCEV expression and re-writes it.
const SCEV * visit(const SCEV *S)
This class represents an analyzed expression in the program.
static constexpr auto FlagAnyWrap
Type * getType() const
Return the LLVM type of this SCEV expression.
The main scalar evolution driver.
LLVM_ABI const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
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 bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
LLVM_ABI const SCEV * getCouldNotCompute()
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
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.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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.
An instruction for storing to memory.
Value * getPointerOperand()
Represent a constant reference to a string, i.e.
Provides information about what library functions are available for the current target.
void getWidestVF(StringRef ScalarF, ElementCount &FixedVF, ElementCount &ScalableVF) const
Returns the largest vectorization factor used in the list of vector functions.
bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
bool isPointerTy() const
True if this is an instance of PointerType.
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isIntOrPtrTy() const
Return true if this is an integer type or a pointer type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
Value * getOperand(unsigned i) const
static bool hasMaskedVariant(const CallInst &CI, std::optional< ElementCount > VF=std::nullopt)
static SmallVector< VFInfo, 8 > getMappings(const CallInst &CI)
Retrieve all the VFInfo instances associated to the CallInst CI.
LLVM Value Representation.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
static constexpr bool isKnownLE(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
constexpr bool isZero() const
const ParentTy * getParent() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ BasicBlock
Various leaf nodes.
void reportVectorizationFailure(const StringRef DebugMsg, const StringRef OREMsg, const StringRef ORETag, OptimizationRemarkEmitter *ORE, const Loop *TheLoop, Instruction *I=nullptr)
Reports a vectorization failure: print DebugMsg for debugging purposes along with the corresponding o...
OneUse_match< SubPat > m_OneUse(const SubPat &SP)
TwoOps_match< ValueOpTy, PointerOpTy, Instruction::Store > m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp)
Matches StoreInst.
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
bool match(Val *V, const Pattern &P)
match_bind< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
CmpClass_match< LHS, RHS, ICmpInst, true > m_c_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
Matches an ICmp with a predicate over LHS and RHS in either order.
auto m_BinOp()
Match an arbitrary binary operation and ignore it.
auto m_Value()
Match an arbitrary value and ignore it.
match_combine_or< match_combine_or< CastInst_match< OpTy, ZExtInst >, CastInst_match< OpTy, SExtInst > >, OpTy > m_ZExtOrSExtOrSelf(const OpTy &Op)
OneOps_match< OpTy, Instruction::Load > m_Load(const OpTy &Op)
Matches LoadInst.
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract(Y &&MD)
Extract a Value from Metadata, if any.
Add a small namespace to avoid name clashes with the classes used in the streaming interface.
NodeAddr< PhiNode * > Phi
NodeAddr< FuncNode * > Func
friend class Instruction
Iterator for Instructions in a `BasicBlock.
bool isSimple(Instruction *I)
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.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
LLVM_ABI Intrinsic::ID getVectorIntrinsicIDForCall(const CallInst *CI, const TargetLibraryInfo *TLI)
Returns intrinsic ID for call.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto successors(const MachineBasicBlock *BB)
const Value * getLoadStorePointerOperand(const Value *V)
A helper function that returns the pointer operand of a load or store instruction.
@ Load
The value being inserted comes from a load (InsertElement only).
static bool isUniformLoopNest(Loop *Lp, Loop *OuterLp)
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
static bool isUniformLoop(Loop *Lp, Loop *OuterLp)
LLVM_ABI bool mustSuppressSpeculation(const LoadInst &LI)
Return true if speculation of the given load must be suppressed to avoid ordering or interfering with...
LLVM_ABI bool isSafeToSpeculativelyExecute(const Instruction *I, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr, bool UseVariableInfo=true, bool IgnoreUBImplyingAttrs=true)
Return true if the instruction does not have any effects besides calculating the result and does not ...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
auto dyn_cast_or_null(const Y &Val)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto reverse(ContainerTy &&C)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
static IntegerType * getWiderInductionTy(const DataLayout &DL, Type *Ty0, Type *Ty1)
static IntegerType * getInductionIntegerTy(const DataLayout &DL, Type *Ty)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI bool hasDisableAllTransformsHint(const Loop *L)
Look for the loop attribute that disables all transformation heuristic.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
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...
static bool storeToSameAddress(ScalarEvolution *SE, StoreInst *A, StoreInst *B)
Returns true if A and B have same pointer operands or same SCEVs addresses.
bool canVectorizeTy(Type *Ty)
Returns true if Ty is a valid vector element type, void, or an unpacked literal struct where all elem...
LLVM_ABI bool isVectorIntrinsicWithScalarOpAtArg(Intrinsic::ID ID, unsigned ScalarOpdIdx, const TargetTransformInfo *TTI)
Identifies if the vector form of the intrinsic has a scalar operand.
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool isReadOnlyLoop(Loop *L, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC, SmallVectorImpl< LoadInst * > &NonDereferenceableAndAlignedLoads, SmallVectorImpl< const SCEVPredicate * > *Predicates=nullptr)
Returns true if the loop contains read-only memory accesses and doesn't throw.
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Type * getLoadStoreType(const Value *I)
A helper function that returns the type of a load or store instruction.
static bool findHistogram(LoadInst *LI, StoreInst *HSt, Loop *TheLoop, const PredicatedScalarEvolution &PSE, SmallVectorImpl< HistogramInfo > &Histograms)
Find histogram operations that match high-level code in loops:
LLVM_ABI bool isGuaranteedNotToBePoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be poison, but may be undef.
static bool isTLIScalarize(const TargetLibraryInfo &TLI, const CallInst &CI)
Checks if a function is scalarizable according to the TLI, in the sense that it should be vectorized ...
LLVM_ABI bool isDereferenceableAndAlignedInLoop(LoadInst *LI, Loop *L, ScalarEvolution &SE, DominatorTree &DT, AssumptionCache *AC=nullptr, SmallVectorImpl< const SCEVPredicate * > *Predicates=nullptr)
Return true if we can prove that the given load (which is assumed to be within the specified loop) wo...
LLVM_ABI std::optional< int64_t > getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr, const Loop *Lp, const DominatorTree &DT, const DenseMap< Value *, const SCEV * > &StridesMap=DenseMap< Value *, const SCEV * >(), bool ShouldCheckWrap=true, SmallVectorImpl< const SCEVPredicate * > *Predicates=nullptr)
If the pointer has a constant stride return it in units of the access type size.
constexpr detail::IsaCheckPredicate< Types... > IsaPred
Function object wrapper for the llvm::isa type check.
SCEVUseT< const SCEV * > SCEVUse
bool SCEVExprContains(const SCEV *Root, PredTy Pred)
Return true if any node in Root satisfies the predicate Pred.
Dependece between memory access instructions.
Instruction * getDestination(const MemoryDepChecker &DepChecker) const
Return the destination instruction of the dependence.
Instruction * getSource(const MemoryDepChecker &DepChecker) const
Return the source instruction of the dependence.
static LLVM_ABI VectorizationSafetyStatus isSafeForVectorization(DepType Type)
Dependence types that don't prevent vectorization.
TODO: The following VectorizationFactor was pulled out of LoopVectorizationCostModel class.
Collection of parameters shared beetween the Loop Vectorizer and the Loop Access Analysis.
static LLVM_ABI const unsigned MaxVectorWidth
Maximum SIMD width.
static LLVM_ABI bool isInterleaveForced()
True if force-vector-interleave was specified by the user.
static LLVM_ABI unsigned VectorizationInterleave
Interleave factor as overridden by the user.
static LLVM_ABI ElementCount VectorizationFactor
VF as overridden by the user.