1//===- RISCVInstrInfoVVLPatterns.td - RVV VL patterns ------*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// This file contains the required infrastructure and VL patterns to
10/// support code generation for the standard 'V' (Vector) extension, version
11/// 0.10.  This version is still experimental as the 'V' extension hasn't been
12/// ratified yet.
13///
14/// This file is included from and depends upon RISCVInstrInfoVPseudos.td
15///
16/// Note: the patterns for RVV intrinsics are found in
17/// RISCVInstrInfoVPseudos.td.
18///
19//===----------------------------------------------------------------------===//
20
21//===----------------------------------------------------------------------===//
22// Helpers to define the VL patterns.
23//===----------------------------------------------------------------------===//
24
25def SDT_RISCVVLE_VL : SDTypeProfile<1, 2, [SDTCisVec<0>, SDTCisPtrTy<1>,
26                                           SDTCisVT<2, XLenVT>]>;
27def SDT_RISCVVSE_VL : SDTypeProfile<0, 3, [SDTCisVec<0>, SDTCisPtrTy<1>,
28                                           SDTCisVT<2, XLenVT>]>;
29
30def SDT_RISCVIntBinOp_VL : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
31                                                SDTCisSameAs<0, 2>,
32                                                SDTCisVec<0>, SDTCisInt<0>,
33                                                SDTCVecEltisVT<3, i1>,
34                                                SDTCisSameNumEltsAs<0, 3>,
35                                                SDTCisVT<4, XLenVT>]>;
36
37def SDT_RISCVFPUnOp_VL : SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>,
38                                              SDTCisVec<0>, SDTCisFP<0>,
39                                              SDTCVecEltisVT<2, i1>,
40                                              SDTCisSameNumEltsAs<0, 2>,
41                                              SDTCisVT<3, XLenVT>]>;
42def SDT_RISCVFPBinOp_VL : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
43                                               SDTCisSameAs<0, 2>,
44                                               SDTCisVec<0>, SDTCisFP<0>,
45                                               SDTCVecEltisVT<3, i1>,
46                                               SDTCisSameNumEltsAs<0, 3>,
47                                               SDTCisVT<4, XLenVT>]>;
48
49def riscv_vmv_v_x_vl : SDNode<"RISCVISD::VMV_V_X_VL",
50                              SDTypeProfile<1, 2, [SDTCisVec<0>, SDTCisInt<0>,
51                                                   SDTCisVT<1, XLenVT>,
52                                                   SDTCisVT<2, XLenVT>]>>;
53def riscv_vfmv_v_f_vl : SDNode<"RISCVISD::VFMV_V_F_VL",
54                               SDTypeProfile<1, 2, [SDTCisVec<0>, SDTCisFP<0>,
55                                                    SDTCisEltOfVec<1, 0>,
56                                                    SDTCisVT<2, XLenVT>]>>;
57def riscv_vmv_s_x_vl : SDNode<"RISCVISD::VMV_S_X_VL",
58                              SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>,
59                                                   SDTCisInt<0>,
60                                                   SDTCisVT<2, XLenVT>,
61                                                   SDTCisVT<3, XLenVT>]>>;
62def riscv_vfmv_s_f_vl : SDNode<"RISCVISD::VFMV_S_F_VL",
63                               SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>,
64                                                    SDTCisFP<0>,
65                                                    SDTCisEltOfVec<2, 0>,
66                                                    SDTCisVT<3, XLenVT>]>>;
67
68def riscv_vle_vl : SDNode<"RISCVISD::VLE_VL", SDT_RISCVVLE_VL,
69                          [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
70def riscv_vse_vl : SDNode<"RISCVISD::VSE_VL", SDT_RISCVVSE_VL,
71                          [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
72
73def riscv_add_vl   : SDNode<"RISCVISD::ADD_VL",   SDT_RISCVIntBinOp_VL, [SDNPCommutative]>;
74def riscv_sub_vl   : SDNode<"RISCVISD::SUB_VL",   SDT_RISCVIntBinOp_VL>;
75def riscv_mul_vl   : SDNode<"RISCVISD::MUL_VL",   SDT_RISCVIntBinOp_VL, [SDNPCommutative]>;
76def riscv_mulhs_vl : SDNode<"RISCVISD::MULHS_VL", SDT_RISCVIntBinOp_VL, [SDNPCommutative]>;
77def riscv_mulhu_vl : SDNode<"RISCVISD::MULHU_VL", SDT_RISCVIntBinOp_VL, [SDNPCommutative]>;
78def riscv_and_vl   : SDNode<"RISCVISD::AND_VL",   SDT_RISCVIntBinOp_VL, [SDNPCommutative]>;
79def riscv_or_vl    : SDNode<"RISCVISD::OR_VL",    SDT_RISCVIntBinOp_VL, [SDNPCommutative]>;
80def riscv_xor_vl   : SDNode<"RISCVISD::XOR_VL",   SDT_RISCVIntBinOp_VL, [SDNPCommutative]>;
81def riscv_sdiv_vl  : SDNode<"RISCVISD::SDIV_VL",  SDT_RISCVIntBinOp_VL>;
82def riscv_srem_vl  : SDNode<"RISCVISD::SREM_VL",  SDT_RISCVIntBinOp_VL>;
83def riscv_udiv_vl  : SDNode<"RISCVISD::UDIV_VL",  SDT_RISCVIntBinOp_VL>;
84def riscv_urem_vl  : SDNode<"RISCVISD::UREM_VL",  SDT_RISCVIntBinOp_VL>;
85def riscv_shl_vl   : SDNode<"RISCVISD::SHL_VL",   SDT_RISCVIntBinOp_VL>;
86def riscv_sra_vl   : SDNode<"RISCVISD::SRA_VL",   SDT_RISCVIntBinOp_VL>;
87def riscv_srl_vl   : SDNode<"RISCVISD::SRL_VL",   SDT_RISCVIntBinOp_VL>;
88def riscv_smin_vl  : SDNode<"RISCVISD::SMIN_VL",  SDT_RISCVIntBinOp_VL>;
89def riscv_smax_vl  : SDNode<"RISCVISD::SMAX_VL",  SDT_RISCVIntBinOp_VL>;
90def riscv_umin_vl  : SDNode<"RISCVISD::UMIN_VL",  SDT_RISCVIntBinOp_VL>;
91def riscv_umax_vl  : SDNode<"RISCVISD::UMAX_VL",  SDT_RISCVIntBinOp_VL>;
92def riscv_fadd_vl  : SDNode<"RISCVISD::FADD_VL",  SDT_RISCVFPBinOp_VL, [SDNPCommutative]>;
93def riscv_fsub_vl  : SDNode<"RISCVISD::FSUB_VL",  SDT_RISCVFPBinOp_VL>;
94def riscv_fmul_vl  : SDNode<"RISCVISD::FMUL_VL",  SDT_RISCVFPBinOp_VL, [SDNPCommutative]>;
95def riscv_fdiv_vl  : SDNode<"RISCVISD::FDIV_VL",  SDT_RISCVFPBinOp_VL>;
96def riscv_fneg_vl  : SDNode<"RISCVISD::FNEG_VL",  SDT_RISCVFPUnOp_VL>;
97def riscv_fabs_vl  : SDNode<"RISCVISD::FABS_VL",  SDT_RISCVFPUnOp_VL>;
98def riscv_fsqrt_vl : SDNode<"RISCVISD::FSQRT_VL", SDT_RISCVFPUnOp_VL>;
99def riscv_fcopysign_vl : SDNode<"RISCVISD::FCOPYSIGN_VL",  SDT_RISCVFPBinOp_VL>;
100def riscv_fminnum_vl   : SDNode<"RISCVISD::FMINNUM_VL",  SDT_RISCVFPBinOp_VL>;
101def riscv_fmaxnum_vl   : SDNode<"RISCVISD::FMAXNUM_VL",  SDT_RISCVFPBinOp_VL>;
102
103def SDT_RISCVVecFMA_VL : SDTypeProfile<1, 5, [SDTCisSameAs<0, 1>,
104                                              SDTCisSameAs<0, 2>,
105                                              SDTCisSameAs<0, 3>,
106                                              SDTCisVec<0>, SDTCisFP<0>,
107                                              SDTCVecEltisVT<4, i1>,
108                                              SDTCisSameNumEltsAs<0, 4>,
109                                              SDTCisVT<5, XLenVT>]>;
110def riscv_fma_vl : SDNode<"RISCVISD::FMA_VL", SDT_RISCVVecFMA_VL, [SDNPCommutative]>;
111
112def SDT_RISCVFPRoundOp_VL  : SDTypeProfile<1, 3, [
113  SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<0, 1>, SDTCisSameNumEltsAs<0, 1>,
114  SDTCVecEltisVT<2, i1>, SDTCisSameNumEltsAs<1, 2>, SDTCisVT<3, XLenVT>
115]>;
116def SDT_RISCVFPExtendOp_VL  : SDTypeProfile<1, 3, [
117  SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<1, 0>, SDTCisSameNumEltsAs<0, 1>,
118  SDTCVecEltisVT<2, i1>, SDTCisSameNumEltsAs<1, 2>, SDTCisVT<3, XLenVT>
119]>;
120
121def riscv_fpround_vl : SDNode<"RISCVISD::FP_ROUND_VL", SDT_RISCVFPRoundOp_VL>;
122def riscv_fpextend_vl : SDNode<"RISCVISD::FP_EXTEND_VL", SDT_RISCVFPExtendOp_VL>;
123def riscv_fncvt_rod_vl : SDNode<"RISCVISD::VFNCVT_ROD_VL", SDT_RISCVFPRoundOp_VL>;
124
125def SDT_RISCVFP2IOp_VL  : SDTypeProfile<1, 3, [
126  SDTCisInt<0>, SDTCisFP<1>, SDTCisSameNumEltsAs<0, 1>,
127  SDTCVecEltisVT<2, i1>, SDTCisSameNumEltsAs<1, 2>, SDTCisVT<3, XLenVT>
128]>;
129def SDT_RISCVI2FPOp_VL  : SDTypeProfile<1, 3, [
130  SDTCisFP<0>, SDTCisInt<1>, SDTCisSameNumEltsAs<0, 1>,
131  SDTCVecEltisVT<2, i1>, SDTCisSameNumEltsAs<1, 2>, SDTCisVT<3, XLenVT>
132]>;
133
134def riscv_fp_to_sint_vl : SDNode<"RISCVISD::FP_TO_SINT_VL", SDT_RISCVFP2IOp_VL>;
135def riscv_fp_to_uint_vl : SDNode<"RISCVISD::FP_TO_UINT_VL", SDT_RISCVFP2IOp_VL>;
136def riscv_sint_to_fp_vl : SDNode<"RISCVISD::SINT_TO_FP_VL", SDT_RISCVI2FPOp_VL>;
137def riscv_uint_to_fp_vl : SDNode<"RISCVISD::UINT_TO_FP_VL", SDT_RISCVI2FPOp_VL>;
138
139def riscv_setcc_vl : SDNode<"RISCVISD::SETCC_VL",
140                            SDTypeProfile<1, 5, [SDTCVecEltisVT<0, i1>,
141                                                 SDTCisVec<1>,
142                                                 SDTCisSameNumEltsAs<0, 1>,
143                                                 SDTCisSameAs<1, 2>,
144                                                 SDTCisVT<3, OtherVT>,
145                                                 SDTCisSameAs<0, 4>,
146                                                 SDTCisVT<5, XLenVT>]>>;
147
148def riscv_vrgather_vx_vl : SDNode<"RISCVISD::VRGATHER_VX_VL",
149                                  SDTypeProfile<1, 4, [SDTCisVec<0>,
150                                                       SDTCisSameAs<0, 1>,
151                                                       SDTCisVT<2, XLenVT>,
152                                                       SDTCVecEltisVT<3, i1>,
153                                                       SDTCisSameNumEltsAs<0, 3>,
154                                                       SDTCisVT<4, XLenVT>]>>;
155def riscv_vrgather_vv_vl : SDNode<"RISCVISD::VRGATHER_VV_VL",
156                                  SDTypeProfile<1, 4, [SDTCisVec<0>,
157                                                       SDTCisSameAs<0, 1>,
158                                                       SDTCisInt<2>,
159                                                       SDTCisSameNumEltsAs<0, 2>,
160                                                       SDTCisSameSizeAs<0, 2>,
161                                                       SDTCVecEltisVT<3, i1>,
162                                                       SDTCisSameNumEltsAs<0, 3>,
163                                                       SDTCisVT<4, XLenVT>]>>;
164def riscv_vrgatherei16_vv_vl : SDNode<"RISCVISD::VRGATHEREI16_VV_VL",
165                                      SDTypeProfile<1, 4, [SDTCisVec<0>,
166                                                           SDTCisSameAs<0, 1>,
167                                                           SDTCisInt<2>,
168                                                           SDTCVecEltisVT<2, i16>,
169                                                           SDTCisSameNumEltsAs<0, 2>,
170                                                           SDTCVecEltisVT<3, i1>,
171                                                           SDTCisSameNumEltsAs<0, 3>,
172                                                           SDTCisVT<4, XLenVT>]>>;
173
174def riscv_vselect_vl : SDNode<"RISCVISD::VSELECT_VL",
175                              SDTypeProfile<1, 4, [SDTCisVec<0>,
176                                                   SDTCisVec<1>,
177                                                   SDTCisSameNumEltsAs<0, 1>,
178                                                   SDTCVecEltisVT<1, i1>,
179                                                   SDTCisSameAs<0, 2>,
180                                                   SDTCisSameAs<2, 3>,
181                                                   SDTCisVT<4, XLenVT>]>>;
182
183def SDT_RISCVMaskBinOp_VL : SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>,
184                                                 SDTCisSameAs<0, 2>,
185                                                 SDTCVecEltisVT<0, i1>,
186                                                 SDTCisVT<3, XLenVT>]>;
187def riscv_vmand_vl : SDNode<"RISCVISD::VMAND_VL", SDT_RISCVMaskBinOp_VL, [SDNPCommutative]>;
188def riscv_vmor_vl  : SDNode<"RISCVISD::VMOR_VL",  SDT_RISCVMaskBinOp_VL, [SDNPCommutative]>;
189def riscv_vmxor_vl : SDNode<"RISCVISD::VMXOR_VL", SDT_RISCVMaskBinOp_VL, [SDNPCommutative]>;
190
191def true_mask : PatLeaf<(riscv_vmset_vl (XLenVT srcvalue))>;
192
193def riscv_vmnot_vl : PatFrag<(ops node:$rs, node:$vl),
194                             (riscv_vmxor_vl node:$rs, true_mask, node:$vl)>;
195
196def riscv_vpopc_vl : SDNode<"RISCVISD::VPOPC_VL",
197                            SDTypeProfile<1, 3, [SDTCisVT<0, XLenVT>,
198                                                 SDTCisVec<1>, SDTCisInt<1>,
199                                                 SDTCVecEltisVT<2, i1>,
200                                                 SDTCisSameNumEltsAs<1, 2>,
201                                                 SDTCisVT<3, XLenVT>]>>;
202
203def SDT_RISCVVEXTEND_VL : SDTypeProfile<1, 3, [SDTCisVec<0>,
204                                               SDTCisSameNumEltsAs<0, 1>,
205                                               SDTCisSameNumEltsAs<1, 2>,
206                                               SDTCVecEltisVT<2, i1>,
207                                               SDTCisVT<3, XLenVT>]>;
208def riscv_sext_vl : SDNode<"RISCVISD::VSEXT_VL", SDT_RISCVVEXTEND_VL>;
209def riscv_zext_vl : SDNode<"RISCVISD::VZEXT_VL", SDT_RISCVVEXTEND_VL>;
210
211def riscv_trunc_vector_vl : SDNode<"RISCVISD::TRUNCATE_VECTOR_VL",
212                                   SDTypeProfile<1, 3, [SDTCisVec<0>,
213                                                        SDTCisVec<1>,
214                                                        SDTCisSameNumEltsAs<0, 2>,
215                                                        SDTCVecEltisVT<2, i1>,
216                                                        SDTCisVT<3, XLenVT>]>>;
217
218def SDTRVVVecReduce : SDTypeProfile<1, 4, [
219  SDTCisVec<0>, SDTCisVec<1>, SDTCisSameAs<0, 2>, SDTCVecEltisVT<3, i1>,
220  SDTCisSameNumEltsAs<1, 3>, SDTCisVT<4, XLenVT>
221]>;
222
223foreach kind = ["ADD", "UMAX", "SMAX", "UMIN", "SMIN", "AND", "OR", "XOR",
224                "FADD", "SEQ_FADD", "FMIN", "FMAX"] in
225  def rvv_vecreduce_#kind#_vl : SDNode<"RISCVISD::VECREDUCE_"#kind#"_VL", SDTRVVVecReduce>;
226
227// Ignore the vl operand.
228def SplatFPOp : PatFrag<(ops node:$op),
229                        (riscv_vfmv_v_f_vl node:$op, srcvalue)>;
230
231def sew8simm5  : ComplexPattern<XLenVT, 1, "selectRVVSimm5<8>",  []>;
232def sew16simm5 : ComplexPattern<XLenVT, 1, "selectRVVSimm5<16>", []>;
233def sew32simm5 : ComplexPattern<XLenVT, 1, "selectRVVSimm5<32>", []>;
234def sew64simm5 : ComplexPattern<XLenVT, 1, "selectRVVSimm5<64>", []>;
235
236def sew8uimm5  : ComplexPattern<XLenVT, 1, "selectRVVUimm5<8>",  []>;
237def sew16uimm5 : ComplexPattern<XLenVT, 1, "selectRVVUimm5<16>", []>;
238def sew32uimm5 : ComplexPattern<XLenVT, 1, "selectRVVUimm5<32>", []>;
239def sew64uimm5 : ComplexPattern<XLenVT, 1, "selectRVVUimm5<64>", []>;
240
241multiclass VPatBinaryVL_VV<SDNode vop,
242                           string instruction_name,
243                           ValueType result_type,
244                           ValueType op_type,
245                           ValueType mask_type,
246                           int sew,
247                           LMULInfo vlmul,
248                           VReg RetClass,
249                           VReg op_reg_class> {
250  def : Pat<(result_type (vop
251                         (op_type op_reg_class:$rs1),
252                         (op_type op_reg_class:$rs2),
253                         (mask_type true_mask),
254                         VLOpFrag)),
255            (!cast<Instruction>(instruction_name#"_VV_"# vlmul.MX)
256                         op_reg_class:$rs1,
257                         op_reg_class:$rs2,
258                         GPR:$vl, sew)>;
259  def : Pat<(result_type (vop
260                         (op_type op_reg_class:$rs1),
261                         (op_type op_reg_class:$rs2),
262                         (mask_type VMV0:$vm),
263                         VLOpFrag)),
264        (!cast<Instruction>(instruction_name#"_VV_"# vlmul.MX#"_MASK")
265                     (op_type (IMPLICIT_DEF)),
266                     op_reg_class:$rs1,
267                     op_reg_class:$rs2,
268                     VMV0:$vm, GPR:$vl, sew)>;
269}
270
271multiclass VPatBinaryVL_XI<SDNode vop,
272                           string instruction_name,
273                           string suffix,
274                           ValueType result_type,
275                           ValueType vop_type,
276                           ValueType mask_type,
277                           int sew,
278                           LMULInfo vlmul,
279                           VReg RetClass,
280                           VReg vop_reg_class,
281                           ComplexPattern SplatPatKind,
282                           DAGOperand xop_kind> {
283  def : Pat<(result_type (vop
284                     (vop_type vop_reg_class:$rs1),
285                     (vop_type (SplatPatKind (XLenVT xop_kind:$rs2))),
286                     (mask_type true_mask),
287                     VLOpFrag)),
288        (!cast<Instruction>(instruction_name#_#suffix#_# vlmul.MX)
289                     vop_reg_class:$rs1,
290                     xop_kind:$rs2,
291                     GPR:$vl, sew)>;
292  def : Pat<(result_type (vop
293                     (vop_type vop_reg_class:$rs1),
294                     (vop_type (SplatPatKind (XLenVT xop_kind:$rs2))),
295                     (mask_type VMV0:$vm),
296                     VLOpFrag)),
297        (!cast<Instruction>(instruction_name#_#suffix#_# vlmul.MX#"_MASK")
298                     (vop_type (IMPLICIT_DEF)),
299                     vop_reg_class:$rs1,
300                     xop_kind:$rs2,
301                     VMV0:$vm, GPR:$vl, sew)>;
302}
303
304multiclass VPatBinaryVL_VV_VX<SDNode vop, string instruction_name> {
305  foreach vti = AllIntegerVectors in {
306    defm : VPatBinaryVL_VV<vop, instruction_name,
307                           vti.Vector, vti.Vector, vti.Mask, vti.Log2SEW,
308                           vti.LMul, vti.RegClass, vti.RegClass>;
309    defm : VPatBinaryVL_XI<vop, instruction_name, "VX",
310                           vti.Vector, vti.Vector, vti.Mask, vti.Log2SEW,
311                           vti.LMul, vti.RegClass, vti.RegClass,
312                           SplatPat, GPR>;
313  }
314}
315
316multiclass VPatBinaryVL_VV_VX_VI<SDNode vop, string instruction_name,
317                                 Operand ImmType = simm5> {
318  foreach vti = AllIntegerVectors in {
319    defm : VPatBinaryVL_VV<vop, instruction_name,
320                           vti.Vector, vti.Vector, vti.Mask, vti.Log2SEW,
321                           vti.LMul, vti.RegClass, vti.RegClass>;
322    defm : VPatBinaryVL_XI<vop, instruction_name, "VX",
323                           vti.Vector, vti.Vector, vti.Mask, vti.Log2SEW,
324                           vti.LMul, vti.RegClass, vti.RegClass,
325                           SplatPat, GPR>;
326    defm : VPatBinaryVL_XI<vop, instruction_name, "VI",
327                           vti.Vector, vti.Vector, vti.Mask, vti.Log2SEW,
328                           vti.LMul, vti.RegClass, vti.RegClass,
329                           !cast<ComplexPattern>(SplatPat#_#ImmType),
330                           ImmType>;
331  }
332}
333
334class VPatBinaryVL_VF<SDNode vop,
335                      string instruction_name,
336                      ValueType result_type,
337                      ValueType vop_type,
338                      ValueType mask_type,
339                      int sew,
340                      LMULInfo vlmul,
341                      VReg RetClass,
342                      VReg vop_reg_class,
343                      RegisterClass scalar_reg_class> :
344    Pat<(result_type (vop (vop_type vop_reg_class:$rs1),
345                          (vop_type (SplatFPOp scalar_reg_class:$rs2)),
346                          (mask_type true_mask),
347                          VLOpFrag)),
348        (!cast<Instruction>(instruction_name#"_"#vlmul.MX)
349                     vop_reg_class:$rs1,
350                     scalar_reg_class:$rs2,
351                     GPR:$vl, sew)>;
352
353multiclass VPatBinaryFPVL_VV_VF<SDNode vop, string instruction_name> {
354  foreach vti = AllFloatVectors in {
355    defm : VPatBinaryVL_VV<vop, instruction_name,
356                           vti.Vector, vti.Vector, vti.Mask, vti.Log2SEW,
357                           vti.LMul, vti.RegClass, vti.RegClass>;
358    def : VPatBinaryVL_VF<vop, instruction_name#"_V"#vti.ScalarSuffix,
359                          vti.Vector, vti.Vector, vti.Mask, vti.Log2SEW,
360                          vti.LMul, vti.RegClass, vti.RegClass,
361                          vti.ScalarRegClass>;
362  }
363}
364
365multiclass VPatBinaryFPVL_R_VF<SDNode vop, string instruction_name> {
366  foreach fvti = AllFloatVectors in
367    def : Pat<(fvti.Vector (vop (SplatFPOp fvti.ScalarRegClass:$rs2),
368                                fvti.RegClass:$rs1,
369                                (fvti.Mask true_mask),
370                                VLOpFrag)),
371              (!cast<Instruction>(instruction_name#"_V"#fvti.ScalarSuffix#"_"#fvti.LMul.MX)
372                           fvti.RegClass:$rs1, fvti.ScalarRegClass:$rs2,
373                           GPR:$vl, fvti.Log2SEW)>;
374}
375
376multiclass VPatIntegerSetCCVL_VV<VTypeInfo vti, string instruction_name,
377                                 CondCode cc> {
378  def : Pat<(vti.Mask (riscv_setcc_vl (vti.Vector vti.RegClass:$rs1),
379                                      vti.RegClass:$rs2, cc,
380                                      (vti.Mask true_mask),
381                                      VLOpFrag)),
382            (!cast<Instruction>(instruction_name#"_VV_"#vti.LMul.MX)
383                         vti.RegClass:$rs1, vti.RegClass:$rs2, GPR:$vl,
384                         vti.Log2SEW)>;
385}
386
387// Inherits from VPatIntegerSetCCVL_VV and adds a pattern with operands swapped.
388multiclass VPatIntegerSetCCVL_VV_Swappable<VTypeInfo vti, string instruction_name,
389                                           CondCode cc, CondCode invcc> :
390  VPatIntegerSetCCVL_VV<vti, instruction_name, cc> {
391  def : Pat<(vti.Mask (riscv_setcc_vl (vti.Vector vti.RegClass:$rs2),
392                                      vti.RegClass:$rs1, invcc,
393                                      (vti.Mask true_mask),
394                                      VLOpFrag)),
395            (!cast<Instruction>(instruction_name#"_VV_"#vti.LMul.MX)
396                         vti.RegClass:$rs1, vti.RegClass:$rs2, GPR:$vl,
397                         vti.Log2SEW)>;
398}
399
400multiclass VPatIntegerSetCCVL_VX_Swappable<VTypeInfo vti, string instruction_name,
401                                           CondCode cc, CondCode invcc> {
402  defvar instruction = !cast<Instruction>(instruction_name#"_VX_"#vti.LMul.MX);
403  def : Pat<(vti.Mask (riscv_setcc_vl (vti.Vector vti.RegClass:$rs1),
404                                      (SplatPat (XLenVT GPR:$rs2)), cc,
405                                      (vti.Mask true_mask),
406                                      VLOpFrag)),
407            (instruction vti.RegClass:$rs1, GPR:$rs2, GPR:$vl, vti.Log2SEW)>;
408  def : Pat<(vti.Mask (riscv_setcc_vl (SplatPat (XLenVT GPR:$rs2)),
409                                      (vti.Vector vti.RegClass:$rs1), invcc,
410                                      (vti.Mask true_mask),
411                                      VLOpFrag)),
412            (instruction vti.RegClass:$rs1, GPR:$rs2, GPR:$vl, vti.Log2SEW)>;
413}
414
415multiclass VPatIntegerSetCCVL_VI_Swappable<VTypeInfo vti, string instruction_name,
416                                           CondCode cc, CondCode invcc> {
417  defvar instruction = !cast<Instruction>(instruction_name#"_VI_"#vti.LMul.MX);
418  def : Pat<(vti.Mask (riscv_setcc_vl (vti.Vector vti.RegClass:$rs1),
419                                      (SplatPat_simm5 simm5:$rs2), cc,
420                                      (vti.Mask true_mask),
421                                      VLOpFrag)),
422            (instruction vti.RegClass:$rs1, XLenVT:$rs2, GPR:$vl, vti.Log2SEW)>;
423  def : Pat<(vti.Mask (riscv_setcc_vl (SplatPat_simm5 simm5:$rs2),
424                                      (vti.Vector vti.RegClass:$rs1), invcc,
425                                      (vti.Mask true_mask),
426                                      VLOpFrag)),
427            (instruction vti.RegClass:$rs1, simm5:$rs2, GPR:$vl, vti.Log2SEW)>;
428}
429
430multiclass VPatIntegerSetCCVL_VIPlus1<VTypeInfo vti, string instruction_name,
431                                      CondCode cc, ComplexPattern splatpat_kind> {
432  defvar instruction = !cast<Instruction>(instruction_name#"_VI_"#vti.LMul.MX);
433  def : Pat<(vti.Mask (riscv_setcc_vl (vti.Vector vti.RegClass:$rs1),
434                                      (splatpat_kind simm5:$rs2), cc,
435                                      (vti.Mask true_mask),
436                                      VLOpFrag)),
437            (instruction vti.RegClass:$rs1, (DecImm simm5:$rs2),
438                         GPR:$vl, vti.Log2SEW)>;
439}
440
441multiclass VPatFPSetCCVL_VV_VF_FV<CondCode cc,
442                                  string inst_name,
443                                  string swapped_op_inst_name> {
444  foreach fvti = AllFloatVectors in {
445    def : Pat<(fvti.Mask (riscv_setcc_vl (fvti.Vector fvti.RegClass:$rs1),
446                                         fvti.RegClass:$rs2,
447                                         cc,
448                                         (fvti.Mask true_mask),
449                                         VLOpFrag)),
450              (!cast<Instruction>(inst_name#"_VV_"#fvti.LMul.MX)
451                  fvti.RegClass:$rs1, fvti.RegClass:$rs2, GPR:$vl, fvti.Log2SEW)>;
452    def : Pat<(fvti.Mask (riscv_setcc_vl (fvti.Vector fvti.RegClass:$rs1),
453                                         (SplatFPOp fvti.ScalarRegClass:$rs2),
454                                         cc,
455                                         (fvti.Mask true_mask),
456                                         VLOpFrag)),
457              (!cast<Instruction>(inst_name#"_V"#fvti.ScalarSuffix#"_"#fvti.LMul.MX)
458                  fvti.RegClass:$rs1, fvti.ScalarRegClass:$rs2,
459                  GPR:$vl, fvti.Log2SEW)>;
460    def : Pat<(fvti.Mask (riscv_setcc_vl (SplatFPOp fvti.ScalarRegClass:$rs2),
461                                         (fvti.Vector fvti.RegClass:$rs1),
462                                         cc,
463                                         (fvti.Mask true_mask),
464                                         VLOpFrag)),
465              (!cast<Instruction>(swapped_op_inst_name#"_V"#fvti.ScalarSuffix#"_"#fvti.LMul.MX)
466                  fvti.RegClass:$rs1, fvti.ScalarRegClass:$rs2,
467                  GPR:$vl, fvti.Log2SEW)>;
468  }
469}
470
471multiclass VPatExtendSDNode_V_VL<SDNode vop, string inst_name, string suffix,
472                                 list <VTypeInfoToFraction> fraction_list> {
473  foreach vtiTofti = fraction_list in {
474    defvar vti = vtiTofti.Vti;
475    defvar fti = vtiTofti.Fti;
476    def : Pat<(vti.Vector (vop (fti.Vector fti.RegClass:$rs2),
477                               true_mask, VLOpFrag)),
478              (!cast<Instruction>(inst_name#"_"#suffix#"_"#vti.LMul.MX)
479                  fti.RegClass:$rs2, GPR:$vl, vti.Log2SEW)>;
480  }
481}
482
483multiclass VPatConvertFP2ISDNode_V_VL<SDNode vop, string instruction_name> {
484  foreach fvti = AllFloatVectors in {
485    defvar ivti = GetIntVTypeInfo<fvti>.Vti;
486    def : Pat<(ivti.Vector (vop (fvti.Vector fvti.RegClass:$rs1),
487                                (fvti.Mask true_mask),
488                                VLOpFrag)),
489              (!cast<Instruction>(instruction_name#"_"#ivti.LMul.MX)
490                  fvti.RegClass:$rs1, GPR:$vl, ivti.Log2SEW)>;
491  }
492}
493
494multiclass VPatConvertI2FPSDNode_V_VL<SDNode vop, string instruction_name> {
495  foreach fvti = AllFloatVectors in {
496    defvar ivti = GetIntVTypeInfo<fvti>.Vti;
497    def : Pat<(fvti.Vector (vop (ivti.Vector ivti.RegClass:$rs1),
498                                (ivti.Mask true_mask),
499                                VLOpFrag)),
500              (!cast<Instruction>(instruction_name#"_"#fvti.LMul.MX)
501                  ivti.RegClass:$rs1, GPR:$vl, fvti.Log2SEW)>;
502  }
503}
504
505multiclass VPatWConvertFP2ISDNode_V_VL<SDNode vop, string instruction_name> {
506  foreach fvtiToFWti = AllWidenableFloatVectors in {
507    defvar fvti = fvtiToFWti.Vti;
508    defvar iwti = GetIntVTypeInfo<fvtiToFWti.Wti>.Vti;
509    def : Pat<(iwti.Vector (vop (fvti.Vector fvti.RegClass:$rs1),
510                                (fvti.Mask true_mask),
511                                VLOpFrag)),
512              (!cast<Instruction>(instruction_name#"_"#fvti.LMul.MX)
513                  fvti.RegClass:$rs1, GPR:$vl, fvti.Log2SEW)>;
514  }
515}
516
517multiclass VPatWConvertI2FPSDNode_V_VL<SDNode vop, string instruction_name> {
518  foreach vtiToWti = AllWidenableIntToFloatVectors in {
519    defvar ivti = vtiToWti.Vti;
520    defvar fwti = vtiToWti.Wti;
521    def : Pat<(fwti.Vector (vop (ivti.Vector ivti.RegClass:$rs1),
522                                (ivti.Mask true_mask),
523                                VLOpFrag)),
524              (!cast<Instruction>(instruction_name#"_"#ivti.LMul.MX)
525                  ivti.RegClass:$rs1, GPR:$vl, ivti.Log2SEW)>;
526  }
527}
528
529multiclass VPatNConvertFP2ISDNode_V_VL<SDNode vop, string instruction_name> {
530  foreach vtiToWti = AllWidenableIntToFloatVectors in {
531    defvar vti = vtiToWti.Vti;
532    defvar fwti = vtiToWti.Wti;
533    def : Pat<(vti.Vector (vop (fwti.Vector fwti.RegClass:$rs1),
534                               (fwti.Mask true_mask),
535                               VLOpFrag)),
536              (!cast<Instruction>(instruction_name#"_"#vti.LMul.MX)
537                  fwti.RegClass:$rs1, GPR:$vl, vti.Log2SEW)>;
538  }
539}
540
541multiclass VPatNConvertI2FPSDNode_V_VL<SDNode vop, string instruction_name> {
542  foreach fvtiToFWti = AllWidenableFloatVectors in {
543    defvar fvti = fvtiToFWti.Vti;
544    defvar iwti = GetIntVTypeInfo<fvtiToFWti.Wti>.Vti;
545    def : Pat<(fvti.Vector (vop (iwti.Vector iwti.RegClass:$rs1),
546                                (iwti.Mask true_mask),
547                                VLOpFrag)),
548              (!cast<Instruction>(instruction_name#"_"#fvti.LMul.MX)
549                  iwti.RegClass:$rs1, GPR:$vl, fvti.Log2SEW)>;
550  }
551}
552
553multiclass VPatReductionVL<SDNode vop, string instruction_name, bit is_float> {
554  foreach vti = !if(is_float, AllFloatVectors, AllIntegerVectors) in {
555    defvar vti_m1 = !cast<VTypeInfo>(!if(is_float, "VF", "VI") # vti.SEW # "M1");
556    def: Pat<(vti_m1.Vector (vop (vti.Vector vti.RegClass:$rs1), VR:$rs2,
557                                 (vti.Mask true_mask),
558                                 VLOpFrag)),
559        (!cast<Instruction>(instruction_name#"_VS_"#vti.LMul.MX)
560            (vti_m1.Vector (IMPLICIT_DEF)),
561            (vti.Vector vti.RegClass:$rs1),
562            (vti_m1.Vector VR:$rs2),
563            GPR:$vl, vti.Log2SEW)>;
564  }
565}
566
567//===----------------------------------------------------------------------===//
568// Patterns.
569//===----------------------------------------------------------------------===//
570
571let Predicates = [HasStdExtV] in {
572
573// 7.4. Vector Unit-Stride Instructions
574foreach vti = AllVectors in {
575  defvar load_instr = !cast<Instruction>("PseudoVLE"#vti.SEW#"_V_"#vti.LMul.MX);
576  defvar store_instr = !cast<Instruction>("PseudoVSE"#vti.SEW#"_V_"#vti.LMul.MX);
577  // Load
578  def : Pat<(vti.Vector (riscv_vle_vl BaseAddr:$rs1, VLOpFrag)),
579            (load_instr BaseAddr:$rs1, GPR:$vl, vti.Log2SEW)>;
580  // Store
581  def : Pat<(riscv_vse_vl (vti.Vector vti.RegClass:$rs2), BaseAddr:$rs1,
582                          VLOpFrag),
583            (store_instr vti.RegClass:$rs2, BaseAddr:$rs1, GPR:$vl, vti.Log2SEW)>;
584}
585
586foreach mti = AllMasks in {
587  defvar load_instr = !cast<Instruction>("PseudoVLE1_V_"#mti.BX);
588  defvar store_instr = !cast<Instruction>("PseudoVSE1_V_"#mti.BX);
589  def : Pat<(mti.Mask (riscv_vle_vl BaseAddr:$rs1, VLOpFrag)),
590            (load_instr BaseAddr:$rs1, GPR:$vl, mti.Log2SEW)>;
591  def : Pat<(riscv_vse_vl (mti.Mask VR:$rs2), BaseAddr:$rs1,
592                          VLOpFrag),
593            (store_instr VR:$rs2, BaseAddr:$rs1, GPR:$vl, mti.Log2SEW)>;
594}
595
596// 12.1. Vector Single-Width Integer Add and Subtract
597defm : VPatBinaryVL_VV_VX_VI<riscv_add_vl, "PseudoVADD">;
598defm : VPatBinaryVL_VV_VX<riscv_sub_vl, "PseudoVSUB">;
599// Handle VRSUB specially since it's the only integer binary op with reversed
600// pattern operands
601foreach vti = AllIntegerVectors in {
602  def : Pat<(riscv_sub_vl (vti.Vector (SplatPat (XLenVT GPR:$rs2))),
603                          (vti.Vector vti.RegClass:$rs1), (vti.Mask true_mask),
604                          VLOpFrag),
605            (!cast<Instruction>("PseudoVRSUB_VX_"# vti.LMul.MX)
606                 vti.RegClass:$rs1, GPR:$rs2, GPR:$vl, vti.Log2SEW)>;
607  def : Pat<(riscv_sub_vl (vti.Vector (SplatPat (XLenVT GPR:$rs2))),
608                          (vti.Vector vti.RegClass:$rs1), (vti.Mask VMV0:$vm),
609                          VLOpFrag),
610            (!cast<Instruction>("PseudoVRSUB_VX_"# vti.LMul.MX#"_MASK")
611                 (vti.Vector (IMPLICIT_DEF)), vti.RegClass:$rs1, GPR:$rs2,
612                 VMV0:$vm, GPR:$vl, vti.Log2SEW)>;
613  def : Pat<(riscv_sub_vl (vti.Vector (SplatPat_simm5 simm5:$rs2)),
614                          (vti.Vector vti.RegClass:$rs1), (vti.Mask true_mask),
615                          VLOpFrag),
616            (!cast<Instruction>("PseudoVRSUB_VI_"# vti.LMul.MX)
617                 vti.RegClass:$rs1, simm5:$rs2, GPR:$vl, vti.Log2SEW)>;
618  def : Pat<(riscv_sub_vl (vti.Vector (SplatPat_simm5 simm5:$rs2)),
619                          (vti.Vector vti.RegClass:$rs1), (vti.Mask VMV0:$vm),
620                          VLOpFrag),
621            (!cast<Instruction>("PseudoVRSUB_VI_"# vti.LMul.MX#"_MASK")
622                 (vti.Vector (IMPLICIT_DEF)), vti.RegClass:$rs1, simm5:$rs2,
623                 VMV0:$vm, GPR:$vl, vti.Log2SEW)>;
624}
625
626// 12.3. Vector Integer Extension
627defm : VPatExtendSDNode_V_VL<riscv_zext_vl, "PseudoVZEXT", "VF2",
628                             AllFractionableVF2IntVectors>;
629defm : VPatExtendSDNode_V_VL<riscv_sext_vl, "PseudoVSEXT", "VF2",
630                             AllFractionableVF2IntVectors>;
631defm : VPatExtendSDNode_V_VL<riscv_zext_vl, "PseudoVZEXT", "VF4",
632                             AllFractionableVF4IntVectors>;
633defm : VPatExtendSDNode_V_VL<riscv_sext_vl, "PseudoVSEXT", "VF4",
634                             AllFractionableVF4IntVectors>;
635defm : VPatExtendSDNode_V_VL<riscv_zext_vl, "PseudoVZEXT", "VF8",
636                             AllFractionableVF8IntVectors>;
637defm : VPatExtendSDNode_V_VL<riscv_sext_vl, "PseudoVSEXT", "VF8",
638                                AllFractionableVF8IntVectors>;
639
640// 12.5. Vector Bitwise Logical Instructions
641defm : VPatBinaryVL_VV_VX_VI<riscv_and_vl, "PseudoVAND">;
642defm : VPatBinaryVL_VV_VX_VI<riscv_or_vl,  "PseudoVOR">;
643defm : VPatBinaryVL_VV_VX_VI<riscv_xor_vl, "PseudoVXOR">;
644
645// 12.6. Vector Single-Width Bit Shift Instructions
646defm : VPatBinaryVL_VV_VX_VI<riscv_shl_vl, "PseudoVSLL", uimm5>;
647defm : VPatBinaryVL_VV_VX_VI<riscv_srl_vl, "PseudoVSRL", uimm5>;
648defm : VPatBinaryVL_VV_VX_VI<riscv_sra_vl, "PseudoVSRA", uimm5>;
649
650// 12.7. Vector Narrowing Integer Right Shift Instructions
651foreach vtiTofti = AllFractionableVF2IntVectors in {
652  defvar vti = vtiTofti.Vti;
653  defvar fti = vtiTofti.Fti;
654  def : Pat<(fti.Vector (riscv_trunc_vector_vl (vti.Vector vti.RegClass:$rs1),
655                                               (vti.Mask true_mask),
656                                               VLOpFrag)),
657            (!cast<Instruction>("PseudoVNSRL_WI_"#fti.LMul.MX)
658                vti.RegClass:$rs1, 0, GPR:$vl, fti.Log2SEW)>;
659}
660
661// 12.8. Vector Integer Comparison Instructions
662foreach vti = AllIntegerVectors in {
663  defm : VPatIntegerSetCCVL_VV<vti, "PseudoVMSEQ", SETEQ>;
664  defm : VPatIntegerSetCCVL_VV<vti, "PseudoVMSNE", SETNE>;
665
666  defm : VPatIntegerSetCCVL_VV_Swappable<vti, "PseudoVMSLT",  SETLT,  SETGT>;
667  defm : VPatIntegerSetCCVL_VV_Swappable<vti, "PseudoVMSLTU", SETULT, SETUGT>;
668  defm : VPatIntegerSetCCVL_VV_Swappable<vti, "PseudoVMSLE",  SETLE,  SETGE>;
669  defm : VPatIntegerSetCCVL_VV_Swappable<vti, "PseudoVMSLEU", SETULE, SETUGE>;
670
671  defm : VPatIntegerSetCCVL_VX_Swappable<vti, "PseudoVMSEQ",  SETEQ,  SETEQ>;
672  defm : VPatIntegerSetCCVL_VX_Swappable<vti, "PseudoVMSNE",  SETNE,  SETNE>;
673  defm : VPatIntegerSetCCVL_VX_Swappable<vti, "PseudoVMSLT",  SETLT,  SETGT>;
674  defm : VPatIntegerSetCCVL_VX_Swappable<vti, "PseudoVMSLTU", SETULT, SETUGT>;
675  defm : VPatIntegerSetCCVL_VX_Swappable<vti, "PseudoVMSLE",  SETLE,  SETGE>;
676  defm : VPatIntegerSetCCVL_VX_Swappable<vti, "PseudoVMSLEU", SETULE, SETUGE>;
677  defm : VPatIntegerSetCCVL_VX_Swappable<vti, "PseudoVMSGT",  SETGT,  SETLT>;
678  defm : VPatIntegerSetCCVL_VX_Swappable<vti, "PseudoVMSGTU", SETUGT, SETULT>;
679  // There is no VMSGE(U)_VX instruction
680
681  defm : VPatIntegerSetCCVL_VI_Swappable<vti, "PseudoVMSEQ",  SETEQ,  SETEQ>;
682  defm : VPatIntegerSetCCVL_VI_Swappable<vti, "PseudoVMSNE",  SETNE,  SETNE>;
683  defm : VPatIntegerSetCCVL_VI_Swappable<vti, "PseudoVMSLE",  SETLE,  SETGE>;
684  defm : VPatIntegerSetCCVL_VI_Swappable<vti, "PseudoVMSLEU", SETULE, SETUGE>;
685
686  defm : VPatIntegerSetCCVL_VIPlus1<vti, "PseudoVMSLE",  SETLT,
687                                    SplatPat_simm5_plus1>;
688  defm : VPatIntegerSetCCVL_VIPlus1<vti, "PseudoVMSLEU", SETULT,
689                                    SplatPat_simm5_plus1_nonzero>;
690  defm : VPatIntegerSetCCVL_VIPlus1<vti, "PseudoVMSGT",  SETGE,
691                                    SplatPat_simm5_plus1>;
692  defm : VPatIntegerSetCCVL_VIPlus1<vti, "PseudoVMSGTU", SETUGE,
693                                    SplatPat_simm5_plus1_nonzero>;
694} // foreach vti = AllIntegerVectors
695
696// 12.9. Vector Integer Min/Max Instructions
697defm : VPatBinaryVL_VV_VX<riscv_umin_vl, "PseudoVMINU">;
698defm : VPatBinaryVL_VV_VX<riscv_smin_vl, "PseudoVMIN">;
699defm : VPatBinaryVL_VV_VX<riscv_umax_vl, "PseudoVMAXU">;
700defm : VPatBinaryVL_VV_VX<riscv_smax_vl, "PseudoVMAX">;
701
702// 12.10. Vector Single-Width Integer Multiply Instructions
703defm : VPatBinaryVL_VV_VX<riscv_mul_vl, "PseudoVMUL">;
704defm : VPatBinaryVL_VV_VX<riscv_mulhs_vl, "PseudoVMULH">;
705defm : VPatBinaryVL_VV_VX<riscv_mulhu_vl, "PseudoVMULHU">;
706
707// 12.11. Vector Integer Divide Instructions
708defm : VPatBinaryVL_VV_VX<riscv_udiv_vl, "PseudoVDIVU">;
709defm : VPatBinaryVL_VV_VX<riscv_sdiv_vl, "PseudoVDIV">;
710defm : VPatBinaryVL_VV_VX<riscv_urem_vl, "PseudoVREMU">;
711defm : VPatBinaryVL_VV_VX<riscv_srem_vl, "PseudoVREM">;
712
713// 12.15. Vector Integer Merge Instructions
714foreach vti = AllIntegerVectors in {
715  def : Pat<(vti.Vector (riscv_vselect_vl (vti.Mask VMV0:$vm),
716                                          vti.RegClass:$rs1,
717                                          vti.RegClass:$rs2,
718                                          VLOpFrag)),
719            (!cast<Instruction>("PseudoVMERGE_VVM_"#vti.LMul.MX)
720                 vti.RegClass:$rs2, vti.RegClass:$rs1, VMV0:$vm,
721                 GPR:$vl, vti.Log2SEW)>;
722
723  def : Pat<(vti.Vector (riscv_vselect_vl (vti.Mask VMV0:$vm),
724                                          (SplatPat XLenVT:$rs1),
725                                          vti.RegClass:$rs2,
726                                          VLOpFrag)),
727            (!cast<Instruction>("PseudoVMERGE_VXM_"#vti.LMul.MX)
728                 vti.RegClass:$rs2, GPR:$rs1, VMV0:$vm, GPR:$vl, vti.Log2SEW)>;
729
730  def : Pat<(vti.Vector (riscv_vselect_vl (vti.Mask VMV0:$vm),
731                                          (SplatPat_simm5 simm5:$rs1),
732                                          vti.RegClass:$rs2,
733                                          VLOpFrag)),
734            (!cast<Instruction>("PseudoVMERGE_VIM_"#vti.LMul.MX)
735                 vti.RegClass:$rs2, simm5:$rs1, VMV0:$vm, GPR:$vl, vti.Log2SEW)>;
736}
737
738// 12.16. Vector Integer Move Instructions
739foreach vti = AllIntegerVectors in {
740  def : Pat<(vti.Vector (riscv_vmv_v_x_vl GPR:$rs2, VLOpFrag)),
741            (!cast<Instruction>("PseudoVMV_V_X_"#vti.LMul.MX)
742             $rs2, GPR:$vl, vti.Log2SEW)>;
743  defvar ImmPat = !cast<ComplexPattern>("sew"#vti.SEW#"simm5");
744  def : Pat<(vti.Vector (riscv_vmv_v_x_vl (ImmPat XLenVT:$imm5),
745                                          VLOpFrag)),
746            (!cast<Instruction>("PseudoVMV_V_I_"#vti.LMul.MX)
747             XLenVT:$imm5, GPR:$vl, vti.Log2SEW)>;
748}
749
750} // Predicates = [HasStdExtV]
751
752// 15.1. Vector Single-Width Integer Reduction Instructions
753let Predicates = [HasStdExtV] in {
754defm : VPatReductionVL<rvv_vecreduce_ADD_vl,  "PseudoVREDSUM", /*is_float*/0>;
755defm : VPatReductionVL<rvv_vecreduce_UMAX_vl, "PseudoVREDMAXU", /*is_float*/0>;
756defm : VPatReductionVL<rvv_vecreduce_SMAX_vl, "PseudoVREDMAX", /*is_float*/0>;
757defm : VPatReductionVL<rvv_vecreduce_UMIN_vl, "PseudoVREDMINU", /*is_float*/0>;
758defm : VPatReductionVL<rvv_vecreduce_SMIN_vl, "PseudoVREDMIN", /*is_float*/0>;
759defm : VPatReductionVL<rvv_vecreduce_AND_vl,  "PseudoVREDAND", /*is_float*/0>;
760defm : VPatReductionVL<rvv_vecreduce_OR_vl,   "PseudoVREDOR", /*is_float*/0>;
761defm : VPatReductionVL<rvv_vecreduce_XOR_vl,  "PseudoVREDXOR", /*is_float*/0>;
762} // Predicates = [HasStdExtV]
763
764// 15.3. Vector Single-Width Floating-Point Reduction Instructions
765let Predicates = [HasStdExtV, HasStdExtF] in {
766defm : VPatReductionVL<rvv_vecreduce_SEQ_FADD_vl, "PseudoVFREDOSUM", /*is_float*/1>;
767defm : VPatReductionVL<rvv_vecreduce_FADD_vl,     "PseudoVFREDSUM", /*is_float*/1>;
768defm : VPatReductionVL<rvv_vecreduce_FMIN_vl,     "PseudoVFREDMIN", /*is_float*/1>;
769defm : VPatReductionVL<rvv_vecreduce_FMAX_vl,     "PseudoVFREDMAX", /*is_float*/1>;
770} // Predicates = [HasStdExtV, HasStdExtF]
771
772let Predicates = [HasStdExtV, HasStdExtF] in {
773
774// 14.2. Vector Single-Width Floating-Point Add/Subtract Instructions
775defm : VPatBinaryFPVL_VV_VF<riscv_fadd_vl, "PseudoVFADD">;
776defm : VPatBinaryFPVL_VV_VF<riscv_fsub_vl, "PseudoVFSUB">;
777defm : VPatBinaryFPVL_R_VF<riscv_fsub_vl, "PseudoVFRSUB">;
778
779// 14.4. Vector Single-Width Floating-Point Multiply/Divide Instructions
780defm : VPatBinaryFPVL_VV_VF<riscv_fmul_vl, "PseudoVFMUL">;
781defm : VPatBinaryFPVL_VV_VF<riscv_fdiv_vl, "PseudoVFDIV">;
782defm : VPatBinaryFPVL_R_VF<riscv_fdiv_vl, "PseudoVFRDIV">;
783
784// 14.6 Vector Single-Width Floating-Point Fused Multiply-Add Instructions.
785foreach vti = AllFloatVectors in {
786  // NOTE: We choose VFMADD because it has the most commuting freedom. So it
787  // works best with how TwoAddressInstructionPass tries commuting.
788  defvar suffix = vti.LMul.MX # "_COMMUTABLE";
789  def : Pat<(vti.Vector (riscv_fma_vl vti.RegClass:$rs1, vti.RegClass:$rd,
790                                      vti.RegClass:$rs2, (vti.Mask true_mask),
791                                      VLOpFrag)),
792            (!cast<Instruction>("PseudoVFMADD_VV_"# suffix)
793                 vti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2,
794                 GPR:$vl, vti.Log2SEW)>;
795  def : Pat<(vti.Vector (riscv_fma_vl vti.RegClass:$rs1, vti.RegClass:$rd,
796                                      (riscv_fneg_vl vti.RegClass:$rs2,
797                                                     (vti.Mask true_mask),
798                                                     VLOpFrag),
799                                      (vti.Mask true_mask),
800                                      VLOpFrag)),
801            (!cast<Instruction>("PseudoVFMSUB_VV_"# suffix)
802                 vti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2,
803                 GPR:$vl, vti.Log2SEW)>;
804  def : Pat<(vti.Vector (riscv_fma_vl (riscv_fneg_vl vti.RegClass:$rs1,
805                                                     (vti.Mask true_mask),
806                                                     VLOpFrag),
807                                      vti.RegClass:$rd,
808                                      (riscv_fneg_vl vti.RegClass:$rs2,
809                                                     (vti.Mask true_mask),
810                                                     VLOpFrag),
811                                      (vti.Mask true_mask),
812                                      VLOpFrag)),
813            (!cast<Instruction>("PseudoVFNMADD_VV_"# suffix)
814                 vti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2,
815                 GPR:$vl, vti.Log2SEW)>;
816  def : Pat<(vti.Vector (riscv_fma_vl (riscv_fneg_vl vti.RegClass:$rs1,
817                                                     (vti.Mask true_mask),
818                                                     VLOpFrag),
819                                      vti.RegClass:$rd, vti.RegClass:$rs2,
820                                      (vti.Mask true_mask),
821                                      VLOpFrag)),
822            (!cast<Instruction>("PseudoVFNMSUB_VV_"# suffix)
823                 vti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2,
824                 GPR:$vl, vti.Log2SEW)>;
825
826  // The choice of VFMADD here is arbitrary, vfmadd.vf and vfmacc.vf are equally
827  // commutable.
828  def : Pat<(vti.Vector (riscv_fma_vl (SplatFPOp vti.ScalarRegClass:$rs1),
829                                       vti.RegClass:$rd, vti.RegClass:$rs2,
830                                       (vti.Mask true_mask),
831                                       VLOpFrag)),
832            (!cast<Instruction>("PseudoVFMADD_V" # vti.ScalarSuffix # "_" # suffix)
833                 vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2,
834                 GPR:$vl, vti.Log2SEW)>;
835  def : Pat<(vti.Vector (riscv_fma_vl (SplatFPOp vti.ScalarRegClass:$rs1),
836                                       vti.RegClass:$rd,
837                                       (riscv_fneg_vl vti.RegClass:$rs2,
838                                                      (vti.Mask true_mask),
839                                                      VLOpFrag),
840                                       (vti.Mask true_mask),
841                                       VLOpFrag)),
842            (!cast<Instruction>("PseudoVFMSUB_V" # vti.ScalarSuffix # "_" # suffix)
843                 vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2,
844                 GPR:$vl, vti.Log2SEW)>;
845  def : Pat<(vti.Vector (riscv_fma_vl (SplatFPOp vti.ScalarRegClass:$rs1),
846                                       (riscv_fneg_vl vti.RegClass:$rd,
847                                                      (vti.Mask true_mask),
848                                                      VLOpFrag),
849                                       (riscv_fneg_vl vti.RegClass:$rs2,
850                                                      (vti.Mask true_mask),
851                                                      VLOpFrag),
852                                       (vti.Mask true_mask),
853                                       VLOpFrag)),
854            (!cast<Instruction>("PseudoVFNMADD_V" # vti.ScalarSuffix # "_" # suffix)
855                 vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2,
856                 GPR:$vl, vti.Log2SEW)>;
857  def : Pat<(vti.Vector (riscv_fma_vl (SplatFPOp vti.ScalarRegClass:$rs1),
858                                       (riscv_fneg_vl vti.RegClass:$rd,
859                                                      (vti.Mask true_mask),
860                                                      VLOpFrag),
861                                       vti.RegClass:$rs2,
862                                       (vti.Mask true_mask),
863                                       VLOpFrag)),
864            (!cast<Instruction>("PseudoVFNMSUB_V" # vti.ScalarSuffix # "_" # suffix)
865                 vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2,
866                 GPR:$vl, vti.Log2SEW)>;
867
868  // The splat might be negated.
869  def : Pat<(vti.Vector (riscv_fma_vl (riscv_fneg_vl (SplatFPOp vti.ScalarRegClass:$rs1),
870                                                     (vti.Mask true_mask),
871                                                     VLOpFrag),
872                                       vti.RegClass:$rd,
873                                       (riscv_fneg_vl vti.RegClass:$rs2,
874                                                      (vti.Mask true_mask),
875                                                      VLOpFrag),
876                                       (vti.Mask true_mask),
877                                       VLOpFrag)),
878            (!cast<Instruction>("PseudoVFNMADD_V" # vti.ScalarSuffix # "_" # suffix)
879                 vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2,
880                 GPR:$vl, vti.Log2SEW)>;
881  def : Pat<(vti.Vector (riscv_fma_vl (riscv_fneg_vl (SplatFPOp vti.ScalarRegClass:$rs1),
882                                                     (vti.Mask true_mask),
883                                                     VLOpFrag),
884                                       vti.RegClass:$rd, vti.RegClass:$rs2,
885                                       (vti.Mask true_mask),
886                                       VLOpFrag)),
887            (!cast<Instruction>("PseudoVFNMSUB_V" # vti.ScalarSuffix # "_" # suffix)
888                 vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2,
889                 GPR:$vl, vti.Log2SEW)>;
890}
891
892// 14.11. Vector Floating-Point MIN/MAX Instructions
893defm : VPatBinaryFPVL_VV_VF<riscv_fminnum_vl, "PseudoVFMIN">;
894defm : VPatBinaryFPVL_VV_VF<riscv_fmaxnum_vl, "PseudoVFMAX">;
895
896// 14.13. Vector Floating-Point Compare Instructions
897defm : VPatFPSetCCVL_VV_VF_FV<SETEQ,  "PseudoVMFEQ", "PseudoVMFEQ">;
898defm : VPatFPSetCCVL_VV_VF_FV<SETOEQ, "PseudoVMFEQ", "PseudoVMFEQ">;
899
900defm : VPatFPSetCCVL_VV_VF_FV<SETNE,  "PseudoVMFNE", "PseudoVMFNE">;
901defm : VPatFPSetCCVL_VV_VF_FV<SETUNE, "PseudoVMFNE", "PseudoVMFNE">;
902
903defm : VPatFPSetCCVL_VV_VF_FV<SETLT,  "PseudoVMFLT", "PseudoVMFGT">;
904defm : VPatFPSetCCVL_VV_VF_FV<SETOLT, "PseudoVMFLT", "PseudoVMFGT">;
905
906defm : VPatFPSetCCVL_VV_VF_FV<SETLE,  "PseudoVMFLE", "PseudoVMFGE">;
907defm : VPatFPSetCCVL_VV_VF_FV<SETOLE, "PseudoVMFLE", "PseudoVMFGE">;
908
909foreach vti = AllFloatVectors in {
910  // 14.8. Vector Floating-Point Square-Root Instruction
911  def : Pat<(riscv_fsqrt_vl (vti.Vector vti.RegClass:$rs2), (vti.Mask true_mask),
912                            VLOpFrag),
913            (!cast<Instruction>("PseudoVFSQRT_V_"# vti.LMul.MX)
914                 vti.RegClass:$rs2, GPR:$vl, vti.Log2SEW)>;
915
916  // 14.12. Vector Floating-Point Sign-Injection Instructions
917  def : Pat<(riscv_fabs_vl (vti.Vector vti.RegClass:$rs), (vti.Mask true_mask),
918                           VLOpFrag),
919            (!cast<Instruction>("PseudoVFSGNJX_VV_"# vti.LMul.MX)
920                 vti.RegClass:$rs, vti.RegClass:$rs, GPR:$vl, vti.Log2SEW)>;
921  // Handle fneg with VFSGNJN using the same input for both operands.
922  def : Pat<(riscv_fneg_vl (vti.Vector vti.RegClass:$rs), (vti.Mask true_mask),
923                           VLOpFrag),
924            (!cast<Instruction>("PseudoVFSGNJN_VV_"# vti.LMul.MX)
925                 vti.RegClass:$rs, vti.RegClass:$rs, GPR:$vl, vti.Log2SEW)>;
926  def : Pat<(riscv_fcopysign_vl (vti.Vector vti.RegClass:$rs1),
927                                (vti.Vector vti.RegClass:$rs2),
928                                (vti.Mask true_mask),
929                                VLOpFrag),
930            (!cast<Instruction>("PseudoVFSGNJ_VV_"# vti.LMul.MX)
931                 vti.RegClass:$rs1, vti.RegClass:$rs2, GPR:$vl, vti.Log2SEW)>;
932  def : Pat<(riscv_fcopysign_vl (vti.Vector vti.RegClass:$rs1),
933                                (riscv_fneg_vl vti.RegClass:$rs2,
934                                               (vti.Mask true_mask),
935                                               VLOpFrag),
936                                (vti.Mask true_mask),
937                                VLOpFrag),
938            (!cast<Instruction>("PseudoVFSGNJN_VV_"# vti.LMul.MX)
939                 vti.RegClass:$rs1, vti.RegClass:$rs2, GPR:$vl, vti.Log2SEW)>;
940
941  def : Pat<(riscv_fcopysign_vl (vti.Vector vti.RegClass:$rs1),
942                                (SplatFPOp vti.ScalarRegClass:$rs2),
943                                (vti.Mask true_mask),
944                                VLOpFrag),
945            (!cast<Instruction>("PseudoVFSGNJ_V"#vti.ScalarSuffix#"_"# vti.LMul.MX)
946                 vti.RegClass:$rs1, vti.ScalarRegClass:$rs2, GPR:$vl, vti.Log2SEW)>;
947}
948
949foreach fvti = AllFloatVectors in {
950  // Floating-point vselects:
951  // 12.15. Vector Integer Merge Instructions
952  // 14.15. Vector Floating-Point Merge Instruction
953  def : Pat<(fvti.Vector (riscv_vselect_vl (fvti.Mask VMV0:$vm),
954                                           fvti.RegClass:$rs1,
955                                           fvti.RegClass:$rs2,
956                                           VLOpFrag)),
957            (!cast<Instruction>("PseudoVMERGE_VVM_"#fvti.LMul.MX)
958                 fvti.RegClass:$rs2, fvti.RegClass:$rs1, VMV0:$vm,
959                 GPR:$vl, fvti.Log2SEW)>;
960
961  def : Pat<(fvti.Vector (riscv_vselect_vl (fvti.Mask VMV0:$vm),
962                                           (SplatFPOp fvti.ScalarRegClass:$rs1),
963                                           fvti.RegClass:$rs2,
964                                           VLOpFrag)),
965            (!cast<Instruction>("PseudoVFMERGE_V"#fvti.ScalarSuffix#"M_"#fvti.LMul.MX)
966                 fvti.RegClass:$rs2,
967                 (fvti.Scalar fvti.ScalarRegClass:$rs1),
968                 VMV0:$vm, GPR:$vl, fvti.Log2SEW)>;
969
970  def : Pat<(fvti.Vector (riscv_vselect_vl (fvti.Mask VMV0:$vm),
971                                           (SplatFPOp (fvti.Scalar fpimm0)),
972                                           fvti.RegClass:$rs2,
973                                           VLOpFrag)),
974            (!cast<Instruction>("PseudoVMERGE_VIM_"#fvti.LMul.MX)
975                 fvti.RegClass:$rs2, 0, VMV0:$vm, GPR:$vl, fvti.Log2SEW)>;
976
977  // 14.16. Vector Floating-Point Move Instruction
978  // If we're splatting fpimm0, use vmv.v.x vd, x0.
979  def : Pat<(fvti.Vector (riscv_vfmv_v_f_vl
980                         (fvti.Scalar (fpimm0)), VLOpFrag)),
981            (!cast<Instruction>("PseudoVMV_V_I_"#fvti.LMul.MX)
982             0, GPR:$vl, fvti.Log2SEW)>;
983
984  def : Pat<(fvti.Vector (riscv_vfmv_v_f_vl
985                         (fvti.Scalar fvti.ScalarRegClass:$rs2), VLOpFrag)),
986            (!cast<Instruction>("PseudoVFMV_V_" # fvti.ScalarSuffix # "_" #
987                                fvti.LMul.MX)
988             (fvti.Scalar fvti.ScalarRegClass:$rs2),
989             GPR:$vl, fvti.Log2SEW)>;
990
991  // 14.17. Vector Single-Width Floating-Point/Integer Type-Convert Instructions
992  defm : VPatConvertFP2ISDNode_V_VL<riscv_fp_to_sint_vl, "PseudoVFCVT_RTZ_X_F_V">;
993  defm : VPatConvertFP2ISDNode_V_VL<riscv_fp_to_uint_vl, "PseudoVFCVT_RTZ_XU_F_V">;
994  defm : VPatConvertI2FPSDNode_V_VL<riscv_sint_to_fp_vl, "PseudoVFCVT_F_X_V">;
995  defm : VPatConvertI2FPSDNode_V_VL<riscv_uint_to_fp_vl, "PseudoVFCVT_F_XU_V">;
996
997  // 14.18. Widening Floating-Point/Integer Type-Convert Instructions
998  defm : VPatWConvertFP2ISDNode_V_VL<riscv_fp_to_sint_vl, "PseudoVFWCVT_RTZ_X_F_V">;
999  defm : VPatWConvertFP2ISDNode_V_VL<riscv_fp_to_uint_vl, "PseudoVFWCVT_RTZ_XU_F_V">;
1000  defm : VPatWConvertI2FPSDNode_V_VL<riscv_sint_to_fp_vl, "PseudoVFWCVT_F_X_V">;
1001  defm : VPatWConvertI2FPSDNode_V_VL<riscv_uint_to_fp_vl, "PseudoVFWCVT_F_XU_V">;
1002  foreach fvtiToFWti = AllWidenableFloatVectors in {
1003    defvar fvti = fvtiToFWti.Vti;
1004    defvar fwti = fvtiToFWti.Wti;
1005    def : Pat<(fwti.Vector (riscv_fpextend_vl (fvti.Vector fvti.RegClass:$rs1),
1006                                              (fvti.Mask true_mask),
1007                                              VLOpFrag)),
1008              (!cast<Instruction>("PseudoVFWCVT_F_F_V_"#fvti.LMul.MX)
1009                  fvti.RegClass:$rs1, GPR:$vl, fvti.Log2SEW)>;
1010  }
1011
1012  // 14.19 Narrowing Floating-Point/Integer Type-Convert Instructions
1013  defm : VPatNConvertFP2ISDNode_V_VL<riscv_fp_to_sint_vl, "PseudoVFNCVT_RTZ_X_F_W">;
1014  defm : VPatNConvertFP2ISDNode_V_VL<riscv_fp_to_uint_vl, "PseudoVFNCVT_RTZ_XU_F_W">;
1015  defm : VPatNConvertI2FPSDNode_V_VL<riscv_sint_to_fp_vl, "PseudoVFNCVT_F_X_W">;
1016  defm : VPatNConvertI2FPSDNode_V_VL<riscv_uint_to_fp_vl, "PseudoVFNCVT_F_XU_W">;
1017  foreach fvtiToFWti = AllWidenableFloatVectors in {
1018    defvar fvti = fvtiToFWti.Vti;
1019    defvar fwti = fvtiToFWti.Wti;
1020    def : Pat<(fvti.Vector (riscv_fpround_vl (fwti.Vector fwti.RegClass:$rs1),
1021                                             (fwti.Mask true_mask),
1022                                             VLOpFrag)),
1023              (!cast<Instruction>("PseudoVFNCVT_F_F_W_"#fvti.LMul.MX)
1024                  fwti.RegClass:$rs1, GPR:$vl, fvti.Log2SEW)>;
1025
1026    def : Pat<(fvti.Vector (riscv_fncvt_rod_vl (fwti.Vector fwti.RegClass:$rs1),
1027                                               (fwti.Mask true_mask),
1028                                               VLOpFrag)),
1029              (!cast<Instruction>("PseudoVFNCVT_ROD_F_F_W_"#fvti.LMul.MX)
1030                  fwti.RegClass:$rs1, GPR:$vl, fvti.Log2SEW)>;
1031  }
1032}
1033
1034} // Predicates = [HasStdExtV, HasStdExtF]
1035
1036let Predicates = [HasStdExtV] in {
1037
1038foreach mti = AllMasks in {
1039  // 16.1 Vector Mask-Register Logical Instructions
1040  def : Pat<(mti.Mask (riscv_vmset_vl VLOpFrag)),
1041            (!cast<Instruction>("PseudoVMSET_M_" # mti.BX) GPR:$vl, mti.Log2SEW)>;
1042  def : Pat<(mti.Mask (riscv_vmclr_vl VLOpFrag)),
1043            (!cast<Instruction>("PseudoVMCLR_M_" # mti.BX) GPR:$vl, mti.Log2SEW)>;
1044
1045  def : Pat<(mti.Mask (riscv_vmand_vl VR:$rs1, VR:$rs2, VLOpFrag)),
1046            (!cast<Instruction>("PseudoVMAND_MM_" # mti.LMul.MX)
1047                 VR:$rs1, VR:$rs2, GPR:$vl, mti.Log2SEW)>;
1048  def : Pat<(mti.Mask (riscv_vmor_vl VR:$rs1, VR:$rs2, VLOpFrag)),
1049            (!cast<Instruction>("PseudoVMOR_MM_" # mti.LMul.MX)
1050                 VR:$rs1, VR:$rs2, GPR:$vl, mti.Log2SEW)>;
1051  def : Pat<(mti.Mask (riscv_vmxor_vl VR:$rs1, VR:$rs2, VLOpFrag)),
1052            (!cast<Instruction>("PseudoVMXOR_MM_" # mti.LMul.MX)
1053                 VR:$rs1, VR:$rs2, GPR:$vl, mti.Log2SEW)>;
1054
1055  def : Pat<(mti.Mask (riscv_vmand_vl (riscv_vmnot_vl VR:$rs1,
1056                                                      VLOpFrag),
1057                                      VR:$rs2, VLOpFrag)),
1058            (!cast<Instruction>("PseudoVMANDNOT_MM_" # mti.LMul.MX)
1059                 VR:$rs1, VR:$rs2, GPR:$vl, mti.Log2SEW)>;
1060  def : Pat<(mti.Mask (riscv_vmor_vl (riscv_vmnot_vl VR:$rs1,
1061                                                     VLOpFrag),
1062                                     VR:$rs2, VLOpFrag)),
1063            (!cast<Instruction>("PseudoVMORNOT_MM_" # mti.LMul.MX)
1064                 VR:$rs1, VR:$rs2, GPR:$vl, mti.Log2SEW)>;
1065  // XOR is associative so we need 2 patterns for VMXNOR.
1066  def : Pat<(mti.Mask (riscv_vmxor_vl (riscv_vmnot_vl VR:$rs1,
1067                                                      VLOpFrag),
1068                                     VR:$rs2, VLOpFrag)),
1069            (!cast<Instruction>("PseudoVMXNOR_MM_" # mti.LMul.MX)
1070                 VR:$rs1, VR:$rs2, GPR:$vl, mti.Log2SEW)>;
1071
1072  def : Pat<(mti.Mask (riscv_vmnot_vl (riscv_vmand_vl VR:$rs1, VR:$rs2,
1073                                                      VLOpFrag),
1074                                      VLOpFrag)),
1075            (!cast<Instruction>("PseudoVMNAND_MM_" # mti.LMul.MX)
1076                 VR:$rs1, VR:$rs2, GPR:$vl, mti.Log2SEW)>;
1077  def : Pat<(mti.Mask (riscv_vmnot_vl (riscv_vmor_vl VR:$rs1, VR:$rs2,
1078                                                     VLOpFrag),
1079                                      VLOpFrag)),
1080            (!cast<Instruction>("PseudoVMNOR_MM_" # mti.LMul.MX)
1081                 VR:$rs1, VR:$rs2, GPR:$vl, mti.Log2SEW)>;
1082  def : Pat<(mti.Mask (riscv_vmnot_vl (riscv_vmxor_vl VR:$rs1, VR:$rs2,
1083                                                      VLOpFrag),
1084                                      VLOpFrag)),
1085            (!cast<Instruction>("PseudoVMXNOR_MM_" # mti.LMul.MX)
1086                 VR:$rs1, VR:$rs2, GPR:$vl, mti.Log2SEW)>;
1087
1088  // Match the not idiom to the vmnot.m pseudo.
1089  def : Pat<(mti.Mask (riscv_vmnot_vl VR:$rs, VLOpFrag)),
1090            (!cast<Instruction>("PseudoVMNAND_MM_" # mti.LMul.MX)
1091                 VR:$rs, VR:$rs, GPR:$vl, mti.Log2SEW)>;
1092
1093  // 16.2 Vector Mask Population Count vpopc
1094  def : Pat<(XLenVT (riscv_vpopc_vl (mti.Mask VR:$rs2), (mti.Mask true_mask),
1095                                    VLOpFrag)),
1096            (!cast<Instruction>("PseudoVPOPC_M_" # mti.BX)
1097                 VR:$rs2, GPR:$vl, mti.Log2SEW)>;
1098}
1099
1100} // Predicates = [HasStdExtV]
1101
1102let Predicates = [HasStdExtV] in {
1103// 17.1. Integer Scalar Move Instructions
1104// 17.4. Vector Register Gather Instruction
1105foreach vti = AllIntegerVectors in {
1106  def : Pat<(vti.Vector (riscv_vmv_s_x_vl (vti.Vector vti.RegClass:$merge),
1107                                          vti.ScalarRegClass:$rs1,
1108                                          VLOpFrag)),
1109            (!cast<Instruction>("PseudoVMV_S_X_"#vti.LMul.MX)
1110                vti.RegClass:$merge,
1111                (vti.Scalar vti.ScalarRegClass:$rs1), GPR:$vl, vti.Log2SEW)>;
1112  def : Pat<(vti.Vector (riscv_vrgather_vv_vl vti.RegClass:$rs2,
1113                                              (vti.Vector vti.RegClass:$rs1),
1114                                              (vti.Mask true_mask),
1115                                              VLOpFrag)),
1116            (!cast<Instruction>("PseudoVRGATHER_VV_"# vti.LMul.MX)
1117                 vti.RegClass:$rs2, vti.RegClass:$rs1, GPR:$vl, vti.Log2SEW)>;
1118  def : Pat<(vti.Vector (riscv_vrgather_vx_vl vti.RegClass:$rs2, GPR:$rs1,
1119                                              (vti.Mask true_mask),
1120                                              VLOpFrag)),
1121            (!cast<Instruction>("PseudoVRGATHER_VX_"# vti.LMul.MX)
1122                 vti.RegClass:$rs2, GPR:$rs1, GPR:$vl, vti.Log2SEW)>;
1123  def : Pat<(vti.Vector (riscv_vrgather_vx_vl vti.RegClass:$rs2, uimm5:$imm,
1124                                              (vti.Mask true_mask),
1125                                              VLOpFrag)),
1126            (!cast<Instruction>("PseudoVRGATHER_VI_"# vti.LMul.MX)
1127                 vti.RegClass:$rs2, uimm5:$imm, GPR:$vl, vti.Log2SEW)>;
1128
1129  def : Pat<(vti.Vector (riscv_vselect_vl (vti.Mask VMV0:$vm),
1130                                          (riscv_vrgather_vv_vl
1131                                            vti.RegClass:$rs2,
1132                                            vti.RegClass:$rs1,
1133                                            (vti.Mask true_mask),
1134                                            VLOpFrag),
1135                                          vti.RegClass:$merge,
1136                                          VLOpFrag)),
1137            (!cast<Instruction>("PseudoVRGATHER_VV_"# vti.LMul.MX#"_MASK")
1138                 vti.RegClass:$merge, vti.RegClass:$rs2, vti.RegClass:$rs1,
1139                 vti.Mask:$vm, GPR:$vl, vti.Log2SEW)>;
1140
1141  // emul = lmul * 16 / sew
1142  defvar vlmul = vti.LMul;
1143  defvar octuple_lmul = octuple_from_str<vlmul.MX>.ret;
1144  defvar octuple_emul = !srl(!mul(octuple_lmul, 16), vti.Log2SEW);
1145  if !and(!ge(octuple_emul, 1), !le(octuple_emul, 64)) then {
1146    defvar emul_str = octuple_to_str<octuple_emul>.ret;
1147    defvar ivti = !cast<VTypeInfo>("VI16" # emul_str);
1148    defvar inst = "PseudoVRGATHEREI16_VV_" # vti.LMul.MX # "_" # emul_str;
1149    def : Pat<(vti.Vector (riscv_vrgatherei16_vv_vl vti.RegClass:$rs2,
1150                                                    (ivti.Vector ivti.RegClass:$rs1),
1151                                                    (vti.Mask true_mask),
1152                                                    VLOpFrag)),
1153              (!cast<Instruction>(inst)
1154                   vti.RegClass:$rs2, ivti.RegClass:$rs1, GPR:$vl, vti.Log2SEW)>;
1155
1156    def : Pat<(vti.Vector (riscv_vselect_vl (vti.Mask VMV0:$vm),
1157                                            (riscv_vrgatherei16_vv_vl
1158                                              vti.RegClass:$rs2,
1159                                              (ivti.Vector ivti.RegClass:$rs1),
1160                                              (vti.Mask true_mask),
1161                                              VLOpFrag),
1162                                            vti.RegClass:$merge,
1163                                            VLOpFrag)),
1164              (!cast<Instruction>(inst#"_MASK")
1165                   vti.RegClass:$merge, vti.RegClass:$rs2, ivti.RegClass:$rs1,
1166                   vti.Mask:$vm, GPR:$vl, vti.Log2SEW)>;
1167  }
1168}
1169
1170} // Predicates = [HasStdExtV]
1171
1172let Predicates = [HasStdExtV, HasStdExtF] in {
1173
1174// 17.2. Floating-Point Scalar Move Instructions
1175foreach vti = AllFloatVectors in {
1176  def : Pat<(vti.Vector (riscv_vfmv_s_f_vl (vti.Vector vti.RegClass:$merge),
1177                                           vti.ScalarRegClass:$rs1,
1178                                           VLOpFrag)),
1179            (!cast<Instruction>("PseudoVFMV_S_"#vti.ScalarSuffix#"_"#vti.LMul.MX)
1180                vti.RegClass:$merge,
1181                (vti.Scalar vti.ScalarRegClass:$rs1), GPR:$vl, vti.Log2SEW)>;
1182  defvar ivti = GetIntVTypeInfo<vti>.Vti;
1183  def : Pat<(vti.Vector (riscv_vrgather_vv_vl vti.RegClass:$rs2,
1184                                              (ivti.Vector vti.RegClass:$rs1),
1185                                              (vti.Mask true_mask),
1186                                              VLOpFrag)),
1187            (!cast<Instruction>("PseudoVRGATHER_VV_"# vti.LMul.MX)
1188                 vti.RegClass:$rs2, vti.RegClass:$rs1, GPR:$vl, vti.Log2SEW)>;
1189  def : Pat<(vti.Vector (riscv_vrgather_vx_vl vti.RegClass:$rs2, GPR:$rs1,
1190                                              (vti.Mask true_mask),
1191                                              VLOpFrag)),
1192            (!cast<Instruction>("PseudoVRGATHER_VX_"# vti.LMul.MX)
1193                 vti.RegClass:$rs2, GPR:$rs1, GPR:$vl, vti.Log2SEW)>;
1194  def : Pat<(vti.Vector (riscv_vrgather_vx_vl vti.RegClass:$rs2, uimm5:$imm,
1195                                              (vti.Mask true_mask),
1196                                              VLOpFrag)),
1197            (!cast<Instruction>("PseudoVRGATHER_VI_"# vti.LMul.MX)
1198                 vti.RegClass:$rs2, uimm5:$imm, GPR:$vl, vti.Log2SEW)>;
1199
1200  def : Pat<(vti.Vector (riscv_vselect_vl (vti.Mask VMV0:$vm),
1201                                          (riscv_vrgather_vv_vl
1202                                            vti.RegClass:$rs2,
1203                                            (ivti.Vector vti.RegClass:$rs1),
1204                                            (vti.Mask true_mask),
1205                                            VLOpFrag),
1206                                          vti.RegClass:$merge,
1207                                          VLOpFrag)),
1208            (!cast<Instruction>("PseudoVRGATHER_VV_"# vti.LMul.MX#"_MASK")
1209                 vti.RegClass:$merge, vti.RegClass:$rs2, vti.RegClass:$rs1,
1210                 vti.Mask:$vm, GPR:$vl, vti.Log2SEW)>;
1211
1212  defvar vlmul = vti.LMul;
1213  defvar octuple_lmul = octuple_from_str<vlmul.MX>.ret;
1214  defvar octuple_emul = !srl(!mul(octuple_lmul, 16), vti.Log2SEW);
1215  if !and(!ge(octuple_emul, 1), !le(octuple_emul, 64)) then {
1216    defvar emul_str = octuple_to_str<octuple_emul>.ret;
1217    defvar ivti = !cast<VTypeInfo>("VI16" # emul_str);
1218    defvar inst = "PseudoVRGATHEREI16_VV_" # vti.LMul.MX # "_" # emul_str;
1219    def : Pat<(vti.Vector (riscv_vrgatherei16_vv_vl vti.RegClass:$rs2,
1220                                                    (ivti.Vector ivti.RegClass:$rs1),
1221                                                    (vti.Mask true_mask),
1222                                                    VLOpFrag)),
1223              (!cast<Instruction>(inst)
1224                   vti.RegClass:$rs2, ivti.RegClass:$rs1, GPR:$vl, vti.Log2SEW)>;
1225
1226    def : Pat<(vti.Vector (riscv_vselect_vl (vti.Mask VMV0:$vm),
1227                                            (riscv_vrgatherei16_vv_vl
1228                                              vti.RegClass:$rs2,
1229                                              (ivti.Vector ivti.RegClass:$rs1),
1230                                              (vti.Mask true_mask),
1231                                              VLOpFrag),
1232                                            vti.RegClass:$merge,
1233                                            VLOpFrag)),
1234              (!cast<Instruction>(inst#"_MASK")
1235                   vti.RegClass:$merge, vti.RegClass:$rs2, ivti.RegClass:$rs1,
1236                   vti.Mask:$vm, GPR:$vl, vti.Log2SEW)>;
1237  }
1238}
1239
1240} // Predicates = [HasStdExtV, HasStdExtF]
1241
1242//===----------------------------------------------------------------------===//
1243// Miscellaneous RISCVISD SDNodes
1244//===----------------------------------------------------------------------===//
1245
1246def riscv_vid_vl : SDNode<"RISCVISD::VID_VL", SDTypeProfile<1, 2,
1247                          [SDTCisVec<0>, SDTCVecEltisVT<1, i1>,
1248                           SDTCisSameNumEltsAs<0, 1>, SDTCisVT<2, XLenVT>]>, []>;
1249
1250def SDTRVVSlide : SDTypeProfile<1, 5, [
1251  SDTCisVec<0>, SDTCisSameAs<1, 0>, SDTCisSameAs<2, 0>, SDTCisVT<3, XLenVT>,
1252  SDTCVecEltisVT<4, i1>, SDTCisSameNumEltsAs<0, 4>, SDTCisVT<5, XLenVT>
1253]>;
1254def SDTRVVSlide1 : SDTypeProfile<1, 4, [
1255  SDTCisVec<0>, SDTCisSameAs<1, 0>, SDTCisInt<0>, SDTCisVT<2, XLenVT>,
1256  SDTCVecEltisVT<3, i1>, SDTCisSameNumEltsAs<0, 3>, SDTCisVT<4, XLenVT>
1257]>;
1258
1259def riscv_slideup_vl   : SDNode<"RISCVISD::VSLIDEUP_VL", SDTRVVSlide, []>;
1260def riscv_slide1up_vl  : SDNode<"RISCVISD::VSLIDE1UP_VL", SDTRVVSlide1, []>;
1261def riscv_slidedown_vl : SDNode<"RISCVISD::VSLIDEDOWN_VL", SDTRVVSlide, []>;
1262def riscv_slide1down_vl  : SDNode<"RISCVISD::VSLIDE1DOWN_VL", SDTRVVSlide1, []>;
1263
1264let Predicates = [HasStdExtV] in {
1265
1266foreach vti = AllIntegerVectors in {
1267  def : Pat<(vti.Vector (riscv_vid_vl (vti.Mask true_mask),
1268                                      VLOpFrag)),
1269            (!cast<Instruction>("PseudoVID_V_"#vti.LMul.MX) GPR:$vl, vti.Log2SEW)>;
1270
1271  def : Pat<(vti.Vector (riscv_slide1up_vl (vti.Vector vti.RegClass:$rs1),
1272                                           GPR:$rs2, (vti.Mask true_mask),
1273                                           VLOpFrag)),
1274            (!cast<Instruction>("PseudoVSLIDE1UP_VX_"#vti.LMul.MX)
1275                vti.RegClass:$rs1, GPR:$rs2, GPR:$vl, vti.Log2SEW)>;
1276  def : Pat<(vti.Vector (riscv_slide1down_vl (vti.Vector vti.RegClass:$rs1),
1277                                           GPR:$rs2, (vti.Mask true_mask),
1278                                           VLOpFrag)),
1279            (!cast<Instruction>("PseudoVSLIDE1DOWN_VX_"#vti.LMul.MX)
1280                vti.RegClass:$rs1, GPR:$rs2, GPR:$vl, vti.Log2SEW)>;
1281}
1282
1283foreach vti = !listconcat(AllIntegerVectors, AllFloatVectors) in {
1284  def : Pat<(vti.Vector (riscv_slideup_vl (vti.Vector vti.RegClass:$rs3),
1285                                          (vti.Vector vti.RegClass:$rs1),
1286                                          uimm5:$rs2, (vti.Mask true_mask),
1287                                          VLOpFrag)),
1288            (!cast<Instruction>("PseudoVSLIDEUP_VI_"#vti.LMul.MX)
1289                vti.RegClass:$rs3, vti.RegClass:$rs1, uimm5:$rs2,
1290                GPR:$vl, vti.Log2SEW)>;
1291
1292  def : Pat<(vti.Vector (riscv_slideup_vl (vti.Vector vti.RegClass:$rs3),
1293                                          (vti.Vector vti.RegClass:$rs1),
1294                                          GPR:$rs2, (vti.Mask true_mask),
1295                                          VLOpFrag)),
1296            (!cast<Instruction>("PseudoVSLIDEUP_VX_"#vti.LMul.MX)
1297                vti.RegClass:$rs3, vti.RegClass:$rs1, GPR:$rs2,
1298                GPR:$vl, vti.Log2SEW)>;
1299
1300  def : Pat<(vti.Vector (riscv_slidedown_vl (vti.Vector vti.RegClass:$rs3),
1301                                            (vti.Vector vti.RegClass:$rs1),
1302                                            uimm5:$rs2, (vti.Mask true_mask),
1303                                            VLOpFrag)),
1304            (!cast<Instruction>("PseudoVSLIDEDOWN_VI_"#vti.LMul.MX)
1305                vti.RegClass:$rs3, vti.RegClass:$rs1, uimm5:$rs2,
1306                GPR:$vl, vti.Log2SEW)>;
1307
1308  def : Pat<(vti.Vector (riscv_slidedown_vl (vti.Vector vti.RegClass:$rs3),
1309                                            (vti.Vector vti.RegClass:$rs1),
1310                                            GPR:$rs2, (vti.Mask true_mask),
1311                                            VLOpFrag)),
1312            (!cast<Instruction>("PseudoVSLIDEDOWN_VX_"#vti.LMul.MX)
1313                vti.RegClass:$rs3, vti.RegClass:$rs1, GPR:$rs2,
1314                GPR:$vl, vti.Log2SEW)>;
1315}
1316
1317} // Predicates = [HasStdExtV]
1318