This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] delegitimize_address target call-back (take 3)


On Sun, 2 Feb 2003, Richard Henderson wrote:
> On Sun, Feb 02, 2003 at 12:58:20PM -0700, Roger Sayle wrote:
> > I believe that constants don't record their mode...
>
> Integer constants don't; floating point constants do.

Yep, that would be an issue.  How about the following?

The only change from the "take 2" version of the patch is the
FLOAT_EXTEND case of avoid_constant_pool_reference.  We now
check that the recursive call to avoid_constant_pool_reference
returns a CONST_DOUBLE (implicitly it must be MODE_FLOAT) and
convert this to the required mode, otherwise we return the
original argument.  This ensures that the return value from
a_c_p_r always has either the same mode as its argument, or
VOIDmode (for integer constants).

The following patch has been tested with a complete bootstrap,
all languages except Ada and treelang, on i686-pc-linux-gnu,
with a full "make -k check" reporting no new regressions.

Ok for mainline with this fix?


2002-02-03  Roger Sayle  <roger@eyesopen.com>

	* hooks.c (hook_rtx_rtx_identity): Generic hook function that
	takes a single rtx and returns it unmodified.
	* hooks.h (hook_rtx_rtx_identity): Prototype here.
	* target.h (struct gcc_target): Add "delegitimize_address"
	field to target structure.
	* target-def.h (TARGET_DELEGITIMIZE_ADDRESS):  Provide default
	for delegitimize_address target using hook_rtx_rtx_identity.
	(TARGET_INITIALIZER): Initialize delegitimize_address field
	using TARGET_DELEGITIMIZE_ADDRESS macro.
	* simplify-rtx.c (avoid_constant_pool_reference): Handle float
	extensions of constant pool references.  Use delegitimize_address
	to undo the obfuscation of "-fpic".
	* Makefile.in (simplify-rtx.o): Add dependency on target.h.

	* config/i386/i386.c (TARGET_DELEGITIMIZE_ADDRESS): Define as
	i386_simplify_dwarf_addr.
	(ix86_find_base_term): Simplify using i386_simplify_dwarf_addr.
  	(maybe_get_pool_constant): Likewise.

	(ix86_expand_int_addcc): Delete unused local variables pat and
	clob to silence compilation warnings.


Index: hooks.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/hooks.c,v
retrieving revision 1.11
diff -c -3 -p -r1.11 hooks.c
*** hooks.c	28 Jan 2003 18:08:48 -0000	1.11
--- hooks.c	3 Feb 2003 02:31:22 -0000
***************
*** 1,5 ****
  /* General-purpose hooks.
!    Copyright (C) 2002 Free Software Foundation, Inc.

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the
--- 1,5 ----
  /* General-purpose hooks.
!    Copyright (C) 2002, 2003 Free Software Foundation, Inc.

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the
*************** hook_bool_rtx_int_int_intp_false (a, b,
*** 147,151 ****
--- 147,159 ----
       int *d ATTRIBUTE_UNUSED;
  {
    return false;
+ }
+
+ /* Generic hook that takes an rtx and returns it.  */
+ rtx
+ hook_rtx_rtx_identity (x)
+      rtx x;
+ {
+   return x;
  }

Index: hooks.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/hooks.h,v
retrieving revision 1.11
diff -c -3 -p -r1.11 hooks.h
*** hooks.h	28 Jan 2003 18:08:48 -0000	1.11
--- hooks.h	3 Feb 2003 02:31:22 -0000
***************
*** 1,5 ****
  /* General-purpose hooks.
!    Copyright (C) 2002 Free Software Foundation, Inc.

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the
--- 1,5 ----
  /* General-purpose hooks.
!    Copyright (C) 2002, 2003 Free Software Foundation, Inc.

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the
*************** bool default_can_output_mi_thunk_no_vcal
*** 44,48 ****
--- 44,50 ----
    PARAMS ((tree, HOST_WIDE_INT, HOST_WIDE_INT, tree));

  bool hook_bool_tree_tree_false PARAMS ((tree, tree));
+
+ rtx hook_rtx_rtx_identity PARAMS ((rtx));

  #endif
Index: target.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/target.h,v
retrieving revision 1.48
diff -c -3 -p -r1.48 target.h
*** target.h	28 Jan 2003 18:08:48 -0000	1.48
--- target.h	3 Feb 2003 02:31:22 -0000
***************
*** 1,5 ****
  /* Data structure definitions for a generic GCC target.
!    Copyright (C) 2001, 2002 Free Software Foundation, Inc.

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the
--- 1,5 ----
  /* Data structure definitions for a generic GCC target.
!    Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the
*************** struct gcc_target
*** 291,296 ****
--- 291,299 ----

    /* True if the constant X cannot be placed in the constant pool.  */
    bool (* cannot_force_const_mem) PARAMS ((rtx));
