RISC-V: Add shorten_memrefs pass.
authorCraig Blackmore <craig.blackmore@embecosm.com>
Tue, 12 May 2020 21:41:08 +0000 (14:41 -0700)
committerJim Wilson <jimw@sifive.com>
Tue, 12 May 2020 21:43:48 +0000 (14:43 -0700)
commitde6320a81695800de0f0f5fc3e4c6487a52cd430
treef6767022ffcd8a6baaca7656b0bccbf8fc6f5735
parent11dd3be56b83d11465ae5d6ecd0d8096531678e5
RISC-V: Add shorten_memrefs pass.

gcc/
* config.gcc:  Add riscv-shorten-memrefs.o to extra_objs for riscv.
* config/riscv/riscv-passes.def: New file.
* config/riscv/riscv-protos.h (make_pass_shorten_memrefs): Declare.
* config/riscv/riscv-shorten-memrefs.c: New file.
* config/riscv/riscv.c (tree-pass.h): New include.
(riscv_compressed_reg_p): New Function
(riscv_compressed_lw_offset_p): Likewise.
(riscv_compressed_lw_address_p): Likewise.
(riscv_shorten_lw_offset): Likewise.
(riscv_legitimize_address): Attempt to convert base + large_offset
to compressible new_base + small_offset.
(riscv_address_cost): Make anticipated compressed load/stores
cheaper for code size than uncompressed load/stores.
(riscv_register_priority): Move compressed register check to
riscv_compressed_reg_p.
* config/riscv/riscv.h (C_S_BITS): Define.
(CSW_MAX_OFFSET): Define.
* config/riscv/riscv.opt (mshorten-memefs): New option.
* config/riscv/t-riscv (riscv-shorten-memrefs.o): New rule.
(PASSES_EXTRA): Add riscv-passes.def.
* doc/invoke.texi: Document -mshorten-memrefs.

* config/riscv/riscv.c (riscv_new_address_profitable_p): New function.
(TARGET_NEW_ADDRESS_PROFITABLE_P): Define.
* doc/tm.texi: Regenerate.
* doc/tm.texi.in (TARGET_NEW_ADDRESS_PROFITABLE_P):  New hook.
* sched-deps.c (attempt_change): Use old address if it is cheaper than
new address.
* target.def (new_address_profitable_p): New hook.
* targhooks.c (default_new_address_profitable_p): New function.
* targhooks.h (default_new_address_profitable_p): Declare.

gcc/testsuite/
* gcc.target/riscv/shorten-memrefs-1.c: New test.
* gcc.target/riscv/shorten-memrefs-2.c: New test.
* gcc.target/riscv/shorten-memrefs-3.c: New test.
* gcc.target/riscv/shorten-memrefs-4.c: New test.
* gcc.target/riscv/shorten-memrefs-5.c: New test.
* gcc.target/riscv/shorten-memrefs-6.c: New test.
* gcc.target/riscv/shorten-memrefs-7.c: New test.
24 files changed:
gcc/ChangeLog
gcc/config.gcc
gcc/config/riscv/riscv-passes.def [new file with mode: 0644]
gcc/config/riscv/riscv-protos.h
gcc/config/riscv/riscv-shorten-memrefs.c [new file with mode: 0644]
gcc/config/riscv/riscv.c
gcc/config/riscv/riscv.h
gcc/config/riscv/riscv.opt
gcc/config/riscv/t-riscv
gcc/doc/invoke.texi
gcc/doc/tm.texi
gcc/doc/tm.texi.in
gcc/sched-deps.c
gcc/target.def
gcc/targhooks.c
gcc/targhooks.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/riscv/shorten-memrefs-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/shorten-memrefs-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/shorten-memrefs-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/shorten-memrefs-4.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/shorten-memrefs-5.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/shorten-memrefs-6.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/shorten-memrefs-7.c [new file with mode: 0644]