This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Make avoid_constant_pool_reference smarter
- From: Paolo Bonzini <paolo dot bonzini at lu dot unisi dot ch>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 25 May 2005 09:29:51 +0200
- Subject: [PATCH] Make avoid_constant_pool_reference smarter
This patch moves one case from CSE's fold_rtx_mem to
avoid_constant_pool_reference. CSE can extract the low part of a
constant that resides in the pool, or a single word of a multiword
constant. In a slightly cleaner way, a_c_p_r uses simplify_subreg to
convert constants between different modes. This patch equips a_c_p_r to
support offsetted addresses (e.g. to extract words from multiword
constants).
In CSE's fold_rtx_mem, the part dealing with LABEL_REF (basically
performing a kind of jump threading) is practically dead and was toggles
even less frequently since Alexandre Oliva fixed PR18628 (the dead-label
bug). So, fold_rtx_mem could reduce to
find_best_addr+avoid_constant_pool_reference. And similarly,
equiv_constant's MEM case could be reduced to
avoid_constant_pool_reference+lookup.
These however are follow-ups that cannot happen in the 4.1 frame (and
I'm thinking more and more about a branch...).
Bootstrapped/regtested all languages on powerpc-apple-darwin7, ok for
mainline?
Paolo
2005-05-25 Paolo Bonzini <bonzini@gnu.org>
* simplify-rtx.c (avoid_constant_pool_reference): Use simplify_subreg
also to handle the (plus (symbol_ref "xx") (const_int C)) case.
Index: simplify-rtx.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/simplify-rtx.c,v
retrieving revision 1.239
diff -p -u -u -r1.239 simplify-rtx.c
*** simplify-rtx.c 24 Apr 2005 22:16:48 -0000 1.239
--- simplify-rtx.c 25 May 2005 07:17:05 -0000
***************
*** 145,150 ****
--- 145,151 ----
{
rtx c, tmp, addr;
enum machine_mode cmode;
+ HOST_WIDE_INT offset = 0;
switch (GET_CODE (x))
{
***************
*** 173,198 ****
/* Call target hook to avoid the effects of -fpic etc.... */
addr = targetm.delegitimize_address (addr);
if (GET_CODE (addr) == LO_SUM)
addr = XEXP (addr, 1);
! if (GET_CODE (addr) != SYMBOL_REF
! || ! CONSTANT_POOL_ADDRESS_P (addr))
! return x;
!
! c = get_pool_constant (addr);
! cmode = get_pool_mode (addr);
!
! /* If we're accessing the constant in a different mode than it was
! originally stored, attempt to fix that up via subreg simplifications.
! If that fails we have no choice but to return the original memory. */
! if (cmode != GET_MODE (x))
! {
! c = simplify_subreg (GET_MODE (x), c, cmode, 0);
! return c ? c : x;
}
! return c;
}
/* Make a unary operation by first seeing if it folds and otherwise making
--- 174,213 ----
/* Call target hook to avoid the effects of -fpic etc.... */
addr = targetm.delegitimize_address (addr);
+ /* Split the address into a base and integer offset. */
+ if (GET_CODE (addr) == CONST
+ && GET_CODE (XEXP (addr, 0)) == PLUS
+ && GET_CODE (XEXP (XEXP (addr, 0), 1)) == CONST_INT)
+ {
+ offset = INTVAL (XEXP (XEXP (addr, 0), 1));
+ addr = XEXP (XEXP (addr, 0), 0);
+ }
+
if (GET_CODE (addr) == LO_SUM)
addr = XEXP (addr, 1);
! /* If this is a constant pool reference, we can turn it into its
! constant and hope that simplifications happen. */
! if (GET_CODE (addr) == SYMBOL_REF
! && CONSTANT_POOL_ADDRESS_P (addr))
! {
! c = get_pool_constant (addr);
! cmode = get_pool_mode (addr);
!
! /* If we're accessing the constant in a different mode than it was
! originally stored, attempt to fix that up via subreg simplifications.
! If that fails we have no choice but to return the original memory. */
! if (offset != 0 || cmode != GET_MODE (x))
! {
! rtx tem = simplify_subreg (GET_MODE (x), c, cmode, offset);
! if (tem && CONSTANT_P (tem))
! return tem;
! }
! else
! return c;
}
! return x;
}
/* Make a unary operation by first seeing if it folds and otherwise making