public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/105733] New: riscv: Poor codegen for large stack frames
@ 2022-05-26  0:49 jrtc27 at jrtc27 dot com
  2022-05-26  6:12 ` [Bug target/105733] " kito at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: jrtc27 at jrtc27 dot com @ 2022-05-26  0:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105733

            Bug ID: 105733
           Summary: riscv: Poor codegen for large stack frames
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jrtc27 at jrtc27 dot com
  Target Milestone: ---
            Target: riscv*-*-*

For the following test:

#define BUF_SIZE 2064

void
foo(unsigned long i)
{
    volatile char buf[BUF_SIZE];

    buf[i] = 0;
}

GCC currently generates:

foo:
        li      t0,-4096
        addi    t0,t0,2016
        li      a4,4096
        add     sp,sp,t0
        li      a5,-4096
        addi    a4,a4,-2032
        add     a4,a4,a5
        addi    a5,sp,16
        add     a5,a4,a5
        add     a0,a5,a0
        li      t0,4096
        sd      a5,8(sp)
        sb      zero,2032(a0)
        addi    t0,t0,-2016
        add     sp,sp,t0
        jr      ra

whereas Clang generates the much shorter:

foo:
        lui     a1, 1
        addiw   a1, a1, -2016
        sub     sp, sp, a1
        addi    a1, sp, 16
        add     a0, a0, a1
        sb      zero, 0(a0)
        lui     a0, 1
        addiw   a0, a0, -2016
        add     sp, sp, a0
        ret

The:

        li      a4,4096
        ...
        li      a5,-4096
        addi    a4,a4,-2032
        add     a4,a4,a5

sequence in particular is rather surprising to see rather than just li a4,-2032
and constant-folding that would halve the instruction count difference between
GCC and Clang alone.

See: https://godbolt.org/z/8EGc85dsf

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

end of thread, other threads:[~2024-05-28 17:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-26  0:49 [Bug target/105733] New: riscv: Poor codegen for large stack frames jrtc27 at jrtc27 dot com
2022-05-26  6:12 ` [Bug target/105733] " kito at gcc dot gnu.org
2022-06-07  2:41 ` wilson at gcc dot gnu.org
2022-07-25 20:39 ` pinskia at gcc dot gnu.org
2022-07-25 20:40 ` pinskia at gcc dot gnu.org
2023-12-15 21:47 ` vineetg at gcc dot gnu.org
2024-05-21 17:35 ` cvs-commit at gcc dot gnu.org
2024-05-28 17:15 ` vineetg at gcc dot gnu.org

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