public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bernd Schmidt <bschmidt@redhat.com>
To: Robert Suchanek <Robert.Suchanek@imgtec.com>,
	       "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [RFC][PATCH] Preferred rename register in regrename pass
Date: Fri, 18 Sep 2015 15:29:00 -0000	[thread overview]
Message-ID: <55FC2B8D.6000106@redhat.com> (raw)
In-Reply-To: <B5E67142681B53468FAF6B7C31356562441B7622@hhmail02.hh.imgtec.org>

On 09/17/2015 04:38 PM, Robert Suchanek wrote:
> We came across a situation for MIPS64 where moves for sign-extension were
> not converted into a nop because of IRA spilled some of the allocnos and
> assigned different hard register for the output operand in the move.
> LRA is not fixing this up as most likely the move was not introduced by
> the LRA itself.  I found it hard to fix this in LRA and looked at
> an alternative solution where regrename pass appeared to be the best candidate.

For reference, please post examples of the insn pattern(s) where you 
would hope to get an improvement. Do they use matching constraints 
between the input and output operands in at least one alternative?

So this does look like something that could be addressed in regrename, 
but I think the patch is not quite the way to do it.

> +/* Return a preferred rename register for HEAD.  */

Function comments ideally ought to be a little more detailed. Preferred 
how and why?

> +static int
> +find_preferred_rename_reg (du_head_p head)
> +{
> +  struct du_chain *this_du;
> +  int preferred_reg = -1;
> +
> +  for (this_du = head->first; this_du; this_du = this_du->next_use)

This loop seems to search for the insn where the chain terminates (i.e. 
the register dies). It seems strange to do this here rather than during 
the initial scan in record_out_operands where we visit every insn and 
already look for REG_DEAD notes.

> +      rtx note;
> +      insn_rr_info *p;
> +
> +      /* The preferred rename register is an output register iff an input
> +	 register dies in an instruction but the candidate must be validated by
> +	 check_new_reg_p.  */
> +      for (note = REG_NOTES (this_du->insn); note; note = XEXP (note, 1))
> +	if (insn_rr.exists()
> +	    && REG_NOTE_KIND (note) == REG_DEAD
> +	    && REGNO (XEXP (note, 0)) == head->regno
> +	    && (p = &insn_rr[INSN_UID (this_du->insn)])
> +	    && p->op_info)
> +	  {
> +	    int i;
> +	    for (i = 0; i < p->op_info->n_chains; i++)
> +	      {
> +		struct du_head *next_head = p->op_info->heads[i];
> +		if (head != next_head)

Here you're not actually verifying the chosen preferred reg is an 
output? Is the use of plain "p->op_info" (which is actually an array) 
intentional as a guess that operand 0 is the output? I'm not thrilled 
with this, and at the very least it should be "p->op_info[0]." to avoid 
reader confusion.
It's also not verifying that this is indeed a case where choosing a 
preferred reg has a beneficial effect at all.

The use of insn_rr would probably also be unnecessary if this was done 
during the scan phase.

> +		    preferred_reg = next_head->regno;

The problem here is that there's an ordering issue. What if next_head 
gets renamed afterwards? The choice of preferred register hasn't bought 
us anything in that case.

For all these reasons I'd suggest a different approach, looking for such 
situations during the scan. Try to detect a situation where
  * we have a REG_DEAD note for an existing chain
  * the insn fulfils certain conditions (i.e. it's a move, or maybe one
    of the alternatives has a matching constraint). After all, there's
    not much point in tying if the reg that dies was used in a memory
    address.
  * a new chain is started for a single output
Then, instead of picking a best register, mark the two chains as tied. 
Then, when choosing a rename register, see if a tied chain already was 
renamed, and try to pick the same register first.

> @@ -1826,7 +1900,7 @@ regrename_optimize (void)
>     df_analyze ();
>     df_set_flags (DF_DEFER_INSN_RESCAN);
>
> -  regrename_init (false);
> +  regrename_init (true);

It would be good to avoid this as it makes the renamer more expensive. I 
expect that if you follow the strategy described above, this won't be 
necessary.

> -  struct du_chain *chains[MAX_REGS_PER_ADDRESS];
> -  struct du_head *heads[MAX_REGS_PER_ADDRESS];
> +  vec<struct du_chain *> chains;
> +  vec<struct du_head *> heads;

Given that MAX_REGS_PER_ADDRESS tends to be 1 or 2 this appears to make 
things more heavyweight, especially with the extra loop needed to free 
the vecs. If possible, try to avoid this. (Again, AFAICS this 
information shouldn't really be necessary for what you're trying to do).


Bernd

  parent reply	other threads:[~2015-09-18 15:19 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-17 14:40 Robert Suchanek
2015-09-17 17:11 ` Jeff Law
2015-09-17 21:28   ` Eric Botcazou
2015-09-18 15:29 ` Bernd Schmidt [this message]
2015-10-09  7:10   ` Robert Suchanek
2015-10-09 11:06     ` Bernd Schmidt
2015-10-09 11:20       ` Robert Suchanek
2015-11-09 13:32       ` Robert Suchanek
2015-11-09 16:30         ` Bernd Schmidt
2015-11-09 17:01           ` Robert Suchanek
2015-11-10 11:21             ` Christophe Lyon
2015-11-10 11:41               ` Robert Suchanek
2015-11-10 16:22                 ` Christophe Lyon
2015-11-10 17:43                   ` James Greenhalgh
2015-11-10 22:33                     ` Robert Suchanek
2015-11-10 22:57                       ` Bernd Schmidt
2015-11-11  0:06                         ` Robert Suchanek
2015-11-11  8:50                         ` Robert Suchanek
2015-11-12  7:47                           ` Christophe Lyon
2015-11-12 12:57                             ` Robert Suchanek
2015-11-10 12:10         ` Bernd Schmidt

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=55FC2B8D.6000106@redhat.com \
    --to=bschmidt@redhat.com \
    --cc=Robert.Suchanek@imgtec.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).