From c5c7f1ef5ffcabb7dcbdc96571dbe1b0d675d4a5 Mon Sep 17 00:00:00 2001 From: Lehua Ding Date: Tue, 18 Jul 2023 15:34:40 +0800 Subject: RISC-V: Fix testcase failed when default -mcmodel=medany This patch fix testcase failed when I build RISC-V GCC with -mcmodel=medany as default. If set to medany, stack_save_restore.c testcase will fail because of the reduced use of s3 registers in assembly (thus calling __riscv_save/store_3 instead of __riscv_save/store_4). So relax assert from `__riscv_save/restore_4` to `__riscv_save/restore_(3|4)` to let this testcase not brittle on any -mcmodel and add another testcase that use -march=rv64imafc. gcc/testsuite/ChangeLog: * gcc.target/riscv/stack_save_restore.c: Moved to... * gcc.target/riscv/stack_save_restore_2.c: ...here. * gcc.target/riscv/stack_save_restore_1.c: New test. --- .../gcc.target/riscv/stack_save_restore.c | 40 ---------------------- .../gcc.target/riscv/stack_save_restore_1.c | 40 ++++++++++++++++++++++ .../gcc.target/riscv/stack_save_restore_2.c | 40 ++++++++++++++++++++++ 3 files changed, 80 insertions(+), 40 deletions(-) delete mode 100644 gcc/testsuite/gcc.target/riscv/stack_save_restore.c create mode 100644 gcc/testsuite/gcc.target/riscv/stack_save_restore_1.c create mode 100644 gcc/testsuite/gcc.target/riscv/stack_save_restore_2.c (limited to 'gcc') diff --git a/gcc/testsuite/gcc.target/riscv/stack_save_restore.c b/gcc/testsuite/gcc.target/riscv/stack_save_restore.c deleted file mode 100644 index 522e706..0000000 --- a/gcc/testsuite/gcc.target/riscv/stack_save_restore.c +++ /dev/null @@ -1,40 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-march=rv32imafc -mabi=ilp32f -msave-restore -O2 -fno-schedule-insns -fno-schedule-insns2 -fno-unroll-loops -fno-peel-loops -fno-lto" } */ -/* { dg-final { check-function-bodies "**" "" } } */ - -char my_getchar(); -float getf(); - -/* -**bar: -** call t0,__riscv_save_4 -** addi sp,sp,-2032 -** ... -** li t0,-12288 -** add sp,sp,t0 -** ... -** li t0,12288 -** add sp,sp,t0 -** ... -** addi sp,sp,2032 -** tail __riscv_restore_4 -*/ -int bar() -{ - float volatile farray[3568]; - - float sum = 0; - float f1 = getf(); - float f2 = getf(); - float f3 = getf(); - float f4 = getf(); - - for (int i = 0; i < 3568; i++) - { - farray[i] = my_getchar() * 1.2; - sum += farray[i]; - } - - return sum + f1 + f2 + f3 + f4; -} - diff --git a/gcc/testsuite/gcc.target/riscv/stack_save_restore_1.c b/gcc/testsuite/gcc.target/riscv/stack_save_restore_1.c new file mode 100644 index 0000000..255ce5f --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/stack_save_restore_1.c @@ -0,0 +1,40 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64imafc -mabi=lp64f -msave-restore -O2 -fno-schedule-insns -fno-schedule-insns2 -fno-unroll-loops -fno-peel-loops -fno-lto" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +char my_getchar(); +float getf(); + +/* +** bar: +** call t0,__riscv_save_(3|4) +** addi sp,sp,-2032 +** ... +** li t0,-12288 +** add sp,sp,t0 +** ... +** li t0,12288 +** add sp,sp,t0 +** ... +** addi sp,sp,2032 +** tail __riscv_restore_(3|4) +*/ +int bar() +{ + float volatile farray[3568]; + + float sum = 0; + float f1 = getf(); + float f2 = getf(); + float f3 = getf(); + float f4 = getf(); + + for (int i = 0; i < 3568; i++) + { + farray[i] = my_getchar() * 1.2; + sum += farray[i]; + } + + return sum + f1 + f2 + f3 + f4; +} + diff --git a/gcc/testsuite/gcc.target/riscv/stack_save_restore_2.c b/gcc/testsuite/gcc.target/riscv/stack_save_restore_2.c new file mode 100644 index 0000000..4ce5e01 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/stack_save_restore_2.c @@ -0,0 +1,40 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv32imafc -mabi=ilp32f -msave-restore -O2 -fno-schedule-insns -fno-schedule-insns2 -fno-unroll-loops -fno-peel-loops -fno-lto" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +char my_getchar(); +float getf(); + +/* +** bar: +** call t0,__riscv_save_(3|4) +** addi sp,sp,-2032 +** ... +** li t0,-12288 +** add sp,sp,t0 +** ... +** li t0,12288 +** add sp,sp,t0 +** ... +** addi sp,sp,2032 +** tail __riscv_restore_(3|4) +*/ +int bar() +{ + float volatile farray[3568]; + + float sum = 0; + float f1 = getf(); + float f2 = getf(); + float f3 = getf(); + float f4 = getf(); + + for (int i = 0; i < 3568; i++) + { + farray[i] = my_getchar() * 1.2; + sum += farray[i]; + } + + return sum + f1 + f2 + f3 + f4; +} + -- cgit v1.1