From: Jeff Law <jeffreyalaw@gmail.com>
To: Vineet Gupta <vineetg@rivosinc.com>, gcc-patches@gcc.gnu.org
Cc: kito.cheng@gmail.com, Palmer Dabbelt <palmer@rivosinc.com>,
gnu-toolchain@rivosinc.com, Robin Dapp <rdapp.gcc@gmail.com>
Subject: Re: [gcc-15 3/3] RISC-V: avoid LUI based const mat in prologue/epilogue expansion [PR/105733]
Date: Sat, 16 Mar 2024 14:27:10 -0600 [thread overview]
Message-ID: <ccba88bd-a3f6-4466-ac14-2424f954453d@gmail.com> (raw)
In-Reply-To: <20240316173524.1147760-4-vineetg@rivosinc.com>
On 3/16/24 11:35 AM, Vineet Gupta wrote:
> If the constant used for stack offset can be expressed as sum of two S12
> values, the constant need not be materialized (in a reg) and instead the
> two S12 bits can be added to instructions involved with frame pointer.
> This avoids burning a register and more importantly can often get down
> to be 2 insn vs. 3.
>
> The prev patches to generally avoid LUI based const materialization didn't
> fix this PR and need this directed fix in funcion prologue/epilogue
> expansion.
>
> This fix doesn't move the neddle for SPEC, at all, but it is still a
> win considering gcc generates one insn fewer than llvm for the test ;-)
>
> gcc-13.1 release | gcc 230823 | |
> | g6619b3d4c15c | This patch | clang/llvm
> ---------------------------------------------------------------------------------
> li t0,-4096 | li t0,-4096 | addi sp,sp,-2048 | addi sp,sp,-2048
> addi t0,t0,2016 | addi t0,t0,2032 | add sp,sp,-16 | addi sp,sp,-32
> li a4,4096 | add sp,sp,t0 | add a5,sp,a0 | add a1,sp,16
> add sp,sp,t0 | addi a5,sp,-2032 | sb zero,0(a5) | add a0,a0,a1
> li a5,-4096 | add a0,a5,a0 | addi sp,sp,2032 | sb zero,0(a0)
> addi a4,a4,-2032 | li t0, 4096 | addi sp,sp,32 | addi sp,sp,2032
> add a4,a4,a5 | sb zero,2032(a0) | ret | addi sp,sp,48
> addi a5,sp,16 | addi t0,t0,-2032 | | ret
> add a5,a4,a5 | add sp,sp,t0 |
> add a0,a5,a0 | ret |
> li t0,4096 |
> sd a5,8(sp) |
> sb zero,2032(a0)|
> addi t0,t0,-2016 |
> add sp,sp,t0 |
> ret |
>
> gcc/ChangeLog:
> PR target/105733
> * config/riscv/riscv.cc (riscv_split_sum_of_two_s12): New
> function to split a sum of two s12 values into constituents.
> (riscv_expand_prologue): Handle offset being sum of two S12.
> (riscv_expand_epilogue): Ditto.
> * config/riscv/riscv-protos.h (riscv_split_sum_of_two_s12): New.
>
> gcc/testsuite/ChangeLog:
> * gcc.target/riscv/pr105733.c: New Test.
> * gcc.target/riscv/rvv/autovec/vls/spill-1.c: Adjust to not
> expect LUI 4096.
> * gcc.target/riscv/rvv/autovec/vls/spill-2.c: Ditto.
> * gcc.target/riscv/rvv/autovec/vls/spill-3.c: Ditto.
> * gcc.target/riscv/rvv/autovec/vls/spill-4.c: Ditto.
> * gcc.target/riscv/rvv/autovec/vls/spill-5.c: Ditto.
> * gcc.target/riscv/rvv/autovec/vls/spill-6.c: Ditto.
> * gcc.target/riscv/rvv/autovec/vls/spill-7.c: Ditto.
Yea, wouldn't expect this to move the needle on spec since it's just
hitting the prologue/epilogue. In fact, I wouldn't be surprised if
there were other stack frame sizes that could be improved. But I
wouldn't bother chasing down those other cases.
If we think about the embedded space, they're probably not going to want
to see functions with large frames to begin with. So optimizing those
cases for the embedded space just doesn't make much sense.
In the distro space, by this time next year we'll be living in a world
where stack clash mitigations are enabled. So for any given size stack
frame, it'll be allocated in at most 1 page chunks. So again, going to
any significant length to optimize other cases just doesn't make much sense.
So we probably should go with this patch in the gcc-15 space, but I
wouldn't suggest heroic efforts for other sized stack frames.
jeff
next prev parent reply other threads:[~2024-03-16 20:27 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-16 17:35 [gcc-15 0/3] RISC-V improve stack/array access by constant mat tweak Vineet Gupta
2024-03-16 17:35 ` [gcc-15 1/3] RISC-V: avoid LUI based const materialization ... [part of PR/106265] Vineet Gupta
2024-03-16 20:28 ` Jeff Law
2024-03-19 0:07 ` Vineet Gupta
2024-03-23 5:59 ` Jeff Law
2024-03-16 17:35 ` [gcc-15 2/3] RISC-V: avoid LUI based const mat: keep stack offsets aligned Vineet Gupta
2024-03-16 20:21 ` Jeff Law
2024-03-19 0:27 ` Vineet Gupta
2024-03-19 6:48 ` Andrew Waterman
2024-03-19 13:10 ` Jeff Law
2024-03-19 20:05 ` Vineet Gupta
2024-03-19 20:58 ` Andrew Waterman
2024-03-19 21:17 ` Palmer Dabbelt
2024-03-20 18:57 ` Jeff Law
2024-03-23 6:05 ` Jeff Law
2024-03-16 17:35 ` [gcc-15 3/3] RISC-V: avoid LUI based const mat in prologue/epilogue expansion [PR/105733] Vineet Gupta
2024-03-16 20:27 ` Jeff Law [this message]
2024-03-19 4:41 ` [gcc-15 0/3] RISC-V improve stack/array access by constant mat tweak Jeff Law
2024-03-21 0:45 ` Vineet Gupta
2024-03-21 14:36 ` scheduler queue flush (was Re: [gcc-15 0/3] RISC-V improve stack/array access by constant mat tweak) Vineet Gupta
2024-03-21 14:45 ` Jeff Law
2024-03-21 17:19 ` Vineet Gupta
2024-03-21 19:56 ` Jeff Law
2024-03-22 0:34 ` scheduler queue flush Vineet Gupta
2024-03-22 8:47 ` scheduler queue flush (was Re: [gcc-15 0/3] RISC-V improve stack/array access by constant mat tweak) Richard Biener
2024-03-22 12:29 ` Jeff Law
2024-03-22 16:56 ` Vineet Gupta
2024-03-25 3:05 ` Jeff Law
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=ccba88bd-a3f6-4466-ac14-2424f954453d@gmail.com \
--to=jeffreyalaw@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=gnu-toolchain@rivosinc.com \
--cc=kito.cheng@gmail.com \
--cc=palmer@rivosinc.com \
--cc=rdapp.gcc@gmail.com \
--cc=vineetg@rivosinc.com \
/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).