On 9/5/26 2:56 AM, Zhongyao Chen wrote:
The vector FMA patterns currently match multiply/add trees, which lets
combine fuse operations into FMA instructions even with -ffp-contract=off.
Rewrite these patterns using fma rtxes:
- fma/fnma/fms/fnms in autovec.md.
- *dual_widen_*, *single_widen_* in autovec-opt.md.
- .vf patterns in autovec-opt.md:
*vfmacc_vf, *vfmsac_vf,
*vfwmacc_vf_v_f, *vfwmsac_vf_v_f,
*vfwnmacc_vf_neg_v_f, *vfwnmsac_vf_neg_v_f.
Unlike the old (plus (mult ...)) form, fma folds neg and sub into its operands.
Operands with or without neg create different RTL shapes for vector-scalar
pairs. Cover these by adding:
- *vfnmsac_vf_neg_f_v, *vfnmsac_vf_neg_v_f.
- *vfnmacc_vf_neg_f_v, *vfnmacc_vf_neg_v_f.
- *vfwmacc_vf_f_v, *vfwmsac_vf_f_v.
- *vfwnmacc_vf_neg_f_v, *vfwnmsac_vf_neg_f_v.
Also, testing showed vf-3-f32.c regressed. That's because a scalar is
reused across multiple loop statements and shares a single widening broadcast.
Combine failed to match the inlined broadcast and fell back to vfnmsac.vv.
Add to fix it:
- *vfnmsac_vf_extend_f.
And add the remaining three extend_f variants as well:
- *vfnmacc_vf_extend_f, *vfmacc_vf_extend_f, *vfmsac_vf_extend_f.
PR target/126932
gcc/ChangeLog:
* config/riscv/autovec.md: Rewrite vector FMA patterns.
* config/riscv/autovec-opt.md: Likewise and add new patterns.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/autovec/ternop/pr126932.c: New test.
Signed-off-by: Zhongyao Chen <[email protected]>
Thanks for the clarifications during the patchwork call clarifying that
this doesn't really interact with the intrinsics and thus my concern
about creating unrecognized insns wasn't valid. I've pushed this to the
trunk. I'll look at backporting to the relevant release branches next week.
Thanks again!
jeff