]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
LoongArch: Improve TARGET_CAN_CHANGE_MODE_CLASS implementation
authorGuo Jie <guojie@loongson.cn>
Sun, 2 Nov 2025 02:01:06 +0000 (10:01 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Mon, 3 Nov 2025 08:09:15 +0000 (16:09 +0800)
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
gcc/testsuite/gcc.target/loongarch/extendsidi2-combine.c [new file with mode: 0644]
gcc/testsuite/gcc.target/loongarch/spill-less.c [new file with mode: 0644]

index 735753ad7e2d70a3879653ff5d66243368c87bea..ecc7e21f49c07217ba4b225635f864f6e850baf7 100644 (file)
@@ -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 (file)
index 0000000..0c3613c
--- /dev/null
@@ -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 (file)
index 0000000..77eb9b5
--- /dev/null
@@ -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" } } */