This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] cse.c: Speed up find_best_addr.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Cc: arend dot bayer at web dot de, law at redhat dot com
- Date: Thu, 27 Jan 2005 07:40:33 -0500 (EST)
- Subject: [patch] cse.c: Speed up find_best_addr.
Hi,
Attached is a patch to speed up find_bast_addr, a revised version of
the patch posted at
http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01818.html
Some numbers about the above patch is posted at:
http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01851.html
Jeff raised a concern that it may not be safe to omit a call to
copy_rtx before calling fold_rtx. In particular, he was afraid that
we might change the original rtx X when it is ASM_OPERAND.
To address his concern, I put an "if" statement around the case that
handles ASM_OPERAND. This is superflous because validate_change and
its children do basically nothing if its first argument is NULL_RTX.
Technically, it sets BB_DIRTY flags, but that does not mean that the
instruction stream is modified.
Tested on i686-pc-linux-gnu. OK to apply?
Kazu Hirata
2005-01-26 Arend Bayer <arend.bayer@web.de>
Kazu Hirata <kazu@cs.umass.edu>
* cse.c: (find_best_addr): Don't call copy_rtx before calling
fold_rtx. Save cost recomputation if fold_rtx did nothing.
(fold_rtx) <ASM_OPERANDS>: Don't do anything if INSN is
NULL_RTX.
Index: cse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cse.c,v
retrieving revision 1.332
diff -c -d -p -r1.332 cse.c
*** cse.c 26 Jan 2005 12:44:58 -0000 1.332
--- cse.c 26 Jan 2005 16:00:55 -0000
*************** find_best_addr (rtx insn, rtx *loc, enum
*** 2844,2861 ****
be valid and produce better code. */
if (!REG_P (addr))
{
! 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;
}
/* If this address is not in the hash table, we can't look for equivalences
--- 2844,2864 ----
be valid and produce better code. */
if (!REG_P (addr))
{
! rtx folded = fold_rtx (addr, NULL_RTX);
! if (folded != addr)
! {
! 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;
! }
}
/* If this address is not in the hash table, we can't look for equivalences
*************** fold_rtx (rtx x, rtx insn)
*** 3608,3616 ****
#endif
case ASM_OPERANDS:
! for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
! validate_change (insn, &ASM_OPERANDS_INPUT (x, i),
! fold_rtx (ASM_OPERANDS_INPUT (x, i), insn), 0);
break;
default:
--- 3611,3622 ----
#endif
case ASM_OPERANDS:
! if (insn)
! {
! for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
! validate_change (insn, &ASM_OPERANDS_INPUT (x, i),
! fold_rtx (ASM_OPERANDS_INPUT (x, i), insn), 0);
! }
break;
default: