[llvm] 218bb21 - [RISCV] Update performCombineVMergeAndVOps comments. NFC (#78472)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 23 21:53:37 PST 2024
Author: Luke Lau
Date: 2024-01-24T12:53:33+07:00
New Revision: 218bb21eaa2f3c08ec24de1f5d88f4d5265068bf
URL: https://github.com/llvm/llvm-project/commit/218bb21eaa2f3c08ec24de1f5d88f4d5265068bf
DIFF: https://github.com/llvm/llvm-project/commit/218bb21eaa2f3c08ec24de1f5d88f4d5265068bf.diff
LOG: [RISCV] Update performCombineVMergeAndVOps comments. NFC (#78472)
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.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
index 0d8688ba2eaeaff..4d6f74bc0285cb8 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))
More information about the llvm-commits
mailing list