https://gcc.gnu.org/g:3993646dcfd9fe06eaca5d0252589487444c7ef5
commit 3993646dcfd9fe06eaca5d0252589487444c7ef5 Author: Christoph Müllner <christoph.muell...@vrull.eu> Date: Wed May 1 16:54:42 2024 +0200 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.muell...@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. (cherry picked from commit 00029408387e9cc64e135324c22d15cd5a70e946) Diff: --- gcc/testsuite/gcc.target/riscv/cpymem-32-ooo.c | 131 +++++++++++++++++++++++ gcc/testsuite/gcc.target/riscv/cpymem-32.c | 138 +++++++++++++++++++++++++ gcc/testsuite/gcc.target/riscv/cpymem-64-ooo.c | 129 +++++++++++++++++++++++ gcc/testsuite/gcc.target/riscv/cpymem-64.c | 138 +++++++++++++++++++++++++ 4 files changed, 536 insertions(+) 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 00000000000..33fb9891d82 --- /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 00000000000..44ba14a1d51 --- /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 00000000000..8e40e52fa91 --- /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 00000000000..bdfaca0d46a --- /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)