-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[AMDGPU] Allow sinking of free vector ops #162580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1301,6 +1301,90 @@ bool GCNTTIImpl::isProfitableToSinkOperands(Instruction *I, | |
|
||
if (match(&Op, m_FAbs(m_Value())) || match(&Op, m_FNeg(m_Value()))) | ||
Ops.push_back(&Op); | ||
|
||
// Zero cost vector instructions (e.g. extractelement 0 of i32 vectors) | ||
// will be optimized away, and sinking them can help SDAG combines. | ||
DataLayout DL = I->getModule()->getDataLayout(); | ||
auto IsFreeExtractInsert = [&DL, this](VectorType *VecType, | ||
unsigned VecIndex) { | ||
unsigned EltSize = DL.getTypeSizeInBits(VecType->getElementType()); | ||
return EltSize >= 32 || | ||
(EltSize == 16 && VecIndex == 0 && ST->has16BitInsts()); | ||
}; | ||
Comment on lines
+1308
to
+1313
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The TTI costs for the vector ops should already be reporting free, shouldn't need to reimplement this |
||
|
||
uint64_t VecIndex; | ||
Value *Vec; | ||
if (match(Op.get(), m_ExtractElt(m_Value(Vec), m_ConstantInt(VecIndex)))) { | ||
Instruction *VecOpInst = | ||
dyn_cast<Instruction>(cast<Instruction>(Op.get())->getOperand(0)); | ||
// If a zero cost extractvector instruction is the only use of the vector, | ||
// then it may be combined with the def. | ||
if (VecOpInst && VecOpInst->hasOneUse()) | ||
continue; | ||
|
||
if (IsFreeExtractInsert(cast<VectorType>(Vec->getType()), VecIndex)) | ||
Ops.push_back(&Op); | ||
|
||
continue; | ||
} | ||
|
||
if (match(Op.get(), | ||
m_InsertElt(m_Value(Vec), m_Value(), m_ConstantInt(VecIndex)))) { | ||
if (IsFreeExtractInsert(cast<VectorType>(Vec->getType()), VecIndex)) | ||
Ops.push_back(&Op); | ||
|
||
continue; | ||
} | ||
|
||
if (auto *Shuffle = dyn_cast<ShuffleVectorInst>(Op.get())) { | ||
if (Shuffle->isIdentity()) { | ||
Ops.push_back(&Op); | ||
continue; | ||
} | ||
|
||
unsigned EltSize = DL.getTypeSizeInBits( | ||
cast<VectorType>(cast<VectorType>(Shuffle->getType())) | ||
->getElementType()); | ||
|
||
// For i32 (or greater) shufflevectors, these will be lowered into a | ||
// series of insert / extract elements, which will be coalesced away. | ||
if (EltSize >= 32) { | ||
Ops.push_back(&Op); | ||
continue; | ||
} | ||
|
||
if (EltSize < 16 || !ST->has16BitInsts()) | ||
continue; | ||
|
||
int NumSubElts, SubIndex; | ||
if (Shuffle->changesLength()) { | ||
if (Shuffle->increasesLength() && Shuffle->isIdentityWithPadding()) { | ||
Ops.push_back(&Op); | ||
continue; | ||
} | ||
|
||
if (Shuffle->isExtractSubvectorMask(SubIndex) || | ||
Shuffle->isInsertSubvectorMask(NumSubElts, SubIndex)) { | ||
if (!(SubIndex % 2)) { | ||
Ops.push_back(&Op); | ||
continue; | ||
Comment on lines
+1366
to
+1370
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these can be combined |
||
} | ||
} | ||
} | ||
|
||
if (Shuffle->isReverse() || Shuffle->isZeroEltSplat() || | ||
Shuffle->isSingleSource()) { | ||
Ops.push_back(&Op); | ||
continue; | ||
} | ||
|
||
if (Shuffle->isInsertSubvectorMask(NumSubElts, SubIndex)) { | ||
if (!(SubIndex % 2)) { | ||
Comment on lines
+1381
to
+1382
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be combined |
||
Ops.push_back(&Op); | ||
continue; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return !Ops.empty(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never copy a DataLayout