]> git.ipfire.org Git - thirdparty/gcc.git/commit
RISC-V: optimize stack manipulation in save-restore
authorFei Gao <gaofei@eswincomputing.com>
Mon, 17 Apr 2023 22:47:23 +0000 (16:47 -0600)
committerJeff Law <jlaw@ventanamicro>
Mon, 17 Apr 2023 22:47:23 +0000 (16:47 -0600)
commit60524be1e3929d83e15fceac6e2aa053c8a6fb20
treede52eccd4d2666b36932c68223334cf482cecbd4
parent6d4ad4cca5d2b15d01a50a893348cbcfc340cdd5
RISC-V: optimize stack manipulation in save-restore

The stack that save-restore reserves is not well accumulated in stack allocation and deallocation.
This patch allows less instructions to be used in stack allocation and deallocation if save-restore enabled.

before patch:
  bar:
    call t0,__riscv_save_4
    addi sp,sp,-64
    ...
    li t0,-12288
    addi t0,t0,-1968 # optimized out after patch
    add sp,sp,t0 # prologue
    ...
    li t0,12288 # epilogue
    addi t0,t0,2000 # optimized out after patch
    add sp,sp,t0
    ...
    addi sp,sp,32
    tail __riscv_restore_4

after patch:
  bar:
    call t0,__riscv_save_4
    addi sp,sp,-2032
    ...
    li t0,-12288
    add sp,sp,t0 # prologue
    ...
    li t0,12288 # epilogue
    add sp,sp,t0
    ...
    addi sp,sp,2032
    tail __riscv_restore_4

gcc/

* config/riscv/riscv.cc (riscv_expand_prologue): Consider save-restore in
stack allocation.
(riscv_expand_epilogue): Consider save-restore in stack deallocation.

gcc/testsuite

* gcc.target/riscv/stack_save_restore.c: New test.
gcc/config/riscv/riscv.cc
gcc/testsuite/gcc.target/riscv/stack_save_restore.c [new file with mode: 0644]