+
+   /* Given an address RTX, undo the effects of LEGITIMIZE_ADDRESS.  */
+   rtx (* delegitimize_address) PARAMS ((rtx));

    /* True if it is OK to do sibling call optimization for the specified
       call expression EXP.  DECL will be the called function, or NULL if
Index: target-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/target-def.h,v
retrieving revision 1.42
diff -c -3 -p -r1.42 target-def.h
*** target-def.h	28 Jan 2003 18:08:48 -0000	1.42
--- target-def.h	3 Feb 2003 02:31:22 -0000
***************
*** 1,5 ****
  /* Default initializers for a generic GCC target.
!    Copyright (C) 2001, 2002 Free Software Foundation, Inc.

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the
--- 1,5 ----
  /* Default initializers for a generic GCC target.
!    Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the
*************** Foundation, 59 Temple Place - Suite 330,
*** 259,264 ****
--- 259,265 ----
  /* In hook.c.  */
  #define TARGET_CANNOT_MODIFY_JUMPS_P hook_bool_void_false
  #define TARGET_CANNOT_FORCE_CONST_MEM hook_bool_rtx_false
+ #define TARGET_DELEGITIMIZE_ADDRESS hook_rtx_rtx_identity
  #define TARGET_FUNCTION_OK_FOR_SIBCALL hook_bool_tree_tree_false
  #define TARGET_COMP_TYPE_ATTRIBUTES hook_int_tree_tree_1
  #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES hook_void_tree
*************** Foundation, 59 Temple Place - Suite 330,
*** 293,298 ****
--- 294,300 ----
    TARGET_SECTION_TYPE_FLAGS,			\
    TARGET_CANNOT_MODIFY_JUMPS_P,			\
    TARGET_CANNOT_FORCE_CONST_MEM,		\
+   TARGET_DELEGITIMIZE_ADDRESS,			\
    TARGET_FUNCTION_OK_FOR_SIBCALL,		\
    TARGET_IN_SMALL_DATA_P,			\
    TARGET_BINDS_LOCAL_P,				\
Index: simplify-rtx.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/simplify-rtx.c,v
retrieving revision 1.130
diff -c -3 -p -r1.130 simplify-rtx.c
*** simplify-rtx.c	24 Jan 2003 22:45:58 -0000	1.130
--- simplify-rtx.c	3 Feb 2003 02:31:23 -0000
*************** Software Foundation, 59 Temple Place - S
*** 38,43 ****
--- 38,44 ----
  #include "toplev.h"
  #include "output.h"
  #include "ggc.h"
+ #include "target.h"

  /* Simplification and canonicalization of RTL.  */

