From: Richard Biener <rguenther@suse.de>
To: Joseph Myers <joseph@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org, Jakub Jelinek <jakub@redhat.com>, matz@suse.de
Subject: Re: [PATCH 1/4][RFC] middle-end/90348 - add explicit birth
Date: Tue, 8 Feb 2022 08:20:21 +0100 (CET) [thread overview]
Message-ID: <o34ssq83-o2os-5s8-1572-2934pp3ps26@fhfr.qr> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2202072342100.9395@digraph.polyomino.org.uk>
On Mon, 7 Feb 2022, Joseph Myers wrote:
> On Fri, 4 Feb 2022, Richard Biener via Gcc-patches wrote:
>
> > This adds explicit variable birth CLOBBERs in an attempt to fix
> > PR90348 and duplicates. The birth / death CLOBBER pairs are
> > used to compute liveness and conflicts for stack variable
> > coalescing where the lack of an explicit birth but instead
> > use of first mention causes misrepresentation of variable life
> > ranges when optimization moves the first mention upwards the
> > original birth point at the variables bind expression start.
>
> I'm not clear on exactly where you consider a variable to be born, but
> note that non-VLA C variables have a lifetime that starts at the beginning
> of their block, not at their declaration: it's valid to jump backward from
> after the declaration to before it and then access the variable via a
> pointer, or jump forward again over the declaration and access it by name.
> (Most programs of course don't do that sort of thing.)
Oh, interesting. So the following is valid
int foo(int always_true_at_runtime)
{
{
int *p;
if (always_true_at_runtime)
goto after;
lab:
return *p;
after:
int i = 0;
p = &i;
if (always_true_at_runtime)
goto lab;
}
return 0;
}
For the implementation I considered starting lifetime at a DECL_EXPR
if it exists and otherwise at the start of the BIND_EXPR. Note the
complication is that control flow has to reach the lifetime-start
clobber before the first access. But that might also save us here,
since for the example above 'i' would be live via the backedge
from goto lab.
That said, the existing complication is that when the gimplifier
visits the BIND_EXPR it has no way to know whether there will be
a following DECL_EXPR or not (and the gimplifier notes there are
cases a DECL_EXPR variable is not in a BIND_EXPR). My plan is to
compute this during one of the body walks the gimplifier performs
before gimplifying.
Another complication is that at least the C frontend + gimplifier
combination for
switch (i)
{
case 1:
int i;
break;
}
will end up having the BIND_EXPR mentioning 'i' containing the
case label, so just placing the birth at the BIND will make it
unreachable as
i = BIRTH;
case_label_for_1:
...
conveniently at least the C frontend has a DECL_EXPR for 'i'
which avoids this and I did not find a way (yet) in the gimplifier
to rectify this when gimplifying switches.
So there's still work to do but I think that starting the lifetime
at a DECL_EXPR if it exists is the way to go?
Richard.
next prev parent reply other threads:[~2022-02-08 7:20 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-04 13:49 Richard Biener
2022-02-04 14:03 ` Jakub Jelinek
2022-02-04 14:11 ` Richard Biener
2022-02-05 18:21 ` Jeff Law
2022-02-05 19:54 ` Eric Botcazou
2022-02-07 7:29 ` Richard Biener
2022-02-08 10:31 ` Eric Botcazou
2022-02-07 23:46 ` Joseph Myers
2022-02-08 7:20 ` Richard Biener [this message]
2022-02-08 14:13 ` Michael Matz
2022-02-08 14:53 ` Richard Biener
2022-02-08 15:19 ` Michael Matz
2022-02-09 14:25 ` Richard Biener
2022-02-09 15:55 ` Michael Matz
2022-02-08 18:38 ` Joseph Myers
2022-02-09 13:37 ` Michael Matz
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=o34ssq83-o2os-5s8-1572-2934pp3ps26@fhfr.qr \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=joseph@codesourcery.com \
--cc=matz@suse.de \
/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).