public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard.sandiford@arm.com>
To: Jeff Law <jlaw@ventanamicro.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [RFA] Avoid unnecessary load-immediate in coremark
Date: Fri, 30 Sep 2022 11:47:31 +0100	[thread overview]
Message-ID: <mptczbdp29o.fsf@arm.com> (raw)
In-Reply-To: <f41501c6-4a9a-6dc0-7224-0f9a721a0765@ventanamicro.com> (Jeff Law's message of "Tue, 27 Sep 2022 13:53:56 -0600")

Jeff Law <jlaw@ventanamicro.com> writes:
> This is another minor improvement to coremark.   I suspect this only 
> improves code size as the load-immediate was likely issuing with the ret 
> statement on multi-issue machines.
>
>
> Basically we're failing to utilize conditional equivalences during the 
> post-reload CSE pass.  So if a particular block is only reached when a 
> certain condition holds (say for example a4 == 0) and the block has an 
> assignment like a4 = 0, we would fail to eliminate the unnecessary 
> assignment.

I wasn't sure (and was too lazy to try, sorry), but: is the reason
that we fail to catch this earlier because the two uses of r4 are
entirely separate (i.e. not from the same pseudo)?

> +	  /* Iterate over each incoming edge and see if they
> +	     all have the same implicit set.  */
> +	  FOR_EACH_EDGE (e, ei, bb->preds)
> +	    {
> +	      /* If the predecessor does not end in a conditional
> +		 jump, then it does not have an implicit set.  */
> +	      if (e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun)
> +		  && !block_ends_with_condjump_p (e->src))
> +		{
> +		  found = false;
> +		  break;
> +		}
> +
> +	      /* We know the predecessor ends with a conditional
> +		 jump.  Now dig into the actal form of the jump
> +		 to potentially extract an implicit set.  */

Very minor, but it looked odd to fall through for the entry block.
How about:

	      if (e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun)
		  || !block_ends_with_condjump_p (e->src))

?

> +	      rtx_insn *condjump = BB_END (e->src);
> +	      if (condjump
> +		  && any_condjump_p (condjump)
> +		  && onlyjump_p (condjump))
> +		{
> +		  /* Extract the condition.  */
> +		  rtx pat = PATTERN (condjump);
> +		  rtx i_t_e = SET_SRC (pat);
> +		  gcc_assert (GET_CODE (i_t_e) == IF_THEN_ELSE);
> +		  rtx cond = XEXP (i_t_e, 0);
> +		  if ((GET_CODE (cond) == EQ
> +		       && GET_CODE (XEXP (i_t_e, 1)) == LABEL_REF
> +		       && XEXP (XEXP (i_t_e, 1), 0) == BB_HEAD (bb))
> +		      || (GET_CODE (cond) == NE
> +			  && XEXP (i_t_e, 2) == pc_rtx
> +			  && e->src->next_bb == bb))
> +		    {
> +		      /* If this is the first time through record
> +			 the source and destination.  */
> +		      if (!dest)
> +			{
> +			  dest = XEXP (cond, 0);
> +			  src = XEXP (cond, 1);
> +			}
> +		      /* If this is not the first time through, then
> +			 verify the source and destination match.  */
> +		      else if (dest == XEXP (cond, 0) && src == XEXP (cond, 1))
> +			;

FWIW, agree with what Richi said about using rtx_equal_p here.  We don't
necessarily end up with shared hard regs, especially if they originated
from different pseudos.

Thanks,
Richard

  parent reply	other threads:[~2022-09-30 10:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-27 19:53 Jeff Law
2022-09-29  7:44 ` Richard Biener
2022-10-01 18:58   ` Jeff Law
2022-09-30 10:47 ` Richard Sandiford [this message]
2022-10-01 19:03   ` Jeff Law

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=mptczbdp29o.fsf@arm.com \
    --to=richard.sandiford@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jlaw@ventanamicro.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).