From 38706dd9401407fa9de649f6acbb2f2bec756279 Mon Sep 17 00:00:00 2001 From: Lian Wang Date: Fri, 8 Apr 2022 09:28:21 +0000 Subject: [PATCH] [RISCV][NFC] Refactor patterns for Multiply Add instructions Reviewed By: craig.topper, frasercrmck Differential Revision: https://reviews.llvm.org/D123355 --- llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td | 52 +++---- llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td | 158 ++++++++------------- 2 files changed, 80 insertions(+), 130 deletions(-) diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td b/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td index ed81976..ba2000e 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td @@ -537,6 +537,26 @@ multiclass VPatWidenFPNegMulSacSDNode_VV_VF { } } +multiclass VPatMultiplyAddSDNode_VV_VX { + foreach vti = AllIntegerVectors in { + defvar suffix = vti.LMul.MX; + // NOTE: We choose VMADD because it has the most commuting freedom. So it + // works best with how TwoAddressInstructionPass tries commuting. + def : Pat<(vti.Vector (op vti.RegClass:$rs2, + (mul_oneuse vti.RegClass:$rs1, vti.RegClass:$rd))), + (!cast(instruction_name#"_VV_"# suffix) + vti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2, + vti.AVL, vti.Log2SEW, TAIL_AGNOSTIC)>; + // The choice of VMADD here is arbitrary, vmadd.vx and vmacc.vx are equally + // commutable. + def : Pat<(vti.Vector (op vti.RegClass:$rs2, + (mul_oneuse (SplatPat XLenVT:$rs1), vti.RegClass:$rd))), + (!cast(instruction_name#"_VX_" # suffix) + vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2, + vti.AVL, vti.Log2SEW, TAIL_AGNOSTIC)>; + } +} + //===----------------------------------------------------------------------===// // Patterns. //===----------------------------------------------------------------------===// @@ -682,36 +702,8 @@ defm : VPatWidenBinarySDNode_VV_VX; // 12.13 Vector Single-Width Integer Multiply-Add Instructions. -foreach vti = AllIntegerVectors in { - // NOTE: We choose VMADD because it has the most commuting freedom. So it - // works best with how TwoAddressInstructionPass tries commuting. - defvar suffix = vti.LMul.MX; - def : Pat<(vti.Vector (add vti.RegClass:$rs2, - (mul_oneuse vti.RegClass:$rs1, vti.RegClass:$rd))), - (!cast("PseudoVMADD_VV_"# suffix) - vti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2, - vti.AVL, vti.Log2SEW, TAIL_AGNOSTIC)>; - def : Pat<(vti.Vector (sub vti.RegClass:$rs2, - (mul_oneuse vti.RegClass:$rs1, vti.RegClass:$rd))), - (!cast("PseudoVNMSUB_VV_"# suffix) - vti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2, - vti.AVL, vti.Log2SEW, TAIL_AGNOSTIC)>; - - // The choice of VMADD here is arbitrary, vmadd.vx and vmacc.vx are equally - // commutable. - def : Pat<(vti.Vector (add vti.RegClass:$rs2, - (mul_oneuse (SplatPat XLenVT:$rs1), - vti.RegClass:$rd))), - (!cast("PseudoVMADD_VX_" # suffix) - vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2, - vti.AVL, vti.Log2SEW, TAIL_AGNOSTIC)>; - def : Pat<(vti.Vector (sub vti.RegClass:$rs2, - (mul_oneuse (SplatPat XLenVT:$rs1), - vti.RegClass:$rd))), - (!cast("PseudoVNMSUB_VX_" # suffix) - vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2, - vti.AVL, vti.Log2SEW, TAIL_AGNOSTIC)>; -} +defm : VPatMultiplyAddSDNode_VV_VX; +defm : VPatMultiplyAddSDNode_VV_VX; // 12.14 Vector Widening Integer Multiply-Add Instructions defm : VPatWidenMulAddSDNode_VV; diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td b/llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td index 521b387..f22dfa3 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td @@ -829,6 +829,59 @@ multiclass VPatNarrowShiftSplatExt_WX { + foreach vti = AllIntegerVectors in { + defvar suffix = vti.LMul.MX; + // NOTE: We choose VMADD because it has the most commuting freedom. So it + // works best with how TwoAddressInstructionPass tries commuting. + def : Pat<(vti.Vector + (op vti.RegClass:$rs2, + (riscv_mul_vl_oneuse vti.RegClass:$rs1, + vti.RegClass:$rd, + (vti.Mask true_mask), VLOpFrag), + (vti.Mask true_mask), VLOpFrag)), + (!cast(instruction_name#"_VV_"# suffix) + vti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2, + GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>; + // The choice of VMADD here is arbitrary, vmadd.vx and vmacc.vx are equally + // commutable. + def : Pat<(vti.Vector + (op vti.RegClass:$rs2, + (riscv_mul_vl_oneuse (SplatPat XLenVT:$rs1), + vti.RegClass:$rd, + (vti.Mask true_mask), VLOpFrag), + (vti.Mask true_mask), VLOpFrag)), + (!cast(instruction_name#"_VX_" # suffix) + vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2, + GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>; + } +} + +multiclass VPatWidenMultiplyAddVL_VV_VX { + foreach vtiTowti = AllWidenableIntVectors in { + defvar vti = vtiTowti.Vti; + defvar wti = vtiTowti.Wti; + def : Pat<(wti.Vector + (riscv_add_vl wti.RegClass:$rd, + (op1 vti.RegClass:$rs1, + (vti.Vector vti.RegClass:$rs2), + (vti.Mask true_mask), VLOpFrag), + (vti.Mask true_mask), VLOpFrag)), + (!cast(instruction_name#"_VV_" # vti.LMul.MX) + wti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2, + GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>; + def : Pat<(wti.Vector + (riscv_add_vl wti.RegClass:$rd, + (op1 (SplatPat XLenVT:$rs1), + (vti.Vector vti.RegClass:$rs2), + (vti.Mask true_mask), VLOpFrag), + (vti.Mask true_mask), VLOpFrag)), + (!cast(instruction_name#"_VX_" # vti.LMul.MX) + wti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2, + GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>; + } +} + //===----------------------------------------------------------------------===// // Patterns. //===----------------------------------------------------------------------===// @@ -1008,113 +1061,18 @@ defm : VPatBinaryWVL_VV_VX; defm : VPatBinaryWVL_VV_VX; // 12.13 Vector Single-Width Integer Multiply-Add Instructions -foreach vti = AllIntegerVectors in { - // NOTE: We choose VMADD because it has the most commuting freedom. So it - // works best with how TwoAddressInstructionPass tries commuting. - defvar suffix = vti.LMul.MX; - def : Pat<(vti.Vector - (riscv_add_vl vti.RegClass:$rs2, - (riscv_mul_vl_oneuse vti.RegClass:$rs1, - vti.RegClass:$rd, - (vti.Mask true_mask), VLOpFrag), - (vti.Mask true_mask), VLOpFrag)), - (!cast("PseudoVMADD_VV_"# suffix) - vti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2, - GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>; - def : Pat<(vti.Vector - (riscv_sub_vl vti.RegClass:$rs2, - (riscv_mul_vl_oneuse vti.RegClass:$rs1, - vti.RegClass:$rd, - (vti.Mask true_mask), VLOpFrag), - (vti.Mask true_mask), VLOpFrag)), - (!cast("PseudoVNMSUB_VV_"# suffix) - vti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2, - GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>; - - // The choice of VMADD here is arbitrary, vmadd.vx and vmacc.vx are equally - // commutable. - def : Pat<(vti.Vector - (riscv_add_vl vti.RegClass:$rs2, - (riscv_mul_vl_oneuse (SplatPat XLenVT:$rs1), - vti.RegClass:$rd, - (vti.Mask true_mask), VLOpFrag), - (vti.Mask true_mask), VLOpFrag)), - (!cast("PseudoVMADD_VX_" # suffix) - vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2, - GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>; - def : Pat<(vti.Vector - (riscv_sub_vl vti.RegClass:$rs2, - (riscv_mul_vl_oneuse (SplatPat XLenVT:$rs1), - vti.RegClass:$rd, - (vti.Mask true_mask), - VLOpFrag), - (vti.Mask true_mask), VLOpFrag)), - (!cast("PseudoVNMSUB_VX_" # suffix) - vti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2, - GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>; -} +defm : VPatMultiplyAddVL_VV_VX; +defm : VPatMultiplyAddVL_VV_VX; // 12.14. Vector Widening Integer Multiply-Add Instructions +defm : VPatWidenMultiplyAddVL_VV_VX; +defm : VPatWidenMultiplyAddVL_VV_VX; +defm : VPatWidenMultiplyAddVL_VV_VX; foreach vtiTowti = AllWidenableIntVectors in { defvar vti = vtiTowti.Vti; defvar wti = vtiTowti.Wti; def : Pat<(wti.Vector (riscv_add_vl wti.RegClass:$rd, - (riscv_vwmul_vl_oneuse vti.RegClass:$rs1, - (vti.Vector vti.RegClass:$rs2), - (vti.Mask true_mask), VLOpFrag), - (vti.Mask true_mask), VLOpFrag)), - (!cast("PseudoVWMACC_VV_" # vti.LMul.MX) - wti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2, - GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>; - def : Pat<(wti.Vector - (riscv_add_vl wti.RegClass:$rd, - (riscv_vwmulu_vl_oneuse vti.RegClass:$rs1, - (vti.Vector vti.RegClass:$rs2), - (vti.Mask true_mask), VLOpFrag), - (vti.Mask true_mask), VLOpFrag)), - (!cast("PseudoVWMACCU_VV_" # vti.LMul.MX) - wti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2, - GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>; - def : Pat<(wti.Vector - (riscv_add_vl wti.RegClass:$rd, - (riscv_vwmulsu_vl_oneuse vti.RegClass:$rs1, - (vti.Vector vti.RegClass:$rs2), - (vti.Mask true_mask), VLOpFrag), - (vti.Mask true_mask), VLOpFrag)), - (!cast("PseudoVWMACCSU_VV_" # vti.LMul.MX) - wti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs2, - GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>; - - def : Pat<(wti.Vector - (riscv_add_vl wti.RegClass:$rd, - (riscv_vwmul_vl_oneuse (SplatPat XLenVT:$rs1), - (vti.Vector vti.RegClass:$rs2), - (vti.Mask true_mask), VLOpFrag), - (vti.Mask true_mask), VLOpFrag)), - (!cast("PseudoVWMACC_VX_" # vti.LMul.MX) - wti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2, - GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>; - def : Pat<(wti.Vector - (riscv_add_vl wti.RegClass:$rd, - (riscv_vwmulu_vl_oneuse (SplatPat XLenVT:$rs1), - (vti.Vector vti.RegClass:$rs2), - (vti.Mask true_mask), VLOpFrag), - (vti.Mask true_mask), VLOpFrag)), - (!cast("PseudoVWMACCU_VX_" # vti.LMul.MX) - wti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2, - GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>; - def : Pat<(wti.Vector - (riscv_add_vl wti.RegClass:$rd, - (riscv_vwmulsu_vl_oneuse (SplatPat XLenVT:$rs1), - (vti.Vector vti.RegClass:$rs2), - (vti.Mask true_mask), VLOpFrag), - (vti.Mask true_mask), VLOpFrag)), - (!cast("PseudoVWMACCSU_VX_" # vti.LMul.MX) - wti.RegClass:$rd, vti.ScalarRegClass:$rs1, vti.RegClass:$rs2, - GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>; - def : Pat<(wti.Vector - (riscv_add_vl wti.RegClass:$rd, (riscv_vwmulsu_vl_oneuse (vti.Vector vti.RegClass:$rs1), (SplatPat XLenVT:$rs2), (vti.Mask true_mask), VLOpFrag), -- 2.7.4