From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 560DF3858C35; Mon, 27 Nov 2023 15:47:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 560DF3858C35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701100074; bh=LjqjPjBf2E3JRtE8sqg9lOcpZK8yW69e0J/akttsUDk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=tbzlExsC1EbTB4QwY2P3W/b9YsyQurEt2i1GksWxc0DB5INi5bSGHPtjzGIBozGn5 sZ7NigUoWAhA1Ihm8oJ0nsnb3kPNe4UkUzw5gnqmPnZPmIrIAELOzBJQSMB9VVrjmG oSOiqLLr7+Z0BCsXnhMIE4JiFJjjTp+IWao5PGA4= From: "uecker at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: lto X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: alias, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: uecker at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112716 --- 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: >=20 > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112716 > >=20 > > --- Comment #5 from Martin Uecker --- > > It works (and is required to work) for other types, e.g. > >=20 > > [[gnu::noinline,gnu::noipa]] > > int foo(void *p, void *q) > > { > > int n =3D 5; > > int (*p2)[n] =3D p; > > (*p2)[0] =3D 1; > > bar(q); > > return (*p2)[0]; > > } > >=20 > > void bar(void* q) > > {=20=20=20=20=20=20=20 > > int n =3D 5; > > int (*q2)[n] =3D q; > > (*q2)[0] =3D 2; > > } > >=20 > > 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 t= he array > > directly but it decays to a pointer. (but then, other languages have ar= ray > > assignment, so why does the middle-end care about this C peculiarity?)= =20 >=20 > 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=20 equivalence classes for structs by ignoring the sizes of all fields of array type (not just VLA) and also the offsets=20 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=20 (but we could also decide to not support full ISO C rules for such structs, of course) >=20 > 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. >=20 > As said, for arrays it probably works as-is since these gets the alias > set of the component. >=20 > > There is also no indication in documentation that structs with variable= size > > follow different rules than conventional structs. So my preference wo= uld be > > to fix this somehow. Otherwise we should document this as a limitation. >=20 > Local declared structs in principle follow the same logic (but they > get promoted "global" due to implementation details I think).=