1010 if (
Node->isMachineOpcode()) {
1012 Node->setNodeId(-1);
1018 unsigned Opcode =
Node->getOpcode();
1019 MVT XLenVT = Subtarget->getXLenVT();
1021 MVT VT =
Node->getSimpleValueType(0);
1023 bool HasBitTest = Subtarget->hasBEXTILike();
1027 assert((VT == Subtarget->getXLenVT() || VT == MVT::i32) &&
"Unexpected VT");
1029 if (ConstNode->isZero()) {
1031 CurDAG->getCopyFromReg(
CurDAG->getEntryNode(),
DL, RISCV::X0, VT);
1035 int64_t Imm = ConstNode->getSExtValue();
1056 Imm = ((
uint64_t)Imm << 32) | (Imm & 0xFFFFFFFF);
1065 bool Is64Bit = Subtarget->is64Bit();
1066 bool HasZdinx = Subtarget->hasStdExtZdinx();
1068 bool NegZeroF64 = APF.
isNegZero() && VT == MVT::f64;
1073 if (VT == MVT::f64 && HasZdinx && !Is64Bit)
1074 Imm =
CurDAG->getRegister(RISCV::X0_Pair, MVT::f64);
1076 Imm =
CurDAG->getRegister(RISCV::X0, XLenVT);
1087 assert(Subtarget->hasStdExtZfbfmin());
1088 Opc = RISCV::FMV_H_X;
1091 Opc = Subtarget->hasStdExtZhinxmin() ? RISCV::COPY : RISCV::FMV_H_X;
1094 Opc = Subtarget->hasStdExtZfinx() ? RISCV::COPY : RISCV::FMV_W_X;
1099 assert((Subtarget->is64Bit() || APF.
isZero()) &&
"Unexpected constant");
1103 Opc = Is64Bit ? RISCV::FMV_D_X : RISCV::FCVT_D_W;
1108 if (VT.
SimpleTy == MVT::f16 &&
Opc == RISCV::COPY) {
1110 CurDAG->getTargetExtractSubreg(RISCV::sub_16,
DL, VT, Imm).getNode();
1111 }
else if (VT.
SimpleTy == MVT::f32 &&
Opc == RISCV::COPY) {
1113 CurDAG->getTargetExtractSubreg(RISCV::sub_32,
DL, VT, Imm).getNode();
1114 }
else if (
Opc == RISCV::FCVT_D_W_IN32X ||
Opc == RISCV::FCVT_D_W)
1115 Res =
CurDAG->getMachineNode(
1123 Opc = RISCV::FSGNJN_D;
1125 Opc = Is64Bit ? RISCV::FSGNJN_D_INX : RISCV::FSGNJN_D_IN32X;
1133 case RISCVISD::BuildGPRPair:
1134 case RISCVISD::BuildPairF64: {
1135 if (Opcode == RISCVISD::BuildPairF64 && !Subtarget->hasStdExtZdinx())
1138 assert((!Subtarget->is64Bit() || Opcode == RISCVISD::BuildGPRPair) &&
1139 "BuildPairF64 only handled here on rv32i_zdinx");
1142 CurDAG->getTargetConstant(RISCV::GPRPairRegClassID,
DL, MVT::i32),
1143 Node->getOperand(0),
1144 CurDAG->getTargetConstant(RISCV::sub_gpr_even,
DL, MVT::i32),
1145 Node->getOperand(1),
1146 CurDAG->getTargetConstant(RISCV::sub_gpr_odd,
DL, MVT::i32)};
1152 case RISCVISD::SplitGPRPair:
1153 case RISCVISD::SplitF64: {
1154 if (Subtarget->hasStdExtZdinx() || Opcode != RISCVISD::SplitF64) {
1155 assert((!Subtarget->is64Bit() || Opcode == RISCVISD::SplitGPRPair) &&
1156 "SplitF64 only handled here on rv32i_zdinx");
1160 Node->getValueType(0),
1161 Node->getOperand(0));
1167 RISCV::sub_gpr_odd,
DL,
Node->getValueType(1),
Node->getOperand(0));
1175 assert(Opcode != RISCVISD::SplitGPRPair &&
1176 "SplitGPRPair should already be handled");
1178 if (!Subtarget->hasStdExtZfa())
1180 assert(Subtarget->hasStdExtD() && !Subtarget->is64Bit() &&
1181 "Unexpected subtarget");
1186 Node->getOperand(0));
1191 Node->getOperand(0));
1206 unsigned ShAmt = N1C->getZExtValue();
1210 unsigned XLen = Subtarget->getXLen();
1213 if (ShAmt <= 32 && TrailingZeros > 0 && LeadingZeros == 32) {
1218 CurDAG->getTargetConstant(TrailingZeros,
DL, VT));
1221 CurDAG->getTargetConstant(TrailingZeros + ShAmt,
DL, VT));
1225 if (TrailingZeros == 0 && LeadingZeros > ShAmt &&
1226 XLen - LeadingZeros > 11 && LeadingZeros != 32) {
1237 CurDAG->getTargetConstant(LeadingZeros,
DL, VT));
1240 CurDAG->getTargetConstant(LeadingZeros - ShAmt,
DL, VT));
1254 unsigned ShAmt = N1C->getZExtValue();
1260 unsigned XLen = Subtarget->getXLen();
1263 if (LeadingZeros == 32 && TrailingZeros > ShAmt) {
1266 CurDAG->getTargetConstant(TrailingZeros,
DL, VT));
1269 CurDAG->getTargetConstant(TrailingZeros - ShAmt,
DL, VT));
1286 if (ShAmt >= TrailingOnes)
1289 if (TrailingOnes == 32) {
1291 Subtarget->is64Bit() ? RISCV::SRLIW : RISCV::SRLI,
DL, VT,
1302 if (HasBitTest && ShAmt + 1 == TrailingOnes) {
1304 Subtarget->hasStdExtZbs() ? RISCV::BEXTI : RISCV::TH_TST,
DL, VT,
1310 const unsigned Msb = TrailingOnes - 1;
1311 const unsigned Lsb = ShAmt;
1315 unsigned LShAmt = Subtarget->getXLen() - TrailingOnes;
1318 CurDAG->getTargetConstant(LShAmt,
DL, VT));
1321 CurDAG->getTargetConstant(LShAmt + ShAmt,
DL, VT));
1346 unsigned ShAmt = N1C->getZExtValue();
1350 if (ExtSize >= 32 || ShAmt >= ExtSize)
1352 unsigned LShAmt = Subtarget->getXLen() - ExtSize;
1355 CurDAG->getTargetConstant(LShAmt,
DL, VT));
1358 CurDAG->getTargetConstant(LShAmt + ShAmt,
DL, VT));
1385 unsigned C2 =
C->getZExtValue();
1386 unsigned XLen = Subtarget->getXLen();
1387 assert((C2 > 0 && C2 < XLen) &&
"Unexpected shift amount!");
1395 bool IsCANDI =
isInt<6>(N1C->getSExtValue());
1407 bool OneUseOrZExtW = N0.
hasOneUse() || C1 == UINT64_C(0xFFFFFFFF);
1417 if (C2 + 32 == Leading) {
1419 RISCV::SRLIW,
DL, VT,
X,
CurDAG->getTargetConstant(C2,
DL, VT));
1429 if (C2 >= 32 && (Leading - C2) == 1 && N0.
hasOneUse() &&
1433 CurDAG->getMachineNode(RISCV::SRAIW,
DL, VT,
X.getOperand(0),
1434 CurDAG->getTargetConstant(31,
DL, VT));
1436 RISCV::SRLIW,
DL, VT,
SDValue(SRAIW, 0),
1437 CurDAG->getTargetConstant(Leading - 32,
DL, VT));
1450 const unsigned Lsb = C2;
1456 bool Skip = Subtarget->hasStdExtZba() && Leading == 32 &&
1460 Skip |= HasBitTest && Leading == XLen - 1;
1461 if (OneUseOrZExtW && !Skip) {
1463 RISCV::SLLI,
DL, VT,
X,
1464 CurDAG->getTargetConstant(Leading - C2,
DL, VT));
1467 CurDAG->getTargetConstant(Leading,
DL, VT));
1479 if (C2 + Leading < XLen &&
1482 if ((XLen - (C2 + Leading)) == 32 && Subtarget->hasStdExtZba()) {
1484 CurDAG->getMachineNode(RISCV::SLLI_UW,
DL, VT,
X,
1485 CurDAG->getTargetConstant(C2,
DL, VT));
1498 const unsigned Msb = XLen - Leading - 1;
1499 const unsigned Lsb = C2;
1504 if (OneUseOrZExtW && !IsCANDI) {
1506 RISCV::SLLI,
DL, VT,
X,
1507 CurDAG->getTargetConstant(C2 + Leading,
DL, VT));
1510 CurDAG->getTargetConstant(Leading,
DL, VT));
1522 if (Leading == C2 && C2 + Trailing < XLen && OneUseOrZExtW &&
1524 unsigned SrliOpc = RISCV::SRLI;
1528 X.getConstantOperandVal(1) == UINT64_C(0xFFFFFFFF)) {
1529 SrliOpc = RISCV::SRLIW;
1530 X =
X.getOperand(0);
1534 CurDAG->getTargetConstant(C2 + Trailing,
DL, VT));
1537 CurDAG->getTargetConstant(Trailing,
DL, VT));
1542 if (Leading > 32 && (Leading - 32) == C2 && C2 + Trailing < 32 &&
1543 OneUseOrZExtW && !IsCANDI) {
1545 RISCV::SRLIW,
DL, VT,
X,
1546 CurDAG->getTargetConstant(C2 + Trailing,
DL, VT));
1549 CurDAG->getTargetConstant(Trailing,
DL, VT));
1554 if (Trailing > 0 && Leading + Trailing == 32 && C2 + Trailing < XLen &&
1555 OneUseOrZExtW && Subtarget->hasStdExtZba()) {
1557 RISCV::SRLI,
DL, VT,
X,
1558 CurDAG->getTargetConstant(C2 + Trailing,
DL, VT));
1560 RISCV::SLLI_UW,
DL, VT,
SDValue(SRLI, 0),
1561 CurDAG->getTargetConstant(Trailing,
DL, VT));
1572 if (Leading == 0 && C2 < Trailing && OneUseOrZExtW && !IsCANDI) {
1574 RISCV::SRLI,
DL, VT,
X,
1575 CurDAG->getTargetConstant(Trailing - C2,
DL, VT));
1578 CurDAG->getTargetConstant(Trailing,
DL, VT));
1583 if (C2 < Trailing && Leading + C2 == 32 && OneUseOrZExtW && !IsCANDI) {
1585 RISCV::SRLIW,
DL, VT,
X,
1586 CurDAG->getTargetConstant(Trailing - C2,
DL, VT));
1589 CurDAG->getTargetConstant(Trailing,
DL, VT));
1595 if (C2 < Trailing && Leading + Trailing == 32 && OneUseOrZExtW &&
1596 Subtarget->hasStdExtZba()) {
1598 RISCV::SRLI,
DL, VT,
X,
1599 CurDAG->getTargetConstant(Trailing - C2,
DL, VT));
1601 RISCV::SLLI_UW,
DL, VT,
SDValue(SRLI, 0),
1602 CurDAG->getTargetConstant(Trailing,
DL, VT));
1609 const uint64_t C1 = N1C->getZExtValue();
1614 unsigned XLen = Subtarget->getXLen();
1615 assert((C2 > 0 && C2 < XLen) &&
"Unexpected shift amount!");
1620 bool Skip = C2 > 32 &&
isInt<12>(N1C->getSExtValue()) &&
1623 X.getConstantOperandVal(1) == 32;
1630 RISCV::SRAI,
DL, VT,
X,
1631 CurDAG->getTargetConstant(C2 - Leading,
DL, VT));
1634 CurDAG->getTargetConstant(Leading,
DL, VT));
1646 if (C2 > Leading && Leading > 0 && Trailing > 0) {
1649 CurDAG->getTargetConstant(C2 - Leading,
DL, VT));
1652 CurDAG->getTargetConstant(Leading + Trailing,
DL, VT));
1655 CurDAG->getTargetConstant(Trailing,
DL, VT));
1668 !(C1 == 0xffff && Subtarget->hasStdExtZbb()) &&
1669 !(C1 == 0xffffffff && Subtarget->hasStdExtZba())) {
1689 if (!N1C || !N1C->hasOneUse())
1710 (C2 == UINT64_C(0xFFFF) && Subtarget->hasStdExtZbb());
1712 IsANDIOrZExt |= C2 == UINT64_C(0xFFFF) && Subtarget->hasVendorXTHeadBb();
1717 bool IsZExtW = C2 == UINT64_C(0xFFFFFFFF) && Subtarget->hasStdExtZba();
1719 IsZExtW |= C2 == UINT64_C(0xFFFFFFFF) && Subtarget->hasVendorXTHeadBb();
1726 unsigned XLen = Subtarget->getXLen();
1732 unsigned ConstantShift = XLen - LeadingZeros;
1736 uint64_t ShiftedC1 = C1 << ConstantShift;
1745 CurDAG->getTargetConstant(LeadingZeros,
DL, VT));
1755 if (Subtarget->hasVendorXCVmem() && !Subtarget->is64Bit()) {
1765 bool Simm12 =
false;
1766 bool SignExtend = Load->getExtensionType() ==
ISD::SEXTLOAD;
1769 int ConstantVal = ConstantOffset->getSExtValue();
1776 unsigned Opcode = 0;
1777 switch (Load->getMemoryVT().getSimpleVT().SimpleTy) {
1779 if (Simm12 && SignExtend)
1780 Opcode = RISCV::CV_LB_ri_inc;
1781 else if (Simm12 && !SignExtend)
1782 Opcode = RISCV::CV_LBU_ri_inc;
1783 else if (!Simm12 && SignExtend)
1784 Opcode = RISCV::CV_LB_rr_inc;
1786 Opcode = RISCV::CV_LBU_rr_inc;
1789 if (Simm12 && SignExtend)
1790 Opcode = RISCV::CV_LH_ri_inc;
1791 else if (Simm12 && !SignExtend)
1792 Opcode = RISCV::CV_LHU_ri_inc;
1793 else if (!Simm12 && SignExtend)
1794 Opcode = RISCV::CV_LH_rr_inc;
1796 Opcode = RISCV::CV_LHU_rr_inc;
1800 Opcode = RISCV::CV_LW_ri_inc;
1802 Opcode = RISCV::CV_LW_rr_inc;
1817 case RISCVISD::LD_RV32: {
1818 assert(Subtarget->hasStdExtZilsd() &&
"LD_RV32 is only used with Zilsd");
1827 RISCV::LD_RV32,
DL, {MVT::Untyped, MVT::Other},
Ops);
1839 case RISCVISD::SD_RV32: {
1851 RegPair =
CurDAG->getRegister(RISCV::X0_Pair, MVT::Untyped);
1854 CurDAG->getTargetConstant(RISCV::GPRPairRegClassID,
DL, MVT::i32),
Lo,
1855 CurDAG->getTargetConstant(RISCV::sub_gpr_even,
DL, MVT::i32),
Hi,
1856 CurDAG->getTargetConstant(RISCV::sub_gpr_odd,
DL, MVT::i32)};
1858 RegPair =
SDValue(
CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE,
DL,
1870 case RISCVISD::PPACK_DH: {
1871 assert(Subtarget->enablePExtCodeGen() && Subtarget->isRV32());
1879 CurDAG->getTargetConstant(RISCV::GPRPairRegClassID,
DL, MVT::i32), Val0,
1880 CurDAG->getTargetConstant(RISCV::sub_gpr_even,
DL, MVT::i32), Val2,
1881 CurDAG->getTargetConstant(RISCV::sub_gpr_odd,
DL, MVT::i32)};
1887 CurDAG->getTargetConstant(RISCV::GPRPairRegClassID,
DL, MVT::i32), Val1,
1888 CurDAG->getTargetConstant(RISCV::sub_gpr_even,
DL, MVT::i32), Val3,
1889 CurDAG->getTargetConstant(RISCV::sub_gpr_odd,
DL, MVT::i32)};
1892 MVT::Untyped, Ops1),
1896 RISCV::PPACK_DH,
DL, MVT::Untyped, {RegPair0, RegPair1});
1899 MVT::i32,
SDValue(PackDH, 0));
1901 MVT::i32,
SDValue(PackDH, 0));
1908 unsigned IntNo =
Node->getConstantOperandVal(0);
1913 case Intrinsic::riscv_vmsgeu:
1914 case Intrinsic::riscv_vmsge: {
1917 bool IsUnsigned = IntNo == Intrinsic::riscv_vmsgeu;
1918 bool IsCmpConstant =
false;
1919 bool IsCmpMinimum =
false;
1927 IsCmpConstant =
true;
1928 CVal =
C->getSExtValue();
1929 if (CVal >= -15 && CVal <= 16) {
1930 if (!IsUnsigned || CVal != 0)
1932 IsCmpMinimum =
true;
1936 IsCmpMinimum =
true;
1939 unsigned VMSLTOpcode, VMNANDOpcode, VMSetOpcode, VMSGTOpcode;
1943#define CASE_VMSLT_OPCODES(lmulenum, suffix) \
1944 case RISCVVType::lmulenum: \
1945 VMSLTOpcode = IsUnsigned ? RISCV::PseudoVMSLTU_VX_##suffix \
1946 : RISCV::PseudoVMSLT_VX_##suffix; \
1947 VMSGTOpcode = IsUnsigned ? RISCV::PseudoVMSGTU_VX_##suffix \
1948 : RISCV::PseudoVMSGT_VX_##suffix; \
1957#undef CASE_VMSLT_OPCODES
1963#define CASE_VMNAND_VMSET_OPCODES(lmulenum, suffix) \
1964 case RISCVVType::lmulenum: \
1965 VMNANDOpcode = RISCV::PseudoVMNAND_MM_##suffix; \
1966 VMSetOpcode = RISCV::PseudoVMSET_M_##suffix; \
1975#undef CASE_VMNAND_VMSET_OPCODES
1986 CurDAG->getMachineNode(VMSetOpcode,
DL, VT, VL, MaskSEW));
1990 if (IsCmpConstant) {
1995 {Src1, Imm, VL, SEW}));
2002 CurDAG->getMachineNode(VMSLTOpcode,
DL, VT, {Src1, Src2, VL, SEW}),
2005 {Cmp, Cmp, VL, MaskSEW}));
2008 case Intrinsic::riscv_vmsgeu_mask:
2009 case Intrinsic::riscv_vmsge_mask: {
2012 bool IsUnsigned = IntNo == Intrinsic::riscv_vmsgeu_mask;
2013 bool IsCmpConstant =
false;
2014 bool IsCmpMinimum =
false;
2022 IsCmpConstant =
true;
2023 CVal =
C->getSExtValue();
2024 if (CVal >= -15 && CVal <= 16) {
2025 if (!IsUnsigned || CVal != 0)
2027 IsCmpMinimum =
true;
2031 IsCmpMinimum =
true;
2034 unsigned VMSLTOpcode, VMSLTMaskOpcode, VMXOROpcode, VMANDNOpcode,
2035 VMOROpcode, VMSGTMaskOpcode;
2039#define CASE_VMSLT_OPCODES(lmulenum, suffix) \
2040 case RISCVVType::lmulenum: \
2041 VMSLTOpcode = IsUnsigned ? RISCV::PseudoVMSLTU_VX_##suffix \
2042 : RISCV::PseudoVMSLT_VX_##suffix; \
2043 VMSLTMaskOpcode = IsUnsigned ? RISCV::PseudoVMSLTU_VX_##suffix##_MASK \
2044 : RISCV::PseudoVMSLT_VX_##suffix##_MASK; \
2045 VMSGTMaskOpcode = IsUnsigned ? RISCV::PseudoVMSGTU_VX_##suffix##_MASK \
2046 : RISCV::PseudoVMSGT_VX_##suffix##_MASK; \
2055#undef CASE_VMSLT_OPCODES
2061#define CASE_VMXOR_VMANDN_VMOR_OPCODES(lmulenum, suffix) \
2062 case RISCVVType::lmulenum: \
2063 VMXOROpcode = RISCV::PseudoVMXOR_MM_##suffix; \
2064 VMANDNOpcode = RISCV::PseudoVMANDN_MM_##suffix; \
2065 VMOROpcode = RISCV::PseudoVMOR_MM_##suffix; \
2074#undef CASE_VMXOR_VMANDN_VMOR_OPCODES
2088 if (Mask == MaskedOff) {
2093 CurDAG->getMachineNode(VMOROpcode,
DL, VT,
2094 {Mask, MaskedOff, VL, MaskSEW}));
2101 if (Mask == MaskedOff) {
2103 CurDAG->getMachineNode(VMSLTOpcode,
DL, VT, {Src1, Src2, VL, SEW}),
2106 {Mask, Cmp, VL, MaskSEW}));
2113 if (IsCmpConstant) {
2118 VMSGTMaskOpcode,
DL, VT,
2119 {MaskedOff, Src1, Imm, Mask, VL, SEW, PolicyOp}));
2129 {MaskedOff, Src1, Src2, Mask,
2130 VL, SEW, PolicyOp}),
2134 {Cmp, Mask, VL, MaskSEW}));
2137 case Intrinsic::riscv_vsetvli:
2138 case Intrinsic::riscv_vsetvlimax:
2140 case Intrinsic::riscv_sf_vsettnt:
2141 case Intrinsic::riscv_sf_vsettm:
2142 case Intrinsic::riscv_sf_vsettk:
2148 unsigned IntNo =
Node->getConstantOperandVal(1);
2153 case Intrinsic::riscv_vlseg2:
2154 case Intrinsic::riscv_vlseg3:
2155 case Intrinsic::riscv_vlseg4:
2156 case Intrinsic::riscv_vlseg5:
2157 case Intrinsic::riscv_vlseg6:
2158 case Intrinsic::riscv_vlseg7:
2159 case Intrinsic::riscv_vlseg8: {
2164 case Intrinsic::riscv_vlseg2_mask:
2165 case Intrinsic::riscv_vlseg3_mask:
2166 case Intrinsic::riscv_vlseg4_mask:
2167 case Intrinsic::riscv_vlseg5_mask:
2168 case Intrinsic::riscv_vlseg6_mask:
2169 case Intrinsic::riscv_vlseg7_mask:
2170 case Intrinsic::riscv_vlseg8_mask: {
2175 case Intrinsic::riscv_vlsseg2:
2176 case Intrinsic::riscv_vlsseg3:
2177 case Intrinsic::riscv_vlsseg4:
2178 case Intrinsic::riscv_vlsseg5:
2179 case Intrinsic::riscv_vlsseg6:
2180 case Intrinsic::riscv_vlsseg7:
2181 case Intrinsic::riscv_vlsseg8: {
2186 case Intrinsic::riscv_vlsseg2_mask:
2187 case Intrinsic::riscv_vlsseg3_mask:
2188 case Intrinsic::riscv_vlsseg4_mask:
2189 case Intrinsic::riscv_vlsseg5_mask:
2190 case Intrinsic::riscv_vlsseg6_mask:
2191 case Intrinsic::riscv_vlsseg7_mask:
2192 case Intrinsic::riscv_vlsseg8_mask: {
2197 case Intrinsic::riscv_vloxseg2:
2198 case Intrinsic::riscv_vloxseg3:
2199 case Intrinsic::riscv_vloxseg4:
2200 case Intrinsic::riscv_vloxseg5:
2201 case Intrinsic::riscv_vloxseg6:
2202 case Intrinsic::riscv_vloxseg7:
2203 case Intrinsic::riscv_vloxseg8:
2207 case Intrinsic::riscv_vluxseg2:
2208 case Intrinsic::riscv_vluxseg3:
2209 case Intrinsic::riscv_vluxseg4:
2210 case Intrinsic::riscv_vluxseg5:
2211 case Intrinsic::riscv_vluxseg6:
2212 case Intrinsic::riscv_vluxseg7:
2213 case Intrinsic::riscv_vluxseg8:
2217 case Intrinsic::riscv_vloxseg2_mask:
2218 case Intrinsic::riscv_vloxseg3_mask:
2219 case Intrinsic::riscv_vloxseg4_mask:
2220 case Intrinsic::riscv_vloxseg5_mask:
2221 case Intrinsic::riscv_vloxseg6_mask:
2222 case Intrinsic::riscv_vloxseg7_mask:
2223 case Intrinsic::riscv_vloxseg8_mask:
2227 case Intrinsic::riscv_vluxseg2_mask:
2228 case Intrinsic::riscv_vluxseg3_mask:
2229 case Intrinsic::riscv_vluxseg4_mask:
2230 case Intrinsic::riscv_vluxseg5_mask:
2231 case Intrinsic::riscv_vluxseg6_mask:
2232 case Intrinsic::riscv_vluxseg7_mask:
2233 case Intrinsic::riscv_vluxseg8_mask:
2237 case Intrinsic::riscv_vlseg8ff:
2238 case Intrinsic::riscv_vlseg7ff:
2239 case Intrinsic::riscv_vlseg6ff:
2240 case Intrinsic::riscv_vlseg5ff:
2241 case Intrinsic::riscv_vlseg4ff:
2242 case Intrinsic::riscv_vlseg3ff:
2243 case Intrinsic::riscv_vlseg2ff: {
2247 case Intrinsic::riscv_vlseg8ff_mask:
2248 case Intrinsic::riscv_vlseg7ff_mask:
2249 case Intrinsic::riscv_vlseg6ff_mask:
2250 case Intrinsic::riscv_vlseg5ff_mask:
2251 case Intrinsic::riscv_vlseg4ff_mask:
2252 case Intrinsic::riscv_vlseg3ff_mask:
2253 case Intrinsic::riscv_vlseg2ff_mask: {
2257 case Intrinsic::riscv_vloxei:
2258 case Intrinsic::riscv_vloxei_mask:
2259 case Intrinsic::riscv_vluxei:
2260 case Intrinsic::riscv_vluxei_mask: {
2261 bool IsMasked = IntNo == Intrinsic::riscv_vloxei_mask ||
2262 IntNo == Intrinsic::riscv_vluxei_mask;
2263 bool IsOrdered = IntNo == Intrinsic::riscv_vloxei ||
2264 IntNo == Intrinsic::riscv_vloxei_mask;
2266 MVT VT =
Node->getSimpleValueType(0);
2279 "Element count mismatch");
2284 if (IndexLog2EEW == 6 && !Subtarget->is64Bit()) {
2286 "index values when XLEN=32");
2289 IsMasked, IsOrdered, IndexLog2EEW,
static_cast<unsigned>(LMUL),
2290 static_cast<unsigned>(IndexLMUL));
2292 CurDAG->getMachineNode(
P->Pseudo,
DL,
Node->getVTList(), Operands);
2299 case Intrinsic::riscv_vlm:
2300 case Intrinsic::riscv_vle:
2301 case Intrinsic::riscv_vle_mask:
2302 case Intrinsic::riscv_vlse:
2303 case Intrinsic::riscv_vlse_mask: {
2304 bool IsMasked = IntNo == Intrinsic::riscv_vle_mask ||
2305 IntNo == Intrinsic::riscv_vlse_mask;
2307 IntNo == Intrinsic::riscv_vlse || IntNo == Intrinsic::riscv_vlse_mask;
2309 MVT VT =
Node->getSimpleValueType(0);
2318 bool HasPassthruOperand = IntNo != Intrinsic::riscv_vlm;
2321 if (HasPassthruOperand)
2327 CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
DL, VT);
2335 RISCV::getVLEPseudo(IsMasked, IsStrided,
false, Log2SEW,
2336 static_cast<unsigned>(LMUL));
2338 CurDAG->getMachineNode(
P->Pseudo,
DL,
Node->getVTList(), Operands);
2345 case Intrinsic::riscv_vleff:
2346 case Intrinsic::riscv_vleff_mask: {
2347 bool IsMasked = IntNo == Intrinsic::riscv_vleff_mask;
2349 MVT VT =
Node->getSimpleValueType(0);
2361 RISCV::getVLEPseudo(IsMasked,
false,
true,
2362 Log2SEW,
static_cast<unsigned>(LMUL));
2364 P->Pseudo,
DL,
Node->getVTList(), Operands);
2370 case Intrinsic::riscv_nds_vln:
2371 case Intrinsic::riscv_nds_vln_mask:
2372 case Intrinsic::riscv_nds_vlnu:
2373 case Intrinsic::riscv_nds_vlnu_mask: {
2374 bool IsMasked = IntNo == Intrinsic::riscv_nds_vln_mask ||
2375 IntNo == Intrinsic::riscv_nds_vlnu_mask;
2376 bool IsUnsigned = IntNo == Intrinsic::riscv_nds_vlnu ||
2377 IntNo == Intrinsic::riscv_nds_vlnu_mask;
2379 MVT VT =
Node->getSimpleValueType(0);
2391 IsMasked, IsUnsigned, Log2SEW,
static_cast<unsigned>(LMUL));
2393 CurDAG->getMachineNode(
P->Pseudo,
DL,
Node->getVTList(), Operands);
2396 CurDAG->setNodeMemRefs(Load, {
MemOp->getMemOperand()});
2405 unsigned IntNo =
Node->getConstantOperandVal(1);
2407 case Intrinsic::riscv_vsseg2:
2408 case Intrinsic::riscv_vsseg3:
2409 case Intrinsic::riscv_vsseg4:
2410 case Intrinsic::riscv_vsseg5:
2411 case Intrinsic::riscv_vsseg6:
2412 case Intrinsic::riscv_vsseg7:
2413 case Intrinsic::riscv_vsseg8: {
2418 case Intrinsic::riscv_vsseg2_mask:
2419 case Intrinsic::riscv_vsseg3_mask:
2420 case Intrinsic::riscv_vsseg4_mask:
2421 case Intrinsic::riscv_vsseg5_mask:
2422 case Intrinsic::riscv_vsseg6_mask:
2423 case Intrinsic::riscv_vsseg7_mask:
2424 case Intrinsic::riscv_vsseg8_mask: {
2429 case Intrinsic::riscv_vssseg2:
2430 case Intrinsic::riscv_vssseg3:
2431 case Intrinsic::riscv_vssseg4:
2432 case Intrinsic::riscv_vssseg5:
2433 case Intrinsic::riscv_vssseg6:
2434 case Intrinsic::riscv_vssseg7:
2435 case Intrinsic::riscv_vssseg8: {
2440 case Intrinsic::riscv_vssseg2_mask:
2441 case Intrinsic::riscv_vssseg3_mask:
2442 case Intrinsic::riscv_vssseg4_mask:
2443 case Intrinsic::riscv_vssseg5_mask:
2444 case Intrinsic::riscv_vssseg6_mask:
2445 case Intrinsic::riscv_vssseg7_mask:
2446 case Intrinsic::riscv_vssseg8_mask: {
2451 case Intrinsic::riscv_vsoxseg2:
2452 case Intrinsic::riscv_vsoxseg3:
2453 case Intrinsic::riscv_vsoxseg4:
2454 case Intrinsic::riscv_vsoxseg5:
2455 case Intrinsic::riscv_vsoxseg6:
2456 case Intrinsic::riscv_vsoxseg7:
2457 case Intrinsic::riscv_vsoxseg8:
2461 case Intrinsic::riscv_vsuxseg2:
2462 case Intrinsic::riscv_vsuxseg3:
2463 case Intrinsic::riscv_vsuxseg4:
2464 case Intrinsic::riscv_vsuxseg5:
2465 case Intrinsic::riscv_vsuxseg6:
2466 case Intrinsic::riscv_vsuxseg7:
2467 case Intrinsic::riscv_vsuxseg8:
2471 case Intrinsic::riscv_vsoxseg2_mask:
2472 case Intrinsic::riscv_vsoxseg3_mask:
2473 case Intrinsic::riscv_vsoxseg4_mask:
2474 case Intrinsic::riscv_vsoxseg5_mask:
2475 case Intrinsic::riscv_vsoxseg6_mask:
2476 case Intrinsic::riscv_vsoxseg7_mask:
2477 case Intrinsic::riscv_vsoxseg8_mask:
2481 case Intrinsic::riscv_vsuxseg2_mask:
2482 case Intrinsic::riscv_vsuxseg3_mask:
2483 case Intrinsic::riscv_vsuxseg4_mask:
2484 case Intrinsic::riscv_vsuxseg5_mask:
2485 case Intrinsic::riscv_vsuxseg6_mask:
2486 case Intrinsic::riscv_vsuxseg7_mask:
2487 case Intrinsic::riscv_vsuxseg8_mask:
2491 case Intrinsic::riscv_vsoxei:
2492 case Intrinsic::riscv_vsoxei_mask:
2493 case Intrinsic::riscv_vsuxei:
2494 case Intrinsic::riscv_vsuxei_mask: {
2495 bool IsMasked = IntNo == Intrinsic::riscv_vsoxei_mask ||
2496 IntNo == Intrinsic::riscv_vsuxei_mask;
2497 bool IsOrdered = IntNo == Intrinsic::riscv_vsoxei ||
2498 IntNo == Intrinsic::riscv_vsoxei_mask;
2500 MVT VT =
Node->getOperand(2)->getSimpleValueType(0);
2513 "Element count mismatch");
2518 if (IndexLog2EEW == 6 && !Subtarget->is64Bit()) {
2520 "index values when XLEN=32");
2523 IsMasked, IsOrdered, IndexLog2EEW,
2524 static_cast<unsigned>(LMUL),
static_cast<unsigned>(IndexLMUL));
2526 CurDAG->getMachineNode(
P->Pseudo,
DL,
Node->getVTList(), Operands);
2533 case Intrinsic::riscv_vsm:
2534 case Intrinsic::riscv_vse:
2535 case Intrinsic::riscv_vse_mask:
2536 case Intrinsic::riscv_vsse:
2537 case Intrinsic::riscv_vsse_mask: {
2538 bool IsMasked = IntNo == Intrinsic::riscv_vse_mask ||
2539 IntNo == Intrinsic::riscv_vsse_mask;
2541 IntNo == Intrinsic::riscv_vsse || IntNo == Intrinsic::riscv_vsse_mask;
2543 MVT VT =
Node->getOperand(2)->getSimpleValueType(0);
2555 IsMasked, IsStrided, Log2SEW,
static_cast<unsigned>(LMUL));
2557 CurDAG->getMachineNode(
P->Pseudo,
DL,
Node->getVTList(), Operands);
2563 case Intrinsic::riscv_sf_vc_x_se:
2564 case Intrinsic::riscv_sf_vc_i_se:
2567 case Intrinsic::riscv_sf_vlte8:
2568 case Intrinsic::riscv_sf_vlte16:
2569 case Intrinsic::riscv_sf_vlte32:
2570 case Intrinsic::riscv_sf_vlte64: {
2572 unsigned PseudoInst;
2574 case Intrinsic::riscv_sf_vlte8:
2575 PseudoInst = RISCV::PseudoSF_VLTE8;
2578 case Intrinsic::riscv_sf_vlte16:
2579 PseudoInst = RISCV::PseudoSF_VLTE16;
2582 case Intrinsic::riscv_sf_vlte32:
2583 PseudoInst = RISCV::PseudoSF_VLTE32;
2586 case Intrinsic::riscv_sf_vlte64:
2587 PseudoInst = RISCV::PseudoSF_VLTE64;
2595 Node->getOperand(3),
2596 Node->getOperand(4),
2599 Node->getOperand(0)};
2602 CurDAG->getMachineNode(PseudoInst,
DL,
Node->getVTList(), Operands);
2604 CurDAG->setNodeMemRefs(TileLoad, {
MemOp->getMemOperand()});
2609 case Intrinsic::riscv_sf_mm_s_s:
2610 case Intrinsic::riscv_sf_mm_s_u:
2611 case Intrinsic::riscv_sf_mm_u_s:
2612 case Intrinsic::riscv_sf_mm_u_u:
2613 case Intrinsic::riscv_sf_mm_e5m2_e5m2:
2614 case Intrinsic::riscv_sf_mm_e5m2_e4m3:
2615 case Intrinsic::riscv_sf_mm_e4m3_e5m2:
2616 case Intrinsic::riscv_sf_mm_e4m3_e4m3:
2617 case Intrinsic::riscv_sf_mm_f_f: {
2618 bool HasFRM =
false;
2619 unsigned PseudoInst;
2621 case Intrinsic::riscv_sf_mm_s_s:
2622 PseudoInst = RISCV::PseudoSF_MM_S_S;
2624 case Intrinsic::riscv_sf_mm_s_u:
2625 PseudoInst = RISCV::PseudoSF_MM_S_U;
2627 case Intrinsic::riscv_sf_mm_u_s:
2628 PseudoInst = RISCV::PseudoSF_MM_U_S;
2630 case Intrinsic::riscv_sf_mm_u_u:
2631 PseudoInst = RISCV::PseudoSF_MM_U_U;
2633 case Intrinsic::riscv_sf_mm_e5m2_e5m2:
2634 PseudoInst = RISCV::PseudoSF_MM_E5M2_E5M2;
2637 case Intrinsic::riscv_sf_mm_e5m2_e4m3:
2638 PseudoInst = RISCV::PseudoSF_MM_E5M2_E4M3;
2641 case Intrinsic::riscv_sf_mm_e4m3_e5m2:
2642 PseudoInst = RISCV::PseudoSF_MM_E4M3_E5M2;
2645 case Intrinsic::riscv_sf_mm_e4m3_e4m3:
2646 PseudoInst = RISCV::PseudoSF_MM_E4M3_E4M3;
2649 case Intrinsic::riscv_sf_mm_f_f:
2650 if (
Node->getOperand(3).getValueType().getScalarType() == MVT::bf16)
2651 PseudoInst = RISCV::PseudoSF_MM_F_F_ALT;
2653 PseudoInst = RISCV::PseudoSF_MM_F_F;
2669 if (IntNo == Intrinsic::riscv_sf_mm_f_f && Log2SEW == 5 &&
2678 Operands.append({TmOp, TnOp, TkOp,
2679 CurDAG->getTargetConstant(Log2SEW,
DL, XLenVT), TWidenOp,
2683 CurDAG->getMachineNode(PseudoInst,
DL,
Node->getVTList(), Operands);
2688 case Intrinsic::riscv_sf_vtzero_t: {
2695 auto *NewNode =
CurDAG->getMachineNode(
2696 RISCV::PseudoSF_VTZERO_T,
DL,
Node->getVTList(),
2697 {CurDAG->getRegister(getTileReg(TileNum), XLenVT), Tm, Tn, Log2SEW,
2706 case ISD::BITCAST: {
2707 MVT SrcVT =
Node->getOperand(0).getSimpleValueType();
2716 if (Subtarget->enablePExtCodeGen()) {
2718 (VT == MVT::i32 && (SrcVT == MVT::v4i8 || SrcVT == MVT::v2i16)) ||
2719 (SrcVT == MVT::i32 && (VT == MVT::v4i8 || VT == MVT::v2i16));
2721 (VT == MVT::i64 && (SrcVT == MVT::v8i8 || SrcVT == MVT::v4i16 ||
2722 SrcVT == MVT::v2i32)) ||
2723 (SrcVT == MVT::i64 &&
2724 (VT == MVT::v8i8 || VT == MVT::v4i16 || VT == MVT::v2i32));
2725 if (Is32BitCast || Is64BitCast) {
2734 if (Subtarget->enablePExtCodeGen()) {
2735 MVT SrcVT =
Node->getOperand(0).getSimpleValueType();
2736 if ((VT == MVT::v2i32 && SrcVT == MVT::i64) ||
2737 (VT == MVT::v4i8 && SrcVT == MVT::i32)) {
2745 case RISCVISD::TUPLE_INSERT: {
2749 auto Idx =
Node->getConstantOperandVal(2);
2753 MVT SubVecContainerVT = SubVecVT;
2756 SubVecContainerVT =
TLI.getContainerForFixedLengthVector(SubVecVT);
2758 [[maybe_unused]]
bool ExactlyVecRegSized =
2760 .isKnownMultipleOf(Subtarget->expandVScale(VecRegSize));
2762 .getKnownMinValue()));
2763 assert(Idx == 0 && (ExactlyVecRegSized || V.isUndef()));
2765 MVT ContainerVT = VT;
2767 ContainerVT =
TLI.getContainerForFixedLengthVector(VT);
2769 const auto *
TRI = Subtarget->getRegisterInfo();
2771 std::tie(SubRegIdx, Idx) =
2773 ContainerVT, SubVecContainerVT, Idx,
TRI);
2783 [[maybe_unused]]
bool IsSubVecPartReg =
2787 assert((V.getValueType().isRISCVVectorTuple() || !IsSubVecPartReg ||
2789 "Expecting lowering to have created legal INSERT_SUBVECTORs when "
2790 "the subvector is smaller than a full-sized register");
2794 if (SubRegIdx == RISCV::NoSubRegister) {
2795 unsigned InRegClassID =
2799 "Unexpected subvector extraction");
2801 SDNode *NewNode =
CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS,
2807 SDValue Insert =
CurDAG->getTargetInsertSubreg(SubRegIdx,
DL, VT, V, SubV);
2812 case RISCVISD::TUPLE_EXTRACT: {
2814 auto Idx =
Node->getConstantOperandVal(1);
2815 MVT InVT = V.getSimpleValueType();
2819 MVT SubVecContainerVT = VT;
2823 SubVecContainerVT =
TLI.getContainerForFixedLengthVector(VT);
2826 InVT =
TLI.getContainerForFixedLengthVector(InVT);
2828 const auto *
TRI = Subtarget->getRegisterInfo();
2830 std::tie(SubRegIdx, Idx) =
2832 InVT, SubVecContainerVT, Idx,
TRI);
2842 if (SubRegIdx == RISCV::NoSubRegister) {
2846 "Unexpected subvector extraction");
2849 CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS,
DL, VT, V, RC);
2854 SDValue Extract =
CurDAG->getTargetExtractSubreg(SubRegIdx,
DL, VT, V);
2858 case RISCVISD::VMV_S_X_VL:
2859 case RISCVISD::VFMV_S_F_VL:
2860 case RISCVISD::VMV_V_X_VL:
2861 case RISCVISD::VFMV_V_F_VL: {
2863 bool IsScalarMove =
Node->getOpcode() == RISCVISD::VMV_S_X_VL ||
2864 Node->getOpcode() == RISCVISD::VFMV_S_F_VL;
2865 if (!
Node->getOperand(0).isUndef())
2871 if (!Ld || Ld->isIndexed())
2873 EVT MemVT = Ld->getMemoryVT();
2899 if (IsStrided && !Subtarget->hasOptimizedZeroStrideLoad())
2903 SDValue(
CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
DL, VT), 0),
2909 Operands.
append({VL, SEW, PolicyOp, Ld->getChain()});
2913 false, IsStrided,
false,
2914 Log2SEW,
static_cast<unsigned>(LMUL));
2916 CurDAG->getMachineNode(
P->Pseudo,
DL, {VT, MVT::Other}, Operands);
2920 CurDAG->setNodeMemRefs(Load, {Ld->getMemOperand()});
2926 unsigned Locality =
Node->getConstantOperandVal(3);
2934 int NontemporalLevel = 0;
2937 NontemporalLevel = 3;
2940 NontemporalLevel = 1;
2943 NontemporalLevel = 0;
2949 if (NontemporalLevel & 0b1)
2951 if (NontemporalLevel & 0b10)