32 class X86InterleavedAccessGroup {
44 const unsigned Factor;
86 : Inst(I), Shuffles(Shuffs), Indices(Ind), Factor(F), Subtarget(STarget),
87 DL(Inst->getModule()->getDataLayout()), Builder(B) {}
91 bool isSupported()
const;
95 bool lowerIntoOptimizedSequence();
99 bool X86InterleavedAccessGroup::isSupported()
const {
100 VectorType *ShuffleVecTy = Shuffles[0]->getType();
105 uint64_t ExpectedShuffleVecSize;
106 if (isa<LoadInst>(Inst))
107 ExpectedShuffleVecSize = 256;
109 ExpectedShuffleVecSize = 1024;
111 if (!Subtarget.hasAVX() || ShuffleVecSize != ExpectedShuffleVecSize ||
118 void X86InterleavedAccessGroup::decompose(
122 assert((isa<LoadInst>(VecInst) || isa<ShuffleVectorInst>(VecInst)) &&
123 "Expected Load or Shuffle");
130 "Invalid Inst-size!!!");
132 if (
auto *SVI = dyn_cast<ShuffleVectorInst>(VecInst)) {
133 Value *Op0 = SVI->getOperand(0);
134 Value *Op1 = SVI->getOperand(1);
137 for (
unsigned i = 0; i < NumSubVectors; ++i)
139 cast<ShuffleVectorInst>(Builder.CreateShuffleVector(
146 LoadInst *LI = cast<LoadInst>(VecInst);
152 for (
unsigned i = 0; i < NumSubVectors; i++) {
154 Value *NewBasePtr = Builder.CreateGEP(VecBasePtr, Builder.getInt32(i));
156 Builder.CreateAlignedLoad(NewBasePtr, LI->
getAlignment());
161 void X86InterleavedAccessGroup::transpose_4x4(
164 assert(Matrix.
size() == 4 &&
"Invalid matrix size");
165 TransposedMatrix.
resize(4);
170 Value *IntrVec1 = Builder.CreateShuffleVector(Matrix[0], Matrix[2], Mask);
171 Value *IntrVec2 = Builder.CreateShuffleVector(Matrix[1], Matrix[3], Mask);
176 Value *IntrVec3 = Builder.CreateShuffleVector(Matrix[0], Matrix[2], Mask);
177 Value *IntrVec4 = Builder.CreateShuffleVector(Matrix[1], Matrix[3], Mask);
182 TransposedMatrix[0] = Builder.CreateShuffleVector(IntrVec1, IntrVec2, Mask);
183 TransposedMatrix[2] = Builder.CreateShuffleVector(IntrVec3, IntrVec4, Mask);
188 TransposedMatrix[1] = Builder.CreateShuffleVector(IntrVec1, IntrVec2, Mask);
189 TransposedMatrix[3] = Builder.CreateShuffleVector(IntrVec3, IntrVec4, Mask);
194 bool X86InterleavedAccessGroup::lowerIntoOptimizedSequence() {
197 VectorType *ShuffleTy = Shuffles[0]->getType();
199 if (isa<LoadInst>(Inst)) {
201 decompose(Inst, Factor, ShuffleTy, DecomposedVectors);
206 transpose_4x4(DecomposedVectors, TransposedVectors);
210 for (
unsigned i = 0, e = Shuffles.size(); i < e; ++i)
211 Shuffles[i]->replaceAllUsesWith(TransposedVectors[Indices[i]]);
222 decompose(Shuffles[0], Factor,
227 transpose_4x4(DecomposedVectors, TransposedVectors);
248 "Invalid interleave factor");
249 assert(!Shuffles.
empty() &&
"Empty shufflevector input");
251 "Unmatched number of shufflevectors and indices");
255 X86InterleavedAccessGroup Grp(LI, Shuffles, Indices, Factor, Subtarget,
258 return Grp.isSupported() && Grp.lowerIntoOptimizedSequence();
263 unsigned Factor)
const {
265 "Invalid interleave factor");
268 "Invalid interleaved store");
274 for (
unsigned i = 0; i < Factor; i++)
275 Indices.push_back(Mask[i]);
281 X86InterleavedAccessGroup Grp(SI, Shuffles, Indices, Factor, Subtarget,
284 return Grp.isSupported() && Grp.lowerIntoOptimizedSequence();
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
This instruction constructs a fixed permutation of two input vectors.
An instruction for reading from memory.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Type * getVectorElementType() const
Constant * createSequentialMask(IRBuilder<> &Builder, unsigned Start, unsigned NumInts, unsigned NumUndefs)
Create a sequential shuffle mask.
Value * concatenateVectors(IRBuilder<> &Builder, ArrayRef< Value * > Vecs)
Concatenate a list of vectors.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
An instruction for storing to memory.
size_t size() const
size - Get the array size.
unsigned getAlignment() const
Return the alignment of the access that is being performed.
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.
Value * getPointerOperand()
bool empty() const
empty - Check if the array is empty.
bool lowerInterleavedLoad(LoadInst *LI, ArrayRef< ShuffleVectorInst * > Shuffles, ArrayRef< unsigned > Indices, unsigned Factor) const override
Lower interleaved load(s) into target specific instructions/intrinsics.
bool lowerInterleavedStore(StoreInst *SI, ShuffleVectorInst *SVI, unsigned Factor) const override
Lower interleaved store(s) into target specific instructions/intrinsics.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
unsigned getMaxSupportedInterleaveFactor() const override
Get the maximum supported factor for interleaved memory accesses.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Class to represent vector types.
unsigned getVectorNumElements() const
unsigned getAlignment() const
Return the alignment of the access that is being performed.
VectorType * getType() const
Overload to return most specific vector type.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
static void getShuffleMask(Constant *Mask, SmallVectorImpl< int > &Result)
Convert the input shuffle mask operand to a vector of integers.
Value * getPointerOperand()