public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: LuluCheng <chenglulu@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-3641] LoongArch: Optimize fixed-point and floating-point conversion operations.
Date: Mon,  4 Sep 2023 01:48:32 +0000 (GMT)	[thread overview]
Message-ID: <20230904014832.E04FB3858D33@sourceware.org> (raw)

https://gcc.gnu.org/g:26aa5d9017104ee3a72de418e9a0a1e5c1e30313

commit r14-3641-g26aa5d9017104ee3a72de418e9a0a1e5c1e30313
Author: Lulu Cheng <chenglulu@loongson.cn>
Date:   Thu Aug 31 19:11:23 2023 +0800

    LoongArch: Optimize fixed-point and floating-point conversion operations.
    
    Before optimization, the operation of taking fixed-point numbers from memory
    and then forcing type conversion needs to be loaded into fixed-point registers
    before conversion. After the optimization is completed, the fixed-point value
    is directly transferred to the floating-point register for type conversion.
    
    eg:
        extern int a;
        float
        test(void)
        {
          return (float)a;
        }
    
    Assembly code before optimization:
            pcalau12i       $r12,%got_pc_hi20(a)
            ld.d    $r12,$r12,%got_pc_lo12(a)
            ldptr.w $r12,$r12,0
            movgr2fr.w      $f0,$r12
            ffint.s.w       $f0,$f0
    
    Optimized assembly code:
            pcalau12i       $r12,%got_pc_hi20(a)
            ld.d    $r12,$r12,%got_pc_lo12(a)
            fld.s   $f0,$r12,0
            ffint.s.w       $f0,$f0
    
    gcc/ChangeLog:
    
            * config/loongarch/loongarch.md: Allows fixed-point values to be loaded
            from memory into floating-point registers.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/loongarch/float-load.c: New test.

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

diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
index b37e070660f1..2936b4c664c0 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -1827,8 +1827,8 @@
 })
 
 (define_insn_and_split "*movsi_internal"
-  [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,w,*f,*f,*r,*m,*r,*z")
-	(match_operand:SI 1 "move_operand" "r,Yd,w,rJ,*r*J,*m,*f,*f,*z,*r"))]
+  [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,w,*f,f,*r,*m,*r,*z")
+	(match_operand:SI 1 "move_operand" "r,Yd,w,rJ,*r*J,m,*f,*f,*z,*r"))]
   "(register_operand (operands[0], SImode)
     || reg_or_0_operand (operands[1], SImode))"
   { return loongarch_output_move (operands[0], operands[1]); }
diff --git a/gcc/testsuite/gcc.target/loongarch/float-load.c b/gcc/testsuite/gcc.target/loongarch/float-load.c
new file mode 100644
index 000000000000..c757a795e214
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/float-load.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-final { scan-assembler "fld\\.s" } } */
+
+extern int a;
+float
+test (void)
+{
+  return (float)a;
+}
+

                 reply	other threads:[~2023-09-04  1:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230904014832.E04FB3858D33@sourceware.org \
    --to=chenglulu@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).