https://gcc.gnu.org/g:ae764adb0ce2ff560542b507799fa28e818f191d
commit r17-6551-gae764adb0ce2ff560542b507799fa28e818f191d Author: Jin Ma <[email protected]> Date: Thu Nov 19 17:04:08 2026 +0800 RISC-V: Fix the memcpy threshold check for runtime lengths The vector copy expander tests the memmove threshold for runtime lengths. Select the threshold for the actual operation so setting one does not affect the other. Assisted-by: qwenwork gcc/ChangeLog: * config/riscv/riscv-string.cc (expand_block_move): Select the threshold for the operation. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/cpymem-size-threshold.c: New test. * gcc.target/riscv/rvv/base/cpymem-size-threshold-move.c: New test. Diff: --- gcc/config/riscv/riscv-string.cc | 4 +++- .../gcc.target/riscv/rvv/base/cpymem-size-threshold-move.c | 13 +++++++++++++ .../gcc.target/riscv/rvv/base/cpymem-size-threshold.c | 12 ++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/gcc/config/riscv/riscv-string.cc b/gcc/config/riscv/riscv-string.cc index afbaf0b95c0e..4eb4bfd72459 100644 --- a/gcc/config/riscv/riscv-string.cc +++ b/gcc/config/riscv/riscv-string.cc @@ -1442,7 +1442,9 @@ expand_block_move (rtx dst_in, rtx src_in, rtx length_in, bool overlap_p) && length > riscv_memcpy_size_threshold) return false; } - else if (riscv_memmove_size_threshold != -1) + else if ((overlap_p + ? riscv_memmove_size_threshold + : riscv_memcpy_size_threshold) != -1) return false; /* Inlining general memmove is a pessimisation: we can't avoid having to diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-size-threshold-move.c b/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-size-threshold-move.c new file mode 100644 index 000000000000..37637e872ac6 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-size-threshold-move.c @@ -0,0 +1,13 @@ +/* { dg-do compile { target rv64 } } */ +/* { dg-options "-O2 -march=rv64gcv -mabi=lp64d" } */ +/* { dg-additional-options "-mstringop-strategy=vector" } */ +/* { dg-additional-options "--param=memmove-size-threshold=512" } */ + +void +copy (void *dst, const void *src, __SIZE_TYPE__ n) +{ + __builtin_memcpy (dst, src, n); +} + +/* { dg-final { scan-assembler-not "\\t(call|tail)\\tmemcpy" } } */ +/* { dg-final { scan-assembler "\\tvle8\\.v\\t" } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-size-threshold.c b/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-size-threshold.c new file mode 100644 index 000000000000..c8fdbdcfadcc --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-size-threshold.c @@ -0,0 +1,12 @@ +/* { dg-do compile { target rv64 } } */ +/* { dg-options "-O2 -march=rv64gcv -mabi=lp64d" } */ +/* { dg-additional-options "-mstringop-strategy=vector" } */ +/* { dg-additional-options "--param=memcpy-size-threshold=512" } */ + +void +copy (void *dst, const void *src, __SIZE_TYPE__ n) +{ + __builtin_memcpy (dst, src, n); +} + +/* { dg-final { scan-assembler "\\t(call|tail)\\tmemcpy" } } */
