From: Kito Cheng Date: Mon, 5 Aug 2019 07:54:31 +0000 (+0000) Subject: RISC-V: Promote type correctly for libcalls X-Git-Tag: releases/gcc-9.2.0~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41e094840be3fc6dc92875aa41c25f8077a1f8e3;p=thirdparty%2Fgcc.git RISC-V: Promote type correctly for libcalls - argument and return value for libcall won't promote at default_promote_function_mode_always_promote, however we expect it should sign-extend as normal function. - Witout this patch, this test case will fail at -march=rv64i -mabi=lp64. - The implementation of riscv_promote_function_mode is borrowed from MIPS. gcc/ChangeLog Backport from mainline 2019-08-05 Kito Cheng * config/riscv/riscv.c (riscv_promote_function_mode): New. (TARGET_PROMOTE_FUNCTION_MODE): Use riscv_promote_function_mode. gcc/testsuite/ChangeLog Backport from mainline 2019-08-05 Kito Cheng * gcc.target/riscv/promote-type-for-libcall.c: New. From-SVN: r274108 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index adfb36f471f0..43352cf059aa 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2019-08-05 Kito Cheng + + Backport from mainline + 2019-08-05 Kito Cheng + + * config/riscv/riscv.c (riscv_promote_function_mode): New. + (TARGET_PROMOTE_FUNCTION_MODE): Use riscv_promote_function_mode. + 2019-08-05 Alan Modra PR target/91349 diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c index e7440f390951..35219956c80d 100644 --- a/gcc/config/riscv/riscv.c +++ b/gcc/config/riscv/riscv.c @@ -4866,6 +4866,32 @@ riscv_constant_alignment (const_tree exp, HOST_WIDE_INT align) return align; } +/* Implement TARGET_PROMOTE_FUNCTION_MODE. */ + +/* This function is equivalent to default_promote_function_mode_always_promote + except that it returns a promoted mode even if type is NULL_TREE. This is + needed by libcalls which have no type (only a mode) such as fixed conversion + routines that take a signed or unsigned char/short/int argument and convert + it to a fixed type. */ + +static machine_mode +riscv_promote_function_mode (const_tree type ATTRIBUTE_UNUSED, + machine_mode mode, + int *punsignedp ATTRIBUTE_UNUSED, + const_tree fntype ATTRIBUTE_UNUSED, + int for_return ATTRIBUTE_UNUSED) +{ + int unsignedp; + + if (type != NULL_TREE) + return promote_mode (type, mode, punsignedp); + + unsignedp = *punsignedp; + PROMOTE_MODE (mode, unsignedp, type); + *punsignedp = unsignedp; + return mode; +} + /* Initialize the GCC target structure. */ #undef TARGET_ASM_ALIGNED_HI_OP #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t" @@ -4907,7 +4933,7 @@ riscv_constant_alignment (const_tree exp, HOST_WIDE_INT align) #define TARGET_EXPAND_BUILTIN_VA_START riscv_va_start #undef TARGET_PROMOTE_FUNCTION_MODE -#define TARGET_PROMOTE_FUNCTION_MODE default_promote_function_mode_always_promote +#define TARGET_PROMOTE_FUNCTION_MODE riscv_promote_function_mode #undef TARGET_RETURN_IN_MEMORY #define TARGET_RETURN_IN_MEMORY riscv_return_in_memory diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 52dac078b697..d3dfb79507ca 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2019-08-05 Kito Cheng + + Backport from mainline + 2019-08-05 Kito Cheng + + * gcc.target/riscv/promote-type-for-libcall.c: New. + 2019-08-04 Jerry DeLisle Backport from mainline. diff --git a/gcc/testsuite/gcc.target/riscv/promote-type-for-libcall.c b/gcc/testsuite/gcc.target/riscv/promote-type-for-libcall.c new file mode 100644 index 000000000000..bdbcbc0316a7 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/promote-type-for-libcall.c @@ -0,0 +1,37 @@ +/* { dg-do run } */ +/* { dg-options "-O1 -ftree-slp-vectorize -funroll-loops" } */ + +#include +#include +#define N 4 +volatile float f[N]; +int x[N] __attribute__((aligned(8))); +int main() { + int i; + x[0] = -1; + x[1] = 2; + x[2] = -2; + x[3] = 2; + + for (i=0;i