51#define LV_NAME "loop-vectorize"
52#define DEBUG_TYPE LV_NAME
57 return cast<VPInstruction>(
this)->opcodeMayReadOrWriteFromMemory();
59 return cast<VPInterleaveRecipe>(
this)->getNumStoreOperands() > 0;
60 case VPWidenStoreEVLSC:
67 return !cast<VPWidenCallRecipe>(
this)
68 ->getCalledScalarFunction()
70 case VPWidenIntrinsicSC:
71 return cast<VPWidenIntrinsicRecipe>(
this)->mayWriteToMemory();
72 case VPBranchOnMaskSC:
73 case VPScalarIVStepsSC:
77 case VPReductionEVLSC:
79 case VPVectorPointerSC:
80 case VPWidenCanonicalIVSC:
83 case VPWidenIntOrFpInductionSC:
84 case VPWidenLoadEVLSC:
89 case VPWidenSelectSC: {
93 assert((!
I || !
I->mayWriteToMemory()) &&
94 "underlying instruction may write to memory");
104 case VPInstructionSC:
105 return cast<VPInstruction>(
this)->opcodeMayReadOrWriteFromMemory();
106 case VPWidenLoadEVLSC:
111 ->mayReadFromMemory();
113 return !cast<VPWidenCallRecipe>(
this)
114 ->getCalledScalarFunction()
115 ->onlyWritesMemory();
116 case VPWidenIntrinsicSC:
117 return cast<VPWidenIntrinsicRecipe>(
this)->mayReadFromMemory();
118 case VPBranchOnMaskSC:
119 case VPPredInstPHISC:
120 case VPScalarIVStepsSC:
121 case VPWidenStoreEVLSC:
125 case VPReductionEVLSC:
127 case VPVectorPointerSC:
128 case VPWidenCanonicalIVSC:
131 case VPWidenIntOrFpInductionSC:
135 case VPWidenSelectSC: {
139 assert((!
I || !
I->mayReadFromMemory()) &&
140 "underlying instruction may read from memory");
151 case VPPredInstPHISC:
153 case VPReverseVectorPointerSC:
155 case VPInstructionSC:
157 case VPWidenCallSC: {
158 Function *Fn = cast<VPWidenCallRecipe>(
this)->getCalledScalarFunction();
161 case VPWidenIntrinsicSC:
162 return cast<VPWidenIntrinsicRecipe>(
this)->mayHaveSideEffects();
164 case VPReductionEVLSC:
166 case VPScalarIVStepsSC:
167 case VPVectorPointerSC:
168 case VPWidenCanonicalIVSC:
171 case VPWidenIntOrFpInductionSC:
173 case VPWidenPointerInductionSC:
176 case VPWidenSelectSC: {
180 assert((!
I || !
I->mayHaveSideEffects()) &&
181 "underlying instruction has side-effects");
186 case VPWidenLoadEVLSC:
188 case VPWidenStoreEVLSC:
193 "mayHaveSideffects result for ingredient differs from this "
196 case VPReplicateSC: {
197 auto *R = cast<VPReplicateRecipe>(
this);
198 return R->getUnderlyingInstr()->mayHaveSideEffects();
206 assert(!Parent &&
"Recipe already in some VPBasicBlock");
208 "Insertion position not in any VPBasicBlock");
214 assert(!Parent &&
"Recipe already in some VPBasicBlock");
220 assert(!Parent &&
"Recipe already in some VPBasicBlock");
222 "Insertion position not in any VPBasicBlock");
254 if (
auto *S = dyn_cast<VPSingleDefRecipe>(
this))
255 UI = dyn_cast_or_null<Instruction>(S->getUnderlyingValue());
256 else if (
auto *IG = dyn_cast<VPInterleaveRecipe>(
this))
257 UI = IG->getInsertPos();
258 else if (
auto *WidenMem = dyn_cast<VPWidenMemoryRecipe>(
this))
259 UI = &WidenMem->getIngredient();
272 dbgs() <<
"Cost of " << RecipeCost <<
" for VF " << VF <<
": ";
286 std::optional<unsigned> Opcode = std::nullopt;
295 if (
auto *WidenR = dyn_cast<VPWidenRecipe>(BinOpR))
296 Opcode = std::make_optional(WidenR->getOpcode());
311 auto *WidenCastR = dyn_cast<VPWidenCastRecipe>(R);
314 if (WidenCastR->getOpcode() == Instruction::CastOps::ZExt)
316 if (WidenCastR->getOpcode() == Instruction::CastOps::SExt)
322 PhiType, VF, GetExtendKind(ExtAR),
323 GetExtendKind(ExtBR), Opcode);
331 "Unhandled partial reduction opcode");
335 assert(PhiVal && BinOpVal &&
"Phi and Mul must be set");
339 CallInst *V = Builder.CreateIntrinsic(
340 RetTy, Intrinsic::experimental_vector_partial_reduce_add,
341 {PhiVal, BinOpVal},
nullptr,
"partial.reduce");
346#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
349 O << Indent <<
"PARTIAL-REDUCE ";
357 assert(OpType == OperationType::FPMathOp &&
358 "recipe doesn't have fast math flags");
370#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
374template <
unsigned PartOpIdx>
377 if (U.getNumOperands() == PartOpIdx + 1)
378 return U.getOperand(PartOpIdx);
382template <
unsigned PartOpIdx>
384 if (
auto *UnrollPartOp = getUnrollPartOperand(U))
385 return cast<ConstantInt>(UnrollPartOp->getLiveInIRValue())->getZExtValue();
395 assert(Opcode == Instruction::ICmp &&
396 "only ICmp predicates supported at the moment");
400 std::initializer_list<VPValue *>
Operands,
405 assert(isFPMathOp() &&
"this op can't take fast-math flags");
408bool VPInstruction::doesGeneratePerAllLanes()
const {
412bool VPInstruction::canGenerateScalarForFirstLane()
const {
418 case Instruction::ICmp:
419 case Instruction::Select:
438 "only PtrAdd opcodes are supported for now");
452 if (
auto *
I = dyn_cast<Instruction>(Res))
462 case Instruction::ICmp: {
468 case Instruction::Select: {
491 {VIVElem0, ScalarTC},
nullptr, Name);
507 if (!V1->getType()->isVectorTy())
527 "Requested vector length should be an integer.");
534 {AVL, VFArg, State.Builder.getTrue()});
540 assert(Part != 0 &&
"Must have a positive part");
590 auto *PhiR = cast<VPReductionPHIRecipe>(
getOperand(0));
591 auto *OrigPhi = cast<PHINode>(PhiR->getUnderlyingValue());
597 Type *PhiTy = OrigPhi->getType();
602 for (
unsigned Part = 0; Part < UF; ++Part)
603 RdxParts[Part] = State.
get(
getOperand(1 + Part), PhiR->isInLoop());
611 for (
unsigned Part = 0; Part < UF; ++Part)
612 RdxParts[Part] = Builder.
CreateTrunc(RdxParts[Part], RdxVecTy);
615 Value *ReducedPartRdx = RdxParts[0];
618 Op = Instruction::Or;
620 if (PhiR->isOrdered()) {
621 ReducedPartRdx = RdxParts[UF - 1];
626 for (
unsigned Part = 1; Part < UF; ++Part) {
627 Value *RdxPart = RdxParts[Part];
628 if (
Op != Instruction::ICmp &&
Op != Instruction::FCmp)
635 ReducedPartRdx =
createMinMaxOp(Builder, RK, ReducedPartRdx, RdxPart);
655 return ReducedPartRdx;
659 unsigned Offset = CI->getZExtValue();
660 assert(
Offset > 0 &&
"Offset from end must be positive");
664 "invalid offset to extract from");
668 assert(
Offset <= 1 &&
"invalid offset to extract from");
671 if (isa<ExtractElementInst>(Res))
682 "can only generate first lane for PtrAdd");
690 for (
const auto &[IncVPV, PredVPBB] :
692 Value *IncV = State.
get(IncVPV,
true);
694 NewPhi->addIncoming(IncV, PredBB);
706 Builder.
getInt64Ty(), Mask,
true,
"first.active.lane");
723 assert(!doesGeneratePerAllLanes() &&
724 "Should only generate a vector value or single scalar, not scalars "
737 Instruction::Or, cast<VectorType>(VecTy), std::nullopt, Ctx.
CostKind);
743 "unexpected VPInstruction witht underlying value");
760bool VPInstruction::isFPMathOp()
const {
763 return Opcode == Instruction::FAdd || Opcode == Instruction::FMul ||
764 Opcode == Instruction::FNeg || Opcode == Instruction::FSub ||
765 Opcode == Instruction::FDiv || Opcode == Instruction::FRem ||
766 Opcode == Instruction::FCmp || Opcode == Instruction::Select;
771 assert(!State.
Lane &&
"VPInstruction executing an Lane");
775 "Recipe not a FPMathOp but has fast-math flags?");
779 bool GeneratesPerFirstLaneOnly = canGenerateScalarForFirstLane() &&
782 bool GeneratesPerAllLanes = doesGeneratePerAllLanes();
783 if (GeneratesPerAllLanes) {
785 Lane != NumLanes; ++Lane) {
786 Value *GeneratedValue = generatePerLane(State,
VPLane(Lane));
787 assert(GeneratedValue &&
"generatePerLane must produce a value");
788 State.
set(
this, GeneratedValue,
VPLane(Lane));
793 Value *GeneratedValue = generate(State);
796 assert(GeneratedValue &&
"generate must produce a value");
800 "scalar value but not only first lane defined");
801 State.
set(
this, GeneratedValue,
802 GeneratesPerFirstLaneOnly);
809 case Instruction::ICmp:
810 case Instruction::Select:
834 case Instruction::ICmp:
835 case Instruction::Select:
836 case Instruction::Or:
860 case Instruction::ICmp:
861 case Instruction::Select:
871#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
879 O << Indent <<
"EMIT ";
891 O <<
"combined load";
894 O <<
"combined store";
897 O <<
"active lane mask";
903 O <<
"EXPLICIT-VECTOR-LENGTH";
906 O <<
"first-order splice";
909 O <<
"branch-on-cond";
912 O <<
"TC > VF ? TC - VF : 0";
918 O <<
"branch-on-count";
921 O <<
"extract-from-end";
924 O <<
"compute-reduction-result";
936 O <<
"extract-first-active";
954 "Only PHINodes can have extra operands");
967 auto *Phi = cast<PHINode>(&I);
970 if (Phi->getBasicBlockIndex(PredBB) == -1)
971 Phi->addIncoming(V, PredBB);
973 Phi->setIncomingValueForBlock(PredBB, V);
990 "can only add exiting operands to phi nodes");
1004#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1007 O << Indent <<
"IR " << I;
1010 O <<
" (extra operand" << (
getNumOperands() > 1 ?
"s" :
"") <<
": ";
1038 Args.push_back(Arg);
1041 assert(Variant !=
nullptr &&
"Can't create vector function.");
1046 CI->getOperandBundlesAsDefs(OpBundles);
1051 if (!V->getType()->isVoidTy())
1063#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1066 O << Indent <<
"WIDEN-CALL ";
1078 O <<
" @" << CalledFn->
getName() <<
"(";
1084 O <<
" (using library function";
1086 O <<
": " << Variant->
getName();
1112 Args.push_back(Arg);
1120 "Can't retrieve vector intrinsic or vector-predication intrinsics.");
1125 CI->getOperandBundlesAsDefs(OpBundles);
1131 if (!V->getType()->isVoidTy())
1145 auto *V =
Op->getUnderlyingValue();
1192#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1195 O << Indent <<
"WIDEN-INTRINSIC ";
1225 Value *Mask =
nullptr;
1227 Mask = State.
get(VPMask);
1234 if (Opcode == Instruction::Sub)
1237 assert(Opcode == Instruction::Add &&
"only add or sub supported for now");
1273 {PtrTy, IncTy, MaskTy});
1280#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1283 O << Indent <<
"WIDEN-HISTOGRAM buckets: ";
1286 if (Opcode == Instruction::Sub)
1289 assert(Opcode == Instruction::Add);
1302 O << Indent <<
"WIDEN-SELECT ";
1329 State.
set(
this, Sel);
1330 if (isa<FPMathOperator>(Sel))
1354 [](
VPValue *
Op) {
return Op->getUnderlyingValue(); }))
1355 Operands.append(SI->op_begin(), SI->op_end());
1356 bool IsLogicalOr =
match(
this,
m_LogicalOr(m_VPValue(Op0), m_VPValue(Op1)));
1358 IsLogicalOr ? Instruction::Or : Instruction::And, VectorTy,
1367 if (
auto *Cmp = dyn_cast<CmpInst>(SI->getCondition()))
1368 Pred = Cmp->getPredicate();
1370 Instruction::Select, VectorTy, CondTy, Pred, Ctx.
CostKind,
1371 {TTI::OK_AnyValue, TTI::OP_None}, {TTI::OK_AnyValue, TTI::OP_None}, SI);
1374VPRecipeWithIRFlags::FastMathFlagsTy::FastMathFlagsTy(
1385#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1388 case OperationType::Cmp:
1391 case OperationType::DisjointOp:
1395 case OperationType::PossiblyExactOp:
1399 case OperationType::OverflowingBinOp:
1405 case OperationType::FPMathOp:
1408 case OperationType::GEPOp:
1416 case OperationType::NonNegOp:
1420 case OperationType::Other:
1430 auto &Builder = State.
Builder;
1432 case Instruction::Call:
1433 case Instruction::Br:
1434 case Instruction::PHI:
1435 case Instruction::GetElementPtr:
1436 case Instruction::Select:
1438 case Instruction::UDiv:
1439 case Instruction::SDiv:
1440 case Instruction::SRem:
1441 case Instruction::URem:
1442 case Instruction::Add:
1443 case Instruction::FAdd:
1444 case Instruction::Sub:
1445 case Instruction::FSub:
1446 case Instruction::FNeg:
1447 case Instruction::Mul:
1448 case Instruction::FMul:
1449 case Instruction::FDiv:
1450 case Instruction::FRem:
1451 case Instruction::Shl:
1452 case Instruction::LShr:
1453 case Instruction::AShr:
1454 case Instruction::And:
1455 case Instruction::Or:
1456 case Instruction::Xor: {
1464 if (
auto *VecOp = dyn_cast<Instruction>(V))
1472 case Instruction::Freeze: {
1476 State.
set(
this, Freeze);
1479 case Instruction::ICmp:
1480 case Instruction::FCmp: {
1482 bool FCmp = Opcode == Instruction::FCmp;
1510 "inferred type and type from generated instructions do not match");
1517 case Instruction::FNeg: {
1521 {TargetTransformInfo::OK_AnyValue, TargetTransformInfo::OP_None},
1522 {TargetTransformInfo::OK_AnyValue, TargetTransformInfo::OP_None});
1525 case Instruction::UDiv:
1526 case Instruction::SDiv:
1527 case Instruction::SRem:
1528 case Instruction::URem:
1531 case Instruction::Add:
1532 case Instruction::FAdd:
1533 case Instruction::Sub:
1534 case Instruction::FSub:
1535 case Instruction::Mul:
1536 case Instruction::FMul:
1537 case Instruction::FDiv:
1538 case Instruction::FRem:
1539 case Instruction::Shl:
1540 case Instruction::LShr:
1541 case Instruction::AShr:
1542 case Instruction::And:
1543 case Instruction::Or:
1544 case Instruction::Xor: {
1550 if (
RHS->isLiveIn())
1564 {TargetTransformInfo::OK_AnyValue, TargetTransformInfo::OP_None},
1567 case Instruction::Freeze: {
1573 case Instruction::ICmp:
1574 case Instruction::FCmp: {
1579 {TTI::OK_AnyValue, TTI::OP_None},
1580 {TTI::OK_AnyValue, TTI::OP_None}, CtxI);
1596 "VPWidenEVLRecipe should not be used for scalars");
1599 Value *EVLArg = State.
get(EVL,
true);
1615 if (isa<FPMathOperator>(VPInst))
1616 setFlags(cast<Instruction>(VPInst));
1618 State.
set(
this, VPInst);
1623#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1626 O << Indent <<
"WIDEN ";
1635 O << Indent <<
"WIDEN ";
1645 auto &Builder = State.
Builder;
1652 State.
set(
this, Cast);
1654 if (
auto *CastOp = dyn_cast<Instruction>(Cast))
1669 if (isa<VPInterleaveRecipe>(R))
1671 if (
const auto *ReplicateRecipe = dyn_cast<VPReplicateRecipe>(R))
1674 const auto *WidenMemoryRecipe = dyn_cast<VPWidenMemoryRecipe>(R);
1675 if (WidenMemoryRecipe ==
nullptr)
1677 if (!WidenMemoryRecipe->isConsecutive())
1679 if (WidenMemoryRecipe->isReverse())
1681 if (WidenMemoryRecipe->isMasked())
1689 if ((Opcode == Instruction::Trunc || Opcode == Instruction::FPTrunc) &&
1691 if (
auto *StoreRecipe = dyn_cast<VPRecipeBase>(*
user_begin()))
1692 CCH = ComputeCCH(StoreRecipe);
1695 else if (Opcode == Instruction::ZExt || Opcode == Instruction::SExt ||
1696 Opcode == Instruction::FPExt) {
1708 Opcode, DestTy, SrcTy, CCH, Ctx.
CostKind,
1712#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1715 O << Indent <<
"WIDEN-CAST ";
1739 auto *ValVTy = cast<VectorType>(Val->
getType());
1744 "Induction Step must be an integer or FP");
1752 Type *InitVecValSTy =
1763 Step = Builder.
CreateMul(InitVec, Step);
1764 return Builder.
CreateAdd(Val, Step,
"induction");
1768 assert((BinOp == Instruction::FAdd || BinOp == Instruction::FSub) &&
1769 "Binary Opcode should be specified for FP induction");
1774 return Builder.
CreateBinOp(BinOp, Val, MulOp,
"induction");
1781 : ConstantFP::get(Ty,
C);
1785 assert(!State.
Lane &&
"Int or FP induction being replicated.");
1792 "Types must match");
1801 if (
ID.getInductionBinOp() && isa<FPMathOperator>(
ID.getInductionBinOp()))
1807 assert((isa<PHINode>(EntryVal) || isa<TruncInst>(EntryVal)) &&
1808 "Expected either an induction phi-node or a truncate of it!");
1811 auto CurrIP = Builder.
saveIP();
1814 if (isa<TruncInst>(EntryVal)) {
1815 assert(Start->getType()->isIntegerTy() &&
1816 "Truncation requires an integer type");
1817 auto *TruncType = cast<IntegerType>(EntryVal->
getType());
1819 Start = Builder.
CreateCast(Instruction::Trunc, Start, TruncType);
1831 AddOp = Instruction::Add;
1832 MulOp = Instruction::Mul;
1834 AddOp =
ID.getInductionOpcode();
1835 MulOp = Instruction::FMul;
1842 SplatVF = State.
get(SplatVFOperand);
1865 State.
set(
this, VecInd);
1868 Builder.
CreateBinOp(AddOp, VecInd, SplatVF,
"vec.ind.next"));
1869 if (isa<TruncInst>(EntryVal))
1882#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1887 O <<
" = WIDEN-INDUCTION ";
1891 O <<
" (truncated to " << *TI->getType() <<
")";
1903 auto *CanIV = cast<VPCanonicalIVPHIRecipe>(&*
getParent()->begin());
1904 return StartC && StartC->isZero() && StepC && StepC->isOne() &&
1908#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1913 O <<
" = DERIVED-IV ";
1937 assert(BaseIVTy == Step->
getType() &&
"Types of BaseIV and Step must match!");
1944 AddOp = Instruction::Add;
1945 MulOp = Instruction::Mul;
1947 AddOp = InductionOpcode;
1948 MulOp = Instruction::FMul;
1957 Type *VecIVTy =
nullptr;
1958 Value *UnitStepVec =
nullptr, *SplatStep =
nullptr, *SplatIV =
nullptr;
1967 unsigned StartLane = 0;
1970 StartLane = State.
Lane->getKnownLane();
1971 EndLane = StartLane + 1;
1978 auto *InitVec = Builder.
CreateAdd(SplatStartIdx, UnitStepVec);
1992 for (
unsigned Lane = StartLane; Lane < EndLane; ++Lane) {
1998 "Expected StartIdx to be folded to a constant when VF is not "
2006#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2011 O <<
" = SCALAR-STEPS ";
2025 if (areAllOperandsInvariant()) {
2061 if (isIndexLoopInvariant(
I - 1))
2072 "NewGEP is not a pointer vector");
2073 State.
set(
this, NewGEP);
2078#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2081 O << Indent <<
"WIDEN-GEP ";
2082 O << (isPointerLoopInvariant() ?
"Inv" :
"Var");
2084 O <<
"[" << (isIndexLoopInvariant(
I) ?
"Inv" :
"Var") <<
"]";
2088 O <<
" = getelementptr";
2099 return IsScalable && (IsReverse || CurrentPart > 0)
2105 auto &Builder = State.
Builder;
2109 CurrentPart, Builder);
2113 if (IndexTy != RunTimeVF->
getType())
2117 ConstantInt::get(IndexTy, -(int64_t)CurrentPart), RunTimeVF);
2119 Value *LastLane = Builder.
CreateSub(ConstantInt::get(IndexTy, 1), RunTimeVF);
2123 ResultPtr = Builder.
CreateGEP(IndexedTy, ResultPtr, LastLane,
"",
2126 State.
set(
this, ResultPtr,
true);
2129#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2134 O <<
" = reverse-vector-pointer";
2141 auto &Builder = State.
Builder;
2145 CurrentPart, Builder);
2152 State.
set(
this, ResultPtr,
true);
2155#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2160 O <<
" = vector-pointer ";
2186 Value *Result =
nullptr;
2187 for (
unsigned In = 0; In < NumIncoming; ++In) {
2200 State.
set(
this, Result, OnlyFirstLaneUsed);
2217#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2220 O << Indent <<
"BLEND ";
2242 assert(!State.
Lane &&
"Reduction being replicated.");
2276 PrevInChain = NewRed;
2277 NextInChain = NewRed;
2283 NewRed, PrevInChain);
2288 State.
set(
this, NextInChain,
true);
2292 assert(!State.
Lane &&
"Reduction being replicated.");
2294 auto &Builder = State.
Builder;
2310 Mask = State.
get(CondOp);
2326 State.
set(
this, NewRed,
true);
2333 auto *VectorTy = cast<VectorType>(
toVectorTy(ElementTy, VF));
2340 "Any-of reduction not implemented in VPlan-based cost model currently.");
2342 (!cast<VPReductionPHIRecipe>(
getOperand(0))->isInLoop() ||
2344 "In-loop reduction not implemented in VPlan-based cost model currently.");
2347 "Inferred type and recurrence type mismatch.");
2362#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2365 O << Indent <<
"REDUCE ";
2380 O <<
" (with final reduction value stored in invariant address sank "
2387 O << Indent <<
"REDUCE ";
2404 O <<
" (with final reduction value stored in invariant address sank "
2413 if (
auto *PredR = dyn_cast<VPPredInstPHIRecipe>(U))
2414 return any_of(PredR->users(), [PredR](
const VPUser *U) {
2415 return !U->usesScalars(PredR);
2430#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2433 O << Indent << (IsUniform ?
"CLONE " :
"REPLICATE ");
2442 O <<
"@" << CB->getCalledFunction()->getName() <<
"(";
2462 "Codegen only implemented for first lane.");
2464 case Instruction::SExt:
2465 case Instruction::ZExt:
2466 case Instruction::Trunc: {
2477 State.
set(
this, generate(State),
VPLane(0));
2480#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2483 O << Indent <<
"SCALAR-CAST ";
2487 O <<
" to " << *ResultTy;
2492 assert(State.
Lane &&
"Branch on Mask works only on single instance.");
2495 Value *ConditionBit =
nullptr;
2498 ConditionBit = State.
get(BlockInMask, *State.
Lane);
2505 assert(isa<UnreachableInst>(CurrentTerminator) &&
2506 "Expected to replace unreachable terminator with conditional branch.");
2522 assert(State.
Lane &&
"Predicated instruction PHI works per instance.");
2527 assert(PredicatingBB &&
"Predicated block has no single predecessor.");
2529 "operand must be VPReplicateRecipe");
2544 State.
reset(
this, VPhi);
2546 State.
set(
this, VPhi);
2558 Phi->addIncoming(ScalarPredInst, PredicatedBB);
2562 State.
set(
this, Phi, *State.
Lane);
2569#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2572 O << Indent <<
"PHI-PREDICATED-INSTRUCTION ";
2582 const Align Alignment =
2593 "Inconsecutive memory access should not have the order.");
2615 cast<VectorType>(Ty), {}, Ctx.
CostKind, 0);
2626 auto &Builder = State.
Builder;
2628 Value *Mask =
nullptr;
2629 if (
auto *VPMask =
getMask()) {
2632 Mask = State.
get(VPMask);
2641 "wide.masked.gather");
2653 State.
set(
this, NewLI);
2656#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2659 O << Indent <<
"WIDEN ";
2671 Value *AllTrueMask =
2673 return Builder.
CreateIntrinsic(ValTy, Intrinsic::experimental_vp_reverse,
2674 {Operand, AllTrueMask, EVL},
nullptr,
Name);
2685 auto &Builder = State.
Builder;
2690 Value *Mask =
nullptr;
2692 Mask = State.
get(VPMask);
2702 nullptr,
"wide.masked.gather");
2707 Instruction::Load, DataTy,
Addr,
"vp.op.load"));
2715 State.
set(
this, Res);
2729 const Align Alignment =
2739 cast<VectorType>(Ty), {}, Ctx.
CostKind,
2743#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2746 O << Indent <<
"WIDEN ";
2760 auto &Builder = State.
Builder;
2763 Value *Mask =
nullptr;
2764 if (
auto *VPMask =
getMask()) {
2767 Mask = State.
get(VPMask);
2772 Value *StoredVal = State.
get(StoredVPValue);
2791#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2794 O << Indent <<
"WIDEN store ";
2806 auto &Builder = State.
Builder;
2810 Value *StoredVal = State.
get(StoredValue);
2814 Value *Mask =
nullptr;
2816 Mask = State.
get(VPMask);
2823 if (CreateScatter) {
2825 Intrinsic::vp_scatter,
2826 {StoredVal, Addr, Mask, EVL});
2832 {StoredVal, Addr}));
2850 const Align Alignment =
2860 cast<VectorType>(Ty), {}, Ctx.
CostKind,
2864#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2867 O << Indent <<
"WIDEN vp.store ";
2875 auto VF = DstVTy->getElementCount();
2876 auto *SrcVecTy = cast<VectorType>(V->getType());
2877 assert(VF == SrcVecTy->getElementCount() &&
"Vector dimensions do not match");
2878 Type *SrcElemTy = SrcVecTy->getElementType();
2879 Type *DstElemTy = DstVTy->getElementType();
2880 assert((
DL.getTypeSizeInBits(SrcElemTy) ==
DL.getTypeSizeInBits(DstElemTy)) &&
2881 "Vector elements must have same size");
2892 "Only one type should be a pointer type");
2894 "Only one type should be a floating point type");
2906 unsigned Factor = Vals.
size();
2907 assert(Factor > 1 &&
"Tried to interleave invalid number of vectors");
2911 for (
Value *Val : Vals)
2912 assert(Val->getType() == VecTy &&
"Tried to interleave mismatched types");
2917 if (VecTy->isScalableTy()) {
2919 "scalable vectors, must be power of 2");
2923 auto *InterleaveTy = cast<VectorType>(InterleavingValues[0]->
getType());
2924 for (
unsigned Midpoint = Factor / 2; Midpoint > 0; Midpoint /= 2) {
2926 for (
unsigned I = 0;
I < Midpoint; ++
I)
2928 InterleaveTy, Intrinsic::vector_interleave2,
2929 {InterleavingValues[I], InterleavingValues[Midpoint + I]},
2932 return InterleavingValues[0];
2939 const unsigned NumElts = VecTy->getElementCount().getFixedValue();
2973 assert(!State.
Lane &&
"Interleave group being replicated.");
2979 unsigned InterleaveFactor = Group->
getFactor();
2985 "Reversed masked interleave-group not supported.");
2989 if (
auto *
I = dyn_cast<Instruction>(ResAddr))
3005 bool InBounds =
false;
3007 InBounds = Gep->isInBounds();
3014 auto CreateGroupMask = [&BlockInMask, &State,
3015 &InterleaveFactor](
Value *MaskForGaps) ->
Value * {
3017 assert(!MaskForGaps &&
"Interleaved groups with gaps are not supported.");
3019 "Unsupported deinterleave factor for scalable vectors");
3020 auto *ResBlockInMask = State.
get(BlockInMask);
3028 Value *ResBlockInMask = State.
get(BlockInMask);
3032 "interleaved.mask");
3034 ShuffledMask, MaskForGaps)
3040 if (isa<LoadInst>(Instr)) {
3041 Value *MaskForGaps =
nullptr;
3042 if (NeedsMaskForGaps) {
3045 assert(MaskForGaps &&
"Mask for Gaps is required but it is null");
3049 if (BlockInMask || MaskForGaps) {
3050 Value *GroupMask = CreateGroupMask(MaskForGaps);
3053 PoisonVec,
"wide.masked.vec");
3061 if (VecTy->isScalableTy()) {
3063 "Unsupported deinterleave factor for scalable vectors");
3068 DeinterleavedValues[0] = NewLoad;
3075 for (
unsigned NumVectors = 1; NumVectors < InterleaveFactor;
3079 for (
unsigned I = 0;
I < NumVectors; ++
I) {
3080 auto *DiTy = DeinterleavedValues[
I]->getType();
3082 Intrinsic::vector_deinterleave2, DiTy, DeinterleavedValues[
I],
3083 nullptr,
"strided.vec");
3086 for (
unsigned I = 0;
I < 2; ++
I)
3087 for (
unsigned J = 0; J < NumVectors; ++J)
3088 DeinterleavedValues[NumVectors *
I + J] =
3093 for (
Value *Val : DeinterleavedValues)
3094 assert(Val &&
"NULL Deinterleaved Value");
3096 for (
unsigned I = 0, J = 0;
I < InterleaveFactor; ++
I) {
3098 Value *StridedVec = DeinterleavedValues[
I];
3101 cast<Instruction>(StridedVec)->eraseFromParent();
3105 if (Member->getType() != ScalarTy) {
3114 State.
set(VPDefs[J], StridedVec);
3124 for (
unsigned I = 0;
I < InterleaveFactor; ++
I) {
3137 if (Member->getType() != ScalarTy) {
3147 State.
set(VPDefs[J], StridedVec);
3157 Value *MaskForGaps =
3160 "masking gaps for scalable vectors is not yet supported.");
3164 unsigned StoredIdx = 0;
3165 for (
unsigned i = 0; i < InterleaveFactor; i++) {
3167 "Fail to get a member from an interleaved store group");
3177 Value *StoredVec = State.
get(StoredValues[StoredIdx]);
3185 if (StoredVec->
getType() != SubVT)
3194 if (BlockInMask || MaskForGaps) {
3195 Value *GroupMask = CreateGroupMask(MaskForGaps);
3197 IVec, ResAddr, Group->
getAlign(), GroupMask);
3205#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3208 O << Indent <<
"INTERLEAVE-GROUP with factor " << IG->getFactor() <<
" at ";
3209 IG->getInsertPos()->printAsOperand(O,
false);
3219 for (
unsigned i = 0; i < IG->getFactor(); ++i) {
3220 if (!IG->getMember(i))
3223 O <<
"\n" << Indent <<
" store ";
3225 O <<
" to index " << i;
3227 O <<
"\n" << Indent <<
" ";
3229 O <<
" = load from index " << i;
3240 unsigned InsertPosIdx = 0;
3241 for (
unsigned Idx = 0; IG->getFactor(); ++
Idx)
3242 if (
auto *Member = IG->getMember(
Idx)) {
3243 if (Member == InsertPos)
3250 auto *VectorTy = cast<VectorType>(
toVectorTy(ValTy, VF));
3253 unsigned InterleaveFactor = IG->getFactor();
3258 for (
unsigned IF = 0; IF < InterleaveFactor; IF++)
3259 if (IG->getMember(IF))
3264 InsertPos->
getOpcode(), WideVecTy, IG->getFactor(), Indices,
3267 if (!IG->isReverse())
3270 return Cost + IG->getNumMembers() *
3272 VectorTy, std::nullopt, Ctx.
CostKind,
3276#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3279 O << Indent <<
"EMIT ";
3281 O <<
" = CANONICAL-INDUCTION ";
3287 return IsScalarAfterVectorization &&
3294 "Not a pointer induction according to InductionDescriptor!");
3296 "Unexpected type.");
3298 "Recipe should have been replaced");
3304 Type *ScStValueType = ScalarStartValue->
getType();
3307 PHINode *NewPointerPhi =
nullptr;
3308 if (CurrentPart == 0) {
3309 auto *IVR = cast<VPHeaderPHIRecipe>(&
getParent()
3311 ->getVectorLoopRegion()
3312 ->getEntryBasicBlock()
3314 PHINode *CanonicalIV = cast<PHINode>(State.
get(IVR,
true));
3317 NewPointerPhi->
addIncoming(ScalarStartValue, VectorPH);
3324 NewPointerPhi = cast<PHINode>(
GEP->getPointerOperand());
3337 if (CurrentPart == 0) {
3341 Value *NumUnrolledElems =
3349 NewPointerPhi->
addIncoming(InductionGEP, VectorPH);
3356 RuntimeVF, ConstantInt::get(PhiType, CurrentPart));
3357 Value *StartOffset =
3364 "scalar step must be the same across all parts");
3368 State.
VF, ScalarStepValue)),
3373#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3377 "unexpected number of operands");
3378 O << Indent <<
"EMIT ";
3380 O <<
" = WIDEN-POINTER-INDUCTION ";
3394 assert(!State.
Lane &&
"cannot be used in per-lane");
3402 "Results must match");
3415#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3418 O << Indent <<
"EMIT ";
3420 O <<
" = EXPAND SCEV " << *Expr;
3438 Value *CanonicalVectorIV = Builder.
CreateAdd(VStart, VStep,
"vec.iv");
3439 State.
set(
this, CanonicalVectorIV);
3442#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3445 O << Indent <<
"EMIT ";
3447 O <<
" = WIDEN-CANONICAL-INDUCTION ";
3453 auto &Builder = State.
Builder;
3458 ? VectorInit->getType()
3464 auto *One = ConstantInt::get(IdxTy, 1);
3468 auto *LastIdx = Builder.
CreateSub(RuntimeVF, One);
3476 Phi->addIncoming(VectorInit, VectorPH);
3477 State.
set(
this, Phi);
3495 cast<VectorType>(VectorTy), Mask, Ctx.
CostKind,
3499#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3502 O << Indent <<
"FIRST-ORDER-RECURRENCE-PHI ";
3510 auto &Builder = State.
Builder;
3525 bool ScalarPHI = State.
VF.
isScalar() || IsInLoop;
3531 "recipe must be in the vector loop header");
3534 State.
set(
this, Phi, IsInLoop);
3538 Value *Iden =
nullptr;
3550 StartV = Iden = State.
get(StartVPV);
3573 if (CurrentPart == 0) {
3588 Phi = cast<PHINode>(State.
get(
this, IsInLoop));
3589 Value *StartVal = (CurrentPart == 0) ? StartV : Iden;
3590 Phi->addIncoming(StartVal, VectorPH);
3593#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3596 O << Indent <<
"WIDEN-REDUCTION-PHI ";
3601 if (VFScaleFactor != 1)
3602 O <<
" (VF scaled by 1/" << VFScaleFactor <<
")";
3608 "Non-native vplans are not expected to have VPWidenPHIRecipes.");
3614 State.
set(
this, VecPhi);
3617#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3620 O << Indent <<
"WIDEN-PHI ";
3645 Phi->addIncoming(StartMask, VectorPH);
3647 State.
set(
this, Phi);
3650#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3653 O << Indent <<
"ACTIVE-LANE-MASK-PHI ";
3661#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3664 O << Indent <<
"EXPLICIT-VECTOR-LENGTH-BASED-IV-PHI ";
3676 Phi->addIncoming(Start, VectorPH);
3678 State.
set(
this, Phi,
true);
3681#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3684 O << Indent <<
"SCALAR-PHI ";
AMDGPU Lower Kernel Arguments
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")
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
This file provides a LoopVectorizationPlanner class.
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())
This file defines the SmallVector class.
static SymbolRef::Type getType(const Symbol *Sym)
This file contains the declarations of different VPlan-related auxiliary helpers.
static Instruction * createReverseEVL(IRBuilderBase &Builder, Value *Operand, Value *EVL, const Twine &Name)
Use all-true mask for reverse rather than actual mask, as it avoids a dependence w/o affecting the re...
static Value * interleaveVectors(IRBuilderBase &Builder, ArrayRef< Value * > Vals, const Twine &Name)
Return a vector containing interleaved elements from multiple smaller input vectors.
static Value * createBitOrPointerCast(IRBuilderBase &Builder, Value *V, VectorType *DstVTy, const DataLayout &DL)
cl::opt< unsigned > ForceTargetInstructionCost
static Value * getStepVector(Value *Val, Value *Step, Instruction::BinaryOps BinOp, ElementCount VF, IRBuilderBase &Builder)
This function adds (0 * Step, 1 * Step, 2 * Step, ...) to each vector element of Val.
static Type * getGEPIndexTy(bool IsScalable, bool IsReverse, unsigned CurrentPart, IRBuilderBase &Builder)
static Constant * getSignedIntOrFpConstant(Type *Ty, int64_t C)
A helper function that returns an integer or floating-point constant with value C.
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.
static Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
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
Returns an iterator to the first instruction in this block that is not a PHINode instruction.
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)
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
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.
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
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.
ArrayRef< Type * > params() const
FunctionType * getFunctionType() const
Returns the FunctionType for me.
bool willReturn() const
Determine if the function will return.
bool doesNotThrow() const
Determine if the function cannot unwind.
Type * getReturnType() const
Returns the type of the ret val.
bool hasNoUnsignedSignedWrap() const
bool hasNoUnsignedWrap() const
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Common base class shared among various IRBuilders.
ConstantInt * getInt1(bool V)
Get a constant value representing either true or false.
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
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 * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
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 * 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 * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr, FMFSource FMFSource={})
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.
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Value * CreateVectorReverse(Value *V, const Twine &Name="")
Return a vector value that contains the vector V reversed.
Value * CreateFCmpFMF(CmpInst::Predicate P, Value *LHS, Value *RHS, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
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)
CallInst * CreateOrReduce(Value *Src)
Create a vector int OR reduction intrinsic of the source vector.
InsertPoint saveIP() const
Returns the current insert point.
CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using Types.
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 * CreateCountTrailingZeroElems(Type *ResTy, Value *Mask, bool ZeroIsPoison=true, const Twine &Name="")
Create a call to llvm.experimental_cttz_elts.
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)
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="", bool IsNUW=false, bool IsNSW=false)
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateLogicalAnd(Value *Cond1, Value *Cond2, 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)
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.
@ IK_PtrInduction
Pointer induction var. Step = C.
This instruction inserts a single (scalar) element into a VectorType value.
VectorType * getType() const
Overload to return most specific vector type.
static InstructionCost getInvalid(CostType Val=0)
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
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
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
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.
InstTy * getInsertPos() const
void addMetadata(InstTy *NewInst) const
Add metadata (e.g.
This is an important class for using LLVM in a threaded context.
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.
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.
Type * getRecurrenceType() const
Returns the type of the recurrence.
TrackingVH< Value > getRecurrenceStartValue() const
static bool isAnyOfRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is of the form select(cmp(),x,y) where one of (x,...
static bool isFindLastIVRecurrenceKind(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
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 represents the LLVM 'select' instruction.
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.
StringRef - Represent a constant reference to a string, i.e.
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.
static Type * getVoidTy(LLVMContext &C)
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.
TypeID getTypeID() const
Return the type id for the type.
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.
void insert(VPRecipeBase *Recipe, iterator InsertPt)
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 VPWidenMemoryRecipe.
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 when normalized the first incoming value wi...
void execute(VPTransformState &State) override
Generate the phi/select nodes.
bool isNormalized() const
A normalized blend is one that has an odd number of operands, whereby the first operand does not have...
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
VPRegionBlock * getParent()
const VPBasicBlock * getExitingBasicBlock() const
const VPBlocksTy & getPredecessors() const
const VPBasicBlock * getEntryBasicBlock() const
VPValue * getMask() const
Return the mask used by this recipe.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPBranchOnMaskRecipe.
void execute(VPTransformState &State) override
Generate the extraction of the appropriate bit from the block mask and the conditional branch.
VPlan-based builder utility analogous to IRBuilder.
VPInstruction * createNaryOp(unsigned Opcode, ArrayRef< VPValue * > Operands, Instruction *Inst=nullptr, const Twine &Name="")
Create an N-ary operation with Opcode, Operands and set Inst as its underlying Instruction.
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).
unsigned getNumDefinedValues() const
Returns the number of values defined by the VPDef.
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 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.
void execute(VPTransformState &State) override
Produce a vectorized histogram operation.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPHistogramRecipe.
VPValue * getMask() const
Return the mask operand if one was provided, or a null pointer if all lanes should be executed uncond...
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
Instruction & getInstruction() const
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPIRInstruction.
void extractLastLaneOfOperand(VPBuilder &Builder)
Update the recipes single operand to the last lane of the operand using Builder.
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 VPInstruction.
@ ResumePhi
Creates a scalar phi in a leaf VPBB with a single predecessor in VPlan.
@ FirstOrderRecurrenceSplice
@ CanonicalIVIncrementForPart
@ CalculateTripCountMinusVF
bool opcodeMayReadOrWriteFromMemory() const
Returns true if the underlying opcode may read from or write to memory.
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...
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.
Instruction * getInsertPos() const
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPInterleaveRecipe.
unsigned getNumStoreOperands() const
Returns the number of stored operands of this interleave group.
static bool isVPIntrinsic(Intrinsic::ID)
In what follows, the term "input IR" refers to code that is fed into the vectorizer whereas the term ...
static VPLane getLastLaneForVF(const ElementCount &VF)
static VPLane getLaneFromEnd(const ElementCount &VF, unsigned Offset)
static VPLane getFirstLane()
void execute(VPTransformState &State) override
Generate the reduction in the loop.
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 VPPartialReductionRecipe.
unsigned getOpcode() const
Get the binary op's opcode.
void execute(VPTransformState &State) override
Generates phi nodes for live-outs (from a replicate region) 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
GEPNoWrapFlags getGEPNoWrapFlags() const
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.
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.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of VPReductionRecipe.
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.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPReplicateRecipe.
unsigned getOpcode() const
bool shouldPack() const
Returns true if the recipe is used by a widened recipe via an intervening VPPredInstPHIRecipe.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
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.
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.
Instruction * getUnderlyingInstr()
Returns the underlying instruction.
LLVM_DUMP_METHOD void dump() const
Print this VPSingleDefRecipe to dbgs() (for debugging).
This class can be used to assign names to VPValues.
LLVMContext & getContext()
Return the LLVMContext used by the analysis.
Type * inferScalarType(const VPValue *V)
Infer the type of V. Returns the scalar type of V.
VPValue * getUnrollPartOperand(VPUser &U) const
Return the VPValue operand containing the unroll part or null if there is no such operand.
unsigned getUnrollPart(VPUser &U) const
Return the unroll part.
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.
void setOperand(unsigned I, VPValue *New)
unsigned getNumOperands() const
operand_iterator op_begin()
VPValue * getOperand(unsigned N) const
virtual bool onlyFirstLaneUsed(const VPValue *Op) const
Returns true if the VPUser only uses the first lane of operand Op.
bool isDefinedOutsideLoopRegions() const
Returns true if the VPValue is defined outside any loop region.
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
bool hasMoreThanOneUniqueUser() const
Returns true if the value has more than one unique user.
Value * getUnderlyingValue() const
Return the underlying Value attached to this VPValue.
user_iterator user_begin()
unsigned getNumUsers() const
Value * getLiveInIRValue()
Returns the underlying IR value, if this VPValue is defined outside the scope of VPlan.
bool isLiveIn() const
Returns true if this VPValue is a live-in, i.e. defined outside the VPlan.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
Function * getCalledScalarFunction() const
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenCallRecipe.
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.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenCastRecipe.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override final
Print the recipe.
void execute(VPTransformState &State) override final
Produce a vp-intrinsic using the opcode and operands of the recipe, processing EVL elements.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate the gep nodes.
PHINode * getPHINode() const
VPValue * getStepValue()
Returns the step value of the induction.
const InductionDescriptor & getInductionDescriptor() const
Returns the induction descriptor for the recipe.
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.
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.
VPValue * getSplatVFValue()
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
StringRef getIntrinsicName() const
Return to name of the intrinsic as string.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
Type * getResultType() const
Return the scalar return type of the intrinsic.
void execute(VPTransformState &State) override
Produce a widened version of the vector intrinsic.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this vector intrinsic.
bool IsMasked
Whether the memory access is masked.
bool Reverse
Whether the consecutive accessed addresses are in reverse order.
bool isConsecutive() const
Return whether the loaded-from / stored-to addresses are consecutive.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenMemoryRecipe.
bool Consecutive
Whether the accessed 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.
VPValue * getFirstUnrolledPartOperand()
Returns the VPValue representing the value of this induction at the first unrolled part,...
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.
unsigned getOpcode() const
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.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
LLVMContext & getContext() const
All values hold a context through their type.
StringRef getName() const
Return a constant reference to the value's name.
VectorBuilder & setEVL(Value *NewExplicitVectorLength)
VectorBuilder & setMask(Value *NewMask)
Value * createVectorInstruction(unsigned Opcode, Type *ReturnTy, ArrayRef< Value * > VecOpArray, const Twine &Name=Twine())
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.
constexpr LeafTy divideCoefficientBy(ScalarTy RHS) const
We do not provide the '/' operator here because division for polynomial types does not work in the sa...
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.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
@ C
The default llvm calling convention, compatible with C.
Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
StringRef getBaseName(ID id)
Return the LLVM name for an intrinsic, without encoded types for overloading, such as "llvm....
bool match(Val *V, const Pattern &P)
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
auto m_LogicalOr()
Matches L || R where L and R are arbitrary values.
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
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 * createSimpleReduction(IRBuilderBase &B, Value *Src, RecurKind RdxKind)
Create a reduction of the given vector.
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
unsigned getLoadStoreAddressSpace(const Value *I)
A helper function that returns the address space of the pointer operand of load or store instruction.
Intrinsic::ID getMinMaxReductionIntrinsicOp(Intrinsic::ID RdxID)
Returns the min/max intrinsic used when expanding a min/max reduction.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
const Value * getLoadStorePointerOperand(const Value *V)
A helper function that returns the pointer operand of a load or store instruction.
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.
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.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
cl::opt< bool > EnableVPlanNativePath("enable-vplan-native-path", cl::Hidden, cl::desc("Enable VPlan-native vectorization path with " "support for outer loop vectorization."))
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.
Value * createReduction(IRBuilderBase &B, const RecurrenceDescriptor &Desc, Value *Src, PHINode *OrigPhi=nullptr)
Create a generic reduction using a recurrence descriptor Desc Fast-math-flags are propagated using th...
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.
@ SMax
Signed integer max implemented in terms of select(cmp()).
bool isVectorIntrinsicWithScalarOpAtArg(Intrinsic::ID ID, unsigned ScalarOpdIdx, const TargetTransformInfo *TTI)
Identifies if the vector form of the intrinsic has a scalar operand.
Value * getRecurrenceIdentity(RecurKind K, Type *Tp, FastMathFlags FMF)
Given information about an recurrence kind, return the identity for the @llvm.vector....
DWARFExpression::Operation Op
Value * createStepForVF(IRBuilderBase &B, Type *Ty, ElementCount VF, int64_t Step)
Return a value for Step multiplied by VF.
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.
Type * toVectorTy(Type *Scalar, ElementCount EC)
A helper function for converting Scalar types to vector types.
bool isVectorIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID, int OpdIdx, const TargetTransformInfo *TTI)
Identifies if the vector form of the intrinsic is overloaded on the type of the operand at index OpdI...
This struct is a compact representation of a valid (non-zero power of two) alignment.
Struct to hold various analysis needed for cost computations.
TargetTransformInfo::OperandValueInfo getOperandInfo(VPValue *V) const
Returns the OperandInfo for V, if it is a live-in.
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...
TargetTransformInfo::TargetCostKind CostKind
const TargetLibraryInfo & TLI
const TargetTransformInfo & TTI
SmallPtrSet< Instruction *, 8 > SkipCostComputation
void execute(VPTransformState &State) override
Generate the phi nodes.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this first-order recurrence phi 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 gather.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenLoadEVLRecipe.
VPValue * getEVL() const
Return the EVL operand.
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.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenSelectRecipe.
void execute(VPTransformState &State) override
Produce a widened version of the select instruction.
VPValue * getStoredValue() const
Return the address accessed by this recipe.
void execute(VPTransformState &State) override
Generate the wide store or scatter.
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 VPWidenStoreEVLRecipe.
VPValue * getEVL() const
Return the EVL operand.
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.