From: Richard Biener <rguenther@suse.de>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] tree-optimization/110434 - avoid <retval> ={v} {CLOBBER} from NRV
Date: Wed, 28 Jun 2023 12:32:51 +0000 (UTC) [thread overview]
Message-ID: <nycvar.YFH.7.77.849.2306281227240.4723@jbgna.fhfr.qr> (raw)
In-Reply-To: <ZJwNdGJdnRr0nRnO@tucnak>
On Wed, 28 Jun 2023, Jakub Jelinek wrote:
> On Wed, Jun 28, 2023 at 10:21:45AM +0000, Richard Biener via Gcc-patches wrote:
> > When NRV replaces a local variable with <retval> it also replaces
> > occurences in clobbers. This leads to <retval> being clobbered
> > before the return of it which is strictly invalid but harmless in
> > practice since there's no pass after NRV which would remove
> > earlier stores.
> >
> > The following fixes this nevertheless.
> >
> > Bootstrapped and tested on x86_64-unknown-linux-gnu, OK?
> >
> > Thanks,
> > Richard.
> >
> > PR tree-optimization/110434
> > * tree-nrv.cc (pass_nrv::execute): Remove CLOBBERs of
> > VAR we replace with <retval>.
>
> This is in a loop over all basic blocks in a function.
> Do we want to kill all clobbers, or just the ones at the end of functions
> (i.e. after the <result> = VAR; assignment that we also remove)?
> Complication is that doesn't necessarily have to be just the rest of
> a single basic block, but all basic blocks from that point until end of
> function.
> I mean, if we have
> var = whatever;
> use (var);
> var = {CLOBBER};
> ...
> var = whatever_else;
> <result> = var;
> var = {CLOBBER};
> killing the first clobber might result in missed optimizations later on.
As said there's nothing run after NRV.
>
> On the other side, could there be partial clobbers for the var -> <result>,
> var.fld = {CLOBBER};
> ? Or even worse, indirect clobbers (MEM_REF with SSA_NAME pointing to
> var or parts of it)?
We know that 'var' is not address taken, not sure about the partial
clobbers. We could deal with this in the walk_gimple_op case and
simply remove a clobber when data.modified.
I went at it under the presumption that <retval> never goes out of
scope so we shouldn't have any CLOBBER for it. You could also say
that NRV should operate flow-sensitive, going from returns backwards
and simply stop replacing when the var it substitutes for is clobbered.
I'll do the adjustment handling var.fld = {CLOBBER};
If we don't remove earlier clobbers shouldn't that prevent the NRV
then?
Richard.
next prev parent reply other threads:[~2023-06-28 12:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230628102150.620743857B8E@sourceware.org>
2023-06-28 10:37 ` Jakub Jelinek
2023-06-28 12:32 ` Richard Biener [this message]
2023-06-28 12:38 ` Jakub Jelinek
[not found] <20230628102159.84C093858412@sourceware.org>
2023-06-28 14:19 ` Jeff Law
2023-06-28 10:21 Richard Biener
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=nycvar.YFH.7.77.849.2306281227240.4723@jbgna.fhfr.qr \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@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).