RISC-V: Add vectorized strlen.
commit2664964b2f695e947faea4c29dbddd3615cc4b0b
authorRobin Dapp <rdapp@ventanamicro.com>
Fri, 1 Dec 2023 08:57:15 +0000 (1 09:57 +0100)
committerRobin Dapp <rdapp@ventanamicro.com>
Fri, 8 Dec 2023 16:31:50 +0000 (8 17:31 +0100)
tree5e248edd698e3bc6f8e5c32d6a19ef69e359f29f
parent8b5cd6c4519cc120badd2b35a9e30d4deb82c012
RISC-V: Add vectorized strlen.

This patch implements a vectorized strlen by re-using and slightly
adjusting the rawmemchr implementation.  Rawmemchr returns the address
of the needle while strlen returns the difference between needle address
and start address.

As before, strlen expansion is guarded by -minline-strlen.

While testing with -minline-strlen I encountered a vsetvl problem in
memcpy-chk.c where we didn't insert a vsetvl at the proper spot (after
a setjmp).  This needs to be fixed separately and I figured I'd post
this patch as-is.

gcc/ChangeLog:

PR target/112109

* config/riscv/riscv-protos.h (expand_rawmemchr): Add strlen
parameter.
* config/riscv/riscv-string.cc (riscv_expand_strlen): Call
rawmemchr.
(expand_rawmemchr): Add strlen handling.
* config/riscv/riscv.md: Add TARGET_VECTOR to strlen expander.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/builtin/strlen-run.c: New test.
* gcc.target/riscv/rvv/autovec/builtin/strlen.c: New test.
gcc/config/riscv/riscv-protos.h
gcc/config/riscv/riscv-string.cc
gcc/config/riscv/riscv.md
gcc/testsuite/gcc.target/riscv/rvv/autovec/builtin/strlen-run.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/rvv/autovec/builtin/strlen.c [new file with mode: 0644]