14#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64PERFECTSHUFFLE_H
15#define LLVM_LIB_TARGET_AARCH64_AARCH64PERFECTSHUFFLE_H
25 assert(M.size() == 4 &&
"Expected a 4 entry perfect shuffle");
29 return E.value() < 0 ||
E.value() == (int)
E.index();
33 return E.value() < 0 ||
E.value() == (int)
E.index() + 4;
39 unsigned PFIndexes[4];
40 for (
unsigned i = 0; i != 4; ++i) {
41 assert(M[i] < 8 &&
"Expected a maximum entry of 8 for shuffle mask");
49 unsigned PFTableIndex = PFIndexes[0] * 9 * 9 * 9 + PFIndexes[1] * 9 * 9 +
50 PFIndexes[2] * 9 + PFIndexes[3];
53 return (PFEntry >> 30) + 1;
62 unsigned &WhichResultOut,
unsigned &OperandOrderOut) {
69 bool Result0Order0 =
true;
70 bool Result1Order0 =
true;
71 bool Result0Order1 =
true;
72 bool Result1Order1 =
true;
74 for (
unsigned i = 0; i != NumElts; i += 2) {
78 Result0Order0 =
false;
79 if (EvenElt != NumElts / 2 + i / 2)
80 Result1Order0 =
false;
81 if (EvenElt != NumElts + i / 2)
82 Result0Order1 =
false;
83 if (EvenElt != NumElts + NumElts / 2 + i / 2)
84 Result1Order1 =
false;
87 unsigned OddElt = (
unsigned)M[i + 1];
88 if (OddElt != NumElts + i / 2)
89 Result0Order0 =
false;
90 if (OddElt != NumElts + NumElts / 2 + i / 2)
91 Result1Order0 =
false;
93 Result0Order1 =
false;
94 if (OddElt != NumElts / 2 + i / 2)
95 Result1Order1 =
false;
99 if (Result0Order0 + Result1Order0 + Result0Order1 + Result1Order1 != 1)
102 WhichResultOut = (Result0Order0 || Result0Order1) ? 0 : 1;
103 OperandOrderOut = (Result0Order0 || Result1Order0) ? 0 : 1;
111 unsigned &WhichResultOut) {
113 unsigned WhichResult = 2;
114 for (
unsigned i = 0; i != NumElts; i++) {
116 WhichResult = ((
unsigned)M[i] == i * 2 ? 0 : 1);
120 if (WhichResult == 2)
124 for (
unsigned i = 0; i != NumElts; ++i) {
127 if ((
unsigned)M[i] != 2 * i + WhichResult)
130 WhichResultOut = WhichResult;
140 unsigned &WhichResultOut,
unsigned &OperandOrderOut) {
141 if (NumElts % 2 != 0)
147 bool Result0Order0 =
true;
148 bool Result1Order0 =
true;
149 bool Result0Order1 =
true;
150 bool Result1Order1 =
true;
152 for (
unsigned i = 0; i != NumElts; i += 2) {
156 Result0Order0 =
false;
157 if (EvenElt != i + 1)
158 Result1Order0 =
false;
159 if (EvenElt != NumElts + i)
160 Result0Order1 =
false;
161 if (EvenElt != NumElts + i + 1)
162 Result1Order1 =
false;
165 unsigned OddElt = (
unsigned)M[i + 1];
166 if (OddElt != NumElts + i)
167 Result0Order0 =
false;
168 if (OddElt != NumElts + i + 1)
169 Result1Order0 =
false;
171 Result0Order1 =
false;
173 Result1Order1 =
false;
177 if (Result0Order0 + Result1Order0 + Result0Order1 + Result1Order1 != 1)
180 WhichResultOut = (Result0Order0 || Result0Order1) ? 0 : 1;
181 OperandOrderOut = (Result0Order0 || Result1Order0) ? 0 : 1;
192 "Only possible block sizes for REV are: 16, 32, 64, 128");
194 unsigned BlockElts = M[0] + 1;
202 for (
unsigned i = 0; i < NumElts; ++i) {
205 if ((
unsigned)M[i] != (i - i % BlockElts) + (BlockElts - 1 - i % BlockElts))
215 unsigned SegmentSize) {
219 if (SegmentSize * Segments != Mask.size())
223 if (Lane >= SegmentSize)
229 const unsigned SegmentIndex =
P.index() / SegmentSize;
230 return P.value() < 0 ||
231 unsigned(
P.value()) == Lane + SegmentIndex * SegmentSize;
240 unsigned SegmentSize) {
242 if (SegmentSize * Segments != Mask.size())
248 const unsigned IndexWithinSegment =
P.index() % SegmentSize;
249 return P.value() < 0 ||
unsigned(
P.value()) == IndexWithinSegment;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static const int BlockSize
Represent a constant reference to an array (0 or more elements consecutively in memory),...
This is an optimization pass for GlobalISel generic memory operations.
std::optional< unsigned > isDUPQMask(ArrayRef< int > Mask, unsigned Segments, unsigned SegmentSize)
isDUPQMask - matches a splat of equivalent lanes within segments of a given number of elements.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
bool isZIPMask(ArrayRef< int > M, unsigned NumElts, unsigned &WhichResultOut, unsigned &OperandOrderOut)
Return true for zip1 or zip2 masks of the form: <0, 8, 1, 9, 2, 10, 3, 11> (WhichResultOut = 0,...
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
bool isDUPFirstSegmentMask(ArrayRef< int > Mask, unsigned Segments, unsigned SegmentSize)
isDUPFirstSegmentMask - matches a splat of the first 128b segment.
unsigned getPerfectShuffleCost(llvm::ArrayRef< int > M)
bool isUZPMask(ArrayRef< int > M, unsigned NumElts, unsigned &WhichResultOut)
Return true for uzp1 or uzp2 masks of the form: <0, 2, 4, 6, 8, 10, 12, 14> or <1,...
bool isREVMask(ArrayRef< int > M, unsigned EltSize, unsigned NumElts, unsigned BlockSize)
isREVMask - Check if a vector shuffle corresponds to a REV instruction with the specified blocksize.
const unsigned PerfectShuffleTable[6561+1]
bool isTRNMask(ArrayRef< int > M, unsigned NumElts, unsigned &WhichResultOut, unsigned &OperandOrderOut)
Return true for trn1 or trn2 masks of the form: <0, 8, 2, 10, 4, 12, 6, 14> (WhichResultOut = 0,...