RE: [PATCH v1] RISC-V: Support rounding mode for VFMSAC/VFMSUB autovec
Committed, thanks Kito. Pan -Original Message- From: Kito Cheng Sent: Thursday, August 31, 2023 9:09 PM To: Li, Pan2 Cc: gcc-patches@gcc.gnu.org; juzhe.zh...@rivai.ai; Wang, Yanzhang Subject: Re: [PATCH v1] RISC-V: Support rounding mode for VFMSAC/VFMSUB autovec LGTM On Thu, Aug 24, 2023 at 3:13 PM Pan Li via Gcc-patches wrote: > > From: Pan Li > > There will be a case like below for intrinsic and autovec combination. > > vfadd RTZ <- intrinisc static rounding > vfmsub <- autovec/autovec-opt > > The autovec generated vfmsub should take DYN mode, and the > frm must be restored before the vfmsub insn. This patch > would like to fix this issue by: > > * Add the frm operand to the autovec/autovec-opt pattern. > * Set the frm_mode attr to DYN. > > Thus, the frm flow when combine autovec and intrinsic should be. > > + > | frrm a5 > | ... > | fsrmi 4 > | vfadd <- intrinsic static rounding. > | ... > | fsrm a5 > | vfmsub <- autovec/autovec-opt > | ... > + > > Signed-off-by: Pan Li > > gcc/ChangeLog: > > * config/riscv/autovec-opt.md: Add FRM_REGNUM to vfmsac/vfmsub > * config/riscv/autovec.md: Ditto. > > gcc/testsuite/ChangeLog: > > * gcc.target/riscv/rvv/base/float-point-frm-autovec-2.c: New test. > --- > gcc/config/riscv/autovec-opt.md | 36 > gcc/config/riscv/autovec.md | 30 --- > .../rvv/base/float-point-frm-autovec-2.c | 88 +++ > 3 files changed, 127 insertions(+), 27 deletions(-) > create mode 100644 > gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm-autovec-2.c > > diff --git a/gcc/config/riscv/autovec-opt.md b/gcc/config/riscv/autovec-opt.md > index 4b07e80ad95..732a51edacd 100644 > --- a/gcc/config/riscv/autovec-opt.md > +++ b/gcc/config/riscv/autovec-opt.md > @@ -583,13 +583,15 @@ (define_insn_and_split "*single_widen_fnma" > ;; vect__13.182_33 = .FMS (vect__11.180_35, vect__8.176_40, vect__4.172_45); > (define_insn_and_split "*double_widen_fms" >[(set (match_operand:VWEXTF 0 "register_operand") > - (fma:VWEXTF > - (float_extend:VWEXTF > - (match_operand: 2 "register_operand")) > - (float_extend:VWEXTF > - (match_operand: 3 "register_operand")) > - (neg:VWEXTF > - (match_operand:VWEXTF 1 "register_operand"] > + (unspec:VWEXTF > + [(fma:VWEXTF > + (float_extend:VWEXTF > + (match_operand: 2 "register_operand")) > + (float_extend:VWEXTF > + (match_operand: 3 "register_operand")) > + (neg:VWEXTF > + (match_operand:VWEXTF 1 "register_operand"))) > + (reg:SI FRM_REGNUM)] UNSPEC_VFFMA))] >"TARGET_VECTOR && can_create_pseudo_p ()" >"#" >"&& 1" > @@ -600,17 +602,20 @@ (define_insn_and_split "*double_widen_fms" > DONE; >} >[(set_attr "type" "vfwmuladd") > - (set_attr "mode" "")]) > + (set_attr "mode" "") > + (set (attr "frm_mode") (symbol_ref "riscv_vector::FRM_DYN"))]) > > ;; This helps to match ext + fms. > (define_insn_and_split "*single_widen_fms" >[(set (match_operand:VWEXTF 0 "register_operand") > - (fma:VWEXTF > - (float_extend:VWEXTF > - (match_operand: 2 "register_operand")) > - (match_operand:VWEXTF 3 "register_operand") > - (neg:VWEXTF > - (match_operand:VWEXTF 1 "register_operand"] > + (unspec:VWEXTF > + [(fma:VWEXTF > + (float_extend:VWEXTF > + (match_operand: 2 "register_operand")) > + (match_operand:VWEXTF 3 "register_operand") > + (neg:VWEXTF > + (match_operand:VWEXTF 1 "register_operand"))) > + (reg:SI FRM_REGNUM)] UNSPEC_VFFMA))] >"TARGET_VECTOR && can_create_pseudo_p ()" >"#" >"&& 1" > @@ -627,7 +632,8 @@ (define_insn_and_split "*single_widen_fms" > DONE; >} >[(set_attr "type" "vfwmuladd") > - (set_attr "mode" "")]) > + (set_attr "mode" "") > + (set (attr "frm_mode") (symbol_ref "riscv_vector::FRM_DYN"))]) > > ;; - > ;; [FP] VFWN
Re: [PATCH v1] RISC-V: Support rounding mode for VFMSAC/VFMSUB autovec
LGTM On Thu, Aug 24, 2023 at 3:13 PM Pan Li via Gcc-patches wrote: > > From: Pan Li > > There will be a case like below for intrinsic and autovec combination. > > vfadd RTZ <- intrinisc static rounding > vfmsub <- autovec/autovec-opt > > The autovec generated vfmsub should take DYN mode, and the > frm must be restored before the vfmsub insn. This patch > would like to fix this issue by: > > * Add the frm operand to the autovec/autovec-opt pattern. > * Set the frm_mode attr to DYN. > > Thus, the frm flow when combine autovec and intrinsic should be. > > + > | frrm a5 > | ... > | fsrmi 4 > | vfadd <- intrinsic static rounding. > | ... > | fsrm a5 > | vfmsub <- autovec/autovec-opt > | ... > + > > Signed-off-by: Pan Li > > gcc/ChangeLog: > > * config/riscv/autovec-opt.md: Add FRM_REGNUM to vfmsac/vfmsub > * config/riscv/autovec.md: Ditto. > > gcc/testsuite/ChangeLog: > > * gcc.target/riscv/rvv/base/float-point-frm-autovec-2.c: New test. > --- > gcc/config/riscv/autovec-opt.md | 36 > gcc/config/riscv/autovec.md | 30 --- > .../rvv/base/float-point-frm-autovec-2.c | 88 +++ > 3 files changed, 127 insertions(+), 27 deletions(-) > create mode 100644 > gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm-autovec-2.c > > diff --git a/gcc/config/riscv/autovec-opt.md b/gcc/config/riscv/autovec-opt.md > index 4b07e80ad95..732a51edacd 100644 > --- a/gcc/config/riscv/autovec-opt.md > +++ b/gcc/config/riscv/autovec-opt.md > @@ -583,13 +583,15 @@ (define_insn_and_split "*single_widen_fnma" > ;; vect__13.182_33 = .FMS (vect__11.180_35, vect__8.176_40, vect__4.172_45); > (define_insn_and_split "*double_widen_fms" >[(set (match_operand:VWEXTF 0 "register_operand") > - (fma:VWEXTF > - (float_extend:VWEXTF > - (match_operand: 2 "register_operand")) > - (float_extend:VWEXTF > - (match_operand: 3 "register_operand")) > - (neg:VWEXTF > - (match_operand:VWEXTF 1 "register_operand"] > + (unspec:VWEXTF > + [(fma:VWEXTF > + (float_extend:VWEXTF > + (match_operand: 2 "register_operand")) > + (float_extend:VWEXTF > + (match_operand: 3 "register_operand")) > + (neg:VWEXTF > + (match_operand:VWEXTF 1 "register_operand"))) > + (reg:SI FRM_REGNUM)] UNSPEC_VFFMA))] >"TARGET_VECTOR && can_create_pseudo_p ()" >"#" >"&& 1" > @@ -600,17 +602,20 @@ (define_insn_and_split "*double_widen_fms" > DONE; >} >[(set_attr "type" "vfwmuladd") > - (set_attr "mode" "")]) > + (set_attr "mode" "") > + (set (attr "frm_mode") (symbol_ref "riscv_vector::FRM_DYN"))]) > > ;; This helps to match ext + fms. > (define_insn_and_split "*single_widen_fms" >[(set (match_operand:VWEXTF 0 "register_operand") > - (fma:VWEXTF > - (float_extend:VWEXTF > - (match_operand: 2 "register_operand")) > - (match_operand:VWEXTF 3 "register_operand") > - (neg:VWEXTF > - (match_operand:VWEXTF 1 "register_operand"] > + (unspec:VWEXTF > + [(fma:VWEXTF > + (float_extend:VWEXTF > + (match_operand: 2 "register_operand")) > + (match_operand:VWEXTF 3 "register_operand") > + (neg:VWEXTF > + (match_operand:VWEXTF 1 "register_operand"))) > + (reg:SI FRM_REGNUM)] UNSPEC_VFFMA))] >"TARGET_VECTOR && can_create_pseudo_p ()" >"#" >"&& 1" > @@ -627,7 +632,8 @@ (define_insn_and_split "*single_widen_fms" > DONE; >} >[(set_attr "type" "vfwmuladd") > - (set_attr "mode" "")]) > + (set_attr "mode" "") > + (set (attr "frm_mode") (symbol_ref "riscv_vector::FRM_DYN"))]) > > ;; - > ;; [FP] VFWNMACC > diff --git a/gcc/config/riscv/autovec.md b/gcc/config/riscv/autovec.md > index 4894986d2a5..d9f1a10eb66 100644 > --- a/gcc/config/riscv/autovec.md > +++ b/gcc/config/riscv/autovec.md > @@ -1218,24 +1218,29 @@ (define_insn_and_split "*fnma" > (define_expand "fms4" >[(parallel > [(set (match_operand:VF 0 "register_operand") > - (fma:VF > - (match_operand:VF 1 "register_operand") > - (match_operand:VF 2 "register_operand") > - (neg:VF > - (match_operand:VF 3 "register_operand" > + (unspec:VF > + [(fma:VF > + (match_operand:VF 1 "register_operand") > + (match_operand:VF 2 "register_operand") > + (neg:VF > + (match_operand:VF 3 "register_operand"))) > +(reg:SI FRM_REGNUM)] UNSPEC_VFFMA)) > (clobber (match_dup 4))])] >"TARGET_VECTOR" >{ > operands[4] = gen_reg_rtx (Pmode); > - }) > + } > + [(set (attr "frm_mode") (symbol_ref "riscv_vector::FRM_DYN"))]) > > (define_insn_and_split "*fms" >
[PATCH v1] RISC-V: Support rounding mode for VFMSAC/VFMSUB autovec
From: Pan Li There will be a case like below for intrinsic and autovec combination. vfadd RTZ <- intrinisc static rounding vfmsub <- autovec/autovec-opt The autovec generated vfmsub should take DYN mode, and the frm must be restored before the vfmsub insn. This patch would like to fix this issue by: * Add the frm operand to the autovec/autovec-opt pattern. * Set the frm_mode attr to DYN. Thus, the frm flow when combine autovec and intrinsic should be. + | frrm a5 | ... | fsrmi 4 | vfadd <- intrinsic static rounding. | ... | fsrm a5 | vfmsub <- autovec/autovec-opt | ... + Signed-off-by: Pan Li gcc/ChangeLog: * config/riscv/autovec-opt.md: Add FRM_REGNUM to vfmsac/vfmsub * config/riscv/autovec.md: Ditto. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/float-point-frm-autovec-2.c: New test. --- gcc/config/riscv/autovec-opt.md | 36 gcc/config/riscv/autovec.md | 30 --- .../rvv/base/float-point-frm-autovec-2.c | 88 +++ 3 files changed, 127 insertions(+), 27 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm-autovec-2.c diff --git a/gcc/config/riscv/autovec-opt.md b/gcc/config/riscv/autovec-opt.md index 4b07e80ad95..732a51edacd 100644 --- a/gcc/config/riscv/autovec-opt.md +++ b/gcc/config/riscv/autovec-opt.md @@ -583,13 +583,15 @@ (define_insn_and_split "*single_widen_fnma" ;; vect__13.182_33 = .FMS (vect__11.180_35, vect__8.176_40, vect__4.172_45); (define_insn_and_split "*double_widen_fms" [(set (match_operand:VWEXTF 0 "register_operand") - (fma:VWEXTF - (float_extend:VWEXTF - (match_operand: 2 "register_operand")) - (float_extend:VWEXTF - (match_operand: 3 "register_operand")) - (neg:VWEXTF - (match_operand:VWEXTF 1 "register_operand"] + (unspec:VWEXTF + [(fma:VWEXTF + (float_extend:VWEXTF + (match_operand: 2 "register_operand")) + (float_extend:VWEXTF + (match_operand: 3 "register_operand")) + (neg:VWEXTF + (match_operand:VWEXTF 1 "register_operand"))) + (reg:SI FRM_REGNUM)] UNSPEC_VFFMA))] "TARGET_VECTOR && can_create_pseudo_p ()" "#" "&& 1" @@ -600,17 +602,20 @@ (define_insn_and_split "*double_widen_fms" DONE; } [(set_attr "type" "vfwmuladd") - (set_attr "mode" "")]) + (set_attr "mode" "") + (set (attr "frm_mode") (symbol_ref "riscv_vector::FRM_DYN"))]) ;; This helps to match ext + fms. (define_insn_and_split "*single_widen_fms" [(set (match_operand:VWEXTF 0 "register_operand") - (fma:VWEXTF - (float_extend:VWEXTF - (match_operand: 2 "register_operand")) - (match_operand:VWEXTF 3 "register_operand") - (neg:VWEXTF - (match_operand:VWEXTF 1 "register_operand"] + (unspec:VWEXTF + [(fma:VWEXTF + (float_extend:VWEXTF + (match_operand: 2 "register_operand")) + (match_operand:VWEXTF 3 "register_operand") + (neg:VWEXTF + (match_operand:VWEXTF 1 "register_operand"))) + (reg:SI FRM_REGNUM)] UNSPEC_VFFMA))] "TARGET_VECTOR && can_create_pseudo_p ()" "#" "&& 1" @@ -627,7 +632,8 @@ (define_insn_and_split "*single_widen_fms" DONE; } [(set_attr "type" "vfwmuladd") - (set_attr "mode" "")]) + (set_attr "mode" "") + (set (attr "frm_mode") (symbol_ref "riscv_vector::FRM_DYN"))]) ;; - ;; [FP] VFWNMACC diff --git a/gcc/config/riscv/autovec.md b/gcc/config/riscv/autovec.md index 4894986d2a5..d9f1a10eb66 100644 --- a/gcc/config/riscv/autovec.md +++ b/gcc/config/riscv/autovec.md @@ -1218,24 +1218,29 @@ (define_insn_and_split "*fnma" (define_expand "fms4" [(parallel [(set (match_operand:VF 0 "register_operand") - (fma:VF - (match_operand:VF 1 "register_operand") - (match_operand:VF 2 "register_operand") - (neg:VF - (match_operand:VF 3 "register_operand" + (unspec:VF + [(fma:VF + (match_operand:VF 1 "register_operand") + (match_operand:VF 2 "register_operand") + (neg:VF + (match_operand:VF 3 "register_operand"))) +(reg:SI FRM_REGNUM)] UNSPEC_VFFMA)) (clobber (match_dup 4))])] "TARGET_VECTOR" { operands[4] = gen_reg_rtx (Pmode); - }) + } + [(set (attr "frm_mode") (symbol_ref "riscv_vector::FRM_DYN"))]) (define_insn_and_split "*fms" [(set (match_operand:VF 0 "register_operand" "=vr, vr, ?&vr") - (fma:VF - (match_operand:VF 1 "register_operand" " %0, vr, vr") - (match_operand:VF 2 "register_operand" " vr, vr, vr") - (neg:VF - (match_operand:VF 3 "register_operand" " vr, 0, vr" + (unspec:VF +