diff mbox series

LoongArch: Remove * on f constraint in movdi_64bit

Message ID 20261105082240.64519-1-dengjianbo@loongson.cn
State New
Headers show
Series LoongArch: Remove * on f constraint in movdi_64bit | expand

Commit Message

dengjianbo Nov. 5, 2026, 8:22 a.m. UTC
Remove the '*' prefix on floating-point register constraints in the
*movdi_64bit pattern. This avoids adding the extra cost of using
FP_REGS and allows the compiler to generate fld.d instruction instead of
ld.d + movgr2fr.d. When the costs of FP_REGS and GR_REGS are equal, the
register allocator determines the register class via
ira_reg_class_subunion[FP_REGS][GR_REGS] (or its symmetric counterpart).
In LoongArch, this subunion is initialized to GR_REGS, causing the
allocator to prefer GR_REGS when costs tie.

In SPEC2017, tests with option -Ofast -mlasx, the following items show
significant decreases in movgr2fr.d static instruction counts:
500.perlbench_r 246 -> 228 (-7.32%)
520.omnetpp_r 277 -> 257 (-7.22%)
525.x264_r 352 -> 328  (-6.82%)
507.cactuBSSN_r  1155 -> 921 (-20.26%)

gcc/ChangeLog:

	* config/loongarch/loongarch.md: Remove * on f constraint in
	movdi_64bit.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/la64/load-long-to-float.c: New test.
---
 gcc/config/loongarch/loongarch.md                     |  4 ++--
 .../gcc.target/loongarch/la64/load-long-to-float.c    | 11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/loongarch/la64/load-long-to-float.c
diff mbox series

Patch

diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
index ceacc5995e6..e095e78d4f4 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -2387,8 +2387,8 @@ 
 })
 
 (define_insn_and_split "*movdi_64bit"
-  [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r,w,*f,*f,*r,*m")
-	(match_operand:DI 1 "move_operand" "r,Yd,w,rJ,*r*J,*m,*f,*f"))]
+  [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r,w,*f,f,*r,*m")
+	(match_operand:DI 1 "move_operand" "r,Yd,w,rJ,*r*J,m,*f,*f"))]
   "TARGET_64BIT
    && (register_operand (operands[0], DImode)
        || reg_or_0_operand (operands[1], DImode))"
diff --git a/gcc/testsuite/gcc.target/loongarch/la64/load-long-to-float.c b/gcc/testsuite/gcc.target/loongarch/la64/load-long-to-float.c
new file mode 100644
index 00000000000..3ea025a9af8
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/la64/load-long-to-float.c
@@ -0,0 +1,11 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-final { scan-assembler "fld\\.d" } } */
+/* { dg-final { scan-assembler-not "movgr2fr" } } */
+
+extern long T[1024];
+
+double test (int i, double n)
+{
+	return T[i] * n;
+}