public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "uecker at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug lto/112716] LTO optimization with struct with variable size
Date: Mon, 27 Nov 2023 15:47:54 +0000	[thread overview]
Message-ID: <bug-112716-4-WLHi3u2yer@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-112716-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112716

--- Comment #7 from uecker at gcc dot gnu.org ---
(In reply to rguenther@suse.de from comment #6)
> On Mon, 27 Nov 2023, muecker at gwdg dot de wrote:
> 
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112716
> > 
> > --- Comment #5 from Martin Uecker <muecker at gwdg dot de> ---
> > It works (and is required to work) for other types, e.g.
> > 
> > [[gnu::noinline,gnu::noipa]]
> > int foo(void *p, void *q)
> > {
> >         int n = 5;
> >         int (*p2)[n] = p;
> >         (*p2)[0] = 1;
> >         bar(q);
> >         return (*p2)[0];
> > }
> > 
> > void bar(void* q)
> > {       
> >         int n = 5;
> >         int (*q2)[n] = q;
> >         (*q2)[0] = 2;
> > }
> > 
> > One could argue that there is a weaker requirement for having an object of type
> > int[n] present than for struct { int x[n]; } because we do not access the array
> > directly but it decays to a pointer. (but then, other languages have array
> > assignment, so why does the middle-end care about this C peculiarity?) 
> 
> So in theory we could disregard the VLA-sized components for TBAA
> which would make the access behaved as if it were a int * indirect access.
> I think if you write it as array as above that's already what happens.

What does "disregard the VLA-sized component" mean?

For full interoperability I think one either has to assign 
equivalence classes for structs by ignoring the sizes of all
fields of array type (not just VLA) and also the offsets 
for the following struct members, or, alternately, one has
to give alias set 0 to  structs with VLA fields.  The later
seems preferable and is what I have included in the current
version of my patch for C23 for structs with VLA fields 
(but we could also decide to not support full ISO C rules for
such structs, of course)

> 
> Note that even without LTO when you enable inlining you'd expose two
> different structures with two different alias-sets, possibly leading
> to wrong-code (look at the RTL expansion dump and check alias-sets).

Yes, for pre C23 this is true for all structs even without VLA.
But for C23 this changes.

The main case where the GNU extension is interesting and useful is
when the VLA field is at the end. So at least for this case it would
be nice to have a solution.

> 
> As said, for arrays it probably works as-is since these gets the alias
> set of the component.
> 
> > There is also no indication in documentation that structs with variable size
> > follow different rules than conventional structs.   So my preference would be
> > to fix this somehow.  Otherwise we should document this as a limitation.
> 
> Local declared structs in principle follow the same logic (but they
> get promoted "global" due to implementation details I think).

  parent reply	other threads:[~2023-11-27 15:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-26 17:46 [Bug lto/112716] New: LTO optimization with struct of variable ssize muecker at gwdg dot de
2023-11-26 17:54 ` [Bug lto/112716] " pinskia at gcc dot gnu.org
2023-11-26 18:17 ` uecker at gcc dot gnu.org
2023-11-26 18:26 ` sjames at gcc dot gnu.org
2023-11-27  8:13 ` [Bug lto/112716] LTO optimization with struct with variable size rguenth at gcc dot gnu.org
2023-11-27 14:00 ` muecker at gwdg dot de
2023-11-27 14:26 ` rguenther at suse dot de
2023-11-27 15:47 ` uecker at gcc dot gnu.org [this message]
2023-11-28  8:02 ` rguenth at gcc dot gnu.org
2023-11-28 15:19 ` muecker at gwdg dot de

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=bug-112716-4-WLHi3u2yer@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).