44#include "llvm/IR/IntrinsicsRISCV.h"
55#define DEBUG_TYPE "riscv-lower"
79 MVT XLenVT = Subtarget.getXLenVT();
84 if (Subtarget.hasStdExtZfhmin())
86 if (Subtarget.hasStdExtZfbfmin() || Subtarget.hasVendorXAndesBFHCvt())
88 if (Subtarget.hasStdExtF())
90 if (Subtarget.hasStdExtD())
92 if (Subtarget.hasStdExtZhinxmin())
94 if (Subtarget.hasStdExtZfinx())
96 if (Subtarget.hasStdExtZdinx()) {
97 if (Subtarget.is64Bit())
104 MVT::nxv1i1, MVT::nxv2i1, MVT::nxv4i1, MVT::nxv8i1,
105 MVT::nxv16i1, MVT::nxv32i1, MVT::nxv64i1};
107 MVT::nxv1i8, MVT::nxv2i8, MVT::nxv4i8, MVT::nxv8i8, MVT::nxv16i8,
108 MVT::nxv32i8, MVT::nxv64i8, MVT::nxv1i16, MVT::nxv2i16, MVT::nxv4i16,
109 MVT::nxv8i16, MVT::nxv16i16, MVT::nxv32i16, MVT::nxv1i32, MVT::nxv2i32,
110 MVT::nxv4i32, MVT::nxv8i32, MVT::nxv16i32, MVT::nxv1i64, MVT::nxv2i64,
111 MVT::nxv4i64, MVT::nxv8i64};
113 MVT::nxv1f16, MVT::nxv2f16, MVT::nxv4f16,
114 MVT::nxv8f16, MVT::nxv16f16, MVT::nxv32f16};
116 MVT::nxv1bf16, MVT::nxv2bf16, MVT::nxv4bf16,
117 MVT::nxv8bf16, MVT::nxv16bf16, MVT::nxv32bf16};
119 MVT::nxv1f32, MVT::nxv2f32, MVT::nxv4f32, MVT::nxv8f32, MVT::nxv16f32};
121 MVT::nxv1f64, MVT::nxv2f64, MVT::nxv4f64, MVT::nxv8f64};
123 MVT::riscv_nxv1i8x2, MVT::riscv_nxv1i8x3, MVT::riscv_nxv1i8x4,
124 MVT::riscv_nxv1i8x5, MVT::riscv_nxv1i8x6, MVT::riscv_nxv1i8x7,
125 MVT::riscv_nxv1i8x8, MVT::riscv_nxv2i8x2, MVT::riscv_nxv2i8x3,
126 MVT::riscv_nxv2i8x4, MVT::riscv_nxv2i8x5, MVT::riscv_nxv2i8x6,
127 MVT::riscv_nxv2i8x7, MVT::riscv_nxv2i8x8, MVT::riscv_nxv4i8x2,
128 MVT::riscv_nxv4i8x3, MVT::riscv_nxv4i8x4, MVT::riscv_nxv4i8x5,
129 MVT::riscv_nxv4i8x6, MVT::riscv_nxv4i8x7, MVT::riscv_nxv4i8x8,
130 MVT::riscv_nxv8i8x2, MVT::riscv_nxv8i8x3, MVT::riscv_nxv8i8x4,
131 MVT::riscv_nxv8i8x5, MVT::riscv_nxv8i8x6, MVT::riscv_nxv8i8x7,
132 MVT::riscv_nxv8i8x8, MVT::riscv_nxv16i8x2, MVT::riscv_nxv16i8x3,
133 MVT::riscv_nxv16i8x4, MVT::riscv_nxv32i8x2};
135 if (Subtarget.hasVInstructions()) {
136 auto addRegClassForRVV = [
this](
MVT VT) {
140 if (VT.getVectorMinNumElements() < MinElts)
143 unsigned Size = VT.getSizeInBits().getKnownMinValue();
146 RC = &RISCV::VRRegClass;
148 RC = &RISCV::VRM2RegClass;
150 RC = &RISCV::VRM4RegClass;
152 RC = &RISCV::VRM8RegClass;
159 for (
MVT VT : BoolVecVTs)
160 addRegClassForRVV(VT);
161 for (
MVT VT : IntVecVTs) {
162 if (VT.getVectorElementType() == MVT::i64 &&
163 !Subtarget.hasVInstructionsI64())
165 addRegClassForRVV(VT);
168 if (Subtarget.hasVInstructionsF16Minimal() ||
169 Subtarget.hasVendorXAndesVPackFPH())
170 for (
MVT VT : F16VecVTs)
171 addRegClassForRVV(VT);
173 if (Subtarget.hasVInstructionsBF16Minimal() ||
174 Subtarget.hasVendorXAndesVBFHCvt())
175 for (
MVT VT : BF16VecVTs)
176 addRegClassForRVV(VT);
178 if (Subtarget.hasVInstructionsF32())
179 for (
MVT VT : F32VecVTs)
180 addRegClassForRVV(VT);
182 if (Subtarget.hasVInstructionsF64())
183 for (
MVT VT : F64VecVTs)
184 addRegClassForRVV(VT);
186 if (Subtarget.useRVVForFixedLengthVectors()) {
187 auto addRegClassForFixedVectors = [
this](
MVT VT) {
194 if (useRVVForFixedLengthVectorVT(VT))
195 addRegClassForFixedVectors(VT);
198 if (useRVVForFixedLengthVectorVT(VT))
199 addRegClassForFixedVectors(VT);
237 if (Subtarget.hasStdExtP()) {
238 if (Subtarget.is64Bit()) {
275 if (!(Subtarget.hasVendorXCValu() && !Subtarget.is64Bit())) {
285 if (!Subtarget.hasVendorXTHeadBb() && !Subtarget.hasVendorXqcibm() &&
286 !Subtarget.hasVendorXAndesPerf())
291 if (!Subtarget.hasStdExtZbb() && !Subtarget.hasVendorXTHeadBb() &&
292 !Subtarget.hasVendorXqcibm() && !Subtarget.hasVendorXAndesPerf() &&
293 !(Subtarget.hasVendorXCValu() && !Subtarget.is64Bit()))
296 if (Subtarget.hasStdExtZilsd() && !Subtarget.is64Bit()) {
301 if (Subtarget.is64Bit()) {
309 }
else if (Subtarget.hasStdExtP()) {
314 if (!Subtarget.hasStdExtZmmul()) {
316 }
else if (Subtarget.is64Bit()) {
323 if (!Subtarget.hasStdExtM()) {
326 }
else if (Subtarget.is64Bit()) {
328 {MVT::i8, MVT::i16, MVT::i32},
Custom);
336 if (!Subtarget.hasStdExtP() || !Subtarget.hasStdExtZmmul() ||
343 if (Subtarget.hasStdExtZbb() || Subtarget.hasStdExtZbkb()) {
344 if (Subtarget.is64Bit())
346 }
else if (Subtarget.hasVendorXTHeadBb()) {
347 if (Subtarget.is64Bit())
350 }
else if (Subtarget.hasVendorXCVbitmanip() && !Subtarget.is64Bit()) {
356 if (Subtarget.hasStdExtP()) {
358 if (!Subtarget.is64Bit())
365 if (Subtarget.hasREVLike()) {
371 if (Subtarget.hasStdExtZbkb())
375 if (Subtarget.hasStdExtZbb() ||
376 (Subtarget.hasVendorXCValu() && !Subtarget.is64Bit())) {
381 if (Subtarget.hasCTZLike()) {
382 if (Subtarget.is64Bit())
388 if (!Subtarget.hasCPOPLike()) {
391 if (Subtarget.is64Bit())
398 if (Subtarget.hasCLZLike()) {
402 if (Subtarget.is64Bit() &&
403 (Subtarget.hasStdExtZbb() || Subtarget.hasStdExtP()))
406 if (Subtarget.hasVendorXCVbitmanip() && !Subtarget.is64Bit())
411 if (Subtarget.hasStdExtP()) {
413 if (Subtarget.is64Bit())
417 if (Subtarget.hasStdExtP() ||
418 (Subtarget.hasVendorXCValu() && !Subtarget.is64Bit())) {
420 if (Subtarget.is64Bit())
422 }
else if (Subtarget.hasShortForwardBranchIALU()) {
425 }
else if (Subtarget.is64Bit()) {
429 if (!Subtarget.useMIPSCCMovInsn() && !Subtarget.hasVendorXTHeadCondMov())
432 if ((Subtarget.hasStdExtP() || Subtarget.hasVendorXqcia()) &&
433 !Subtarget.is64Bit()) {
436 }
else if (Subtarget.hasStdExtP() && Subtarget.is64Bit()) {
439 }
else if (!Subtarget.hasStdExtZbb() && Subtarget.is64Bit()) {
444 if ((Subtarget.hasStdExtP() || Subtarget.hasVendorXqcia()) &&
445 !Subtarget.is64Bit()) {
452 if (Subtarget.hasStdExtP() && !Subtarget.is64Bit()) {
460 if (Subtarget.hasStdExtZbkc()) {
462 if (Subtarget.hasStdExtZbc())
464 }
else if (Subtarget.hasStdExtZvbc() && Subtarget.is64Bit()) {
471 static const unsigned FPLegalNodeTypes[] = {
487 static const unsigned FPOpToLibCall[] = {
ISD::FREM};
489 static const unsigned FPRndMode[] = {
493 static const unsigned ZfhminZfbfminPromoteOps[] = {
505 if (Subtarget.hasStdExtP()) {
506 static const MVT P32VecVTs[] = {MVT::v2i16, MVT::v4i8};
507 static const MVT P64VecVTs[] = {MVT::v2i32, MVT::v4i16, MVT::v8i8};
509 if (Subtarget.is64Bit()) {
516 {MVT::v2i16, MVT::v4i8},
Custom);
548 if (VT != MVT::v2i32)
550 if (VT.getVectorElementType() != MVT::i8) {
573 if (!Subtarget.is64Bit())
581 if (!Subtarget.is64Bit()) {
586 for (
MVT VT : P64VecVTs) {
611 {MVT::v4i16, MVT::v8i8},
Legal);
630 {MVT::v4i16, MVT::v8i8},
Custom);
635 {MVT::v4i16, MVT::v2i32},
Legal);
652 {MVT::v4i16, MVT::v2i32},
Legal);
660 {MVT::v2i8, MVT::v4i8, MVT::v2i16, MVT::v4i16, MVT::v2i32},
Legal);
663 if (Subtarget.hasStdExtZfbfmin()) {
679 if (Subtarget.hasStdExtZfhminOrZhinxmin()) {
680 if (Subtarget.hasStdExtZfhmin())
682 if (Subtarget.hasStdExtZfhOrZhinx()) {
689 if (Subtarget.hasStdExtZfa())
705 if (!Subtarget.hasStdExtD()) {
725 Subtarget.hasStdExtZfh() && Subtarget.hasStdExtZfa() ?
Legal :
Promote);
741 if (Subtarget.is64Bit())
745 if (Subtarget.hasStdExtFOrZfinx()) {
746 if (Subtarget.hasStdExtF())
770 if (Subtarget.hasStdExtZfa()) {
779 if (Subtarget.hasStdExtFOrZfinx() && Subtarget.is64Bit())
782 if (Subtarget.hasStdExtDOrZdinx()) {
783 if (Subtarget.hasStdExtD())
787 if (!Subtarget.is64Bit())
790 if (Subtarget.hasStdExtZdinx() && !Subtarget.hasStdExtZilsd() &&
791 !Subtarget.is64Bit()) {
796 if (Subtarget.hasStdExtZfa()) {
802 if (Subtarget.is64Bit())
832 if (Subtarget.is64Bit()) {
837 }
else if (Subtarget.hasStdExtZfhminOrZhinxmin()) {
846 if (Subtarget.hasStdExtFOrZfinx()) {
872 if (Subtarget.is64Bit())
882 if (Subtarget.is64Bit()) {
889 if (Subtarget.is64Bit())
892 if (Subtarget.hasVendorXMIPSCBOP())
897 if (Subtarget.hasStdExtZalrsc()) {
899 if (Subtarget.hasStdExtZabha() && Subtarget.hasStdExtZacas())
903 }
else if (Subtarget.hasForcedAtomics()) {
918 if (Subtarget.hasVInstructions()) {
927 {MVT::i8, MVT::i16},
Custom);
928 if (Subtarget.is64Bit())
938 static const unsigned IntegerVPOps[] = {
939 ISD::VP_SDIV, ISD::VP_UDIV, ISD::VP_SREM,
940 ISD::VP_UREM, ISD::VP_REDUCE_ADD, ISD::VP_REDUCE_AND,
941 ISD::VP_REDUCE_OR, ISD::VP_REDUCE_XOR, ISD::VP_REDUCE_SMAX,
942 ISD::VP_REDUCE_SMIN, ISD::VP_REDUCE_UMAX, ISD::VP_REDUCE_UMIN,
944 ISD::EXPERIMENTAL_VP_REVERSE, ISD::EXPERIMENTAL_VP_SPLICE,
945 ISD::VP_CTTZ_ELTS, ISD::VP_CTTZ_ELTS_ZERO_POISON};
947 static const unsigned FloatingPointVPOps[] = {
948 ISD::VP_REDUCE_FADD, ISD::VP_REDUCE_SEQ_FADD,
949 ISD::VP_REDUCE_FMIN, ISD::VP_REDUCE_FMAX, ISD::VP_MERGE,
950 ISD::VP_REDUCE_FMINIMUM, ISD::VP_REDUCE_FMAXIMUM};
952 static const unsigned IntegerVecReduceOps[] = {
957 static const unsigned FloatingPointVecReduceOps[] = {
961 static const unsigned FloatingPointLibCallOps[] = {
965 if (!Subtarget.is64Bit()) {
974 ISD::VP_REDUCE_OR, ISD::VP_REDUCE_XOR,
975 ISD::VP_REDUCE_SMAX, ISD::VP_REDUCE_SMIN,
976 ISD::VP_REDUCE_UMAX, ISD::VP_REDUCE_UMIN},
980 for (
MVT VT : BoolVecVTs) {
1001 ISD::VP_CTTZ_ELTS, ISD::VP_CTTZ_ELTS_ZERO_POISON},
1009 {ISD::VP_REDUCE_AND, ISD::VP_REDUCE_OR, ISD::VP_REDUCE_XOR}, VT,
1034 {2, 3, 4, 5, 6, 7, 8}, VT,
Custom);
1048 for (
MVT VT : IntVecVTs) {
1059 if (VT.getVectorElementType() == MVT::i64 && !Subtarget.hasStdExtV())
1065 if (Subtarget.hasStdExtZvabd()) {
1087 if (!Subtarget.avoidVXRM())
1116 {ISD::VP_LOAD, ISD::VP_STORE, ISD::EXPERIMENTAL_VP_STRIDED_LOAD,
1117 ISD::EXPERIMENTAL_VP_STRIDED_STORE, ISD::VP_GATHER, ISD::VP_SCATTER},
1138 {2, 3, 4, 5, 6, 7, 8}, VT,
Custom);
1143 if (Subtarget.hasStdExtZvkb()) {
1150 if (Subtarget.hasStdExtZvbb()) {
1166 if (VT.getVectorElementType() == MVT::i64) {
1167 if (Subtarget.hasStdExtZvbc())
1170 if (Subtarget.hasStdExtZvbc32e()) {
1172 }
else if (Subtarget.hasStdExtZvbc()) {
1188 for (
MVT VT : VecTupleVTs) {
1209 static const unsigned ZvfhminZvfbfminPromoteOps[] = {
1245 static const unsigned ZvfbfaPromoteOps[] = {
ISD::FDIV,
1263 static const unsigned ZvfhminZvfbfminPromoteVPOps[] = {
1264 ISD::VP_REDUCE_FMIN,
1265 ISD::VP_REDUCE_FMAX,
1266 ISD::VP_REDUCE_FMINIMUM,
1267 ISD::VP_REDUCE_FMAXIMUM};
1270 const auto SetCommonVFPActions = [&](
MVT VT) {
1310 {ISD::VP_LOAD, ISD::VP_STORE, ISD::EXPERIMENTAL_VP_STRIDED_LOAD,
1311 ISD::EXPERIMENTAL_VP_STRIDED_STORE, ISD::VP_GATHER, ISD::VP_SCATTER},
1324 {2, 3, 4, 5, 6, 7, 8}, VT,
Custom);
1350 const auto SetCommonVFPExtLoadTruncStoreActions =
1352 for (
auto SmallVT : SmallerVTs) {
1360 const auto SetCommonPromoteToF32Actions = [&](
MVT VT) {
1376 {2, 3, 4, 5, 6, 7, 8}, VT,
Custom);
1387 ISD::VP_STORE, ISD::EXPERIMENTAL_VP_STRIDED_LOAD,
1388 ISD::EXPERIMENTAL_VP_STRIDED_STORE, ISD::VP_GATHER,
1415 const auto SetZvfbfaActions = [&](
MVT VT) {
1432 {2, 3, 4, 5, 6, 7, 8}, VT,
Custom);
1450 ISD::VP_STORE, ISD::EXPERIMENTAL_VP_STRIDED_LOAD,
1451 ISD::EXPERIMENTAL_VP_STRIDED_STORE, ISD::VP_GATHER,
1472 if (Subtarget.hasVInstructionsF16()) {
1473 for (
MVT VT : F16VecVTs) {
1476 SetCommonVFPActions(VT);
1478 }
else if (Subtarget.hasVInstructionsF16Minimal()) {
1479 for (
MVT VT : F16VecVTs) {
1482 SetCommonPromoteToF32Actions(VT);
1486 if (Subtarget.hasVInstructionsBF16()) {
1487 for (
MVT VT : BF16VecVTs) {
1490 SetZvfbfaActions(VT);
1492 }
else if (Subtarget.hasVInstructionsBF16Minimal()) {
1493 for (
MVT VT : BF16VecVTs) {
1496 SetCommonPromoteToF32Actions(VT);
1500 if (Subtarget.hasStdExtZvfofp8min()) {
1501 for (
MVT VT : BF16VecVTs) {
1508 if (Subtarget.hasVInstructionsF32()) {
1509 for (
MVT VT : F32VecVTs) {
1512 SetCommonVFPActions(VT);
1513 SetCommonVFPExtLoadTruncStoreActions(VT, F16VecVTs);
1514 SetCommonVFPExtLoadTruncStoreActions(VT, BF16VecVTs);
1518 if (Subtarget.hasVInstructionsF64()) {
1519 for (
MVT VT : F64VecVTs) {
1522 SetCommonVFPActions(VT);
1523 SetCommonVFPExtLoadTruncStoreActions(VT, F16VecVTs);
1524 SetCommonVFPExtLoadTruncStoreActions(VT, BF16VecVTs);
1525 SetCommonVFPExtLoadTruncStoreActions(VT, F32VecVTs);
1529 if (Subtarget.useRVVForFixedLengthVectors()) {
1531 if (!useRVVForFixedLengthVectorVT(VT))
1557 {2, 3, 4, 5, 6, 7, 8}, VT,
Custom);
1581 {ISD::VP_REDUCE_AND, ISD::VP_REDUCE_OR, ISD::VP_REDUCE_XOR}, VT,
1634 ISD::EXPERIMENTAL_VP_STRIDED_LOAD,
1635 ISD::EXPERIMENTAL_VP_STRIDED_STORE, ISD::VP_GATHER,
1654 if (!Subtarget.avoidVXRM())
1676 if (Subtarget.hasStdExtZvkb())
1679 if (Subtarget.hasStdExtZvbb()) {
1694 if (Subtarget.hasStdExtZvbc())
1697 if (Subtarget.hasStdExtZvbc32e()) {
1699 }
else if (Subtarget.hasStdExtZvbc()) {
1703 if (I64VecVT.
isValid() && useRVVForFixedLengthVectorVT(I64VecVT))
1721 if (!useRVVForFixedLengthVectorVT(VT))
1742 {2, 3, 4, 5, 6, 7, 8}, VT,
Custom);
1748 ISD::VP_SCATTER, ISD::EXPERIMENTAL_VP_STRIDED_LOAD,
1749 ISD::EXPERIMENTAL_VP_STRIDED_STORE},
1760 !Subtarget.hasVInstructionsF16()) {
1766 if (Subtarget.hasStdExtZfhmin()) {
1797 if (Subtarget.hasStdExtZvfofp8min())
1799 if (Subtarget.hasStdExtZfbfmin()) {
1806 if (Subtarget.hasVInstructionsBF16()) {
1827 if (Subtarget.hasVInstructionsBF16())
1871 if (Subtarget.is64Bit())
1873 if (Subtarget.hasStdExtZfhminOrZhinxmin())
1875 if (Subtarget.hasStdExtZfbfmin())
1877 if (Subtarget.hasStdExtFOrZfinx())
1879 if (Subtarget.hasStdExtDOrZdinx())
1884 if (Subtarget.hasStdExtZaamo())
1886 {MVT::i8, MVT::i16, MVT::i32, XLenVT},
Expand);
1888 if (Subtarget.hasForcedAtomics()) {
1895 {MVT::i8, MVT::i16, MVT::i32, XLenVT},
LibCall);
1898 if (Subtarget.hasVendorXTHeadMemIdx()) {
1907 if (Subtarget.is64Bit()) {
1914 if (Subtarget.hasVendorXCVmem() && !Subtarget.is64Bit()) {
1925 if (Subtarget.hasStdExtZvdot4a8i() && Subtarget.getELen() >= 64) {
1942 if (Subtarget.useRVVForFixedLengthVectors()) {
1944 if ((VT.getVectorElementType() != MVT::i32 &&
1945 VT.getVectorElementType() != MVT::i64) ||
1946 !useRVVForFixedLengthVectorVT(VT))
1949 unsigned Scale = VT.getVectorElementType() == MVT::i64 ? 8 : 4;
1957 if (Subtarget.hasVendorXAndesBFHCvt() && !Subtarget.hasStdExtZfh()) {
1963 const Align FunctionAlignment(Subtarget.hasStdExtZca() ? 2 : 4);
1975 if (Subtarget.hasStdExtFOrZfinx())
1979 if (Subtarget.hasVInstructions())
1981 if (Subtarget.hasVInstructions() || Subtarget.hasStdExtP())
1984 if ((Subtarget.hasStdExtZbs() && Subtarget.is64Bit()) ||
1985 Subtarget.hasVInstructions() || Subtarget.hasStdExtP())
1988 if (Subtarget.hasStdExtZbkb())
1991 if (Subtarget.hasStdExtZbc() && Subtarget.is64Bit())
1994 if (Subtarget.hasStdExtFOrZfinx())
1997 if (Subtarget.hasVInstructions())
2012 ISD::EXPERIMENTAL_VP_REVERSE,
2027 if (Subtarget.hasStdExtZvzip())
2030 if (Subtarget.hasVendorXTHeadMemPair())
2032 if (Subtarget.useRVVForFixedLengthVectors() || Subtarget.hasStdExtP())
2034 if (Subtarget.hasStdExtP() && Subtarget.is64Bit())
2060 Subtarget.getMaxStoresPerMemmove(
true);
2069 if (Subtarget.is64Bit() && Subtarget.hasStdExtP())
2070 if (VT == MVT::v2i16 || VT == MVT::v4i8)
2081 if (Subtarget.hasVInstructions() &&
2092 if (
F->hasOptSize())
2099 const RISCVOptions &CLOpts = Subtarget.getCLOpts();
2100 int BaseCost = CLOpts.br_merging_base_cost.value_or(
2101 Subtarget.getMispredictionPenalty() / 4);
2102 return {BaseCost, CLOpts.br_merging_likely_bias,
2103 CLOpts.br_merging_unlikely_bias};
2110bool RISCVTargetLowering::isProfitableToFoldVScaleAdd(
SDValue N)
const {
2111 return N.hasOneUse();
2115bool RISCVTargetLowering::shouldExpandGetVectorLength(
EVT TripCountVT,
2118 if (!Subtarget.hasVInstructions())
2124 if (TripCountVT != MVT::i32 && TripCountVT != Subtarget.getXLenVT())
2145 auto &
DL =
I.getDataLayout();
2147 auto SetRVVLoadStoreInfo = [&](
unsigned PtrOp,
bool IsStore,
2148 bool IsUnitStrided,
bool UsePtrVal =
false) {
2153 Info.ptrVal =
I.getArgOperand(PtrOp);
2155 Info.fallbackAddressSpace =
2156 I.getArgOperand(PtrOp)->getType()->getPointerAddressSpace();
2160 MemTy =
I.getArgOperand(0)->getType();
2163 MemTy =
I.getType();
2178 Info.align =
DL.getABITypeAlign(MemTy);
2188 if (
I.hasMetadata(LLVMContext::MD_nontemporal))
2195 case Intrinsic::riscv_masked_atomicrmw_xchg:
2196 case Intrinsic::riscv_masked_atomicrmw_add:
2197 case Intrinsic::riscv_masked_atomicrmw_sub:
2198 case Intrinsic::riscv_masked_atomicrmw_nand:
2199 case Intrinsic::riscv_masked_atomicrmw_max:
2200 case Intrinsic::riscv_masked_atomicrmw_min:
2201 case Intrinsic::riscv_masked_atomicrmw_umax:
2202 case Intrinsic::riscv_masked_atomicrmw_umin:
2203 case Intrinsic::riscv_masked_cmpxchg:
2210 Info.memVT = MVT::i32;
2211 Info.ptrVal =
I.getArgOperand(0);
2213 Info.align =
Align(4);
2218 case Intrinsic::riscv_seg2_load_mask:
2219 case Intrinsic::riscv_seg3_load_mask:
2220 case Intrinsic::riscv_seg4_load_mask:
2221 case Intrinsic::riscv_seg5_load_mask:
2222 case Intrinsic::riscv_seg6_load_mask:
2223 case Intrinsic::riscv_seg7_load_mask:
2224 case Intrinsic::riscv_seg8_load_mask:
2225 case Intrinsic::riscv_sseg2_load_mask:
2226 case Intrinsic::riscv_sseg3_load_mask:
2227 case Intrinsic::riscv_sseg4_load_mask:
2228 case Intrinsic::riscv_sseg5_load_mask:
2229 case Intrinsic::riscv_sseg6_load_mask:
2230 case Intrinsic::riscv_sseg7_load_mask:
2231 case Intrinsic::riscv_sseg8_load_mask:
2232 SetRVVLoadStoreInfo( 0,
false,
2235 case Intrinsic::riscv_seg2_store_mask:
2236 case Intrinsic::riscv_seg3_store_mask:
2237 case Intrinsic::riscv_seg4_store_mask:
2238 case Intrinsic::riscv_seg5_store_mask:
2239 case Intrinsic::riscv_seg6_store_mask:
2240 case Intrinsic::riscv_seg7_store_mask:
2241 case Intrinsic::riscv_seg8_store_mask:
2243 SetRVVLoadStoreInfo(
I.arg_size() - 3,
2247 case Intrinsic::riscv_sseg2_store_mask:
2248 case Intrinsic::riscv_sseg3_store_mask:
2249 case Intrinsic::riscv_sseg4_store_mask:
2250 case Intrinsic::riscv_sseg5_store_mask:
2251 case Intrinsic::riscv_sseg6_store_mask:
2252 case Intrinsic::riscv_sseg7_store_mask:
2253 case Intrinsic::riscv_sseg8_store_mask:
2255 SetRVVLoadStoreInfo(
I.arg_size() - 4,
2259 case Intrinsic::riscv_vlm:
2260 SetRVVLoadStoreInfo( 0,
2265 case Intrinsic::riscv_vle:
2266 case Intrinsic::riscv_vle_mask:
2267 case Intrinsic::riscv_vleff:
2268 case Intrinsic::riscv_vleff_mask:
2269 SetRVVLoadStoreInfo( 1,
2274 case Intrinsic::riscv_vsm:
2275 case Intrinsic::riscv_vse:
2276 case Intrinsic::riscv_vse_mask:
2277 SetRVVLoadStoreInfo( 1,
2282 case Intrinsic::riscv_vlse:
2283 case Intrinsic::riscv_vlse_mask:
2284 case Intrinsic::riscv_vloxei:
2285 case Intrinsic::riscv_vloxei_mask:
2286 case Intrinsic::riscv_vluxei:
2287 case Intrinsic::riscv_vluxei_mask:
2288 SetRVVLoadStoreInfo( 1,
2292 case Intrinsic::riscv_vsse:
2293 case Intrinsic::riscv_vsse_mask:
2294 case Intrinsic::riscv_vsoxei:
2295 case Intrinsic::riscv_vsoxei_mask:
2296 case Intrinsic::riscv_vsuxei:
2297 case Intrinsic::riscv_vsuxei_mask:
2298 SetRVVLoadStoreInfo( 1,
2302 case Intrinsic::riscv_vlseg2:
2303 case Intrinsic::riscv_vlseg3:
2304 case Intrinsic::riscv_vlseg4:
2305 case Intrinsic::riscv_vlseg5:
2306 case Intrinsic::riscv_vlseg6:
2307 case Intrinsic::riscv_vlseg7:
2308 case Intrinsic::riscv_vlseg8:
2309 case Intrinsic::riscv_vlseg2ff:
2310 case Intrinsic::riscv_vlseg3ff:
2311 case Intrinsic::riscv_vlseg4ff:
2312 case Intrinsic::riscv_vlseg5ff:
2313 case Intrinsic::riscv_vlseg6ff:
2314 case Intrinsic::riscv_vlseg7ff:
2315 case Intrinsic::riscv_vlseg8ff:
2316 SetRVVLoadStoreInfo(
I.arg_size() - 3,
2320 case Intrinsic::riscv_vlseg2_mask:
2321 case Intrinsic::riscv_vlseg3_mask:
2322 case Intrinsic::riscv_vlseg4_mask:
2323 case Intrinsic::riscv_vlseg5_mask:
2324 case Intrinsic::riscv_vlseg6_mask:
2325 case Intrinsic::riscv_vlseg7_mask:
2326 case Intrinsic::riscv_vlseg8_mask:
2327 case Intrinsic::riscv_vlseg2ff_mask:
2328 case Intrinsic::riscv_vlseg3ff_mask:
2329 case Intrinsic::riscv_vlseg4ff_mask:
2330 case Intrinsic::riscv_vlseg5ff_mask:
2331 case Intrinsic::riscv_vlseg6ff_mask:
2332 case Intrinsic::riscv_vlseg7ff_mask:
2333 case Intrinsic::riscv_vlseg8ff_mask:
2334 SetRVVLoadStoreInfo(
I.arg_size() - 5,
2338 case Intrinsic::riscv_vlsseg2:
2339 case Intrinsic::riscv_vlsseg3:
2340 case Intrinsic::riscv_vlsseg4:
2341 case Intrinsic::riscv_vlsseg5:
2342 case Intrinsic::riscv_vlsseg6:
2343 case Intrinsic::riscv_vlsseg7:
2344 case Intrinsic::riscv_vlsseg8:
2345 case Intrinsic::riscv_vloxseg2:
2346 case Intrinsic::riscv_vloxseg3:
2347 case Intrinsic::riscv_vloxseg4:
2348 case Intrinsic::riscv_vloxseg5:
2349 case Intrinsic::riscv_vloxseg6:
2350 case Intrinsic::riscv_vloxseg7:
2351 case Intrinsic::riscv_vloxseg8:
2352 case Intrinsic::riscv_vluxseg2:
2353 case Intrinsic::riscv_vluxseg3:
2354 case Intrinsic::riscv_vluxseg4:
2355 case Intrinsic::riscv_vluxseg5:
2356 case Intrinsic::riscv_vluxseg6:
2357 case Intrinsic::riscv_vluxseg7:
2358 case Intrinsic::riscv_vluxseg8:
2359 SetRVVLoadStoreInfo(
I.arg_size() - 4,
2363 case Intrinsic::riscv_vlsseg2_mask:
2364 case Intrinsic::riscv_vlsseg3_mask:
2365 case Intrinsic::riscv_vlsseg4_mask:
2366 case Intrinsic::riscv_vlsseg5_mask:
2367 case Intrinsic::riscv_vlsseg6_mask:
2368 case Intrinsic::riscv_vlsseg7_mask:
2369 case Intrinsic::riscv_vlsseg8_mask:
2370 case Intrinsic::riscv_vloxseg2_mask:
2371 case Intrinsic::riscv_vloxseg3_mask:
2372 case Intrinsic::riscv_vloxseg4_mask:
2373 case Intrinsic::riscv_vloxseg5_mask:
2374 case Intrinsic::riscv_vloxseg6_mask:
2375 case Intrinsic::riscv_vloxseg7_mask:
2376 case Intrinsic::riscv_vloxseg8_mask:
2377 case Intrinsic::riscv_vluxseg2_mask:
2378 case Intrinsic::riscv_vluxseg3_mask:
2379 case Intrinsic::riscv_vluxseg4_mask:
2380 case Intrinsic::riscv_vluxseg5_mask:
2381 case Intrinsic::riscv_vluxseg6_mask:
2382 case Intrinsic::riscv_vluxseg7_mask:
2383 case Intrinsic::riscv_vluxseg8_mask:
2384 SetRVVLoadStoreInfo(
I.arg_size() - 6,
2388 case Intrinsic::riscv_vsseg2:
2389 case Intrinsic::riscv_vsseg3:
2390 case Intrinsic::riscv_vsseg4:
2391 case Intrinsic::riscv_vsseg5:
2392 case Intrinsic::riscv_vsseg6:
2393 case Intrinsic::riscv_vsseg7:
2394 case Intrinsic::riscv_vsseg8:
2395 SetRVVLoadStoreInfo(
I.arg_size() - 3,
2399 case Intrinsic::riscv_vsseg2_mask:
2400 case Intrinsic::riscv_vsseg3_mask:
2401 case Intrinsic::riscv_vsseg4_mask:
2402 case Intrinsic::riscv_vsseg5_mask:
2403 case Intrinsic::riscv_vsseg6_mask:
2404 case Intrinsic::riscv_vsseg7_mask:
2405 case Intrinsic::riscv_vsseg8_mask:
2406 SetRVVLoadStoreInfo(
I.arg_size() - 4,
2410 case Intrinsic::riscv_vssseg2:
2411 case Intrinsic::riscv_vssseg3:
2412 case Intrinsic::riscv_vssseg4:
2413 case Intrinsic::riscv_vssseg5:
2414 case Intrinsic::riscv_vssseg6:
2415 case Intrinsic::riscv_vssseg7:
2416 case Intrinsic::riscv_vssseg8:
2417 case Intrinsic::riscv_vsoxseg2:
2418 case Intrinsic::riscv_vsoxseg3:
2419 case Intrinsic::riscv_vsoxseg4:
2420 case Intrinsic::riscv_vsoxseg5:
2421 case Intrinsic::riscv_vsoxseg6:
2422 case Intrinsic::riscv_vsoxseg7:
2423 case Intrinsic::riscv_vsoxseg8:
2424 case Intrinsic::riscv_vsuxseg2:
2425 case Intrinsic::riscv_vsuxseg3:
2426 case Intrinsic::riscv_vsuxseg4:
2427 case Intrinsic::riscv_vsuxseg5:
2428 case Intrinsic::riscv_vsuxseg6:
2429 case Intrinsic::riscv_vsuxseg7:
2430 case Intrinsic::riscv_vsuxseg8:
2431 SetRVVLoadStoreInfo(
I.arg_size() - 4,
2435 case Intrinsic::riscv_vssseg2_mask:
2436 case Intrinsic::riscv_vssseg3_mask:
2437 case Intrinsic::riscv_vssseg4_mask:
2438 case Intrinsic::riscv_vssseg5_mask:
2439 case Intrinsic::riscv_vssseg6_mask:
2440 case Intrinsic::riscv_vssseg7_mask:
2441 case Intrinsic::riscv_vssseg8_mask:
2442 case Intrinsic::riscv_vsoxseg2_mask:
2443 case Intrinsic::riscv_vsoxseg3_mask:
2444 case Intrinsic::riscv_vsoxseg4_mask:
2445 case Intrinsic::riscv_vsoxseg5_mask:
2446 case Intrinsic::riscv_vsoxseg6_mask:
2447 case Intrinsic::riscv_vsoxseg7_mask:
2448 case Intrinsic::riscv_vsoxseg8_mask:
2449 case Intrinsic::riscv_vsuxseg2_mask:
2450 case Intrinsic::riscv_vsuxseg3_mask:
2451 case Intrinsic::riscv_vsuxseg4_mask:
2452 case Intrinsic::riscv_vsuxseg5_mask:
2453 case Intrinsic::riscv_vsuxseg6_mask:
2454 case Intrinsic::riscv_vsuxseg7_mask:
2455 case Intrinsic::riscv_vsuxseg8_mask:
2456 SetRVVLoadStoreInfo(
I.arg_size() - 5,
2460 case Intrinsic::riscv_sf_vlte8:
2461 case Intrinsic::riscv_sf_vlte16:
2462 case Intrinsic::riscv_sf_vlte32:
2463 case Intrinsic::riscv_sf_vlte64:
2465 Info.ptrVal =
I.getArgOperand(1);
2467 case Intrinsic::riscv_sf_vlte8:
2468 Info.memVT = MVT::i8;
2469 Info.align =
Align(1);
2471 case Intrinsic::riscv_sf_vlte16:
2472 Info.memVT = MVT::i16;
2473 Info.align =
Align(2);
2475 case Intrinsic::riscv_sf_vlte32:
2476 Info.memVT = MVT::i32;
2477 Info.align =
Align(4);
2479 case Intrinsic::riscv_sf_vlte64:
2480 Info.memVT = MVT::i64;
2481 Info.align =
Align(8);
2488 case Intrinsic::riscv_sf_vste8:
2489 case Intrinsic::riscv_sf_vste16:
2490 case Intrinsic::riscv_sf_vste32:
2491 case Intrinsic::riscv_sf_vste64:
2493 Info.ptrVal =
I.getArgOperand(1);
2495 case Intrinsic::riscv_sf_vste8:
2496 Info.memVT = MVT::i8;
2497 Info.align =
Align(1);
2499 case Intrinsic::riscv_sf_vste16:
2500 Info.memVT = MVT::i16;
2501 Info.align =
Align(2);
2503 case Intrinsic::riscv_sf_vste32:
2504 Info.memVT = MVT::i32;
2505 Info.align =
Align(4);
2507 case Intrinsic::riscv_sf_vste64:
2508 Info.memVT = MVT::i64;
2509 Info.align =
Align(8);
2537 if (Subtarget.hasVendorXqcilo()) {
2566 if (Subtarget.hasVendorXqcilia())
2577 if (Subtarget.is64Bit() || !SrcTy->isIntegerTy() || !DstTy->
isIntegerTy())
2579 unsigned SrcBits = SrcTy->getPrimitiveSizeInBits();
2581 return (SrcBits == 64 && DestBits == 32);
2592 return (SrcBits == 64 && DestBits == 32);
2598 if (Subtarget.hasVInstructions() &&
2603 if (SrcBits == DestBits * 2) {
2615 EVT MemVT = LD->getMemoryVT();
2616 if ((MemVT == MVT::i8 || MemVT == MVT::i16) &&
2626 return Subtarget.is64Bit() && SrcVT == MVT::i32 && DstVT == MVT::i64;
2634 return Subtarget.hasCTZLike();
2638 return Subtarget.hasCLZLike();
2649 if (!Subtarget.hasBEXTILike())
2654 return !Mask->getValue().isSignedIntN(12) && Mask->getValue().isPowerOf2();
2658 EVT VT =
Y.getValueType();
2663 return (Subtarget.hasStdExtZbb() || Subtarget.hasStdExtZbkb()) &&
2668 EVT VT =
Y.getValueType();
2675 return Subtarget.hasVInstructions();
2677 return Subtarget.hasStdExtZvkb();
2682 if (Subtarget.hasStdExtZbs())
2683 return X.getValueType().isScalarInteger();
2686 if (Subtarget.hasVendorXTHeadBs())
2687 return C !=
nullptr;
2689 return C &&
C->getAPIntValue().ule(10);
2693 unsigned BinOpcode,
EVT VT,
unsigned SelectOpcode,
SDValue X,
2699 if (!VT.
isVector() || !Subtarget.hasVInstructions())
2710 assert(Ty->isIntegerTy());
2712 unsigned BitSize = Ty->getIntegerBitWidth();
2713 if (BitSize > Subtarget.getXLen())
2717 int64_t Val =
Imm.getSExtValue();
2725 if (!Subtarget.enableUnalignedScalarMem())
2735 return Seq.
size() <= Subtarget.getMaxBuildIntsCost();
2741 unsigned OldShiftOpcode,
unsigned NewShiftOpcode,
2752 if (NewShiftOpcode ==
ISD::SRL &&
CC->isOne())
2796 if (!Subtarget.hasStdExtZfa())
2799 bool IsSupportedVT =
false;
2800 if (VT == MVT::f16) {
2801 IsSupportedVT = Subtarget.hasStdExtZfh() || Subtarget.hasStdExtZvfh();
2802 }
else if (VT == MVT::f32) {
2803 IsSupportedVT =
true;
2804 }
else if (VT == MVT::f64) {
2805 assert(Subtarget.hasStdExtD() &&
"Expect D extension");
2806 IsSupportedVT =
true;
2817 bool ForCodeSize)
const {
2818 bool IsLegalVT =
false;
2820 IsLegalVT = Subtarget.hasStdExtZfhminOrZhinxmin();
2821 else if (VT == MVT::f32)
2822 IsLegalVT = Subtarget.hasStdExtFOrZfinx();
2823 else if (VT == MVT::f64)
2824 IsLegalVT = Subtarget.hasStdExtDOrZdinx();
2825 else if (VT == MVT::bf16)
2826 IsLegalVT = Subtarget.hasStdExtZfbfmin();
2846 if (
Imm.isNegZero())
2851 const int FmvCost = Subtarget.hasStdExtZfinx() ? 0 : 1;
2854 Subtarget.getXLen(), Subtarget);
2855 return Cost <= Subtarget.getCLOpts().lower_fpimm_cost
2861 if (Ty.isBFloat16())
2864 switch (Ty.getSizeInBits()) {
2878 bool ForCodeSize)
const {
2886 unsigned Index)
const {
2887 if (Subtarget.hasStdExtP() && !Subtarget.is64Bit() &&
2888 (ResVT == MVT::v4i8 || ResVT == MVT::v2i16)) {
2894 if (!Subtarget.hasVInstructions())
2912 if (EltVT == MVT::i1)
2918 unsigned MinVLen = Subtarget.getRealMinVLen();
2925 if (Index + ResElts <= MinVLMAX && Index < 31)
2934 if ((ResElts * 2) == SrcElts && Index == ResElts)
2944 if (VT == MVT::f16 && Subtarget.hasStdExtFOrZfinx() &&
2945 !Subtarget.hasStdExtZfhminOrZhinxmin())
2953 std::optional<MVT> RegisterVT)
const {
2955 if (VT == (Subtarget.is64Bit() ? MVT::i128 : MVT::i64) && RegisterVT &&
2956 *RegisterVT == MVT::Untyped)
2967 if (VT == MVT::f16 && Subtarget.hasStdExtFOrZfinx() &&
2968 !Subtarget.hasStdExtZfhminOrZhinxmin())
2993 ShAmt =
LHS.getValueSizeInBits() - 1 -
Log2_64(Mask);
3007 int64_t
C = RHSC->getSExtValue();
3078 if (VT.
SimpleTy >= MVT::riscv_nxv1i8x2 &&
3079 VT.
SimpleTy <= MVT::riscv_nxv1i8x8)
3081 if (VT.
SimpleTy >= MVT::riscv_nxv2i8x2 &&
3082 VT.
SimpleTy <= MVT::riscv_nxv2i8x8)
3084 if (VT.
SimpleTy >= MVT::riscv_nxv4i8x2 &&
3085 VT.
SimpleTy <= MVT::riscv_nxv4i8x8)
3087 if (VT.
SimpleTy >= MVT::riscv_nxv8i8x2 &&
3088 VT.
SimpleTy <= MVT::riscv_nxv8i8x8)
3090 if (VT.
SimpleTy >= MVT::riscv_nxv16i8x2 &&
3091 VT.
SimpleTy <= MVT::riscv_nxv16i8x4)
3093 if (VT.
SimpleTy == MVT::riscv_nxv32i8x2)
3103 switch (KnownSize) {
3131 return RISCV::VRRegClassID;
3133 return RISCV::VRM2RegClassID;
3135 return RISCV::VRM4RegClassID;
3137 return RISCV::VRM8RegClassID;
3145 static_assert(RISCV::sub_vrm1_7 == RISCV::sub_vrm1_0 + 7,
3146 "Unexpected subreg numbering");
3147 return RISCV::sub_vrm1_0 + Index;
3150 static_assert(RISCV::sub_vrm2_3 == RISCV::sub_vrm2_0 + 3,
3151 "Unexpected subreg numbering");
3152 return RISCV::sub_vrm2_0 + Index;
3155 static_assert(RISCV::sub_vrm4_1 == RISCV::sub_vrm4_0 + 1,
3156 "Unexpected subreg numbering");
3157 return RISCV::sub_vrm4_0 + Index;
3165 unsigned RegsPerField =
3168 switch (RegsPerField) {
3171 return RISCV::VRN2M1RegClassID;
3173 return RISCV::VRN3M1RegClassID;
3175 return RISCV::VRN4M1RegClassID;
3177 return RISCV::VRN5M1RegClassID;
3179 return RISCV::VRN6M1RegClassID;
3181 return RISCV::VRN7M1RegClassID;
3183 return RISCV::VRN8M1RegClassID;
3187 return RISCV::VRN2M2RegClassID;
3189 return RISCV::VRN3M2RegClassID;
3191 return RISCV::VRN4M2RegClassID;
3195 return RISCV::VRN2M4RegClassID;
3203 return RISCV::VRRegClassID;
3212std::pair<unsigned, unsigned>
3214 MVT VecVT,
MVT SubVecVT,
unsigned InsertExtractIdx,
3216 static_assert((RISCV::VRM8RegClassID > RISCV::VRM4RegClassID &&
3217 RISCV::VRM4RegClassID > RISCV::VRM2RegClassID &&
3218 RISCV::VRM2RegClassID > RISCV::VRRegClassID),
3219 "Register classes not ordered");
3226 if (VecRegClassID == SubRegClassID)
3227 return {RISCV::NoSubRegister, 0};
3230 "Only allow scalable vector subvector.");
3232 "Invalid vector tuple insert/extract for vector and subvector with "
3243 unsigned SubRegIdx = RISCV::NoSubRegister;
3244 for (
const unsigned RCID :
3245 {RISCV::VRM4RegClassID, RISCV::VRM2RegClassID, RISCV::VRRegClassID})
3246 if (VecRegClassID > RCID && SubRegClassID <= RCID) {
3250 SubRegIdx =
TRI->composeSubRegIndices(SubRegIdx,
3255 return {SubRegIdx, InsertExtractIdx};
3260bool RISCVTargetLowering::mergeStoresAfterLegalization(
EVT VT)
const {
3262 (VT == MVT::i32 || VT == MVT::v2i16 || VT == MVT::v4i8))
3265 return !
Subtarget.useRVVForFixedLengthVectors() ||
3274 return Subtarget.is64Bit() ? Subtarget.hasVInstructionsI64() :
true;
3278 return Subtarget.hasVInstructions();
3280 return Subtarget.hasVInstructionsI64();
3282 return Subtarget.hasVInstructionsF16Minimal();
3284 return Subtarget.hasVInstructionsBF16Minimal();
3286 return Subtarget.hasVInstructionsF32();
3288 return Subtarget.hasVInstructionsF64();
3296 return Subtarget.getCLOpts().lower_fp_repeated_divisors;
3302 "Unexpected opcode");
3304 unsigned IntNo =
Op.getConstantOperandVal(HasChain ? 1 : 0);
3306 RISCVVIntrinsicsTable::getRISCVVIntrinsicInfo(IntNo);
3309 return Op.getOperand(
II->VLOperand + 1 + HasChain);
3315 if (!
Subtarget.useRVVForFixedLengthVectors())
3325 unsigned MinVLen =
Subtarget.getRealMinVLen();
3349 if (!
Subtarget.hasVInstructionsF16Minimal())
3353 if (!
Subtarget.hasVInstructionsBF16Minimal())
3383bool RISCVTargetLowering::useRVVForFixedLengthVectorVT(
MVT VT)
const {
3384 return ::useRVVForFixedLengthVectorVT(VT, Subtarget);
3392 Subtarget.getTargetLowering()->isTypeLegal(VT)) ||
3394 "Expected legal fixed length vector!");
3396 unsigned MinVLen =
Subtarget.getRealMinVLen();
3425 return ::getContainerForFixedLengthVector(VT,
getSubtarget());
3432 "Expected to convert into a scalable vector!");
3433 assert(
V.getValueType().isFixedLengthVector() &&
3434 "Expected a fixed length vector operand!");
3443 "Expected to convert into a fixed length vector!");
3444 assert(
V.getValueType().isScalableVector() &&
3445 "Expected a scalable vector operand!");
3464 return DAG.
getNode(RISCVISD::VMSET_VL,
DL, MaskVT, VL);
3467static std::pair<SDValue, SDValue>
3476static std::pair<SDValue, SDValue>
3489static std::pair<SDValue, SDValue>
3506std::pair<unsigned, unsigned>
3514 unsigned VectorBitsMax = Subtarget.getRealMaxVLen();
3518 unsigned VectorBitsMin = Subtarget.getRealMinVLen();
3522 return std::make_pair(MinVLMAX, MaxVLMAX);
3534 EVT VT,
unsigned DefinedValues)
const {
3543 unsigned DLenFactor = Subtarget.getDLenFactor();
3548 std::tie(LMul, Fractional) =
3551 Cost = LMul <= DLenFactor ? (DLenFactor / LMul) : 1;
3553 Cost = (LMul * DLenFactor);
3567 bool Log2CostModel =
3569 if (Log2CostModel && LMULCost.isValid()) {
3570 unsigned Log =
Log2_64(LMULCost.getValue());
3572 return LMULCost * Log;
3574 return LMULCost * LMULCost;
3608 if ((
Op.getValueType() == MVT::f16 && !
Subtarget.hasStdExtZfhOrZhinx()) ||
3609 Op.getValueType() == MVT::bf16) {
3610 bool IsStrict =
Op->isStrictFPOpcode();
3615 {Op.getOperand(0), Op.getOperand(1)});
3617 {
Op.getValueType(), MVT::Other},
3623 DAG.
getNode(
Op.getOpcode(),
DL, MVT::f32,
Op.getOperand(0)),
3638 MVT DstVT =
Op.getSimpleValueType();
3646 if ((Src.getValueType() == MVT::f16 && !
Subtarget.hasStdExtZfhOrZhinx()) ||
3647 Src.getValueType() == MVT::bf16) {
3653 Opc = IsSigned ? RISCVISD::FCVT_X : RISCVISD::FCVT_XU;
3654 else if (DstVT == MVT::i64 && SatVT == MVT::i32)
3655 Opc = IsSigned ? RISCVISD::FCVT_W_RV64 : RISCVISD::FCVT_WU_RV64;
3662 Opc,
DL, DstVT, Src,
3665 if (
Opc == RISCVISD::FCVT_WU_RV64)
3676 MVT SrcVT = Src.getSimpleValueType();
3682 if (SatVT != DstEltVT)
3685 MVT DstContainerVT = DstVT;
3686 MVT SrcContainerVT = SrcVT;
3692 "Expected same element count");
3701 {Src, Src, DAG.getCondCode(ISD::SETNE),
3702 DAG.getUNDEF(Mask.getValueType()), Mask, VL});
3706 if (DstEltSize > (2 * SrcEltSize)) {
3709 Src = DAG.
getNode(RISCVISD::FP_EXTEND_VL,
DL, InterVT, Src, Mask, VL);
3712 MVT CvtContainerVT = DstContainerVT;
3713 MVT CvtEltVT = DstEltVT;
3714 if (SrcEltSize > (2 * DstEltSize)) {
3720 IsSigned ? RISCVISD::VFCVT_RTZ_X_F_VL : RISCVISD::VFCVT_RTZ_XU_F_VL;
3723 while (CvtContainerVT != DstContainerVT) {
3727 unsigned ClipOpc = IsSigned ? RISCVISD::TRUNCATE_VECTOR_VL_SSAT
3728 : RISCVISD::TRUNCATE_VECTOR_VL_USAT;
3729 Res = DAG.
getNode(ClipOpc,
DL, CvtContainerVT, Res, Mask, VL);
3733 RISCVISD::VMV_V_X_VL,
DL, DstContainerVT, DAG.
getUNDEF(DstContainerVT),
3735 Res = DAG.
getNode(RISCVISD::VMERGE_VL,
DL, DstContainerVT, IsNan, SplatZero,
3736 Res, DAG.
getUNDEF(DstContainerVT), VL);
3746 bool IsStrict =
Op->isStrictFPOpcode();
3747 SDValue SrcVal =
Op.getOperand(IsStrict ? 1 : 0);
3757 {
Op.getOperand(0), SrcVal});
3758 return DAG.
getNode(
Op.getOpcode(),
DL, {Op.getValueType(), MVT::Other},
3759 {Ext.getValue(1), Ext.getValue(0)});
3808 MVT VT =
Op.getSimpleValueType();
3845 DAG.
getNode(RISCVISD::SETCC_VL,
DL, SetccVT,
3854 switch (
Op.getOpcode()) {
3864 Truncated = DAG.
getNode(RISCVISD::VFCVT_RM_X_F_VL,
DL, IntVT, Src, Mask,
3869 Truncated = DAG.
getNode(RISCVISD::VFCVT_RTZ_X_F_VL,
DL, IntVT, Src,
3879 if (Truncated.
getOpcode() != RISCVISD::VFROUND_NOEXCEPT_VL)
3885 Src, Src, Mask, VL);
3900 MVT VT =
Op.getSimpleValueType();
3916 MVT MaskVT = Mask.getSimpleValueType();
3919 {Chain, Src, Src, DAG.getCondCode(ISD::SETUNE),
3920 DAG.getUNDEF(MaskVT), Mask, VL});
3922 Src = DAG.
getNode(RISCVISD::STRICT_FADD_VL,
DL,
3924 {Chain, Src, Src, Src, Unorder, VL});
3945 RISCVISD::SETCC_VL,
DL, MaskVT,
3953 switch (
Op.getOpcode()) {
3963 RISCVISD::STRICT_VFCVT_RM_X_F_VL,
DL, DAG.
getVTList(IntVT, MVT::Other),
3964 {Chain, Src, Mask, DAG.getTargetConstant(FRM, DL, XLenVT), VL});
3969 DAG.
getNode(RISCVISD::STRICT_VFCVT_RTZ_X_F_VL,
DL,
3970 DAG.
getVTList(IntVT, MVT::Other), Chain, Src, Mask, VL);
3973 Truncated = DAG.
getNode(RISCVISD::STRICT_VFROUND_NOEXCEPT_VL,
DL,
3982 Truncated = DAG.
getNode(RISCVISD::STRICT_SINT_TO_FP_VL,
DL,
3984 Truncated, Mask, VL);
3990 Src, Src, Mask, VL);
4000 MVT VT =
Op.getSimpleValueType();
4021 return DAG.
getNode(RISCVISD::FROUND,
DL, VT, Src, MaxValNode,
4029 MVT DstVT =
Op.getSimpleValueType();
4031 MVT SrcVT = Src.getSimpleValueType();
4036 MVT DstContainerVT = DstVT;
4037 MVT SrcContainerVT = SrcVT;
4049 if (SrcElemType == MVT::f16 || SrcElemType == MVT::bf16) {
4051 Src = DAG.
getNode(RISCVISD::FP_EXTEND_VL,
DL, F32VT, Src, Mask, VL);
4055 DAG.
getNode(RISCVISD::VFCVT_RM_X_F_VL,
DL, DstContainerVT, Src, Mask,
4075 return DAG.
getNode(RISCVISD::VSLIDEDOWN_VL,
DL, VT,
Ops);
4087 return DAG.
getNode(RISCVISD::VSLIDEUP_VL,
DL, VT,
Ops);
4112 return std::nullopt;
4130 unsigned EltSizeInBits) {
4133 return std::nullopt;
4134 bool IsInteger =
Op.getValueType().isInteger();
4136 std::optional<unsigned> SeqStepDenom;
4137 std::optional<APInt> SeqStepNum;
4138 std::optional<APInt> SeqAddend;
4139 std::optional<std::pair<APInt, unsigned>> PrevElt;
4140 assert(EltSizeInBits >=
Op.getValueType().getScalarSizeInBits());
4145 const unsigned OpSize =
Op.getScalarValueSizeInBits();
4146 for (
auto [Idx, Elt] :
enumerate(
Op->op_values())) {
4147 if (Elt.isUndef()) {
4148 Elts[Idx] = std::nullopt;
4152 Elts[Idx] = Elt->getAsAPIntVal().trunc(OpSize).zext(EltSizeInBits);
4157 return std::nullopt;
4158 Elts[Idx] = *ExactInteger;
4162 for (
auto [Idx, Elt] :
enumerate(Elts)) {
4171 unsigned IdxDiff = Idx - PrevElt->second;
4172 APInt ValDiff = *Elt - PrevElt->first;
4180 int64_t Remainder = ValDiff.
srem(IdxDiff);
4185 return std::nullopt;
4186 ValDiff = ValDiff.
sdiv(IdxDiff);
4191 SeqStepNum = ValDiff;
4192 else if (ValDiff != SeqStepNum)
4193 return std::nullopt;
4196 SeqStepDenom = IdxDiff;
4197 else if (IdxDiff != *SeqStepDenom)
4198 return std::nullopt;
4202 if (!PrevElt || PrevElt->first != *Elt)
4203 PrevElt = std::make_pair(*Elt, Idx);
4207 if (!SeqStepNum || !SeqStepDenom)
4208 return std::nullopt;
4212 for (
auto [Idx, Elt] :
enumerate(Elts)) {
4216 (
APInt(EltSizeInBits, Idx,
false,
true) *
4218 .sdiv(*SeqStepDenom);
4220 APInt Addend = *Elt - ExpectedVal;
4223 else if (Addend != SeqAddend)
4224 return std::nullopt;
4227 assert(SeqAddend &&
"Must have an addend if we have a step");
4229 return VIDSequence{SeqStepNum->getSExtValue(), *SeqStepDenom,
4230 SeqAddend->getSExtValue()};
4245 if (EltTy == MVT::i1 ||
4248 MVT SrcVT = Src.getSimpleValueType();
4253 if (Idx.getValueType() !=
Subtarget.getXLenVT())
4268 MVT SrcContainerVT = SrcVT;
4292 MVT VT =
Op.getSimpleValueType();
4301 int64_t StepNumerator = SimpleVID->StepNumerator;
4302 unsigned StepDenominator = SimpleVID->StepDenominator;
4303 int64_t Addend = SimpleVID->Addend;
4305 assert(StepNumerator != 0 &&
"Invalid step");
4306 bool Negate =
false;
4307 int64_t SplatStepVal = StepNumerator;
4311 if (StepNumerator != 1 && StepNumerator !=
INT64_MIN &&
4313 Negate = StepNumerator < 0;
4315 SplatStepVal =
Log2_64(std::abs(StepNumerator));
4325 (SplatStepVal >= 0 || StepDenominator == 1) &&
isInt<32>(Addend)) {
4335 if ((StepOpcode ==
ISD::MUL && SplatStepVal != 1) ||
4336 (StepOpcode ==
ISD::SHL && SplatStepVal != 0)) {
4338 VID = DAG.
getNode(StepOpcode,
DL, VIDVT, VID, SplatStep);
4340 if (StepDenominator != 1) {
4345 if (Addend != 0 || Negate) {
4371 MVT VT =
Op.getSimpleValueType();
4380 unsigned NumElts =
Op.getNumOperands();
4383 unsigned MostCommonCount = 0;
4385 unsigned NumUndefElts =
4393 unsigned NumScalarLoads = 0;
4399 unsigned &
Count = ValueCounts[
V];
4402 NumScalarLoads += !CFP->isPosZero();
4407 if (++
Count >= MostCommonCount) {
4409 MostCommonCount =
Count;
4413 assert(DominantValue &&
"Not expecting an all-undef BUILD_VECTOR");
4414 unsigned NumDefElts = NumElts - NumUndefElts;
4415 unsigned DominantValueCountThreshold = NumDefElts <= 2 ? 0 : NumDefElts - 2;
4421 ((MostCommonCount > DominantValueCountThreshold) ||
4433 if (
SDValue LastOp =
Op->getOperand(
Op->getNumOperands() - 1);
4434 !LastOp.isUndef() && ValueCounts[LastOp] == 1 &&
4435 LastOp != DominantValue) {
4438 VT.
isFloatingPoint() ? RISCVISD::VFSLIDE1DOWN_VL : RISCVISD::VSLIDE1DOWN_VL;
4444 Processed.
insert(LastOp);
4450 if (
V.isUndef() || !Processed.
insert(
V).second)
4452 if (ValueCounts[
V] == 1) {
4460 return DAG.getConstant(V == V1, DL, XLenVT);
4476 MVT VT =
Op.getSimpleValueType();
4485 unsigned NumElts =
Op.getNumOperands();
4506 unsigned NumViaIntegerBits = std::clamp(NumElts, 8u,
Subtarget.getXLen());
4507 NumViaIntegerBits = std::min(NumViaIntegerBits,
Subtarget.getELen());
4515 unsigned IntegerViaVecElts =
divideCeil(NumElts, NumViaIntegerBits);
4516 MVT IntegerViaVecVT =
4521 unsigned BitPos = 0, IntegerEltIdx = 0;
4524 for (
unsigned I = 0;
I < NumElts;) {
4526 bool BitValue = !
V.isUndef() &&
V->getAsZExtVal();
4527 Bits |= ((
uint64_t)BitValue << BitPos);
4533 if (
I % NumViaIntegerBits == 0 ||
I == NumElts) {
4534 if (NumViaIntegerBits <= 32)
4537 Elts[IntegerEltIdx] = Elt;
4546 if (NumElts < NumViaIntegerBits) {
4550 assert(IntegerViaVecVT == MVT::v1i8 &&
"Unexpected mask vector type");
4565 : RISCVISD::VMV_V_X_VL;
4584 assert((ViaIntVT == MVT::i16 || ViaIntVT == MVT::i32) &&
4585 "Unexpected sequence type");
4589 unsigned ViaVecLen =
4596 for (
const auto &OpIdx :
enumerate(
Op->op_values())) {
4597 const auto &SeqV = OpIdx.value();
4598 if (!SeqV.isUndef())
4600 ((SeqV->getAsZExtVal() & EltMask) << (OpIdx.index() * EltBitSize));
4606 if (ViaIntVT == MVT::i32)
4628 BV->getRepeatedSequence(Sequence) &&
4629 (Sequence.size() * EltBitSize) <=
Subtarget.getELen()) {
4630 unsigned SeqLen = Sequence.size();
4632 assert((ViaIntVT == MVT::i16 || ViaIntVT == MVT::i32 ||
4633 ViaIntVT == MVT::i64) &&
4634 "Unexpected sequence type");
4639 const unsigned RequiredVL = NumElts / SeqLen;
4640 const unsigned ViaVecLen =
4642 NumElts : RequiredVL;
4645 unsigned EltIdx = 0;
4650 for (
const auto &SeqV : Sequence) {
4651 if (!SeqV.isUndef())
4653 ((SeqV->getAsZExtVal() & EltMask) << (EltIdx * EltBitSize));
4660 if (ViaIntVT == MVT::i32)
4667 (!
Subtarget.is64Bit() && ViaIntVT == MVT::i64)) &&
4668 "Unexpected bitcast sequence");
4672 MVT ViaContainerVT =
4675 DAG.
getNode(RISCVISD::VMV_V_X_VL,
DL, ViaContainerVT,
4679 if (ViaVecLen != RequiredVL)
4718 return RISCV::PACKH;
4720 return Subtarget.is64Bit() ? RISCV::PACKW : RISCV::PACK;
4735 MVT VT =
Op.getSimpleValueType();
4767 ElemDL, XLenVT,
A,
B),
4779 NewOperands.
reserve(NumElts / 2);
4781 NewOperands.
push_back(pack(
Op.getOperand(i),
Op.getOperand(i + 1)));
4796 auto IsUndef = [](
SDValue V) {
return V.isUndef(); };
4799 if (
Ops.size() == 1)
4802 size_t N =
Ops.size() / 2;
4820 MVT VT =
Op.getSimpleValueType();
4833 if (
Subtarget.is64Bit() || VT == MVT::v2i16) {
4834 assert((!
Subtarget.is64Bit() || (VT == MVT::v4i16 || VT == MVT::v8i8)) &&
4835 "Unexpected RV64 P BUILD_VECTOR type");
4840 if (VT == MVT::v4i8) {
4860 DAG.
getNode(RISCVISD::PPAIRE,
DL, MVT::v2i16,
4865 if (VT == MVT::v8i8 || VT == MVT::v4i16) {
4884 if ((EltVT == MVT::f16 && !
Subtarget.hasVInstructionsF16()) ||
4885 (EltVT == MVT::bf16 && !
Subtarget.hasVInstructionsBF16())) {
4890 if ((EltVT == MVT::bf16 &&
Subtarget.hasStdExtZfbfmin()) ||
4891 (EltVT == MVT::f16 &&
Subtarget.hasStdExtZfhmin())) {
4901 NewOps[
I] = DAG.
getNode(RISCVISD::FMV_X_ANYEXTH,
DL, XLenVT, Elem);
4953 bool IsScalar =
all_of(
Op->ops().drop_front(),
4954 [](
const SDUse &U) { return U.get().isUndef(); });
4957 ? (IsScalar ? RISCVISD::VFMV_S_F_VL : RISCVISD::VFMV_V_F_VL)
4958 : (IsScalar ? RISCVISD::VMV_S_X_VL : RISCVISD::VMV_V_X_VL);
4969 if (
const auto VLen =
Subtarget.getRealVLen();
4986 auto OneVRegOfOps =
ArrayRef(BuildVectorOps).slice(i, ElemsPerVReg);
4990 unsigned InsertIdx = (i / ElemsPerVReg) * NumOpElts;
5012 unsigned NumUndefElts =
5014 unsigned NumDefElts = NumElts - NumUndefElts;
5015 if (NumDefElts >= 8 && NumDefElts > NumElts / 2 &&
5022 for (
const auto &[Idx, U] :
enumerate(
Op->ops())) {
5024 if (Idx < NumElts / 2) {
5031 bool SelectMaskVal = (Idx < NumElts / 2);
5034 assert(SubVecAOps.
size() == NumElts && SubVecBOps.
size() == NumElts &&
5035 MaskVals.
size() == NumElts);
5070 unsigned UndefCount = 0;
5077 LinearBudget -= PerSlideCost;
5080 LinearBudget -= PerSlideCost;
5083 LinearBudget -= PerSlideCost;
5086 if (LinearBudget < 0)
5091 "Illegal type which will result in reserved encoding");
5107 bool SlideUp =
false;
5132 if (EVecEltVT != ContainerEltVT)
5188 Opcode = SlideUp ? RISCVISD::VFSLIDE1UP_VL : RISCVISD::VFSLIDE1DOWN_VL;
5190 Opcode = SlideUp ? RISCVISD::VSLIDE1UP_VL : RISCVISD::VSLIDE1DOWN_VL;
5215 if ((LoC >> 31) == HiC)
5216 return DAG.
getNode(RISCVISD::VMV_V_X_VL,
DL, VT, Passthru,
Lo, VL);
5220 if (LoC == HiC && Passthru.
isUndef()) {
5228 auto InterVec = DAG.
getNode(RISCVISD::VMV_V_X_VL,
DL, InterVT,
5252 Hi.getConstantOperandVal(1) == 31)
5253 return DAG.
getNode(RISCVISD::VMV_V_X_VL,
DL, VT, Passthru,
Lo, VL);
5258 return DAG.
getNode(RISCVISD::VMV_V_X_VL,
DL, VT, Passthru,
Lo, VL);
5261 return DAG.
getNode(RISCVISD::SPLAT_VECTOR_SPLIT_I64_VL,
DL, VT, Passthru,
Lo,
5271 assert(
Scalar.getValueType() == MVT::i64 &&
"Unexpected VT!");
5283 bool HasPassthru = Passthru && !Passthru.
isUndef();
5284 if (!HasPassthru && !Passthru)
5291 if ((EltVT == MVT::f16 && !
Subtarget.hasVInstructionsF16()) ||
5292 (EltVT == MVT::bf16 && !
Subtarget.hasVInstructionsBF16())) {
5293 if ((EltVT == MVT::bf16 &&
Subtarget.hasStdExtZfbfmin()) ||
5294 (EltVT == MVT::f16 &&
Subtarget.hasStdExtZfhmin()))
5304 return DAG.
getNode(RISCVISD::VFMV_V_F_VL,
DL, VT, Passthru,
Scalar, VL);
5308 if (
Scalar.getValueType().bitsLE(XLenVT)) {
5316 return DAG.
getNode(RISCVISD::VMV_V_X_VL,
DL, VT, Passthru,
Scalar, VL);
5319 assert(XLenVT == MVT::i32 &&
Scalar.getValueType() == MVT::i64 &&
5320 "Unexpected scalar for splat lowering!");
5323 return DAG.
getNode(RISCVISD::VMV_S_X_VL,
DL, VT, Passthru,
5349 MVT ExtractedContainerVT = ExtractedVT;
5351 ExtractedContainerVT =
5356 if (ExtractedContainerVT.
bitsLE(VT))
5368 if (!
Scalar.getValueType().bitsLE(XLenVT))
5389 EVT VT =
V1.getValueType();
5403 if (
V1.getConstantOperandVal(1) != 0 ||
5420 Src && Src.
getValueType().getVectorNumElements() == (NumElts * 2))
5428 unsigned MinSize =
ContainerVT.getSizeInBits().getKnownMinValue();
5460 return EltBits * 16 <= LMULOctuple * std::min(
Subtarget.getELen(),
5481 int Size = Mask.size();
5483 assert(
Size == (
int)NumElts &&
"Unexpected mask size");
5489 EvenSrc = StartIndexes[0];
5490 OddSrc = StartIndexes[1];
5493 if (EvenSrc != 0 && OddSrc != 0)
5503 int HalfNumElts = NumElts / 2;
5504 return ((EvenSrc % HalfNumElts) == 0) && ((OddSrc % HalfNumElts) == 0);
5509 std::array<std::pair<int, int>, 2> &SrcInfo) {
5514 if (SrcInfo[0].second == 0 && SrcInfo[1].second == 0)
5518 if ((SrcInfo[0].second > 0 && SrcInfo[1].second < 0) ||
5519 SrcInfo[1].second == 0)
5521 assert(SrcInfo[0].first != -1 &&
"Must find one slide");
5529 if (SrcInfo[1].first == -1)
5531 return SrcInfo[0].second < 0 && SrcInfo[1].second > 0 &&
5532 SrcInfo[1].second - SrcInfo[0].second == (int)NumElts;
5544 ElementCount SrcEC = Src.getValueType().getVectorElementCount();
5551 unsigned Shift = Index * EltBits;
5576 std::optional<int> SplatIdx;
5578 if (M == -1 ||
I == (
unsigned)M)
5580 if (SplatIdx && *SplatIdx != M)
5589 for (
int MaskIndex : Mask) {
5590 bool SelectMaskVal = MaskIndex == *SplatIdx;
5593 assert(MaskVals.
size() == NumElts &&
"Unexpected select-like shuffle");
5618 auto findNonEXTRACT_SUBVECTORParent =
5619 [](
SDValue Parent) -> std::pair<SDValue, uint64_t> {
5624 Parent.getOperand(0).getSimpleValueType().isFixedLengthVector()) {
5625 Offset += Parent.getConstantOperandVal(1);
5626 Parent = Parent.getOperand(0);
5628 return std::make_pair(Parent,
Offset);
5631 auto [V1Src, V1IndexOffset] = findNonEXTRACT_SUBVECTORParent(
V1);
5632 auto [V2Src, V2IndexOffset] = findNonEXTRACT_SUBVECTORParent(V2);
5641 for (
size_t i = 0; i != NewMask.
size(); ++i) {
5642 if (NewMask[i] == -1)
5645 if (
static_cast<size_t>(NewMask[i]) < NewMask.
size()) {
5646 NewMask[i] = NewMask[i] + V1IndexOffset;
5650 NewMask[i] = NewMask[i] - NewMask.
size() + V2IndexOffset;
5656 if (NewMask[0] <= 0)
5660 for (
unsigned i = 1; i != NewMask.
size(); ++i)
5661 if (NewMask[i - 1] + 1 != NewMask[i])
5665 MVT SrcVT = Src.getSimpleValueType();
5694 int NumSubElts, Index;
5699 bool OpsSwapped = Mask[Index] < (int)NumElts;
5701 SDValue ToInsert = OpsSwapped ?
V1 : V2;
5712 if (NumSubElts + Index >= (
int)NumElts)
5749 unsigned NumElts = Mask.size();
5752 int Lane = Mask[Idx];
5757 bool SecondOp =
false;
5758 if ((
unsigned)Lane < NumElts) {
5759 OrigLane = V1Mask[Lane];
5761 OrigLane = V2Mask[Lane - NumElts];
5767 if ((
unsigned)OrigLane >= NumElts)
5770 OrigLane += NumElts;
5771 NewMask[Idx] = OrigLane;
5788 bool OpsSwapped =
false;
5803 const unsigned E = Mask.size() - ((
Offset > 0) ?
Offset : 0);
5804 for (
unsigned i = S; i !=
E; ++i)
5805 if (Mask[i] >= 0 && (
unsigned)Mask[i] !=
Base + i +
Offset)
5811 bool IsVSlidedown = isSlideMask(Mask, OpsSwapped ? 0 : NumElts, 1);
5812 if (!IsVSlidedown && !isSlideMask(Mask, OpsSwapped ? 0 : NumElts, -1))
5815 const int InsertIdx = Mask[IsVSlidedown ? (NumElts - 1) : 0];
5817 if (InsertIdx < 0 || InsertIdx / NumElts != (
unsigned)OpsSwapped)
5835 IsVSlidedown ? RISCVISD::VSLIDE1DOWN_VL : RISCVISD::VSLIDE1UP_VL,
DL,
5841 auto OpCode = IsVSlidedown ?
5842 (VT.
isFloatingPoint() ? RISCVISD::VFSLIDE1DOWN_VL : RISCVISD::VSLIDE1DOWN_VL) :
5843 (VT.
isFloatingPoint() ? RISCVISD::VFSLIDE1UP_VL : RISCVISD::VSLIDE1UP_VL);
5849 Splat, TrueMask, VL);
5861 for (
unsigned i = 0; i < Mask.size(); i++)
5862 LaneIsUndef[i % Factor] &= (Mask[i] == -1);
5865 for (
unsigned i = 0; i < Factor; i++) {
5876 for (
unsigned i = 0; i < Mask.size() / Factor; i++) {
5877 unsigned j = i * Factor + Index;
5878 if (Mask[j] != -1 && (
unsigned)Mask[j] != i)
5887 assert(RISCVISD::VPAIRE_VL ==
Opc || RISCVISD::VPAIRO_VL ==
Opc);
5932 DAG.
getNode(RISCVISD::VZIP_VL,
DL, ResVT, Op0, Op1, Passthru, Mask, VL);
5943 assert(
Opc == RISCVISD::VUNZIPE_VL ||
Opc == RISCVISD::VUNZIPO_VL);
5944 MVT VT =
Op.getSimpleValueType();
5956 !
Subtarget.getTargetLowering()->isTypeLegal(
5981 MVT VT =
V.getSimpleValueType();
6014 MVT VecContainerVT = VecVT;
6031 MVT WideContainerVT = WideVT;
6037 EvenV = DAG.
getBitcast(VecContainerVT, EvenV);
6048 Interleaved = DAG.
getNode(RISCVISD::VWSLL_VL,
DL, WideContainerVT, OddV,
6049 OffsetVec, Passthru, Mask, VL);
6050 Interleaved = DAG.
getNode(RISCVISD::VWADDU_W_VL,
DL, WideContainerVT,
6051 Interleaved, EvenV, Passthru, Mask, VL);
6058 Interleaved = DAG.
getNode(RISCVISD::VWADDU_VL,
DL, WideContainerVT, EvenV,
6059 OddV, Passthru, Mask, VL);
6065 OddV, AllOnesVec, Passthru, Mask, VL);
6072 Interleaved = DAG.
getNode(RISCVISD::ADD_VL,
DL, WideContainerVT,
6073 Interleaved, OddsMul, Passthru, Mask, VL);
6080 Interleaved = DAG.
getBitcast(ResultContainerVT, Interleaved);
6119 !
Subtarget.getTargetLowering()->isTypeLegal(ViaBitVT))
6125 if (ViaEltSize > NumElts)
6133 if (ViaEltSize > NumElts)
6139 if (ViaEltSize > NumElts)
6146 MVT &RotateVT,
unsigned &RotateAmt) {
6149 unsigned NumSubElts;
6151 NumElts, NumSubElts, RotateAmt))
6154 NumElts / NumSubElts);
6157 return Subtarget.getTargetLowering()->isTypeLegal(RotateVT);
6202 const auto VLen =
Subtarget.getRealVLen();
6221 unsigned NumElts =
ContainerVT.getVectorMinNumElements();
6222 unsigned NumOfSrcRegs = NumElts / NumOpElts;
6223 unsigned NumOfDestRegs = NumElts / NumOpElts;
6232 Mask, NumOfSrcRegs, NumOfDestRegs, NumOfDestRegs,
6233 [&]() {
Operands.emplace_back(); },
6234 [&](
ArrayRef<int> SrcSubMask,
unsigned SrcVecIdx,
unsigned DstVecIdx) {
6235 Operands.emplace_back().emplace_back(SrcVecIdx, UINT_MAX,
6238 [&](
ArrayRef<int> SrcSubMask,
unsigned Idx1,
unsigned Idx2,
bool NewReg) {
6243 assert(
Operands.size() == NumOfDestRegs &&
"Whole vector must be processed");
6248 unsigned NumShuffles = std::accumulate(
6255 for (const auto &P : Data) {
6256 unsigned Idx2 = std::get<1>(P);
6257 ArrayRef<int> Mask = std::get<2>(P);
6258 if (Idx2 != UINT_MAX)
6260 else if (ShuffleVectorInst::isIdentityMask(Mask, Mask.size()))
6265 if ((NumOfDestRegs > 2 && NumShuffles > NumOfDestRegs) ||
6266 (NumOfDestRegs <= 2 && NumShuffles >= 4))
6268 auto ExtractValue = [&, &DAG = DAG](
SDValue SrcVec,
unsigned ExtractIdx) {
6269 SDValue SubVec = DAG.getExtractSubvector(
DL, M1VT, SrcVec, ExtractIdx);
6273 auto PerformShuffle = [&, &DAG = DAG](
SDValue SubVec1,
SDValue SubVec2,
6275 SDValue SubVec = DAG.getVectorShuffle(OneRegVT,
DL, SubVec1, SubVec2, Mask);
6284 const auto &[Idx1, Idx2,
_] =
Data[
I];
6292 V = ExtractValue(Idx1 >= NumOfSrcRegs ? V2 :
V1,
6293 (Idx1 % NumOfSrcRegs) * NumOpElts);
6294 if (Idx2 != UINT_MAX) {
6297 V = ExtractValue(Idx2 >= NumOfSrcRegs ? V2 :
V1,
6298 (Idx2 % NumOfSrcRegs) * NumOpElts);
6302 for (
const auto &[Idx1, Idx2, Mask] :
Data) {
6305 V = PerformShuffle(
V1, V2, Mask);
6309 unsigned InsertIdx =
I * NumOpElts;
6311 Vec = DAG.getInsertSubvector(
DL, Vec,
V, InsertIdx);
6321 bool SawUndef =
false;
6322 for (
const auto &[Idx, M] :
enumerate(Mask)) {
6329 if (Idx > (
unsigned)M)
6362 for (
int Idx : Mask) {
6365 unsigned SrcIdx = Idx % Mask.size();
6366 int Src = (
uint32_t)Idx < Mask.size() ? 0 : 1;
6367 if (Srcs[SrcIdx] == -1)
6370 else if (Srcs[SrcIdx] != Src)
6376 for (
int Lane : Srcs) {
6389 for (
unsigned I = 0;
I < Mask.size();
I++) {
6393 NewMask[
I] = Mask[
I] % Mask.size();
6407 if ((M / Span) != (
int)(
I / Span))
6409 int SpanIdx =
I % Span;
6419 return all_of(Mask, [&](
const auto &Idx) {
return Idx == -1 || Idx < Span; });
6431 int SpanIdx =
I % Span;
6432 if (Mask[SpanIdx] != M)
6446 MVT VT =
Op.getSimpleValueType();
6454 if (ElementSize > 32)
6484 if (VT != MVT::v8i8 && VT != MVT::v4i16)
6490 unsigned EvenSrc = StartIndexes[0];
6491 unsigned OddSrc = StartIndexes[1];
6492 if (EvenSrc == 0 && OddSrc == NumElts) {
6494 return DAG.
getNode(RISCVISD::PZIP,
DL, VT,
V1, V2);
6498 return DAG.
getNode(RISCVISD::PWZIP,
DL, VT,
V1, V2);
6500 if (EvenSrc == NumElts && OddSrc == 0) {
6502 return DAG.
getNode(RISCVISD::PZIP,
DL, VT, V2,
V1);
6506 return DAG.
getNode(RISCVISD::PWZIP,
DL, VT, V2,
V1);
6509 unsigned HalfNumElts = NumElts / 2;
6510 if (EvenSrc == HalfNumElts && OddSrc == NumElts + HalfNumElts)
6511 return DAG.
getNode(RISCVISD::PZIPH,
DL, VT,
V1, V2);
6512 if (EvenSrc == NumElts + HalfNumElts && OddSrc == HalfNumElts)
6513 return DAG.
getNode(RISCVISD::PZIPH,
DL, VT, V2,
V1);
6526 if (!IsRV64 || (VT != MVT::v8i8 && VT != MVT::v4i16))
6538 unsigned Opc = Index == 0 ? RISCVISD::PUNZIPE : RISCVISD::PUNZIPO;
6549 if (VT != MVT::v4i8 && VT != MVT::v8i8 && VT != MVT::v2i16 &&
6550 VT != MVT::v4i16 && VT != MVT::v2i32)
6552 if (!
Subtarget.is64Bit() && VT == MVT::v2i32)
6557 unsigned ActiveElts = NumElts;
6559 all_of(Mask.drop_front(NumElts / 2), [](
int M) { return M < 0; }))
6563 bool SlideUp = ActiveMask[0] == (int)NumElts &&
6565 return M.value() == (int)M.index();
6567 bool SlideDown = ActiveMask.
back() == (int)NumElts &&
6569 return M.value() == (int)M.index() + 1;
6571 if (!SlideUp && !SlideDown)
6578 unsigned SlideBits = ActiveElts * EltBits;
6583 if (ActiveElts == 2) {
6585 return DAG.
getNode(SlideUp ? RISCVISD::PPAIRE : RISCVISD::PPAIROE,
DL, VT,
6586 SlideUp ? ScalarVec :
V1, SlideUp ?
V1 : ScalarVec);
6607 assert(SlideBits == 32 &&
"Unexpected RV64 packed slide width");
6626 assert(SlideBits == 64 &&
"Unexpected RV32 packed slide width");
6628 MVT HalfVT = LoVec.getSimpleValueType();
6655 unsigned NumElts = Mask.size();
6656 if (NumElts % 2 != 0)
6658 for (
unsigned I = 0;
I != NumElts / 2; ++
I)
6659 if ((Mask[2 *
I] >= 0 && Mask[2 *
I] != (
int)(2 *
I)) ||
6660 (Mask[2 *
I + 1] >= 0 && Mask[2 *
I + 1] < (
int)NumElts))
6672 if (VT != MVT::v4i8)
6682 MVT SrcVT = VT == MVT::v4i8 ? MVT::v8i8 : MVT::v4i16;
6687 if (Src.getValueType().getVectorNumElements() != 2 * NumElts)
6695 return DAG.
getNode(RISCVISD::PNSRL,
DL, VT, Src,
6707 if (VT != MVT::v4i8 && VT != MVT::v8i8 && VT != MVT::v2i16 &&
6708 VT != MVT::v4i16 && !(IsRV64 && VT == MVT::v2i32))
6731 std::optional<bool> Parity[2];
6732 for (
unsigned I = 0;
I != NumElts; ++
I) {
6736 unsigned Lane =
I % 2;
6737 bool FromV1 = (
unsigned)M < NumElts;
6742 else if (Src[Lane] != Cand)
6746 if (FromV1 ? V1IsSplat : V2IsSplat)
6756 else if (*Parity[Lane] !=
P)
6761 if (!Src[0] || !Src[1])
6764 bool EvenIsOdd = Parity[0].value_or(
false);
6765 bool OddIsOdd = Parity[1].value_or(
false);
6767 if (!EvenIsOdd && !OddIsOdd)
6768 Opc = RISCVISD::PPAIRE;
6769 else if (EvenIsOdd && OddIsOdd)
6770 Opc = RISCVISD::PPAIRO;
6771 else if (!EvenIsOdd && OddIsOdd)
6772 Opc = RISCVISD::PPAIREO;
6774 Opc = RISCVISD::PPAIROE;
6784 MVT XLenVT = Subtarget.getXLenVT();
6785 MVT VT =
Op.getSimpleValueType();
6791 if (Subtarget.hasStdExtP() && !Subtarget.hasVInstructions()) {
6798 auto IsLowReverse = [&](
unsigned L) {
6801 all_of(
Mask.drop_front(L), [](
int M) { return M < 0; });
6803 if (IsLowReverse(NumElts))
6805 if (Subtarget.is64Bit() && VT == MVT::v4i16 && IsLowReverse(2))
6811 IsLowReverse(NumElts / 2)) {
6861 auto [TrueMask, VL] = TrueMaskVL;
6876 V.getOperand(0).getSimpleValueType().getVectorNumElements();
6877 V =
V.getOperand(
Offset / OpElements);
6910 if (SVT == MVT::bf16 ||
6911 (SVT == MVT::f16 && !Subtarget.hasStdExtZfh())) {
6920 V = DAG.
getLoad(SVT,
DL, Ld->getChain(), NewAddr,
6921 Ld->getPointerInfo().getWithOffset(
Offset),
6922 Ld->getBaseAlign(), Ld->getMemOperand()->getFlags());
6925 Ld->getPointerInfo().getWithOffset(
Offset), SVT,
6927 Ld->getMemOperand()->getFlags());
6931 : RISCVISD::VMV_V_X_VL;
6939 assert(Lane < (
int)NumElts &&
"Unexpected lane!");
6964 if (Subtarget.hasStdExtZvkb())
6974 if (Subtarget.hasStdExtZvzip() &&
6976 1 <
count_if(Mask, [](
int Idx) {
return Idx != -1; })) {
6977 bool UsesBothSources =
6979 [&Mask](
int Idx) {
return Idx < (int)
Mask.size(); }) &&
6981 [&Mask](
int Idx) {
return Idx >= (int)
Mask.size(); });
6983 unsigned Opc =
Index == 0 ? RISCVISD::VUNZIPE_VL : RISCVISD::VUNZIPO_VL;
6990 }
else if (
auto VLEN = Subtarget.getRealVLen();
7002 if (UsesBothSources &&
7004 V1.getSimpleValueType().getVectorMinNumElements() >= 2 &&
7020 assert(MaxFactor == 2 || MaxFactor == 4 || MaxFactor == 8);
7021 for (
unsigned Factor = 2; Factor <= MaxFactor; Factor <<= 1) {
7024 1 <
count_if(Mask, [](
int Idx) {
return Idx != -1; })) {
7028 [&Mask](
int Idx) {
return Idx < (int)
Mask.size(); }) &&
7029 1 <
count_if(Mask, [&Mask](
int Idx) {
7030 return Idx >= (int)
Mask.size();
7063 int EvenSrc, OddSrc;
7073 bool LaneIsUndef[2] = {
true,
true};
7074 for (
const auto &[Idx, M] :
enumerate(Mask))
7075 LaneIsUndef[
Idx % 2] &= (
M == -1);
7079 if (LaneIsUndef[0]) {
7082 assert(EvenSrc >= 0 &&
"Undef source?");
7083 EvenV = (EvenSrc /
Size) == 0 ?
V1 : V2;
7087 if (LaneIsUndef[1]) {
7090 assert(OddSrc >= 0 &&
"Undef source?");
7091 OddV = (OddSrc /
Size) == 0 ?
V1 : V2;
7097 if (Subtarget.hasStdExtZvzip() &&
7109 std::array<std::pair<int, int>, 2> SrcInfo;
7116 auto GetSourceFor = [&](
const std::pair<int, int> &
Info) {
7117 int SrcIdx =
Info.first;
7118 assert(SrcIdx == 0 || SrcIdx == 1);
7119 SDValue &Src = Sources[SrcIdx];
7126 auto GetSlide = [&](
const std::pair<int, int> &Src,
SDValue Mask,
7128 auto [TrueMask, VL] = TrueMaskVL;
7129 SDValue SrcV = GetSourceFor(Src);
7130 int SlideAmt = Src.second;
7131 if (SlideAmt == 0) {
7133 assert(Mask == TrueMask);
7145 if (SrcInfo[1].first == -1) {
7147 Res = GetSlide(SrcInfo[0], TrueMask, Res);
7151 if (Subtarget.hasStdExtZvzip()) {
7152 bool TryWiden =
false;
7185 for (
const auto &[Idx, M] :
enumerate(Mask)) {
7187 (SrcInfo[1].second > 0 && Idx < (
unsigned)SrcInfo[1].second)) {
7191 int Src =
M >= (int)NumElts;
7192 int Diff = (int)Idx - (M % NumElts);
7193 bool C = Src == SrcInfo[1].first && Diff == SrcInfo[1].second;
7194 assert(
C ^ (Src == SrcInfo[0].first && Diff == SrcInfo[0].second) &&
7195 "Must match exactly one of the two slides");
7198 assert(MaskVals.
size() == NumElts &&
"Unexpected select-like shuffle");
7205 Res = GetSlide(SrcInfo[0], TrueMask, Res);
7206 Res = GetSlide(SrcInfo[1], SelectMask, Res);
7211 assert(!
V1.isUndef() &&
"Unexpected shuffle canonicalization");
7226 assert(MaxFactor == 2 || MaxFactor == 4 || MaxFactor == 8);
7227 for (
unsigned Factor = 4; Factor <= MaxFactor; Factor <<= 1) {
7240 unsigned MinVLen = Subtarget.getRealMinVLen();
7242 if (NumElts > MinVLMAX) {
7243 unsigned MaxIdx = 0;
7247 MaxIdx = std::max({(unsigned)
I, (
unsigned)
M, MaxIdx});
7249 unsigned NewNumElts =
7251 if (NewNumElts != NumElts) {
7255 Mask.take_front(NewNumElts));
7272 for (
auto Idx : Mask) {
7275 assert(Idx >= 0 && (
unsigned)Idx < NumElts);
7285 any_of(Mask, [&](
const auto &Idx) {
return Idx > 255; })) {
7295 unsigned GatherVVOpc = RISCVISD::VRGATHER_VV_VL;
7301 GatherVVOpc = RISCVISD::VRGATHEREI16_VV_VL;
7309 (IndexVT.
getSizeInBits() / Subtarget.getRealMinVLen()) > 1) {
7310 GatherVVOpc = RISCVISD::VRGATHEREI16_VV_VL;
7314 MVT IndexContainerVT =
7319 for (
int MaskIndex : Mask) {
7320 bool IsLHSIndex = MaskIndex < (int)NumElts && MaskIndex >= 0;
7330 if (NumElts <= MinVLMAX) {
7338 auto [InnerTrueMask, InnerVL] =
7350 for (
int i = 0; i <
N; i++) {
7354 DAG.
getNode(GatherVVOpc,
DL, M1VT, SubV1, SubIndex,
7355 DAG.
getUNDEF(M1VT), InnerTrueMask, InnerVL);
7372 DAG.
getUNDEF(M1VT), InnerTrueMask, InnerVL);
7374 for (
int i = 0; i <
N; i++)
7390 for (
int i = 0; i <
N; i++) {
7393 DAG.
getUNDEF(IndexContainerVT), LHSIndices,
7394 SlideAmt, TrueMask, VL);
7398 DAG.
getNode(GatherVVOpc,
DL, M1VT, SubV1, SubIndex,
7399 DAG.
getUNDEF(M1VT), InnerTrueMask, InnerVL);
7415 SmallVector<int> ShuffleMaskLHS, ShuffleMaskRHS;
7419 for (
int MaskIndex : Mask) {
7420 bool IsLHSOrUndefIndex = MaskIndex < (int)NumElts;
7421 ShuffleMaskLHS.
push_back(IsLHSOrUndefIndex && MaskIndex >= 0
7423 ShuffleMaskRHS.
push_back(IsLHSOrUndefIndex ? -1 : (MaskIndex - NumElts));
7454 for (
int MaskIndex : Mask) {
7455 bool SelectMaskVal = (MaskIndex < (int)NumElts) ^ !SwapOps;
7459 assert(MaskVals.
size() == NumElts &&
"Unexpected select-like shuffle");
7475 if (!Subtarget.hasStdExtP() || !VT.
isSimple())
7480 return (SVT == MVT::v4i8 || SVT == MVT::v8i8 || SVT == MVT::v4i16) &&
7486 if (!
isTypeLegal(VT) || !Subtarget.hasVInstructions())
7493 const unsigned NumElts = M.size();
7500 std::array<std::pair<int, int>, 2> SrcInfo;
7511RISCVTargetLowering::lowerCTLZ_CTTZ_ZERO_POISON(
SDValue Op,
7513 MVT VT =
Op.getSimpleValueType();
7522 MVT FloatEltVT = (EltSize >= 32) ? MVT::f64 :
MVT::f32;
7524 FloatEltVT = MVT::f32;
7531 "Expected legal float type!");
7542 if (FloatVT.
bitsGT(VT)) {
7553 MVT ContainerFloatVT =
7555 FloatVal = DAG.
getNode(RISCVISD::VFCVT_RM_F_XU_VL,
DL, ContainerFloatVT,
7556 Src, Mask, RTZRM, VL);
7563 unsigned ShiftAmt = FloatEltVT == MVT::f64 ? 52 : 23;
7570 else if (IntVT.
bitsGT(VT))
7574 unsigned ExponentBias = FloatEltVT == MVT::f64 ? 1023 : 127;
7582 unsigned Adjust = ExponentBias + (EltSize - 1);
7597 MVT XLenVT = Subtarget.getXLenVT();
7599 MVT SrcVT =
Source.getSimpleValueType();
7620 SDValue Res = DAG.
getNode(RISCVISD::VFIRST_VL,
DL, XLenVT, Source, Mask, EVL);
7621 if (
Op->getOpcode() == ISD::VP_CTTZ_ELTS_ZERO_POISON)
7639 assert(
Load &&
Load->getMemoryVT().isVector() &&
"Expected vector load");
7642 Load->getMemoryVT(),
7643 *
Load->getMemOperand()))
7647 MVT VT =
Op.getSimpleValueType();
7649 assert((EltSizeBits == 16 || EltSizeBits == 32 || EltSizeBits == 64) &&
7650 "Unexpected unaligned RVV load type");
7654 "Expecting equally-sized RVV vector types to be legal");
7656 Load->getPointerInfo(),
Load->getBaseAlign(),
7657 Load->getMemOperand()->getFlags());
7669 "Expected vector store");
7672 Store->getMemoryVT(),
7673 *
Store->getMemOperand()))
7680 assert((EltSizeBits == 16 || EltSizeBits == 32 || EltSizeBits == 64) &&
7681 "Unexpected unaligned RVV store type");
7685 "Expecting equally-sized RVV vector types to be legal");
7686 StoredVal = DAG.
getBitcast(NewVT, StoredVal);
7688 Store->getPointerInfo(),
Store->getBaseAlign(),
7689 Store->getMemOperand()->getFlags());
7699 assert(
Load &&
Load->getMemoryVT().isVector() &&
"Expected vector load");
7702 Load->getMemoryVT(),
7703 *
Load->getMemOperand()))
7713 MVT VT =
Op.getSimpleValueType();
7715 assert((EltSizeBits == 16 || EltSizeBits == 32 || EltSizeBits == 64) &&
7716 "Unexpected unaligned RVV load type");
7720 "Expecting equally-sized RVV vector types to be legal");
7729 Load->getPointerInfo(),
Load->getBaseAlign(),
7742 "Expected vector store");
7745 Store->getMemoryVT(),
7746 *
Store->getMemOperand()))
7759 assert((EltSizeBits == 16 || EltSizeBits == 32 || EltSizeBits == 64) &&
7760 "Unexpected unaligned RVV store type");
7764 "Expecting equally-sized RVV vector types to be legal");
7770 StoredVal = DAG.
getBitcast(NewVT, StoredVal);
7775 Store->getPointerInfo(),
Store->getMemOperand()->getFlags(),
Size,
7776 Store->getBaseAlign());
7787 assert(
Op.getValueType() == MVT::i64 &&
"Unexpected VT");
7799 if (!
Subtarget.useConstantPoolForLargeInts())
7816 unsigned ShiftAmt, AddOpc;
7827 MVT VT =
Op.getSimpleValueType();
7831 bool Negate =
false;
7835 if (Index < 0 &&
Imm.isNegative()) {
7858 unsigned IsData =
Op.getConstantOperandVal(4);
7861 if (
Subtarget.hasVendorXMIPSCBOP() && !IsData)
7862 return Op.getOperand(0);
7898 MVT VT =
Op.getSimpleValueType();
7899 MVT XLenVT = Subtarget.getXLenVT();
7900 unsigned Check =
Op.getConstantOperandVal(1);
7901 unsigned TDCMask = 0;
7929 MVT VT0 =
Op.getOperand(0).getSimpleValueType();
7935 VL,
Op->getFlags());
7952 SDValue FPCLASS = DAG.
getNode(RISCVISD::FCLASS_VL,
DL, ContainerDstVT, Op0,
7953 Mask, VL,
Op->getFlags());
7955 TDCMaskV = DAG.
getNode(RISCVISD::VMV_V_X_VL,
DL, ContainerDstVT,
7956 DAG.
getUNDEF(ContainerDstVT), TDCMaskV, VL);
7965 TDCMaskV, DAG.
getUNDEF(ContainerDstVT), Mask, VL);
7968 SplatZero = DAG.
getNode(RISCVISD::VMV_V_X_VL,
DL, ContainerDstVT,
7969 DAG.
getUNDEF(ContainerDstVT), SplatZero, VL);
7989 MVT VT =
Op.getSimpleValueType();
8035 DAG.
getNode(RISCVISD::SETCC_VL,
DL, Mask.getValueType(),
8036 {X, X, DAG.getCondCode(ISD::SETOEQ),
8037 DAG.getUNDEF(Mask.getValueType()), Mask, VL});
8045 DAG.
getNode(RISCVISD::SETCC_VL,
DL, Mask.getValueType(),
8046 {Y, Y, DAG.getCondCode(ISD::SETOEQ),
8047 DAG.getUNDEF(Mask.getValueType()), Mask, VL});
8053 Op.getOpcode() ==
ISD::FMAXIMUM ? RISCVISD::VFMAX_VL : RISCVISD::VFMIN_VL;
8065 "Wrong opcode for lowering FABS or FNEG.");
8068 MVT VT =
Op.getSimpleValueType();
8069 assert((VT == MVT::f16 || VT == MVT::bf16) &&
"Unexpected type");
8073 DAG.
getNode(RISCVISD::FMV_X_ANYEXTH,
DL, XLenVT,
Op.getOperand(0));
8081 return DAG.
getNode(RISCVISD::FMV_H_X,
DL, VT, Logic);
8089 MVT VT =
Op.getSimpleValueType();
8090 assert((VT == MVT::f16 || VT == MVT::bf16) &&
"Unexpected type");
8098 unsigned SignSize =
Sign.getValueSizeInBits();
8104 return DAG.
getNode(RISCVISD::FMV_X_ANYEXTH,
DL, XLenVT,
Sign);
8106 return DAG.
getNode(RISCVISD::FMV_X_ANYEXTW_RV64,
DL, XLenVT,
Sign);
8108 assert(XLenVT == MVT::i32 &&
"Unexpected type");
8111 return DAG.
getNode(RISCVISD::SplitF64,
DL, {MVT::i32, MVT::i32},
Sign)
8141 return DAG.
getNode(RISCVISD::FMV_H_X,
DL, VT, CopiedSign);
8146#define OP_CASE(NODE) \
8148 return RISCVISD::NODE##_VL;
8149#define VP_CASE(NODE) \
8150 case ISD::VP_##NODE: \
8151 return RISCVISD::NODE##_VL;
8153 switch (
Op.getOpcode()) {
8209 return RISCVISD::CTLZ_VL;
8211 return RISCVISD::CTTZ_VL;
8213 return RISCVISD::VFMADD_VL;
8215 return RISCVISD::STRICT_VFMADD_VL;
8217 if (
Op.getSimpleValueType().getVectorElementType() == MVT::i1)
8218 return RISCVISD::VMAND_VL;
8219 return RISCVISD::AND_VL;
8221 if (
Op.getSimpleValueType().getVectorElementType() == MVT::i1)
8222 return RISCVISD::VMOR_VL;
8223 return RISCVISD::OR_VL;
8225 if (
Op.getSimpleValueType().getVectorElementType() == MVT::i1)
8226 return RISCVISD::VMXOR_VL;
8227 return RISCVISD::XOR_VL;
8230 return RISCVISD::VZEXT_VL;
8232 return RISCVISD::VSEXT_VL;
8234 return RISCVISD::SETCC_VL;
8236 return RISCVISD::VMERGE_VL;
8238 return RISCVISD::VMERGE_VL;
8241 return RISCVISD::VFMIN_VL;
8244 return RISCVISD::VFMAX_VL;
8247 return RISCVISD::VFCVT_RM_X_F_VL;
8249 return RISCVISD::UDIV_VL;
8251 return RISCVISD::UREM_VL;
8253 return RISCVISD::SDIV_VL;
8255 return RISCVISD::SREM_VL;
8265 MVT OpVT =
Op.getSimpleValueType();
8269 if (!(EltVT == MVT::f16 &&
Subtarget.hasVInstructionsF16Minimal() &&
8271 !(EltVT == MVT::bf16 &&
Subtarget.hasVInstructionsBF16Minimal() &&
8276 return !
TLI.isTypeLegal(
8287 for (
unsigned j = 0; j !=
Op.getNumOperands(); ++j) {
8288 if (!
Op.getOperand(j).getValueType().isVector()) {
8289 LoOperands[j] =
Op.getOperand(j);
8290 HiOperands[j] =
Op.getOperand(j);
8293 std::tie(LoOperands[j], HiOperands[j]) =
8298 DAG.
getNode(
Op.getOpcode(),
DL, LoVT, LoOperands,
Op->getFlags());
8300 DAG.
getNode(
Op.getOpcode(),
DL, HiVT, HiOperands,
Op->getFlags());
8312 auto [EVLLo, EVLHi] =
8313 DAG.
SplitEVL(
Op.getOperand(3),
Op.getOperand(1).getValueType(),
DL);
8317 {Op.getOperand(0), Lo, MaskLo, EVLLo},
Op->getFlags());
8319 {ResLo, Hi, MaskHi, EVLHi},
Op->getFlags());
8322 unsigned Opcode =
Op.getOpcode();
8328 Op.getOperand(0),
Lo,
Op->getFlags());
8338 return DAG.
getNode(BaseOpc,
DL,
Op.getValueType(), ResLo, ResHi,
8356 for (
unsigned j = 0; j !=
Op.getNumOperands(); ++j) {
8357 if (!
Op.getOperand(j).getValueType().isVector()) {
8358 LoOperands[j] =
Op.getOperand(j);
8359 HiOperands[j] =
Op.getOperand(j);
8362 std::tie(LoOperands[j], HiOperands[j]) =
8367 DAG.
getNode(
Op.getOpcode(),
DL, LoVTs, LoOperands,
Op->getFlags());
8370 DAG.
getNode(
Op.getOpcode(),
DL, HiVTs, HiOperands,
Op->getFlags());
8378RISCVTargetLowering::lowerXAndesBfHCvtBFloat16Load(
SDValue Op,
8380 assert(Subtarget.hasVendorXAndesBFHCvt() && !Subtarget.hasStdExtZfh() &&
8381 "Unexpected bfloat16 load lowering");
8385 EVT MemVT =
LD->getMemoryVT();
8390 LD->getMemOperand());
8398 DAG.
getNode(RISCVISD::NDS_FMV_BF16_X,
DL, MVT::bf16, OrSixteenOne);
8403RISCVTargetLowering::lowerXAndesBfHCvtBFloat16Store(
SDValue Op,
8405 assert(Subtarget.hasVendorXAndesBFHCvt() && !Subtarget.hasStdExtZfh() &&
8406 "Unexpected bfloat16 store lowering");
8411 Subtarget.getXLenVT(),
ST->getValue());
8413 ST->getChain(),
DL, FMV,
ST->getBasePtr(),
8415 ST->getMemOperand());
8426 switch (
Op.getOpcode()) {
8429 "Unimplemented RISCVTargetLowering::LowerOperation Case");
8435 return lowerGlobalAddress(
Op, DAG);
8437 return lowerBlockAddress(
Op, DAG);
8439 return lowerConstantPool(
Op, DAG);
8441 return lowerJumpTable(
Op, DAG);
8443 return lowerGlobalTLSAddress(
Op, DAG);
8447 return lowerConstantFP(
Op, DAG);
8449 return lowerSELECT(
Op, DAG);
8451 return lowerBRCOND(
Op, DAG);
8453 return lowerVASTART(
Op, DAG);
8455 return lowerFRAMEADDR(
Op, DAG);
8457 return lowerRETURNADDR(
Op, DAG);
8459 return lowerShiftLeftParts(
Op, DAG);
8461 return lowerShiftRightParts(
Op, DAG,
true);
8463 return lowerShiftRightParts(
Op, DAG,
false);
8466 if (
Op.getValueType().isFixedLengthVector()) {
8467 assert(Subtarget.hasStdExtZvkb());
8468 return lowerToScalableOp(
Op, DAG);
8470 assert(Subtarget.hasVendorXTHeadBb() &&
8471 !(Subtarget.hasStdExtZbb() || Subtarget.hasStdExtZbkb()) &&
8472 "Unexpected custom legalization");
8479 EVT VT =
Op.getValueType();
8482 MVT XLenVT = Subtarget.getXLenVT();
8483 if (Op0VT == MVT::i16 &&
8484 ((VT == MVT::f16 && Subtarget.hasStdExtZfhminOrZhinxmin()) ||
8485 (VT == MVT::bf16 && Subtarget.hasStdExtZfbfmin()))) {
8487 return DAG.
getNode(RISCVISD::FMV_H_X,
DL, VT, NewOp0);
8489 if (VT == MVT::f32 && Op0VT == MVT::i32 && Subtarget.is64Bit() &&
8490 Subtarget.hasStdExtFOrZfinx()) {
8492 return DAG.
getNode(RISCVISD::FMV_W_X_RV64,
DL, MVT::f32, NewOp0);
8494 if (VT == MVT::f64 && Op0VT == MVT::i64 && !Subtarget.is64Bit() &&
8495 Subtarget.hasStdExtDOrZdinx()) {
8498 return DAG.
getNode(RISCVISD::BuildPairF64,
DL, MVT::f64,
Lo,
Hi);
8505 if (Op0VT.
getSimpleVT() == Subtarget.getXLenVT() &&
8519 "Unexpected types");
8551 return LowerINTRINSIC_WO_CHAIN(
Op, DAG);
8553 return LowerINTRINSIC_W_CHAIN(
Op, DAG);
8555 return LowerINTRINSIC_VOID(
Op, DAG);
8557 return LowerIS_FPCLASS(
Op, DAG);
8559 MVT VT =
Op.getSimpleValueType();
8560 if (VT == MVT::v8i8 && !Subtarget.is64Bit() && Subtarget.hasStdExtP()) {
8569 assert(Subtarget.hasStdExtZvbb());
8570 return lowerToScalableOp(
Op, DAG);
8573 assert(Subtarget.hasStdExtZbkb() &&
"Unexpected custom legalization");
8577 return DAG.
getNode(RISCVISD::BREV8,
DL, VT, BSwap);
8583 if (!
Op.getSimpleValueType().isVector())
8585 return lowerVectorTrunc(
Op, DAG);
8588 if (
Op.getOperand(0).getValueType().isVector() &&
8589 Op.getOperand(0).getValueType().getVectorElementType() == MVT::i1)
8590 return lowerVectorMaskExt(
Op, DAG, 1);
8591 if (
Op.getValueType().isScalableVector())
8593 return lowerToScalableOp(
Op, DAG);
8595 if (
Op.getOperand(0).getValueType().isVector() &&
8596 Op.getOperand(0).getValueType().getVectorElementType() == MVT::i1)
8597 return lowerVectorMaskExt(
Op, DAG, -1);
8598 if (
Op.getValueType().isScalableVector())
8600 return lowerToScalableOp(
Op, DAG);
8602 return lowerSPLAT_VECTOR_PARTS(
Op, DAG);
8604 return lowerINSERT_VECTOR_ELT(
Op, DAG);
8606 return lowerEXTRACT_VECTOR_ELT(
Op, DAG);
8608 MVT VT =
Op.getSimpleValueType();
8635 MVT XLenVT = Subtarget.getXLenVT();
8636 MVT VT =
Op.getSimpleValueType();
8647 uint64_t Val =
Op.getConstantOperandVal(0);
8655 }
else if (
Log2 > 3) {
8659 }
else if ((Val % 8) == 0) {
8677 if (
Op.getValueType() == MVT::f16 && Subtarget.is64Bit() &&
8678 Op.getOperand(1).getValueType() == MVT::i32) {
8695 return lowerVectorFPExtendOrRound(
Op, DAG);
8698 return lowerStrictFPExtendOrRoundLike(
Op, DAG);
8704 if (
Op.getValueType().isVector() &&
8705 Op.getOperand(0).getValueType().getVectorElementType() == MVT::i1) {
8707 EVT VT =
Op.getValueType();
8715 Op.getValueType().isVector() &&
8716 ((
Op.getValueType().getScalarType() == MVT::f16 &&
8717 (Subtarget.hasVInstructionsF16Minimal() &&
8718 !Subtarget.hasVInstructionsF16())) ||
8719 (
Op.getValueType().getScalarType() == MVT::bf16 &&
8720 (Subtarget.hasVInstructionsBF16Minimal() &&
8721 (!Subtarget.hasVInstructionsBF16() ||
8722 Op1.getValueType().getScalarSizeInBits() > 8))))) {
8740 Op1.getValueType().isVector() &&
8741 ((Op1.getValueType().getScalarType() == MVT::f16 &&
8742 (Subtarget.hasVInstructionsF16Minimal() &&
8743 !Subtarget.hasVInstructionsF16())) ||
8744 (Op1.getValueType().getScalarType() == MVT::bf16 &&
8745 (Subtarget.hasVInstructionsBF16Minimal() &&
8746 (!Subtarget.hasVInstructionsBF16() ||
8747 Op.getValueType().getScalarSizeInBits() > 8))))) {
8749 Op1.getValueType().getVectorElementCount());
8756 return DAG.
getNode(
Op.getOpcode(),
DL,
Op.getValueType(), WidenVec);
8766 MVT VT =
Op.getSimpleValueType();
8769 bool IsStrict =
Op->isStrictFPOpcode();
8770 SDValue Src =
Op.getOperand(0 + IsStrict);
8771 MVT SrcVT = Src.getSimpleValueType();
8782 "Unexpected vector element types");
8786 if (EltSize > (2 * SrcEltSize)) {
8798 Op.getOperand(0), Ext);
8802 assert((SrcEltVT == MVT::f16 || SrcEltVT == MVT::bf16) &&
8803 "Unexpected FP_TO_[US]INT lowering");
8808 auto [FExt, Chain] =
8810 return DAG.
getNode(
Op.getOpcode(),
DL,
Op->getVTList(), Chain, FExt);
8817 if (SrcEltSize > (2 * EltSize)) {
8820 assert((EltVT == MVT::f16 || EltVT == MVT::bf16) &&
8821 "Unexpected [US]_TO_FP lowering");
8826 Op.getOperand(0), Src);
8841 Op.getOperand(0), Src);
8859 unsigned RVVOpc = 0;
8860 switch (
Op.getOpcode()) {
8864 RVVOpc = RISCVISD::VFCVT_RTZ_X_F_VL;
8867 RVVOpc = RISCVISD::VFCVT_RTZ_XU_F_VL;
8870 RVVOpc = RISCVISD::SINT_TO_FP_VL;
8873 RVVOpc = RISCVISD::UINT_TO_FP_VL;
8876 RVVOpc = RISCVISD::STRICT_VFCVT_RTZ_X_F_VL;
8879 RVVOpc = RISCVISD::STRICT_VFCVT_RTZ_XU_F_VL;
8882 RVVOpc = RISCVISD::STRICT_SINT_TO_FP_VL;
8885 RVVOpc = RISCVISD::STRICT_UINT_TO_FP_VL;
8892 "Expected same element count");
8899 Op.getOperand(0), Src, Mask, VL);
8912 assert(!Subtarget.isSoftFPABI() &&
"Unexpected custom legalization");
8918 makeLibCall(DAG, LC, MVT::f32,
Op.getOperand(0), CallOptions,
DL).first;
8919 if (Subtarget.is64Bit())
8920 return DAG.
getNode(RISCVISD::FMV_X_ANYEXTW_RV64,
DL, MVT::i64, Res);
8924 assert(Subtarget.hasStdExtFOrZfinx() &&
"Unexpected custom legalization");
8925 MVT VT =
Op.getSimpleValueType();
8930 SDValue Res = Subtarget.is64Bit()
8931 ? DAG.
getNode(RISCVISD::FMV_W_X_RV64,
DL, MVT::f32,
Op)
8942 assert(Subtarget.hasStdExtFOrZfinx() &&
"Unexpected custom legalisation");
8945 bool IsStrict =
Op->isStrictFPOpcode();
8946 SDValue Op0 = IsStrict ?
Op.getOperand(1) :
Op.getOperand(0);
8950 std::tie(Res, Chain) =
8951 makeLibCall(DAG, LC, MVT::f32, Op0, CallOptions,
DL, Chain);
8954 ? DAG.
getNode(RISCVISD::FMV_X_ANYEXTW_RV64,
DL, MVT::i64, Res)
8964 assert(Subtarget.hasStdExtFOrZfinx() &&
"Unexpected custom legalisation");
8967 bool IsStrict =
Op->isStrictFPOpcode();
8968 SDValue Op0 = IsStrict ?
Op.getOperand(1) :
Op.getOperand(0);
8970 SDValue Arg = Subtarget.is64Bit()
8971 ? DAG.
getNode(RISCVISD::FMV_W_X_RV64,
DL, MVT::f32, Op0)
8974 std::tie(Res, Chain) =
makeLibCall(DAG, RTLIB::FPEXT_F16_F32, MVT::f32, Arg,
8975 CallOptions,
DL, Chain);
8992 MVT VT =
Op.getSimpleValueType();
9005 if (
Op.getValueType().isVector())
9007 assert(
Op.getOperand(0).getValueType() == MVT::f16 &&
9008 "Unexpected custom legalisation");
9011 return DAG.
getNode(
Op.getOpcode(),
DL,
Op.getValueType(), Ext);
9017 assert(
Op.getOperand(1).getValueType() == MVT::f16 &&
9018 "Unexpected custom legalisation");
9021 {
Op.getOperand(0),
Op.getOperand(1)});
9022 return DAG.
getNode(
Op.getOpcode(),
DL, {Op.getValueType(), MVT::Other},
9023 {Ext.getValue(1), Ext.getValue(0)});
9030 return lowerVECREDUCE(
Op, DAG);
9034 if (
Op.getOperand(0).getValueType().getVectorElementType() == MVT::i1)
9035 return lowerVectorMaskVecReduction(
Op, DAG,
false);
9036 return lowerVECREDUCE(
Op, DAG);
9040 return lowerFPVECREDUCE(
Op, DAG);
9048 return lowerFPVECREDUCE(
Op, DAG);
9049 case ISD::VP_REDUCE_ADD:
9050 case ISD::VP_REDUCE_UMAX:
9051 case ISD::VP_REDUCE_SMAX:
9052 case ISD::VP_REDUCE_UMIN:
9053 case ISD::VP_REDUCE_SMIN:
9054 case ISD::VP_REDUCE_FADD:
9055 case ISD::VP_REDUCE_SEQ_FADD:
9056 case ISD::VP_REDUCE_FMIN:
9057 case ISD::VP_REDUCE_FMAX:
9058 case ISD::VP_REDUCE_FMINIMUM:
9059 case ISD::VP_REDUCE_FMAXIMUM:
9062 return lowerVPREDUCE(
Op, DAG);
9063 case ISD::VP_REDUCE_AND:
9064 case ISD::VP_REDUCE_OR:
9065 case ISD::VP_REDUCE_XOR:
9066 if (
Op.getOperand(1).getValueType().getVectorElementType() == MVT::i1)
9067 return lowerVectorMaskVecReduction(
Op, DAG,
true);
9068 return lowerVPREDUCE(
Op, DAG);
9069 case ISD::VP_CTTZ_ELTS:
9070 case ISD::VP_CTTZ_ELTS_ZERO_POISON:
9071 return lowerVPCttzElements(
Op, DAG);
9082 return lowerINSERT_SUBVECTOR(
Op, DAG);
9084 return lowerEXTRACT_SUBVECTOR(
Op, DAG);
9086 return lowerVECTOR_DEINTERLEAVE(
Op, DAG);
9088 return lowerVECTOR_INTERLEAVE(
Op, DAG);
9090 return lowerSTEP_VECTOR(
Op, DAG);
9092 return lowerVECTOR_REVERSE(
Op, DAG);
9095 return lowerVECTOR_SPLICE(
Op, DAG);
9097 MVT VT =
Op.getSimpleValueType();
9099 if (!Subtarget.is64Bit() && EltVT == MVT::i64)
9104 MVT VT =
Op.getSimpleValueType();
9106 if ((EltVT == MVT::f16 && !Subtarget.hasVInstructionsF16()) ||
9107 EltVT == MVT::bf16) {
9110 if ((EltVT == MVT::bf16 && Subtarget.hasStdExtZfbfmin()) ||
9111 (EltVT == MVT::f16 && Subtarget.hasStdExtZfhmin()))
9112 Elt = DAG.
getNode(RISCVISD::FMV_X_ANYEXTH,
DL, Subtarget.getXLenVT(),
9121 if (EltVT == MVT::i1)
9122 return lowerVectorMaskSplat(
Op, DAG);
9126 return lowerVECTOR_SHUFFLE(
Op, DAG);
9131 MVT VT =
Op.getSimpleValueType();
9144 if (
Op.getNumOperands() > 2 &&
9148 size_t HalfNumOps =
Op.getNumOperands() / 2;
9150 Op->ops().take_front(HalfNumOps));
9152 Op->ops().drop_front(HalfNumOps));
9156 unsigned NumOpElts =
9157 Op.getOperand(0).getSimpleValueType().getVectorMinNumElements();
9160 SDValue SubVec = OpIdx.value();
9170 EVT VT =
Load->getValueType(0);
9171 if (VT == MVT::f64) {
9172 assert(Subtarget.hasStdExtZdinx() && !Subtarget.hasStdExtZilsd() &&
9173 !Subtarget.is64Bit() &&
"Unexpected custom legalisation");
9181 DAG.
getLoad(MVT::i32,
DL, Chain, BasePtr,
Load->getPointerInfo(),
9182 Load->getBaseAlign(),
Load->getMemOperand()->getFlags());
9185 MVT::i32,
DL, Chain, BasePtr,
Load->getPointerInfo().getWithOffset(4),
9186 Load->getBaseAlign(),
Load->getMemOperand()->getFlags());
9191 if (!Subtarget.isLittleEndian())
9198 if (Subtarget.hasStdExtP() && !Subtarget.is64Bit() &&
9199 (VT == MVT::v2i32 || VT == MVT::v4i16 || VT == MVT::v8i8)) {
9200 assert(!Subtarget.is64Bit() &&
"Unexpected custom legalisation");
9204 if (VT == MVT::v2i32)
9206 else if (VT == MVT::v4i16)
9207 HalfVT = MVT::v2i16;
9217 DAG.
getLoad(HalfVT,
DL, Chain, BasePtr,
Load->getPointerInfo(),
9218 Load->getBaseAlign(),
Load->getMemOperand()->getFlags());
9224 Load->getPointerInfo().getWithOffset(HalfSize),
9225 Load->getBaseAlign(),
Load->getMemOperand()->getFlags());
9231 if (VT == MVT::v2i32) {
9242 if (VT == MVT::bf16)
9243 return lowerXAndesBfHCvtBFloat16Load(
Op, DAG);
9248 MVT XLenVT = Subtarget.getXLenVT();
9251 unsigned NumElts = Sz / (NF * 8);
9252 int Log2LMUL =
Log2_64(NumElts) - 3;
9255 Flag.setNoUnsignedWrap(
true);
9265 for (
unsigned i = 0; i < NF; ++i) {
9270 Ret = DAG.
getNode(RISCVISD::TUPLE_INSERT,
DL, VT, Ret, LoadVal,
9278 if (
auto V = expandUnalignedRVVLoad(
Op, DAG))
9280 if (
Op.getValueType().isFixedLengthVector())
9281 return lowerFixedLengthVectorLoadToRVV(
Op, DAG);
9289 if (VT == MVT::f64) {
9290 assert(Subtarget.hasStdExtZdinx() && !Subtarget.hasStdExtZilsd() &&
9291 !Subtarget.is64Bit() &&
"Unexpected custom legalisation");
9298 DAG.
getVTList(MVT::i32, MVT::i32), StoredVal);
9304 if (!Subtarget.isLittleEndian())
9308 Chain,
DL,
Lo, BasePtr,
Store->getPointerInfo(),
9309 Store->getBaseAlign(),
Store->getMemOperand()->getFlags());
9312 Chain,
DL,
Hi, BasePtr,
Store->getPointerInfo().getWithOffset(4),
9313 Store->getBaseAlign(),
Store->getMemOperand()->getFlags());
9316 if (VT == MVT::i64) {
9317 assert(Subtarget.hasStdExtZilsd() && !Subtarget.is64Bit() &&
9318 "Unexpected custom legalisation");
9319 if (
Store->isTruncatingStore())
9322 if (
Store->getAlign() < Subtarget.getZilsdAlign())
9333 {Store->getChain(), Lo, Hi, Store->getBasePtr()}, MVT::i64,
9334 Store->getMemOperand());
9337 if (Subtarget.hasStdExtP() && !Subtarget.is64Bit() &&
9338 (VT == MVT::v2i32 || VT == MVT::v4i16 || VT == MVT::v8i8)) {
9339 assert(!Subtarget.is64Bit() &&
"Unexpected custom legalisation");
9346 if (VT == MVT::v2i32)
9348 else if (VT == MVT::v4i16)
9349 HalfVT = MVT::v2i16;
9359 if (VT == MVT::v2i32) {
9376 Chain,
DL,
Lo, BasePtr,
Store->getPointerInfo(),
9377 Store->getBaseAlign(),
Store->getMemOperand()->getFlags());
9382 Chain,
DL,
Hi, BasePtr,
9383 Store->getPointerInfo().getWithOffset(HalfSize),
9384 Store->getBaseAlign(),
Store->getMemOperand()->getFlags());
9389 if (VT == MVT::bf16)
9390 return lowerXAndesBfHCvtBFloat16Store(
Op, DAG);
9395 MVT XLenVT = Subtarget.getXLenVT();
9398 unsigned NumElts = Sz / (NF * 8);
9399 int Log2LMUL =
Log2_64(NumElts) - 3;
9402 Flag.setNoUnsignedWrap(
true);
9412 for (
unsigned i = 0; i < NF; ++i) {
9414 DAG.
getNode(RISCVISD::TUPLE_EXTRACT,
DL,
9417 Ret = DAG.
getStore(Chain,
DL, Extract, BasePtr,
9419 Store->getBaseAlign(),
9420 Store->getMemOperand()->getFlags());
9427 if (
auto V = expandUnalignedRVVStore(
Op, DAG))
9429 if (
Op.getOperand(1).getValueType().isFixedLengthVector())
9430 return lowerFixedLengthVectorStoreToRVV(
Op, DAG);
9434 if (
SDValue V = expandUnalignedVPLoad(
Op, DAG))
9438 return lowerMaskedLoad(
Op, DAG);
9439 case ISD::VP_LOAD_FF:
9440 return lowerLoadFF(
Op, DAG);
9442 if (
SDValue V = expandUnalignedVPStore(
Op, DAG))
9446 return lowerMaskedStore(
Op, DAG);
9448 return lowerVectorCompress(
Op, DAG);
9457 EVT VT =
Op.getValueType();
9468 MVT OpVT =
Op.getOperand(0).getSimpleValueType();
9470 MVT VT =
Op.getSimpleValueType();
9475 "Unexpected CondCode");
9508 return DAG.
getSetCC(
DL, VT, RHS, LHS, CCVal);
9511 MVT VT =
Op.getSimpleValueType();
9538 return DAG.
getSetCC(
DL, VT, RHS, LHS, CCVal);
9547 return lowerToScalableOp(
Op, DAG);
9557 return lowerToScalableOp(
Op, DAG);
9559 EVT VT =
Op.getValueType();
9561 if (Subtarget.hasStdExtP() && !Subtarget.is64Bit() &&
9562 (VT == MVT::v4i16 || VT == MVT::v8i8)) {
9575 MaskLo, TrueLo, FalseLo);
9577 MaskHi, TrueHi, FalseHi);
9581 return lowerToScalableOp(
Op, DAG);
9589 EVT VT =
Op.getValueType();
9590 unsigned Opc =
Op.getOpcode();
9592 if (Subtarget.hasStdExtP() && !Subtarget.is64Bit() &&
9593 (VT == MVT::v4i16 || VT == MVT::v8i8)) {
9599 MVT HalfVT = (VT == MVT::v4i16) ? MVT::v2i16 : MVT::v4i8;
9602 auto [LHSLo, LHSHi] = DAG.
SplitVector(LHS,
DL, HalfVT, HalfVT);
9605 auto [RHSLo, RHSHi] = DAG.
SplitVector(RHS,
DL, HalfVT, HalfVT);
9614 if (Subtarget.hasStdExtP() && !Subtarget.is64Bit() &&
9616 (VT == MVT::v4i8 || VT == MVT::v2i16)) {
9618 "Unexpected custom legalisation");
9620 MVT WideVT = (VT == MVT::v4i8) ? MVT::v4i16 : MVT::v2i32;
9624 DAG.
getNode(WMulOpc,
DL, WideVT,
Op.getOperand(0),
Op.getOperand(1));
9634 if (Subtarget.hasStdExtP() && Subtarget.is64Bit() &&
9635 ((
Opc ==
ISD::MUL && (VT == MVT::v8i8 || VT == MVT::v4i16)) ||
9640 unsigned LoOpc =
Opc ==
ISD::MULHU ? RISCVISD::PMULU_HALVES_00
9641 : RISCVISD::PMUL_HALVES_00;
9642 unsigned HiOpc =
Opc ==
ISD::MULHU ? RISCVISD::PMULU_HALVES_11
9643 : RISCVISD::PMUL_HALVES_11;
9644 MVT WideVT = VT == MVT::v8i8 ? MVT::v4i16 : MVT::v2i32;
9647 unsigned PairOpc =
Opc ==
ISD::MUL ? RISCVISD::PPAIRE : RISCVISD::PPAIRO;
9651 return lowerToScalableOp(
Op, DAG);
9654 EVT VT =
Op.getValueType();
9655 assert(Subtarget.hasStdExtP() && Subtarget.is64Bit() &&
9656 (VT == MVT::v2i32 || VT == MVT::v4i16) &&
9657 "Unexpected custom legalisation");
9665 if (
Op.getSimpleValueType().isFixedLengthVector()) {
9666 if (Subtarget.hasStdExtP()) {
9674 switch (
Op.getOpcode()) {
9678 Opc = RISCVISD::PSLL;
9681 Opc = RISCVISD::PSRL;
9684 Opc = RISCVISD::PSRA;
9687 Opc = RISCVISD::PSSHA;
9693 return lowerToScalableOp(
Op, DAG);
9699 ((Subtarget.is64Bit() &&
Op.getOperand(1).getValueType() == MVT::i32) ||
9700 (!Subtarget.is64Bit() && Subtarget.hasStdExtP() &&
9701 Op.getOperand(1).getValueType() == MVT::i64)) &&
9702 "Unexpected custom legalisation");
9709 MVT VT =
Op.getSimpleValueType();
9724 if (
Op.getValueType() == MVT::f16 ||
Op.getValueType() == MVT::bf16)
9752 return lowerToScalableOp(
Op, DAG);
9755 EVT VT =
Op->getValueType(0);
9756 if (Subtarget.hasStdExtZvabd() && VT.
isVector())
9757 return lowerToScalableOp(
Op, DAG);
9774 return lowerABS(
Op, DAG);
9779 if (Subtarget.hasStdExtZvbb())
9780 return lowerToScalableOp(
Op, DAG);
9782 return lowerCTLZ_CTTZ_ZERO_POISON(
Op, DAG);
9786 MVT VT =
Op.getSimpleValueType();
9787 MVT XLenVT = Subtarget.getXLenVT();
9791 assert(Subtarget.hasStdExtZvbc() && Subtarget.is64Bit() && VT == XLenVT &&
9792 "Unexpected custom legalisation");
9795 Attribute::NoImplicitFloat))
9804 return DAG.
getNode(RISCVISD::VMV_X_S,
DL, XLenVT, Res);
9810 return lowerToScalableOp(
Op, DAG);
9813 "Unexpected custom legalisation");
9822 if (
Op.getValueType() == MVT::f16 ||
Op.getValueType() == MVT::bf16)
9826 return lowerToScalableOp(
Op, DAG);
9835 return lowerToScalableOp(
Op, DAG);
9838 return lowerVectorStrictFSetcc(
Op, DAG);
9848 case ISD::VP_GATHER:
9849 return lowerMaskedGather(
Op, DAG);
9851 case ISD::VP_SCATTER:
9852 return lowerMaskedScatter(
Op, DAG);
9854 return lowerGET_ROUNDING(
Op, DAG);
9856 return lowerSET_ROUNDING(
Op, DAG);
9858 return lowerGET_FPENV(
Op, DAG);
9860 return lowerSET_FPENV(
Op, DAG);
9862 return lowerRESET_FPENV(
Op, DAG);
9864 return lowerGET_FPMODE(
Op, DAG);
9866 return lowerSET_FPMODE(
Op, DAG);
9868 return lowerRESET_FPMODE(
Op, DAG);
9870 return lowerEH_DWARF_CFA(
Op, DAG);
9872 if (
Op.getSimpleValueType().getVectorElementType() == MVT::i1)
9873 return lowerVPMergeMask(
Op, DAG);
9879 return lowerVPOp(
Op, DAG);
9880 case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
9881 return lowerVPStridedLoad(
Op, DAG);
9882 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
9883 return lowerVPStridedStore(
Op, DAG);
9884 case ISD::EXPERIMENTAL_VP_SPLICE:
9885 return lowerVPSpliceExperimental(
Op, DAG);
9886 case ISD::EXPERIMENTAL_VP_REVERSE:
9887 return lowerVPReverseExperimental(
Op, DAG);
9890 "llvm.clear_cache only needs custom lower on Linux targets");
9893 return emitFlushICache(DAG,
Op.getOperand(0),
Op.getOperand(1),
9894 Op.getOperand(2), Flags,
DL);
9897 return lowerDYNAMIC_STACKALLOC(
Op, DAG);
9899 return lowerINIT_TRAMPOLINE(
Op, DAG);
9901 return lowerADJUST_TRAMPOLINE(
Op, DAG);
9905 return lowerPARTIAL_REDUCE_MLA(
Op, DAG);
9917 MakeLibCallOptions CallOptions;
9918 std::pair<SDValue, SDValue> CallResult =
9919 makeLibCall(DAG, RTLIB::RISCV_FLUSH_ICACHE, MVT::isVoid,
9920 {Start,
End, Flags}, CallOptions,
DL, InChain);
9923 return CallResult.second;
9928 if (!Subtarget.is64Bit())
9936 std::unique_ptr<MCCodeEmitter> CodeEmitter(
9965 const bool HasCFBranch =
9966 MF.
getInfo<RISCVMachineFunctionInfo>()->hasCFProtectionBranch();
9967 const unsigned StaticChainIdx = HasCFBranch ? 5 : 4;
9968 const unsigned StaticChainOffset = StaticChainIdx * 4;
9969 const unsigned FunctionAddressOffset = StaticChainOffset + 8;
9972 auto GetEncoding = [&](
const MCInst &MC) {
9975 CodeEmitter->encodeInstruction(MC, CB, Fixups, STI);
9982 SmallVector<uint32_t> Encodings;
9987 GetEncoding(MCInstBuilder(RISCV::AUIPC).addReg(RISCV::X7).addImm(0)),
9991 GetEncoding(MCInstBuilder(RISCV::LD)
9994 .addImm(FunctionAddressOffset)),
9997 GetEncoding(MCInstBuilder(RISCV::LD)
10000 .addImm(StaticChainOffset)),
10003 GetEncoding(MCInstBuilder(RISCV::JALR)
10011 GetEncoding(MCInstBuilder(RISCV::AUIPC).addReg(RISCV::X0).addImm(0)),
10014 GetEncoding(MCInstBuilder(RISCV::AUIPC).addReg(RISCV::X28).addImm(0)),
10018 GetEncoding(MCInstBuilder(RISCV::LD)
10020 .addReg(RISCV::X28)
10021 .addImm(FunctionAddressOffset - 4)),
10024 GetEncoding(MCInstBuilder(RISCV::LD)
10025 .addReg(RISCV::X28)
10026 .addReg(RISCV::X28)
10027 .addImm(StaticChainOffset - 4)),
10030 GetEncoding(MCInstBuilder(RISCV::JALR)
10042 Root, dl, DAG.
getConstant(Encoding, dl, MVT::i64), Addr,
10043 MachinePointerInfo(TrmpAddr, Idx * 4), MVT::i32));
10047 SDValue FunctionAddress =
Op.getOperand(2);
10048 SDValue StaticChain =
Op.getOperand(3);
10051 struct OffsetValuePair {
10055 } OffsetValues[] = {
10056 {StaticChainOffset, StaticChain},
10057 {FunctionAddressOffset, FunctionAddress},
10059 for (
auto &OffsetValue : OffsetValues) {
10062 DAG.
getConstant(OffsetValue.Offset, dl, MVT::i64));
10063 OffsetValue.Addr = Addr;
10065 DAG.
getStore(Root, dl, OffsetValue.Value, Addr,
10066 MachinePointerInfo(TrmpAddr, OffsetValue.Offset)));
10069 assert(OutChains.
size() == StaticChainIdx + 2 &&
10070 "Size of OutChains mismatch");
10075 SDValue EndOfTrmp = OffsetValues[0].Addr;
10086 if (!Subtarget.is64Bit())
10089 return Op.getOperand(0);
10099 MVT VT =
Op.getSimpleValueType();
10103 MVT ArgVT =
A.getSimpleValueType();
10104 assert(ArgVT ==
B.getSimpleValueType() &&
10121 {DAG.getConstant(0, DL, DotVT), A, B});
10177 switch (
Op.getOpcode()) {
10179 Opc = RISCVISD::VDOT4A_VL;
10182 Opc = RISCVISD::VDOT4AU_VL;
10185 Opc = RISCVISD::VDOT4ASU_VL;
10211 N->getOffset(), Flags);
10240template <
class NodeTy>
10242 bool IsLocal,
bool IsExternWeak)
const {
10252 if (IsLocal && !Subtarget.allowTaggedGlobals())
10256 return DAG.
getNode(RISCVISD::LLA,
DL, Ty, Addr);
10279 if (Subtarget.hasVendorXqcili()) {
10283 return DAG.
getNode(RISCVISD::QC_E_LI,
DL, Ty, Addr);
10290 return DAG.
getNode(RISCVISD::ADD_LO,
DL, Ty, MNHi, AddrLo);
10294 if (IsExternWeak) {
10314 return DAG.
getNode(RISCVISD::LLA,
DL, Ty, Addr);
10322 return DAG.
getNode(RISCVISD::LLA,
DL, Ty, Addr);
10330 assert(
N->getOffset() == 0 &&
"unexpected offset in global node");
10331 const GlobalValue *GV =
N->getGlobal();
10340 return getAddr(
N, DAG);
10347 return getAddr(
N, DAG);
10354 return getAddr(
N, DAG);
10359 bool UseGOT)
const {
10362 const GlobalValue *GV =
N->getGlobal();
10363 MVT XLenVT = Subtarget.getXLenVT();
10400 DAG.
getNode(RISCVISD::ADD_TPREL,
DL, Ty, MNHi, TPReg, AddrAdd);
10401 return DAG.
getNode(RISCVISD::ADD_LO,
DL, Ty, MNAdd, AddrLo);
10409 const GlobalValue *GV =
N->getGlobal();
10423 TargetLowering::CallLoweringInfo CLI(DAG);
10424 CLI.setDebugLoc(
DL)
10437 const GlobalValue *GV =
N->getGlobal();
10453 assert(
N->getOffset() == 0 &&
"unexpected offset in global node");
10467 Addr = getStaticTLSAddr(
N, DAG,
false);
10470 Addr = getStaticTLSAddr(
N, DAG,
true);
10475 : getDynamicTLSAddr(
N, DAG);
10492 if (
LHS == LHS2 &&
RHS == RHS2) {
10497 }
else if (
LHS == RHS2 &&
RHS == LHS2) {
10505 return std::nullopt;
10516 SDValue FalseV =
N->getOperand(2);
10517 MVT VT =
N->getSimpleValueType(0);
10520 if (!
Subtarget.hasConditionalMoveFusion()) {
10544 int64_t MulImm = TrueC->getSExtValue();
10547 return DAG.
getNode(RISCVISD::QC_MULIADD,
DL, VT, CondV, CondV,
10551 uint64_t TrueVal = TrueC->getZExtValue();
10560 unsigned ShAmount =
Log2_64(TrueM1);
10562 return DAG.
getNode(RISCVISD::SHL_ADD,
DL, VT, CondV,
10578 if (~TrueVal == FalseVal) {
10618 if (
Subtarget.hasShortForwardBranchIALU())
10621 unsigned SelOpNo = 0;
10631 unsigned ConstSelOpNo = 1;
10632 unsigned OtherSelOpNo = 2;
10639 if (!ConstSelOpNode || ConstSelOpNode->
isOpaque())
10644 if (!ConstBinOpNode || ConstBinOpNode->
isOpaque())
10650 SDValue NewConstOps[2] = {ConstSelOp, ConstBinOp};
10652 std::swap(NewConstOps[0], NewConstOps[1]);
10664 SDValue NewNonConstOps[2] = {OtherSelOp, ConstBinOp};
10666 std::swap(NewNonConstOps[0], NewNonConstOps[1]);
10669 SDValue NewT = (ConstSelOpNo == 1) ? NewConstOp : NewNonConstOp;
10670 SDValue NewF = (ConstSelOpNo == 1) ? NewNonConstOp : NewConstOp;
10679 MVT VT =
Op.getSimpleValueType();
10680 MVT XLenVT = Subtarget.getXLenVT();
10688 if (Subtarget.isPExtPackedType(VT)) {
10710 bool FPinGPR = Subtarget.hasStdExtZfinx();
10714 Subtarget.getXLenVT().getSizeInBits());
10716 bool UseZicondForFPSel = Subtarget.hasStdExtZicond() && FPinGPR &&
10719 if (UseZicondForFPSel) {
10726 if (VT == MVT::f16)
10727 return DAG.
getNode(RISCVISD::FMV_X_ANYEXTH,
DL, XLenVT,
V);
10729 if (VT == MVT::f32 && Subtarget.is64Bit())
10730 return DAG.
getNode(RISCVISD::FMV_X_ANYEXTW_RV64,
DL, XLenVT,
V);
10735 SDValue TrueVInt = CastToInt(TrueV);
10736 SDValue FalseVInt = CastToInt(FalseV);
10743 if (VT == MVT::f32 && Subtarget.is64Bit())
10744 return DAG.
getNode(RISCVISD::FMV_W_X_RV64,
DL, VT, ResultInt);
10746 if (VT == MVT::f16)
10747 return DAG.
getNode(RISCVISD::FMV_H_X,
DL, VT, ResultInt);
10760 return DAG.
getNode(RISCVISD::CZERO_EQZ,
DL, VT, TrueV, CondV);
10763 return DAG.
getNode(RISCVISD::CZERO_NEZ,
DL, VT, FalseV, CondV);
10767 auto getNotOperand = [](
const SDValue &
Op) -> std::optional<const SDValue> {
10768 using namespace llvm::SDPatternMatch;
10773 return std::nullopt;
10779 auto NotOperand = (TrueV.
getOperand(0) == FalseV)
10781 : getNotOperand(TrueV.getOperand(0));
10784 DAG.
getNode(RISCVISD::CZERO_EQZ,
DL, VT, *NotOperand, CondV);
10790 DAG.
getNode(RISCVISD::CZERO_NEZ,
DL, VT, FalseV, CondV));
10797 auto NotOperand = (FalseV.
getOperand(0) == TrueV)
10799 : getNotOperand(FalseV.getOperand(0));
10802 DAG.
getNode(RISCVISD::CZERO_NEZ,
DL, VT, *NotOperand, CondV);
10808 DAG.
getNode(RISCVISD::CZERO_EQZ,
DL, VT, TrueV, CondV));
10825 int64_t TrueImm =
TrueVal.getSExtValue();
10826 int64_t FalseImm =
FalseVal.getSExtValue();
10845 if ((TrueVal - FalseVal).isPowerOf2() &&
FalseVal.isSignedIntN(12)) {
10850 if ((FalseVal - TrueVal).isPowerOf2() &&
TrueVal.isSignedIntN(12)) {
10862 if ((TrueVal - FalseVal).isPowerOf2() &&
10869 if ((FalseVal - TrueVal).isPowerOf2() && !
FalseVal.isSignedIntN(12) &&
10877 auto getCost = [&](
const APInt &Delta,
const APInt &Addend) {
10879 Delta, Subtarget.getXLen(), Subtarget,
true);
10881 if (Addend.isSignedIntN(12))
10884 Addend, Subtarget.getXLen(), Subtarget,
true);
10885 return AddendCost + DeltaCost;
10887 bool IsCZERO_NEZ =
getCost(FalseVal - TrueVal, TrueVal) <=
10888 getCost(TrueVal - FalseVal, FalseVal);
10890 IsCZERO_NEZ ? FalseVal - TrueVal : TrueVal - FalseVal,
DL, VT);
10892 DAG.
getNode(IsCZERO_NEZ ? RISCVISD::CZERO_NEZ : RISCVISD::CZERO_EQZ,
10893 DL, VT, LHSVal, CondV);
10901 SDValue ConstVal = IsCZERO_NEZ ? TrueV : FalseV;
10902 SDValue RegV = IsCZERO_NEZ ? FalseV : TrueV;
10908 unsigned SubOpc = (RawConstVal == -0x800) ?
ISD::XOR : ISD::
SUB;
10909 unsigned AddOpc = (RawConstVal == -0x800) ?
ISD::XOR : ISD::
ADD;
10912 DAG.
getNode(IsCZERO_NEZ ? RISCVISD::CZERO_NEZ : RISCVISD::CZERO_EQZ,
10913 DL, VT, SubOp, CondV);
10914 return DAG.
getNode(AddOpc,
DL, VT, CZERO, ConstVal);
10921 using namespace llvm::SDPatternMatch;
10928 DAG.
getNode(RISCVISD::CZERO_EQZ,
DL, VT, TrueV, CondV),
10929 DAG.
getNode(RISCVISD::CZERO_NEZ,
DL, VT, TrueV, CondV));
10936 DAG.
getNode(RISCVISD::CZERO_NEZ,
DL, VT, FalseV, CondV),
10937 DAG.
getNode(RISCVISD::CZERO_EQZ,
DL, VT, FalseV, CondV));
10943 DAG.
getNode(RISCVISD::CZERO_EQZ,
DL, VT, TrueV, CondV),
10944 DAG.
getNode(RISCVISD::CZERO_NEZ,
DL, VT, FalseV, CondV),
10949 if (
Op.hasOneUse()) {
10950 unsigned UseOpc =
Op->user_begin()->getOpcode();
10952 SDNode *BinOp = *
Op->user_begin();
10959 return lowerSELECT(NewSel, DAG);
10969 if (FPTV && FPFV) {
11013 if (TrueVal - 1 == FalseVal)
11015 if (TrueVal + 1 == FalseVal)
11022 RHS == TrueV &&
LHS == FalseV) {
11053 MVT XLenVT = Subtarget.getXLenVT();
11064 return DAG.
getNode(RISCVISD::BR_CC,
DL,
Op.getValueType(),
Op.getOperand(0),
11065 LHS,
RHS, TargetCC,
Op.getOperand(2));
11068 return DAG.
getNode(RISCVISD::BR_CC,
DL,
Op.getValueType(),
Op.getOperand(0),
11075 RISCVMachineFunctionInfo *FuncInfo = MF.
getInfo<RISCVMachineFunctionInfo>();
11085 MachinePointerInfo(SV));
11090 const RISCVRegisterInfo &RI = *Subtarget.getRegisterInfo();
11095 int XLenInBytes = Subtarget.getXLen() / 8;
11097 EVT VT =
Op.getValueType();
11100 unsigned Depth =
Op.getConstantOperandVal(0);
11102 int Offset = -(XLenInBytes * 2);
11114 const RISCVRegisterInfo &RI = *Subtarget.getRegisterInfo();
11118 MVT XLenVT = Subtarget.getXLenVT();
11119 int XLenInBytes = Subtarget.getXLen() / 8;
11121 EVT VT =
Op.getValueType();
11123 unsigned Depth =
Op.getConstantOperandVal(0);
11125 int Off = -XLenInBytes;
11126 SDValue FrameAddr = lowerFRAMEADDR(
Op, DAG);
11130 MachinePointerInfo());
11145 EVT VT =
Lo.getValueType();
11146 unsigned XLen = Subtarget.getXLen();
11149 if (Subtarget.hasStdExtP()) {
11213 bool IsSRA)
const {
11218 EVT VT =
Lo.getValueType();
11221 if (Subtarget.hasStdExtP()) {
11222 unsigned XLen = Subtarget.getXLen();
11225 if (Subtarget.is64Bit()) {
11233 LoRes = DAG.
getNode(IsSRA ? RISCVISD::NSRA : RISCVISD::NSRL,
DL, VT,
Lo,
11252 if (Subtarget.is64Bit()) {
11326 MVT VT =
Op.getSimpleValueType();
11331 return DAG.
getNode(RISCVISD::VMSET_VL,
DL, VT, VL);
11335 return DAG.
getNode(RISCVISD::VMCLR_VL,
DL, VT, VL);
11352 MVT VecVT =
Op.getSimpleValueType();
11354 "Unexpected SPLAT_VECTOR_PARTS lowering");
11380 int64_t ExtTrueVal)
const {
11382 MVT VecVT =
Op.getSimpleValueType();
11385 assert(Src.getValueType().isVector() &&
11386 Src.getValueType().getVectorElementType() == MVT::i1);
11391 if (Src.getOpcode() ==
ISD::XOR &&
11399 MVT I1ContainerVT =
11406 MVT XLenVT = Subtarget.getXLenVT();
11412 if (
Xor.getOpcode() == RISCVISD::VMXOR_VL) {
11417 CC =
Xor.getOperand(0);
11440 EVT MaskVT =
Op.getValueType();
11443 "Unexpected type for vector mask lowering");
11445 MVT VecVT = Src.getSimpleValueType();
11467 Trunc = DAG.
getNode(RISCVISD::SETCC_VL,
DL, MaskContainerVT,
11477 unsigned Opc =
Op.getOpcode();
11480 MVT VT =
Op.getSimpleValueType();
11482 assert(VT.
isVector() &&
"Unexpected type for vector truncate lowering");
11486 return lowerVectorMaskTrunc(
Op, DAG);
11494 MVT SrcVT = Src.getSimpleValueType();
11499 "Unexpected vector truncate lowering");
11512 NewOpc = RISCVISD::TRUNCATE_VECTOR_VL_SSAT;
11514 NewOpc = RISCVISD::TRUNCATE_VECTOR_VL_USAT;
11516 NewOpc = RISCVISD::TRUNCATE_VECTOR_VL;
11522 }
while (SrcEltVT != DstEltVT);
11531RISCVTargetLowering::lowerStrictFPExtendOrRoundLike(
SDValue Op,
11536 MVT VT =
Op.getSimpleValueType();
11537 MVT SrcVT = Src.getSimpleValueType();
11557 ? RISCVISD::STRICT_FP_EXTEND_VL
11558 : RISCVISD::STRICT_VFNCVT_ROD_VL;
11561 Chain, Src, Mask, VL);
11562 Chain = Src.getValue(1);
11566 ? RISCVISD::STRICT_FP_EXTEND_VL
11567 : RISCVISD::STRICT_FP_ROUND_VL;
11569 Chain, Src, Mask, VL);
11580RISCVTargetLowering::lowerVectorFPExtendOrRound(
SDValue Op,
11587 MVT VT =
Op.getSimpleValueType();
11589 assert(VT.
isVector() &&
"Unexpected type for vector truncate lowering");
11592 MVT SrcVT = Src.getSimpleValueType();
11594 bool IsDirectExtend =
11602 bool IsDirectConv = IsDirectExtend || IsDirectTrunc;
11619 unsigned ConvOpc = IsExtend ? RISCVISD::FP_EXTEND_VL : RISCVISD::FP_ROUND_VL;
11621 if (IsDirectConv) {
11628 unsigned InterConvOpc =
11629 IsExtend ? RISCVISD::FP_EXTEND_VL : RISCVISD::VFNCVT_ROD_VL;
11633 DAG.
getNode(InterConvOpc,
DL, InterVT, Src, Mask, VL);
11646static std::optional<MVT>
11651 const unsigned VectorBitsMin =
Subtarget.getRealMinVLen();
11652 const unsigned MinVLMAX = VectorBitsMin / EltSize;
11654 if (MaxIdx < MinVLMAX)
11656 else if (MaxIdx < MinVLMAX * 2)
11659 else if (MaxIdx < MinVLMAX * 4)
11664 return std::nullopt;
11677 MVT VecVT =
Op.getSimpleValueType();
11678 MVT XLenVT = Subtarget.getXLenVT();
11693 if ((ValVT == MVT::f16 && !Subtarget.hasVInstructionsF16()) ||
11694 (ValVT == MVT::bf16 && !Subtarget.hasVInstructionsBF16())) {
11699 DAG.
getNode(RISCVISD::FMV_X_ANYEXTH,
DL, XLenVT, Val), Idx);
11708 unsigned IdxVal = IdxC->getZExtValue();
11714 if (!Subtarget.is64Bit() && VecVT == MVT::v2i32)
11717 if (!Subtarget.is64Bit() && (VecVT == MVT::v4i16 || VecVT == MVT::v8i8)) {
11718 unsigned HalfNumElts = NumElts / 2;
11720 MVT HalfVT =
Lo.getSimpleValueType();
11721 if (IdxVal < HalfNumElts) {
11736 if (NumElts == 2) {
11740 return DAG.
getNode(RISCVISD::PPAIREO,
DL, VecVT, NewElt, Vec);
11742 return DAG.
getNode(RISCVISD::PPAIRE,
DL, VecVT, Vec, NewElt);
11748 if (NumElts == 4 || NumElts == 8) {
11750 unsigned ShiftAmt = IdxVal * EltBits;
11751 uint64_t PosMask = ((1ULL << EltBits) - 1) << ShiftAmt;
11758 DAG.
getNode(RISCVISD::MERGE,
DL, XLenVT, Mask, Vec, ShiftedVal);
11775 std::optional<unsigned> AlignedIdx;
11777 const unsigned OrigIdx = IdxC->getZExtValue();
11780 DL, DAG, Subtarget)) {
11792 unsigned RemIdx = OrigIdx % ElemsPerVReg;
11793 unsigned SubRegIdx = OrigIdx / ElemsPerVReg;
11803 bool IsLegalInsert = Subtarget.is64Bit() || Val.
getValueType() != MVT::i64;
11808 if (!IsLegalInsert) {
11812 IsLegalInsert =
true;
11817 IsLegalInsert =
true;
11826 if (IsLegalInsert) {
11828 VecVT.
isFloatingPoint() ? RISCVISD::VFMV_S_F_VL : RISCVISD::VMV_S_X_VL;
11848 std::tie(ValLo, ValHi) = DAG.
SplitScalar(Val,
DL, MVT::i32, MVT::i32);
11849 MVT I32ContainerVT =
11860 ValInVec = DAG.
getNode(RISCVISD::VSLIDE1DOWN_VL,
DL, I32ContainerVT,
11861 I32Vec, I32Vec, ValLo, I32Mask, InsertI64VL);
11865 ValInVec = DAG.
getNode(RISCVISD::VSLIDE1DOWN_VL,
DL, I32ContainerVT,
11866 Tail, ValInVec, ValHi, I32Mask, InsertI64VL);
11879 ValInVec = DAG.
getNode(RISCVISD::VSLIDE1DOWN_VL,
DL, I32ContainerVT,
11881 DAG.
getUNDEF(I32ContainerVT), ValLo,
11882 I32Mask, InsertI64VL);
11883 ValInVec = DAG.
getNode(RISCVISD::VSLIDE1DOWN_VL,
DL, I32ContainerVT,
11884 DAG.
getUNDEF(I32ContainerVT), ValInVec, ValHi,
11885 I32Mask, InsertI64VL);
11900 Idx, Mask, InsertVL, Policy);
11918 EVT EltVT =
Op.getValueType();
11920 MVT XLenVT = Subtarget.getXLenVT();
11932 DAG.
getNode(RISCVISD::VFIRST_VL,
DL, XLenVT, Vec, Mask, VL);
11939 if (NumElts >= 8) {
11941 unsigned WidenVecLen;
11944 unsigned MaxEEW = Subtarget.getELen();
11949 "the number of elements should be power of 2");
11953 ExtractBitIdx =
Idx;
11955 WideEltVT = LargestEltVT;
11958 ExtractElementIdx = DAG.
getNode(
11969 Vec, ExtractElementIdx);
11984 if ((EltVT == MVT::f16 && !Subtarget.hasVInstructionsF16()) ||
11985 (EltVT == MVT::bf16 && !Subtarget.hasVInstructionsBF16())) {
11991 return DAG.
getNode(RISCVISD::FMV_H_X,
DL, EltVT, IntExtract);
11995 if (VecVT != MVT::v4i16 && VecVT != MVT::v2i16 && VecVT != MVT::v8i8 &&
11996 VecVT != MVT::v4i8 && VecVT != MVT::v2i32)
12007 if (VecVT == MVT::v2i32) {
12018 return DAG.
getNode(RISCVISD::NSRL,
DL, XLenVT,
Lo,
Hi, Shamt);
12021 if (VecVT == MVT::v2i32)
12023 unsigned IdxVal = IdxC->getZExtValue();
12026 if (IdxVal < HalfNumElts)
12050 const auto VLen = Subtarget.getRealVLen();
12052 IdxC && VLen && VecVT.
getSizeInBits().getKnownMinValue() > *VLen) {
12054 unsigned OrigIdx = IdxC->getZExtValue();
12057 unsigned RemIdx = OrigIdx % ElemsPerVReg;
12058 unsigned SubRegIdx = OrigIdx / ElemsPerVReg;
12059 unsigned ExtractIdx =
12068 std::optional<uint64_t> MaxIdx;
12072 MaxIdx = IdxC->getZExtValue();
12074 if (
auto SmallerVT =
12122 "Unexpected opcode");
12129 unsigned IntNo =
Op.getConstantOperandVal(HasChain ? 1 : 0);
12134 RISCVVIntrinsicsTable::getRISCVVIntrinsicInfo(IntNo);
12135 if (!
II || !
II->hasScalarOperand())
12138 unsigned SplatOp =
II->ScalarOperand + 1 + HasChain;
12139 assert(SplatOp <
Op.getNumOperands());
12151 if (OpVT.
bitsLT(XLenVT)) {
12158 ScalarOp = DAG.
getNode(ExtOpc,
DL, XLenVT, ScalarOp);
12168 assert(
II->ScalarOperand > 0 &&
"Unexpected splat operand!");
12169 MVT VT =
Op.getOperand(SplatOp - 1).getSimpleValueType();
12172 assert(XLenVT == MVT::i32 && OpVT == MVT::i64 &&
12183 case Intrinsic::riscv_vslide1up:
12184 case Intrinsic::riscv_vslide1down:
12185 case Intrinsic::riscv_vslide1up_mask:
12186 case Intrinsic::riscv_vslide1down_mask: {
12188 unsigned NumOps =
Op.getNumOperands();
12189 bool IsMasked =
NumOps == 7;
12195 std::tie(ScalarLo, ScalarHi) =
12204 const auto [MinVLMAX, MaxVLMAX] =
12208 if (AVLInt <= MinVLMAX) {
12210 }
else if (AVLInt >= 2 * MaxVLMAX) {
12244 if (IntNo == Intrinsic::riscv_vslide1up ||
12245 IntNo == Intrinsic::riscv_vslide1up_mask) {
12246 Vec = DAG.
getNode(RISCVISD::VSLIDE1UP_VL,
DL, I32VT, Passthru, Vec,
12247 ScalarHi, I32Mask, I32VL);
12248 Vec = DAG.
getNode(RISCVISD::VSLIDE1UP_VL,
DL, I32VT, Passthru, Vec,
12249 ScalarLo, I32Mask, I32VL);
12251 Vec = DAG.
getNode(RISCVISD::VSLIDE1DOWN_VL,
DL, I32VT, Passthru, Vec,
12252 ScalarLo, I32Mask, I32VL);
12253 Vec = DAG.
getNode(RISCVISD::VSLIDE1DOWN_VL,
DL, I32VT, Passthru, Vec,
12254 ScalarHi, I32Mask, I32VL);
12272 return DAG.
getNode(RISCVISD::VMERGE_VL,
DL, VT, Mask, Vec, MaskedOff,
12276 return DAG.
getNode(RISCVISD::VMERGE_VL,
DL, VT, Mask, Vec, MaskedOff,
12303 const unsigned ElementWidth = 8;
12308 [[maybe_unused]]
unsigned MinVF =
12311 [[maybe_unused]]
unsigned VF =
N->getConstantOperandVal(2);
12315 bool Fractional = VF < LMul1VF;
12316 unsigned LMulVal = Fractional ? LMul1VF / VF : VF / LMul1VF;
12345 SDValue Res = DAG.
getNode(RISCVISD::VFIRST_VL,
DL, XLenVT, Op0, Mask, VL);
12353 return DAG.
getSelect(
DL, XLenVT, Setcc, VL, Res);
12359 const uint64_t SemEnum =
Op->getConstantOperandVal(1);
12366 EVT SrcEVT = Src.getValueType();
12370 MVT DstVT =
Op.getSimpleValueType();
12374 MVT SrcContainerVT = SrcVT;
12375 MVT DstContainerVT = DstVT;
12403 unsigned IntNo =
Op.getConstantOperandVal(HasChain ? 1 : 0);
12407 RISCVVIntrinsicsTable::getRISCVVIntrinsicInfo(IntNo);
12408 if (!
II || !
II->hasScalarOperand())
12411 unsigned SplatOp =
II->ScalarOperand + 1;
12412 assert(SplatOp <
Op.getNumOperands());
12424 if (OpVT.
bitsLT(XLenVT)) {
12427 ScalarOp = DAG.
getNode(ExtOpc,
DL, XLenVT, ScalarOp);
12438 EVT ValType =
V.getValueType();
12439 if (ValType.isVector() && ValType.isFloatingPoint()) {
12442 ValType.getVectorElementCount());
12445 if (ValType.isFixedLengthVector()) {
12446 MVT OpContainerVT =
12465 "Unexpected RISC-V packed saturating and rounding shift intrinsic");
12466 case Intrinsic::riscv_psll:
12467 return RISCVISD::PSLL;
12468 case Intrinsic::riscv_psrl:
12469 return RISCVISD::PSRL;
12470 case Intrinsic::riscv_psra:
12471 return RISCVISD::PSRA;
12472 case Intrinsic::riscv_pssha:
12473 return RISCVISD::PSSHA;
12474 case Intrinsic::riscv_psshar:
12475 return RISCVISD::PSSHAR;
12476 case Intrinsic::riscv_psshl:
12477 return RISCVISD::PSSHL;
12478 case Intrinsic::riscv_psshlr:
12479 return RISCVISD::PSSHLR;
12487 case Intrinsic::riscv_pnsrl:
12488 return RISCVISD::PNSRL;
12489 case Intrinsic::riscv_pnsra:
12490 return RISCVISD::PNSRA;
12491 case Intrinsic::riscv_pnsrar:
12492 return RISCVISD::PNSRAR;
12493 case Intrinsic::riscv_pnclipu:
12494 return RISCVISD::PNCLIPU;
12495 case Intrinsic::riscv_pnclipru:
12496 return RISCVISD::PNCLIPRU;
12497 case Intrinsic::riscv_pnclip:
12498 return RISCVISD::PNCLIP;
12499 case Intrinsic::riscv_pnclipr:
12500 return RISCVISD::PNCLIPR;
12508 case Intrinsic::riscv_nclipu_u32:
12509 return RISCVISD::NCLIPU;
12510 case Intrinsic::riscv_nclipru_u32:
12511 return RISCVISD::NCLIPRU;
12512 case Intrinsic::riscv_nsrar_i32:
12513 return RISCVISD::NSRAR;
12514 case Intrinsic::riscv_nclip_i32:
12515 return RISCVISD::NCLIP;
12516 case Intrinsic::riscv_nclipr_i32:
12517 return RISCVISD::NCLIPR;
12529 MVT VT = Src.getSimpleValueType();
12544 case Intrinsic::riscv_pmulhr:
12545 return RISCVISD::MULHR;
12546 case Intrinsic::riscv_pmulhru:
12547 return RISCVISD::MULHRU;
12548 case Intrinsic::riscv_pmulhsu:
12549 return RISCVISD::MULHSU;
12550 case Intrinsic::riscv_pmulhrsu:
12551 return RISCVISD::MULHRSU;
12559 "Unexpected RISC-V scalar averaging, multiply high, Q-format "
12560 "multiply or multiply high accumulate intrinsic");
12561 case Intrinsic::riscv_aadd_i32:
12563 case Intrinsic::riscv_aaddu_u32:
12565 case Intrinsic::riscv_asub_i32:
12567 case Intrinsic::riscv_asubu_u32:
12569 case Intrinsic::riscv_ssh1sadd_i32:
12570 return RISCVISD::SSH1SADD;
12571 case Intrinsic::riscv_mseq_u32:
12572 return RISCVISD::MSEQ;
12573 case Intrinsic::riscv_mslt_i32:
12574 return RISCVISD::MSLT;
12575 case Intrinsic::riscv_msltu_u32:
12576 return RISCVISD::MSLTU;
12577 case Intrinsic::riscv_mulhr_i32:
12578 return RISCVISD::MULHR;
12579 case Intrinsic::riscv_mulhru_u32:
12580 return RISCVISD::MULHRU;
12581 case Intrinsic::riscv_mulhsu_i32:
12582 return RISCVISD::MULHSU;
12583 case Intrinsic::riscv_mulhrsu_i32:
12584 return RISCVISD::MULHRSU;
12585 case Intrinsic::riscv_mulq_i32:
12586 return RISCVISD::MULQ;
12587 case Intrinsic::riscv_mulqr_i32:
12588 return RISCVISD::MULQR;
12589 case Intrinsic::riscv_mhacc_i32:
12590 return RISCVISD::MHACC;
12591 case Intrinsic::riscv_mhracc_i32:
12592 return RISCVISD::MHRACC;
12593 case Intrinsic::riscv_mhaccu_u32:
12594 return RISCVISD::MHACCU;
12595 case Intrinsic::riscv_mhraccu_u32:
12596 return RISCVISD::MHRACCU;
12597 case Intrinsic::riscv_mhaccsu_i32:
12598 return RISCVISD::MHACCSU;
12599 case Intrinsic::riscv_mhraccsu_i32:
12600 return RISCVISD::MHRACCSU;
12608 "Unexpected RISC-V packed multiply high accumulate intrinsic");
12609 case Intrinsic::riscv_pmhacc:
12610 return RISCVISD::MHACC;
12611 case Intrinsic::riscv_pmhracc:
12612 return RISCVISD::MHRACC;
12613 case Intrinsic::riscv_pmhaccu:
12614 return RISCVISD::MHACCU;
12615 case Intrinsic::riscv_pmhraccu:
12616 return RISCVISD::MHRACCU;
12617 case Intrinsic::riscv_pmhaccsu:
12618 return RISCVISD::MHACCSU;
12619 case Intrinsic::riscv_pmhraccsu:
12620 return RISCVISD::MHRACCSU;
12628 llvm_unreachable(
"Unexpected RISC-V packed multiply high accumulate half "
12630 case Intrinsic::riscv_pmhacc_half_0:
12631 return RISCVISD::MHACC_HALF_0;
12632 case Intrinsic::riscv_pmhacc_half_1:
12633 return RISCVISD::MHACC_HALF_1;
12634 case Intrinsic::riscv_pmhaccsu_half_0:
12635 return RISCVISD::MHACCSU_HALF_0;
12636 case Intrinsic::riscv_pmhaccsu_half_1:
12637 return RISCVISD::MHACCSU_HALF_1;
12648 case Intrinsic::riscv_pmulh_half_0:
12649 case Intrinsic::riscv_mulh_h0:
12650 return RISCVISD::MULH_HALF_0;
12651 case Intrinsic::riscv_pmulh_half_1:
12652 case Intrinsic::riscv_mulh_h1:
12653 return RISCVISD::MULH_HALF_1;
12654 case Intrinsic::riscv_pmulhsu_half_0:
12655 case Intrinsic::riscv_mulhsu_h0:
12656 return RISCVISD::MULHSU_HALF_0;
12657 case Intrinsic::riscv_pmulhsu_half_1:
12658 case Intrinsic::riscv_mulhsu_h1:
12659 return RISCVISD::MULHSU_HALF_1;
12666 llvm_unreachable(
"Unexpected RISC-V packed Q-format accumulate intrinsic");
12667 case Intrinsic::riscv_mqacc_00:
12668 case Intrinsic::riscv_pmqacc_h00:
12669 return RISCVISD::MQACC_HALVES_00;
12670 case Intrinsic::riscv_mqacc_01:
12671 case Intrinsic::riscv_pmqacc_h01:
12672 return RISCVISD::MQACC_HALVES_01;
12673 case Intrinsic::riscv_mqacc_11:
12674 case Intrinsic::riscv_pmqacc_h11:
12675 return RISCVISD::MQACC_HALVES_11;
12676 case Intrinsic::riscv_mqracc_00:
12677 case Intrinsic::riscv_pmqracc_h00:
12678 return RISCVISD::MQRACC_HALVES_00;
12679 case Intrinsic::riscv_mqracc_01:
12680 case Intrinsic::riscv_pmqracc_h01:
12681 return RISCVISD::MQRACC_HALVES_01;
12682 case Intrinsic::riscv_mqracc_11:
12683 case Intrinsic::riscv_pmqracc_h11:
12684 return RISCVISD::MQRACC_HALVES_11;
12691 llvm_unreachable(
"Unexpected RISC-V packed horizontal multiply intrinsic");
12692 case Intrinsic::riscv_pm4add:
12693 return RISCVISD::PM4ADD;
12694 case Intrinsic::riscv_pm2add:
12695 return RISCVISD::PM2ADD;
12696 case Intrinsic::riscv_pm2add_x:
12697 return RISCVISD::PM2ADD_X;
12698 case Intrinsic::riscv_pm4addu:
12699 return RISCVISD::PM4ADDU;
12700 case Intrinsic::riscv_pm2addu:
12701 return RISCVISD::PM2ADDU;
12702 case Intrinsic::riscv_pmq2add:
12703 return RISCVISD::PMQ2ADD;
12704 case Intrinsic::riscv_pmqr2add:
12705 return RISCVISD::PMQR2ADD;
12706 case Intrinsic::riscv_pm2sadd:
12707 return RISCVISD::PM2SADD;
12708 case Intrinsic::riscv_pm2sadd_x:
12709 return RISCVISD::PM2SADD_X;
12710 case Intrinsic::riscv_pm2sub:
12711 return RISCVISD::PM2SUB;
12712 case Intrinsic::riscv_pm2sub_x:
12713 return RISCVISD::PM2SUB_X;
12714 case Intrinsic::riscv_pm4addsu:
12715 return RISCVISD::PM4ADDSU;
12716 case Intrinsic::riscv_pm2addsu:
12717 return RISCVISD::PM2ADDSU;
12718 case Intrinsic::riscv_pm2wadd:
12719 return RISCVISD::PM2WADD;
12720 case Intrinsic::riscv_pm2wadd_x:
12721 return RISCVISD::PM2WADD_X;
12722 case Intrinsic::riscv_pm2waddu:
12723 return RISCVISD::PM2WADDU;
12724 case Intrinsic::riscv_pm2wsub:
12725 return RISCVISD::PM2WSUB;
12726 case Intrinsic::riscv_pm2wsub_x:
12727 return RISCVISD::PM2WSUB_X;
12728 case Intrinsic::riscv_pm2waddsu:
12729 return RISCVISD::PM2WADDSU;
12737 case Intrinsic::riscv_pwmacc_i32x2:
12738 return RISCVISD::PWMACC_H;
12739 case Intrinsic::riscv_pwmaccu_u32x2:
12740 return RISCVISD::PWMACCU_H;
12741 case Intrinsic::riscv_pwmaccsu_i32x2:
12742 return RISCVISD::PWMACCSU_H;
12750 "Unexpected RISC-V packed horizontal multiply-accumulate intrinsic");
12751 case Intrinsic::riscv_pm2wadda:
12752 return RISCVISD::PM2WADDA;
12753 case Intrinsic::riscv_pm2wadda_x:
12754 return RISCVISD::PM2WADDA_X;
12755 case Intrinsic::riscv_pm2waddau:
12756 return RISCVISD::PM2WADDAU;
12757 case Intrinsic::riscv_pm2wsuba:
12758 return RISCVISD::PM2WSUBA;
12759 case Intrinsic::riscv_pm2wsuba_x:
12760 return RISCVISD::PM2WSUBA_X;
12761 case Intrinsic::riscv_pm2waddasu:
12762 return RISCVISD::PM2WADDASU;
12769 llvm_unreachable(
"Unexpected RISC-V packed multiplication with horizontal "
12770 "addition/subtraction accumulate intrinsic");
12771 case Intrinsic::riscv_pm2adda:
12772 return RISCVISD::PM2ADDA;
12773 case Intrinsic::riscv_pm2adda_x:
12774 return RISCVISD::PM2ADDA_X;
12775 case Intrinsic::riscv_pm2addau:
12776 return RISCVISD::PM2ADDAU;
12777 case Intrinsic::riscv_pmq2adda:
12778 return RISCVISD::PMQ2ADDA;
12779 case Intrinsic::riscv_pmqr2adda:
12780 return RISCVISD::PMQR2ADDA;
12781 case Intrinsic::riscv_pm2suba:
12782 return RISCVISD::PM2SUBA;
12783 case Intrinsic::riscv_pm2suba_x:
12784 return RISCVISD::PM2SUBA_X;
12785 case Intrinsic::riscv_pm2addasu:
12786 return RISCVISD::PM2ADDASU;
12787 case Intrinsic::riscv_pm4adda:
12788 return RISCVISD::PM4ADDA;
12789 case Intrinsic::riscv_pm4addau:
12790 return RISCVISD::PM4ADDAU;
12791 case Intrinsic::riscv_pm4addasu:
12792 return RISCVISD::PM4ADDASU;
12799 auto Extract = [&](
SDValue V,
unsigned Idx) {
12813 unsigned MulOpc, AccOpc;
12817 case Intrinsic::riscv_pm4add:
12818 MulOpc = RISCVISD::PM2WADD;
12819 AccOpc = RISCVISD::PM2WADDA;
12821 case Intrinsic::riscv_pm4addu:
12822 MulOpc = RISCVISD::PM2WADDU;
12823 AccOpc = RISCVISD::PM2WADDAU;
12825 case Intrinsic::riscv_pm4addsu:
12826 MulOpc = RISCVISD::PM2WADDSU;
12827 AccOpc = RISCVISD::PM2WADDASU;
12837 "Unexpected RV32 horizontal multiply source type");
12838 SDValue Rs1Lo = Extract(Rs1, 0);
12839 SDValue Rs1Hi = Extract(Rs1, 1);
12840 SDValue Rs2Lo = Extract(Rs2, 0);
12841 SDValue Rs2Hi = Extract(Rs2, 1);
12843 if (IntNo == Intrinsic::riscv_pmq2add || IntNo == Intrinsic::riscv_pmqr2add) {
12844 unsigned AccOpc = IntNo == Intrinsic::riscv_pmq2add ? RISCVISD::MQWACC
12845 : RISCVISD::MQRWACC;
12854 if (IntNo == Intrinsic::riscv_pm2addu)
12856 else if (IntNo == Intrinsic::riscv_pm2addsu)
12857 MulOpc = RISCVISD::WMULSU;
12859 IntNo == Intrinsic::riscv_pm2sub || IntNo == Intrinsic::riscv_pm2sub_x;
12860 if (IntNo == Intrinsic::riscv_pm2add_x || IntNo == Intrinsic::riscv_pm2sub_x)
12866 unsigned Opc = IsSub ? RISCVISD::SUBD : RISCVISD::ADDD;
12878 case Intrinsic::riscv_pmul_00:
12879 case Intrinsic::riscv_mul_00:
12880 return RISCVISD::PMUL_HALVES_00;
12881 case Intrinsic::riscv_pmul_01:
12882 case Intrinsic::riscv_mul_01:
12883 return RISCVISD::PMUL_HALVES_01;
12884 case Intrinsic::riscv_pmul_11:
12885 case Intrinsic::riscv_mul_11:
12886 return RISCVISD::PMUL_HALVES_11;
12887 case Intrinsic::riscv_pmulu_00:
12888 case Intrinsic::riscv_mulu_00:
12889 return RISCVISD::PMULU_HALVES_00;
12890 case Intrinsic::riscv_pmulu_01:
12891 case Intrinsic::riscv_mulu_01:
12892 return RISCVISD::PMULU_HALVES_01;
12893 case Intrinsic::riscv_pmulu_11:
12894 case Intrinsic::riscv_mulu_11:
12895 return RISCVISD::PMULU_HALVES_11;
12896 case Intrinsic::riscv_pmulsu_00:
12897 case Intrinsic::riscv_mulsu_00:
12898 return RISCVISD::PMULSU_HALVES_00;
12899 case Intrinsic::riscv_pmulsu_11:
12900 case Intrinsic::riscv_mulsu_11:
12901 return RISCVISD::PMULSU_HALVES_11;
12911 case Intrinsic::riscv_pmul_00:
12912 return Intrinsic::riscv_mul_00;
12913 case Intrinsic::riscv_pmul_01:
12914 return Intrinsic::riscv_mul_01;
12915 case Intrinsic::riscv_pmul_11:
12916 return Intrinsic::riscv_mul_11;
12917 case Intrinsic::riscv_pmulu_00:
12918 return Intrinsic::riscv_mulu_00;
12919 case Intrinsic::riscv_pmulu_01:
12920 return Intrinsic::riscv_mulu_01;
12921 case Intrinsic::riscv_pmulu_11:
12922 return Intrinsic::riscv_mulu_11;
12923 case Intrinsic::riscv_pmulsu_00:
12924 return Intrinsic::riscv_mulsu_00;
12925 case Intrinsic::riscv_pmulsu_11:
12926 return Intrinsic::riscv_mulsu_11;
12936 case Intrinsic::riscv_mul_00:
12937 return Intrinsic::riscv_macc_00;
12938 case Intrinsic::riscv_pmul_00:
12939 return Intrinsic::riscv_pmacc_00;
12940 case Intrinsic::riscv_mul_01:
12941 return Intrinsic::riscv_macc_01;
12942 case Intrinsic::riscv_pmul_01:
12943 return Intrinsic::riscv_pmacc_01;
12944 case Intrinsic::riscv_mul_11:
12945 return Intrinsic::riscv_macc_11;
12946 case Intrinsic::riscv_pmul_11:
12947 return Intrinsic::riscv_pmacc_11;
12948 case Intrinsic::riscv_mulu_00:
12949 return Intrinsic::riscv_maccu_00;
12950 case Intrinsic::riscv_pmulu_00:
12951 return Intrinsic::riscv_pmaccu_00;
12952 case Intrinsic::riscv_mulu_01:
12953 return Intrinsic::riscv_maccu_01;
12954 case Intrinsic::riscv_pmulu_01:
12955 return Intrinsic::riscv_pmaccu_01;
12956 case Intrinsic::riscv_mulu_11:
12957 return Intrinsic::riscv_maccu_11;
12958 case Intrinsic::riscv_pmulu_11:
12959 return Intrinsic::riscv_pmaccu_11;
12960 case Intrinsic::riscv_mulsu_00:
12961 return Intrinsic::riscv_maccsu_00;
12962 case Intrinsic::riscv_pmulsu_00:
12963 return Intrinsic::riscv_pmaccsu_00;
12964 case Intrinsic::riscv_mulsu_11:
12965 return Intrinsic::riscv_maccsu_11;
12966 case Intrinsic::riscv_pmulsu_11:
12967 return Intrinsic::riscv_pmaccsu_11;
12975 llvm_unreachable(
"Unexpected RISC-V multiply-parts accumulate intrinsic");
12976 case Intrinsic::riscv_pmacc_00:
12977 case Intrinsic::riscv_macc_00:
12978 return RISCVISD::PMACC_HALVES_00;
12979 case Intrinsic::riscv_pmacc_01:
12980 case Intrinsic::riscv_macc_01:
12981 return RISCVISD::PMACC_HALVES_01;
12982 case Intrinsic::riscv_pmacc_11:
12983 case Intrinsic::riscv_macc_11:
12984 return RISCVISD::PMACC_HALVES_11;
12985 case Intrinsic::riscv_pmaccu_00:
12986 case Intrinsic::riscv_maccu_00:
12987 return RISCVISD::PMACCU_HALVES_00;
12988 case Intrinsic::riscv_pmaccu_01:
12989 case Intrinsic::riscv_maccu_01:
12990 return RISCVISD::PMACCU_HALVES_01;
12991 case Intrinsic::riscv_pmaccu_11:
12992 case Intrinsic::riscv_maccu_11:
12993 return RISCVISD::PMACCU_HALVES_11;
12994 case Intrinsic::riscv_pmaccsu_00:
12995 case Intrinsic::riscv_maccsu_00:
12996 return RISCVISD::PMACCSU_HALVES_00;
12997 case Intrinsic::riscv_pmaccsu_11:
12998 case Intrinsic::riscv_maccsu_11:
12999 return RISCVISD::PMACCSU_HALVES_11;
13004static std::tuple<unsigned, unsigned, unsigned>
13009 case Intrinsic::riscv_mul_00:
13011 case Intrinsic::riscv_mul_01:
13013 case Intrinsic::riscv_mul_11:
13015 case Intrinsic::riscv_mulu_00:
13017 case Intrinsic::riscv_mulu_01:
13019 case Intrinsic::riscv_mulu_11:
13021 case Intrinsic::riscv_mulsu_00:
13022 return {RISCVISD::WMULSU, 0, 0};
13023 case Intrinsic::riscv_mulsu_11:
13024 return {RISCVISD::WMULSU, 1, 1};
13030static std::tuple<unsigned, unsigned, unsigned>
13034 llvm_unreachable(
"Unexpected RISC-V multiply-parts accumulate intrinsic");
13035 case Intrinsic::riscv_macc_00:
13036 return {RISCVISD::WMACC, 0, 0};
13037 case Intrinsic::riscv_macc_01:
13038 return {RISCVISD::WMACC, 0, 1};
13039 case Intrinsic::riscv_macc_11:
13040 return {RISCVISD::WMACC, 1, 1};
13041 case Intrinsic::riscv_maccu_00:
13042 return {RISCVISD::WMACCU, 0, 0};
13043 case Intrinsic::riscv_maccu_01:
13044 return {RISCVISD::WMACCU, 0, 1};
13045 case Intrinsic::riscv_maccu_11:
13046 return {RISCVISD::WMACCU, 1, 1};
13047 case Intrinsic::riscv_maccsu_00:
13048 return {RISCVISD::WMACCSU, 0, 0};
13049 case Intrinsic::riscv_maccsu_11:
13050 return {RISCVISD::WMACCSU, 1, 1};
13059 unsigned IntNo =
Op.getConstantOperandVal(0);
13061 MVT XLenVT = Subtarget.getXLenVT();
13066 case Intrinsic::riscv_tuple_insert: {
13071 return DAG.
getNode(RISCVISD::TUPLE_INSERT,
DL,
Op.getValueType(), Vec,
13074 case Intrinsic::riscv_tuple_extract: {
13078 return DAG.
getNode(RISCVISD::TUPLE_EXTRACT,
DL,
Op.getValueType(), Vec,
13081 case Intrinsic::thread_pointer: {
13085 case Intrinsic::riscv_pmul_00:
13086 case Intrinsic::riscv_pmul_01:
13087 case Intrinsic::riscv_pmul_11:
13088 case Intrinsic::riscv_pmulu_00:
13089 case Intrinsic::riscv_pmulu_01:
13090 case Intrinsic::riscv_pmulu_11:
13091 case Intrinsic::riscv_pmulsu_00:
13092 case Intrinsic::riscv_pmulsu_11: {
13093 MVT VT =
Op.getSimpleValueType();
13097 if (!Subtarget.isPExtPackedDoubleType(VT))
13104 if (VT == MVT::v2i32) {
13119 case Intrinsic::riscv_pmacc_00:
13120 case Intrinsic::riscv_pmacc_01:
13121 case Intrinsic::riscv_pmacc_11:
13122 case Intrinsic::riscv_pmaccu_00:
13123 case Intrinsic::riscv_pmaccu_01:
13124 case Intrinsic::riscv_pmaccu_11:
13125 case Intrinsic::riscv_pmaccsu_00:
13126 case Intrinsic::riscv_pmaccsu_11:
13127 case Intrinsic::riscv_macc_00:
13128 case Intrinsic::riscv_macc_01:
13129 case Intrinsic::riscv_macc_11:
13130 case Intrinsic::riscv_maccu_00:
13131 case Intrinsic::riscv_maccu_01:
13132 case Intrinsic::riscv_maccu_11:
13133 case Intrinsic::riscv_maccsu_00:
13134 case Intrinsic::riscv_maccsu_11: {
13135 MVT VT =
Op.getSimpleValueType();
13140 if (VT != MVT::v2i32 || !Subtarget.isPExtPackedDoubleType(VT))
13155 case Intrinsic::riscv_pas:
13156 case Intrinsic::riscv_psa:
13157 case Intrinsic::riscv_psas:
13158 case Intrinsic::riscv_pssa:
13159 case Intrinsic::riscv_paas:
13160 case Intrinsic::riscv_pasa: {
13164 if (Subtarget.is64Bit() ||
Op.getSimpleValueType() != MVT::v2i32)
13167 unsigned EvenOpc, OddOpc;
13169 case Intrinsic::riscv_pas:
13173 case Intrinsic::riscv_psa:
13177 case Intrinsic::riscv_psas:
13181 case Intrinsic::riscv_pssa:
13185 case Intrinsic::riscv_paas:
13189 case Intrinsic::riscv_pasa:
13208 case Intrinsic::riscv_orc_b:
13209 case Intrinsic::riscv_brev8:
13210 case Intrinsic::riscv_sha256sig0:
13211 case Intrinsic::riscv_sha256sig1:
13212 case Intrinsic::riscv_sha256sum0:
13213 case Intrinsic::riscv_sha256sum1:
13214 case Intrinsic::riscv_sm3p0:
13215 case Intrinsic::riscv_sm3p1: {
13218 case Intrinsic::riscv_orc_b:
Opc = RISCVISD::ORC_B;
break;
13219 case Intrinsic::riscv_brev8:
Opc = RISCVISD::BREV8;
break;
13220 case Intrinsic::riscv_sha256sig0:
Opc = RISCVISD::SHA256SIG0;
break;
13221 case Intrinsic::riscv_sha256sig1:
Opc = RISCVISD::SHA256SIG1;
break;
13222 case Intrinsic::riscv_sha256sum0:
Opc = RISCVISD::SHA256SUM0;
break;
13223 case Intrinsic::riscv_sha256sum1:
Opc = RISCVISD::SHA256SUM1;
break;
13224 case Intrinsic::riscv_sm3p0:
Opc = RISCVISD::SM3P0;
break;
13225 case Intrinsic::riscv_sm3p1:
Opc = RISCVISD::SM3P1;
break;
13230 case Intrinsic::riscv_sm4ks:
13231 case Intrinsic::riscv_sm4ed: {
13233 IntNo == Intrinsic::riscv_sm4ks ? RISCVISD::SM4KS : RISCVISD::SM4ED;
13238 case Intrinsic::riscv_zip:
13239 case Intrinsic::riscv_unzip: {
13241 IntNo == Intrinsic::riscv_zip ? RISCVISD::ZIP : RISCVISD::UNZIP;
13244 case Intrinsic::riscv_mopr:
13245 return DAG.
getNode(RISCVISD::MOP_R,
DL, XLenVT,
Op.getOperand(1),
13248 case Intrinsic::riscv_moprr: {
13249 return DAG.
getNode(RISCVISD::MOP_RR,
DL, XLenVT,
Op.getOperand(1),
13250 Op.getOperand(2),
Op.getOperand(3));
13252 case Intrinsic::riscv_clmulh:
13253 case Intrinsic::riscv_clmulr: {
13257 case Intrinsic::riscv_paadd:
13258 case Intrinsic::riscv_paaddu:
13259 case Intrinsic::riscv_pasub:
13260 case Intrinsic::riscv_pasubu:
13261 case Intrinsic::riscv_pabd:
13262 case Intrinsic::riscv_pabdu:
13263 case Intrinsic::riscv_psabs: {
13266 case Intrinsic::riscv_paadd:
13269 case Intrinsic::riscv_paaddu:
13272 case Intrinsic::riscv_pasub:
13275 case Intrinsic::riscv_pasubu:
13278 case Intrinsic::riscv_pabd:
13281 case Intrinsic::riscv_pabdu:
13284 case Intrinsic::riscv_psabs:
13285 Opc = RISCVISD::PSABS;
13289 if (IntNo == Intrinsic::riscv_psabs)
13295 case Intrinsic::riscv_pnclipp:
13296 case Intrinsic::riscv_pnclipup: {
13297 bool IsSigned = IntNo == Intrinsic::riscv_pnclipp;
13298 EVT VT =
Op.getValueType();
13301 if (Subtarget.is64Bit()) {
13302 unsigned Opc = IsSigned ? RISCVISD::PNCLIPP : RISCVISD::PNCLIPUP;
13307 if (VT == MVT::v4i8) {
13308 unsigned ClipOpc = IsSigned ? RISCVISD::PNCLIP : RISCVISD::PNCLIPU;
13310 return DAG.
getNode(ClipOpc,
DL, VT, Pair, Shift);
13312 if (VT == MVT::v2i16) {
13313 unsigned ClipOpc = IsSigned ? RISCVISD::PNCLIP : RISCVISD::PNCLIPU;
13315 return DAG.
getNode(ClipOpc,
DL, VT, Pair, Shift);
13317 if (VT == MVT::v2i32) {
13318 unsigned ClipOpc = IsSigned ? RISCVISD::NCLIP : RISCVISD::NCLIPU;
13319 auto [Rs1Lo, Rs1Hi] = DAG.
SplitScalar(Rs1,
DL, XLenVT, XLenVT);
13320 auto [Rs2Lo, Rs2Hi] = DAG.
SplitScalar(Rs2,
DL, XLenVT, XLenVT);
13325 if (VT == MVT::v8i8 || VT == MVT::v4i16) {
13326 unsigned ClipOpc = IsSigned ? RISCVISD::PNCLIP : RISCVISD::PNCLIPU;
13327 MVT HalfVT = VT == MVT::v8i8 ? MVT::v4i8 : MVT::v2i16;
13335 case Intrinsic::riscv_mqacc_00:
13336 case Intrinsic::riscv_mqacc_01:
13337 case Intrinsic::riscv_mqacc_11:
13338 case Intrinsic::riscv_mqracc_00:
13339 case Intrinsic::riscv_mqracc_01:
13340 case Intrinsic::riscv_mqracc_11:
13341 case Intrinsic::riscv_pmqacc_h00:
13342 case Intrinsic::riscv_pmqacc_h01:
13343 case Intrinsic::riscv_pmqacc_h11:
13344 case Intrinsic::riscv_pmqracc_h00:
13345 case Intrinsic::riscv_pmqracc_h01:
13346 case Intrinsic::riscv_pmqracc_h11: {
13347 EVT VT =
Op.getValueType();
13353 if (Subtarget.is64Bit()) {
13368 if (VT == XLenVT) {
13375 case Intrinsic::riscv_pmulq:
13376 case Intrinsic::riscv_pmulqr: {
13379 case Intrinsic::riscv_pmulq:
13380 Opc = RISCVISD::MULQ;
13382 case Intrinsic::riscv_pmulqr:
13383 Opc = RISCVISD::MULQR;
13387 EVT VT =
Op.getValueType();
13395 if (!Subtarget.is64Bit()) {
13396 if (VT == MVT::v2i32) {
13405 if (VT == MVT::v4i16) {
13416 case Intrinsic::riscv_psll:
13417 case Intrinsic::riscv_psrl:
13418 case Intrinsic::riscv_psra:
13419 case Intrinsic::riscv_pssha:
13420 case Intrinsic::riscv_psshar:
13421 case Intrinsic::riscv_psshl:
13422 case Intrinsic::riscv_psshlr: {
13426 Op.getOperand(1), ShAmt);
13428 case Intrinsic::riscv_pwsll:
13429 case Intrinsic::riscv_pwsla: {
13430 MVT VT =
Op.getSimpleValueType();
13432 MVT SrcVT = Src.getSimpleValueType();
13433 if (!((VT == MVT::v4i16 && SrcVT == MVT::v4i8) ||
13434 (VT == MVT::v2i32 && SrcVT == MVT::v2i16)))
13438 bool IsSigned = IntNo == Intrinsic::riscv_pwsla;
13439 if (!Subtarget.is64Bit()) {
13440 unsigned Opc = IsSigned ? RISCVISD::PWSLA : RISCVISD::PWSLL;
13446 return DAG.
getNode(RISCVISD::PSLL,
DL, VT, Wide, ShAmt);
13448 case Intrinsic::riscv_pnsrl:
13449 case Intrinsic::riscv_pnsra:
13450 case Intrinsic::riscv_pnsrar:
13451 case Intrinsic::riscv_pnclipu:
13452 case Intrinsic::riscv_pnclipru:
13453 case Intrinsic::riscv_pnclip:
13454 case Intrinsic::riscv_pnclipr: {
13455 MVT VT =
Op.getSimpleValueType();
13456 MVT SrcVT =
Op.getOperand(1).getSimpleValueType();
13457 if (!((VT == MVT::v4i8 && SrcVT == MVT::v4i16) ||
13458 (VT == MVT::v2i16 && SrcVT == MVT::v2i32)))
13465 case Intrinsic::riscv_nclipu_u32:
13466 case Intrinsic::riscv_nclipru_u32:
13467 case Intrinsic::riscv_nsrar_i32:
13468 case Intrinsic::riscv_nclip_i32:
13469 case Intrinsic::riscv_nclipr_i32: {
13470 assert(!Subtarget.is64Bit() &&
13471 "RV64 should be handled during type legalization");
13478 case Intrinsic::riscv_psati:
13479 case Intrinsic::riscv_pusati:
13480 case Intrinsic::riscv_sati:
13481 case Intrinsic::riscv_usati: {
13483 IntNo == Intrinsic::riscv_psati || IntNo == Intrinsic::riscv_sati;
13484 unsigned Opc = IsSigned ? RISCVISD::SATI : RISCVISD::USATI;
13486 Opc,
DL,
Op.getValueType(),
Op.getOperand(1),
13489 case Intrinsic::riscv_psext_b:
13490 case Intrinsic::riscv_psext_h: {
13491 EVT VT =
Op.getValueType();
13496 unsigned SrcEltBits = IntNo == Intrinsic::riscv_psext_b ? 8 : 16;
13505 case Intrinsic::riscv_pzext_b:
13506 case Intrinsic::riscv_pzext_h: {
13507 EVT VT =
Op.getValueType();
13512 unsigned SrcEltBits = IntNo == Intrinsic::riscv_pzext_b ? 8 : 16;
13518 case Intrinsic::riscv_pabdsumu:
13519 case Intrinsic::riscv_pabdsumau: {
13528 bool IsAcc = IntNo == Intrinsic::riscv_pabdsumau;
13536 AbdsumauId,
Op.getOperand(1), Rs1Lo, Rs2Lo)
13538 AbdsumuId, Rs1Lo, Rs2Lo);
13542 case Intrinsic::riscv_pmulhr:
13543 case Intrinsic::riscv_pmulhru:
13544 case Intrinsic::riscv_pmulhsu:
13545 case Intrinsic::riscv_pmulhrsu: {
13546 EVT VT =
Op.getValueType();
13552 if (!Subtarget.is64Bit() && VT == MVT::v4i16) {
13560 if (!Subtarget.is64Bit() && VT == MVT::v2i32) {
13567 DAG.
getNode(
Opc,
DL, MVT::i32, Extract(Rs1, 0), Extract(Rs2, 0));
13569 DAG.
getNode(
Opc,
DL, MVT::i32, Extract(Rs1, 1), Extract(Rs2, 1));
13575 case Intrinsic::riscv_aadd_i32:
13576 case Intrinsic::riscv_aaddu_u32:
13577 case Intrinsic::riscv_asub_i32:
13578 case Intrinsic::riscv_asubu_u32:
13579 case Intrinsic::riscv_ssh1sadd_i32:
13580 case Intrinsic::riscv_mseq_u32:
13581 case Intrinsic::riscv_mslt_i32:
13582 case Intrinsic::riscv_msltu_u32:
13583 case Intrinsic::riscv_mulhr_i32:
13584 case Intrinsic::riscv_mulhru_u32:
13585 case Intrinsic::riscv_mulhsu_i32:
13586 case Intrinsic::riscv_mulhrsu_i32:
13587 case Intrinsic::riscv_mulq_i32:
13588 case Intrinsic::riscv_mulqr_i32:
13589 case Intrinsic::riscv_mhacc_i32:
13590 case Intrinsic::riscv_mhracc_i32:
13591 case Intrinsic::riscv_mhaccu_u32:
13592 case Intrinsic::riscv_mhraccu_u32:
13593 case Intrinsic::riscv_mhaccsu_i32:
13594 case Intrinsic::riscv_mhraccsu_i32: {
13601 case Intrinsic::riscv_mqwacc_i64:
13602 case Intrinsic::riscv_mqrwacc_i64: {
13604 unsigned Opc = IntNo == Intrinsic::riscv_mqwacc_i64
13605 ? RISCVISD::MQACC_HALVES_00
13606 : RISCVISD::MQRACC_HALVES_00;
13611 return DAG.
getNode(
Opc,
DL, MVT::i64,
Op.getOperand(1), Rs1, Rs2);
13613 case Intrinsic::riscv_pmhacc:
13614 case Intrinsic::riscv_pmhracc:
13615 case Intrinsic::riscv_pmhaccu:
13616 case Intrinsic::riscv_pmhraccu:
13617 case Intrinsic::riscv_pmhaccsu:
13618 case Intrinsic::riscv_pmhraccsu: {
13619 EVT VT =
Op.getValueType();
13628 if (!Subtarget.is64Bit() && VT == MVT::v4i16) {
13637 if (!Subtarget.is64Bit() && VT == MVT::v2i32) {
13642 Extract(Rs1, 0), Extract(Rs2, 0));
13644 Extract(Rs1, 1), Extract(Rs2, 1));
13648 return DAG.
getNode(MulOpc,
DL, VT, Rd, Rs1, Rs2);
13650 case Intrinsic::riscv_pmhacc_half_0:
13651 case Intrinsic::riscv_pmhacc_half_1:
13652 case Intrinsic::riscv_pmhaccsu_half_0:
13653 case Intrinsic::riscv_pmhaccsu_half_1: {
13654 EVT VT =
Op.getValueType();
13661 if (!Subtarget.is64Bit() && VT == MVT::v4i16) {
13672 if (!Subtarget.is64Bit() && VT == MVT::v2i32) {
13678 Extract(Rs1, 0), Rs2Lo);
13680 Extract(Rs1, 1), Rs2Hi);
13686 case Intrinsic::riscv_pmulh_half_0:
13687 case Intrinsic::riscv_pmulh_half_1:
13688 case Intrinsic::riscv_pmulhsu_half_0:
13689 case Intrinsic::riscv_pmulhsu_half_1: {
13690 EVT VT =
Op.getValueType();
13697 if (!Subtarget.is64Bit() && VT == MVT::v4i16) {
13707 if (!Subtarget.is64Bit() && VT == MVT::v2i32) {
13719 case Intrinsic::riscv_pmqwacc_i32x2:
13720 case Intrinsic::riscv_pmqrwacc_i32x2: {
13721 EVT VT =
Op.getValueType();
13726 if (!Subtarget.is64Bit()) {
13727 unsigned Opc = IntNo == Intrinsic::riscv_pmqwacc_i32x2
13728 ? RISCVISD::PMQWACC_H
13729 : RISCVISD::PMQRWACC_H;
13738 unsigned Opc = IntNo == Intrinsic::riscv_pmqwacc_i32x2
13739 ? RISCVISD::MQACC_HALVES_01
13740 : RISCVISD::MQRACC_HALVES_01;
13743 case Intrinsic::riscv_mulh_h0:
13744 case Intrinsic::riscv_mulh_h1:
13745 case Intrinsic::riscv_mulhsu_h0:
13746 case Intrinsic::riscv_mulhsu_h1: {
13750 EVT VT =
Op.getValueType();
13751 if (VT != MVT::i32 || Subtarget.is64Bit())
13759 case Intrinsic::riscv_pm4add:
13760 case Intrinsic::riscv_pm2add:
13761 case Intrinsic::riscv_pm2add_x:
13762 case Intrinsic::riscv_pm4addu:
13763 case Intrinsic::riscv_pm2addu:
13764 case Intrinsic::riscv_pmq2add:
13765 case Intrinsic::riscv_pmqr2add:
13766 case Intrinsic::riscv_pm2sadd:
13767 case Intrinsic::riscv_pm2sadd_x:
13768 case Intrinsic::riscv_pm2sub:
13769 case Intrinsic::riscv_pm2sub_x:
13770 case Intrinsic::riscv_pm4addsu:
13771 case Intrinsic::riscv_pm2addsu: {
13772 EVT VT =
Op.getValueType();
13779 if (!Subtarget.is64Bit() && VT == MVT::v2i32) {
13789 case Intrinsic::riscv_pwmacc_i32x2:
13790 case Intrinsic::riscv_pwmaccu_u32x2:
13791 case Intrinsic::riscv_pwmaccsu_i32x2: {
13792 EVT VT =
Op.getValueType();
13797 if (Subtarget.is64Bit()) {
13808 if (IntNo == Intrinsic::riscv_pwmaccsu_i32x2) {
13810 Rs1 = DAG.
getNode(RISCVISD::PZIP,
DL, MVT::v4i16, Rs1,
Zero);
13811 Rs2 = DAG.
getNode(RISCVISD::PZIP,
DL, MVT::v4i16, Rs2,
Zero);
13812 return DAG.
getNode(RISCVISD::PMACCSU_HALVES_00,
DL, VT, Acc, Rs1, Rs2);
13815 unsigned Opc = IntNo == Intrinsic::riscv_pwmaccu_u32x2
13816 ? RISCVISD::PMACCU_HALVES_01
13817 : RISCVISD::PMACC_HALVES_01;
13826 case Intrinsic::riscv_pm2wadd:
13827 case Intrinsic::riscv_pm2wadd_x:
13828 case Intrinsic::riscv_pm2waddu:
13829 case Intrinsic::riscv_pm2wsub:
13830 case Intrinsic::riscv_pm2wsub_x:
13831 case Intrinsic::riscv_pm2waddsu: {
13844 assert(Subtarget.is64Bit() &&
Op.getValueType() == MVT::i64 &&
13845 "Unexpected widening horizontal multiply-add legalization");
13849 if (IntNo == Intrinsic::riscv_pm2wsub ||
13850 IntNo == Intrinsic::riscv_pm2wsub_x) {
13857 unsigned SubIntNo = IntNo == Intrinsic::riscv_pm2wsub
13858 ? Intrinsic::riscv_pm2sub
13859 : Intrinsic::riscv_pm2sub_x;
13873 if (IntNo == Intrinsic::riscv_pm2wadd_x) {
13875 B = DAG.
getNode(RISCVISD::PPAIROE,
DL, MVT::v4i16, Rs2Wide, Rs2Wide);
13880 unsigned MulOpc = IntNo == Intrinsic::riscv_pm2waddu ? RISCVISD::PM4ADDU
13881 : IntNo == Intrinsic::riscv_pm2waddsu ? RISCVISD::PM4ADDSU
13882 : RISCVISD::PM4ADD;
13885 case Intrinsic::riscv_pm2wadda:
13886 case Intrinsic::riscv_pm2wadda_x:
13887 case Intrinsic::riscv_pm2waddau:
13888 case Intrinsic::riscv_pm2wsuba:
13889 case Intrinsic::riscv_pm2wsuba_x:
13890 case Intrinsic::riscv_pm2waddasu: {
13892 assert(Subtarget.is64Bit() &&
Op.getValueType() == MVT::i64 &&
13893 "Unexpected widening horizontal multiply-accumulate legalization");
13898 auto WidenAnyAcc = [&](
SDValue V) {
13904 if (IntNo == Intrinsic::riscv_pm2wsuba ||
13905 IntNo == Intrinsic::riscv_pm2wsuba_x) {
13908 unsigned SubOpc = IntNo == Intrinsic::riscv_pm2wsuba ? RISCVISD::PM2SUB
13909 : RISCVISD::PM2SUB_X;
13918 if (IntNo == Intrinsic::riscv_pm2wadda_x) {
13920 B = DAG.
getNode(RISCVISD::PPAIROE,
DL, MVT::v4i16, Rs2Wide, Rs2Wide);
13925 unsigned AccOpc = IntNo == Intrinsic::riscv_pm2waddau ? RISCVISD::PM4ADDAU
13926 : IntNo == Intrinsic::riscv_pm2waddasu
13927 ? RISCVISD::PM4ADDASU
13928 : RISCVISD::PM4ADDA;
13929 return DAG.
getNode(AccOpc,
DL, MVT::i64, Rd,
A,
B);
13931 case Intrinsic::riscv_pm2adda:
13932 case Intrinsic::riscv_pm2adda_x:
13933 case Intrinsic::riscv_pm2addau:
13934 case Intrinsic::riscv_pmq2adda:
13935 case Intrinsic::riscv_pmqr2adda:
13936 case Intrinsic::riscv_pm2suba:
13937 case Intrinsic::riscv_pm2suba_x:
13938 case Intrinsic::riscv_pm2addasu:
13939 case Intrinsic::riscv_pm4adda:
13940 case Intrinsic::riscv_pm4addau:
13941 case Intrinsic::riscv_pm4addasu: {
13942 MVT VT =
Op.getSimpleValueType();
13948 if (VT == Subtarget.getXLenVT())
13951 assert(VT == MVT::v2i32 &&
13952 "Unexpected packed multiply-horizontal-add-accumulate result");
13953 if (Subtarget.is64Bit())
13964 case Intrinsic::riscv_pmerge: {
13965 EVT VT =
Op.getValueType();
13967 if (!Subtarget.is64Bit() && (VT == MVT::v8i8 || VT == MVT::v4i16)) {
13968 MVT HalfVT = VT == MVT::v8i8 ? MVT::v4i8 : MVT::v2i16;
13969 auto [Rs1Lo, Rs1Hi] =
13971 auto [Rs2Lo, Rs2Hi] =
13973 auto [MaskLo, MaskHi] =
13976 DAG.
getNode(RISCVISD::MERGE,
DL, HalfVT, MaskLo, Rs1Lo, Rs2Lo);
13978 DAG.
getNode(RISCVISD::MERGE,
DL, HalfVT, MaskHi, Rs1Hi, Rs2Hi);
13983 if (!Subtarget.is64Bit() && VT == MVT::v2i32) {
13985 for (
unsigned I = 0;
I != 2; ++
I) {
13992 Elts[
I] = DAG.
getNode(RISCVISD::MERGE,
DL, MVT::i32, Mask, Rs1, Rs2);
13997 return DAG.
getNode(RISCVISD::MERGE,
DL, VT,
Op.getOperand(3),
13998 Op.getOperand(1),
Op.getOperand(2));
14000 case Intrinsic::experimental_get_vector_length:
14002 case Intrinsic::riscv_vmv_x_s: {
14006 case Intrinsic::riscv_vfmv_f_s:
14008 case Intrinsic::riscv_vmv_v_x:
14010 Op.getOperand(3),
Op.getSimpleValueType(),
DL, DAG,
14012 case Intrinsic::riscv_vfmv_v_f:
14013 return DAG.
getNode(RISCVISD::VFMV_V_F_VL,
DL,
Op.getValueType(),
14014 Op.getOperand(1),
Op.getOperand(2),
Op.getOperand(3));
14015 case Intrinsic::riscv_vmv_s_x: {
14018 if (
Scalar.getValueType().bitsLE(XLenVT)) {
14020 return DAG.
getNode(RISCVISD::VMV_S_X_VL,
DL,
Op.getValueType(),
14021 Op.getOperand(1),
Scalar,
Op.getOperand(3));
14024 assert(
Scalar.getValueType() == MVT::i64 &&
"Unexpected scalar VT!");
14041 MVT VT =
Op.getSimpleValueType();
14046 if (
Op.getOperand(1).isUndef())
14047 return SplattedVal;
14056 DAG.
getNode(RISCVISD::SETCC_VL,
DL, MaskVT,
14059 return DAG.
getNode(RISCVISD::VMERGE_VL,
DL, VT, SelectCond, SplattedVal,
14062 case Intrinsic::riscv_vfmv_s_f:
14063 return DAG.
getNode(RISCVISD::VFMV_S_F_VL,
DL,
Op.getValueType(),
14064 Op.getOperand(1),
Op.getOperand(2),
Op.getOperand(3));
14066 case Intrinsic::riscv_vaesdf_vv:
14067 case Intrinsic::riscv_vaesdf_vs:
14068 case Intrinsic::riscv_vaesdm_vv:
14069 case Intrinsic::riscv_vaesdm_vs:
14070 case Intrinsic::riscv_vaesef_vv:
14071 case Intrinsic::riscv_vaesef_vs:
14072 case Intrinsic::riscv_vaesem_vv:
14073 case Intrinsic::riscv_vaesem_vs:
14074 case Intrinsic::riscv_vaeskf1:
14075 case Intrinsic::riscv_vaeskf2:
14076 case Intrinsic::riscv_vaesz_vs:
14077 case Intrinsic::riscv_vsm4k:
14078 case Intrinsic::riscv_vsm4r_vv:
14079 case Intrinsic::riscv_vsm4r_vs: {
14080 if (!
isValidEGW(4,
Op.getSimpleValueType(), Subtarget) ||
14081 !
isValidEGW(4,
Op->getOperand(1).getSimpleValueType(), Subtarget) ||
14082 !
isValidEGW(4,
Op->getOperand(2).getSimpleValueType(), Subtarget))
14087 case Intrinsic::riscv_vsm3c:
14088 case Intrinsic::riscv_vsm3me: {
14089 if (!
isValidEGW(8,
Op.getSimpleValueType(), Subtarget) ||
14090 !
isValidEGW(8,
Op->getOperand(1).getSimpleValueType(), Subtarget))
14095 case Intrinsic::riscv_vsha2ch:
14096 case Intrinsic::riscv_vsha2cl:
14097 case Intrinsic::riscv_vsha2ms: {
14098 if (
Op->getSimpleValueType(0).getScalarSizeInBits() == 64 &&
14099 !Subtarget.hasStdExtZvknhb())
14101 if (!
isValidEGW(4,
Op.getSimpleValueType(), Subtarget) ||
14102 !
isValidEGW(4,
Op->getOperand(1).getSimpleValueType(), Subtarget) ||
14103 !
isValidEGW(4,
Op->getOperand(2).getSimpleValueType(), Subtarget))
14107 case Intrinsic::riscv_sf_vc_v_x:
14108 case Intrinsic::riscv_sf_vc_v_i:
14109 case Intrinsic::riscv_sf_vc_v_xv:
14110 case Intrinsic::riscv_sf_vc_v_iv:
14111 case Intrinsic::riscv_sf_vc_v_vv:
14112 case Intrinsic::riscv_sf_vc_v_fv:
14113 case Intrinsic::riscv_sf_vc_v_xvv:
14114 case Intrinsic::riscv_sf_vc_v_ivv:
14115 case Intrinsic::riscv_sf_vc_v_vvv:
14116 case Intrinsic::riscv_sf_vc_v_fvv:
14117 case Intrinsic::riscv_sf_vc_v_xvw:
14118 case Intrinsic::riscv_sf_vc_v_ivw:
14119 case Intrinsic::riscv_sf_vc_v_vvw:
14120 case Intrinsic::riscv_sf_vc_v_fvw: {
14121 MVT VT =
Op.getSimpleValueType();
14158 MVT VT =
Op.getSimpleValueType();
14162 if (VT.isFloatingPoint()) {
14164 VT.getVectorElementCount());
14167 if (VT.isFixedLengthVector())
14176 if (VT.isFixedLengthVector())
14178 if (VT.isFloatingPoint())
14201 case Intrinsic::riscv_seg2_load_mask:
14202 case Intrinsic::riscv_seg3_load_mask:
14203 case Intrinsic::riscv_seg4_load_mask:
14204 case Intrinsic::riscv_seg5_load_mask:
14205 case Intrinsic::riscv_seg6_load_mask:
14206 case Intrinsic::riscv_seg7_load_mask:
14207 case Intrinsic::riscv_seg8_load_mask:
14210 case Intrinsic::riscv_sseg2_load_mask:
14211 case Intrinsic::riscv_sseg3_load_mask:
14212 case Intrinsic::riscv_sseg4_load_mask:
14213 case Intrinsic::riscv_sseg5_load_mask:
14214 case Intrinsic::riscv_sseg6_load_mask:
14215 case Intrinsic::riscv_sseg7_load_mask:
14216 case Intrinsic::riscv_sseg8_load_mask:
14224 Intrinsic::riscv_vlseg2_mask, Intrinsic::riscv_vlseg3_mask,
14225 Intrinsic::riscv_vlseg4_mask, Intrinsic::riscv_vlseg5_mask,
14226 Intrinsic::riscv_vlseg6_mask, Intrinsic::riscv_vlseg7_mask,
14227 Intrinsic::riscv_vlseg8_mask};
14229 Intrinsic::riscv_vlsseg2_mask, Intrinsic::riscv_vlsseg3_mask,
14230 Intrinsic::riscv_vlsseg4_mask, Intrinsic::riscv_vlsseg5_mask,
14231 Intrinsic::riscv_vlsseg6_mask, Intrinsic::riscv_vlsseg7_mask,
14232 Intrinsic::riscv_vlsseg8_mask};
14235 unsigned NF =
Op->getNumValues() - 1;
14236 assert(NF >= 2 && NF <= 8 &&
"Unexpected seg number");
14238 MVT VT =
Op->getSimpleValueType(0);
14240 unsigned Sz = NF *
ContainerVT.getVectorMinNumElements() *
14246 SDValue VL =
Op.getOperand(
Op.getNumOperands() - 1);
14247 SDValue Mask =
Op.getOperand(
Op.getNumOperands() - 2);
14248 MVT MaskVT = Mask.getSimpleValueType();
14253 IsStrided ? VlssegInts[NF - 2] : VlsegInts[NF - 2],
DL, XLenVT);
14269 Ops.insert(std::next(
Ops.begin(), 4),
Op.getOperand(3));
14273 Load->getMemoryVT(),
Load->getMemOperand());
14275 for (
unsigned int RetIdx = 0; RetIdx < NF; RetIdx++) {
14277 Result.getValue(0),
14281 Results.push_back(Result.getValue(1));
14287 unsigned IntNo =
Op.getConstantOperandVal(1);
14291 case Intrinsic::riscv_seg2_load_mask:
14292 case Intrinsic::riscv_seg3_load_mask:
14293 case Intrinsic::riscv_seg4_load_mask:
14294 case Intrinsic::riscv_seg5_load_mask:
14295 case Intrinsic::riscv_seg6_load_mask:
14296 case Intrinsic::riscv_seg7_load_mask:
14297 case Intrinsic::riscv_seg8_load_mask:
14298 case Intrinsic::riscv_sseg2_load_mask:
14299 case Intrinsic::riscv_sseg3_load_mask:
14300 case Intrinsic::riscv_sseg4_load_mask:
14301 case Intrinsic::riscv_sseg5_load_mask:
14302 case Intrinsic::riscv_sseg6_load_mask:
14303 case Intrinsic::riscv_sseg7_load_mask:
14304 case Intrinsic::riscv_sseg8_load_mask:
14307 case Intrinsic::riscv_sf_vc_v_x_se:
14309 case Intrinsic::riscv_sf_vc_v_i_se:
14311 case Intrinsic::riscv_sf_vc_v_xv_se:
14313 case Intrinsic::riscv_sf_vc_v_iv_se:
14315 case Intrinsic::riscv_sf_vc_v_vv_se:
14317 case Intrinsic::riscv_sf_vc_v_fv_se:
14319 case Intrinsic::riscv_sf_vc_v_xvv_se:
14321 case Intrinsic::riscv_sf_vc_v_ivv_se:
14323 case Intrinsic::riscv_sf_vc_v_vvv_se:
14325 case Intrinsic::riscv_sf_vc_v_fvv_se:
14327 case Intrinsic::riscv_sf_vc_v_xvw_se:
14329 case Intrinsic::riscv_sf_vc_v_ivw_se:
14331 case Intrinsic::riscv_sf_vc_v_vvw_se:
14333 case Intrinsic::riscv_sf_vc_v_fvw_se:
14346 case Intrinsic::riscv_seg2_store_mask:
14347 case Intrinsic::riscv_seg3_store_mask:
14348 case Intrinsic::riscv_seg4_store_mask:
14349 case Intrinsic::riscv_seg5_store_mask:
14350 case Intrinsic::riscv_seg6_store_mask:
14351 case Intrinsic::riscv_seg7_store_mask:
14352 case Intrinsic::riscv_seg8_store_mask:
14355 case Intrinsic::riscv_sseg2_store_mask:
14356 case Intrinsic::riscv_sseg3_store_mask:
14357 case Intrinsic::riscv_sseg4_store_mask:
14358 case Intrinsic::riscv_sseg5_store_mask:
14359 case Intrinsic::riscv_sseg6_store_mask:
14360 case Intrinsic::riscv_sseg7_store_mask:
14361 case Intrinsic::riscv_sseg8_store_mask:
14370 Intrinsic::riscv_vsseg2_mask, Intrinsic::riscv_vsseg3_mask,
14371 Intrinsic::riscv_vsseg4_mask, Intrinsic::riscv_vsseg5_mask,
14372 Intrinsic::riscv_vsseg6_mask, Intrinsic::riscv_vsseg7_mask,
14373 Intrinsic::riscv_vsseg8_mask};
14375 Intrinsic::riscv_vssseg2_mask, Intrinsic::riscv_vssseg3_mask,
14376 Intrinsic::riscv_vssseg4_mask, Intrinsic::riscv_vssseg5_mask,
14377 Intrinsic::riscv_vssseg6_mask, Intrinsic::riscv_vssseg7_mask,
14378 Intrinsic::riscv_vssseg8_mask};
14382 unsigned NF =
Op->getNumOperands() - (IsStrided ? 6 : 5);
14383 assert(NF >= 2 && NF <= 8 &&
"Unexpected seg number");
14385 MVT VT =
Op->getOperand(2).getSimpleValueType();
14387 unsigned Sz = NF *
ContainerVT.getVectorMinNumElements() *
14391 SDValue VL =
Op.getOperand(
Op.getNumOperands() - 1);
14392 SDValue Mask =
Op.getOperand(
Op.getNumOperands() - 2);
14393 MVT MaskVT = Mask.getSimpleValueType();
14398 IsStrided ? VsssegInts[NF - 2] : VssegInts[NF - 2],
DL, XLenVT);
14404 for (
unsigned i = 0; i < NF; i++)
14406 RISCVISD::TUPLE_INSERT,
DL, VecTupTy, StoredVal,
14412 FixedIntrinsic->getChain(),
14421 Ops.insert(std::next(
Ops.begin(), 4),
14422 Op.getOperand(
Op.getNumOperands() - 3));
14426 FixedIntrinsic->getMemoryVT(), FixedIntrinsic->getMemOperand());
14431 unsigned IntNo =
Op.getConstantOperandVal(1);
14435 case Intrinsic::riscv_seg2_store_mask:
14436 case Intrinsic::riscv_seg3_store_mask:
14437 case Intrinsic::riscv_seg4_store_mask:
14438 case Intrinsic::riscv_seg5_store_mask:
14439 case Intrinsic::riscv_seg6_store_mask:
14440 case Intrinsic::riscv_seg7_store_mask:
14441 case Intrinsic::riscv_seg8_store_mask:
14442 case Intrinsic::riscv_sseg2_store_mask:
14443 case Intrinsic::riscv_sseg3_store_mask:
14444 case Intrinsic::riscv_sseg4_store_mask:
14445 case Intrinsic::riscv_sseg5_store_mask:
14446 case Intrinsic::riscv_sseg6_store_mask:
14447 case Intrinsic::riscv_sseg7_store_mask:
14448 case Intrinsic::riscv_sseg8_store_mask:
14451 case Intrinsic::riscv_sf_vc_xv_se:
14453 case Intrinsic::riscv_sf_vc_iv_se:
14455 case Intrinsic::riscv_sf_vc_vv_se:
14457 case Intrinsic::riscv_sf_vc_fv_se:
14459 case Intrinsic::riscv_sf_vc_xvv_se:
14461 case Intrinsic::riscv_sf_vc_ivv_se:
14463 case Intrinsic::riscv_sf_vc_vvv_se:
14465 case Intrinsic::riscv_sf_vc_fvv_se:
14467 case Intrinsic::riscv_sf_vc_xvw_se:
14469 case Intrinsic::riscv_sf_vc_ivw_se:
14471 case Intrinsic::riscv_sf_vc_vvw_se:
14473 case Intrinsic::riscv_sf_vc_fvw_se:
14481 switch (ISDOpcode) {
14484 case ISD::VP_REDUCE_ADD:
14486 return RISCVISD::VECREDUCE_ADD_VL;
14487 case ISD::VP_REDUCE_UMAX:
14489 return RISCVISD::VECREDUCE_UMAX_VL;
14490 case ISD::VP_REDUCE_SMAX:
14492 return RISCVISD::VECREDUCE_SMAX_VL;
14493 case ISD::VP_REDUCE_UMIN:
14495 return RISCVISD::VECREDUCE_UMIN_VL;
14496 case ISD::VP_REDUCE_SMIN:
14498 return RISCVISD::VECREDUCE_SMIN_VL;
14499 case ISD::VP_REDUCE_AND:
14501 return RISCVISD::VECREDUCE_AND_VL;
14502 case ISD::VP_REDUCE_OR:
14504 return RISCVISD::VECREDUCE_OR_VL;
14505 case ISD::VP_REDUCE_XOR:
14507 return RISCVISD::VECREDUCE_XOR_VL;
14508 case ISD::VP_REDUCE_FADD:
14509 return RISCVISD::VECREDUCE_FADD_VL;
14510 case ISD::VP_REDUCE_SEQ_FADD:
14511 return RISCVISD::VECREDUCE_SEQ_FADD_VL;
14512 case ISD::VP_REDUCE_FMAX:
14513 case ISD::VP_REDUCE_FMAXIMUM:
14514 return RISCVISD::VECREDUCE_FMAX_VL;
14515 case ISD::VP_REDUCE_FMIN:
14516 case ISD::VP_REDUCE_FMINIMUM:
14517 return RISCVISD::VECREDUCE_FMIN_VL;
14526 SDValue Vec =
Op.getOperand(IsVP ? 1 : 0);
14531 Op.getOpcode() == ISD::VP_REDUCE_AND ||
14532 Op.getOpcode() == ISD::VP_REDUCE_OR ||
14533 Op.getOpcode() == ISD::VP_REDUCE_XOR) &&
14534 "Unexpected reduction lowering");
14536 MVT XLenVT = Subtarget.getXLenVT();
14546 Mask =
Op.getOperand(2);
14549 VL =
Op.getOperand(3);
14551 std::tie(Mask, VL) =
14556 switch (
Op.getOpcode()) {
14560 case ISD::VP_REDUCE_AND: {
14567 Vec = DAG.
getNode(RISCVISD::VCPOP_VL,
DL, XLenVT, Vec, Mask, VL);
14572 case ISD::VP_REDUCE_OR:
14574 Vec = DAG.
getNode(RISCVISD::VCPOP_VL,
DL, XLenVT, Vec, Mask, VL);
14578 case ISD::VP_REDUCE_XOR: {
14581 Vec = DAG.
getNode(RISCVISD::VCPOP_VL,
DL, XLenVT, Vec, Mask, VL);
14602 return DAG.
getNode(BaseOpc,
DL,
Op.getValueType(), SetCC,
Op.getOperand(0));
14608 return (RegisterAVL && RegisterAVL->getReg() == RISCV::X0) ||
14609 (ImmAVL && ImmAVL->getZExtValue() >= 1);
14625 auto InnerVT = VecVT.
bitsLE(M1VT) ? VecVT : M1VT;
14629 auto InnerVL = NonZeroAVL ? VL : DAG.
getConstant(1,
DL, XLenVT);
14632 if (M1VT != InnerVT)
14637 SDValue Ops[] = {PassThru, Vec, InitialValue, Mask, VL, Policy};
14655 VecEVT =
Lo.getValueType();
14691 Mask, VL,
DL, DAG, Subtarget);
14697static std::tuple<unsigned, SDValue, SDValue>
14701 auto Flags =
Op->getFlags();
14702 unsigned Opcode =
Op.getOpcode();
14710 return std::make_tuple(RISCVISD::VECREDUCE_FADD_VL,
Op.getOperand(0),
Zero);
14713 return std::make_tuple(RISCVISD::VECREDUCE_SEQ_FADD_VL,
Op.getOperand(1),
14722 ? RISCVISD::VECREDUCE_FMIN_VL
14723 : RISCVISD::VECREDUCE_FMAX_VL;
14724 return std::make_tuple(RVVOpc,
Op.getOperand(0), Front);
14732 MVT VecEltVT =
Op.getSimpleValueType();
14734 unsigned RVVOpcode;
14735 SDValue VectorVal, ScalarVal;
14736 std::tie(RVVOpcode, VectorVal, ScalarVal) =
14746 MVT ResVT =
Op.getSimpleValueType();
14749 VL,
DL, DAG, Subtarget);
14754 if (
Op->getFlags().hasNoNaNs())
14760 {VectorVal, VectorVal, DAG.getCondCode(ISD::SETNE),
14761 DAG.getUNDEF(Mask.getValueType()), Mask, VL});
14762 MVT XLenVT = Subtarget.getXLenVT();
14763 SDValue CPop = DAG.
getNode(RISCVISD::VCPOP_VL,
DL, XLenVT, IsNan, Mask, VL);
14767 DL, ResVT, NoNaNs, Res,
14774 unsigned Opc =
Op.getOpcode();
14778 MVT XLenVT = Subtarget.getXLenVT();
14798 Vec, Mask, VL,
DL, DAG, Subtarget);
14799 if ((
Opc != ISD::VP_REDUCE_FMINIMUM &&
Opc != ISD::VP_REDUCE_FMAXIMUM) ||
14800 Op->getFlags().hasNoNaNs())
14807 RISCVISD::SETCC_VL,
DL, PredVT,
14809 SDValue VCPop = DAG.
getNode(RISCVISD::VCPOP_VL,
DL, XLenVT, IsNaN, Mask, VL);
14817 DL, ResVT, NoNaNs, Res,
14829 MVT XLenVT = Subtarget.getXLenVT();
14830 unsigned OrigIdx =
Op.getConstantOperandVal(2);
14831 const RISCVRegisterInfo *
TRI = Subtarget.getRegisterInfo();
14835 if (Subtarget.hasStdExtP() && !Subtarget.is64Bit() &&
14836 (VecVT == MVT::v4i16 || VecVT == MVT::v8i8)) {
14838 if (SubVecVT.
getSizeInBits() != 32 || (OrigIdx != 0 && OrigIdx != HalfElts))
14842 return OrigIdx == 0
14847 if (OrigIdx == 0 && Vec.
isUndef())
14858 assert(OrigIdx % 8 == 0 &&
"Invalid index");
14861 "Unexpected mask vector lowering");
14891 const auto VLen = Subtarget.getRealVLen();
14915 if (OrigIdx == 0) {
14921 SlideupAmt, Mask, VL, Policy);
14929 MVT ContainerVecVT = VecVT;
14935 MVT ContainerSubVecVT = SubVecVT;
14941 unsigned SubRegIdx;
14942 ElementCount RemIdx;
14951 ContainerVecVT, ContainerSubVecVT, OrigIdx / Vscale,
TRI);
14952 SubRegIdx = Decompose.first;
14954 (OrigIdx % Vscale));
14958 ContainerVecVT, ContainerSubVecVT, OrigIdx,
TRI);
14959 SubRegIdx = Decompose.first;
14965 Subtarget.expandVScale(SubVecVT.
getSizeInBits()).getKnownMinValue()));
14966 bool ExactlyVecRegSized =
14968 .isKnownMultipleOf(Subtarget.expandVScale(VecRegSize));
14983 if (RemIdx.
isZero() && (ExactlyVecRegSized || Vec.
isUndef())) {
14987 if (SubRegIdx == RISCV::NoSubRegister) {
15009 MVT InterSubVT = ContainerVecVT;
15010 SDValue AlignedExtract = Vec;
15031 if (Subtarget.expandVScale(EndIndex) ==
15038 SubVec = DAG.
getNode(RISCVISD::VMV_V_V_VL,
DL, InterSubVT, AlignedExtract,
15047 SubVec =
getVSlideup(DAG, Subtarget,
DL, InterSubVT, AlignedExtract, SubVec,
15048 SlideupAmt, Mask, VL, Policy);
15053 if (ContainerVecVT.
bitsGT(InterSubVT))
15061 return DAG.
getBitcast(
Op.getSimpleValueType(), SubVec);
15067 MVT SubVecVT =
Op.getSimpleValueType();
15071 MVT XLenVT = Subtarget.getXLenVT();
15072 unsigned OrigIdx =
Op.getConstantOperandVal(1);
15073 const RISCVRegisterInfo *
TRI = Subtarget.getRegisterInfo();
15088 assert(OrigIdx % 8 == 0 &&
"Invalid index");
15091 "Unexpected mask vector lowering");
15117 const auto VLen = Subtarget.getRealVLen();
15133 if (
auto ShrunkVT =
15158 MVT ContainerSubVecVT = SubVecVT;
15162 unsigned SubRegIdx;
15163 ElementCount RemIdx;
15172 VecVT, ContainerSubVecVT, OrigIdx / Vscale,
TRI);
15173 SubRegIdx = Decompose.first;
15175 (OrigIdx % Vscale));
15179 VecVT, ContainerSubVecVT, OrigIdx,
TRI);
15180 SubRegIdx = Decompose.first;
15207 MVT InterSubVT = VecVT;
15212 assert(SubRegIdx != RISCV::NoSubRegister);
15231 Vec, SlidedownAmt, Mask, VL);
15239 return DAG.
getBitcast(
Op.getSimpleValueType(), Slidedown);
15246 MVT VT =
N.getSimpleValueType();
15250 assert(
Op.getSimpleValueType() == VT &&
15251 "Operands and result must be same type");
15255 unsigned NumVals =
N->getNumValues();
15259 N.getValueType().changeVectorElementType(*DAG.
getContext(), MVT::i8)));
15262 for (
unsigned I = 0;
I < NumVals;
I++) {
15268 if (TruncVals.
size() > 1)
15270 return TruncVals.
front();
15276 MVT VecVT =
Op.getSimpleValueType();
15278 const unsigned Factor =
Op->getNumValues();
15287 MVT ContainerVecVT = VecVT;
15295 for (
unsigned i = 0; i != Factor; ++i) {
15298 Ops[i * 2 + 1] = OpHi;
15309 for (
unsigned i = 0; i != Factor; ++i)
15316 if (Subtarget.hasStdExtZvzip() && Factor == 2 && !IsFixedVector) {
15317 MVT VT =
Op->getSimpleValueType(0);
15332 if (Factor == 2 && IsFixedVector) {
15335 for (
unsigned I = 0;
I != Factor; ++
I)
15352 if (Factor == 2 && !IsFixedVector) {
15370 EvenSplat = DAG.
getBitcast(MVT::nxv64i1, EvenSplat);
15374 OddSplat = DAG.
getBitcast(MVT::nxv64i1, OddSplat);
15379 EvenMask, DAG.
getUNDEF(ConcatVT));
15392 MVT XLenVT = Subtarget.getXLenVT();
15397 MachinePointerInfo PtrInfo;
15398 if (IsFixedVector) {
15413 MachinePointerInfo PI = PtrInfo;
15415 for (
auto [Idx, FieldOp] :
enumerate(
Op->op_values())) {
15421 Tokens[
Idx] = DAG.
getStore(Chain,
DL, FieldOp, BasePtr, PI, Alignment);
15426 std::tie(Mask, VL) =
15448 Intrinsic::riscv_vlseg2_mask, Intrinsic::riscv_vlseg3_mask,
15449 Intrinsic::riscv_vlseg4_mask, Intrinsic::riscv_vlseg5_mask,
15450 Intrinsic::riscv_vlseg6_mask, Intrinsic::riscv_vlseg7_mask,
15451 Intrinsic::riscv_vlseg8_mask};
15475 for (
unsigned i = 0U; i < Factor; ++i) {
15477 DAG.
getNode(RISCVISD::TUPLE_EXTRACT,
DL, ContainerVecVT,
Load,
15490 MVT VecVT =
Op.getSimpleValueType();
15503 Op.getOperand(0),
Op.getOperand(1));
15516 MVT ContainerVecVT = VecVT;
15525 (Subtarget.hasStdExtZvzip() && Factor == 2 &&
15529 for (
unsigned i = 0; i != Factor; ++i) {
15532 Ops[i + Factor] = OpHi;
15543 for (
unsigned i = 0; i != Factor; ++i) {
15544 unsigned IdxLo = 2 * i;
15545 unsigned IdxHi = 2 * i + 1;
15547 Res[IdxLo / Factor].
getValue(IdxLo % Factor),
15548 Res[IdxHi / Factor].
getValue(IdxHi % Factor));
15554 MVT XLenVT = Subtarget.getXLenVT();
15573 EVT PtrVT =
StackPtr.getValueType();
15579 Intrinsic::riscv_vsseg2_mask, Intrinsic::riscv_vsseg3_mask,
15580 Intrinsic::riscv_vsseg4_mask, Intrinsic::riscv_vsseg5_mask,
15581 Intrinsic::riscv_vsseg6_mask, Intrinsic::riscv_vsseg7_mask,
15582 Intrinsic::riscv_vsseg8_mask,
15590 for (
unsigned i = 0; i < Factor; i++) {
15594 StoredVal = DAG.
getNode(RISCVISD::TUPLE_INSERT,
DL, VecTupTy, StoredVal,
15615 for (
unsigned i = 0; i != Factor; ++i) {
15619 Loads[i] = DAG.
getLoad(VecVT,
DL, Chain, StackPtr, PtrInfo);
15625 if (Subtarget.hasStdExtZvzip() && !
Op.getOperand(0).isUndef() &&
15626 !
Op.getOperand(1).isUndef()) {
15627 MVT VT =
Op->getSimpleValueType(0);
15650 for (
unsigned I = 0;
I != Factor; ++
I)
15652 VecVT,
DL,
Op.getOperand(0),
Op.getOperand(1),
15653 ArrayRef(ShuffleMask).slice(
I * NumElts, NumElts));
15660 Op.getOperand(0),
Op.getOperand(1));
15684 DAG.
getNode(RISCVISD::ADD_VL,
DL, IdxVT, Idx, VLMax, Idx, OddMask, VL);
15689 Interleaved = DAG.
getNode(RISCVISD::VRGATHEREI16_VV_VL,
DL, ConcatVT,
15706 MVT VT =
Op.getSimpleValueType();
15708 MVT XLenVT = Subtarget.getXLenVT();
15711 uint64_t StepValImm =
Op.getConstantOperandVal(0);
15712 if (StepValImm != 1) {
15721 VL, VT,
DL, DAG, Subtarget);
15736 MVT VecVT =
Op.getSimpleValueType();
15740 if (Subtarget.hasStdExtP() && !Subtarget.hasVInstructions()) {
15742 "Unexpected packed VECTOR_REVERSE type");
15744 if (VecVT == MVT::v2i32) {
15771 MVT XLenVT = Subtarget.getXLenVT();
15817 unsigned VectorBitsMax = Subtarget.getRealMaxVLen();
15818 unsigned MaxVLMAX =
15823 unsigned GatherOpc = RISCVISD::VRGATHER_VV_VL;
15828 if (MaxVLMAX > 256 && EltSize == 8) {
15844 GatherOpc = RISCVISD::VRGATHEREI16_VV_VL;
15852 GatherOpc = RISCVISD::VRGATHEREI16_VV_VL;
15889 MVT XLenVT = Subtarget.getXLenVT();
15890 MVT VecVT =
Op.getSimpleValueType();
15894 SDValue DownOffset, UpOffset;
15910 DAG, Subtarget,
DL, VecVT, DAG.
getUNDEF(VecVT),
V1, DownOffset, TrueMask,
15911 Subtarget.hasVLDependentLatency() ? UpOffset
15913 return getVSlideup(DAG, Subtarget,
DL, VecVT, SlideDown, V2, UpOffset,
15919RISCVTargetLowering::lowerFixedLengthVectorLoadToRVV(
SDValue Op,
15925 Load->getMemoryVT(),
15926 *
Load->getMemOperand()) &&
15927 "Expecting a correctly-aligned load");
15929 MVT VT =
Op.getSimpleValueType();
15930 MVT XLenVT = Subtarget.getXLenVT();
15935 const auto [MinVLMAX, MaxVLMAX] =
15939 MachineMemOperand *MMO =
Load->getMemOperand();
15952 IsMaskOp ? Intrinsic::riscv_vlm : Intrinsic::riscv_vle,
DL, XLenVT);
15956 Ops.push_back(
Load->getBasePtr());
15961 Load->getMemoryVT(),
Load->getMemOperand());
15968RISCVTargetLowering::lowerFixedLengthVectorStoreToRVV(
SDValue Op,
15974 Store->getMemoryVT(),
15975 *
Store->getMemOperand()) &&
15976 "Expecting a correctly-aligned store");
15980 MVT XLenVT = Subtarget.getXLenVT();
15996 const auto [MinVLMAX, MaxVLMAX] =
16000 MachineMemOperand *MMO =
Store->getMemOperand();
16010 IsMaskOp ? Intrinsic::riscv_vsm : Intrinsic::riscv_vse,
DL, XLenVT);
16013 {Store->getChain(), IntID, NewValue, Store->getBasePtr(), VL},
16014 Store->getMemoryVT(),
Store->getMemOperand());
16020 MVT VT =
Op.getSimpleValueType();
16023 EVT MemVT = MemSD->getMemoryVT();
16024 MachineMemOperand *MMO = MemSD->getMemOperand();
16025 SDValue Chain = MemSD->getChain();
16029 bool IsExpandingLoad =
false;
16031 Mask = VPLoad->getMask();
16033 VL = VPLoad->getVectorLength();
16037 PassThru =
MLoad->getPassThru();
16038 IsExpandingLoad =
MLoad->isExpandingLoad();
16043 MVT XLenVT = Subtarget.getXLenVT();
16059 if (!IsUnmasked && IsExpandingLoad) {
16062 DAG.
getNode(RISCVISD::VCPOP_VL,
DL, XLenVT, Mask,
16066 unsigned IntID = IsUnmasked || IsExpandingLoad ? Intrinsic::riscv_vle
16067 : Intrinsic::riscv_vle_mask;
16069 if (IntID == Intrinsic::riscv_vle)
16072 Ops.push_back(PassThru);
16073 Ops.push_back(BasePtr);
16074 if (IntID == Intrinsic::riscv_vle_mask)
16075 Ops.push_back(Mask);
16077 if (IntID == Intrinsic::riscv_vle_mask)
16084 Chain =
Result.getValue(1);
16091 bool UseVRGATHEREI16 =
false;
16098 if (IndexEltVT == MVT::i8 && MaxEltCount > 256) {
16102 UseVRGATHEREI16 =
true;
16108 DAG.
getUNDEF(IndexVT), Mask, ExpandingVL);
16110 DAG.
getNode(UseVRGATHEREI16 ? RISCVISD::VRGATHEREI16_VV_VL
16111 : RISCVISD::VRGATHER_VV_VL,
16112 DL,
ContainerVT, Result, Iota, PassThru, Mask, ExpandingVL);
16123 MVT VT =
Op->getSimpleValueType(0);
16126 EVT MemVT = VPLoadFF->getMemoryVT();
16127 MachineMemOperand *MMO = VPLoadFF->getMemOperand();
16128 SDValue Chain = VPLoadFF->getChain();
16132 SDValue VL = VPLoadFF->getVectorLength();
16134 MVT XLenVT = Subtarget.getXLenVT();
16143 unsigned IntID = Intrinsic::riscv_vleff_mask;
16158 Chain =
Result.getValue(2);
16171 EVT MemVT = MemSD->getMemoryVT();
16172 MachineMemOperand *MMO = MemSD->getMemOperand();
16173 SDValue Chain = MemSD->getChain();
16177 bool IsCompressingStore =
false;
16179 Val = VPStore->getValue();
16180 Mask = VPStore->getMask();
16181 VL = VPStore->getVectorLength();
16184 Val = MStore->getValue();
16185 Mask = MStore->getMask();
16186 IsCompressingStore = MStore->isCompressingStore();
16193 MVT XLenVT = Subtarget.getXLenVT();
16200 if (!IsUnmasked || IsCompressingStore) {
16209 if (IsCompressingStore) {
16215 DAG.
getNode(RISCVISD::VCPOP_VL,
DL, XLenVT, Mask,
16220 IsUnmasked ? Intrinsic::riscv_vse : Intrinsic::riscv_vse_mask;
16222 Ops.push_back(Val);
16223 Ops.push_back(BasePtr);
16225 Ops.push_back(Mask);
16240 MVT XLenVT = Subtarget.getXLenVT();
16254 Passthru, Val, Mask, VL);
16264 unsigned Opc =
Op.getOpcode();
16271 MVT VT =
Op.getSimpleValueType();
16279 SDVTList VTList =
Op->getVTList();
16304 MVT ContainerInVT = InVT;
16322 RISCVISD::STRICT_FSETCC_VL,
DL, DAG.
getVTList(MaskVT, MVT::Other),
16323 {Chain, Op1, Op1, DAG.getCondCode(ISD::SETOEQ), DAG.getUNDEF(MaskVT),
16326 RISCVISD::STRICT_FSETCC_VL,
DL, DAG.
getVTList(MaskVT, MVT::Other),
16327 {Chain, Op2, Op2, DAG.getCondCode(ISD::SETOEQ), DAG.getUNDEF(MaskVT),
16330 DAG.
getNode(RISCVISD::VMAND_VL,
DL, MaskVT, OrderMask1, OrderMask2, VL);
16333 Res = DAG.
getNode(RISCVISD::STRICT_FSETCCS_VL,
DL,
16335 {Chain, Op1, Op2, CC, Mask, Mask, VL});
16338 : RISCVISD::STRICT_FSETCCS_VL;
16340 {Chain, Op1, Op2, CC, DAG.getUNDEF(MaskVT), Mask, VL});
16353 MVT VT =
Op.getSimpleValueType();
16367 if (Subtarget.hasStdExtZvabd()) {
16381 const auto &TSInfo =
16385 bool HasPassthruOp = TSInfo.hasPassthruOp(NewOpc);
16386 bool HasMask = TSInfo.hasMaskOp(NewOpc);
16388 MVT VT =
Op.getSimpleValueType();
16397 if (!
V.getValueType().isVector()) {
16403 assert(useRVVForFixedLengthVectorVT(
V.getSimpleValueType()) &&
16404 "Only fixed length vectors are supported!");
16406 V.getSimpleValueType().getVectorElementType());
16415 Ops.push_back(Mask);
16420 if (
Op->isStrictFPOpcode()) {
16439 const auto &TSInfo =
16443 bool HasPassthruOp = TSInfo.hasPassthruOp(RISCVISDOpc);
16446 MVT VT =
Op.getSimpleValueType();
16458 if (HasPassthruOp) {
16461 if (*MaskIdx == OpIdx.index())
16465 assert(
Op.getOpcode() == ISD::VP_MERGE);
16467 Ops.push_back(
Ops.back());
16471 if (RISCVISDOpc == RISCVISD::VFCVT_RM_X_F_VL &&
16474 Subtarget.getXLenVT()));
16476 if (!
V.getValueType().isFixedLengthVector()) {
16481 MVT OpVT =
V.getSimpleValueType();
16483 assert(useRVVForFixedLengthVectorVT(OpVT) &&
16484 "Only fixed length vectors are supported!");
16499 MVT VT =
Op.getSimpleValueType();
16500 MVT XLenVT = Subtarget.getXLenVT();
16533 TrueVal = DAG.
getNode(RISCVISD::VMERGE_VL,
DL, PromotedVT, TrueVal, SplatOne,
16534 SplatZero, DAG.
getUNDEF(PromotedVT), VL);
16537 SplatOne, SplatZero, DAG.
getUNDEF(PromotedVT), VLMax);
16541 TrueVal, FalseVal, FalseVal, VL);
16556RISCVTargetLowering::lowerVPSpliceExperimental(
SDValue Op,
16558 using namespace SDPatternMatch;
16569 const MVT XLenVT = Subtarget.getXLenVT();
16570 MVT VT =
Op.getSimpleValueType();
16581 if (IsMaskVector) {
16604 auto getVectorFirstEle = [](
SDValue Vec) {
16617 if (
auto FirstEle = getVectorFirstEle(
Op->getOperand(0))) {
16620 if ((EltVT == MVT::f16 && !Subtarget.hasVInstructionsF16()) ||
16621 (EltVT == MVT::bf16 && !Subtarget.hasVInstructionsBF16())) {
16629 : RISCVISD::VSLIDE1UP_VL,
16631 FirstEle, Mask, EVL2);
16641 SDValue DownOffset, UpOffset;
16642 if (ImmValue >= 0) {
16657 Subtarget.hasVLDependentLatency() ? UpOffset : EVL2);
16661 if (IsMaskVector) {
16665 {Result, DAG.getConstant(0, DL, ContainerVT),
16666 DAG.getCondCode(ISD::SETNE), DAG.getUNDEF(getMaskTypeFor(ContainerVT)),
16676RISCVTargetLowering::lowerVPReverseExperimental(
SDValue Op,
16679 MVT VT =
Op.getSimpleValueType();
16680 MVT XLenVT = Subtarget.getXLenVT();
16698 if (IsMaskVector) {
16708 Op1 = DAG.
getNode(RISCVISD::VMERGE_VL,
DL, IndicesVT, Op1, SplatOne,
16709 SplatZero, DAG.
getUNDEF(IndicesVT), EVL);
16714 unsigned VectorBitsMax = Subtarget.getRealMaxVLen();
16715 unsigned MaxVLMAX =
16718 unsigned GatherOpc = RISCVISD::VRGATHER_VV_VL;
16724 if (MaxVLMAX > 256 && EltSize == 8) {
16751 DAG.
getUNDEF(GatherVT), Result, Diff, Mask, EVL);
16753 if (IsMaskVector) {
16769 GatherOpc = RISCVISD::VRGATHEREI16_VV_VL;
16776 DAG.
getUNDEF(IndicesVT), VecLen, EVL);
16777 SDValue VRSUB = DAG.
getNode(RISCVISD::SUB_VL,
DL, IndicesVT, VecLenSplat, VID,
16778 DAG.
getUNDEF(IndicesVT), Mask, EVL);
16780 DAG.
getUNDEF(GatherVT), Mask, EVL);
16782 if (IsMaskVector) {
16798 MVT XLenVT = Subtarget.getXLenVT();
16799 MVT VT =
Op.getSimpleValueType();
16812 : Intrinsic::riscv_vlse_mask,
16816 VPNode->getStride()};
16822 Ops.push_back(Mask);
16824 Ops.push_back(VPNode->getVectorLength());
16828 Ops.push_back(Policy);
16833 VPNode->getMemoryVT(), VPNode->getMemOperand());
16845 MVT XLenVT = Subtarget.getXLenVT();
16848 SDValue StoreVal = VPNode->getValue();
16861 : Intrinsic::riscv_vsse_mask,
16864 VPNode->getBasePtr(), VPNode->getStride()};
16870 Ops.push_back(Mask);
16872 Ops.push_back(VPNode->getVectorLength());
16875 Ops, VPNode->getMemoryVT(),
16876 VPNode->getMemOperand());
16888 MVT VT =
Op.getSimpleValueType();
16891 EVT MemVT = MemSD->getMemoryVT();
16892 MachineMemOperand *MMO = MemSD->getMemOperand();
16893 SDValue Chain = MemSD->getChain();
16900 Index = VPGN->getIndex();
16901 Mask = VPGN->getMask();
16903 VL = VPGN->getVectorLength();
16909 Index = MGN->getIndex();
16910 Mask = MGN->getMask();
16911 PassThru = MGN->getPassThru();
16915 MVT IndexVT =
Index.getSimpleValueType();
16916 MVT XLenVT = Subtarget.getXLenVT();
16919 "Unexpected VTs!");
16920 assert(
BasePtr.getSimpleValueType() == XLenVT &&
"Unexpected pointer type");
16923 "Unexpected extending MGATHER/VP_GATHER");
16953 IsUnmasked ? Intrinsic::riscv_vluxei : Intrinsic::riscv_vluxei_mask;
16958 Ops.push_back(PassThru);
16959 Ops.push_back(BasePtr);
16960 Ops.push_back(Index);
16962 Ops.push_back(Mask);
16970 Chain =
Result.getValue(1);
16988 EVT MemVT = MemSD->getMemoryVT();
16989 MachineMemOperand *MMO = MemSD->getMemOperand();
16990 SDValue Chain = MemSD->getChain();
16993 [[maybe_unused]]
bool IsTruncatingStore =
false;
16997 Index = VPSN->getIndex();
16998 Mask = VPSN->getMask();
16999 Val = VPSN->getValue();
17000 VL = VPSN->getVectorLength();
17002 IsTruncatingStore =
false;
17006 Index = MSN->getIndex();
17007 Mask = MSN->getMask();
17008 Val = MSN->getValue();
17009 IsTruncatingStore = MSN->isTruncatingStore();
17013 MVT IndexVT =
Index.getSimpleValueType();
17014 MVT XLenVT = Subtarget.getXLenVT();
17017 "Unexpected VTs!");
17018 assert(
BasePtr.getSimpleValueType() == XLenVT &&
"Unexpected pointer type");
17021 assert(!IsTruncatingStore &&
"Unexpected truncating MSCATTER/VP_SCATTER");
17051 IsUnmasked ? Intrinsic::riscv_vsoxei : Intrinsic::riscv_vsoxei_mask;
17053 Ops.push_back(Val);
17054 Ops.push_back(BasePtr);
17055 Ops.push_back(Index);
17057 Ops.push_back(Mask);
17066 const MVT XLenVT = Subtarget.getXLenVT();
17070 SDVTList VTs = DAG.
getVTList(XLenVT, MVT::Other);
17077 static const int Table =
17096 const MVT XLenVT = Subtarget.getXLenVT();
17106 static const unsigned Table =
17121 return DAG.
getNode(RISCVISD::WRITE_CSR,
DL, MVT::Other, Chain, SysRegNo,
17127 const MVT XLenVT = Subtarget.getXLenVT();
17131 SDVTList VTs = DAG.
getVTList(XLenVT, MVT::Other);
17132 return DAG.
getNode(RISCVISD::READ_CSR,
DL, VTs, Chain, SysRegNo);
17137 const MVT XLenVT = Subtarget.getXLenVT();
17144 return DAG.
getNode(RISCVISD::WRITE_CSR,
DL, MVT::Other, Chain, SysRegNo,
17150 const MVT XLenVT = Subtarget.getXLenVT();
17156 return DAG.
getNode(RISCVISD::WRITE_CSR,
DL, MVT::Other, Chain, SysRegNo,
17170 SDValue Result = DAG.
getNode(RISCVISD::READ_CSR,
DL, VTs, Chain, SysRegNo);
17171 Chain = Result.getValue(1);
17177 const MVT XLenVT = Subtarget.getXLenVT();
17187 Chain = DAG.
getNode(RISCVISD::CLEAR_CSR,
DL, MVT::Other, Chain, SysRegNo,
17189 return DAG.
getNode(RISCVISD::SET_CSR,
DL, MVT::Other, Chain, SysRegNo,
17195 const MVT XLenVT = Subtarget.getXLenVT();
17202 return DAG.
getNode(RISCVISD::CLEAR_CSR,
DL, MVT::Other, Chain, SysRegNo,
17210 bool isRISCV64 = Subtarget.is64Bit();
17224 return RISCVISD::SLLW;
17226 return RISCVISD::SRAW;
17228 return RISCVISD::SRLW;
17230 return RISCVISD::DIVW;
17232 return RISCVISD::DIVUW;
17234 return RISCVISD::REMUW;
17236 return RISCVISD::ROLW;
17238 return RISCVISD::RORW;
17282 switch (
N->getOpcode()) {
17284 llvm_unreachable(
"Don't know how to custom type legalize this operation!");
17289 bool IsStrict =
N->isStrictFPOpcode();
17292 SDValue Op0 = IsStrict ?
N->getOperand(1) :
N->getOperand(0);
17299 if (!Subtarget.is64Bit()) {
17300 assert(
N->getValueType(0) == MVT::i64 &&
17301 "Unexpected custom legalisation");
17308 DL, {MVT::i32, MVT::Other}, {
N->getOperand(0), Op0});
17320 assert(
N->getValueType(0) == MVT::i32 &&
"Unexpected custom legalisation");
17329 !Subtarget.hasStdExtZfhOrZhinx()) {
17334 unsigned Opc = IsSigned ? RISCVISD::STRICT_FCVT_W_RV64
17335 : RISCVISD::STRICT_FCVT_WU_RV64;
17338 Opc,
DL, VTs, Chain, Op0,
17347 !Subtarget.hasStdExtZfhOrZhinx()) ||
17351 unsigned Opc = IsSigned ? RISCVISD::FCVT_W_RV64 : RISCVISD::FCVT_WU_RV64;
17372 std::tie(Result, Chain) =
17373 makeLibCall(DAG, LC,
N->getValueType(0), Op0, CallOptions,
DL, Chain);
17388 if (Op0.
getValueType() == MVT::f16 && !Subtarget.hasStdExtZfhOrZhinx())
17392 DAG.
getNode(RISCVISD::FCVT_W_RV64,
DL, MVT::i64, Op0,
17400 RTLIB::Libcall LC = RTLIB::getLROUND(Op0.
getValueType());
17401 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected FP type for LROUND!");
17412 assert(!Subtarget.is64Bit() &&
"READCYCLECOUNTER/READSTEADYCOUNTER only "
17413 "has custom type legalization on riscv32");
17415 SDValue LoCounter, HiCounter;
17416 MVT XLenVT = Subtarget.getXLenVT();
17426 N->getOperand(0), LoCounter, HiCounter);
17441 if (
N->getValueType(0) == MVT::i64) {
17442 assert(Subtarget.hasStdExtZilsd() && !Subtarget.is64Bit() &&
17443 "Unexpected custom legalisation");
17445 if (Ld->getAlign() < Subtarget.getZilsdAlign())
17450 RISCVISD::LD_RV32,
DL,
17451 DAG.
getVTList({MVT::i32, MVT::i32, MVT::Other}),
17452 {Ld->getChain(), Ld->getBasePtr()}, MVT::i64, Ld->getMemOperand());
17456 Results.append({Pair, Result.getValue(2)});
17460 assert(
N->getValueType(0) == MVT::i32 && Subtarget.is64Bit() &&
17461 "Unexpected custom legalisation");
17465 Ld->getBasePtr(), Ld->getMemoryVT(),
17466 Ld->getMemOperand());
17472 unsigned Size =
N->getSimpleValueType(0).getSizeInBits();
17473 unsigned XLen = Subtarget.getXLen();
17481 assert(
Size == (XLen * 2) &&
"Unexpected custom legalisation");
17484 unsigned LoHiOpc) {
17485 MVT XLenVT = Subtarget.getXLenVT();
17489 if (Subtarget.hasStdExtP() && !Subtarget.is64Bit()) {
17492 Hi =
Lo.getValue(1);
17506 if (LHSIsU && RHSIsU) {
17513 if (LHSIsS && RHSIsS)
17515 else if (RHSIsU && LHSIsS)
17517 MakeMULPair(LHS, RHS, RISCVISD::MULHSU, RISCVISD::WMULSU));
17518 else if (LHSIsU && RHSIsS)
17520 MakeMULPair(RHS, LHS, RISCVISD::MULHSU, RISCVISD::WMULSU));
17528 if (
N->getValueType(0) == MVT::i64) {
17529 assert(!Subtarget.is64Bit() && Subtarget.hasStdExtP() &&
17530 "Unexpected custom legalisation");
17533 auto [LHSLo, LHSHi] =
17535 auto [RHSLo, RHSHi] =
17538 N->getOpcode() ==
ISD::ADD ? RISCVISD::ADDD : RISCVISD::SUBD;
17540 LHSLo, LHSHi, RHSLo, RHSHi);
17546 assert(
N->getValueType(0) == MVT::i32 && Subtarget.is64Bit() &&
17547 "Unexpected custom legalisation");
17551 MVT VT =
N->getSimpleValueType(0);
17553 Subtarget.is64Bit() && (VT == MVT::v2i16 || VT == MVT::v4i8) &&
17554 "Unexpected custom legalisation");
17572 for (
unsigned i = 0; i != NumElts; ++i)
17573 ShuffleMask[i] = i * 2;
17577 DAG.
getUNDEF(WidenVT), ShuffleMask));
17583 EVT VT =
N->getValueType(0);
17585 assert(Subtarget.is64Bit() && (VT == MVT::v2i16 || VT == MVT::v4i8) &&
17586 "Unexpected vector type for P-extension shift");
17590 SDValue ShiftAmt =
N->getOperand(1);
17602 if (VT == MVT::i64) {
17603 assert(!Subtarget.is64Bit() && Subtarget.hasStdExtP() &&
17604 "Unexpected custom legalisation");
17609 unsigned WideOpc = 0;
17613 WideOpc = RISCVISD::WSLL;
17615 WideOpc = RISCVISD::WSLA;
17632 if (!ShAmtC || ShAmtC->getZExtValue() >= 32)
17646 uint64_t ShAmtVal = ShAmtC->getZExtValue();
17651 bool IsSRA =
N->getOpcode() ==
ISD::SRA;
17652 LoRes = DAG.
getNode(IsSRA ? RISCVISD::NSRA : RISCVISD::NSRL,
DL,
17653 MVT::i32,
Lo,
Hi, ShAmt);
17662 assert(VT == MVT::i32 && Subtarget.is64Bit() &&
17663 "Unexpected custom legalisation");
17666 if (
N->getOpcode() ==
ISD::SHL && Subtarget.hasStdExtZbs() &&
17692 assert(!Subtarget.is64Bit() && Subtarget.hasStdExtP() &&
17693 N->getValueType(0) == MVT::i64 &&
17694 "Unexpected custom funnel shift legalization");
17696 auto [XLo, XHi] = DAG.
SplitScalar(
N->getOperand(0),
DL, MVT::i32, MVT::i32);
17697 auto [YLo, YHi] = DAG.
SplitScalar(
N->getOperand(1),
DL, MVT::i32, MVT::i32);
17700 unsigned Amt =
C->getZExtValue() % 64;
17702 if (Amt == 0 || Amt == 32)
17720 Lo = Nsrl(YLo, YHi, Amt);
17727 Hi = Nsrl(XLo, XHi, Amt - 32);
17734 unsigned Opc =
N->getOpcode();
17746 return DAG.
getNode(RISCVISD::MERGE,
DL, MVT::i32, Mask, Below32,
17752 SDValue Cross = Funnel(XLo, YHi);
17753 SDValue LoBelow32, HiBelow32, LoAtLeast32, HiAtLeast32;
17756 HiBelow32 = Funnel(XHi, XLo);
17757 LoAtLeast32 = Funnel(YHi, YLo);
17758 HiAtLeast32 = Cross;
17760 LoBelow32 = Funnel(YHi, YLo);
17762 LoAtLeast32 = Cross;
17763 HiAtLeast32 = Funnel(XHi, XLo);
17773 assert(
N->getValueType(0) == MVT::i32 && Subtarget.is64Bit() &&
17774 "Unexpected custom legalisation");
17775 assert((Subtarget.hasStdExtZbb() || Subtarget.hasStdExtZbkb() ||
17776 Subtarget.hasVendorXTHeadBb()) &&
17777 "Unexpected custom legalization");
17779 !(Subtarget.hasStdExtZbb() || Subtarget.hasStdExtZbkb()))
17788 assert(
N->getValueType(0) == MVT::i32 && Subtarget.is64Bit() &&
17789 "Unexpected custom legalisation");
17794 switch (
N->getOpcode()) {
17798 Opc = RISCVISD::CTZW;
17802 Opc = RISCVISD::CLZW;
17805 Opc = RISCVISD::CLSW;
17816 MVT VT =
N->getSimpleValueType(0);
17817 assert((VT == MVT::i8 || VT == MVT::i16 || VT == MVT::i32) &&
17818 Subtarget.is64Bit() && Subtarget.hasStdExtM() &&
17819 "Unexpected custom legalisation");
17831 if (VT != MVT::i32)
17840 assert(
N->getValueType(0) == MVT::i32 && Subtarget.is64Bit() &&
17841 "Unexpected custom legalisation");
17863 EVT OType =
N->getValueType(1);
17880 assert(
N->getValueType(0) == MVT::i32 && Subtarget.is64Bit() &&
17881 "Unexpected custom legalisation");
17898 Overflow = DAG.
getSetCC(
DL,
N->getValueType(1), Res,
17902 Overflow = DAG.
getSetCC(
DL,
N->getValueType(1),
N->getOperand(0),
17909 Overflow = DAG.
getSetCC(
DL,
N->getValueType(1), Res, LHS,
17921 assert(
N->getValueType(0) == MVT::i32 && Subtarget.is64Bit() &&
17922 "Unexpected custom legalisation");
17924 if (Subtarget.hasStdExtP()) {
17940 assert(!Subtarget.hasStdExtZbb() &&
"Unexpected custom legalisation");
17946 assert(
N->getValueType(0) == MVT::i32 && Subtarget.is64Bit() &&
17947 "Unexpected custom legalisation");
17949 if (Subtarget.hasStdExtP()) {
17957 if (Subtarget.hasStdExtZbb()) {
17991 EVT VT =
N->getValueType(0);
17995 MVT XLenVT = Subtarget.getXLenVT();
17996 if (VT == MVT::i16 &&
17997 ((Op0VT == MVT::f16 && Subtarget.hasStdExtZfhminOrZhinxmin()) ||
17998 (Op0VT == MVT::bf16 && Subtarget.hasStdExtZfbfmin()))) {
18001 }
else if (VT == MVT::i32 && Op0VT == MVT::f32 && Subtarget.is64Bit() &&
18002 Subtarget.hasStdExtFOrZfinx()) {
18004 DAG.
getNode(RISCVISD::FMV_X_ANYEXTW_RV64,
DL, MVT::i64, Op0);
18006 }
else if (VT == MVT::i64 && Op0VT == MVT::f64 && !Subtarget.is64Bit() &&
18007 Subtarget.hasStdExtDOrZdinx()) {
18009 DAG.
getVTList(MVT::i32, MVT::i32), Op0);
18013 if (!Subtarget.isLittleEndian())
18032 assert(
N->getValueType(0) == MVT::i8 && Subtarget.hasStdExtZbkb() &&
18033 "Unexpected custom legalisation");
18034 MVT XLenVT = Subtarget.getXLenVT();
18042 case RISCVISD::BREV8:
18043 case RISCVISD::ORC_B: {
18044 MVT VT =
N->getSimpleValueType(0);
18045 MVT XLenVT = Subtarget.getXLenVT();
18046 assert((VT == MVT::i16 || (VT == MVT::i32 && Subtarget.is64Bit())) &&
18047 "Unexpected custom legalisation");
18048 assert(((
N->getOpcode() == RISCVISD::BREV8 && Subtarget.hasStdExtZbkb()) ||
18049 (
N->getOpcode() == RISCVISD::ORC_B && Subtarget.hasStdExtZbb())) &&
18050 "Unexpected extension");
18058 case RISCVISD::MULHSU:
18059 case RISCVISD::MULHR:
18060 case RISCVISD::MULHRU:
18061 case RISCVISD::MULHRSU: {
18062 MVT VT =
N->getSimpleValueType(0);
18065 unsigned Opcode =
N->getOpcode();
18066 assert(VT == MVT::v2i16);
18067 MVT NewVT = MVT::v4i16;
18092 assert(!Subtarget.is64Bit() &&
N->getValueType(0) == MVT::i64 &&
18094 "Unexpected EXTRACT_VECTOR_ELT legalization");
18103 MVT XLenVT = Subtarget.getXLenVT();
18133 unsigned IntNo =
N->getConstantOperandVal(0);
18137 "Don't know how to custom type legalize this intrinsic!");
18138 case Intrinsic::experimental_get_vector_length: {
18143 case Intrinsic::riscv_psext_h:
18145 case Intrinsic::riscv_pzext_h:
18147 case Intrinsic::riscv_psext_b:
18148 case Intrinsic::riscv_pzext_b: {
18149 bool IsSExt = IntNo == Intrinsic::riscv_psext_b;
18150 const char *UnsupportedMsg =
18151 IsSExt ?
"unsupported llvm.riscv.psext intrinsic"
18152 :
"unsupported llvm.riscv.pzext intrinsic";
18153 EVT VT =
N->getValueType(0);
18154 if (!Subtarget.is64Bit() || VT != MVT::v2i16)
18168 case Intrinsic::riscv_pmhacc:
18169 case Intrinsic::riscv_pmhracc:
18170 case Intrinsic::riscv_pmhaccu:
18171 case Intrinsic::riscv_pmhraccu:
18172 case Intrinsic::riscv_pmhaccsu:
18173 case Intrinsic::riscv_pmhraccsu: {
18174 EVT VT =
N->getValueType(0);
18175 if (!Subtarget.is64Bit() || VT != MVT::v2i16)
18178 EVT WideVT = MVT::v4i16;
18187 WideVT, Rd, Rs1, Rs2);
18191 case Intrinsic::riscv_pmhacc_half_0:
18192 case Intrinsic::riscv_pmhacc_half_1:
18193 case Intrinsic::riscv_pmhaccsu_half_0:
18194 case Intrinsic::riscv_pmhaccsu_half_1: {
18198 EVT VT =
N->getValueType(0);
18199 if (!Subtarget.is64Bit() || VT != MVT::v2i16)
18202 EVT WideVT = MVT::v4i16;
18210 N->getOperand(3), DAG.
getUNDEF(MVT::v4i8));
18212 WideVT, Rd, Rs1, Rs2);
18216 case Intrinsic::riscv_pm4add:
18217 case Intrinsic::riscv_pm2add:
18218 case Intrinsic::riscv_pm2add_x:
18219 case Intrinsic::riscv_pm4addu:
18220 case Intrinsic::riscv_pm2addu:
18221 case Intrinsic::riscv_pmq2add:
18222 case Intrinsic::riscv_pmqr2add:
18223 case Intrinsic::riscv_pm2sadd:
18224 case Intrinsic::riscv_pm2sadd_x:
18225 case Intrinsic::riscv_pm2sub:
18226 case Intrinsic::riscv_pm2sub_x:
18227 case Intrinsic::riscv_pm4addsu:
18228 case Intrinsic::riscv_pm2addsu: {
18229 MVT VT =
N->getSimpleValueType(0);
18234 if (!Subtarget.is64Bit() && VT == MVT::i64) {
18240 assert(Subtarget.is64Bit() && VT == MVT::i32 &&
18241 "Unexpected horizontal multiply legalization");
18243 MVT WideSrcVT = SrcVT == MVT::v4i8 ? MVT::v8i8 : MVT::v4i16;
18253 case Intrinsic::riscv_pm2wadd:
18254 case Intrinsic::riscv_pm2wadd_x:
18255 case Intrinsic::riscv_pm2waddu:
18256 case Intrinsic::riscv_pm2wsub:
18257 case Intrinsic::riscv_pm2wsub_x:
18258 case Intrinsic::riscv_pm2waddsu: {
18261 assert(!Subtarget.is64Bit() &&
N->getSimpleValueType(0) == MVT::i64 &&
18262 "Unexpected widening horizontal multiply-add legalization");
18269 case Intrinsic::riscv_pm2wadda:
18270 case Intrinsic::riscv_pm2wadda_x:
18271 case Intrinsic::riscv_pm2waddau:
18272 case Intrinsic::riscv_pm2wsuba:
18273 case Intrinsic::riscv_pm2wsuba_x:
18274 case Intrinsic::riscv_pm2waddasu: {
18276 assert(!Subtarget.is64Bit() &&
N->getSimpleValueType(0) == MVT::i64 &&
18277 "Unexpected widening horizontal multiply-accumulate legalization");
18280 auto [RdLo, RdHi] =
18284 {RdLo, RdHi, Rs1, Rs2});
18290 case Intrinsic::riscv_pm2adda:
18291 case Intrinsic::riscv_pm2adda_x:
18292 case Intrinsic::riscv_pm2addau:
18293 case Intrinsic::riscv_pmq2adda:
18294 case Intrinsic::riscv_pmqr2adda:
18295 case Intrinsic::riscv_pm2suba:
18296 case Intrinsic::riscv_pm2suba_x:
18297 case Intrinsic::riscv_pm2addasu: {
18299 if (
N->getSimpleValueType(0) == MVT::i32) {
18310 WideRd, WideRs1, WideRs2);
18315 assert(!Subtarget.is64Bit() &&
N->getSimpleValueType(0) == MVT::i64 &&
18316 "Unexpected multiply-horizontal-add-accumulate legalization");
18319 auto [RdLo, RdHi] =
18322 auto Extract = [&](
SDValue V,
unsigned Idx) {
18325 SDValue Rs1Lo = Extract(Rs1, 0);
18326 SDValue Rs1Hi = Extract(Rs1, 1);
18327 SDValue Rs2Lo = Extract(Rs2, 0);
18328 SDValue Rs2Hi = Extract(Rs2, 1);
18330 if (IntNo == Intrinsic::riscv_pmq2adda ||
18331 IntNo == Intrinsic::riscv_pmqr2adda) {
18332 unsigned AccOpc = IntNo == Intrinsic::riscv_pmq2adda
18334 : RISCVISD::MQRWACC;
18343 if (IntNo == Intrinsic::riscv_pm2suba ||
18344 IntNo == Intrinsic::riscv_pm2suba_x) {
18345 if (IntNo == Intrinsic::riscv_pm2suba_x)
18358 if (IntNo == Intrinsic::riscv_pm2adda_x)
18362 if (IntNo == Intrinsic::riscv_pm2addau)
18364 else if (IntNo == Intrinsic::riscv_pm2addasu)
18365 MulOpc = RISCVISD::WMULSU;
18378 case Intrinsic::riscv_pm4adda:
18379 case Intrinsic::riscv_pm4addau:
18380 case Intrinsic::riscv_pm4addasu: {
18382 if (
N->getSimpleValueType(0) == MVT::i32) {
18394 DAG.
getNode(
Opc,
DL, MVT::v2i32, WideRd, WideRs1, WideRs2);
18399 assert(!Subtarget.is64Bit() &&
N->getSimpleValueType(0) == MVT::i64 &&
18400 "Unexpected widening horizontal multiply-accumulate legalization");
18405 auto [RdLo, RdHi] =
18407 unsigned AccOpc = IntNo == Intrinsic::riscv_pm4addau ? RISCVISD::PM2WADDAU
18408 : IntNo == Intrinsic::riscv_pm4addasu
18409 ? RISCVISD::PM2WADDASU
18410 : RISCVISD::PM2WADDA;
18419 case Intrinsic::riscv_pmul_00:
18420 case Intrinsic::riscv_pmul_01:
18421 case Intrinsic::riscv_pmul_11:
18422 case Intrinsic::riscv_pmulu_00:
18423 case Intrinsic::riscv_pmulu_01:
18424 case Intrinsic::riscv_pmulu_11:
18425 case Intrinsic::riscv_pmulsu_00:
18426 case Intrinsic::riscv_pmulsu_11: {
18427 MVT VT =
N->getSimpleValueType(0);
18428 if (!Subtarget.is64Bit() || VT != MVT::v2i16)
18433 N->getOperand(1),
Undef);
18435 N->getOperand(2),
Undef);
18441 case Intrinsic::riscv_mul_00:
18442 case Intrinsic::riscv_mul_01:
18443 case Intrinsic::riscv_mul_11:
18444 case Intrinsic::riscv_mulu_00:
18445 case Intrinsic::riscv_mulu_01:
18446 case Intrinsic::riscv_mulu_11:
18447 case Intrinsic::riscv_mulsu_00:
18448 case Intrinsic::riscv_mulsu_11: {
18451 MVT VT =
N->getSimpleValueType(0);
18452 MVT SrcVT =
N->getOperand(1).getSimpleValueType();
18453 if (Subtarget.hasStdExtP() && Subtarget.is64Bit() && VT == MVT::i32 &&
18454 SrcVT == MVT::v2i16) {
18458 N->getOperand(1),
Undef);
18460 N->getOperand(2),
Undef);
18466 if (Subtarget.hasStdExtP() && !Subtarget.is64Bit() && VT == MVT::i64 &&
18467 SrcVT == MVT::v2i32) {
18481 case Intrinsic::riscv_pmulh_half_0:
18482 case Intrinsic::riscv_pmulh_half_1:
18483 case Intrinsic::riscv_pmulhsu_half_0:
18484 case Intrinsic::riscv_pmulhsu_half_1: {
18487 EVT VT =
N->getValueType(0);
18488 if (!Subtarget.is64Bit() || VT != MVT::v2i16)
18493 N->getOperand(1),
Undef);
18496 DAG.
getUNDEF(Src2.getValueType()));
18502 case Intrinsic::riscv_mulh_h0:
18503 case Intrinsic::riscv_mulh_h1:
18504 case Intrinsic::riscv_mulhsu_h0:
18505 case Intrinsic::riscv_mulhsu_h1: {
18508 MVT VT =
N->getSimpleValueType(0);
18509 MVT SrcVT =
N->getOperand(2).getSimpleValueType();
18510 if (Subtarget.hasStdExtP() && Subtarget.is64Bit() && VT == MVT::i32 &&
18511 SrcVT == MVT::v2i16) {
18517 N->getOperand(2),
Undef);
18519 MVT::v2i32, Rd, Rs1);
18524 "unsupported llvm.riscv multiply-high-parts intrinsic");
18526 case Intrinsic::riscv_macc_00:
18527 case Intrinsic::riscv_macc_01:
18528 case Intrinsic::riscv_macc_11:
18529 case Intrinsic::riscv_maccu_00:
18530 case Intrinsic::riscv_maccu_01:
18531 case Intrinsic::riscv_maccu_11:
18532 case Intrinsic::riscv_maccsu_00:
18533 case Intrinsic::riscv_maccsu_11: {
18536 MVT VT =
N->getSimpleValueType(0);
18537 MVT SrcVT =
N->getOperand(2).getSimpleValueType();
18538 if (Subtarget.hasStdExtP() && Subtarget.is64Bit() && VT == MVT::i32 &&
18539 SrcVT == MVT::v2i16) {
18545 N->getOperand(2),
Undef);
18547 N->getOperand(3),
Undef);
18549 MVT::v2i32, Rd, Rs1, Rs2);
18553 if (Subtarget.hasStdExtP() && !Subtarget.is64Bit() && VT == MVT::i64 &&
18554 SrcVT == MVT::v2i32) {
18555 auto [
Opc, Rs1Lane, Rs2Lane] =
18557 auto [RdLo, RdHi] =
18564 RdLo, RdHi, Rs1, Rs2);
18571 case Intrinsic::riscv_paadd:
18572 case Intrinsic::riscv_paaddu:
18573 case Intrinsic::riscv_pasub:
18574 case Intrinsic::riscv_pasubu:
18575 case Intrinsic::riscv_pabd:
18576 case Intrinsic::riscv_pabdu:
18577 case Intrinsic::riscv_pas:
18578 case Intrinsic::riscv_psa:
18579 case Intrinsic::riscv_psas:
18580 case Intrinsic::riscv_pssa:
18581 case Intrinsic::riscv_paas:
18582 case Intrinsic::riscv_pasa:
18583 case Intrinsic::riscv_pmerge:
18584 case Intrinsic::riscv_pmulq:
18585 case Intrinsic::riscv_pmulqr:
18586 case Intrinsic::riscv_pmulhr:
18587 case Intrinsic::riscv_pmulhru:
18588 case Intrinsic::riscv_pmulhsu:
18589 case Intrinsic::riscv_pmulhrsu:
18590 case Intrinsic::riscv_psabs:
18591 case Intrinsic::riscv_psati:
18592 case Intrinsic::riscv_pusati: {
18593 EVT VT =
N->getValueType(0);
18594 if (!Subtarget.is64Bit() || (VT != MVT::v4i8 && VT != MVT::v2i16))
18599 case Intrinsic::riscv_paadd:
18602 case Intrinsic::riscv_paaddu:
18605 case Intrinsic::riscv_pasub:
18608 case Intrinsic::riscv_pasubu:
18611 case Intrinsic::riscv_pabd:
18614 case Intrinsic::riscv_pabdu:
18617 case Intrinsic::riscv_psabs:
18618 Opc = RISCVISD::PSABS;
18620 case Intrinsic::riscv_pmulq:
18621 Opc = RISCVISD::MULQ;
18623 case Intrinsic::riscv_pmulqr:
18624 Opc = RISCVISD::MULQR;
18626 case Intrinsic::riscv_pmulhr:
18627 case Intrinsic::riscv_pmulhru:
18628 case Intrinsic::riscv_pmulhsu:
18629 case Intrinsic::riscv_pmulhrsu:
18632 case Intrinsic::riscv_psati:
18633 Opc = RISCVISD::SATI;
18635 case Intrinsic::riscv_pusati:
18636 Opc = RISCVISD::USATI;
18638 case Intrinsic::riscv_pmerge:
18639 Opc = RISCVISD::MERGE;
18648 EVT WideVT = VT == MVT::v4i8 ? MVT::v8i8 : MVT::v4i16;
18652 if (
Op.getValueType() == VT)
18658 }
else if (
Opc == RISCVISD::SATI ||
Opc == RISCVISD::USATI) {
18660 Subtarget.getXLenVT());
18662 }
else if (
Opc == RISCVISD::MERGE) {
18671 case Intrinsic::riscv_mseq_u32:
18672 case Intrinsic::riscv_mslt_i32:
18673 case Intrinsic::riscv_msltu_u32: {
18674 if (!Subtarget.is64Bit() ||
N->getValueType(0) != MVT::i32)
18678 case Intrinsic::riscv_mseq_u32:
18681 case Intrinsic::riscv_mslt_i32:
18684 case Intrinsic::riscv_msltu_u32:
18698 case Intrinsic::riscv_aadd_i32:
18699 case Intrinsic::riscv_aaddu_u32:
18700 case Intrinsic::riscv_asub_i32:
18701 case Intrinsic::riscv_asubu_u32:
18702 case Intrinsic::riscv_ssh1sadd_i32:
18703 case Intrinsic::riscv_mulhr_i32:
18704 case Intrinsic::riscv_mulhru_u32:
18705 case Intrinsic::riscv_mulhsu_i32:
18706 case Intrinsic::riscv_mulhrsu_i32:
18707 case Intrinsic::riscv_mulq_i32:
18708 case Intrinsic::riscv_mulqr_i32:
18709 case Intrinsic::riscv_mhacc_i32:
18710 case Intrinsic::riscv_mhracc_i32:
18711 case Intrinsic::riscv_mhaccu_u32:
18712 case Intrinsic::riscv_mhraccu_u32:
18713 case Intrinsic::riscv_mhaccsu_i32:
18714 case Intrinsic::riscv_mhraccsu_i32: {
18718 assert(Subtarget.is64Bit() &&
N->getValueType(0) == MVT::i32 &&
18719 "Unexpected subtarget or result type");
18728 case Intrinsic::riscv_sati:
18729 case Intrinsic::riscv_usati: {
18731 if (!Subtarget.is64Bit() ||
N->getValueType(0) != MVT::i32)
18734 IntNo == Intrinsic::riscv_sati ? RISCVISD::SATI : RISCVISD::USATI;
18738 Opc,
DL, MVT::i64, Rs1,
18743 case Intrinsic::riscv_nclipu_u32:
18744 case Intrinsic::riscv_nclipru_u32:
18745 case Intrinsic::riscv_nsrar_i32:
18746 case Intrinsic::riscv_nclip_i32:
18747 case Intrinsic::riscv_nclipr_i32: {
18748 if (!Subtarget.is64Bit() ||
N->getValueType(0) != MVT::i32)
18754 bool IsSigned = IntNo == Intrinsic::riscv_nsrar_i32 ||
18755 IntNo == Intrinsic::riscv_nclip_i32 ||
18756 IntNo == Intrinsic::riscv_nclipr_i32;
18757 bool IsRounding = IntNo == Intrinsic::riscv_nclipru_u32 ||
18758 IntNo == Intrinsic::riscv_nsrar_i32 ||
18759 IntNo == Intrinsic::riscv_nclipr_i32;
18764 ShiftOpc = IsSigned ? RISCVISD::SHAR : RISCVISD::SHLR;
18770 if (IntNo == Intrinsic::riscv_nsrar_i32) {
18776 unsigned ClipOpc = IsSigned ? RISCVISD::PNCLIPP : RISCVISD::PNCLIPUP;
18781 case Intrinsic::riscv_mqwacc_i64:
18782 case Intrinsic::riscv_mqrwacc_i64: {
18783 if (Subtarget.is64Bit())
18785 unsigned Opc = IntNo == Intrinsic::riscv_mqwacc_i64 ? RISCVISD::MQWACC
18786 : RISCVISD::MQRWACC;
18787 auto [RdLo, RdHi] =
18791 {RdLo, RdHi, N->getOperand(2), N->getOperand(3)});
18796 case Intrinsic::riscv_pnclipp:
18797 case Intrinsic::riscv_pnclipup: {
18798 bool IsSigned = IntNo == Intrinsic::riscv_pnclipp;
18799 EVT VT =
N->getValueType(0);
18800 if (!Subtarget.is64Bit() || (VT != MVT::v4i8 && VT != MVT::v2i16))
18802 unsigned Opc = IsSigned ? RISCVISD::PNCLIPP : RISCVISD::PNCLIPUP;
18805 if (VT == MVT::v4i8) {
18806 MVT WideSrcVT = MVT::v4i16;
18812 MVT WideSrcVT = MVT::v2i32;
18820 case Intrinsic::riscv_psll:
18821 case Intrinsic::riscv_psrl:
18822 case Intrinsic::riscv_psra:
18823 case Intrinsic::riscv_pssha:
18824 case Intrinsic::riscv_psshar:
18825 case Intrinsic::riscv_psshl:
18826 case Intrinsic::riscv_psshlr: {
18827 MVT VT =
N->getSimpleValueType(0);
18828 if (!Subtarget.is64Bit() || (VT != MVT::v4i8 && VT != MVT::v2i16))
18831 EVT WideVT = VT == MVT::v4i8 ? MVT::v8i8 : MVT::v4i16;
18841 case Intrinsic::riscv_pnsrl:
18842 case Intrinsic::riscv_pnsra:
18843 case Intrinsic::riscv_pnsrar: {
18844 MVT VT =
N->getSimpleValueType(0);
18845 if (!Subtarget.is64Bit() || (VT != MVT::v4i8 && VT != MVT::v2i16))
18849 MVT SrcVT = Src.getSimpleValueType();
18850 if (!((VT == MVT::v4i8 && SrcVT == MVT::v4i16) ||
18851 (VT == MVT::v2i16 && SrcVT == MVT::v2i32)))
18854 MVT XLenVT = Subtarget.getXLenVT();
18861 case Intrinsic::riscv_pnsrl:
18862 Opc = RISCVISD::PSRL;
18864 case Intrinsic::riscv_pnsra:
18865 Opc = RISCVISD::PSRA;
18867 case Intrinsic::riscv_pnsrar:
18868 Opc = RISCVISD::PSSHAR;
18876 MVT UnzipVT = VT == MVT::v4i8 ? MVT::v8i8 : MVT::v4i16;
18883 case Intrinsic::riscv_pnclipu:
18884 case Intrinsic::riscv_pnclipru:
18885 case Intrinsic::riscv_pnclip:
18886 case Intrinsic::riscv_pnclipr: {
18887 MVT VT =
N->getSimpleValueType(0);
18888 if (!Subtarget.is64Bit() || (VT != MVT::v4i8 && VT != MVT::v2i16))
18892 MVT SrcVT = Src.getSimpleValueType();
18893 if (!((VT == MVT::v4i8 && SrcVT == MVT::v4i16) ||
18894 (VT == MVT::v2i16 && SrcVT == MVT::v2i32)))
18897 MVT XLenVT = Subtarget.getXLenVT();
18901 IntNo == Intrinsic::riscv_pnclip || IntNo == Intrinsic::riscv_pnclipr;
18902 bool IsRounding = IntNo == Intrinsic::riscv_pnclipru ||
18903 IntNo == Intrinsic::riscv_pnclipr;
18910 unsigned ShiftOpc = IsRounding
18911 ? (IsSigned ? RISCVISD::PSSHAR : RISCVISD::PSSHLR)
18912 : (IsSigned ? RISCVISD::PSRA : RISCVISD::PSRL);
18914 MVT WideVT = VT == MVT::v4i8 ? MVT::v8i8 : MVT::v4i16;
18916 unsigned ClipOpc = IsSigned ? RISCVISD::PNCLIPP : RISCVISD::PNCLIPUP;
18921 case Intrinsic::riscv_predsum:
18922 case Intrinsic::riscv_predsumu: {
18923 bool IsSigned = IntNo == Intrinsic::riscv_predsum;
18937 if (!Subtarget.is64Bit() &&
N->getValueType(0) == MVT::i64) {
18940 if (VecVT == MVT::v2i32) {
18956 if (!Subtarget.is64Bit() ||
N->getValueType(0) != MVT::i32)
18960 if (VecVT == MVT::v4i8 || VecVT == MVT::v2i16)
18962 DAG,
DL, Vec, VecVT == MVT::v4i8 ? MVT::v8i8 : MVT::v4i16);
18968 SDValue Res = RedSum(MVT::i64, Vec, Acc);
18972 case Intrinsic::riscv_pabdsumu:
18973 case Intrinsic::riscv_pabdsumau: {
18974 bool IsAcc = IntNo == Intrinsic::riscv_pabdsumau;
18976 SDValue Rs1 =
N->getOperand(
N->getNumOperands() - 2);
18977 SDValue Rs2 =
N->getOperand(
N->getNumOperands() - 1);
18982 if (!Subtarget.is64Bit() &&
N->getValueType(0) == MVT::i64) {
19007 if (!Subtarget.is64Bit() ||
N->getValueType(0) != MVT::i32)
19009 if (VecVT == MVT::v4i8) {
19017 Ops.push_back(Rs1);
19018 Ops.push_back(Rs2);
19023 case Intrinsic::riscv_mqacc_00:
19024 case Intrinsic::riscv_mqacc_01:
19025 case Intrinsic::riscv_mqacc_11:
19026 case Intrinsic::riscv_mqracc_00:
19027 case Intrinsic::riscv_mqracc_01:
19028 case Intrinsic::riscv_mqracc_11: {
19029 EVT VT =
N->getValueType(0);
19030 if (Subtarget.is64Bit() && VT == MVT::i32) {
19033 auto WidenSrc = [&](
SDValue V) {
19037 SDValue Rs1 = WidenSrc(
N->getOperand(2));
19038 SDValue Rs2 = WidenSrc(
N->getOperand(3));
19045 if (!Subtarget.is64Bit() && VT == MVT::i64) {
19046 bool IsRound = IntNo == Intrinsic::riscv_mqracc_00 ||
19047 IntNo == Intrinsic::riscv_mqracc_01 ||
19048 IntNo == Intrinsic::riscv_mqracc_11;
19049 bool Hi1 = IntNo == Intrinsic::riscv_mqacc_11 ||
19050 IntNo == Intrinsic::riscv_mqracc_11;
19051 bool Hi2 = IntNo == Intrinsic::riscv_mqacc_01 ||
19052 IntNo == Intrinsic::riscv_mqacc_11 ||
19053 IntNo == Intrinsic::riscv_mqracc_01 ||
19054 IntNo == Intrinsic::riscv_mqracc_11;
19055 MVT XLenVT = Subtarget.getXLenVT();
19060 auto [RdLo, RdHi] =
19062 unsigned Opc = IsRound ? RISCVISD::MQRWACC : RISCVISD::MQWACC;
19071 case Intrinsic::riscv_orc_b:
19072 case Intrinsic::riscv_brev8:
19073 case Intrinsic::riscv_sha256sig0:
19074 case Intrinsic::riscv_sha256sig1:
19075 case Intrinsic::riscv_sha256sum0:
19076 case Intrinsic::riscv_sha256sum1:
19077 case Intrinsic::riscv_sm3p0:
19078 case Intrinsic::riscv_sm3p1: {
19079 if (!Subtarget.is64Bit() ||
N->getValueType(0) != MVT::i32)
19083 case Intrinsic::riscv_orc_b:
Opc = RISCVISD::ORC_B;
break;
19084 case Intrinsic::riscv_brev8:
Opc = RISCVISD::BREV8;
break;
19085 case Intrinsic::riscv_sha256sig0:
Opc = RISCVISD::SHA256SIG0;
break;
19086 case Intrinsic::riscv_sha256sig1:
Opc = RISCVISD::SHA256SIG1;
break;
19087 case Intrinsic::riscv_sha256sum0:
Opc = RISCVISD::SHA256SUM0;
break;
19088 case Intrinsic::riscv_sha256sum1:
Opc = RISCVISD::SHA256SUM1;
break;
19089 case Intrinsic::riscv_sm3p0:
Opc = RISCVISD::SM3P0;
break;
19090 case Intrinsic::riscv_sm3p1:
Opc = RISCVISD::SM3P1;
break;
19099 case Intrinsic::riscv_sm4ks:
19100 case Intrinsic::riscv_sm4ed: {
19102 IntNo == Intrinsic::riscv_sm4ks ? RISCVISD::SM4KS : RISCVISD::SM4ED;
19108 DAG.
getNode(
Opc,
DL, MVT::i64, NewOp0, NewOp1,
N->getOperand(3));
19112 case Intrinsic::riscv_mopr: {
19113 if (!Subtarget.is64Bit() ||
N->getValueType(0) != MVT::i32)
19118 RISCVISD::MOP_R,
DL, MVT::i64, NewOp,
19123 case Intrinsic::riscv_moprr: {
19124 if (!Subtarget.is64Bit() ||
N->getValueType(0) != MVT::i32)
19131 RISCVISD::MOP_RR,
DL, MVT::i64, NewOp0, NewOp1,
19136 case Intrinsic::riscv_clmulh:
19137 case Intrinsic::riscv_clmulr: {
19138 if (!Subtarget.is64Bit() ||
N->getValueType(0) != MVT::i32)
19146 unsigned ShAmt = IntNo == Intrinsic::riscv_clmulh ? 32 : 31;
19153 case Intrinsic::riscv_vmv_x_s: {
19154 EVT VT =
N->getValueType(0);
19155 MVT XLenVT = Subtarget.getXLenVT();
19156 if (VT.
bitsLT(XLenVT)) {
19159 Subtarget.getXLenVT(),
N->getOperand(1));
19164 assert(VT == MVT::i64 && !Subtarget.is64Bit() &&
19165 "Unexpected custom legalization");
19181 SDValue LShr32 = DAG.
getNode(RISCVISD::SRL_VL,
DL, VecVT, Vec, ThirtyTwoV,
19203 case ISD::VP_REDUCE_ADD:
19204 case ISD::VP_REDUCE_AND:
19205 case ISD::VP_REDUCE_OR:
19206 case ISD::VP_REDUCE_XOR:
19207 case ISD::VP_REDUCE_SMAX:
19208 case ISD::VP_REDUCE_UMAX:
19209 case ISD::VP_REDUCE_SMIN:
19210 case ISD::VP_REDUCE_UMIN:
19278 const EVT VT =
N->getValueType(0);
19279 const unsigned Opc =
N->getOpcode();
19289 if (!
N->getFlags().hasAllowReassociation())
19300 "Inconsistent mappings");
19304 if (!
LHS.hasOneUse() || !
RHS.hasOneUse())
19333 if (0 == std::min(LHSIdx, RHSIdx) && 1 == std::max(LHSIdx, RHSIdx)) {
19336 return DAG.
getNode(ReduceOpc,
DL, VT, Vec,
N->getFlags());
19343 if (
LHS.getOpcode() != ReduceOpc)
19357 return DAG.
getNode(ReduceOpc,
DL, VT, Vec,
19358 ReduceVec->
getFlags() &
N->getFlags());
19368 auto BinOpToRVVReduce = [](
unsigned Opc) {
19373 return RISCVISD::VECREDUCE_ADD_VL;
19375 return RISCVISD::VECREDUCE_UMAX_VL;
19377 return RISCVISD::VECREDUCE_SMAX_VL;
19379 return RISCVISD::VECREDUCE_UMIN_VL;
19381 return RISCVISD::VECREDUCE_SMIN_VL;
19383 return RISCVISD::VECREDUCE_AND_VL;
19385 return RISCVISD::VECREDUCE_OR_VL;
19387 return RISCVISD::VECREDUCE_XOR_VL;
19389 return RISCVISD::VECREDUCE_FADD_VL;
19391 return RISCVISD::VECREDUCE_FMAX_VL;
19393 return RISCVISD::VECREDUCE_FMIN_VL;
19397 auto IsReduction = [&BinOpToRVVReduce](
SDValue V,
unsigned Opc) {
19400 V.getOperand(0).getOpcode() == BinOpToRVVReduce(
Opc);
19403 unsigned Opc =
N->getOpcode();
19404 unsigned ReduceIdx;
19405 if (IsReduction(
N->getOperand(0),
Opc))
19407 else if (IsReduction(
N->getOperand(1),
Opc))
19413 if (
Opc ==
ISD::FADD && !
N->getFlags().hasAllowReassociation())
19416 SDValue Extract =
N->getOperand(ReduceIdx);
19429 if (ScalarV.
getOpcode() != RISCVISD::VFMV_S_F_VL &&
19430 ScalarV.
getOpcode() != RISCVISD::VMV_S_X_VL &&
19431 ScalarV.
getOpcode() != RISCVISD::VMV_V_X_VL)
19448 SDValue NewStart =
N->getOperand(1 - ReduceIdx);
19481 EVT VT =
N->getValueType(0);
19497 int64_t
C0 = N0C->getSExtValue();
19498 int64_t
C1 = N1C->getSExtValue();
19499 if (
C0 <= 0 ||
C1 <= 0)
19502 int64_t Diff = std::abs(
C0 -
C1);
19508 int64_t Bits = std::min(
C0,
C1);
19540 if (VShift.
slt(1) || VShift.
sgt(3))
19544 EVT VT =
N->getValueType(0);
19564 EVT VT =
N->getValueType(0);
19592 EVT VT =
N->getValueType(0);
19598 if (!
Subtarget.hasConditionalMoveFusion()) {
19613 Slct.
getOpcode() != RISCVISD::SELECT_CC) ||
19621 bool SwapSelectOps;
19622 unsigned OpOffset = Slct.
getOpcode() == RISCVISD::SELECT_CC ? 2 : 0;
19627 SwapSelectOps =
false;
19628 NonConstantVal = FalseVal;
19630 SwapSelectOps =
true;
19631 NonConstantVal = TrueVal;
19637 FalseVal = DAG.
getNode(
N->getOpcode(),
SDLoc(
N), VT, OtherOp, NonConstantVal);
19642 if (Slct.
getOpcode() == RISCVISD::SELECT_CC)
19685 EVT VT =
N->getValueType(0);
19700 if (!N0C->hasOneUse())
19702 int64_t
C0 = N0C->getSExtValue();
19703 int64_t
C1 = N1C->getSExtValue();
19710 if (
C0 == -1 ||
C0 == 0 ||
C0 == 1 ||
19711 Subtarget.getTargetLowering()->isLegalAddImmediate(
C1))
19742 EVT VT =
N->getValueType(0);
19749 if (!
N->hasOneUse())
19764 unsigned ExtOpc =
LHS.getOpcode();
19766 RHS.getOpcode() != ExtOpc || !
LHS.hasOneUse() || !
RHS.hasOneUse())
19800 EVT VT =
N->getValueType(0);
19820 EVT SrcVT = Src0.getValueType();
19830 Src0 = DAG.
getNode(N0Opc,
SDLoc(Src0), NarrowVT, Src0);
19831 Src1 = DAG.
getNode(N1Opc,
SDLoc(Src1), NarrowVT, Src1);
19836 unsigned OuterExtend = AnySExt ||
N->getOpcode() ==
ISD::SUB
19841 OuterExtend,
SDLoc(
N), VT,
19850 EVT VT =
N->getValueType(0);
19866 if (Z.getValueType().getScalarType() == MVT::i1)
19882 EVT VT =
N->getValueType(0);
19916 EVT VT =
N->getValueType(0);
19918 bool IsPExtPackedDoubleType =
19920 if (!
TLI.isOperationLegal(
ISD::MULHS, VT) && !IsPExtPackedDoubleType &&
19947 if (IsPExtPackedDoubleType) {
19952 if (HalfVT == MVT::v4i8) {
19953 ResLo = MakePWMulSU(XLo, CLo);
19954 ResHi = MakePWMulSU(XHi, CHi);
19956 ResLo = DAG.
getNode(RISCVISD::MULHSU,
DL, HalfVT, XLo, CLo);
19957 ResHi = DAG.
getNode(RISCVISD::MULHSU,
DL, HalfVT, XHi, CHi);
19984 for (
unsigned I = 0;
I != 2; ++
I) {
19996 N->getOperand(1 -
I),
Mul.getOperand(1),
19997 Mul.getOperand(2));
20006 N->getValueType(0) != MVT::v2i32)
20010 for (
unsigned I = 0;
I != 2; ++
I) {
20015 unsigned Opc =
Lo.getOpcode();
20016 if (
Opc !=
Hi.getOpcode() ||
20017 (
Opc != RISCVISD::PM4ADD &&
Opc != RISCVISD::PM4ADDU &&
20018 Opc != RISCVISD::PM4ADDSU))
20021 if (!
Lo.hasOneUse() && !
Hi.hasOneUse())
20042 unsigned Opcode =
N->getOpcode();
20046 EVT VT =
N->getValueType(0);
20047 if (VT != MVT::v4i16 && VT != MVT::v2i32)
20052 unsigned ExtendOpcode = N0.
getOpcode();
20060 MVT SrcVT = VT == MVT::v4i16 ? MVT::v4i8 : MVT::v2i16;
20061 MVT LegalSrcVT = VT == MVT::v4i16 ? MVT::v8i8 : MVT::v4i16;
20062 if (
A.getValueType() != SrcVT ||
B.getValueType() != SrcVT)
20065 if (VT == MVT::v4i16 && !IsSExt)
20068 bool IsPM2Halfword = VT == MVT::v2i32 && (IsSExt || Opcode ==
ISD::ADD);
20069 if (VT == MVT::v2i32 && !IsPM2Halfword)
20077 if (VT == MVT::v4i16) {
20088 unsigned Opc = Opcode ==
ISD::ADD ? RISCVISD::PM2ADD_H : RISCVISD::PM2SUB_H;
20093 return DAG.
getNode(RISCVISD::PM2ADDU_H,
DL, VT, Zip, Ones);
20108 EVT VT =
N->getValueType(0);
20109 if (VT != MVT::v4i16 && VT != MVT::v2i32)
20112 auto MatchExtend = [](
SDValue V,
unsigned ExtendOpcode,
MVT SrcVT,
20120 MVT SrcVT = VT == MVT::v4i16 ? MVT::v4i8 : MVT::v2i16;
20121 unsigned ExtendOpcode = Ext.
getOpcode();
20125 if (!MatchExtend(Ext, ExtendOpcode, SrcVT,
B))
20131 if (MatchExtend(
Add.getOperand(0), ExtendOpcode, SrcVT,
A))
20132 Acc =
Add.getOperand(1);
20133 else if (MatchExtend(
Add.getOperand(1), ExtendOpcode, SrcVT,
A))
20134 Acc =
Add.getOperand(0);
20138 if (Acc.getValueType() != VT)
20147 if (!Match(
N->getOperand(0),
N->getOperand(1), Acc,
A,
B, IsSExt) &&
20148 !Match(
N->getOperand(1),
N->getOperand(0), Acc,
A,
B, IsSExt))
20151 if (VT == MVT::v4i16 && !IsSExt)
20155 MVT LegalSrcVT = VT == MVT::v4i16 ? MVT::v8i8 : MVT::v4i16;
20156 MVT SrcVT = VT == MVT::v4i16 ? MVT::v4i8 : MVT::v2i16;
20161 if (VT == MVT::v4i16) {
20172 unsigned Opc = IsSExt ? RISCVISD::PM2ADDA_H : RISCVISD::PM2ADDAU_H;
20187 EVT VT =
N->getValueType(0);
20188 if (VT != MVT::v4i16 && VT != MVT::v2i32)
20191 MVT SrcVT = VT == MVT::v4i16 ? MVT::v4i8 : MVT::v2i16;
20200 Extend(ExtB,
B))) ||
20212 MVT LegalSrcVT = VT == MVT::v4i16 ? MVT::v8i8 : MVT::v4i16;
20217 if (VT == MVT::v4i16) {
20228 return DAG.
getNode(RISCVISD::PM2SUBA_H,
DL, VT, Acc, Zip, Ones);