aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorChristoph Müllner <christoph.muellner@vrull.eu>2024-05-01 16:54:42 +0200
committerChristoph Müllner <christoph.muellner@vrull.eu>2024-05-15 13:01:45 +0200
commit00029408387e9cc64e135324c22d15cd5a70e946 (patch)
tree3226c8a9414aca5d60eddf0248ac3120818e6771 /gcc
parentc400b2100719d0a9e5989c63e0827b9e98919df3 (diff)
downloadgcc-00029408387e9cc64e135324c22d15cd5a70e946.zip
gcc-00029408387e9cc64e135324c22d15cd5a70e946.tar.gz
gcc-00029408387e9cc64e135324c22d15cd5a70e946.tar.bz2
RISC-V: Add test cases for cpymem expansion
We have two mechanisms in the RISC-V backend that expand cpymem pattern: a) by-pieces, b) riscv_expand_block_move() in riscv-string.cc. The by-pieces framework has higher priority and emits a sequence of up to 15 instructions (see use_by_pieces_infrastructure_p() for more details). As a rule-of-thumb, by-pieces emits alternating load/store sequences and the setmem expansion in the backend emits a sequence of loads followed by a sequence of stores. Let's add some test cases to document the current behaviour and to have tests to identify regressions. Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu> gcc/testsuite/ChangeLog: * gcc.target/riscv/cpymem-32-ooo.c: New test. * gcc.target/riscv/cpymem-32.c: New test. * gcc.target/riscv/cpymem-64-ooo.c: New test. * gcc.target/riscv/cpymem-64.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gcc.target/riscv/cpymem-32-ooo.c131
-rw-r--r--gcc/testsuite/gcc.target/riscv/cpymem-32.c138
-rw-r--r--gcc/testsuite/gcc.target/riscv/cpymem-64-ooo.c129
-rw-r--r--gcc/testsuite/gcc.target/riscv/cpymem-64.c138
4 files changed, 536 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.target/riscv/cpymem-32-ooo.c b/gcc/testsuite/gcc.target/riscv/cpymem-32-ooo.c
new file mode 100644
index 0000000..33fb989
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/cpymem-32-ooo.c
@@ -0,0 +1,131 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target rv32 } */
+/* { dg-options "-march=rv32gc -mabi=ilp32d -mtune=generic-ooo" } */
+/* { dg-skip-if "" { *-*-* } {"-O0" "-Os" "-Og" "-Oz" "-flto" } } */
+/* { dg-final { check-function-bodies "**" "" } } */
+/* { dg-allow-blank-lines-in-output 1 } */
+
+#define COPY_N(N) \
+void copy_##N (void *to, void *from) \
+{ \
+ __builtin_memcpy (to, from, N); \
+}
+
+#define COPY_ALIGNED_N(N) \
+void copy_aligned_##N (void *to, void *from) \
+{ \
+ to = __builtin_assume_aligned(to, sizeof(long)); \
+ from = __builtin_assume_aligned(from, sizeof(long)); \
+ __builtin_memcpy (to, from, N); \
+}
+
+/*
+**copy_7:
+** ...
+** lw\t[at][0-9],0\([at][0-9]\)
+** sw\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],6\([at][0-9]\)
+** sb\t[at][0-9],6\([at][0-9]\)
+** ...
+*/
+COPY_N(7)
+
+/*
+**copy_aligned_7:
+** ...
+** lw\t[at][0-9],0\([at][0-9]\)
+** sw\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],6\([at][0-9]\)
+** sb\t[at][0-9],6\([at][0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(7)
+
+/*
+**copy_8:
+** ...
+** lw\ta[0-9],0\(a[0-9]\)
+** sw\ta[0-9],0\(a[0-9]\)
+** ...
+*/
+COPY_N(8)
+
+/*
+**copy_aligned_8:
+** ...
+** lw\ta[0-9],0\(a[0-9]\)
+** sw\ta[0-9],0\(a[0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(8)
+
+/*
+**copy_11:
+** ...
+** lbu\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],10\([at][0-9]\)
+** ...
+** sb\t[at][0-9],0\([at][0-9]\)
+** ...
+** sb\t[at][0-9],10\([at][0-9]\)
+** ...
+*/
+COPY_N(11)
+
+/*
+**copy_aligned_11:
+** ...
+** lw\t[at][0-9],0\([at][0-9]\)
+** ...
+** sw\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],10\([at][0-9]\)
+** sb\t[at][0-9],10\([at][0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(11)
+
+/*
+**copy_15:
+** ...
+** (call|tail)\tmemcpy
+** ...
+*/
+COPY_N(15)
+
+/*
+**copy_aligned_15:
+** ...
+** lw\t[at][0-9],0\([at][0-9]\)
+** ...
+** sw\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],14\([at][0-9]\)
+** sb\t[at][0-9],14\([at][0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(15)
+
+/*
+**copy_27:
+** ...
+** (call|tail)\tmemcpy
+** ...
+*/
+COPY_N(27)
+
+/*
+**copy_aligned_27:
+** ...
+** lw\t[at][0-9],20\([at][0-9]\)
+** ...
+** sw\t[at][0-9],20\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],26\([at][0-9]\)
+** sb\t[at][0-9],26\([at][0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(27)
diff --git a/gcc/testsuite/gcc.target/riscv/cpymem-32.c b/gcc/testsuite/gcc.target/riscv/cpymem-32.c
new file mode 100644
index 0000000..44ba14a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/cpymem-32.c
@@ -0,0 +1,138 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target rv32 } */
+/* { dg-options "-march=rv32gc -mabi=ilp32d -mtune=rocket" } */
+/* { dg-skip-if "" { *-*-* } {"-O0" "-Os" "-Og" "-Oz" "-flto" } } */
+/* { dg-final { check-function-bodies "**" "" } } */
+/* { dg-allow-blank-lines-in-output 1 } */
+
+#define COPY_N(N) \
+void copy_##N (void *to, void *from) \
+{ \
+ __builtin_memcpy (to, from, N); \
+}
+
+#define COPY_ALIGNED_N(N) \
+void copy_aligned_##N (void *to, void *from) \
+{ \
+ to = __builtin_assume_aligned(to, sizeof(long)); \
+ from = __builtin_assume_aligned(from, sizeof(long)); \
+ __builtin_memcpy (to, from, N); \
+}
+
+/*
+**copy_7:
+** ...
+** lbu\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],6\([at][0-9]\)
+** ...
+** sb\t[at][0-9],0\([at][0-9]\)
+** ...
+** sb\t[at][0-9],6\([at][0-9]\)
+** ...
+*/
+COPY_N(7)
+
+/*
+**copy_aligned_7:
+** ...
+** lw\t[at][0-9],0\([at][0-9]\)
+** sw\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],6\([at][0-9]\)
+** sb\t[at][0-9],6\([at][0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(7)
+
+/*
+**copy_8:
+** ...
+** lbu\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],7\([at][0-9]\)
+** ...
+** sb\t[at][0-9],0\([at][0-9]\)
+** ...
+** sb\t[at][0-9],7\([at][0-9]\)
+** ...
+*/
+COPY_N(8)
+
+/*
+**copy_aligned_8:
+** ...
+** lw\ta[0-9],0\(a[0-9]\)
+** sw\ta[0-9],0\(a[0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(8)
+
+/*
+**copy_11:
+** ...
+** lbu\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],10\([at][0-9]\)
+** ...
+** sb\t[at][0-9],0\([at][0-9]\)
+** ...
+** sb\t[at][0-9],10\([at][0-9]\)
+** ...
+*/
+COPY_N(11)
+
+/*
+**copy_aligned_11:
+** ...
+** lw\t[at][0-9],0\([at][0-9]\)
+** ...
+** sw\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],10\([at][0-9]\)
+** sb\t[at][0-9],10\([at][0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(11)
+
+/*
+**copy_15:
+** ...
+** (call|tail)\tmemcpy
+** ...
+*/
+COPY_N(15)
+
+/*
+**copy_aligned_15:
+** ...
+** lw\t[at][0-9],0\([at][0-9]\)
+** ...
+** sw\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],14\([at][0-9]\)
+** sb\t[at][0-9],14\([at][0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(15)
+
+/*
+**copy_27:
+** ...
+** (call|tail)\tmemcpy
+** ...
+*/
+COPY_N(27)
+
+/*
+**copy_aligned_27:
+** ...
+** lw\t[at][0-9],20\([at][0-9]\)
+** ...
+** sw\t[at][0-9],20\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],26\([at][0-9]\)
+** sb\t[at][0-9],26\([at][0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(27)
diff --git a/gcc/testsuite/gcc.target/riscv/cpymem-64-ooo.c b/gcc/testsuite/gcc.target/riscv/cpymem-64-ooo.c
new file mode 100644
index 0000000..8e40e52
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/cpymem-64-ooo.c
@@ -0,0 +1,129 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target rv64 } */
+/* { dg-options "-march=rv64gc -mabi=lp64d -mtune=generic-ooo" } */
+/* { dg-skip-if "" { *-*-* } {"-O0" "-Os" "-Og" "-Oz" "-flto" } } */
+/* { dg-final { check-function-bodies "**" "" } } */
+/* { dg-allow-blank-lines-in-output 1 } */
+
+#define COPY_N(N) \
+void copy_##N (void *to, void *from) \
+{ \
+ __builtin_memcpy (to, from, N); \
+}
+
+#define COPY_ALIGNED_N(N) \
+void copy_aligned_##N (void *to, void *from) \
+{ \
+ to = __builtin_assume_aligned(to, sizeof(long)); \
+ from = __builtin_assume_aligned(from, sizeof(long)); \
+ __builtin_memcpy (to, from, N); \
+}
+
+/*
+**copy_7:
+** ...
+** lw\t[at][0-9],0\([at][0-9]\)
+** sw\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],6\([at][0-9]\)
+** sb\t[at][0-9],6\([at][0-9]\)
+** ...
+*/
+COPY_N(7)
+
+/*
+**copy_aligned_7:
+** ...
+** lw\t[at][0-9],0\([at][0-9]\)
+** sw\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],6\([at][0-9]\)
+** sb\t[at][0-9],6\([at][0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(7)
+
+/*
+**copy_8:
+** ...
+** ld\ta[0-9],0\(a[0-9]\)
+** sd\ta[0-9],0\(a[0-9]\)
+** ...
+*/
+COPY_N(8)
+
+/*
+**copy_aligned_8:
+** ...
+** ld\ta[0-9],0\(a[0-9]\)
+** sd\ta[0-9],0\(a[0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(8)
+
+/*
+**copy_11:
+** ...
+** ld\t[at][0-9],0\([at][0-9]\)
+** sd\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],10\([at][0-9]\)
+** sb\t[at][0-9],10\([at][0-9]\)
+** ...
+*/
+COPY_N(11)
+
+/*
+**copy_aligned_11:
+** ...
+** ld\t[at][0-9],0\([at][0-9]\)
+** ...
+** sd\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],10\([at][0-9]\)
+** sb\t[at][0-9],10\([at][0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(11)
+
+/*
+**copy_15:
+** ...
+** (call|tail)\tmemcpy
+** ...
+*/
+COPY_N(15)
+
+/*
+**copy_aligned_15:
+** ...
+** ld\t[at][0-9],0\([at][0-9]\)
+** ...
+** sd\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],14\([at][0-9]\)
+** sb\t[at][0-9],14\([at][0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(15)
+
+/*
+**copy_27:
+** ...
+** (call|tail)\tmemcpy
+** ...
+*/
+COPY_N(27)
+
+/*
+**copy_aligned_27:
+** ...
+** ld\t[at][0-9],16\([at][0-9]\)
+** ...
+** sd\t[at][0-9],16\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],26\([at][0-9]\)
+** sb\t[at][0-9],26\([at][0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(27)
diff --git a/gcc/testsuite/gcc.target/riscv/cpymem-64.c b/gcc/testsuite/gcc.target/riscv/cpymem-64.c
new file mode 100644
index 0000000..bdfaca0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/cpymem-64.c
@@ -0,0 +1,138 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target rv64 } */
+/* { dg-options "-march=rv64gc -mabi=lp64d -mtune=rocket" } */
+/* { dg-skip-if "" { *-*-* } {"-O0" "-Os" "-Og" "-Oz" "-flto" } } */
+/* { dg-final { check-function-bodies "**" "" } } */
+/* { dg-allow-blank-lines-in-output 1 } */
+
+#define COPY_N(N) \
+void copy_##N (void *to, void *from) \
+{ \
+ __builtin_memcpy (to, from, N); \
+}
+
+#define COPY_ALIGNED_N(N) \
+void copy_aligned_##N (void *to, void *from) \
+{ \
+ to = __builtin_assume_aligned(to, sizeof(long)); \
+ from = __builtin_assume_aligned(from, sizeof(long)); \
+ __builtin_memcpy (to, from, N); \
+}
+
+/*
+**copy_7:
+** ...
+** lbu\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],6\([at][0-9]\)
+** ...
+** sb\t[at][0-9],0\([at][0-9]\)
+** ...
+** sb\t[at][0-9],6\([at][0-9]\)
+** ...
+*/
+COPY_N(7)
+
+/*
+**copy_aligned_7:
+** ...
+** lw\t[at][0-9],0\([at][0-9]\)
+** sw\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],6\([at][0-9]\)
+** sb\t[at][0-9],6\([at][0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(7)
+
+/*
+**copy_8:
+** ...
+** lbu\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],7\([at][0-9]\)
+** ...
+** sb\t[at][0-9],0\([at][0-9]\)
+** ...
+** sb\t[at][0-9],7\([at][0-9]\)
+** ...
+*/
+COPY_N(8)
+
+/*
+**copy_aligned_8:
+** ...
+** ld\ta[0-9],0\(a[0-9]\)
+** sd\ta[0-9],0\(a[0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(8)
+
+/*
+**copy_11:
+** ...
+** lbu\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],10\([at][0-9]\)
+** ...
+** sb\t[at][0-9],0\([at][0-9]\)
+** ...
+** sb\t[at][0-9],10\([at][0-9]\)
+** ...
+*/
+COPY_N(11)
+
+/*
+**copy_aligned_11:
+** ...
+** ld\t[at][0-9],0\([at][0-9]\)
+** ...
+** sd\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],10\([at][0-9]\)
+** sb\t[at][0-9],10\([at][0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(11)
+
+/*
+**copy_15:
+** ...
+** (call|tail)\tmemcpy
+** ...
+*/
+COPY_N(15)
+
+/*
+**copy_aligned_15:
+** ...
+** ld\t[at][0-9],0\([at][0-9]\)
+** ...
+** sd\t[at][0-9],0\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],14\([at][0-9]\)
+** sb\t[at][0-9],14\([at][0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(15)
+
+/*
+**copy_27:
+** ...
+** (call|tail)\tmemcpy
+** ...
+*/
+COPY_N(27)
+
+/*
+**copy_aligned_27:
+** ...
+** ld\t[at][0-9],16\([at][0-9]\)
+** ...
+** sd\t[at][0-9],16\([at][0-9]\)
+** ...
+** lbu\t[at][0-9],26\([at][0-9]\)
+** sb\t[at][0-9],26\([at][0-9]\)
+** ...
+*/
+COPY_ALIGNED_N(27)