On 12/26/23 19:38, Juzhe-Zhong wrote:
Notice we have this following situation:

         vsetivli        zero,4,e32,m1,ta,ma
         vlseg4e32.v     v4,(a5)
         vlseg4e32.v     v12,(a3)
         vsetvli a5,zero,e32,m1,tu,ma             ---> This is redundant since 
VLMAX AVL = 4 when it is fixed-vlmax
         vfadd.vf        v3,v13,fa0
         vfadd.vf        v1,v12,fa1
         vfmul.vv        v17,v3,v5
         vfmul.vv        v16,v1,v5

The rootcause is that we transform COND_LEN_xxx into VLMAX AVL when len == 
NUNITS blindly.
However, we don't need to transform all of them since when len is range of 
[0,31], we don't need to
consume scalar registers.

After this patch:

        vsetivli        zero,4,e32,m1,tu,ma
        addi    a4,a5,400
        vlseg4e32.v     v12,(a3)
        vfadd.vf        v3,v13,fa0
        vfadd.vf        v1,v12,fa1
        vlseg4e32.v     v4,(a4)
        vfadd.vf        v2,v14,fa1
        vfmul.vv        v17,v3,v5
        vfmul.vv        v16,v1,v5

Tested on both RV32 and RV64 no regression.
So it looks like the two fragments above are from different sources, though I guess it's also possible one of the cut-n-pastes just got truncated. Note the differing number of vfadd intructions. That doesn't invalidate the patch, but does make it slightly harder to reason about what you're doing.



Ok for trunk ?

gcc/ChangeLog:

        * config/riscv/riscv-v.cc (is_vlmax_len_p): New function.
        (expand_load_store): Disallow transformation into VLMAX when len is in 
range of [0,31]
        (expand_cond_len_op): Ditto.
        (expand_gather_scatter): Ditto.
        (expand_lanes_load_store): Ditto.
        (expand_fold_extract_last): Ditto.

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/rvv/autovec/post-ra-avl.c: Adapt test.
        * gcc.target/riscv/rvv/base/vf_avl-2.c: New test.

---
  gcc/config/riscv/riscv-v.cc                   | 21 +++++++++++++------
  .../riscv/rvv/autovec/post-ra-avl.c           |  2 +-
  .../gcc.target/riscv/rvv/base/vf_avl-2.c      | 21 +++++++++++++++++++
  3 files changed, 37 insertions(+), 7 deletions(-)
  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/vf_avl-2.c

diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc
index 038ab084a37..0cc7af58da6 100644
--- a/gcc/config/riscv/riscv-v.cc
+++ b/gcc/config/riscv/riscv-v.cc
@@ -68,6 +68,16 @@ imm_avl_p (machine_mode mode)
           : false;
  }
+/* Return true if LEN is equal to NUNITS that outbounds range of [0, 31]. */
Perhaps "that is out of the range [0, 31]."?

OK with the comment nit fixed.
jeff

Reply via email to