*************** rtx
*** 106,117 ****
  avoid_constant_pool_reference (x)
       rtx x;
  {
!   rtx c, addr;
    enum machine_mode cmode;

!   if (GET_CODE (x) != MEM)
!     return x;
    addr = XEXP (x, 0);

    if (GET_CODE (addr) == LO_SUM)
      addr = XEXP (addr, 1);
--- 107,141 ----
  avoid_constant_pool_reference (x)
       rtx x;
  {
!   rtx c, tmp, addr;
    enum machine_mode cmode;

!   switch (GET_CODE (x))
!     {
!     case MEM:
!       break;
!
!     case FLOAT_EXTEND:
!       /* Handle float extensions of constant pool references.  */
!       tmp = XEXP (x, 0);
!       c = avoid_constant_pool_reference (tmp);
!       if (c != tmp && GET_CODE (c) == CONST_DOUBLE)
! 	{
! 	  REAL_VALUE_TYPE d;
!
! 	  REAL_VALUE_FROM_CONST_DOUBLE (d, c);
! 	  return CONST_DOUBLE_FROM_REAL_VALUE (d, GET_MODE (x));
! 	}
!       return x;
!
!     default:
!       return x;
!     }
!
    addr = XEXP (x, 0);
+
+   /* 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);
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.983
diff -c -3 -p -r1.983 Makefile.in
*** Makefile.in	29 Jan 2003 12:32:08 -0000	1.983
--- Makefile.in	3 Feb 2003 02:31:24 -0000
*************** jump.o : jump.c $(CONFIG_H) $(SYSTEM_H)
*** 1538,1544 ****

  simplify-rtx.o : simplify-rtx.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
     $(REGS_H) hard-reg-set.h flags.h real.h insn-config.h $(RECOG_H) $(EXPR_H) toplev.h \
!    output.h function.h $(GGC_H) $(OBSTACK_H) $(TM_P_H) $(TREE_H)
  cselib.o : cselib.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) $(REGS_H) \
     hard-reg-set.h flags.h real.h insn-config.h $(RECOG_H) $(EXPR_H) toplev.h \
     output.h function.h cselib.h $(GGC_H) $(TM_P_H) gt-cselib.h
--- 1538,1544 ----

  simplify-rtx.o : simplify-rtx.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
     $(REGS_H) hard-reg-set.h flags.h real.h insn-config.h $(RECOG_H) $(EXPR_H) toplev.h \
!    output.h function.h $(GGC_H) $(OBSTACK_H) $(TM_P_H) $(TREE_H) $(TARGET_H)
  cselib.o : cselib.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) $(REGS_H) \
     hard-reg-set.h flags.h real.h insn-config.h $(RECOG_H) $(EXPR_H) toplev.h \
     output.h function.h cselib.h $(GGC_H) $(TM_P_H) gt-cselib.h
Index: config/i386/i386.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.519
diff -c -3 -p -r1.519 i386.c
*** config/i386/i386.c	28 Jan 2003 18:08:50 -0000	1.519
--- config/i386/i386.c	3 Feb 2003 02:31:27 -0000
*************** static enum x86_64_reg_class merge_class
*** 990,995 ****
--- 990,998 ----
  #undef TARGET_CANNOT_FORCE_CONST_MEM
  #define TARGET_CANNOT_FORCE_CONST_MEM ix86_cannot_force_const_mem

+ #undef TARGET_DELEGITIMIZE_ADDRESS
+ #define TARGET_DELEGITIMIZE_ADDRESS i386_simplify_dwarf_addr
+
  #undef TARGET_MS_BITFIELD_LAYOUT_P
  #define TARGET_MS_BITFIELD_LAYOUT_P ix86_ms_bitfield_layout_p

*************** ix86_find_base_term (x)
*** 5368,5388 ****
        return term;
      }

!   if (GET_CODE (x) != PLUS
!       || XEXP (x, 0) != pic_offset_table_rtx
!       || GET_CODE (XEXP (x, 1)) != CONST)
!     return x;
!
!   term = XEXP (XEXP (x, 1), 0);
!
!   if (GET_CODE (term) == PLUS && GET_CODE (XEXP (term, 1)) == CONST_INT)
!     term = XEXP (term, 0);
!
!   if (GET_CODE (term) != UNSPEC
!       || XINT (term, 1) != UNSPEC_GOTOFF)
!     return x;
!
!   term = XVECEXP (term, 0, 0);

    if (GET_CODE (term) != SYMBOL_REF
        && GET_CODE (term) != LABEL_REF)
--- 5371,5377 ----
        return term;
      }

!   term = i386_simplify_dwarf_addr (x);

    if (GET_CODE (term) != SYMBOL_REF
        && GET_CODE (term) != LABEL_REF)
*************** static rtx
*** 8047,8070 ****
  maybe_get_pool_constant (x)
       rtx x;
  {
!   x = XEXP (x, 0);
!
!   if (flag_pic && ! TARGET_64BIT)
!     {
!       if (GET_CODE (x) != PLUS)
! 	return NULL_RTX;
!       if (XEXP (x, 0) != pic_offset_table_rtx)
! 	return NULL_RTX;
!       x = XEXP (x, 1);
!       if (GET_CODE (x) != CONST)
! 	return NULL_RTX;
!       x = XEXP (x, 0);
!       if (GET_CODE (x) != UNSPEC)
! 	return NULL_RTX;
!       if (XINT (x, 1) != UNSPEC_GOTOFF)
! 	return NULL_RTX;
!       x = XVECEXP (x, 0, 0);
!     }

    if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
      return get_pool_constant (x);
--- 8036,8042 ----
  maybe_get_pool_constant (x)
       rtx x;
  {
!   x = i386_simplify_dwarf_addr (XEXP (x, 0));

    if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
      return get_pool_constant (x);
*************** ix86_expand_int_addcc (operands)
*** 10153,10159 ****
    rtx compare_op;
    rtx val = const0_rtx;
    bool fpcmp = false;
-   rtx pat, clob;
    enum machine_mode mode = GET_MODE (operands[0]);

    if (operands[3] != const1_rtx
--- 10125,10130 ----

Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]