Skip to content

Commit 3b3394b

Browse files
authored
[RISCV] Use Log2SEW=0 for VMNAND/VMSET created for riscv_vmsge(u) intrinsics. (#119767)
These instructions should always be created with Log2SEW=0 and an LMUL based on SEW=8. This is used by the vsetvli pass to know these instructions only care about the ratio and not the specific value. Looks like I fixed riscv_vmsge(u)_mask intrinsics years ago, but forgot the unmasked intrinsics. I'm working on an enhancement to our MachineVerifier checks that will require VMNAND and VMSET to have Log2SEW=0.
1 parent 5cac0eb commit 3b3394b

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,32 +1664,50 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
16641664
switch (RISCVTargetLowering::getLMUL(Src1VT)) {
16651665
default:
16661666
llvm_unreachable("Unexpected LMUL!");
1667-
#define CASE_VMSLT_VMNAND_VMSET_OPCODES(lmulenum, suffix, suffix_b) \
1667+
#define CASE_VMSLT_OPCODES(lmulenum, suffix) \
16681668
case RISCVII::VLMUL::lmulenum: \
16691669
VMSLTOpcode = IsUnsigned ? RISCV::PseudoVMSLTU_VX_##suffix \
16701670
: RISCV::PseudoVMSLT_VX_##suffix; \
16711671
VMSGTOpcode = IsUnsigned ? RISCV::PseudoVMSGTU_VX_##suffix \
16721672
: RISCV::PseudoVMSGT_VX_##suffix; \
1673-
VMNANDOpcode = RISCV::PseudoVMNAND_MM_##suffix_b; \
1674-
VMSetOpcode = RISCV::PseudoVMSET_M_##suffix_b; \
16751673
break;
1676-
CASE_VMSLT_VMNAND_VMSET_OPCODES(LMUL_F8, MF8, B64)
1677-
CASE_VMSLT_VMNAND_VMSET_OPCODES(LMUL_F4, MF4, B32)
1678-
CASE_VMSLT_VMNAND_VMSET_OPCODES(LMUL_F2, MF2, B16)
1679-
CASE_VMSLT_VMNAND_VMSET_OPCODES(LMUL_1, M1, B8)
1680-
CASE_VMSLT_VMNAND_VMSET_OPCODES(LMUL_2, M2, B4)
1681-
CASE_VMSLT_VMNAND_VMSET_OPCODES(LMUL_4, M4, B2)
1682-
CASE_VMSLT_VMNAND_VMSET_OPCODES(LMUL_8, M8, B1)
1683-
#undef CASE_VMSLT_VMNAND_VMSET_OPCODES
1674+
CASE_VMSLT_OPCODES(LMUL_F8, MF8)
1675+
CASE_VMSLT_OPCODES(LMUL_F4, MF4)
1676+
CASE_VMSLT_OPCODES(LMUL_F2, MF2)
1677+
CASE_VMSLT_OPCODES(LMUL_1, M1)
1678+
CASE_VMSLT_OPCODES(LMUL_2, M2)
1679+
CASE_VMSLT_OPCODES(LMUL_4, M4)
1680+
CASE_VMSLT_OPCODES(LMUL_8, M8)
1681+
#undef CASE_VMSLT_OPCODES
1682+
}
1683+
// Mask operations use the LMUL from the mask type.
1684+
switch (RISCVTargetLowering::getLMUL(VT)) {
1685+
default:
1686+
llvm_unreachable("Unexpected LMUL!");
1687+
#define CASE_VMNAND_VMSET_OPCODES(lmulenum, suffix) \
1688+
case RISCVII::VLMUL::lmulenum: \
1689+
VMNANDOpcode = RISCV::PseudoVMNAND_MM_##suffix; \
1690+
VMSetOpcode = RISCV::PseudoVMSET_M_##suffix; \
1691+
break;
1692+
CASE_VMNAND_VMSET_OPCODES(LMUL_F8, B64)
1693+
CASE_VMNAND_VMSET_OPCODES(LMUL_F4, B32)
1694+
CASE_VMNAND_VMSET_OPCODES(LMUL_F2, B16)
1695+
CASE_VMNAND_VMSET_OPCODES(LMUL_1, B8)
1696+
CASE_VMNAND_VMSET_OPCODES(LMUL_2, B4)
1697+
CASE_VMNAND_VMSET_OPCODES(LMUL_4, B2)
1698+
CASE_VMNAND_VMSET_OPCODES(LMUL_8, B1)
1699+
#undef CASE_VMNAND_VMSET_OPCODES
16841700
}
16851701
SDValue SEW = CurDAG->getTargetConstant(
16861702
Log2_32(Src1VT.getScalarSizeInBits()), DL, XLenVT);
1703+
SDValue MaskSEW = CurDAG->getTargetConstant(0, DL, XLenVT);
16871704
SDValue VL;
16881705
selectVLOp(Node->getOperand(3), VL);
16891706

16901707
// If vmsge(u) with minimum value, expand it to vmset.
16911708
if (IsCmpMinimum) {
1692-
ReplaceNode(Node, CurDAG->getMachineNode(VMSetOpcode, DL, VT, VL, SEW));
1709+
ReplaceNode(Node,
1710+
CurDAG->getMachineNode(VMSetOpcode, DL, VT, VL, MaskSEW));
16931711
return;
16941712
}
16951713

@@ -1708,7 +1726,7 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
17081726
CurDAG->getMachineNode(VMSLTOpcode, DL, VT, {Src1, Src2, VL, SEW}),
17091727
0);
17101728
ReplaceNode(Node, CurDAG->getMachineNode(VMNANDOpcode, DL, VT,
1711-
{Cmp, Cmp, VL, SEW}));
1729+
{Cmp, Cmp, VL, MaskSEW}));
17121730
return;
17131731
}
17141732
case Intrinsic::riscv_vmsgeu_mask:
@@ -1742,7 +1760,7 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
17421760
switch (RISCVTargetLowering::getLMUL(Src1VT)) {
17431761
default:
17441762
llvm_unreachable("Unexpected LMUL!");
1745-
#define CASE_VMSLT_OPCODES(lmulenum, suffix, suffix_b) \
1763+
#define CASE_VMSLT_OPCODES(lmulenum, suffix) \
17461764
case RISCVII::VLMUL::lmulenum: \
17471765
VMSLTOpcode = IsUnsigned ? RISCV::PseudoVMSLTU_VX_##suffix \
17481766
: RISCV::PseudoVMSLT_VX_##suffix; \
@@ -1751,13 +1769,13 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
17511769
VMSGTMaskOpcode = IsUnsigned ? RISCV::PseudoVMSGTU_VX_##suffix##_MASK \
17521770
: RISCV::PseudoVMSGT_VX_##suffix##_MASK; \
17531771
break;
1754-
CASE_VMSLT_OPCODES(LMUL_F8, MF8, B64)
1755-
CASE_VMSLT_OPCODES(LMUL_F4, MF4, B32)
1756-
CASE_VMSLT_OPCODES(LMUL_F2, MF2, B16)
1757-
CASE_VMSLT_OPCODES(LMUL_1, M1, B8)
1758-
CASE_VMSLT_OPCODES(LMUL_2, M2, B4)
1759-
CASE_VMSLT_OPCODES(LMUL_4, M4, B2)
1760-
CASE_VMSLT_OPCODES(LMUL_8, M8, B1)
1772+
CASE_VMSLT_OPCODES(LMUL_F8, MF8)
1773+
CASE_VMSLT_OPCODES(LMUL_F4, MF4)
1774+
CASE_VMSLT_OPCODES(LMUL_F2, MF2)
1775+
CASE_VMSLT_OPCODES(LMUL_1, M1)
1776+
CASE_VMSLT_OPCODES(LMUL_2, M2)
1777+
CASE_VMSLT_OPCODES(LMUL_4, M4)
1778+
CASE_VMSLT_OPCODES(LMUL_8, M8)
17611779
#undef CASE_VMSLT_OPCODES
17621780
}
17631781
// Mask operations use the LMUL from the mask type.

llvm/test/CodeGen/RISCV/rvv/vmsgeu.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,7 @@ entry:
21832183
define <vscale x 4 x i1> @intrinsic_vmsgeu_vi_nxv4i16_i16(<vscale x 4 x i16> %0, iXLen %1) nounwind {
21842184
; CHECK-LABEL: intrinsic_vmsgeu_vi_nxv4i16_i16:
21852185
; CHECK: # %bb.0: # %entry
2186-
; CHECK-NEXT: vsetvli zero, a0, e16, m1, ta, ma
2186+
; CHECK-NEXT: vsetvli zero, a0, e8, mf2, ta, ma
21872187
; CHECK-NEXT: vmset.m v0
21882188
; CHECK-NEXT: ret
21892189
entry:

0 commit comments

Comments
 (0)