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] ...


Hello,

in testcase for PR opt/8634, the initialization of
const char head[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'};

is done as

*(int *) head = (*(int *) head & 0xffffff00) | 'A'
head[1] = 'B';
head[2] = 'C';
...

the initialization of the first element through strange arithmetics
is due to attempt of gcc to avoid creating "head" variable at all;
when it finds out on access to head[1] that it has to create the
variable, the previous attempt to handle it like pseudo is fixed to
look like this.

This patch makes gcc to first create variables that it will anyway
decide to later. This masks (but probably not solve) PR opt/8634
(see http://gcc.gnu.org/ml/gcc-patches/2002-12/msg00533.html for this).

Zdenek

Changelog:
	* function.c (purge_addressof_1, purge_addressof): Add pre-pass over
	insns.

Index: function.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/function.c,v
retrieving revision 1.380.2.9
diff -c -3 -p -r1.380.2.9 function.c
*** function.c	8 Feb 2003 19:43:34 -0000	1.380.2.9
--- function.c	20 Feb 2003 10:06:14 -0000
*************** static void emit_return_into_block PARAM
*** 278,284 ****
  #endif
  static void put_addressof_into_stack PARAMS ((rtx, htab_t));
  static bool purge_addressof_1 PARAMS ((rtx *, rtx, int, int,
! 					  htab_t));
  static void purge_single_hard_subreg_set PARAMS ((rtx));
  #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
  static rtx keep_stack_depressed PARAMS ((rtx));
--- 278,284 ----
  #endif
  static void put_addressof_into_stack PARAMS ((rtx, htab_t));
  static bool purge_addressof_1 PARAMS ((rtx *, rtx, int, int,
! 					  htab_t, int));
  static void purge_single_hard_subreg_set PARAMS ((rtx));
  #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
  static rtx keep_stack_depressed PARAMS ((rtx));
*************** static rtx purge_addressof_replacements;
*** 2969,2982 ****
  /* Helper function for purge_addressof.  See if the rtx expression at *LOC
     in INSN needs to be changed.  If FORCE, always put any ADDRESSOFs into
     the stack.  If the function returns FALSE then the replacement could not
!    be made.  */
  
  static bool
! purge_addressof_1 (loc, insn, force, store, ht)
       rtx *loc;
       rtx insn;
       int force, store;
       htab_t ht;
  {
    rtx x;
    RTX_CODE code;
--- 2969,2984 ----
  /* Helper function for purge_addressof.  See if the rtx expression at *LOC
     in INSN needs to be changed.  If FORCE, always put any ADDRESSOFs into
     the stack.  If the function returns FALSE then the replacement could not
!    be made.  If PREPASS, just process those ADDRESSOFs that will be put
!    into the stack.  */
  
  static bool
! purge_addressof_1 (loc, insn, force, store, ht, prepass)
       rtx *loc;
       rtx insn;
       int force, store;
       htab_t ht;
+      int prepass;
  {
    rtx x;
    RTX_CODE code;
*************** purge_addressof_1 (loc, insn, force, sto
*** 2998,3005 ****
       memory.  */
    if (code == SET)
      {
!       result = purge_addressof_1 (&SET_DEST (x), insn, force, 1, ht);
!       result &= purge_addressof_1 (&SET_SRC (x), insn, force, 0, ht);
        return result;
      }
    else if (code == ADDRESSOF)
--- 3000,3007 ----
       memory.  */
    if (code == SET)
      {
!       result = purge_addressof_1 (&SET_DEST (x), insn, force, 1, ht, prepass);
!       result &= purge_addressof_1 (&SET_SRC (x), insn, force, 0, ht, prepass);
        return result;
      }
    else if (code == ADDRESSOF)
*************** purge_addressof_1 (loc, insn, force, sto
*** 3032,3037 ****
--- 3034,3042 ----
      {
        rtx sub = XEXP (XEXP (x, 0), 0);
  
+       if (prepass)
+ 	return false;
+ 
        if (GET_CODE (sub) == MEM)
  	sub = adjust_address_nv (sub, GET_MODE (x), 0);
        else if (GET_CODE (sub) == REG
*************** purge_addressof_1 (loc, insn, force, sto
*** 3224,3233 ****
    for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
      {
        if (*fmt == 'e')
! 	result &= purge_addressof_1 (&XEXP (x, i), insn, force, 0, ht);
        else if (*fmt == 'E')
  	for (j = 0; j < XVECLEN (x, i); j++)
! 	  result &= purge_addressof_1 (&XVECEXP (x, i, j), insn, force, 0, ht);
      }
  
    return result;
--- 3229,3239 ----
    for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
      {
        if (*fmt == 'e')
! 	result &= purge_addressof_1 (&XEXP (x, i), insn, force, 0, ht, prepass);
        else if (*fmt == 'E')
  	for (j = 0; j < XVECLEN (x, i); j++)
! 	  result &= purge_addressof_1 (&XVECEXP (x, i, j), insn, force, 0, ht,
! 				       prepass);
      }
  
    return result;
*************** purge_addressof (insns)
*** 3358,3363 ****
--- 3364,3381 ----
    rtx insn;
    htab_t ht;
  
+   /* A simple pre-pass in that we check for addressofs that will be really
+      emitted as variables.  This prevents us from creating strange arithmetic
+      sequences on pseudoregisters in belief that we will avoid emitting
+      them.  */
+   for (insn = insns; insn; insn = NEXT_INSN (insn))
+     if (INSN_P (insn))
+       {
+ 	purge_addressof_1 (&PATTERN (insn), insn,
+   			   asm_noperands (PATTERN (insn)) > 0, 0, NULL, 1);
+ 	purge_addressof_1 (&REG_NOTES (insn), NULL_RTX, 0, 0, NULL, 1);
+       }
+   
    /* When we actually purge ADDRESSOFs, we turn REGs into MEMs.  That
       requires a fixup pass over the instruction stream to correct
       INSNs that depended on the REG being a REG, and not a MEM.  But,
*************** purge_addressof (insns)
*** 3372,3383 ****
      if (INSN_P (insn))
        {
  	if (! purge_addressof_1 (&PATTERN (insn), insn,
! 				 asm_noperands (PATTERN (insn)) > 0, 0, ht))
  	  /* If we could not replace the ADDRESSOFs in the insn,
  	     something is wrong.  */
  	  abort ();
  
! 	if (! purge_addressof_1 (&REG_NOTES (insn), NULL_RTX, 0, 0, ht))
  	  {
  	    /* If we could not replace the ADDRESSOFs in the insn's notes,
  	       we can just remove the offending notes instead.  */
--- 3390,3401 ----
      if (INSN_P (insn))
        {
  	if (! purge_addressof_1 (&PATTERN (insn), insn,
! 				 asm_noperands (PATTERN (insn)) > 0, 0, ht, 0))
  	  /* If we could not replace the ADDRESSOFs in the insn,
  	     something is wrong.  */
  	  abort ();
  
! 	if (! purge_addressof_1 (&REG_NOTES (insn), NULL_RTX, 0, 0, ht, 0))
  	  {
  	    /* If we could not replace the ADDRESSOFs in the insn's notes,
  	       we can just remove the offending notes instead.  */


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