-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[RISCV] Allow folding vmerge into masked ops when mask is the same #97989
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 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3523,24 +3523,26 @@ bool RISCVDAGToDAGISel::doPeepholeSExtW(SDNode *N) { | |
return false; | ||
} | ||
|
||
static bool usesAllOnesMask(SDValue MaskOp, SDValue GlueOp) { | ||
// After ISel, a vector pseudo's mask will be copied to V0, and the CopyToReg | ||
// will be glued to the pseudo. This tries to up the value that was copied to | ||
// V0. | ||
static SDValue getMaskSetter(SDValue MaskOp, SDValue GlueOp) { | ||
// Check that we're using V0 as a mask register. | ||
if (!isa<RegisterSDNode>(MaskOp) || | ||
cast<RegisterSDNode>(MaskOp)->getReg() != RISCV::V0) | ||
return false; | ||
return SDValue(); | ||
|
||
// The glued user defines V0. | ||
const auto *Glued = GlueOp.getNode(); | ||
|
||
if (!Glued || Glued->getOpcode() != ISD::CopyToReg) | ||
return false; | ||
return SDValue(); | ||
|
||
// Check that we're defining V0 as a mask register. | ||
if (!isa<RegisterSDNode>(Glued->getOperand(1)) || | ||
cast<RegisterSDNode>(Glued->getOperand(1))->getReg() != RISCV::V0) | ||
return false; | ||
return SDValue(); | ||
|
||
// Check the instruction defining V0; it needs to be a VMSET pseudo. | ||
SDValue MaskSetter = Glued->getOperand(2); | ||
|
||
// Sometimes the VMSET is wrapped in a COPY_TO_REGCLASS, e.g. if the mask came | ||
|
@@ -3549,6 +3551,15 @@ static bool usesAllOnesMask(SDValue MaskOp, SDValue GlueOp) { | |
MaskSetter->getMachineOpcode() == RISCV::COPY_TO_REGCLASS) | ||
MaskSetter = MaskSetter->getOperand(0); | ||
|
||
return MaskSetter; | ||
} | ||
|
||
static bool usesAllOnesMask(SDValue MaskOp, SDValue GlueOp) { | ||
// Check the instruction defining V0; it needs to be a VMSET pseudo. | ||
SDValue MaskSetter = getMaskSetter(MaskOp, GlueOp); | ||
if (!MaskSetter) | ||
return false; | ||
|
||
const auto IsVMSet = [](unsigned Opc) { | ||
return Opc == RISCV::PseudoVMSET_M_B1 || Opc == RISCV::PseudoVMSET_M_B16 || | ||
Opc == RISCV::PseudoVMSET_M_B2 || Opc == RISCV::PseudoVMSET_M_B32 || | ||
|
@@ -3755,12 +3766,16 @@ bool RISCVDAGToDAGISel::performCombineVMergeAndVOps(SDNode *N) { | |
return false; | ||
} | ||
|
||
// If True is masked then the vmerge must have an all 1s mask, since we're | ||
// going to keep the mask from True. | ||
// If True is masked then the vmerge must have either the same mask or an all | ||
// 1s mask, since we're going to keep the mask from True. | ||
if (IsMasked && Mask) { | ||
// FIXME: Support mask agnostic True instruction which would have an | ||
// undef merge operand. | ||
if (!usesAllOnesMask(Mask, Glue)) | ||
SDValue TrueMask = | ||
getMaskSetter(True->getOperand(Info->MaskOpIdx), | ||
True->getOperand(True->getNumOperands() - 1)); | ||
Comment on lines
+3774
to
+3776
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 is a bit gnarly but I still hope to eventually move all this into RISCVFoldMasks.cpp #71764. Sorry for dropping the ball on that |
||
assert(TrueMask); | ||
if (!usesAllOnesMask(Mask, Glue) && getMaskSetter(Mask, Glue) != TrueMask) | ||
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.
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.