public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Zdenek Dvorak <rakdver@atrey.karlin.mff.cuni.cz>
To: gcc-patches@gcc.gnu.org
Cc: rth@redhat.com, jh@suse.cz
Subject: [PATCH] ...
Date: Thu, 20 Feb 2003 12:36:00 -0000	[thread overview]
Message-ID: <20030220123626.GA19946@atrey.karlin.mff.cuni.cz> (raw)

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.  */

             reply	other threads:[~2003-02-20 12:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-20 12:36 Zdenek Dvorak [this message]
2003-12-16 14:00 [PATCH] Hartmut Penner
2003-12-16 17:36 ` [PATCH] Zack Weinberg
2004-02-08 22:05 [PATCH] Bernardo Innocenti
2004-02-08 22:55 ` [PATCH] Richard Henderson
2004-02-21 13:45   ` [PATCH] Richard Henderson
2004-02-21 13:45 ` [PATCH] Bernardo Innocenti
2004-05-04  0:26 [PATCH] Eric Christopher
2004-05-04  0:42 [PATCH] Ulrich Weigand
2004-05-04  0:52 ` [PATCH] Eric Christopher
2004-05-04  1:14   ` [PATCH] Ulrich Weigand
2004-05-04  2:05     ` [PATCH] Eric Christopher
2004-05-04  1:11 ` [PATCH] Eric Christopher
2004-05-04  1:14   ` [PATCH] Ulrich Weigand
     [not found] <no.id>
2004-05-04  0:50 ` [PATCH] Ulrich Weigand
2004-05-04  0:52   ` [PATCH] Eric Christopher
2006-05-10 10:44 [patch] François-Xavier Coudert
2006-10-10 19:31 [PATCH]: Kaveh R. GHAZI
     [not found] <ormtqpsbuc.fsf@lxoliva.fsfla.org>
2021-09-09  7:11 ` [PATCH] strub: machine-independent stack scrubbing Alexandre Oliva
2022-07-29  6:16   ` [PATCH v2 00/10] Introduce " Alexandre Oliva
2023-06-16  6:09     ` [PATCH v3] " Alexandre Oliva
2023-10-20  6:03       ` [PATCH v4] " Alexandre Oliva
2023-10-26  6:15         ` Alexandre Oliva
2023-11-20 12:40           ` Alexandre Oliva
2023-11-22 14:14             ` Richard Biener
2023-11-23 10:56               ` Alexandre Oliva
2023-11-23 12:05                 ` Richard Biener
2023-11-29  8:53                   ` Alexandre Oliva
2023-11-29 12:48                     ` Richard Biener
2023-11-30  4:13                       ` Alexandre Oliva
2023-11-30 12:00                         ` Richard Biener
2023-12-02 17:56                           ` [PATCH v5] " Alexandre Oliva
2023-12-06  8:36                             ` Causes to nvptx bootstrap fail: " Tobias Burnus
2023-12-06 11:32                               ` Thomas Schwinge
2023-12-06 22:12                                 ` Alexandre Oliva
2023-12-07  3:33                                   ` [PATCH] strub: enable conditional support Alexandre Oliva
2023-12-07 16:44                                     ` Thomas Schwinge
2023-12-07 17:52                                       ` [PATCH] Alexandre Oliva
2023-12-08  6:46                                         ` [PATCH] Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030220123626.GA19946@atrey.karlin.mff.cuni.cz \
    --to=rakdver@atrey.karlin.mff.cuni.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jh@suse.cz \
    --cc=rth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).