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

commit r17-6449-ga9f0d2a9c91246bce74b01cf1a06d39d9dfc724e
Author: Deng Jianbo <[email protected]>
Date:   Thu Nov 5 16:22:40 2026 +0800

    LoongArch: Remove * on f and m constraint in movdi_64bit
    
    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 and m
            constraint in movdi_64bit.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/loongarch/la64/load-long-to-float.c: New test.

Diff:
---
 gcc/config/loongarch/loongarch.md                            |  4 ++--
 gcc/testsuite/gcc.target/loongarch/la64/load-long-to-float.c | 11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/gcc/config/loongarch/loongarch.md 
b/gcc/config/loongarch/loongarch.md
index f6a03861205a..de18494af0b0 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -2376,8 +2376,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 000000000000..3ea025a9af8d
--- /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;
+}

Reply via email to