From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EECC33858D39; Thu, 3 Mar 2022 17:18:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EECC33858D39 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/104696] [OpenMP] Implicit mapping breaks struct mapping Date: Thu, 03 Mar 2022 17:18:51 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: missed-optimization, openmp, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus 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: 12.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: short_desc keywords 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Mar 2022 17:18:52 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104696 Tobias Burnus changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|[12 Regression][OpenMP] |[OpenMP] Implicit mapping |Implicit mapping breaks |breaks struct mapping |struct mapping | Keywords| |missed-optimization --- Comment #1 from Tobias Burnus --- Looking closer at it, I no longer think it is a regression (to be checked if deemed important). But it looks as if there are two problems - one wrong-code one and one missed-optimization one. Namely, I think reason for both issues is that=20 map(to:var3.r[1].d [len: 88]) ... is not turned into map(struct:var3 [len: 1]) map(to:var3.r[1].d [len: 88]) but into 'to' + pointer assign. This does not even work when using the 'alw= ays' modifier. ('struct:' appears when using 'Q' instead of 'R(2)'.) That that the struct not detected seems to be because array and component r= efs are mixed =E2=80=93 hiding that the var is memory wise in the same struct. I believe with that fixed, it would work correctly. * * * For C/C++, it "works". But: it still does not detect that the member is part of the whole struct -= and allocates pointlessly too much memory. To illustrate this, I added a large 'arr' element. Otherwise, that the reason that it works in C/C++ is that ATTACH and not pointer assign is used. Namely: ------------ test.c-------------- struct s { int *d; }; struct s2 { struct s r[5], q, arr[1024][1024]; }; int main () { struct s2 x; x.q.d =3D __builtin_malloc(sizeof(int)); x.r[1].d =3D __builtin_malloc(sizeof(int)); #pragma omp target map(tofrom: x.q.d[:1]) *x.q.d =3D 2; #pragma omp target map(tofrom: x.r[1].d[:1]) *x.r[1].d =3D 3; __builtin_printf("%d, %d\n", *x.q.d, *x.r[1].d); return 0; } ------------ test.c-------------- gives: #pragma omp target num_teams(1) thread_limit(0) map(tofrom:x [len: 8388656][implicit]) map(tofrom:*_3 [len: 4]) map(attach:x.q.d [bias: 0]) #pragma omp target num_teams(1) thread_limit(0) map(tofrom:x [len: 8388656][implicit]) map(tofrom:*_4 [len: 4]) map(attach:x.r[1].d [bias: 0])=