35#define DEBUG_TYPE "vectorutils"
47 case Intrinsic::bswap:
48 case Intrinsic::bitreverse:
49 case Intrinsic::ctpop:
58 case Intrinsic::sadd_sat:
59 case Intrinsic::ssub_sat:
60 case Intrinsic::uadd_sat:
61 case Intrinsic::usub_sat:
62 case Intrinsic::sshl_sat:
63 case Intrinsic::ushl_sat:
64 case Intrinsic::smul_fix:
65 case Intrinsic::smul_fix_sat:
66 case Intrinsic::umul_fix:
67 case Intrinsic::umul_fix_sat:
68 case Intrinsic::uadd_with_overflow:
69 case Intrinsic::sadd_with_overflow:
70 case Intrinsic::usub_with_overflow:
71 case Intrinsic::ssub_with_overflow:
72 case Intrinsic::umul_with_overflow:
73 case Intrinsic::smul_with_overflow:
78 case Intrinsic::atan2:
81 case Intrinsic::sincos:
82 case Intrinsic::sincospi:
88 case Intrinsic::exp10:
90 case Intrinsic::frexp:
91 case Intrinsic::ldexp:
93 case Intrinsic::log10:
96 case Intrinsic::minnum:
97 case Intrinsic::maxnum:
98 case Intrinsic::minimum:
99 case Intrinsic::maximum:
100 case Intrinsic::minimumnum:
101 case Intrinsic::maximumnum:
102 case Intrinsic::modf:
103 case Intrinsic::copysign:
104 case Intrinsic::floor:
105 case Intrinsic::ceil:
106 case Intrinsic::trunc:
107 case Intrinsic::rint:
108 case Intrinsic::nearbyint:
109 case Intrinsic::round:
110 case Intrinsic::roundeven:
113 case Intrinsic::fmuladd:
114 case Intrinsic::is_fpclass:
115 case Intrinsic::powi:
116 case Intrinsic::canonicalize:
117 case Intrinsic::fptosi_sat:
118 case Intrinsic::fptoui_sat:
119 case Intrinsic::lround:
120 case Intrinsic::llround:
121 case Intrinsic::lrint:
122 case Intrinsic::llrint:
123 case Intrinsic::ucmp:
124 case Intrinsic::scmp:
125 case Intrinsic::clmul:
126 case Intrinsic::pdep:
127 case Intrinsic::pext:
128 case Intrinsic::smulh:
129 case Intrinsic::umulh:
145 unsigned ScalarOpdIdx,
149 return TTI->isTargetIntrinsicWithScalarOpAtArg(ID, ScalarOpdIdx);
157 case Intrinsic::ctlz:
158 case Intrinsic::cttz:
159 case Intrinsic::is_fpclass:
160 case Intrinsic::powi:
161 case Intrinsic::vector_extract:
162 case Intrinsic::masked_compressstore:
163 return (ScalarOpdIdx == 1);
164 case Intrinsic::smul_fix:
165 case Intrinsic::smul_fix_sat:
166 case Intrinsic::umul_fix:
167 case Intrinsic::umul_fix_sat:
168 case Intrinsic::vector_splice_left:
169 case Intrinsic::vector_splice_right:
170 return (ScalarOpdIdx == 2);
171 case Intrinsic::experimental_vp_splice:
172 return ScalarOpdIdx == 2 || ScalarOpdIdx == 4;
173 case Intrinsic::experimental_vp_strided_load:
174 return ScalarOpdIdx == 0 || ScalarOpdIdx == 1;
175 case Intrinsic::experimental_vp_strided_store:
176 return ScalarOpdIdx == 1 || ScalarOpdIdx == 2;
177 case Intrinsic::masked_expandload:
178 return ScalarOpdIdx == 0;
179 case Intrinsic::loop_dependence_war_mask:
191 return TTI->isTargetIntrinsicWithOverloadTypeAtArg(ID, OpdIdx);
194 case Intrinsic::fptosi_sat:
195 case Intrinsic::fptoui_sat:
196 case Intrinsic::lround:
197 case Intrinsic::llround:
198 case Intrinsic::lrint:
199 case Intrinsic::llrint:
200 case Intrinsic::ucmp:
201 case Intrinsic::scmp:
202 case Intrinsic::vector_extract:
203 case Intrinsic::loop_dependence_war_mask:
204 case Intrinsic::masked_expandload:
205 return OpdIdx == -1 || OpdIdx == 0;
206 case Intrinsic::modf:
207 case Intrinsic::sincos:
208 case Intrinsic::sincospi:
209 case Intrinsic::is_fpclass:
211 case Intrinsic::powi:
212 case Intrinsic::ldexp:
213 return OpdIdx == -1 || OpdIdx == 1;
214 case Intrinsic::experimental_vp_strided_load:
215 return OpdIdx == -1 || OpdIdx == 0 || OpdIdx == 1;
216 case Intrinsic::experimental_vp_strided_store:
217 return OpdIdx == 0 || OpdIdx == 1 || OpdIdx == 2;
218 case Intrinsic::masked_compressstore:
219 return OpdIdx == 0 || OpdIdx == 1;
225std::optional<unsigned>
228 case Intrinsic::experimental_vp_strided_store:
229 case Intrinsic::masked_compressstore:
231 case Intrinsic::experimental_vp_strided_load:
232 case Intrinsic::masked_expandload:
239std::optional<unsigned>
242 case Intrinsic::experimental_vp_strided_store:
243 case Intrinsic::masked_compressstore:
254 case Intrinsic::masked_compressstore:
256 case Intrinsic::masked_expandload:
267 return TTI->isTargetIntrinsicWithStructReturnOverloadAtField(ID, RetIdx);
270 case Intrinsic::frexp:
271 return RetIdx == 0 || RetIdx == 1;
287 ID == Intrinsic::lifetime_end || ID == Intrinsic::assume ||
288 ID == Intrinsic::experimental_noalias_scope_decl ||
289 ID == Intrinsic::sideeffect || ID == Intrinsic::pseudoprobe)
303 if (HasIntrinsicMapping(Intrinsic::sincos))
305 LibFunc LF = NotLibFunc;
307 LF = LibFunc_sincosf;
310 if (LF != NotLibFunc &&
TLI.isFunctionVectorizable(
TLI.getName(LF), EC))
312 return HasIntrinsicMapping(Intrinsic::sin) &&
313 HasIntrinsicMapping(Intrinsic::cos);
318 case Intrinsic::vector_interleave2:
320 case Intrinsic::vector_interleave3:
322 case Intrinsic::vector_interleave4:
324 case Intrinsic::vector_interleave5:
326 case Intrinsic::vector_interleave6:
328 case Intrinsic::vector_interleave7:
330 case Intrinsic::vector_interleave8:
339 case Intrinsic::vector_deinterleave2:
341 case Intrinsic::vector_deinterleave3:
343 case Intrinsic::vector_deinterleave4:
345 case Intrinsic::vector_deinterleave5:
347 case Intrinsic::vector_deinterleave6:
349 case Intrinsic::vector_deinterleave7:
351 case Intrinsic::vector_deinterleave8:
359 [[maybe_unused]]
unsigned Factor =
362 assert(Factor && Factor == DISubtypes.
size() &&
363 "unexpected deinterleave factor or result type");
371 assert(V->getType()->isVectorTy() &&
"Not looking at a vector?");
375 unsigned Width = FVTy->getNumElements();
381 return C->getAggregateElement(EltNo);
392 return III->getOperand(1);
395 if (III == III->getOperand(0))
411 if (InEl < (
int)LHSWidth)
420 if (
Constant *Elt =
C->getAggregateElement(EltNo))
421 if (Elt->isNullValue())
427 if (EltNo < VTy->getElementCount().getKnownMinValue())
442 if (SplatIndex != -1 && SplatIndex != M)
448 assert((SplatIndex == -1 || SplatIndex >= 0) &&
"Negative index?");
459 return C->getSplatValue();
480 return C->getSplatValue() !=
nullptr;
495 return Shuf->getMaskValue(Index) == Index;
520 const APInt &DemandedElts,
APInt &DemandedLHS,
521 APInt &DemandedRHS,
bool AllowUndefElts) {
525 if (DemandedElts.
isZero())
534 for (
unsigned I = 0, E = Mask.size();
I != E; ++
I) {
536 assert((-1 <= M) && (M < (SrcWidth * 2)) &&
537 "Invalid shuffle mask constant");
539 if (!DemandedElts[
I] || (AllowUndefElts && (M < 0)))
550 DemandedRHS.
setBit(M - SrcWidth);
557 const APInt &DemandedElts,
APInt &DemandedLHS,
558 APInt &DemandedRHS) {
561 DemandedLHS = DemandedRHS = DemandedElts;
568 DemandedLHS, DemandedRHS);
572 std::array<std::pair<int, int>, 2> &SrcInfo) {
573 const int SignalValue = NumElts * 2;
574 SrcInfo[0] = {-1, SignalValue};
575 SrcInfo[1] = {-1, SignalValue};
579 int Src = M >= NumElts;
580 int Diff = (int)i - (M % NumElts);
582 for (
int j = 0; j < 2; j++) {
583 auto &[SrcE, DiffE] = SrcInfo[j];
585 assert(DiffE == SignalValue);
589 if (SrcE == Src && DiffE == Diff) {
598 return SrcInfo[0].first != -1;
603 assert(Scale > 0 &&
"Unexpected scaling factor");
607 ScaledMask.
assign(Mask.begin(), Mask.end());
612 for (
int MaskElt : Mask) {
614 assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <= INT32_MAX &&
615 "Overflowed 32-bits");
617 for (
int SliceElt = 0; SliceElt != Scale; ++SliceElt)
618 ScaledMask.
push_back(MaskElt < 0 ? MaskElt : Scale * MaskElt + SliceElt);
624 assert(Scale > 0 &&
"Unexpected scaling factor");
628 ScaledMask.
assign(Mask.begin(), Mask.end());
633 int NumElts = Mask.size();
634 if (NumElts % Scale != 0)
638 ScaledMask.
reserve(NumElts / Scale);
643 assert((
int)MaskSlice.
size() == Scale &&
"Expected Scale-sized slice.");
646 int SliceFront = MaskSlice.
front();
647 if (SliceFront < 0) {
655 if (SliceFront % Scale != 0)
658 for (
int i = 1; i < Scale; ++i)
659 if (MaskSlice[i] != SliceFront + i)
661 ScaledMask.
push_back(SliceFront / Scale);
663 Mask = Mask.drop_front(Scale);
664 }
while (!Mask.empty());
666 assert((
int)ScaledMask.
size() * Scale == NumElts &&
"Unexpected scaled mask");
675 unsigned NumElts = M.size();
676 if (NumElts % 2 != 0)
680 for (
unsigned i = 0; i < NumElts; i += 2) {
685 if (
M0 == -1 &&
M1 == -1) {
690 if (
M0 == -1 &&
M1 != -1 && (
M1 % 2) == 1) {
695 if (
M0 != -1 && (
M0 % 2) == 0 && ((
M0 + 1) ==
M1 ||
M1 == -1)) {
704 assert(NewMask.
size() == NumElts / 2 &&
"Incorrect size for mask!");
710 unsigned NumSrcElts = Mask.size();
711 assert(NumSrcElts > 0 && NumDstElts > 0 &&
"Unexpected scaling factor");
714 if (NumSrcElts == NumDstElts) {
715 ScaledMask.
assign(Mask.begin(), Mask.end());
720 assert(((NumSrcElts % NumDstElts) == 0 || (NumDstElts % NumSrcElts) == 0) &&
721 "Unexpected scaling factor");
723 if (NumSrcElts > NumDstElts) {
724 int Scale = NumSrcElts / NumDstElts;
728 int Scale = NumDstElts / NumSrcElts;
735 std::array<SmallVector<int, 16>, 2> TmpMasks;
738 for (
unsigned Scale = 2; Scale <= InputMask.
size(); ++Scale) {
748 ArrayRef<int> Mask,
unsigned NumOfSrcRegs,
unsigned NumOfDestRegs,
749 unsigned NumOfUsedRegs,
function_ref<
void()> NoInputAction,
758 int Sz = Mask.size();
759 unsigned SzDest = Sz / NumOfDestRegs;
760 unsigned SzSrc = Sz / NumOfSrcRegs;
761 for (
unsigned I = 0;
I < NumOfDestRegs; ++
I) {
762 auto &RegMasks = Res[
I];
763 RegMasks.
assign(2 * NumOfSrcRegs, {});
766 for (
unsigned K = 0;
K < SzDest; ++
K) {
767 int Idx =
I * SzDest +
K;
772 int MaskIdx = Mask[Idx] % Sz;
773 int SrcRegIdx = MaskIdx / SzSrc + (Mask[Idx] >= Sz ? NumOfSrcRegs : 0);
776 if (RegMasks[SrcRegIdx].empty())
778 RegMasks[SrcRegIdx][
K] = MaskIdx % SzSrc;
786 switch (NumSrcRegs) {
795 unsigned SrcReg = std::distance(Dest.begin(), It);
796 SingleInputAction(*It, SrcReg,
I);
808 for (
int Idx = 0, VF = FirstMask.
size(); Idx < VF; ++Idx) {
811 "Expected undefined mask element.");
812 FirstMask[Idx] = SecondMask[Idx] + VF;
817 for (
int Idx = 0, VF = Mask.size(); Idx < VF; ++Idx) {
833 if (FirstIdx == SecondIdx) {
839 SecondMask = RegMask;
840 CombineMasks(FirstMask, SecondMask);
841 ManyInputsAction(FirstMask, FirstIdx, SecondIdx, NewReg);
843 NormalizeMask(FirstMask);
845 SecondMask = FirstMask;
846 SecondIdx = FirstIdx;
848 if (FirstIdx != SecondIdx && SecondIdx >= 0) {
849 CombineMasks(SecondMask, FirstMask);
850 ManyInputsAction(SecondMask, SecondIdx, FirstIdx, NewReg);
852 Dest[FirstIdx].clear();
853 NormalizeMask(SecondMask);
855 }
while (SecondIdx >= 0);
863 const APInt &DemandedElts,
865 APInt &DemandedRHS) {
866 assert(VectorBitWidth >= 128 &&
"Vectors smaller than 128 bit not supported");
867 int NumLanes = VectorBitWidth / 128;
869 int NumEltsPerLane = NumElts / NumLanes;
870 int HalfEltsPerLane = NumEltsPerLane / 2;
876 for (
int Idx = 0; Idx != NumElts; ++Idx) {
877 if (!DemandedElts[Idx])
879 int LaneIdx = (Idx / NumEltsPerLane) * NumEltsPerLane;
880 int LocalIdx = Idx % NumEltsPerLane;
881 if (LocalIdx < HalfEltsPerLane) {
882 DemandedLHS.
setBit(LaneIdx + 2 * LocalIdx);
884 LocalIdx -= HalfEltsPerLane;
885 DemandedRHS.
setBit(LaneIdx + 2 * LocalIdx);
906 bool SeenExtFromIllegalType =
false;
907 for (
auto *BB : Blocks)
908 for (
auto &
I : *BB) {
909 InstructionSet.insert(&
I);
912 !
TTI->isTypeLegal(
I.getOperand(0)->getType()))
913 SeenExtFromIllegalType =
true;
917 !
I.getType()->isVectorTy() &&
918 I.getOperand(0)->getType()->getScalarSizeInBits() <= 64) {
929 if (Worklist.
empty() || (
TTI && !SeenExtFromIllegalType))
933 while (!Worklist.
empty()) {
942 if (DB.getDemandedBits(
I).getBitWidth() > 64)
945 uint64_t V = DB.getDemandedBits(
I).getZExtValue();
952 !InstructionSet.count(
I))
959 !
I->getType()->isIntegerTy()) {
960 DBits[Leader] |= ~0ULL;
975 if (DBits[Leader] == ~0ULL)
979 for (
Value *O :
I->operands()) {
992 for (
auto &
I : DBits) {
999 for (
auto *U :
I.first->users())
1000 if (U->getType()->isIntegerTy() && DBits.
count(U) == 0)
1004 for (
const auto &E : ECs) {
1007 uint64_t LeaderDemandedBits = 0;
1009 LeaderDemandedBits |= DBits[M];
1032 Type *Ty = M->getType();
1034 Ty =
MI->getOperand(0)->getType();
1036 if (MinBW >= Ty->getScalarSizeInBits())
1049 U.getOperandNo() == 1)
1050 return CI->uge(MinBW);
1051 return bit_ceil(DB.getDemandedBits(&U).getActiveBits()) > MinBW;
1073 for (
unsigned i = 0; i < VF; i++)
1074 for (
unsigned j = 0; j < Group.
getFactor(); ++j) {
1075 unsigned HasMember = Group.
getMember(j) ? 1 : 0;
1076 Mask.push_back(Builder.getInt1(HasMember));
1085 for (
unsigned i = 0; i < VF; i++)
1086 for (
unsigned j = 0; j < ReplicationFactor; j++)
1095 for (
unsigned i = 0; i < VF; i++)
1096 for (
unsigned j = 0; j < NumVecs; j++)
1097 Mask.push_back(j * VF + i);
1105 for (
unsigned i = 0; i < VF; i++)
1106 Mask.push_back(Start + i * Stride);
1113 unsigned NumUndefs) {
1115 for (
unsigned i = 0; i < NumInts; i++)
1116 Mask.push_back(Start + i);
1118 for (
unsigned i = 0; i < NumUndefs; i++)
1127 int NumEltsSigned = NumElts;
1128 assert(NumEltsSigned > 0 &&
"Expected smaller or non-zero element count");
1133 for (
int MaskElt : Mask) {
1134 assert((MaskElt < NumEltsSigned * 2) &&
"Expected valid shuffle mask");
1135 int UnaryElt = MaskElt >= NumEltsSigned ? MaskElt - NumEltsSigned : MaskElt;
1148 assert(VecTy1 && VecTy2 &&
1149 VecTy1->getScalarType() == VecTy2->getScalarType() &&
1150 "Expect two vectors with the same element type");
1154 assert(NumElts1 >= NumElts2 &&
"Unexpect the first vector has less elements");
1156 if (NumElts1 > NumElts2) {
1158 V2 = Builder.CreateShuffleVector(
1162 return Builder.CreateShuffleVector(
1168 unsigned NumVecs = Vecs.
size();
1169 assert(NumVecs > 1 &&
"Should be at least two vectors");
1175 for (
unsigned i = 0; i < NumVecs - 1; i += 2) {
1176 Value *V0 = ResList[i], *
V1 = ResList[i + 1];
1177 assert((V0->getType() ==
V1->getType() || i == NumVecs - 2) &&
1178 "Only the last vector may have a different type");
1184 if (NumVecs % 2 != 0)
1185 TmpList.
push_back(ResList[NumVecs - 1]);
1188 NumVecs = ResList.
size();
1189 }
while (NumVecs > 1);
1199 "Mask must be a vector of i1");
1213 "Mask must be a fixed width vector of i1");
1215 const unsigned VWidth =
1219 for (
unsigned i = 0; i < VWidth; i++)
1220 if (CV->getAggregateElement(i)->isNullValue())
1222 return DemandedElts;
1231 LAI(LAI), OptForSize(OptForSize) {}
1233bool InterleavedAccessInfo::isStrided(
int Stride)
const {
1234 unsigned Factor = std::abs(Stride);
1235 return Factor >= 2 && Factor <= Opts.max_interleave_group_factor;
1238void InterleavedAccessInfo::collectConstStrideAccesses(
1253 for (
auto &
I : *BB) {
1262 if (
Size * 8 !=
DL.getTypeSizeInBits(ElementTy))
1272 int64_t Stride =
getPtrStride(PSE, ElementTy, Ptr, TheLoop, *DT, Strides,
1282 AccessStrideInfo[&
I] = StrideDescriptor(Stride, Scev,
Size,
1324 bool EnablePredicatedInterleavedMemAccesses) {
1326 const auto &Strides = LAI->getSymbolicStrides();
1331 collectConstStrideAccesses(AccessStrideInfo, Strides,
1332 OptForSize ?
nullptr : &Predicates);
1334 if (AccessStrideInfo.
empty())
1338 collectDependences();
1359 for (
auto BI = AccessStrideInfo.
rbegin(), E = AccessStrideInfo.
rend();
1362 StrideDescriptor DesB = BI->second;
1368 if (isStrided(DesB.Stride) &&
1369 (!isPredicated(
B->getParent()) || EnablePredicatedInterleavedMemAccesses)) {
1374 GroupB = createInterleaveGroup(
B, DesB.Stride, DesB.Alignment);
1375 if (
B->mayWriteToMemory())
1376 StoreGroups.
insert(GroupB);
1378 LoadGroups.
insert(GroupB);
1382 for (
auto AI = std::next(BI); AI != E; ++AI) {
1384 StrideDescriptor DesA = AI->second;
1409 if (MemberOfGroupB && !canReorderMemAccessesForInterleavedGroups(
1410 A, &*AccessStrideInfo.
find(MemberOfGroupB)))
1411 return MemberOfGroupB;
1421 if (
A->mayWriteToMemory() && GroupA != GroupB) {
1429 if (GroupB && LoadGroups.
contains(GroupB))
1430 DependentInst = DependentMember(GroupB, &*AI);
1431 else if (!canReorderMemAccessesForInterleavedGroups(&*AI, &*BI))
1434 if (DependentInst) {
1439 if (GroupA && StoreGroups.
contains(GroupA)) {
1441 "dependence between "
1442 << *
A <<
" and " << *DependentInst <<
'\n');
1443 StoreGroups.
remove(GroupA);
1444 releaseGroup(GroupA);
1450 if (GroupB && LoadGroups.
contains(GroupB)) {
1452 <<
" as complete.\n");
1453 CompletedLoadGroups.
insert(GroupB);
1457 if (CompletedLoadGroups.
contains(GroupB)) {
1465 if (!isStrided(DesA.Stride) || !isStrided(DesB.Stride))
1475 (
A->mayReadFromMemory() !=
B->mayReadFromMemory()) ||
1476 (
A->mayWriteToMemory() !=
B->mayWriteToMemory()))
1481 if (DesA.Stride != DesB.Stride || DesA.Size != DesB.Size)
1491 PSE.getSE()->getMinusSCEV(DesA.Scev, DesB.Scev));
1498 if (DistanceToB %
static_cast<int64_t
>(DesB.Size))
1505 if ((isPredicated(BlockA) || isPredicated(BlockB)) &&
1506 (!EnablePredicatedInterleavedMemAccesses || BlockA != BlockB))
1512 GroupB->
getIndex(
B) + DistanceToB /
static_cast<int64_t
>(DesB.Size);
1519 <<
" into the interleave group with" << *
B
1521 InterleaveGroupMap[
A] = GroupB;
1524 if (
A->mayReadFromMemory())
1531 if (!LoadGroups.
empty() || !StoreGroups.
empty())
1532 PSE.addPredicates(Predicates);
1536 const char *FirstOrLast) ->
bool {
1538 assert(Member &&
"Group member does not exist");
1541 if (
getPtrStride(PSE, AccessTy, MemberPtr, TheLoop, *DT, Strides,
1545 LLVM_DEBUG(
dbgs() <<
"LV: Invalidate candidate interleaved group due to "
1547 <<
" group member potentially pointer-wrapping.\n");
1548 releaseGroup(Group);
1566 for (
auto *Group : LoadGroups) {
1578 if (InvalidateGroupIfMemberMayWrap(Group, 0,
"first"))
1581 InvalidateGroupIfMemberMayWrap(Group, Group->
getFactor() - 1,
"last");
1590 dbgs() <<
"LV: Invalidate candidate interleaved group due to "
1591 "a reverse access with gaps.\n");
1592 releaseGroup(Group);
1596 dbgs() <<
"LV: Interleaved group requires epilogue iteration.\n");
1597 RequiresScalarEpilogue =
true;
1601 for (
auto *Group : StoreGroups) {
1611 if (!EnablePredicatedInterleavedMemAccesses) {
1613 dbgs() <<
"LV: Invalidate candidate interleaved store group due "
1615 releaseGroup(Group);
1625 if (InvalidateGroupIfMemberMayWrap(Group, 0,
"first"))
1627 for (
int Index = Group->
getFactor() - 1; Index > 0; Index--)
1629 InvalidateGroupIfMemberMayWrap(Group, Index,
"last");
1643 bool ReleasedGroup = InterleaveGroups.
remove_if([&](
auto *Group) {
1644 if (!Group->requiresScalarEpilogue())
1648 <<
"LV: Invalidate candidate interleaved group due to gaps that "
1649 "require a scalar epilogue (not allowed under optsize) and cannot "
1650 "be masked (not enabled). \n");
1651 releaseGroupWithoutRemovingFromSet(Group);
1654 assert(ReleasedGroup &&
"At least one group must be invalidated, as a "
1655 "scalar epilogue was required");
1656 (void)ReleasedGroup;
1657 RequiresScalarEpilogue =
false;
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Generic implementation of equivalence classes through the use Tarjan's efficient union-find algorithm...
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
This file provides utility for Memory Model Relaxation Annotations (MMRAs).
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static SymbolRef::Type getType(const Symbol *Sym)
static Value * concatenateTwoVectors(IRBuilderBase &Builder, Value *V1, Value *V2)
A helper function for concatenating vectors.
Class for arbitrary precision integers.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
void clearBit(unsigned BitPosition)
Set a given bit to 0.
void setBit(unsigned BitPosition)
Set the given bit to 1 whose position is given as "bitPosition".
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
int64_t getSExtValue() const
Get sign extended value.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
const T & front() const
Get the first element.
size_t size() const
Get the array size.
LLVM Basic Block Representation.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
This class represents a function call, abstracting a target machine's calling convention.
static LLVM_ABI Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
This represents a collection of equivalence classes and supports three efficient operations: insert a...
iterator_range< member_iterator > members(const ECValue &ECV) const
const ElemTy & getOrInsertLeaderValue(const ElemTy &V)
Return the leader for the specified value that is in the set.
member_iterator unionSets(const ElemTy &V1, const ElemTy &V2)
Merge the two equivalence sets for the specified values, inserting them if they do not already exist ...
Common base class shared among various IRBuilders.
This instruction inserts a single (scalar) element into a VectorType value.
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.
bool isFull() const
Return true if this group is full, i.e. it has no gaps.
uint32_t getIndex(const InstTy *Instr) const
Get the index for the given member.
void setInsertPos(InstTy *Inst)
bool insertMember(InstTy *Instr, int32_t Index, Align NewAlign)
Try to insert a new member Instr with index Index and alignment NewAlign.
InterleaveGroup< Instruction > * getInterleaveGroup(const Instruction *Instr) const
Get the interleave group that Instr belongs to.
bool requiresScalarEpilogue() const
Returns true if an interleaved group that may access memory out-of-bounds requires a scalar epilogue ...
bool isInterleaved(Instruction *Instr) const
Check if Instr belongs to any interleave group.
LLVM_ABI InterleavedAccessInfo(PredicatedScalarEvolution &PSE, Loop *L, DominatorTree *DT, LoopInfo *LI, const LoopAccessInfo *LAI, bool OptForSize)
LLVM_ABI void analyzeInterleaving(bool EnableMaskedInterleavedGroup)
Analyze the interleaved accesses and collect them in interleave groups.
LLVM_ABI void invalidateGroupsRequiringScalarEpilogue()
Invalidate groups that require a scalar epilogue (due to gaps).
A wrapper class for inspecting calls to intrinsic functions.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
Drive the analysis of memory accesses in the loop.
BlockT * getHeader() const
Store the result of a depth first search within basic blocks contained by a single loop.
Represents a single loop in the control flow graph.
This class implements a map that also provides access to all stored values in a deterministic order.
iterator find(const KeyT &Key)
reverse_iterator rbegin()
A Module instance is used to store all the information related to an LLVM module.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
This class represents a constant integer value.
const APInt & getAPInt() const
This class represents an analyzed expression in the program.
bool remove(const value_type &X)
Remove an item from the set vector.
bool contains(const_arg_type key) const
Check if the SetVector contains the given key.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
This instruction constructs a fixed permutation of two input vectors.
int getMaskValue(unsigned Elt) const
Return the shuffle mask value of this instruction for the given element index.
VectorType * getType() const
Overload to return most specific vector type.
static LLVM_ABI void getShuffleMask(const Constant *Mask, SmallVectorImpl< int > &Result)
Convert the input shuffle mask operand to a vector of integers.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
bool remove_if(UnaryPredicate P)
Remove elements that match the given predicate.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Provides information about what library functions are available for the current target.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
ArrayRef< Type * > subtypes() const
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
A Use represents the edge between a Value definition and its users.
Value * getOperand(unsigned i) const
static LLVM_ABI std::optional< unsigned > getMaskParamPos(Intrinsic::ID IntrinsicID)
static LLVM_ABI std::optional< unsigned > getVectorLengthParamPos(Intrinsic::ID IntrinsicID)
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
Base class of all SIMD vector types.
Type * getElementType() const
An efficient, type-erasing, non-owning reference to a callable.
LLVM_ABI StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
LLVM_ABI bool isTriviallyScalarizable(ID id)
Returns true if the intrinsic is trivially scalarizable.
LLVM_ABI bool isTargetIntrinsic(ID IID)
isTargetIntrinsic - Returns true if IID is an intrinsic specific to a certain target.
SpecificConstantMatch m_ZeroInt()
Convenience matchers for specific integer values.
AllOnesConstantMatch m_AllOnes()
match_combine_or< Ty... > m_CombineOr(const Ty &...Ps)
Combine pattern matchers matching any of Ps patterns.
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
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_BinOp()
Match an arbitrary binary operation and ignore it.
auto m_Value()
Match an arbitrary value and ignore it.
auto m_UndefValue()
Match an arbitrary UndefValue constant.
auto m_Constant()
Match an arbitrary Constant and ignore it.
ContainsMatchingVectorElement_match< SPTy > m_ContainsMatchingVectorElement(const SPTy &SubPattern)
Match a vector constant where at least one of its elements matches the subpattern.
TwoOps_match< V1_t, V2_t, Instruction::ShuffleVector > m_Shuffle(const V1_t &v1, const V2_t &v2)
Matches ShuffleVectorInst independently of mask value.
ThreeOps_match< Val_t, Elt_t, Idx_t, Instruction::InsertElement > m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx)
Matches InsertElementInst.
auto m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
This is an optimization pass for GlobalISel generic memory operations.
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.
LLVM_ABI Intrinsic::ID getVectorIntrinsicIDForCall(const CallInst *CI, const TargetLibraryInfo *TLI)
Returns intrinsic ID for call.
LLVM_ABI APInt possiblyDemandedEltsInMask(Value *Mask)
Given a mask vector of the form <Y x i1>, return an APInt (of bitwidth Y) for each lane which may be ...
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
LLVM_ABI std::optional< unsigned > getVectorStoreIntrinsicDataArgIdx(Intrinsic::ID ID)
Returns the argument index of the data value of the vector store intrinsic ID, or std::nullopt if the...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
const Value * getLoadStorePointerOperand(const Value *V)
A helper function that returns the pointer operand of a load or store instruction.
LLVM_ABI llvm::SmallVector< int, 16 > createUnaryMask(ArrayRef< int > Mask, unsigned NumElts)
Given a shuffle mask for a binary shuffle, create the equivalent shuffle mask assuming both operands ...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ABI const SCEV * replaceSymbolicStrideSCEV(PredicatedScalarEvolution &PSE, const Loop *Lp, const SymbolicStrideMap &PtrToStride, Value *Ptr, SmallVectorImpl< const SCEVPredicate * > *Predicates=nullptr)
Return the SCEV corresponding to a pointer with the symbolic stride replaced with constant one,...
int bit_width(T Value)
Returns the number of bits needed to represent Value if Value is nonzero.
LLVM_ABI 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.
LLVM_ABI bool widenShuffleMaskElts(int Scale, ArrayRef< int > Mask, SmallVectorImpl< int > &ScaledMask)
Try to transform a shuffle mask by replacing elements with the scaled index for an equivalent mask of...
LLVM_ABI Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
LLVM_ABI std::optional< int64_t > getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr, const Loop *Lp, const DominatorTree &DT, const SymbolicStrideMap &StridesMap=SymbolicStrideMap(), bool ShouldCheckWrap=true, SmallVectorImpl< const SCEVPredicate * > *Predicates=nullptr)
If the pointer has a constant stride return it in units of the access type size.
T bit_ceil(T Value)
Returns the smallest integral power of two no smaller than Value if Value is nonzero.
constexpr auto equal_to(T &&Arg)
Functor variant of std::equal_to that can be used as a UnaryPredicate in functional algorithms like a...
unsigned M1(unsigned Val)
const AnalysisOptions & getAnalysisOptions(const LLVMContext &C)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI bool getShuffleDemandedElts(int SrcWidth, ArrayRef< int > Mask, const APInt &DemandedElts, APInt &DemandedLHS, APInt &DemandedRHS, bool AllowUndefElts=false)
Transform a shuffle mask's output demanded element mask into demanded element masks for the 2 operand...
LLVM_ABI bool isSplatValue(const Value *V, int Index=-1, unsigned Depth=0)
Return true if each element of the vector value V is poisoned or equal to every other non-poisoned el...
LLVM_ABI 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.
constexpr unsigned MaxAnalysisRecursionDepth
LLVM_ABI llvm::SmallVector< int, 16 > createStrideMask(unsigned Start, unsigned Stride, unsigned VF)
Create a stride shuffle mask.
LLVM_ABI void getHorizDemandedEltsForFirstOperand(unsigned VectorBitWidth, const APInt &DemandedElts, APInt &DemandedLHS, APInt &DemandedRHS)
Compute the demanded elements mask of horizontal binary operations.
LLVM_ABI llvm::SmallVector< int, 16 > createReplicatedMask(unsigned ReplicationFactor, unsigned VF)
Create a mask with replicated elements.
DenseMap< Value *, const SCEVUnknown * > SymbolicStrideMap
Maps a pointer to its symbolic (non-constant) stride.
LLVM_ABI unsigned getDeinterleaveIntrinsicFactor(Intrinsic::ID ID)
Returns the corresponding factor of llvm.vector.deinterleaveN intrinsics.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI unsigned getInterleaveIntrinsicFactor(Intrinsic::ID ID)
Returns the corresponding factor of llvm.vector.interleaveN intrinsics.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
constexpr int PoisonMaskElem
LLVM_ABI bool isTriviallyScalarizable(Intrinsic::ID ID)
Identify if the intrinsic is trivially scalarizable.
LLVM_ABI Intrinsic::ID getIntrinsicForCallSite(const CallBase &CB, const TargetLibraryInfo *TLI)
Map a call instruction to an intrinsic ID.
LLVM_ABI bool isVectorIntrinsicWithStructReturnOverloadAtField(Intrinsic::ID ID, int RetIdx, const TargetTransformInfo *TTI)
Identifies if the vector form of the intrinsic that returns a struct is overloaded at the struct elem...
LLVM_ABI void narrowShuffleMaskElts(int Scale, ArrayRef< int > Mask, SmallVectorImpl< int > &ScaledMask)
Replace each shuffle mask index with the scaled sequential indices for an equivalent mask of narrowed...
LLVM_ABI bool isMaskedSlidePair(ArrayRef< int > Mask, int NumElts, std::array< std::pair< int, int >, 2 > &SrcInfo)
Does this shuffle mask represent either one slide shuffle or a pair of two slide shuffles,...
LLVM_ABI VectorType * getDeinterleavedVectorType(IntrinsicInst *DI)
Given a deinterleaveN intrinsic, return the (narrow) vector type of each factor.
LLVM_ABI llvm::SmallVector< int, 16 > createInterleaveMask(unsigned VF, unsigned NumVecs)
Create an interleave shuffle mask.
LLVM_ABI std::optional< unsigned > getVectorMemoryIntrinsicPointerArgIdx(Intrinsic::ID ID)
Returns the argument index of the pointer parameter for the vector memory intrinsic ID,...
LLVM_ABI bool isVectorIntrinsicWithScalarOpAtArg(Intrinsic::ID ID, unsigned ScalarOpdIdx, const TargetTransformInfo *TTI)
Identifies if the vector form of the intrinsic has a scalar operand.
LLVM_ABI Value * findScalarElement(Value *V, unsigned EltNo)
Given a vector and an element number, see if the scalar value is already around as a register,...
unsigned M0(unsigned Val)
LLVM_ABI std::optional< unsigned > getVectorIntrinsicMaskArgIdx(Intrinsic::ID ID)
Returns the argument index of the mask for the vector intrinsic ID, or std::nullopt if the intrinsic ...
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI bool shouldSplitVectorSinCos(const TargetLibraryInfo &TLI, Type *ScalarTy, ElementCount EC, Module *M)
Returns true if the vector llvm.sincos with ScalarTy elements and EC element count has no vector libr...
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
LLVM_ABI void getShuffleMaskWithWidestElts(ArrayRef< int > Mask, SmallVectorImpl< int > &ScaledMask)
Repetitively apply widenShuffleMaskElts() for as long as it succeeds, to get the shuffle mask with wi...
Type * getLoadStoreType(const Value *I)
A helper function that returns the type of a load or store instruction.
LLVM_ABI void processShuffleMasks(ArrayRef< int > Mask, unsigned NumOfSrcRegs, unsigned NumOfDestRegs, unsigned NumOfUsedRegs, function_ref< void()> NoInputAction, function_ref< void(ArrayRef< int >, unsigned, unsigned)> SingleInputAction, function_ref< void(ArrayRef< int >, unsigned, unsigned, bool)> ManyInputsAction)
Splits and processes shuffle mask depending on the number of input and output registers.
bool all_equal(std::initializer_list< T > Values)
Returns true if all Values in the initializer lists are equal or the list.
LLVM_ABI bool maskContainsAllOneOrUndef(Value *Mask)
Given a mask vector of i1, Return true if any of the elements of this predicate mask are known to be ...
LLVM_ABI bool isTriviallyVectorizable(Intrinsic::ID ID)
Identify if the intrinsic is trivially vectorizable.
LLVM_ABI llvm::SmallVector< int, 16 > createSequentialMask(unsigned Start, unsigned NumInts, unsigned NumUndefs)
Create a sequential shuffle mask.
LLVM_ABI 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...
LLVM_ABI MapVector< Instruction *, uint64_t > computeMinimumValueSizes(ArrayRef< BasicBlock * > Blocks, DemandedBits &DB, const TargetTransformInfo *TTI=nullptr)
Compute a map of integer instructions to their minimum legal type size.
LLVM_ABI bool scaleShuffleMaskElts(unsigned NumDstElts, ArrayRef< int > Mask, SmallVectorImpl< int > &ScaledMask)
Attempt to narrow/widen the Mask shuffle mask to the NumDstElts target width.
LLVM_ABI int getSplatIndex(ArrayRef< int > Mask)
If all non-negative Mask elements are the same value, return that value.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.