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