This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH v2 2/2] sched-deps.c: Avoid replacing address if it increases address cost
- From: Craig Blackmore <craig dot blackmore at embecosm dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: jimw at sifive dot com, Ofer dot Shinaar at wdc dot com, Nidal dot Faour at wdc dot com, kito dot cheng at gmail dot com, law at redhat dot com, Craig Blackmore <craig dot blackmore at embecosm dot com>
- Date: Fri, 25 Oct 2019 18:39:11 +0100
- Subject: [PATCH v2 2/2] sched-deps.c: Avoid replacing address if it increases address cost
- References: <CA+yXCZDC2g8SNOeD-dWOLwDeWRd51514_dk++g7yVkS-dbG0-A@mail.gmail.com> <1572025151-22783-1-git-send-email-craig.blackmore@embecosm.com>
The sched2 pass undoes some of the addresses generated by the RISC-V
shorten_memrefs code size optimization (patch 1/2) and consequently increases
code size. This patch prevents sched-deps.c from changing an address if it is
expected to increase address cost.
Tested on bare metal rv32i, rv32iac, rv32im, rv32imac, rv32imafc, rv64imac,
rv64imafdc via QEMU. Bootstrapped and tested on x86_64-linux-gnu. No
regressions.
gcc/ChangeLog:
* sched-deps.c (attempt_change): Use old address if it is
cheaper than new address.
---
gcc/sched-deps.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/gcc/sched-deps.c b/gcc/sched-deps.c
index 308db4e3ca0..c7d0ca550df 100644
--- a/gcc/sched-deps.c
+++ b/gcc/sched-deps.c
@@ -39,6 +39,7 @@ along with GCC; see the file COPYING3. If not see
#include "params.h"
#include "cselib.h"
#include "function-abi.h"
+#include "predict.h"
#ifdef INSN_SCHEDULING
@@ -4694,6 +4695,14 @@ attempt_change (struct mem_inc_info *mii, rtx new_addr)
rtx mem = *mii->mem_loc;
rtx new_mem;
+ /* Prefer old address if it is less expensive. */
+ addr_space_t as = MEM_ADDR_SPACE (mem);
+ bool speed = optimize_bb_for_speed_p (BLOCK_FOR_INSN (mii->mem_insn));
+ int old_cost = address_cost (XEXP (mem, 0), GET_MODE (mem), as, speed);
+ int new_cost = address_cost (new_addr, GET_MODE (mem), as, speed);
+ if (new_cost > old_cost)
+ return NULL_RTX;
+
/* Jump through a lot of hoops to keep the attributes up to date. We
do not want to call one of the change address variants that take
an offset even though we know the offset in many cases. These
--
2.17.1