From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8864 invoked by alias); 20 Feb 2003 12:36:28 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 8852 invoked from network); 20 Feb 2003 12:36:27 -0000 Received: from unknown (HELO atrey.karlin.mff.cuni.cz) (195.113.31.123) by 172.16.49.205 with SMTP; 20 Feb 2003 12:36:27 -0000 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 29025) id DC73E4F9B8; Thu, 20 Feb 2003 13:36:26 +0100 (CET) Date: Thu, 20 Feb 2003 12:36:00 -0000 From: Zdenek Dvorak To: gcc-patches@gcc.gnu.org Cc: rth@redhat.com, jh@suse.cz Subject: [PATCH] ... Message-ID: <20030220123626.GA19946@atrey.karlin.mff.cuni.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.28i X-SW-Source: 2003-02/txt/msg01655.txt.bz2 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 (®_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 (®_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 (®_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. */