71#define DEBUG_TYPE "mve-laneinterleave"
85 StringRef getPassName()
const override {
return "MVE lane interleaving"; }
96char MVELaneInterleaving::ID = 0;
102 return new MVELaneInterleaving();
119 for (
auto *
E : Exts) {
125 for (
auto *
T : Truncs) {
134 for (
auto *
E : Exts) {
135 if (!
E->hasOneUse() ||
136 (*
E->user_begin())->getOpcode() != Instruction::Mul) {
152 std::vector<Instruction *> Worklist;
153 Worklist.push_back(Start);
162 while (!Worklist.empty()) {
166 switch (
I->getOpcode()) {
168 case Instruction::Trunc:
169 case Instruction::FPTrunc:
176 case Instruction::SExt:
177 case Instruction::ZExt:
178 case Instruction::FPExt:
182 Worklist.push_back(
Use);
186 case Instruction::Call: {
191 if (
II->getIntrinsicID() == Intrinsic::vector_reduce_add) {
198 switch (
II->getIntrinsicID()) {
200 case Intrinsic::smin:
201 case Intrinsic::smax:
202 case Intrinsic::umin:
203 case Intrinsic::umax:
204 case Intrinsic::sadd_sat:
205 case Intrinsic::ssub_sat:
206 case Intrinsic::uadd_sat:
207 case Intrinsic::usub_sat:
208 case Intrinsic::minnum:
209 case Intrinsic::maxnum:
210 case Intrinsic::fabs:
212 case Intrinsic::ceil:
213 case Intrinsic::floor:
214 case Intrinsic::rint:
215 case Intrinsic::round:
216 case Intrinsic::trunc:
224 case Instruction::Add:
225 case Instruction::Sub:
226 case Instruction::Mul:
227 case Instruction::AShr:
228 case Instruction::LShr:
229 case Instruction::Shl:
230 case Instruction::ICmp:
231 case Instruction::FCmp:
232 case Instruction::FAdd:
233 case Instruction::FMul:
234 case Instruction::Select:
238 for (
Use &
Op :
I->operands()) {
248 Worklist.push_back(
Use);
251 case Instruction::ShuffleVector:
267 dbgs() <<
"Found group:\n Exts:\n";
269 dbgs() <<
" " << *
I <<
"\n";
272 dbgs() <<
" " << *
I <<
"\n";
273 dbgs() <<
" OtherLeafs:\n";
274 for (
auto *
I : OtherLeafs)
275 dbgs() <<
" " << *
I->get() <<
" of " << *
I->getUser() <<
"\n";
276 dbgs() <<
" Truncs:\n";
277 for (
auto *
I : Truncs)
278 dbgs() <<
" " << *
I <<
"\n";
279 dbgs() <<
" Reducts:\n";
280 for (
auto *
I : Reducts)
281 dbgs() <<
" " << *
I <<
"\n";
285 "Expected some truncs or reductions");
289 auto *VT = !Truncs.
empty()
295 unsigned NumElts = VT->getNumElements();
296 unsigned BaseElts = VT->getScalarSizeInBits() == 16
298 : (VT->getScalarSizeInBits() == 8 ? 16 : 0);
299 if (BaseElts == 0 || NumElts % BaseElts != 0) {
303 if (Start->getOperand(0)->getType()->getScalarSizeInBits() !=
304 VT->getScalarSizeInBits() * 2) {
309 if (
I->getOperand(0)->getType() != VT) {
314 if (
I->getType() != VT) {
323 return I->getOpcode() == Instruction::Mul ||
324 I->getOpcode() == Instruction::Select ||
325 I->getOpcode() == Instruction::ICmp;
338 for (
unsigned Base = 0;
Base < NumElts;
Base += BaseElts) {
339 for (
unsigned i = 0; i < BaseElts / 2; i++)
341 for (
unsigned i = 0; i < BaseElts / 2; i++)
344 for (
unsigned Base = 0;
Base < NumElts;
Base += BaseElts) {
345 for (
unsigned i = 0; i < BaseElts / 2; i++) {
353 Builder.SetInsertPoint(
I);
354 Value *Shuffle = Builder.CreateShuffleVector(
I->getOperand(0), LeafMask);
357 Value *Ext = FPext ? Builder.CreateFPExt(Shuffle,
I->getType())
358 : Sext ? Builder.CreateSExt(Shuffle,
I->getType())
359 : Builder.CreateZExt(Shuffle,
I->getType());
360 I->replaceAllUsesWith(Ext);
364 for (
Use *
I : OtherLeafs) {
367 Value *Shuffle = Builder.CreateShuffleVector(
I->get(), LeafMask);
368 I->getUser()->setOperand(
I->getOperandNo(), Shuffle);
375 Builder.SetInsertPoint(++
I->getIterator());
376 Value *Shuf = Builder.CreateShuffleVector(
I, TruncMask);
377 I->replaceAllUsesWith(Shuf);
390 return II->getIntrinsicID() == Intrinsic::vector_reduce_add;
394bool MVELaneInterleaving::runOnFunction(
Function &
F) {
395 auto &TPC = getAnalysis<TargetPassConfig>();
396 auto &TM = TPC.getTM<TargetMachine>();
397 auto *
ST = &TM.getSubtarget<ARMSubtarget>(
F);
398 if (!
ST->getCLOpts().mve_interleave || !
ST->hasMVEIntegerOps())
403 SmallPtrSet<Instruction *, 16> Visited;
405 if (((
I.getType()->isVectorTy() &&
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Expand Atomic instructions
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool runOnFunction(Function &F, bool PostInlining)
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static bool isProfitableToInterleave(SmallSetVector< Instruction *, 4 > &Exts, SmallSetVector< Instruction *, 4 > &Truncs)
static bool tryInterleave(Instruction *Start, SmallPtrSetImpl< Instruction * > &Visited)
static bool isAddReduction(Instruction &I)
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file implements a set that has insertion order iteration characteristics.
static SymbolRef::Type getType(const Symbol *Sym)
This file describes how to lower LLVM code to machine code.
Target-Independent Code Generator Pass Configuration Options pass.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
FunctionPass class - This class is used to implement most global optimizations.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
A wrapper class for inspecting calls to intrinsic functions.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Pass interface - Implemented by all 'passes'.
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
size_type count(const_arg_type key) const
Count the number of elements of a given key in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
A SetVector that performs no allocations if smaller than a certain size.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Target-Independent Code Generator Pass Configuration Options.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
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.
Pass * createMVELaneInterleavingPass()
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
void initializeMVELaneInterleavingPass(PassRegistry &)
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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...
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.