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.
---
 gcc/config/riscv/riscv-string.cc                    |  4 +++-
 .../riscv/rvv/base/cpymem-size-threshold-move.c     | 13 +++++++++++++
 .../riscv/rvv/base/cpymem-size-threshold.c          | 12 ++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-size-threshold-move.c
 create mode 100644 
gcc/testsuite/gcc.target/riscv/rvv/base/cpymem-size-threshold.c

diff --git a/gcc/config/riscv/riscv-string.cc b/gcc/config/riscv/riscv-string.cc
index 67aaae7c1e4..b0b7efece91 100644
--- a/gcc/config/riscv/riscv-string.cc
+++ b/gcc/config/riscv/riscv-string.cc
@@ -1452,7 +1452,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 00000000000..37637e872ac
--- /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 00000000000..c8fdbdcfadc
--- /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" } } */
-- 
2.52.0

Reply via email to