Skip to content
Snippets Groups Projects
Commit 60524be1 authored by Fei Gao's avatar Fei Gao Committed by Jeff Law
Browse files

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.
parent 6d4ad4cc
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment