44#define LV_NAME "loop-vectorize"
45#define DEBUG_TYPE LV_NAME
50 return cast<VPInterleaveRecipe>(
this)->getNumStoreOperands() > 0;
51 case VPWidenStoreEVLSC:
58 return !cast<VPWidenCallRecipe>(
this)
59 ->getCalledScalarFunction()
61 case VPBranchOnMaskSC:
62 case VPScalarIVStepsSC:
66 case VPReductionEVLSC:
68 case VPWidenCanonicalIVSC:
71 case VPWidenIntOrFpInductionSC:
72 case VPWidenLoadEVLSC:
76 case VPWidenSelectSC: {
80 assert((!
I || !
I->mayWriteToMemory()) &&
81 "underlying instruction may write to memory");
91 case VPWidenLoadEVLSC:
96 ->mayReadFromMemory();
98 return !cast<VPWidenCallRecipe>(
this)
99 ->getCalledScalarFunction()
100 ->onlyWritesMemory();
101 case VPBranchOnMaskSC:
102 case VPPredInstPHISC:
103 case VPScalarIVStepsSC:
104 case VPWidenStoreEVLSC:
108 case VPReductionEVLSC:
110 case VPWidenCanonicalIVSC:
113 case VPWidenIntOrFpInductionSC:
116 case VPWidenSelectSC: {
120 assert((!
I || !
I->mayReadFromMemory()) &&
121 "underlying instruction may read from memory");
132 case VPPredInstPHISC:
135 case VPInstructionSC:
136 switch (cast<VPInstruction>(
this)->
getOpcode()) {
137 case Instruction::Or:
138 case Instruction::ICmp:
139 case Instruction::Select:
151 case VPWidenCallSC: {
152 Function *Fn = cast<VPWidenCallRecipe>(
this)->getCalledScalarFunction();
156 case VPReductionEVLSC:
158 case VPScalarIVStepsSC:
159 case VPWidenCanonicalIVSC:
162 case VPWidenIntOrFpInductionSC:
164 case VPWidenPointerInductionSC:
166 case VPWidenSelectSC: {
170 assert((!
I || !
I->mayHaveSideEffects()) &&
171 "underlying instruction has side-effects");
176 case VPWidenLoadEVLSC:
178 case VPWidenStoreEVLSC:
183 "mayHaveSideffects result for ingredient differs from this "
186 case VPReplicateSC: {
187 auto *R = cast<VPReplicateRecipe>(
this);
188 return R->getUnderlyingInstr()->mayHaveSideEffects();
203 auto *ExitingVPBB = ExitingRecipe ? ExitingRecipe->
getParent() :
nullptr;
220#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
231 assert(!Parent &&
"Recipe already in some VPBasicBlock");
233 "Insertion position not in any VPBasicBlock");
239 assert(!Parent &&
"Recipe already in some VPBasicBlock");
245 assert(!Parent &&
"Recipe already in some VPBasicBlock");
247 "Insertion position not in any VPBasicBlock");
276 if (
auto *S = dyn_cast<VPSingleDefRecipe>(R))
277 return dyn_cast_or_null<Instruction>(S->getUnderlyingValue());
278 if (
auto *IG = dyn_cast<VPInterleaveRecipe>(R))
279 return IG->getInsertPos();
280 if (
auto *WidenMem = dyn_cast<VPWidenMemoryRecipe>(R))
281 return &WidenMem->getIngredient();
296 dbgs() <<
"Cost of " << RecipeCost <<
" for VF " << VF <<
": ";
308 if (UI && isa<VPReplicateRecipe>(
this)) {
317 assert(OpType == OperationType::FPMathOp &&
318 "recipe doesn't have fast math flags");
336 assert(Opcode == Instruction::ICmp &&
337 "only ICmp predicates supported at the moment");
341 std::initializer_list<VPValue *>
Operands,
346 assert(isFPMathOp() &&
"this op can't take fast-math flags");
349bool VPInstruction::doesGeneratePerAllLanes()
const {
353bool VPInstruction::canGenerateScalarForFirstLane()
const {
359 case Instruction::ICmp:
377 "only PtrAdd opcodes are supported for now");
391 if (
auto *
I = dyn_cast<Instruction>(Res))
401 case Instruction::ICmp: {
407 case Instruction::Select: {
429 {VIVElem0, ScalarTC},
nullptr, Name);
454 return State.
get(
this, 0,
true);
467 assert(AVL->getType()->isIntegerTy() &&
468 "Requested vector length should be an integer.");
476 {AVL, VFArg, State.Builder.getTrue()});
481 assert(Part == 0 &&
"No unrolling expected for predicated vectorization.");
486 Value *EVL = GetEVL(State, AVL);
547 return State.
get(
this, 0,
true);
551 auto *PhiR = cast<VPReductionPHIRecipe>(
getOperand(0));
552 auto *OrigPhi = cast<PHINode>(PhiR->getUnderlyingValue());
559 Type *PhiTy = OrigPhi->getType();
561 for (
unsigned Part = 0; Part < State.
UF; ++Part)
562 RdxParts[Part] = State.
get(LoopExitingDef, Part, PhiR->isInLoop());
570 for (
unsigned Part = 0; Part < State.
UF; ++Part)
571 RdxParts[Part] = Builder.
CreateTrunc(RdxParts[Part], RdxVecTy);
574 Value *ReducedPartRdx = RdxParts[0];
577 Op = Instruction::Or;
579 if (PhiR->isOrdered()) {
580 ReducedPartRdx = RdxParts[State.
UF - 1];
585 for (
unsigned Part = 1; Part < State.
UF; ++Part) {
586 Value *RdxPart = RdxParts[Part];
587 if (
Op != Instruction::ICmp &&
Op != Instruction::FCmp)
591 ReducedPartRdx =
createMinMaxOp(Builder, RK, ReducedPartRdx, RdxPart);
614 ReducedPartRdx,
SI->getPointerOperand(),
SI->getAlign());
618 return ReducedPartRdx;
622 return State.
get(
this, 0,
true);
625 unsigned Offset = CI->getZExtValue();
626 assert(
Offset > 0 &&
"Offset from end must be positive");
630 "invalid offset to extract from");
640 if (isa<ExtractElementInst>(Res))
651 "can only generate first lane for PtrAdd");
658 return State.
get(
this, 0,
true);
659 Value *IncomingFromVPlanPred =
661 Value *IncomingFromOtherPreds =
668 NewPhi->addIncoming(IncomingFromVPlanPred, VPlanPred);
670 assert(OtherPred != VPlanPred &&
671 "VPlan predecessors should not be connected yet");
672 NewPhi->addIncoming(IncomingFromOtherPreds, OtherPred);
692bool VPInstruction::isFPMathOp()
const {
695 return Opcode == Instruction::FAdd || Opcode == Instruction::FMul ||
696 Opcode == Instruction::FNeg || Opcode == Instruction::FSub ||
697 Opcode == Instruction::FDiv || Opcode == Instruction::FRem ||
698 Opcode == Instruction::FCmp || Opcode == Instruction::Select;
707 "Recipe not a FPMathOp but has fast-math flags?");
711 bool GeneratesPerFirstLaneOnly = canGenerateScalarForFirstLane() &&
714 bool GeneratesPerAllLanes = doesGeneratePerAllLanes();
716 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
717 if (GeneratesPerAllLanes) {
719 Lane != NumLanes; ++Lane) {
721 assert(GeneratedValue &&
"generatePerLane must produce a value");
727 if (Part != 0 && OnlyFirstPartUsed &&
hasResult()) {
728 Value *Part0 = State.
get(
this, 0, GeneratesPerFirstLaneOnly);
729 State.
set(
this, Part0, Part,
730 GeneratesPerFirstLaneOnly);
734 Value *GeneratedValue = generatePerPart(State, Part);
737 assert(GeneratedValue &&
"generatePerPart must produce a value");
739 !GeneratesPerFirstLaneOnly ||
741 "scalar value but not only first lane defined");
742 State.
set(
this, GeneratedValue, Part,
743 GeneratesPerFirstLaneOnly);
755 case Instruction::ICmp:
779 case Instruction::ICmp:
780 case Instruction::Select:
790#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
798 O << Indent <<
"EMIT ";
810 O <<
"combined load";
813 O <<
"combined store";
816 O <<
"active lane mask";
822 O <<
"EXPLICIT-VECTOR-LENGTH";
825 O <<
"first-order splice";
828 O <<
"branch-on-cond";
831 O <<
"TC > VF ? TC - VF : 0";
837 O <<
"branch-on-count";
840 O <<
"extract-from-end";
843 O <<
"compute-reduction-result";
869 "DbgInfoIntrinsic should have been dropped during VPlan construction");
876 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
897 Arg = State.
get(
I.value(), Part);
909 assert(VectorF &&
"Can't retrieve vector intrinsic.");
912 assert(Variant !=
nullptr &&
"Can't create vector function.");
920 CI->getOperandBundlesAsDefs(OpBundles);
924 if (isa<FPMathOperator>(V))
925 V->copyFastMathFlags(CI);
927 if (!V->getType()->isVoidTy())
928 State.
set(
this, V, Part);
933#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
936 O << Indent <<
"WIDEN-CALL ";
946 O <<
"call @" << CalledFn->
getName() <<
"(";
952 if (VectorIntrinsicID)
953 O <<
" (using vector intrinsic)";
955 O <<
" (using library function";
957 O <<
": " << Variant->
getName();
964 O << Indent <<
"WIDEN-SELECT ";
986 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
991 State.
set(
this, Sel, Part);
996VPRecipeWithIRFlags::FastMathFlagsTy::FastMathFlagsTy(
1007#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1010 case OperationType::Cmp:
1013 case OperationType::DisjointOp:
1017 case OperationType::PossiblyExactOp:
1021 case OperationType::OverflowingBinOp:
1027 case OperationType::FPMathOp:
1030 case OperationType::GEPOp:
1034 case OperationType::NonNegOp:
1038 case OperationType::Other:
1048 auto &Builder = State.
Builder;
1050 case Instruction::Call:
1051 case Instruction::Br:
1052 case Instruction::PHI:
1053 case Instruction::GetElementPtr:
1054 case Instruction::Select:
1056 case Instruction::UDiv:
1057 case Instruction::SDiv:
1058 case Instruction::SRem:
1059 case Instruction::URem:
1060 case Instruction::Add:
1061 case Instruction::FAdd:
1062 case Instruction::Sub:
1063 case Instruction::FSub:
1064 case Instruction::FNeg:
1065 case Instruction::Mul:
1066 case Instruction::FMul:
1067 case Instruction::FDiv:
1068 case Instruction::FRem:
1069 case Instruction::Shl:
1070 case Instruction::LShr:
1071 case Instruction::AShr:
1072 case Instruction::And:
1073 case Instruction::Or:
1074 case Instruction::Xor: {
1076 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
1083 if (
auto *VecOp = dyn_cast<Instruction>(V))
1087 State.
set(
this, V, Part);
1093 case Instruction::Freeze: {
1094 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
1098 State.
set(
this, Freeze, Part);
1102 case Instruction::ICmp:
1103 case Instruction::FCmp: {
1105 bool FCmp = Opcode == Instruction::FCmp;
1106 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
1119 State.
set(
this,
C, Part);
1135 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
1138 "inferred type and type from generated instructions do not match");
1147 case Instruction::FNeg: {
1156 case Instruction::UDiv:
1157 case Instruction::SDiv:
1158 case Instruction::SRem:
1159 case Instruction::URem:
1162 case Instruction::Add:
1163 case Instruction::FAdd:
1164 case Instruction::Sub:
1165 case Instruction::FSub:
1166 case Instruction::Mul:
1167 case Instruction::FMul:
1168 case Instruction::FDiv:
1169 case Instruction::FRem:
1170 case Instruction::Shl:
1171 case Instruction::LShr:
1172 case Instruction::AShr:
1173 case Instruction::And:
1174 case Instruction::Or:
1175 case Instruction::Xor: {
1181 if (
RHS->isLiveIn())
1199 case Instruction::Freeze: {
1205 case Instruction::ICmp:
1206 case Instruction::FCmp: {
1217#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1220 O << Indent <<
"WIDEN ";
1230 auto &Builder = State.
Builder;
1235 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
1236 if (Part > 0 &&
Op->isLiveIn()) {
1238 State.
set(
this, State.
get(
this, 0), Part);
1243 State.
set(
this, Cast, Part);
1248#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1251 O << Indent <<
"WIDEN-CAST ";
1270 auto *ValVTy = cast<VectorType>(Val->
getType());
1275 "Induction Step must be an integer or FP");
1283 Type *InitVecValSTy =
1293 InitVec = Builder.
CreateAdd(InitVec, StartIdxSplat);
1298 Step = Builder.
CreateMul(InitVec, Step);
1299 return Builder.
CreateAdd(Val, Step,
"induction");
1303 assert((BinOp == Instruction::FAdd || BinOp == Instruction::FSub) &&
1304 "Binary Opcode should be specified for FP induction");
1306 InitVec = Builder.
CreateFAdd(InitVec, StartIdxSplat);
1310 return Builder.
CreateBinOp(BinOp, Val, MulOp,
"induction");
1317 : ConstantFP::get(Ty,
C);
1325 return B.CreateUIToFP(RuntimeVF, FTy);
1329 assert(!State.
Instance &&
"Int or FP induction being replicated.");
1335 assert(IV->
getType() ==
ID.getStartValue()->getType() &&
"Types must match");
1340 Instruction *EntryVal = Trunc ? cast<Instruction>(Trunc) : IV;
1344 if (
ID.getInductionBinOp() && isa<FPMathOperator>(
ID.getInductionBinOp()))
1350 assert((isa<PHINode>(EntryVal) || isa<TruncInst>(EntryVal)) &&
1351 "Expected either an induction phi-node or a truncate of it!");
1354 auto CurrIP = Builder.
saveIP();
1357 if (isa<TruncInst>(EntryVal)) {
1358 assert(Start->getType()->isIntegerTy() &&
1359 "Truncation requires an integer type");
1360 auto *TruncType = cast<IntegerType>(EntryVal->
getType());
1362 Start = Builder.
CreateCast(Instruction::Trunc, Start, TruncType);
1368 SplatStart, Zero, Step,
ID.getInductionOpcode(), State.
VF, State.
Builder);
1375 AddOp = Instruction::Add;
1376 MulOp = Instruction::Mul;
1378 AddOp =
ID.getInductionOpcode();
1379 MulOp = Instruction::FMul;
1397 Value *SplatVF = isa<Constant>(
Mul)
1408 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
1409 State.
set(
this, LastInduction, Part);
1411 if (isa<TruncInst>(EntryVal))
1414 LastInduction = cast<Instruction>(
1415 Builder.
CreateBinOp(AddOp, LastInduction, SplatVF,
"step.add"));
1419 LastInduction->
setName(
"vec.ind.next");
1429#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1432 O << Indent <<
"WIDEN-INDUCTION";
1436 O <<
" +\n" << Indent <<
"\" ";
1454 auto *CanIV = cast<VPCanonicalIVPHIRecipe>(&*
getParent()->begin());
1455 return StartC && StartC->isZero() && StepC && StepC->isOne() &&
1459#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1464 O << Indent <<
"= DERIVED-IV ";
1488 assert(BaseIVTy == Step->
getType() &&
"Types of BaseIV and Step must match!");
1495 AddOp = Instruction::Add;
1496 MulOp = Instruction::Mul;
1498 AddOp = InductionOpcode;
1499 MulOp = Instruction::FMul;
1508 Type *VecIVTy =
nullptr;
1509 Value *UnitStepVec =
nullptr, *SplatStep =
nullptr, *SplatIV =
nullptr;
1518 unsigned StartPart = 0;
1519 unsigned EndPart = State.
UF;
1520 unsigned StartLane = 0;
1524 EndPart = StartPart + 1;
1525 StartLane = State.
Instance->Lane.getKnownLane();
1526 EndLane = StartLane + 1;
1528 for (
unsigned Part = StartPart; Part < EndPart; ++Part) {
1533 auto *InitVec = Builder.
CreateAdd(SplatStartIdx, UnitStepVec);
1538 State.
set(
this,
Add, Part);
1547 for (
unsigned Lane = StartLane; Lane < EndLane; ++Lane) {
1553 "Expected StartIdx to be folded to a constant when VF is not "
1562#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1567 O <<
" = SCALAR-STEPS ";
1581 if (areAllOperandsInvariant()) {
1601 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
1603 State.
set(
this, EntryPart, Part);
1614 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
1617 auto *
Ptr = isPointerLoopInvariant()
1626 if (isIndexLoopInvariant(
I - 1))
1637 "NewGEP is not a pointer vector");
1638 State.
set(
this, NewGEP, Part);
1644#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1647 O << Indent <<
"WIDEN-GEP ";
1648 O << (isPointerLoopInvariant() ?
"Inv" :
"Var");
1650 O <<
"[" << (isIndexLoopInvariant(
I) ?
"Inv" :
"Var") <<
"]";
1654 O <<
" = getelementptr";
1661 auto &Builder = State.
Builder;
1663 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
1665 Value *PartPtr =
nullptr;
1671 ?
DL.getIndexType(IndexedTy->getPointerTo())
1674 bool InBounds = isInBounds();
1683 ConstantInt::get(IndexTy, -(int64_t)Part), RunTimeVF);
1686 Builder.
CreateSub(ConstantInt::get(IndexTy, 1), RunTimeVF);
1687 PartPtr = Builder.
CreateGEP(IndexedTy,
Ptr, NumElt,
"", InBounds);
1688 PartPtr = Builder.
CreateGEP(IndexedTy, PartPtr, LastLane,
"", InBounds);
1691 PartPtr = Builder.
CreateGEP(IndexedTy,
Ptr, Increment,
"", InBounds);
1694 State.
set(
this, PartPtr, Part,
true);
1698#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1703 O <<
" = vector-pointer ";
1731 for (
unsigned In = 0; In < NumIncoming; ++In) {
1732 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
1748 for (
unsigned Part = 0; Part < State.
UF; ++Part)
1749 State.
set(
this, Entry[Part], Part, OnlyFirstLaneUsed);
1752#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1755 O << Indent <<
"BLEND ";
1783 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
1808 PrevInChain = NewRed;
1815 NewRed, PrevInChain);
1816 }
else if (IsOrdered)
1817 NextInChain = NewRed;
1821 State.
set(
this, NextInChain, Part,
true);
1828 "Expected only UF == 1 when vectorizing with explicit vector length.");
1830 auto &Builder = State.
Builder;
1846 Mask = State.
get(CondOp, 0);
1862 State.
set(
this, NewRed, 0,
true);
1865#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1868 O << Indent <<
"REDUCE ";
1883 O <<
" (with final reduction value stored in invariant address sank "
1890 O << Indent <<
"REDUCE ";
1907 O <<
" (with final reduction value stored in invariant address sank "
1916 if (
auto *PredR = dyn_cast<VPPredInstPHIRecipe>(U))
1917 return any_of(PredR->users(), [PredR](
const VPUser *U) {
1918 return !U->usesScalars(PredR);
1924#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1927 O << Indent << (IsUniform ?
"CLONE " :
"REPLICATE ");
1936 O <<
"@" << CB->getCalledFunction()->getName() <<
"(";
1959 return C->isDefinedOutsideVectorRegions() ||
1960 isa<VPDerivedIVRecipe>(
C->getOperand(0)) ||
1961 isa<VPCanonicalIVPHIRecipe>(
C->getOperand(0));
1966 "Codegen only implemented for first lane.");
1968 case Instruction::SExt:
1969 case Instruction::ZExt:
1970 case Instruction::Trunc: {
1982 for (
unsigned Part = 0; Part != State.
UF; ++Part) {
1986 if (Part > 0 && IsUniformAcrossVFsAndUFs)
1989 Res = generate(State, Part);
1994#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1997 O << Indent <<
"SCALAR-CAST ";
2001 O <<
" to " << *ResultTy;
2006 assert(State.
Instance &&
"Branch on Mask works only on single instance.");
2008 unsigned Part = State.
Instance->Part;
2009 unsigned Lane = State.
Instance->Lane.getKnownLane();
2011 Value *ConditionBit =
nullptr;
2014 ConditionBit = State.
get(BlockInMask, Part);
2024 assert(isa<UnreachableInst>(CurrentTerminator) &&
2025 "Expected to replace unreachable terminator with conditional branch.");
2032 assert(State.
Instance &&
"Predicated instruction PHI works per instance.");
2037 assert(PredicatingBB &&
"Predicated block has no single predecessor.");
2039 "operand must be VPReplicateRecipe");
2047 unsigned Part = State.
Instance->Part;
2055 State.
reset(
this, VPhi, Part);
2057 State.
set(
this, VPhi, Part);
2066 Phi->addIncoming(ScalarPredInst, PredicatedBB);
2077#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2080 O << Indent <<
"PHI-PREDICATED-INSTRUCTION ";
2095 auto &Builder = State.
Builder;
2097 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
2099 Value *Mask =
nullptr;
2100 if (
auto *VPMask =
getMask()) {
2103 Mask = State.
get(VPMask, Part);
2111 "wide.masked.gather");
2115 "wide.masked.load");
2123 State.
set(
this, NewLI, Part);
2127#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2130 O << Indent <<
"WIDEN ";
2138 O << Indent <<
"WIDEN ";
2152 auto &Builder = State.
Builder;
2155 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
2157 Value *Mask =
nullptr;
2158 if (
auto *VPMask =
getMask()) {
2161 Mask = State.
get(VPMask, Part);
2166 Value *StoredVal = State.
get(StoredVPValue, Part);
2185#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2188 O << Indent <<
"WIDEN store ";
2194 O << Indent <<
"WIDEN vp.store ";
2202 auto VF = DstVTy->getElementCount();
2203 auto *SrcVecTy = cast<VectorType>(V->getType());
2204 assert(VF == SrcVecTy->getElementCount() &&
"Vector dimensions do not match");
2205 Type *SrcElemTy = SrcVecTy->getElementType();
2206 Type *DstElemTy = DstVTy->getElementType();
2207 assert((
DL.getTypeSizeInBits(SrcElemTy) ==
DL.getTypeSizeInBits(DstElemTy)) &&
2208 "Vector elements must have same size");
2219 "Only one type should be a pointer type");
2221 "Only one type should be a floating point type");
2233 unsigned Factor = Vals.
size();
2234 assert(Factor > 1 &&
"Tried to interleave invalid number of vectors");
2238 for (
Value *Val : Vals)
2239 assert(Val->getType() == VecTy &&
"Tried to interleave mismatched types");
2244 if (VecTy->isScalableTy()) {
2246 return Builder.
CreateIntrinsic(WideVecTy, Intrinsic::vector_interleave2,
2255 const unsigned NumElts = VecTy->getElementCount().getFixedValue();
2295 unsigned InterleaveFactor = Group->
getFactor();
2305 "Reversed masked interleave-group not supported.");
2326 for (
unsigned Part = 0; Part < State.
UF; Part++) {
2328 if (
auto *
I = dyn_cast<Instruction>(AddrPart))
2343 bool InBounds =
false;
2345 InBounds =
gep->isInBounds();
2353 auto CreateGroupMask = [&BlockInMask, &State, &InterleaveFactor](
2354 unsigned Part,
Value *MaskForGaps) ->
Value * {
2356 assert(!MaskForGaps &&
"Interleaved groups with gaps are not supported.");
2357 assert(InterleaveFactor == 2 &&
2358 "Unsupported deinterleave factor for scalable vectors");
2359 auto *BlockInMaskPart = State.
get(BlockInMask, Part);
2364 MaskTy, Intrinsic::vector_interleave2, Ops,
2365 nullptr,
"interleaved.mask");
2371 Value *BlockInMaskPart = State.
get(BlockInMask, Part);
2375 "interleaved.mask");
2377 ShuffledMask, MaskForGaps)
2383 if (isa<LoadInst>(Instr)) {
2384 Value *MaskForGaps =
nullptr;
2385 if (NeedsMaskForGaps) {
2388 assert(MaskForGaps &&
"Mask for Gaps is required but it is null");
2393 for (
unsigned Part = 0; Part < State.
UF; Part++) {
2395 if (BlockInMask || MaskForGaps) {
2396 Value *GroupMask = CreateGroupMask(Part, MaskForGaps);
2399 PoisonVec,
"wide.masked.vec");
2402 VecTy, AddrParts[Part], Group->
getAlign(),
"wide.vec");
2409 if (VecTy->isScalableTy()) {
2410 assert(InterleaveFactor == 2 &&
2411 "Unsupported deinterleave factor for scalable vectors");
2413 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
2417 Intrinsic::vector_deinterleave2, VecTy, NewLoads[Part],
2418 nullptr,
"strided.vec");
2420 for (
unsigned I = 0;
I < InterleaveFactor; ++
I) {
2428 if (Member->getType() != ScalarTy) {
2438 State.
set(VPDefs[J], StridedVec, Part);
2449 for (
unsigned I = 0;
I < InterleaveFactor; ++
I) {
2458 for (
unsigned Part = 0; Part < State.
UF; Part++) {
2460 NewLoads[Part], StrideMask,
"strided.vec");
2463 if (Member->getType() != ScalarTy) {
2473 State.
set(VPDefs[J], StridedVec, Part);
2484 Value *MaskForGaps =
2487 "masking gaps for scalable vectors is not yet supported.");
2489 for (
unsigned Part = 0; Part < State.
UF; Part++) {
2492 unsigned StoredIdx = 0;
2493 for (
unsigned i = 0; i < InterleaveFactor; i++) {
2495 "Fail to get a member from an interleaved store group");
2505 Value *StoredVec = State.
get(StoredValues[StoredIdx], Part);
2513 if (StoredVec->
getType() != SubVT)
2523 if (BlockInMask || MaskForGaps) {
2524 Value *GroupMask = CreateGroupMask(Part, MaskForGaps);
2526 IVec, AddrParts[Part], Group->
getAlign(), GroupMask);
2535#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2538 O << Indent <<
"INTERLEAVE-GROUP with factor " << IG->getFactor() <<
" at ";
2539 IG->getInsertPos()->printAsOperand(O,
false);
2549 for (
unsigned i = 0; i < IG->getFactor(); ++i) {
2550 if (!IG->getMember(i))
2553 O <<
"\n" << Indent <<
" store ";
2555 O <<
" to index " << i;
2557 O <<
"\n" << Indent <<
" ";
2559 O <<
" = load from index " << i;
2574 for (
unsigned Part = 0, UF = State.
UF; Part < UF; ++Part)
2575 State.
set(
this, EntryPart, Part,
true);
2578#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2581 O << Indent <<
"EMIT ";
2583 O <<
" = CANONICAL-INDUCTION ";
2603 return StepC && StepC->
isOne();
2607 return IsScalarAfterVectorization &&
2613 "Not a pointer induction according to InductionDescriptor!");
2615 "Unexpected type.");
2617 "Recipe should have been replaced");
2620 PHINode *CanonicalIV = cast<PHINode>(State.
get(IVR, 0,
true));
2625 Type *ScStValueType = ScalarStartValue->
getType();
2630 NewPointerPhi->
addIncoming(ScalarStartValue, VectorPH);
2637 Value *NumUnrolledElems =
2648 NewPointerPhi->
addIncoming(InductionGEP, VectorPH);
2653 for (
unsigned Part = 0; Part < State.
UF; ++Part) {
2655 Value *StartOffsetScalar =
2657 Value *StartOffset =
2664 "scalar step must be the same across all parts");
2671 State.
set(
this,
GEP, Part);
2675#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2678 O << Indent <<
"EMIT ";
2680 O <<
" = WIDEN-POINTER-INDUCTION ";
2682 O <<
", " << *IndDesc.
getStep();
2694 "Same SCEV expanded multiple times");
2696 for (
unsigned Part = 0, UF = State.
UF; Part < UF; ++Part)
2697 State.
set(
this, Res, {Part, 0});
2700#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2703 O << Indent <<
"EMIT ";
2705 O <<
" = EXPAND SCEV " << *Expr;
2717 for (
unsigned Part = 0, UF = State.
UF; Part < UF; ++Part) {
2724 Value *CanonicalVectorIV = Builder.
CreateAdd(VStart, VStep,
"vec.iv");
2725 State.
set(
this, CanonicalVectorIV, Part);
2729#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2732 O << Indent <<
"EMIT ";
2734 O <<
" = WIDEN-CANONICAL-INDUCTION ";
2740 auto &Builder = State.
Builder;
2745 ? VectorInit->getType()
2751 auto *One = ConstantInt::get(IdxTy, 1);
2755 auto *LastIdx = Builder.
CreateSub(RuntimeVF, One);
2764 State.
set(
this, EntryPart, 0);
2767#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2770 O << Indent <<
"FIRST-ORDER-RECURRENCE-PHI ";
2778 auto &Builder = State.
Builder;
2789 bool ScalarPHI = State.
VF.
isScalar() || IsInLoop;
2795 "recipe must be in the vector loop header");
2796 unsigned LastPartForNewPhi =
isOrdered() ? 1 : State.
UF;
2797 for (
unsigned Part = 0; Part < LastPartForNewPhi; ++Part) {
2800 State.
set(
this, EntryPart, Part, IsInLoop);
2805 Value *Iden =
nullptr;
2831 for (
unsigned Part = 0; Part < LastPartForNewPhi; ++Part) {
2832 Value *EntryPart = State.
get(
this, Part, IsInLoop);
2835 Value *StartVal = (Part == 0) ? StartV : Iden;
2836 cast<PHINode>(EntryPart)->addIncoming(StartVal, VectorPH);
2840#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2843 O << Indent <<
"WIDEN-REDUCTION-PHI ";
2853 "Non-native vplans are not expected to have VPWidenPHIRecipes.");
2858 State.
set(
this, VecPhi, 0);
2861#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2864 O << Indent <<
"WIDEN-PHI ";
2886 for (
unsigned Part = 0, UF = State.
UF; Part < UF; ++Part) {
2892 State.
set(
this, EntryPart, Part);
2896#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2899 O << Indent <<
"ACTIVE-LANE-MASK-PHI ";
2909 assert(State.
UF == 1 &&
"Expected unroll factor 1 for VP vectorization.");
2915 State.
set(
this, EntryPart, 0,
true);
2918#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2921 O << Indent <<
"EXPLICIT-VECTOR-LENGTH-BASED-IV-PHI ";
amdgpu AMDGPU Register Bank Select
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static cl::opt< TargetTransformInfo::TargetCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(TargetTransformInfo::TCK_RecipThroughput), cl::values(clEnumValN(TargetTransformInfo::TCK_RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(TargetTransformInfo::TCK_Latency, "latency", "Instruction latency"), clEnumValN(TargetTransformInfo::TCK_CodeSize, "code-size", "Code size"), clEnumValN(TargetTransformInfo::TCK_SizeAndLatency, "size-latency", "Code size and latency")))
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
cl::opt< unsigned > ForceTargetInstructionCost("force-target-instruction-cost", cl::init(0), cl::Hidden, cl::desc("A flag that overrides the target's expected cost for " "an instruction to a single constant value. Mostly " "useful for getting consistent testing."))
mir Rename Register Operands
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
separate const offset from gep
This file defines the SmallVector class.
static SymbolRef::Type getType(const Symbol *Sym)
static Value * interleaveVectors(IRBuilderBase &Builder, ArrayRef< Value * > Vals, const Twine &Name)
Return a vector containing interleaved elements from multiple smaller input vectors.
static Value * getStepVector(Value *Val, Value *StartIdx, Value *Step, Instruction::BinaryOps BinOp, ElementCount VF, IRBuilderBase &Builder)
This function adds (StartIdx * Step, (StartIdx + 1) * Step, (StartIdx + 2) * Step,...
static Value * createBitOrPointerCast(IRBuilderBase &Builder, Value *V, VectorType *DstVTy, const DataLayout &DL)
cl::opt< unsigned > ForceTargetInstructionCost
static bool isUniformAcrossVFsAndUFs(VPScalarCastRecipe *C)
Checks if C is uniform across all VFs and UFs.
static Instruction * getInstructionForCost(const VPRecipeBase *R)
Return the underlying instruction to be used for computing R's cost via the legacy cost model.
static Constant * getSignedIntOrFpConstant(Type *Ty, int64_t C)
A helper function that returns an integer or floating-point constant with value C.
static Value * getRuntimeVFAsFloat(IRBuilderBase &B, Type *FTy, ElementCount VF)
static std::optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
This file contains the declarations of the Vectorization Plan base classes:
static const uint32_t IV[8]
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
LLVM Basic Block Representation.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
InstListType::const_iterator getFirstNonPHIIt() const
Iterator returning form of getFirstNonPHI.
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
const DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
InstListType::iterator iterator
Instruction iterators...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
void setSuccessor(unsigned idx, BasicBlock *NewSucc)
This class represents a function call, abstracting a target machine's calling convention.
static bool isBitOrNoopPointerCastable(Type *SrcTy, Type *DestTy, const DataLayout &DL)
Check whether a bitcast, inttoptr, or ptrtoint cast between these types is valid and a no-op.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ ICMP_UGT
unsigned greater than
@ ICMP_ULT
unsigned less than
static StringRef getPredicateName(Predicate P)
This is the shared class of boolean and integer constants.
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
static Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
This is an important base class in LLVM.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
constexpr bool isVector() const
One or more elements.
constexpr bool isScalar() const
Exactly one element.
Convenience struct for specifying and reasoning about fast-math flags.
void setAllowContract(bool B=true)
bool noSignedZeros() const
void setAllowReciprocal(bool B=true)
bool allowReciprocal() const
void print(raw_ostream &O) const
Print fast-math flags to O.
void setNoSignedZeros(bool B=true)
bool allowReassoc() const
Flag queries.
void setNoNaNs(bool B=true)
void setAllowReassoc(bool B=true)
Flag setters.
void setApproxFunc(bool B=true)
void setNoInfs(bool B=true)
bool allowContract() const
Class to represent function types.
Type * getParamType(unsigned i) const
Parameter type accessors.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
bool willReturn() const
Determine if the function will return.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
bool doesNotThrow() const
Determine if the function cannot unwind.
Type * getReturnType() const
Returns the type of the ret val.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Common base class shared among various IRBuilders.
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Value * CreateSIToFP(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const char *Name)
Value * CreateFAdd(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Value * CreateVectorSplice(Value *V1, Value *V2, int64_t Imm, const Twine &Name="")
Return a vector splice intrinsic if using scalable vectors, otherwise return a shufflevector.
Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
ConstantInt * getTrue()
Get the constant value for i1 true.
CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, Instruction *FMFSource=nullptr, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using Types.
CallInst * CreateMaskedLoad(Type *Ty, Value *Ptr, Align Alignment, Value *Mask, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Load intrinsic.
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
BasicBlock::iterator GetInsertPoint() const
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateFreeze(Value *V, const Twine &Name="")
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Value * CreatePtrAdd(Value *Ptr, Value *Offset, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Value * CreateUIToFP(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
BasicBlock * GetInsertBlock() const
void setFastMathFlags(FastMathFlags NewFMF)
Set the fast-math flags to be used with generated fp-math operators.
Value * CreateVectorReverse(Value *V, const Twine &Name="")
Return a vector value that contains the vector V reversed.
Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNSW=false)
InsertPoint saveIP() const
Returns the current insert point.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Value * CreateBitOrPointerCast(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateCmp(CmpInst::Predicate Pred, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Value * CreateNot(Value *V, const Twine &Name="")
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
Value * CreateNAryOp(unsigned Opc, ArrayRef< Value * > Ops, const Twine &Name="", MDNode *FPMathTag=nullptr)
Create either a UnaryOperator or BinaryOperator depending on Opc.
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
LLVMContext & getContext() const
CallInst * CreateMaskedStore(Value *Val, Value *Ptr, Align Alignment, Value *Mask)
Create a call to Masked Store intrinsic.
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="", bool IsNUW=false, bool IsNSW=false)
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name="")
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="")
void restoreIP(InsertPoint IP)
Sets the current insert point to a previously-saved location.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, MaybeAlign Align, bool isVolatile=false)
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateFMul(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Value * CreateStepVector(Type *DstType, const Twine &Name="")
Creates a vector of type DstType with the linear sequence <0, 1, ...>
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
CallInst * CreateMaskedScatter(Value *Val, Value *Ptrs, Align Alignment, Value *Mask=nullptr)
Create a call to Masked Scatter intrinsic.
CallInst * CreateMaskedGather(Type *Ty, Value *Ptrs, Align Alignment, Value *Mask=nullptr, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Gather intrinsic.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
A struct for saving information about induction variables.
InductionKind getKind() const
const SCEV * getStep() const
InductionKind
This enum represents the kinds of inductions that we support.
@ IK_PtrInduction
Pointer induction var. Step = C.
@ IK_IntInduction
Integer induction variable. Step = C.
This instruction inserts a single (scalar) element into a VectorType value.
VectorType * getType() const
Overload to return most specific vector type.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
FastMathFlags getFastMathFlags() const LLVM_READONLY
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
const char * getOpcodeName() const
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
The group of interleaved loads/stores sharing the same stride and close to each other.
uint32_t getFactor() const
InstTy * getMember(uint32_t Index) const
Get the member with the given index Index.
uint32_t getIndex(const InstTy *Instr) const
Get the index for the given member.
InstTy * getInsertPos() const
void addMetadata(InstTy *NewInst) const
Add metadata (e.g.
BlockT * getHeader() const
void print(raw_ostream &OS, const SlotIndexes *=nullptr, bool IsStandalone=true) const
A Module instance is used to store all the information related to an LLVM module.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
void setIncomingValueForBlock(const BasicBlock *BB, Value *V)
Set every incoming value(s) for block BB to V.
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
FastMathFlags getFastMathFlags() const
static unsigned getOpcode(RecurKind Kind)
Returns the opcode corresponding to the RecurrenceKind.
unsigned getOpcode() const
Type * getRecurrenceType() const
Returns the type of the recurrence.
static bool isAnyOfRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is of the form select(cmp(),x,y) where one of (x,...
bool isSigned() const
Returns true if all source operands of the recurrence are SExtInsts.
RecurKind getRecurrenceKind() const
Value * getRecurrenceIdentity(RecurKind K, Type *Tp, FastMathFlags FMF) const
Returns identity corresponding to the RecurrenceKind.
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.
This class uses information about analyze scalars to rewrite expressions in canonical form.
Type * getType() const
Return the LLVM type of this SCEV expression.
This class provides computation of slot numbers for LLVM Assembly writing.
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.
This class represents a truncation of integer types.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
bool isPointerTy() const
True if this is an instance of PointerType.
static IntegerType * getInt1Ty(LLVMContext &C)
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isVoidTy() const
Return true if this is 'void'.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
value_op_iterator value_op_end()
Value * getOperand(unsigned i) const
value_op_iterator value_op_begin()
void execute(VPTransformState &State) override
Generate the active lane mask phi of the vector loop.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
RecipeListTy & getRecipeList()
Returns a reference to the list of recipes.
VPRegionBlock * getEnclosingLoopRegion()
void insert(VPRecipeBase *Recipe, iterator InsertPt)
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPValue * getIncomingValue(unsigned Idx) const
Return incoming value number Idx.
VPValue * getMask(unsigned Idx) const
Return mask number Idx.
unsigned getNumIncomingValues() const
Return the number of incoming values, taking into account that the first incoming value has no mask.
void execute(VPTransformState &State) override
Generate the phi/select nodes.
VPRegionBlock * getParent()
const VPBasicBlock * getEntryBasicBlock() const
VPBlockBase * getSingleSuccessor() const
VPValue * getMask() const
Return the mask used by this recipe.
void execute(VPTransformState &State) override
Generate the extraction of the appropriate bit from the block mask and the conditional branch.
void execute(VPTransformState &State) override
Generate the canonical scalar induction phi of the vector loop.
bool isCanonical(InductionDescriptor::InductionKind Kind, VPValue *Start, VPValue *Step) const
Check if the induction described by Kind, /p Start and Step is canonical, i.e.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
This class augments a recipe with a set of VPValues defined by the recipe.
void dump() const
Dump the VPDef to stderr (for debugging).
ArrayRef< VPValue * > definedValues()
Returns an ArrayRef of the values defined by the VPDef.
VPValue * getVPSingleValue()
Returns the only VPValue defined by the VPDef.
VPValue * getVPValue(unsigned I)
Returns the VPValue with index I defined by the VPDef.
unsigned getVPDefID() const
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPValue * getStepValue() const
VPValue * getStartValue() const
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate phi for handling IV based on EVL over iterations correctly.
void execute(VPTransformState &State) override
Generate a canonical vector induction variable of the vector loop, with.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
LLVM_DUMP_METHOD void dump() const
Print the VPInstruction to dbgs() (for debugging).
unsigned getOpcode() const
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first part of operand Op.
bool isVectorToScalar() const
Returns true if this VPInstruction produces a scalar value from a vector, e.g.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the VPInstruction to O.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
bool isSingleScalar() const
Returns true if this VPInstruction's operands are single scalars and the result is also a single scal...
@ ResumePhi
Creates a scalar phi in a leaf VPBB with a single predecessor in VPlan.
@ FirstOrderRecurrenceSplice
@ CanonicalIVIncrementForPart
@ CalculateTripCountMinusVF
void execute(VPTransformState &State) override
Generate the instruction.
VPValue * getAddr() const
Return the address accessed by this recipe.
VPValue * getMask() const
Return the mask used by this recipe.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate the wide load or store, and shuffles.
ArrayRef< VPValue * > getStoredValues() const
Return the VPValues stored by this interleave group.
unsigned getNumStoreOperands() const
Returns the number of stored operands of this interleave group.
static VPLane getLastLaneForVF(const ElementCount &VF)
static VPLane getLaneFromEnd(const ElementCount &VF, unsigned Offset)
static VPLane getFirstLane()
void print(raw_ostream &O, VPSlotTracker &SlotTracker) const
Print the VPLiveOut to O.
void fixPhi(VPlan &Plan, VPTransformState &State)
Fix the wrapped phi node.
void execute(VPTransformState &State) override
Generates phi nodes for live-outs as needed to retain SSA form.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
bool mayReadFromMemory() const
Returns true if the recipe may read from memory.
bool mayHaveSideEffects() const
Returns true if the recipe may have side-effects.
bool mayWriteToMemory() const
Returns true if the recipe may write to memory.
virtual InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const
Compute the cost of this recipe either using a recipe's specialized implementation or using the legac...
VPBasicBlock * getParent()
DebugLoc getDebugLoc() const
Returns the debug location of the recipe.
void moveBefore(VPBasicBlock &BB, iplist< VPRecipeBase >::iterator I)
Unlink this recipe and insert into BB before I.
void insertBefore(VPRecipeBase *InsertPos)
Insert an unlinked recipe into a basic block immediately before the specified recipe.
void insertAfter(VPRecipeBase *InsertPos)
Insert an unlinked Recipe into a basic block immediately after the specified Recipe.
iplist< VPRecipeBase >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
InstructionCost cost(ElementCount VF, VPCostContext &Ctx)
Return the cost of this recipe, taking into account if the cost computation should be skipped and the...
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
void moveAfter(VPRecipeBase *MovePos)
Unlink this recipe from its current VPBasicBlock and insert it into the VPBasicBlock that MovePos liv...
Class to record LLVM IR flag for a recipe along with it.
NonNegFlagsTy NonNegFlags
void setFlags(Instruction *I) const
Set the IR flags for I.
bool hasFastMathFlags() const
Returns true if the recipe has fast-math flags.
DisjointFlagsTy DisjointFlags
bool hasNoUnsignedWrap() const
void printFlags(raw_ostream &O) const
CmpInst::Predicate getPredicate() const
bool hasNoSignedWrap() const
FastMathFlags getFastMathFlags() const
void execute(VPTransformState &State) override
Generate the reduction in the loop.
VPValue * getEVL() const
The VPValue of the explicit vector length.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
bool isOrdered() const
Returns true, if the phi is part of an ordered reduction.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate the phi/select nodes.
bool isConditional() const
Return true if the in-loop reduction is conditional.
VPValue * getVecOp() const
The VPValue of the vector value to be reduced.
const RecurrenceDescriptor & getRecurrenceDescriptor() const
Return the recurrence decriptor for the in-loop reduction.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPValue * getCondOp() const
The VPValue of the condition for the block.
bool isOrdered() const
Return true if the in-loop reduction is ordered.
VPValue * getChainOp() const
The VPValue of the scalar Chain being accumulated.
void execute(VPTransformState &State) override
Generate the reduction in the loop.
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
const VPBlockBase * getEntry() const
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
unsigned getOpcode() const
bool shouldPack() const
Returns true if the recipe is used by a widened recipe via an intervening VPPredInstPHIRecipe.
VPScalarCastRecipe is a recipe to create scalar cast instructions.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPValue * getStepValue() const
void execute(VPTransformState &State) override
Generate the scalarized versions of the phi node as needed by their users.
Instruction * getUnderlyingInstr()
Returns the underlying instruction.
This class can be used to assign names to VPValues.
Type * inferScalarType(const VPValue *V)
Infer the type of V. Returns the scalar type of V.
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
void printOperands(raw_ostream &O, VPSlotTracker &SlotTracker) const
Print the operands to O.
unsigned getNumOperands() const
operand_iterator op_begin()
VPValue * getOperand(unsigned N) const
VPRecipeBase * getDefiningRecipe()
Returns the recipe defining this VPValue or nullptr if it is not defined by a recipe,...
void printAsOperand(raw_ostream &OS, VPSlotTracker &Tracker) const
friend class VPInstruction
Value * getUnderlyingValue() const
Return the underlying Value attached to this VPValue.
Value * getLiveInIRValue()
Returns the underlying IR value, if this VPValue is defined outside the scope of VPlan.
bool isDefinedOutsideVectorRegions() const
Returns true if the VPValue is defined outside any vector regions, i.e.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
Function * getCalledScalarFunction() const
void execute(VPTransformState &State) override
Produce a widened version of the call instruction.
operand_range arg_operands()
void execute(VPTransformState &State) override
Generate a canonical vector induction variable of the vector loop, with start = {<Part*VF,...
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
Type * getResultType() const
Returns the result type of the cast.
void execute(VPTransformState &State) override
Produce widened copies of the cast.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate the gep nodes.
TruncInst * getTruncInst()
Returns the first defined value as TruncInst, if it is one or nullptr otherwise.
void execute(VPTransformState &State) override
Generate the vectorized and scalarized versions of the phi node as needed by their users.
VPValue * getStepValue()
Returns the step value of the induction.
Type * getScalarType() const
Returns the scalar type of the induction.
bool isCanonical() const
Returns true if the induction is canonical, i.e.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
const InductionDescriptor & getInductionDescriptor() const
Returns the induction descriptor for the recipe.
bool Reverse
Whether the consecutive accessed addresses are in reverse order.
bool isConsecutive() const
Return whether the loaded-from / stored-to addresses are consecutive.
VPValue * getMask() const
Return the mask used by this recipe.
VPValue * getAddr() const
Return the address accessed by this recipe.
bool isReverse() const
Return whether the consecutive loaded/stored addresses are in reverse order.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate the phi/select nodes.
bool onlyScalarsGenerated(bool IsScalable)
Returns true if only scalar values will be generated.
void execute(VPTransformState &State) override
Generate vector values for the pointer induction.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenRecipe.
void execute(VPTransformState &State) override
Produce a widened instruction using the opcode and operands of the recipe, processing State....
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
VPCanonicalIVPHIRecipe * getCanonicalIV()
Returns the canonical induction recipe of the vector loop.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void setName(const Twine &Name)
Change the name of the value.
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
StringRef getName() const
Return a constant reference to the value's name.
VectorBuilder & setEVL(Value *NewExplicitVectorLength)
VectorBuilder & setMask(Value *NewMask)
Base class of all SIMD vector types.
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
static VectorType * getDoubleElementsVectorType(VectorType *VTy)
This static method returns a VectorType with twice as many elements as the input type and the same el...
Type * getElementType() const
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
const ParentTy * getParent() const
self_iterator getIterator()
base_list_type::iterator iterator
iterator erase(iterator where)
pointer remove(iterator &IT)
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=std::nullopt)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
bool isUniformAfterVectorization(const VPValue *VPV)
Returns true if VPV is uniform after vectorization.
bool onlyFirstPartUsed(const VPValue *Def)
Returns true if only the first part of Def is used.
bool onlyFirstLaneUsed(const VPValue *Def)
Returns true if only the first lane of Def is used.
This is an optimization pass for GlobalISel generic memory operations.
void ReplaceInstWithInst(BasicBlock *BB, BasicBlock::iterator &BI, Instruction *I)
Replace the instruction specified by BI with the instruction specified by I.
Value * createSimpleTargetReduction(IRBuilderBase &B, Value *Src, RecurKind RdxKind)
Create a target reduction of the given vector.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
bool isVectorIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID, int OpdIdx)
Identifies if the vector form of the intrinsic is overloaded on the type of the operand at index OpdI...
Value * getRuntimeVF(IRBuilderBase &B, Type *Ty, ElementCount VF)
Return the runtime value for VF.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void interleaveComma(const Container &c, StreamT &os, UnaryFunctor each_fn)
Value * concatenateVectors(IRBuilderBase &Builder, ArrayRef< Value * > Vecs)
Concatenate a list of vectors.
Align getLoadStoreAlignment(const Value *I)
A helper function that returns the alignment of load or store instruction.
Instruction * propagateMetadata(Instruction *I, ArrayRef< Value * > VL)
Specifically, let Kinds = [MD_tbaa, MD_alias_scope, MD_noalias, MD_fpmath, MD_nontemporal,...
Value * createMinMaxOp(IRBuilderBase &Builder, RecurKind RK, Value *Left, Value *Right)
Returns a Min/Max operation corresponding to MinMaxRecurrenceKind.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Constant * createBitMaskForGaps(IRBuilderBase &Builder, unsigned VF, const InterleaveGroup< Instruction > &Group)
Create a mask that filters the members of an interleave group where there are gaps.
llvm::SmallVector< int, 16 > createStrideMask(unsigned Start, unsigned Stride, unsigned VF)
Create a stride shuffle mask.
cl::opt< bool > EnableVPlanNativePath("enable-vplan-native-path", cl::Hidden, cl::desc("Enable VPlan-native vectorization path with " "support for outer loop vectorization."))
static bool isDbgInfoIntrinsic(Intrinsic::ID ID)
Check if ID corresponds to a debug info intrinsic.
llvm::SmallVector< int, 16 > createReplicatedMask(unsigned ReplicationFactor, unsigned VF)
Create a mask with replicated elements.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isPointerTy(const Type *T)
Value * createOrderedReduction(IRBuilderBase &B, const RecurrenceDescriptor &Desc, Value *Src, Value *Start)
Create an ordered reduction intrinsic using the given recurrence descriptor Desc.
Type * ToVectorTy(Type *Scalar, ElementCount EC)
A helper function for converting Scalar types to vector types.
llvm::SmallVector< int, 16 > createInterleaveMask(unsigned VF, unsigned NumVecs)
Create an interleave shuffle mask.
RecurKind
These are the kinds of recurrences that we support.
@ Mul
Product of integers.
Value * createStepForVF(IRBuilderBase &B, Type *Ty, ElementCount VF, int64_t Step)
Return a value for Step multiplied by VF.
auto predecessors(const MachineBasicBlock *BB)
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.
bool isVectorIntrinsicWithScalarOpAtArg(Intrinsic::ID ID, unsigned ScalarOpdIdx)
Identifies if the vector form of the intrinsic has a scalar operand.
Value * createTargetReduction(IRBuilderBase &B, const RecurrenceDescriptor &Desc, Value *Src, PHINode *OrigPhi=nullptr)
Create a generic target reduction using a recurrence descriptor Desc The target is queried to determi...
This struct is a compact representation of a valid (non-zero power of two) alignment.
Struct to hold various analysis needed for cost computations.
bool skipCostComputation(Instruction *UI, bool IsVector) const
Return true if the cost for UI shouldn't be computed, e.g.
InstructionCost getLegacyCost(Instruction *UI, ElementCount VF) const
Return the cost for UI with VF using the legacy cost model as fallback until computing the cost of al...
const TargetLibraryInfo & TLI
const TargetTransformInfo & TTI
SmallPtrSet< Instruction *, 8 > SkipCostComputation
void execute(VPTransformState &State) override
Generate the phi nodes.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPIteration represents a single point in the iteration space of the output (vectorized and/or unrolle...
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate a wide load or gather.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
bool isInvariantCond() const
VPValue * getCond() const
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Produce a widened version of the select instruction.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate a wide store or scatter.
VPValue * getStoredValue() const
Return the value stored by this recipe.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.