https://gcc.gnu.org/g:fbd9051a96a3a2e7ee7db5524e79e42c6477ef65

commit r16-4950-gfbd9051a96a3a2e7ee7db5524e79e42c6477ef65
Author: Guo Jie <[email protected]>
Date:   Sun Nov 2 10:01:06 2025 +0800

    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:
---
 gcc/config/loongarch/loongarch.cc                        |  4 ++++
 gcc/testsuite/gcc.target/loongarch/extendsidi2-combine.c | 13 +++++++++++++
 gcc/testsuite/gcc.target/loongarch/spill-less.c          | 14 ++++++++++++++
 3 files changed, 31 insertions(+)

diff --git a/gcc/config/loongarch/loongarch.cc 
b/gcc/config/loongarch/loongarch.cc
index 735753ad7e2d..ecc7e21f49c0 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 000000000000..0c3613c0efda
--- /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 000000000000..77eb9b5963b4
--- /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" } } */

Reply via email to