[PATCH] fold_rtx call in find_best_addr (speedup)
Arend Bayer
arend.bayer@web.de
Tue Jul 1 07:54:00 GMT 2003
While looking for speedups in the CSE pass, I noticed two bogus
assumptions in the code toched below:
1. It is not necessary to copy_rtx before calling fold_rtx, as that
will copy the rtx itself if s.th. changes
2. The code probably assume that approx_reg_cost is cheap, which it
is not.
The patch below fixed the first, and shortcuts the expensive checks
in the common case that fold_rtx did nothing.
This was tested by make bootstrap and make -k check on i586-pc-linux-gnu
all languages except java (which doesn't bootstrap for me). I also
tested it on my project (GNU Go) by verfying that the assembler output
did not change.
There, it gives a speedup of 1%. (This would of course be less after
Ishikawa's speedup.)
Regards,
Arend
P.S.: I think this patch is small enough not to be copyrightable,
but I would also be willing to make a copyright assignment in case
I come up with s.th. less trivial another time.
2003-07-01 Arend Bayer <arend.bayer@web.de>
* cse.c (find_best_addr): Do not copy_rtx before fold_rtx.
Skip expensive checks if fold_rtx did nothing.
Index: gcc/cse.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cse.c,v
retrieving revision 1.268
diff -u -p -c -3 -p -r1.268 cse.c
*** gcc/cse.c 1 Jul 2003 01:15:03 -0000 1.268
--- gcc/cse.c 1 Jul 2003 07:40:59 -0000
*************** find_best_addr (rtx insn, rtx *loc, enum
*** 2860,2875 ****
be valid and produce better code. */
if (GET_CODE (addr) != REG)
{
! rtx folded = fold_rtx (copy_rtx (addr), NULL_RTX);
int addr_folded_cost = address_cost (folded, mode);
int addr_cost = address_cost (addr, mode);
! if ((addr_folded_cost < addr_cost
! || (addr_folded_cost == addr_cost
! /* ??? The rtx_cost comparison is left over from an older
! version of this code. It is probably no longer helpful. */
! && (rtx_cost (folded, MEM) > rtx_cost (addr, MEM)
! || approx_reg_cost (folded) < approx_reg_cost (addr))))
&& validate_change (insn, loc, folded, 0))
addr = folded;
}
--- 2860,2880 ----
be valid and produce better code. */
if (GET_CODE (addr) != REG)
{
! /* fold_rtx will copy the the rtx if it changed s.th., so... */
! rtx folded = fold_rtx (addr, NULL_RTX);
int addr_folded_cost = address_cost (folded, mode);
int addr_cost = address_cost (addr, mode);
! /* ...if folded == addr nothing changed and we can skip the
! (expensive) checks below. */
! if (folded != addr
! && (addr_folded_cost < addr_cost
! || (addr_folded_cost == addr_cost
! /* ??? The rtx_cost comparison is left over from an older
! version of this code. It is probably no longer
! helpful. */
! && (rtx_cost (folded, MEM) > rtx_cost (addr, MEM)
! || approx_reg_cost (folded) < approx_reg_cost (addr))))
&& validate_change (insn, loc, folded, 0))
addr = folded;
}
More information about the Gcc-patches
mailing list