-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[GlobalISel] Combine G_UNMERGE_VALUES with anyext and build vector #112370
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7e58c4f
[GlobalISel] Combine G_UNMERGE_VALUES with anyext and build vector
tschuett 0c79139
fix riscv test
tschuett d13650d
address review comments
tschuett 758226e
address review comments II
tschuett e312b4e
fix docstring
tschuett 3195635
small fix
tschuett 944f801
small fix II
tschuett afdec48
small fix III
tschuett b81f009
fix test
tschuett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7611,3 +7611,85 @@ bool CombinerHelper::matchFoldAMinusC1PlusC2(const MachineInstr &MI, | |
|
||
return true; | ||
} | ||
|
||
bool CombinerHelper::matchUnmergeValuesAnyExtBuildVector(const MachineInstr &MI, | ||
BuildFnTy &MatchInfo) { | ||
const GUnmerge *Unmerge = cast<GUnmerge>(&MI); | ||
|
||
if (!MRI.hasOneNonDBGUse(Unmerge->getSourceReg())) | ||
return false; | ||
|
||
const MachineInstr *Source = MRI.getVRegDef(Unmerge->getSourceReg()); | ||
|
||
LLT DstTy = MRI.getType(Unmerge->getReg(0)); | ||
|
||
// $bv:_(<8 x s8>) = G_BUILD_VECTOR .... | ||
// $any:_(<8 x s16>) = G_ANYEXT $bv | ||
// $uv:_(<4 x s16>), $uv1:_(<4 x s16>) = G_UNMERGE_VALUES $any | ||
// | ||
// -> | ||
// | ||
// $any:_(s16) = G_ANYEXT $bv[0] | ||
// $any1:_(s16) = G_ANYEXT $bv[1] | ||
// $any2:_(s16) = G_ANYEXT $bv[2] | ||
// $any3:_(s16) = G_ANYEXT $bv[3] | ||
// $any4:_(s16) = G_ANYEXT $bv[4] | ||
// $any5:_(s16) = G_ANYEXT $bv[5] | ||
// $any6:_(s16) = G_ANYEXT $bv[6] | ||
// $any7:_(s16) = G_ANYEXT $bv[7] | ||
// $uv:_(<4 x s16>) = G_BUILD_VECTOR $any, $any1, $any2, $any3 | ||
// $uv1:_(<4 x s16>) = G_BUILD_VECTOR $any4, $any5, $any6, $any7 | ||
|
||
// We want to unmerge into vectors. | ||
if (!DstTy.isFixedVector()) | ||
return false; | ||
|
||
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. DAG style comment for the pattern? 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. Is the doc sufficient? |
||
const GAnyExt *Any = dyn_cast<GAnyExt>(Source); | ||
if (!Any) | ||
return false; | ||
|
||
const MachineInstr *NextSource = MRI.getVRegDef(Any->getSrcReg()); | ||
|
||
if (const GBuildVector *BV = dyn_cast<GBuildVector>(NextSource)) { | ||
// G_UNMERGE_VALUES G_ANYEXT G_BUILD_VECTOR | ||
|
||
if (!MRI.hasOneNonDBGUse(BV->getReg(0))) | ||
return false; | ||
|
||
// FIXME: check element types? | ||
if (BV->getNumSources() % Unmerge->getNumDefs() != 0) | ||
return false; | ||
|
||
LLT BigBvTy = MRI.getType(BV->getReg(0)); | ||
LLT SmallBvTy = DstTy; | ||
LLT SmallBvElemenTy = SmallBvTy.getElementType(); | ||
|
||
if (!isLegalOrBeforeLegalizer( | ||
{TargetOpcode::G_BUILD_VECTOR, {SmallBvTy, SmallBvElemenTy}})) | ||
return false; | ||
|
||
// We check the legality of scalar anyext. | ||
if (!isLegalOrBeforeLegalizer( | ||
{TargetOpcode::G_ANYEXT, | ||
{SmallBvElemenTy, BigBvTy.getElementType()}})) | ||
return false; | ||
|
||
MatchInfo = [=](MachineIRBuilder &B) { | ||
// Build into each G_UNMERGE_VALUES def | ||
// a small build vector with anyext from the source build vector. | ||
for (unsigned I = 0; I < Unmerge->getNumDefs(); ++I) { | ||
SmallVector<Register> Ops; | ||
for (unsigned J = 0; J < SmallBvTy.getNumElements(); ++J) { | ||
Register SourceArray = | ||
BV->getSourceReg(I * SmallBvTy.getNumElements() + J); | ||
auto AnyExt = B.buildAnyExt(SmallBvElemenTy, SourceArray); | ||
Ops.push_back(AnyExt.getReg(0)); | ||
} | ||
B.buildBuildVector(Unmerge->getOperand(I).getReg(), Ops); | ||
}; | ||
}; | ||
return true; | ||
}; | ||
|
||
return false; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.