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