-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[RISCV] Update performCombineVMergeAndVOps comments. NFC #78472
[RISCV] Update performCombineVMergeAndVOps comments. NFC #78472
Conversation
The current comment was written whenever we had separate TU/TA variants for each pseudo, and hasn't been accurate for a while. This method has grown rather complicated over time so rather than enumerate all the different possible cases now (which must be a lot), this updates the comment to list the different rules that are required for us to be able to fold a vmerge.
@llvm/pr-subscribers-backend-risc-v Author: Luke Lau (lukel97) ChangesThe current comment was written whenever we had separate TU/TA variants for Full diff: https://github.com/llvm/llvm-project/pull/78472.diff 1 Files Affected:
diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
index 0d8688ba2eaeaf..4d6f74bc0285cb 100644
--- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
@@ -3458,19 +3458,27 @@ static unsigned GetVMSetForLMul(RISCVII::VLMUL LMUL) {
llvm_unreachable("Unknown VLMUL enum");
}
-// Try to fold away VMERGE_VVM instructions. We handle these cases:
-// -Masked TU VMERGE_VVM combined with an unmasked TA instruction instruction
-// folds to a masked TU instruction. VMERGE_VVM must have have merge operand
-// same as false operand.
-// -Masked TA VMERGE_VVM combined with an unmasked TA instruction fold to a
-// masked TA instruction.
-// -Unmasked TU VMERGE_VVM combined with a masked MU TA instruction folds to
-// masked TU instruction. Both instructions must have the same merge operand.
-// VMERGE_VVM must have have merge operand same as false operand.
-// Note: The VMERGE_VVM forms above (TA, and TU) refer to the policy implied,
-// not the pseudo name. That is, a TA VMERGE_VVM can be either the _TU pseudo
-// form with an IMPLICIT_DEF passthrough operand or the unsuffixed (TA) pseudo
-// form.
+// Try to fold away VMERGE_VVM instructions into their true operands:
+//
+// %true = PseudoVADD_VV ...
+// %x = PseudoVMERGE_VVM %false, %false, %true, %mask
+// ->
+// %x = PseudoVADD_VV_MASK %false, ..., %mask
+//
+// We can only fold if vmerge's merge operand, vmerge's false operand and
+// %true's merge operand (if it has one) are the same. This is because we have
+// to consolidate them into one merge operand in the result.
+//
+// If %true is masked, then we can use its mask instead of vmerge's if vmerge's
+// mask is all ones.
+//
+// We can also fold a VMV_V_V into its true operand, since it is equivalent to a
+// VMERGE_VVM with an all ones mask.
+//
+// The resulting VL is the minimum of the two VLs.
+//
+// The resulting policy is the effective policy the vmerge would have had,
+// i.e. whether or not it's merge operand was implicit-def.
bool RISCVDAGToDAGISel::performCombineVMergeAndVOps(SDNode *N) {
SDValue Merge, False, True, VL, Mask, Glue;
// A vmv.v.v is equivalent to a vmerge with an all-ones mask.
@@ -3530,6 +3538,8 @@ bool RISCVDAGToDAGISel::performCombineVMergeAndVOps(SDNode *N) {
if (Info->MaskAffectsResult && Mask && !usesAllOnesMask(Mask, Glue))
return false;
+ // If True has a merge operand then it needs to be the same as vmerge's False,
+ // since False will be used for the result's merge operand.
if (HasTiedDest && !isImplicitDef(True->getOperand(0))) {
// The vmerge instruction must be TU.
// FIXME: This could be relaxed, but we need to handle the policy for the
@@ -3537,19 +3547,17 @@ bool RISCVDAGToDAGISel::performCombineVMergeAndVOps(SDNode *N) {
if (isImplicitDef(Merge))
return false;
SDValue MergeOpTrue = True->getOperand(0);
- // Both the vmerge instruction and the True instruction must have the same
- // merge operand.
if (False != MergeOpTrue)
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 (IsMasked) {
assert(HasTiedDest && "Expected tied dest");
// The vmerge instruction must be TU.
if (isImplicitDef(Merge))
return false;
- // The vmerge instruction must have an all 1s mask since we're going to keep
- // the mask from the True instruction.
// FIXME: Support mask agnostic True instruction which would have an
// undef merge operand.
if (Mask && !usesAllOnesMask(Mask, Glue))
|
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.
LGTM
The current comment was written whenever we had separate TU/TA variants for
each pseudo, and hasn't been accurate for a while.
This method has grown rather complicated over time so rather than enumerate all
the different possible cases now (which must be a lot), this updates the
comment to list the different rules that are required for us to be able to fold
a vmerge.