public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard@codesourcery.com>
To: gcc-patches@gcc.gnu.org
Subject: RFA (was RFC): RTL sharing between decls and instructions
Date: Tue, 31 Jul 2007 20:44:00 -0000	[thread overview]
Message-ID: <87y7gws6hi.fsf@firetop.home> (raw)
In-Reply-To: <87d4ydlet3.fsf@firetop.home> (Richard Sandiford's message of 	"Fri\, 27 Jul 2007 22\:25\:28 +0100")

Richard Sandiford <richard@codesourcery.com> writes:
> unshare_all_rtl used to unshare DECL_RTLs as well as expressions in the
> instruction stream.  That changed with:
>
>     http://gcc.gnu.org/ml/gcc-patches/2007-05/msg00541.html
>
> I think that patch was in itself the right thing to do.  However, in
> anticipation of the old unshare_all_rtl behaviour, unshare_all_rtl_again
> used to reset the used flags on all those DECL_RTLs.  I think that's no
> longer correct.  unshare_all_rtl_again is used after reload, which may
> have introduced invalid sharing by converting pseudo registers into
> non-register expressions.  These sharing problems exist between
> DECL_RTLs and the instruction stream as well as between instructions
> themselves.
>
> Thus I think the right thing now is to get unshare_all_rtl_again to
> _set_ rather than reset the used flags on DECL_RTLs, so that if a
> DECL_RTL mentions an ex-register, all references to that ex-register
> in the instruction stream will be copied.  This is what the old
> unshare_all_decls did as a side effect.
>
> Does that sound right?  I've checked that this patch fixes the case
> I'm seeing, but I'm not too familiar with this code, so I wanted to
> check whether I was barking up the wrong tree.

I've now bootstrapped & regression-tested the patch on
x86_64-linux-gnu, and regression-tested it on mipsisa64-elfoabi
(options {-EB,-EL}{,-msoft-float}{,-mips16}).  I don't have a
testcase because I only encountered this problem with a
soon-to-be-sumitted MIPS16 mode for which constant pool entries
are no longer legitimate addresses.  The same problem could in
theory affect current non-MIPS16 targets, but I'm not sure how
easy it would be to reproduce.

OK to install?

Richard

> gcc/
> 	* emit-rtl.c (reset_used_decls): Rename to...
> 	(set_used_decls): ...this.  Set the used flag rather than clearing it.
> 	(unshare_all_rtl_again): Update accordingly.  Set flags on argument
> 	DECL_RTLs rather than resetting them.
>
> Index: gcc/emit-rtl.c
> ===================================================================
> --- gcc/emit-rtl.c	(revision 126993)
> +++ gcc/emit-rtl.c	(working copy)
> @@ -167,7 +167,7 @@ #define first_label_num (cfun->emit->x_f
>  
>  static rtx make_call_insn_raw (rtx);
>  static rtx change_address_1 (rtx, enum machine_mode, rtx, int);
> -static void reset_used_decls (tree);
> +static void set_used_decls (tree);
>  static void mark_label_nuses (rtx);
>  static hashval_t const_int_htab_hash (const void *);
>  static int const_int_htab_eq (const void *, const void *);
> @@ -2160,11 +2160,11 @@ unshare_all_rtl_again (rtx insn)
>        }
>  
>    /* Make sure that virtual stack slots are not shared.  */
> -  reset_used_decls (DECL_INITIAL (cfun->decl));
> +  set_used_decls (DECL_INITIAL (cfun->decl));
>  
>    /* Make sure that virtual parameters are not shared.  */
>    for (decl = DECL_ARGUMENTS (cfun->decl); decl; decl = TREE_CHAIN (decl))
> -    reset_used_flags (DECL_RTL (decl));
> +    set_used_flags (DECL_RTL (decl));
>  
>    reset_used_flags (stack_slot_list);
>  
> @@ -2353,20 +2353,28 @@ unshare_all_rtl_in_chain (rtx insn)
>  }
>  
>  /* Go through all virtual stack slots of a function and mark them as
> -   not shared.  */
> +   shared.  We never replace the DECL_RTLs themselves with a copy,
> +   but expressions mentioned into a DECL_RTL cannot be shared with
> +   expressions in the instruction stream.
> +
> +   Note that reload may convert pseudo registers into memories in-place.
> +   Pseudo registers are always shared, but MEMs never are.  Thus if we
> +   reset the used flags on MEMs in the instruction stream, we must set
> +   them again on MEMs that appear in DECL_RTLs.  */
> +
>  static void
> -reset_used_decls (tree blk)
> +set_used_decls (tree blk)
>  {
>    tree t;
>  
>    /* Mark decls.  */
>    for (t = BLOCK_VARS (blk); t; t = TREE_CHAIN (t))
>      if (DECL_RTL_SET_P (t))
> -      reset_used_flags (DECL_RTL (t));
> +      set_used_flags (DECL_RTL (t));
>  
>    /* Now process sub-blocks.  */
>    for (t = BLOCK_SUBBLOCKS (blk); t; t = TREE_CHAIN (t))
> -    reset_used_decls (t);
> +    set_used_decls (t);
>  }
>  
>  /* Mark ORIG as in use, and return a copy of it if it was already in use.

       reply	other threads:[~2007-07-31 19:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87d4ydlet3.fsf@firetop.home>
2007-07-31 20:44 ` Richard Sandiford [this message]
2007-08-01 14:46 ` RFC: " Ian Lance Taylor

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=87y7gws6hi.fsf@firetop.home \
    --to=richard@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).