Respin of https://gcc.gnu.org/pipermail/gcc-patches/2025-August/691426.html but separates the middle end vectorizer changes from the RISC-V target specific changes.
The patch changes the riscv loop codegen from vsetvli a5,a2,e32,m1,ta,mu vle32.v v1,0(a1) slli a4,a5,2 sub a2,a2,a5 add a1,a1,a4 vmsgtu.vx v0,v1,a3 vrsub.vi v2,v1,0 vsra.vi v1,v2,31,v0.t vsetvli zero,zero,e16,mf2,ta,ma vnsrl.wi v1,v1,0 vsetvli zero,zero,e8,mf4,ta,ma vnsrl.wi v1,v1,0 vse8.v v1,0(a0) to vsetvli a5,a2,e32,m1,ta,ma vle32.v v1,0(a1) slli a4,a5,2 sub a2,a2,a5 add a1,a1,a4 vmax.vv v1,v1,v2 <-- v2 defined by `vmv.v.i v2,0` outside vsetvli zero,zero,e16,mf2,ta,ma vnclipu.wi v1,v1,0 vsetvli zero,zero,e8,mf4,ta,ma vnclipu.wi v1,v1,0 vse8.v v1,0(a0) which is closer to how clang vectorizes the pattern. Edwin Lu (2): Match: Support SAT_TRUNC variant NARROW_CLIP RISC-V: Support vnclip idiom testcase [PR120378] --- V2: - Add more testcases - Try to clarify the pattern matching code comments --- gcc/match.pd | 26 +++++++++++++++ .../gcc.target/riscv/rvv/autovec/pr120378-1.c | 21 ++++++++++++ .../gcc.target/riscv/rvv/autovec/pr120378-2.c | 21 ++++++++++++ .../gcc.target/riscv/rvv/autovec/pr120378-3.c | 21 ++++++++++++ .../gcc.target/riscv/rvv/autovec/pr120378-4.c | 21 ++++++++++++ .../gcc.target/riscv/rvv/autovec/pr120378-5.c | 21 ++++++++++++ gcc/tree-vect-patterns.cc | 32 +++++++++++++++++++ 7 files changed, 163 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-3.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-4.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr120378-5.c -- 2.43.0