//===- RISCVInstrInfoVVLPatterns.td - RVV VL patterns ------*- tablegen -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// /// This file contains the required infrastructure and VL patterns to /// support code generation for the standard 'V' (Vector) extension, version /// 0.10. This version is still experimental as the 'V' extension hasn't been /// ratified yet. /// /// This file is included from and depends upon RISCVInstrInfoVPseudos.td /// /// Note: the patterns for RVV intrinsics are found in /// RISCVInstrInfoVPseudos.td. /// //===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===// // Helpers to define the VL patterns. //===----------------------------------------------------------------------===// def SDT_RISCVVLE_VL : SDTypeProfile<1, 2, [SDTCisVec<0>, SDTCisPtrTy<1>, SDTCisVT<2, XLenVT>]>; def SDT_RISCVVSE_VL : SDTypeProfile<0, 3, [SDTCisVec<0>, SDTCisPtrTy<1>, SDTCisVT<2, XLenVT>]>; def SDT_RISCVIntBinOp_VL : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisVec<0>, SDTCisInt<0>, SDTCVecEltisVT<3, i1>, SDTCisSameNumEltsAs<0, 3>, SDTCisVT<4, XLenVT>]>; def SDT_RISCVFPUnOp_VL : SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisVec<0>, SDTCisFP<0>, SDTCVecEltisVT<2, i1>, SDTCisSameNumEltsAs<0, 2>, SDTCisVT<3, XLenVT>]>; def SDT_RISCVFPBinOp_VL : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisVec<0>, SDTCisFP<0>, SDTCVecEltisVT<3, i1>, SDTCisSameNumEltsAs<0, 3>, SDTCisVT<4, XLenVT>]>; def riscv_vmv_v_x_vl : SDNode<"RISCVISD::VMV_V_X_VL", SDTypeProfile<1, 2, [SDTCisVec<0>, SDTCisInt<0>, SDTCisVT<1, XLenVT>, SDTCisVT<2, XLenVT>]>>; def riscv_vfmv_v_f_vl : SDNode<"RISCVISD::VFMV_V_F_VL", SDTypeProfile<1, 2, [SDTCisVec<0>, SDTCisFP<0>, SDTCisEltOfVec<1, 0>, SDTCisVT<2, XLenVT>]>>; def riscv_vle_vl : SDNode<"RISCVISD::VLE_VL", SDT_RISCVVLE_VL, [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>; def riscv_vse_vl : SDNode<"RISCVISD::VSE_VL", SDT_RISCVVSE_VL, [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>; def riscv_add_vl : SDNode<"RISCVISD::ADD_VL", SDT_RISCVIntBinOp_VL, [SDNPCommutative]>; def riscv_sub_vl : SDNode<"RISCVISD::SUB_VL", SDT_RISCVIntBinOp_VL>; def riscv_mul_vl : SDNode<"RISCVISD::MUL_VL", SDT_RISCVIntBinOp_VL, [SDNPCommutative]>; def riscv_and_vl : SDNode<"RISCVISD::AND_VL", SDT_RISCVIntBinOp_VL, [SDNPCommutative]>; def riscv_or_vl : SDNode<"RISCVISD::OR_VL", SDT_RISCVIntBinOp_VL, [SDNPCommutative]>; def riscv_xor_vl : SDNode<"RISCVISD::XOR_VL", SDT_RISCVIntBinOp_VL, [SDNPCommutative]>; def riscv_sdiv_vl : SDNode<"RISCVISD::SDIV_VL", SDT_RISCVIntBinOp_VL>; def riscv_srem_vl : SDNode<"RISCVISD::SREM_VL", SDT_RISCVIntBinOp_VL>; def riscv_udiv_vl : SDNode<"RISCVISD::UDIV_VL", SDT_RISCVIntBinOp_VL>; def riscv_urem_vl : SDNode<"RISCVISD::UREM_VL", SDT_RISCVIntBinOp_VL>; def riscv_shl_vl : SDNode<"RISCVISD::SHL_VL", SDT_RISCVIntBinOp_VL>; def riscv_sra_vl : SDNode<"RISCVISD::SRA_VL", SDT_RISCVIntBinOp_VL>; def riscv_srl_vl : SDNode<"RISCVISD::SRL_VL", SDT_RISCVIntBinOp_VL>; def riscv_smin_vl : SDNode<"RISCVISD::SMIN_VL", SDT_RISCVIntBinOp_VL>; def riscv_smax_vl : SDNode<"RISCVISD::SMAX_VL", SDT_RISCVIntBinOp_VL>; def riscv_umin_vl : SDNode<"RISCVISD::UMIN_VL", SDT_RISCVIntBinOp_VL>; def riscv_umax_vl : SDNode<"RISCVISD::UMAX_VL", SDT_RISCVIntBinOp_VL>; def riscv_fadd_vl : SDNode<"RISCVISD::FADD_VL", SDT_RISCVFPBinOp_VL, [SDNPCommutative]>; def riscv_fsub_vl : SDNode<"RISCVISD::FSUB_VL", SDT_RISCVFPBinOp_VL>; def riscv_fmul_vl : SDNode<"RISCVISD::FMUL_VL", SDT_RISCVFPBinOp_VL, [SDNPCommutative]>; def riscv_fdiv_vl : SDNode<"RISCVISD::FDIV_VL", SDT_RISCVFPBinOp_VL>; def riscv_fneg_vl : SDNode<"RISCVISD::FNEG_VL", SDT_RISCVFPUnOp_VL>; def riscv_fabs_vl : SDNode<"RISCVISD::FABS_VL", SDT_RISCVFPUnOp_VL>; def riscv_fsqrt_vl : SDNode<"RISCVISD::FSQRT_VL", SDT_RISCVFPUnOp_VL>; def SDT_RISCVVecFMA_VL : SDTypeProfile<1, 5, [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisVec<0>, SDTCisFP<0>, SDTCVecEltisVT<4, i1>, SDTCisSameNumEltsAs<0, 4>, SDTCisVT<5, XLenVT>]>; def riscv_fma_vl : SDNode<"RISCVISD::FMA_VL", SDT_RISCVVecFMA_VL, [SDNPCommutative]>; def riscv_setcc_vl : SDNode<"RISCVISD::SETCC_VL", SDTypeProfile<1, 5, [SDTCVecEltisVT<0, i1>, SDTCisVec<1>, SDTCisSameNumEltsAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>, SDTCisSameAs<0, 4>, SDTCisVT<5, XLenVT>]>>; def riscv_vrgather_vx_vl : SDNode<"RISCVISD::VRGATHER_VX_VL", SDTypeProfile<1, 4, [SDTCisVec<0>, SDTCisSameAs<0, 1>, SDTCisVT<2, XLenVT>, SDTCVecEltisVT<3, i1>, SDTCisSameNumEltsAs<0, 3>, SDTCisVT<4, XLenVT>]>>; def riscv_vselect_vl : SDNode<"RISCVISD::VSELECT_VL", SDTypeProfile<1, 4, [SDTCisVec<0>, SDTCisVec<1>, SDTCisSameNumEltsAs<0, 1>, SDTCVecEltisVT<1, i1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>, SDTCisVT<4, XLenVT>]>>; def SDT_RISCVMaskBinOp_VL : SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCVecEltisVT<0, i1>, SDTCisVT<3, XLenVT>]>; def riscv_vmand_vl : SDNode<"RISCVISD::VMAND_VL", SDT_RISCVMaskBinOp_VL, [SDNPCommutative]>; def riscv_vmor_vl : SDNode<"RISCVISD::VMOR_VL", SDT_RISCVMaskBinOp_VL, [SDNPCommutative]>; def riscv_vmxor_vl : SDNode<"RISCVISD::VMXOR_VL", SDT_RISCVMaskBinOp_VL, [SDNPCommutative]>; def SDT_RISCVVMSETCLR_VL : SDTypeProfile<1, 1, [SDTCVecEltisVT<0, i1>, SDTCisVT<1, XLenVT>]>; def riscv_vmclr_vl : SDNode<"RISCVISD::VMCLR_VL", SDT_RISCVVMSETCLR_VL>; def riscv_vmset_vl : SDNode<"RISCVISD::VMSET_VL", SDT_RISCVVMSETCLR_VL>; def true_mask : PatLeaf<(riscv_vmset_vl (XLenVT srcvalue))>; def riscv_vmnot_vl : PatFrag<(ops node:$rs, node:$vl), (riscv_vmxor_vl node:$rs, true_mask, node:$vl)>; // Ignore the vl operand. def SplatFPOp : PatFrag<(ops node:$op), (riscv_vfmv_v_f_vl node:$op, srcvalue)>; def sew8simm5 : ComplexPattern", []>; def sew16simm5 : ComplexPattern", []>; def sew32simm5 : ComplexPattern", []>; def sew64simm5 : ComplexPattern", []>; def sew8uimm5 : ComplexPattern", []>; def sew16uimm5 : ComplexPattern", []>; def sew32uimm5 : ComplexPattern", []>; def sew64uimm5 : ComplexPattern", []>; class VPatBinaryVL_VV : Pat<(result_type (vop (op_type op_reg_class:$rs1), (op_type op_reg_class:$rs2), (mask_type true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast(instruction_name#"_VV_"# vlmul.MX) op_reg_class:$rs1, op_reg_class:$rs2, GPR:$vl, sew)>; class VPatBinaryVL_XI : Pat<(result_type (vop (vop_type vop_reg_class:$rs1), (vop_type (SplatPatKind xop_kind:$rs2)), (mask_type true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast(instruction_name#_#suffix#_# vlmul.MX) vop_reg_class:$rs1, xop_kind:$rs2, GPR:$vl, sew)>; multiclass VPatBinaryVL_VV_VX { foreach vti = AllIntegerVectors in { def : VPatBinaryVL_VV; def : VPatBinaryVL_XI; } } multiclass VPatBinaryVL_VV_VX_VI { foreach vti = AllIntegerVectors in { def : VPatBinaryVL_VV; def : VPatBinaryVL_XI; def : VPatBinaryVL_XI(SplatPat#_#ImmType), ImmType>; } } class VPatBinaryVL_VF : Pat<(result_type (vop (vop_type vop_reg_class:$rs1), (vop_type (SplatFPOp scalar_reg_class:$rs2)), (mask_type true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast(instruction_name#"_"#vlmul.MX) vop_reg_class:$rs1, scalar_reg_class:$rs2, GPR:$vl, sew)>; multiclass VPatBinaryFPVL_VV_VF { foreach vti = AllFloatVectors in { def : VPatBinaryVL_VV; def : VPatBinaryVL_VF; } } multiclass VPatBinaryFPVL_R_VF { foreach fvti = AllFloatVectors in def : Pat<(fvti.Vector (vop (SplatFPOp fvti.ScalarRegClass:$rs2), fvti.RegClass:$rs1, (fvti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast(instruction_name#"_V"#fvti.ScalarSuffix#"_"#fvti.LMul.MX) fvti.RegClass:$rs1, fvti.ScalarRegClass:$rs2, GPR:$vl, fvti.SEW)>; } multiclass VPatIntegerSetCCVL_VV { def : Pat<(vti.Mask (riscv_setcc_vl (vti.Vector vti.RegClass:$rs1), vti.RegClass:$rs2, cc, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast(instruction_name#"_VV_"#vti.LMul.MX) vti.RegClass:$rs1, vti.RegClass:$rs2, GPR:$vl, vti.SEW)>; } // Inherits from VPatIntegerSetCCVL_VV and adds a pattern with operands swapped. multiclass VPatIntegerSetCCVL_VV_Swappable : VPatIntegerSetCCVL_VV { def : Pat<(vti.Mask (riscv_setcc_vl (vti.Vector vti.RegClass:$rs2), vti.RegClass:$rs1, invcc, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast(instruction_name#"_VV_"#vti.LMul.MX) vti.RegClass:$rs1, vti.RegClass:$rs2, GPR:$vl, vti.SEW)>; } multiclass VPatIntegerSetCCVL_VX_Swappable { defvar instruction = !cast(instruction_name#"_VX_"#vti.LMul.MX); def : Pat<(vti.Mask (riscv_setcc_vl (vti.Vector vti.RegClass:$rs1), (SplatPat GPR:$rs2), cc, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (instruction vti.RegClass:$rs1, GPR:$rs2, GPR:$vl, vti.SEW)>; def : Pat<(vti.Mask (riscv_setcc_vl (SplatPat GPR:$rs2), (vti.Vector vti.RegClass:$rs1), invcc, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (instruction vti.RegClass:$rs1, GPR:$rs2, GPR:$vl, vti.SEW)>; } multiclass VPatIntegerSetCCVL_VI_Swappable { defvar instruction = !cast(instruction_name#"_VI_"#vti.LMul.MX); defvar ImmPat = !cast("sew"#vti.SEW#"simm5"); def : Pat<(vti.Mask (riscv_setcc_vl (vti.Vector vti.RegClass:$rs1), (SplatPat_simm5 simm5:$rs2), cc, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (instruction vti.RegClass:$rs1, XLenVT:$rs2, GPR:$vl, vti.SEW)>; def : Pat<(vti.Mask (riscv_setcc_vl (SplatPat_simm5 simm5:$rs2), (vti.Vector vti.RegClass:$rs1), invcc, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (instruction vti.RegClass:$rs1, simm5:$rs2, GPR:$vl, vti.SEW)>; } multiclass VPatFPSetCCVL_VV_VF_FV { foreach fvti = AllFloatVectors in { def : Pat<(fvti.Mask (riscv_setcc_vl (fvti.Vector fvti.RegClass:$rs1), fvti.RegClass:$rs2, cc, (fvti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast(inst_name#"_VV_"#fvti.LMul.MX) fvti.RegClass:$rs1, fvti.RegClass:$rs2, GPR:$vl, fvti.SEW)>; def : Pat<(fvti.Mask (riscv_setcc_vl (fvti.Vector fvti.RegClass:$rs1), (SplatFPOp fvti.ScalarRegClass:$rs2), cc, (fvti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast(inst_name#"_V"#fvti.ScalarSuffix#"_"#fvti.LMul.MX) fvti.RegClass:$rs1, fvti.ScalarRegClass:$rs2, GPR:$vl, fvti.SEW)>; def : Pat<(fvti.Mask (riscv_setcc_vl (SplatFPOp fvti.ScalarRegClass:$rs2), (fvti.Vector fvti.RegClass:$rs1), cc, (fvti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast(swapped_op_inst_name#"_V"#fvti.ScalarSuffix#"_"#fvti.LMul.MX) fvti.RegClass:$rs1, fvti.ScalarRegClass:$rs2, GPR:$vl, fvti.SEW)>; } } //===----------------------------------------------------------------------===// // Patterns. //===----------------------------------------------------------------------===// let Predicates = [HasStdExtV] in { // 7.4. Vector Unit-Stride Instructions foreach vti = AllVectors in { defvar load_instr = !cast("PseudoVLE"#vti.SEW#"_V_"#vti.LMul.MX); defvar store_instr = !cast("PseudoVSE"#vti.SEW#"_V_"#vti.LMul.MX); // Load def : Pat<(vti.Vector (riscv_vle_vl BaseAddr:$rs1, (XLenVT (VLOp GPR:$vl)))), (load_instr BaseAddr:$rs1, GPR:$vl, vti.SEW)>; // Store def : Pat<(riscv_vse_vl (vti.Vector vti.RegClass:$rs2), BaseAddr:$rs1, (XLenVT (VLOp GPR:$vl))), (store_instr vti.RegClass:$rs2, BaseAddr:$rs1, GPR:$vl, vti.SEW)>; } foreach mti = AllMasks in { defvar load_instr = !cast("PseudoVLE1_V_"#mti.BX); defvar store_instr = !cast("PseudoVSE1_V_"#mti.BX); def : Pat<(mti.Mask (riscv_vle_vl BaseAddr:$rs1, (XLenVT (VLOp GPR:$vl)))), (load_instr BaseAddr:$rs1, GPR:$vl, mti.SEW)>; def : Pat<(riscv_vse_vl (mti.Mask VR:$rs2), BaseAddr:$rs1, (XLenVT (VLOp GPR:$vl))), (store_instr VR:$rs2, BaseAddr:$rs1, GPR:$vl, mti.SEW)>; } // 12.1. Vector Single-Width Integer Add and Subtract defm "" : VPatBinaryVL_VV_VX_VI; defm "" : VPatBinaryVL_VV_VX; // Handle VRSUB specially since it's the only integer binary op with reversed // pattern operands foreach vti = AllIntegerVectors in { def : Pat<(riscv_sub_vl (vti.Vector (SplatPat GPR:$rs2)), (vti.Vector vti.RegClass:$rs1), (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl))), (!cast("PseudoVRSUB_VX_"# vti.LMul.MX) vti.RegClass:$rs1, GPR:$rs2, GPR:$vl, vti.SEW)>; def : Pat<(riscv_sub_vl (vti.Vector (SplatPat_simm5 simm5:$rs2)), (vti.Vector vti.RegClass:$rs1), (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl))), (!cast("PseudoVRSUB_VI_"# vti.LMul.MX) vti.RegClass:$rs1, simm5:$rs2, GPR:$vl, vti.SEW)>; } // 12.5. Vector Bitwise Logical Instructions defm "" : VPatBinaryVL_VV_VX_VI; defm "" : VPatBinaryVL_VV_VX_VI; defm "" : VPatBinaryVL_VV_VX_VI; // 12.6. Vector Single-Width Bit Shift Instructions defm "" : VPatBinaryVL_VV_VX_VI; defm "" : VPatBinaryVL_VV_VX_VI; defm "" : VPatBinaryVL_VV_VX_VI; // 12.8. Vector Integer Comparison Instructions foreach vti = AllIntegerVectors in { defm "" : VPatIntegerSetCCVL_VV; defm "" : VPatIntegerSetCCVL_VV; defm "" : VPatIntegerSetCCVL_VV_Swappable; defm "" : VPatIntegerSetCCVL_VV_Swappable; defm "" : VPatIntegerSetCCVL_VV_Swappable; defm "" : VPatIntegerSetCCVL_VV_Swappable; defm "" : VPatIntegerSetCCVL_VX_Swappable; defm "" : VPatIntegerSetCCVL_VX_Swappable; defm "" : VPatIntegerSetCCVL_VX_Swappable; defm "" : VPatIntegerSetCCVL_VX_Swappable; defm "" : VPatIntegerSetCCVL_VX_Swappable; defm "" : VPatIntegerSetCCVL_VX_Swappable; defm "" : VPatIntegerSetCCVL_VX_Swappable; defm "" : VPatIntegerSetCCVL_VX_Swappable; // There is no VMSGE(U)_VX instruction // FIXME: Support immediate forms of these by choosing SGT and decrementing // the immediate defm "" : VPatIntegerSetCCVL_VI_Swappable; defm "" : VPatIntegerSetCCVL_VI_Swappable; defm "" : VPatIntegerSetCCVL_VI_Swappable; defm "" : VPatIntegerSetCCVL_VI_Swappable; } // foreach vti = AllIntegerVectors // 12.9. Vector Integer Min/Max Instructions defm "" : VPatBinaryVL_VV_VX; defm "" : VPatBinaryVL_VV_VX; defm "" : VPatBinaryVL_VV_VX; defm "" : VPatBinaryVL_VV_VX; // 12.10. Vector Single-Width Integer Multiply Instructions defm "" : VPatBinaryVL_VV_VX; // 12.11. Vector Integer Divide Instructions defm "" : VPatBinaryVL_VV_VX; defm "" : VPatBinaryVL_VV_VX; defm "" : VPatBinaryVL_VV_VX; defm "" : VPatBinaryVL_VV_VX; // 12.16. Vector Integer Merge Instructions foreach vti = AllIntegerVectors in { def : Pat<(vti.Vector (riscv_vselect_vl (vti.Mask VMV0:$vm), vti.RegClass:$rs1, vti.RegClass:$rs2, (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMERGE_VVM_"#vti.LMul.MX) vti.RegClass:$rs2, vti.RegClass:$rs1, VMV0:$vm, GPR:$vl, vti.SEW)>; def : Pat<(vti.Vector (riscv_vselect_vl (vti.Mask VMV0:$vm), (SplatPat XLenVT:$rs1), vti.RegClass:$rs2, (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMERGE_VXM_"#vti.LMul.MX) vti.RegClass:$rs2, GPR:$rs1, VMV0:$vm, GPR:$vl, vti.SEW)>; def : Pat<(vti.Vector (riscv_vselect_vl (vti.Mask VMV0:$vm), (SplatPat_simm5 simm5:$rs1), vti.RegClass:$rs2, (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMERGE_VIM_"#vti.LMul.MX) vti.RegClass:$rs2, simm5:$rs1, VMV0:$vm, GPR:$vl, vti.SEW)>; } // 12.17. Vector Integer Move Instructions foreach vti = AllIntegerVectors in { def : Pat<(vti.Vector (riscv_vmv_v_x_vl GPR:$rs2, (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMV_V_X_"#vti.LMul.MX) $rs2, GPR:$vl, vti.SEW)>; defvar ImmPat = !cast("sew"#vti.SEW#"simm5"); def : Pat<(vti.Vector (riscv_vmv_v_x_vl (ImmPat XLenVT:$imm5), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMV_V_I_"#vti.LMul.MX) XLenVT:$imm5, GPR:$vl, vti.SEW)>; } } // Predicates = [HasStdExtV] let Predicates = [HasStdExtV, HasStdExtF] in { // 14.2. Vector Single-Width Floating-Point Add/Subtract Instructions defm "" : VPatBinaryFPVL_VV_VF; defm "" : VPatBinaryFPVL_VV_VF; defm "" : VPatBinaryFPVL_R_VF; // 14.4. Vector Single-Width Floating-Point Multiply/Divide Instructions defm "" : VPatBinaryFPVL_VV_VF; defm "" : VPatBinaryFPVL_VV_VF; defm "" : VPatBinaryFPVL_R_VF; // 14.6 Vector Single-Width Floating-Point Fused Multiply-Add Instructions. foreach vti = AllFloatVectors in { // NOTE: We choose VFMADD because it has the most commuting freedom. So it // works best with how TwoAddressInstructionPass tries commuting. defvar suffix = vti.LMul.MX # "_COMMUTABLE"; def : Pat<(vti.Vector (riscv_fma_vl vti.RegClass:$rs1, vti.RegClass:$rd, vti.RegClass:$rs2, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVFMADD_VV_"# suffix) vti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2, GPR:$vl, vti.SEW)>; def : Pat<(vti.Vector (riscv_fma_vl vti.RegClass:$rs1, vti.RegClass:$rd, (riscv_fneg_vl vti.RegClass:$rs2, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl))), (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVFMSUB_VV_"# suffix) vti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2, GPR:$vl, vti.SEW)>; def : Pat<(vti.Vector (riscv_fma_vl (riscv_fneg_vl vti.RegClass:$rs1, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl))), vti.RegClass:$rd, (riscv_fneg_vl vti.RegClass:$rs2, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl))), (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVFNMADD_VV_"# suffix) vti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2, GPR:$vl, vti.SEW)>; def : Pat<(vti.Vector (riscv_fma_vl (riscv_fneg_vl vti.RegClass:$rs1, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl))), vti.RegClass:$rd, vti.RegClass:$rs2, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVFNMSUB_VV_"# suffix) vti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2, GPR:$vl, vti.SEW)>; // The choice of VFMADD here is arbitrary, vfmadd.vf and vfmacc.vf are equally // commutable. def : Pat<(vti.Vector (riscv_fma_vl (SplatFPOp vti.ScalarRegClass:$rs1), vti.RegClass:$rd, vti.RegClass:$rs2, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVFMADD_V" # vti.ScalarSuffix # "_" # suffix) vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2, GPR:$vl, vti.SEW)>; def : Pat<(vti.Vector (riscv_fma_vl (SplatFPOp vti.ScalarRegClass:$rs1), vti.RegClass:$rd, (riscv_fneg_vl vti.RegClass:$rs2, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl))), (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVFMSUB_V" # vti.ScalarSuffix # "_" # suffix) vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2, GPR:$vl, vti.SEW)>; def : Pat<(vti.Vector (riscv_fma_vl (SplatFPOp vti.ScalarRegClass:$rs1), (riscv_fneg_vl vti.RegClass:$rd, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl))), (riscv_fneg_vl vti.RegClass:$rs2, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl))), (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVFNMADD_V" # vti.ScalarSuffix # "_" # suffix) vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2, GPR:$vl, vti.SEW)>; def : Pat<(vti.Vector (riscv_fma_vl (SplatFPOp vti.ScalarRegClass:$rs1), (riscv_fneg_vl vti.RegClass:$rd, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl))), vti.RegClass:$rs2, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVFNMSUB_V" # vti.ScalarSuffix # "_" # suffix) vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2, GPR:$vl, vti.SEW)>; // The splat might be negated. def : Pat<(vti.Vector (riscv_fma_vl (riscv_fneg_vl (SplatFPOp vti.ScalarRegClass:$rs1), (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl))), vti.RegClass:$rd, (riscv_fneg_vl vti.RegClass:$rs2, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl))), (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVFNMADD_V" # vti.ScalarSuffix # "_" # suffix) vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2, GPR:$vl, vti.SEW)>; def : Pat<(vti.Vector (riscv_fma_vl (riscv_fneg_vl (SplatFPOp vti.ScalarRegClass:$rs1), (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl))), vti.RegClass:$rd, vti.RegClass:$rs2, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVFNMSUB_V" # vti.ScalarSuffix # "_" # suffix) vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2, GPR:$vl, vti.SEW)>; } // 14.11. Vector Floating-Point Compare Instructions defm "" : VPatFPSetCCVL_VV_VF_FV; defm "" : VPatFPSetCCVL_VV_VF_FV; defm "" : VPatFPSetCCVL_VV_VF_FV; defm "" : VPatFPSetCCVL_VV_VF_FV; defm "" : VPatFPSetCCVL_VV_VF_FV; defm "" : VPatFPSetCCVL_VV_VF_FV; defm "" : VPatFPSetCCVL_VV_VF_FV; defm "" : VPatFPSetCCVL_VV_VF_FV; // 14.12. Vector Floating-Point Sign-Injection Instructions // Handle fneg with VFSGNJN using the same input for both operands. foreach vti = AllFloatVectors in { // 14.8. Vector Floating-Point Square-Root Instruction def : Pat<(riscv_fsqrt_vl (vti.Vector vti.RegClass:$rs2), (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl))), (!cast("PseudoVFSQRT_V_"# vti.LMul.MX) vti.RegClass:$rs2, GPR:$vl, vti.SEW)>; // 14.12. Vector Floating-Point Sign-Injection Instructions def : Pat<(riscv_fabs_vl (vti.Vector vti.RegClass:$rs), (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl))), (!cast("PseudoVFSGNJX_VV_"# vti.LMul.MX) vti.RegClass:$rs, vti.RegClass:$rs, GPR:$vl, vti.SEW)>; // Handle fneg with VFSGNJN using the same input for both operands. def : Pat<(riscv_fneg_vl (vti.Vector vti.RegClass:$rs), (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl))), (!cast("PseudoVFSGNJN_VV_"# vti.LMul.MX) vti.RegClass:$rs, vti.RegClass:$rs, GPR:$vl, vti.SEW)>; } foreach fvti = AllFloatVectors in { // Floating-point vselects: // 12.16. Vector Integer Merge Instructions // 14.13. Vector Floating-Point Merge Instruction def : Pat<(fvti.Vector (riscv_vselect_vl (fvti.Mask VMV0:$vm), fvti.RegClass:$rs1, fvti.RegClass:$rs2, (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMERGE_VVM_"#fvti.LMul.MX) fvti.RegClass:$rs2, fvti.RegClass:$rs1, VMV0:$vm, GPR:$vl, fvti.SEW)>; def : Pat<(fvti.Vector (riscv_vselect_vl (fvti.Mask VMV0:$vm), (SplatFPOp fvti.ScalarRegClass:$rs1), fvti.RegClass:$rs2, (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVFMERGE_V"#fvti.ScalarSuffix#"M_"#fvti.LMul.MX) fvti.RegClass:$rs2, (fvti.Scalar fvti.ScalarRegClass:$rs1), VMV0:$vm, GPR:$vl, fvti.SEW)>; def : Pat<(fvti.Vector (riscv_vselect_vl (fvti.Mask VMV0:$vm), (SplatFPOp (fvti.Scalar fpimm0)), fvti.RegClass:$rs2, (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMERGE_VIM_"#fvti.LMul.MX) fvti.RegClass:$rs2, 0, VMV0:$vm, GPR:$vl, fvti.SEW)>; // 14.16. Vector Floating-Point Move Instruction // If we're splatting fpimm0, use vmv.v.x vd, x0. def : Pat<(fvti.Vector (riscv_vfmv_v_f_vl (fvti.Scalar (fpimm0)), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMV_V_I_"#fvti.LMul.MX) 0, GPR:$vl, fvti.SEW)>; def : Pat<(fvti.Vector (riscv_vfmv_v_f_vl (fvti.Scalar fvti.ScalarRegClass:$rs2), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVFMV_V_" # fvti.ScalarSuffix # "_" # fvti.LMul.MX) (fvti.Scalar fvti.ScalarRegClass:$rs2), GPR:$vl, fvti.SEW)>; } } // Predicates = [HasStdExtV, HasStdExtF] // 16.1 Vector Mask-Register Logical Instructions let Predicates = [HasStdExtV] in { foreach mti = AllMasks in { def : Pat<(mti.Mask (riscv_vmset_vl (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMSET_M_" # mti.BX) GPR:$vl, mti.SEW)>; def : Pat<(mti.Mask (riscv_vmclr_vl (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMCLR_M_" # mti.BX) GPR:$vl, mti.SEW)>; def : Pat<(mti.Mask (riscv_vmand_vl VR:$rs1, VR:$rs2, (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMAND_MM_" # mti.LMul.MX) VR:$rs1, VR:$rs2, GPR:$vl, mti.SEW)>; def : Pat<(mti.Mask (riscv_vmor_vl VR:$rs1, VR:$rs2, (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMOR_MM_" # mti.LMul.MX) VR:$rs1, VR:$rs2, GPR:$vl, mti.SEW)>; def : Pat<(mti.Mask (riscv_vmxor_vl VR:$rs1, VR:$rs2, (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMXOR_MM_" # mti.LMul.MX) VR:$rs1, VR:$rs2, GPR:$vl, mti.SEW)>; def : Pat<(mti.Mask (riscv_vmand_vl (riscv_vmnot_vl VR:$rs1, (XLenVT (VLOp GPR:$vl))), VR:$rs2, (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMANDNOT_MM_" # mti.LMul.MX) VR:$rs1, VR:$rs2, GPR:$vl, mti.SEW)>; def : Pat<(mti.Mask (riscv_vmor_vl (riscv_vmnot_vl VR:$rs1, (XLenVT (VLOp GPR:$vl))), VR:$rs2, (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMORNOT_MM_" # mti.LMul.MX) VR:$rs1, VR:$rs2, GPR:$vl, mti.SEW)>; // XOR is associative so we need 2 patterns for VMXNOR. def : Pat<(mti.Mask (riscv_vmxor_vl (riscv_vmnot_vl VR:$rs1, (XLenVT (VLOp GPR:$vl))), VR:$rs2, (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMXNOR_MM_" # mti.LMul.MX) VR:$rs1, VR:$rs2, GPR:$vl, mti.SEW)>; def : Pat<(mti.Mask (riscv_vmnot_vl (riscv_vmand_vl VR:$rs1, VR:$rs2, (XLenVT (VLOp GPR:$vl))), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMNAND_MM_" # mti.LMul.MX) VR:$rs1, VR:$rs2, GPR:$vl, mti.SEW)>; def : Pat<(mti.Mask (riscv_vmnot_vl (riscv_vmor_vl VR:$rs1, VR:$rs2, (XLenVT (VLOp GPR:$vl))), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMNOR_MM_" # mti.LMul.MX) VR:$rs1, VR:$rs2, GPR:$vl, mti.SEW)>; def : Pat<(mti.Mask (riscv_vmnot_vl (riscv_vmxor_vl VR:$rs1, VR:$rs2, (XLenVT (VLOp GPR:$vl))), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMXNOR_MM_" # mti.LMul.MX) VR:$rs1, VR:$rs2, GPR:$vl, mti.SEW)>; // Match the not idiom to the vnot.mm pseudo. def : Pat<(mti.Mask (riscv_vmnot_vl VR:$rs, (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVMNAND_MM_" # mti.LMul.MX) VR:$rs, VR:$rs, GPR:$vl, mti.SEW)>; } } // Predicates = [HasStdExtV] // 17.4. Vector Register GAther Instruction let Predicates = [HasStdExtV] in { foreach vti = AllIntegerVectors in { def : Pat<(vti.Vector (riscv_vrgather_vx_vl vti.RegClass:$rs2, GPR:$rs1, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVRGATHER_VX_"# vti.LMul.MX) vti.RegClass:$rs2, GPR:$rs1, GPR:$vl, vti.SEW)>; def : Pat<(vti.Vector (riscv_vrgather_vx_vl vti.RegClass:$rs2, uimm5:$imm, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVRGATHER_VI_"# vti.LMul.MX) vti.RegClass:$rs2, uimm5:$imm, GPR:$vl, vti.SEW)>; } } // Predicates = [HasStdExtV] let Predicates = [HasStdExtV, HasStdExtF] in { foreach vti = AllFloatVectors in { def : Pat<(vti.Vector (riscv_vrgather_vx_vl vti.RegClass:$rs2, GPR:$rs1, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVRGATHER_VX_"# vti.LMul.MX) vti.RegClass:$rs2, GPR:$rs1, GPR:$vl, vti.SEW)>; def : Pat<(vti.Vector (riscv_vrgather_vx_vl vti.RegClass:$rs2, uimm5:$imm, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVRGATHER_VI_"# vti.LMul.MX) vti.RegClass:$rs2, uimm5:$imm, GPR:$vl, vti.SEW)>; } } // Predicates = [HasStdExtV, HasStdExtF] //===----------------------------------------------------------------------===// // Miscellaneous RISCVISD SDNodes //===----------------------------------------------------------------------===// def riscv_vid_vl : SDNode<"RISCVISD::VID_VL", SDTypeProfile<1, 2, [SDTCisVec<0>, SDTCVecEltisVT<1, i1>, SDTCisSameNumEltsAs<0, 1>, SDTCisVT<2, XLenVT>]>, []>; def SDTRVVSlide : SDTypeProfile<1, 5, [ SDTCisVec<0>, SDTCisSameAs<1, 0>, SDTCisSameAs<2, 0>, SDTCisVT<3, XLenVT>, SDTCVecEltisVT<4, i1>, SDTCisSameNumEltsAs<0, 4>, SDTCisVT<5, XLenVT> ]>; def riscv_slideup_vl : SDNode<"RISCVISD::VSLIDEUP_VL", SDTRVVSlide, []>; def riscv_slidedown_vl : SDNode<"RISCVISD::VSLIDEDOWN_VL", SDTRVVSlide, []>; let Predicates = [HasStdExtV] in { foreach vti = AllIntegerVectors in def : Pat<(vti.Vector (riscv_vid_vl (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVID_V_"#vti.LMul.MX) GPR:$vl, vti.SEW)>; foreach vti = !listconcat(AllIntegerVectors, AllFloatVectors) in { def : Pat<(vti.Vector (riscv_slideup_vl (vti.Vector vti.RegClass:$rs3), (vti.Vector vti.RegClass:$rs1), uimm5:$rs2, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVSLIDEUP_VI_"#vti.LMul.MX) vti.RegClass:$rs3, vti.RegClass:$rs1, uimm5:$rs2, GPR:$vl, vti.SEW)>; def : Pat<(vti.Vector (riscv_slideup_vl (vti.Vector vti.RegClass:$rs3), (vti.Vector vti.RegClass:$rs1), GPR:$rs2, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVSLIDEUP_VX_"#vti.LMul.MX) vti.RegClass:$rs3, vti.RegClass:$rs1, GPR:$rs2, GPR:$vl, vti.SEW)>; def : Pat<(vti.Vector (riscv_slidedown_vl (vti.Vector vti.RegClass:$rs3), (vti.Vector vti.RegClass:$rs1), uimm5:$rs2, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVSLIDEDOWN_VI_"#vti.LMul.MX) vti.RegClass:$rs3, vti.RegClass:$rs1, uimm5:$rs2, GPR:$vl, vti.SEW)>; def : Pat<(vti.Vector (riscv_slidedown_vl (vti.Vector vti.RegClass:$rs3), (vti.Vector vti.RegClass:$rs1), GPR:$rs2, (vti.Mask true_mask), (XLenVT (VLOp GPR:$vl)))), (!cast("PseudoVSLIDEDOWN_VX_"#vti.LMul.MX) vti.RegClass:$rs3, vti.RegClass:$rs1, GPR:$rs2, GPR:$vl, vti.SEW)>; } } // Predicates = [HasStdExtV]