From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7C0C23857353; Thu, 26 May 2022 00:49:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C0C23857353 From: "jrtc27 at jrtc27 dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/105733] New: riscv: Poor codegen for large stack frames Date: Thu, 26 May 2022 00:49:50 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jrtc27 at jrtc27 dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone cf_gcctarget Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 May 2022 00:49:50 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105733 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] =3D 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 betw= een GCC and Clang alone. See: https://godbolt.org/z/8EGc85dsf=