public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Richard Henderson <rth@redhat.com>,
	       Richard Biener <richard.guenther@gmail.com>,
	Jeff Law <law@redhat.com>,
	       Richard Biener <rguenther@suse.de>,
	       Eric Botcazou <ebotcazou@adacore.com>,
	gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Reenable CSE of non-volatile inline asm (PR rtl-optimization/63637)
Date: Sat, 24 Jan 2015 07:23:00 -0000	[thread overview]
Message-ID: <20150124011858.GA31255@gate.crashing.org> (raw)
In-Reply-To: <20150123214850.GZ1746@tucnak.redhat.com>

On Fri, Jan 23, 2015 at 10:48:50PM +0100, Jakub Jelinek wrote:
> On Fri, Jan 23, 2015 at 03:39:40PM -0600, Segher Boessenkool wrote:
> > I understand that argument.  But it is not what GCC actually does, nor
> > what I think it should do.  Consider this program:
> > 
> > --- 8< ---
> > int main(void)
> > {
> > 	int x[100], y[100];
> > 
> > 	x[31] = 42;
> > 
> > 	asm("# eww %0" : "=m"(y[4]) : : "memory");
> > 
> > 	return 0;
> > }
> > --- 8< ---
> 
> Here x isn't addressable, so it is certainly fine to DSE it.
> x shouldn't be considered memory.
> If the address of x escaped, either to the assembly or to some global var
> etc., then it probably shouldn't be removed.

But GCC does consider it memory.  If you look at the (tree) dump files
you see both arrays are clobbered after the asm.  Tree DCE removes the
store to x[31] nevertheless.

If the address of x escapes then of course the store to x[31] should
not be removed, irrespective of whether the clobber implies a read
or not.

> > Here is another program:
> > 
> > --- 8< ---
> > int main(void)
> > {
> > 	int x;
> > 
> > 	asm("# eww %0" : "=r"(x) : : "memory");
> > 	asm("# eww %0" : "=r"(x) : : "memory");
> > 
> > 	return x;
> > }
> > --- 8< ---
> > 
> > If "memory" would imply a write and a read, the identical asm here could
> > not be CSEd.  But it is.
> 
> Certainly not in GCC 4.9 nor trunk.  I've committed the patch because it
> makes GCC more aggressive again, just not for the "memory" case.

Yes, sorry, it is not actually removed by the CSE pass, but much much earlier
("deleted 2 trivially dead insns" in the early RTL "jump" pass).  My point
is that much of the compiler does not agree that "memory" implies a read.

But, to show RTL CSE removes the redundant insn here with older compilers:

--- 8< ---
int main(void)
{
	int x1, x2;

	asm("# eww %0" : "=r"(x1) : : "memory");
	asm("# eww %0" : "=r"(x2) : : "memory");

	return x1 + x2;
}
--- 8< ---

You can argue CSE should not do that.  But other passes feel free to
remove one of the asms (in the previous program), and they should not
either if "memory" implies a read and a write.

> In case of two idential non-volatile asms with "memory" clobber,
> if there are no intervening memory reads or writes, we can talk about
> allowing that to be CSEd despite "memory" being considered unspecified
> read and write.  If there are stores in between, we certainly should not CSE.

If there is a store inbetween, we cannot remove the later asm, which is
what CSE would do AFAIK.  But we can remove the *earlier* asm (and, in
fact, GCC does do that).


Segher

  reply	other threads:[~2015-01-24  1:19 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-13 16:22 Jakub Jelinek
2015-01-13 17:06 ` Segher Boessenkool
2015-01-13 20:02   ` Jeff Law
2015-01-13 20:29     ` Jakub Jelinek
2015-01-13 22:28       ` Jeff Law
2015-01-14  3:44         ` Segher Boessenkool
2015-01-14  6:52           ` Jeff Law
2015-01-14 15:40             ` Segher Boessenkool
2015-01-15  6:46               ` Jeff Law
2015-01-15  7:54                 ` Richard Biener
2015-01-15  8:40                   ` Jakub Jelinek
2015-01-15  8:43                     ` Richard Biener
2015-01-15  9:50                     ` Jakub Jelinek
2015-01-15 18:22                     ` Jeff Law
2015-01-23 21:39                     ` Richard Henderson
2015-01-23 22:53                       ` Segher Boessenkool
2015-01-23 23:12                         ` Jakub Jelinek
2015-01-24  7:23                           ` Segher Boessenkool [this message]
2015-01-24 14:39                             ` Richard Sandiford
2015-01-13 22:42     ` Segher Boessenkool
2015-01-14  0:40       ` Segher Boessenkool
2015-01-14  7:12 ` 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=20150124011858.GA31255@gate.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=law@redhat.com \
    --cc=rguenther@suse.de \
    --cc=richard.guenther@gmail.com \
    --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).