74 #define DEBUG_TYPE "interleaved-access" 77 "lower-interleaved-accesses",
78 cl::desc(
"Enable lowering interleaved accesses to intrinsics"),
91 StringRef getPassName()
const override {
return "Interleaved Access Pass"; }
108 bool lowerInterleavedLoad(
LoadInst *LI,
128 "Lower interleaved memory accesses to target specific intrinsics",
false,
136 return new InterleavedAccess();
145 for (Index = 0; Index < Factor; Index++) {
150 for (; i < Mask.
size(); i++)
151 if (Mask[i] >= 0 && static_cast<unsigned>(Mask[i]) != Index + i * Factor)
154 if (i == Mask.
size())
167 unsigned &
Index,
unsigned MaxFactor,
168 unsigned NumLoadElements) {
173 for (Factor = 2; Factor <= MaxFactor; Factor++) {
175 if (Mask.
size() * Factor > NumLoadElements)
196 unsigned MaxFactor,
unsigned OpNumElts) {
197 unsigned NumElts = Mask.
size();
202 for (Factor = 2; Factor <= MaxFactor; Factor++) {
203 if (NumElts % Factor)
206 unsigned LaneLen = NumElts / Factor;
214 for (; I < Factor; I++) {
215 unsigned SavedLaneValue;
216 unsigned SavedNoUndefs = 0;
219 for (J = 0; J < LaneLen - 1; J++) {
221 unsigned Lane = J * Factor +
I;
222 unsigned NextLane = Lane + Factor;
223 int LaneValue = Mask[Lane];
224 int NextLaneValue = Mask[NextLane];
227 if (LaneValue >= 0 && NextLaneValue >= 0 &&
228 LaneValue + 1 != NextLaneValue)
232 if (LaneValue >= 0 && NextLaneValue < 0) {
233 SavedLaneValue = LaneValue;
242 if (SavedNoUndefs > 0 && LaneValue < 0) {
244 if (NextLaneValue >= 0 &&
245 SavedLaneValue + SavedNoUndefs != (
unsigned)NextLaneValue)
257 }
else if (Mask[(LaneLen - 1) * Factor + I] >= 0) {
259 StartMask = Mask[(LaneLen - 1) * Factor + I] - J;
260 }
else if (SavedNoUndefs > 0) {
262 StartMask = SavedLaneValue - (LaneLen - 1 - SavedNoUndefs);
269 if (StartMask + LaneLen > OpNumElts*2)
281 bool InterleavedAccess::lowerInterleavedLoad(
295 if (Extract && isa<ConstantInt>(Extract->getIndexOperand())) {
300 if (!SVI || !isa<UndefValue>(SVI->
getOperand(1)))
306 if (Shuffles.
empty())
309 unsigned Factor,
Index;
314 MaxFactor, NumLoadElements))
321 Type *VecTy = Shuffles[0]->getType();
325 for (
unsigned i = 1; i < Shuffles.
size(); i++) {
326 if (Shuffles[i]->
getType() != VecTy)
338 if (!tryReplaceExtracts(Extracts, Shuffles))
341 LLVM_DEBUG(
dbgs() <<
"IA: Found an interleaved load: " << *LI <<
"\n");
344 if (!TLI->lowerInterleavedLoad(LI, Shuffles, Indices, Factor))
347 for (
auto SVI : Shuffles)
354 bool InterleavedAccess::tryReplaceExtracts(
359 if (Extracts.
empty())
366 for (
auto *Extract : Extracts) {
368 auto *IndexOperand = cast<ConstantInt>(Extract->getIndexOperand());
369 auto Index = IndexOperand->getSExtValue();
374 for (
auto *Shuffle : Shuffles) {
377 if (!DT->dominates(Shuffle, Extract))
384 Shuffle->getShuffleMask(Indices);
385 for (
unsigned I = 0;
I < Indices.
size(); ++
I)
386 if (Indices[
I] == Index) {
387 assert(Extract->getOperand(0) == Shuffle->getOperand(0) &&
388 "Vector operations do not match");
389 ReplacementMap[Extract] = std::make_pair(Shuffle,
I);
394 if (ReplacementMap.
count(Extract))
400 if (!ReplacementMap.
count(Extract))
406 for (
auto &Replacement : ReplacementMap) {
407 auto *Extract = Replacement.first;
408 auto *
Vector = Replacement.second.first;
409 auto Index = Replacement.second.second;
412 Extract->eraseFromParent();
418 bool InterleavedAccess::lowerInterleavedStore(
433 LLVM_DEBUG(
dbgs() <<
"IA: Found an interleaved store: " << *SI <<
"\n");
436 if (!TLI->lowerInterleavedStore(SI, SVI, Factor))
446 auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
452 DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
454 TLI =
TM.getSubtargetImpl(F)->getTargetLowering();
455 MaxFactor = TLI->getMaxSupportedInterleaveFactor();
459 bool Changed =
false;
462 if (
LoadInst *LI = dyn_cast<LoadInst>(&
I))
463 Changed |= lowerInterleavedLoad(LI, DeadInsts);
466 Changed |= lowerInterleavedStore(SI, DeadInsts);
469 for (
auto I : DeadInsts)
470 I->eraseFromParent();
Value * getValueOperand()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
INITIALIZE_PASS_BEGIN(InterleavedAccess, DEBUG_TYPE, "Lower interleaved memory accesses to target specific intrinsics", false, false) INITIALIZE_PASS_END(InterleavedAccess
void push_back(const T &Elt)
static cl::opt< bool > LowerInterleavedAccesses("lower-interleaved-accesses", cl::desc("Enable lowering interleaved accesses to intrinsics"), cl::init(true), cl::Hidden)
This instruction constructs a fixed permutation of two input vectors.
An instruction for reading from memory.
static bool isDeInterleaveMask(ArrayRef< int > Mask, unsigned &Factor, unsigned &Index, unsigned MaxFactor, unsigned NumLoadElements)
Check if the mask is a DE-interleave mask for an interleaved load.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Type * getType() const
All values are typed, get the type of this value.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
An instruction for storing to memory.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
static bool isReInterleaveMask(ArrayRef< int > Mask, unsigned &Factor, unsigned MaxFactor, unsigned OpNumElts)
Check if the mask can be used in an interleaved store.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
Value * getOperand(unsigned i) const
static bool runOnFunction(Function &F, bool PostInlining)
initializer< Ty > init(const Ty &Val)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
The instances of the Type class are immutable: once they are created, they are never changed...
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
FunctionPass * createInterleavedAccessPass()
InterleavedAccess Pass - This pass identifies and matches interleaved memory accesses to target speci...
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
static wasm::ValType getType(const TargetRegisterClass *RC)
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
void initializeInterleavedAccessPass(PassRegistry &)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static void getShuffleMask(const Constant *Mask, SmallVectorImpl< int > &Result)
Convert the input shuffle mask operand to a vector of integers.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned getVectorNumElements() const
Lower interleaved memory accesses to target specific intrinsics
LLVM_NODISCARD bool empty() const
StringRef getName() const
Return a constant reference to the value's name.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
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.
Primary interface to the complete machine description for the target machine.
bool hasOneUse() const
Return true if there is exactly one user of this value.
StringRef - Represent a constant reference to a string, i.e.
inst_range instructions(Function *F)
Legacy analysis pass which computes a DominatorTree.
static bool isDeInterleaveMaskOfFactor(ArrayRef< int > Mask, unsigned Factor, unsigned &Index)
Check if the mask is a DE-interleave mask of the given factor Factor like: <Index, Index+Factor, ..., Index+(NumElts-1)*Factor>
bool empty() const
empty - Check if the array is empty.
This file describes how to lower LLVM code to machine code.