From: Guo Jie Date: Sun, 2 Nov 2025 02:01:06 +0000 (+0800) Subject: LoongArch: Improve TARGET_CAN_CHANGE_MODE_CLASS implementation X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fbd9051a96a3a2e7ee7db5524e79e42c6477ef65;p=thirdparty%2Fgcc.git LoongArch: Improve TARGET_CAN_CHANGE_MODE_CLASS implementation Support for conversion between scalar INT and scalar FP. gcc/ChangeLog: * config/loongarch/loongarch.cc (loongarch_can_change_mode_class): Support for conversion between scalar INT and scalar FP. gcc/testsuite/ChangeLog: * gcc.target/loongarch/extendsidi2-combine.c: New test. * gcc.target/loongarch/spill-less.c: New test. --- diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 735753ad7e2..ecc7e21f49c 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -7108,6 +7108,10 @@ static bool loongarch_can_change_mode_class (machine_mode from, machine_mode to, reg_class_t rclass) { + if ((INTEGRAL_MODE_P (from) && FLOAT_MODE_P (to)) + || (INTEGRAL_MODE_P (to) && FLOAT_MODE_P (from))) + return true; + /* Allow conversions between different LSX/LASX vector modes. */ if (LASX_SUPPORTED_MODE_P (from) && LASX_SUPPORTED_MODE_P (to)) return true; diff --git a/gcc/testsuite/gcc.target/loongarch/extendsidi2-combine.c b/gcc/testsuite/gcc.target/loongarch/extendsidi2-combine.c new file mode 100644 index 00000000000..0c3613c0efd --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/extendsidi2-combine.c @@ -0,0 +1,13 @@ +/* { dg-do compile { target { loongarch64*-*-* } } } */ +/* { dg-options "-O3 -fno-strict-aliasing" } */ + +int +test (double a) +{ + int z; + + *((double *)&z) = a; + return z; +} + +/* { dg-final { scan-assembler-not "slli\\.w" } } */ diff --git a/gcc/testsuite/gcc.target/loongarch/spill-less.c b/gcc/testsuite/gcc.target/loongarch/spill-less.c new file mode 100644 index 00000000000..77eb9b5963b --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/spill-less.c @@ -0,0 +1,14 @@ +/* { dg-do compile { target { loongarch64*-*-* } } } */ +/* { dg-options "-O3 -fno-strict-aliasing" } */ + +double +convert (long long in) +{ + double f; + *((long long *)&f) = in; + return f; +} + +/* { dg-final { scan-assembler-not "st\\.d" } } */ +/* { dg-final { scan-assembler-not "fld\\.d" } } */ +/* { dg-final { scan-assembler "movgr2fr\\.d" } } */