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

diff --git a/gcc/config/loongarch/loongarch.cc 
b/gcc/config/loongarch/loongarch.cc
index f7ce3aa2999..d30f171e00d 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -7087,6 +7087,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" } } */
-- 
2.50.0

Reply via email to