public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/riscv/heads/gcc-13-with-riscv-opts)] RISC-V: improve codegen for large constants with same 32-bit lo and hi parts [2]
@ 2023-07-14  2:37 Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2023-07-14  2:37 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:17a61c57eb16d94915753061ab3bff31818a15af

commit 17a61c57eb16d94915753061ab3bff31818a15af
Author: Vineet Gupta <vineetg@rivosinc.com>
Date:   Tue May 9 16:22:08 2023 -0700

    RISC-V: improve codegen for large constants with same 32-bit lo and hi parts [2]
    
    [part #2 of PR/109279]
    
    SPEC2017 deepsjeng uses large constants which currently generates less than
    ideal code. This fix improves codegen for large constants which have
    same low and hi parts: e.g.
    
            long long f(void) { return 0x0101010101010101ull; }
    
    Before
            li      a5,0x1010000
            addi    a5,a5,0x101
            mv      a0,a5
            slli    a5,a5,32
            add     a0,a5,a0
            ret
    
    With patch
            li      a5,0x1010000
            addi    a5,a5,0x101
            slli    a0,a5,32
            add     a0,a0,a5
            ret
    
    This is testsuite clean.
    
    gcc/ChangeLog:
    
            * config/riscv/riscv.cc (riscv_split_integer): if loval is equal
            to hival, ASHIFT the corresponding regs.
    
    Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>

Diff:
---
 gcc/config/riscv/riscv.cc | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 02f9396c22c..1b851de755d 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -703,13 +703,18 @@ riscv_split_integer (HOST_WIDE_INT val, machine_mode mode)
   unsigned HOST_WIDE_INT hival = sext_hwi ((val - loval) >> 32, 32);
   rtx hi = gen_reg_rtx (mode), lo = gen_reg_rtx (mode);
 
-  riscv_move_integer (hi, hi, hival, mode);
   riscv_move_integer (lo, lo, loval, mode);
 
-  hi = gen_rtx_fmt_ee (ASHIFT, mode, hi, GEN_INT (32));
-  hi = force_reg (mode, hi);
+  if (loval == hival)
+      hi = gen_rtx_ASHIFT (mode, lo, GEN_INT (32));
+  else
+    {
+      riscv_move_integer (hi, hi, hival, mode);
+      hi = gen_rtx_ASHIFT (mode, hi, GEN_INT (32));
+    }
 
-  return gen_rtx_fmt_ee (PLUS, mode, hi, lo);
+  hi = force_reg (mode, hi);
+  return gen_rtx_PLUS (mode, hi, lo);
 }
 
 /* Return true if X is a thread-local symbol.  */

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [gcc(refs/vendors/riscv/heads/gcc-13-with-riscv-opts)] RISC-V: improve codegen for large constants with same 32-bit lo and hi parts [2]
@ 2023-05-25 23:21 Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2023-05-25 23:21 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8d521bc464ed4ac360fa22c98e848c68deaa0bbd

commit 8d521bc464ed4ac360fa22c98e848c68deaa0bbd
Author: Vineet Gupta <vineetg@rivosinc.com>
Date:   Tue May 9 16:22:08 2023 -0700

    RISC-V: improve codegen for large constants with same 32-bit lo and hi parts [2]
    
    [part #2 of PR/109279]
    
    SPEC2017 deepsjeng uses large constants which currently generates less than
    ideal code. This fix improves codegen for large constants which have
    same low and hi parts: e.g.
    
            long long f(void) { return 0x0101010101010101ull; }
    
    Before
            li      a5,0x1010000
            addi    a5,a5,0x101
            mv      a0,a5
            slli    a5,a5,32
            add     a0,a5,a0
            ret
    
    With patch
            li      a5,0x1010000
            addi    a5,a5,0x101
            slli    a0,a5,32
            add     a0,a0,a5
            ret
    
    This is testsuite clean.
    
    gcc/ChangeLog:
    
            * config/riscv/riscv.cc (riscv_split_integer): if loval is equal
            to hival, ASHIFT the corresponding regs.
    
    Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>

Diff:
---
 gcc/config/riscv/riscv.cc | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 8320069f92f..2a7b43849e5 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -703,13 +703,18 @@ riscv_split_integer (HOST_WIDE_INT val, machine_mode mode)
   unsigned HOST_WIDE_INT hival = sext_hwi ((val - loval) >> 32, 32);
   rtx hi = gen_reg_rtx (mode), lo = gen_reg_rtx (mode);
 
-  riscv_move_integer (hi, hi, hival, mode);
   riscv_move_integer (lo, lo, loval, mode);
 
-  hi = gen_rtx_fmt_ee (ASHIFT, mode, hi, GEN_INT (32));
-  hi = force_reg (mode, hi);
+  if (loval == hival)
+      hi = gen_rtx_ASHIFT (mode, lo, GEN_INT (32));
+  else
+    {
+      riscv_move_integer (hi, hi, hival, mode);
+      hi = gen_rtx_ASHIFT (mode, hi, GEN_INT (32));
+    }
 
-  return gen_rtx_fmt_ee (PLUS, mode, hi, lo);
+  hi = force_reg (mode, hi);
+  return gen_rtx_PLUS (mode, hi, lo);
 }
 
 /* Return true if X is a thread-local symbol.  */

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-07-14  2:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-14  2:37 [gcc(refs/vendors/riscv/heads/gcc-13-with-riscv-opts)] RISC-V: improve codegen for large constants with same 32-bit lo and hi parts [2] Jeff Law
  -- strict thread matches above, loose matches on Subject: below --
2023-05-25 23:21 Jeff Law

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).