Skip to content

Commit 218bb21

Browse files
authored
[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.
1 parent 4c3de45 commit 218bb21

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3458,19 +3458,27 @@ static unsigned GetVMSetForLMul(RISCVII::VLMUL LMUL) {
34583458
llvm_unreachable("Unknown VLMUL enum");
34593459
}
34603460

3461-
// Try to fold away VMERGE_VVM instructions. We handle these cases:
3462-
// -Masked TU VMERGE_VVM combined with an unmasked TA instruction instruction
3463-
// folds to a masked TU instruction. VMERGE_VVM must have have merge operand
3464-
// same as false operand.
3465-
// -Masked TA VMERGE_VVM combined with an unmasked TA instruction fold to a
3466-
// masked TA instruction.
3467-
// -Unmasked TU VMERGE_VVM combined with a masked MU TA instruction folds to
3468-
// masked TU instruction. Both instructions must have the same merge operand.
3469-
// VMERGE_VVM must have have merge operand same as false operand.
3470-
// Note: The VMERGE_VVM forms above (TA, and TU) refer to the policy implied,
3471-
// not the pseudo name. That is, a TA VMERGE_VVM can be either the _TU pseudo
3472-
// form with an IMPLICIT_DEF passthrough operand or the unsuffixed (TA) pseudo
3473-
// form.
3461+
// Try to fold away VMERGE_VVM instructions into their true operands:
3462+
//
3463+
// %true = PseudoVADD_VV ...
3464+
// %x = PseudoVMERGE_VVM %false, %false, %true, %mask
3465+
// ->
3466+
// %x = PseudoVADD_VV_MASK %false, ..., %mask
3467+
//
3468+
// We can only fold if vmerge's merge operand, vmerge's false operand and
3469+
// %true's merge operand (if it has one) are the same. This is because we have
3470+
// to consolidate them into one merge operand in the result.
3471+
//
3472+
// If %true is masked, then we can use its mask instead of vmerge's if vmerge's
3473+
// mask is all ones.
3474+
//
3475+
// We can also fold a VMV_V_V into its true operand, since it is equivalent to a
3476+
// VMERGE_VVM with an all ones mask.
3477+
//
3478+
// The resulting VL is the minimum of the two VLs.
3479+
//
3480+
// The resulting policy is the effective policy the vmerge would have had,
3481+
// i.e. whether or not it's merge operand was implicit-def.
34743482
bool RISCVDAGToDAGISel::performCombineVMergeAndVOps(SDNode *N) {
34753483
SDValue Merge, False, True, VL, Mask, Glue;
34763484
// A vmv.v.v is equivalent to a vmerge with an all-ones mask.
@@ -3530,26 +3538,26 @@ bool RISCVDAGToDAGISel::performCombineVMergeAndVOps(SDNode *N) {
35303538
if (Info->MaskAffectsResult && Mask && !usesAllOnesMask(Mask, Glue))
35313539
return false;
35323540

3541+
// If True has a merge operand then it needs to be the same as vmerge's False,
3542+
// since False will be used for the result's merge operand.
35333543
if (HasTiedDest && !isImplicitDef(True->getOperand(0))) {
35343544
// The vmerge instruction must be TU.
35353545
// FIXME: This could be relaxed, but we need to handle the policy for the
35363546
// resulting op correctly.
35373547
if (isImplicitDef(Merge))
35383548
return false;
35393549
SDValue MergeOpTrue = True->getOperand(0);
3540-
// Both the vmerge instruction and the True instruction must have the same
3541-
// merge operand.
35423550
if (False != MergeOpTrue)
35433551
return false;
35443552
}
35453553

3554+
// If True is masked then the vmerge must have an all 1s mask, since we're
3555+
// going to keep the mask from True.
35463556
if (IsMasked) {
35473557
assert(HasTiedDest && "Expected tied dest");
35483558
// The vmerge instruction must be TU.
35493559
if (isImplicitDef(Merge))
35503560
return false;
3551-
// The vmerge instruction must have an all 1s mask since we're going to keep
3552-
// the mask from the True instruction.
35533561
// FIXME: Support mask agnostic True instruction which would have an
35543562
// undef merge operand.
35553563
if (Mask && !usesAllOnesMask(Mask, Glue))

0 commit comments

Comments
 (0)