]> gcc.gnu.org Git - gcc.git/commitdiff
RISC-V: Add test cases for cpymem expansion
authorChristoph Müllner <christoph.muellner@vrull.eu>
Wed, 1 May 2024 14:54:42 +0000 (16:54 +0200)
committerChristoph Müllner <christoph.muellner@vrull.eu>
Wed, 15 May 2024 11:01:45 +0000 (13:01 +0200)
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.

gcc/testsuite/gcc.target/riscv/cpymem-32-ooo.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/cpymem-32.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/cpymem-64-ooo.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/cpymem-64.c [new file with mode: 0644]

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 (file)
index 0000000..33fb989
--- /dev/null
@@ -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 (file)
index 0000000..44ba14a
--- /dev/null
@@ -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 (file)
index 0000000..8e40e52
--- /dev/null
@@ -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 (file)
index 0000000..bdfaca0
--- /dev/null
@@ -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)
This page took 0.074313 seconds and 5 git commands to generate.