public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/97474] [8/9/10/11 Regression] produces wrong code with references to another field
Date: Mon, 19 Oct 2020 07:49:25 +0000	[thread overview]
Message-ID: <bug-97474-4-pB1r8eveAO@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-97474-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
OK, so the issue is that the C++ frontend marks 'this' as restrict which in
turn means that no other pointer can alias it.  For foo() GCC computes

  <bb 2> :
  _1 = MEM[(struct A &)a_7(D) clique 1 base 1].a;
  # PT = nonlocal escaped null 
  _2 = MEM[(struct A &)a_7(D) clique 1 base 1].b;
  _3 = MEM[(int &)_2 clique 1 base 0]; 
  _4 = _1 * _3; 
  MEM[(struct A &)a_7(D) clique 1 base 1].a = _4;
  # PT = nonlocal escaped null  
  _5 = MEM[(struct A &)a_7(D) clique 1 base 1].b;
  _9 = MEM[(int &)_5 clique 1 base 0]; 
  return _9;

in particular

a_7(D), points-to NULL, points-to vars: { D.2410 } (nonlocal, restrict)
_5, points-to non-local, points-to escaped, points-to NULL, points-to vars: { }

and thus the load of _9 via _5 does not alias the store via a_7.  Basically,
GCC does not consider storage pointed to by a restrict pointer to point to
itself (what the CTOR does - make b refer to its own a).

It's not difficult to fix this - simply amend the constraints:

a = &PARM_NOALIAS(9)
PARM_NOALIAS(9) = &NONLOCAL

also have

PARM_NOALIAS(9) = &PARM_NOALIAS(9)

the question is whether this generally applies to restrict qualified pointers.
In some sense for

 A * restrict p;
 int *q = p->b;

q is derived from p.

  parent reply	other threads:[~2020-10-19  7:49 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-17 20:42 [Bug c++/97474] New: Regression: optimization produces wrong code sfranzen85 at hotmail dot com
2020-10-17 21:21 ` [Bug c++/97474] " pinskia at gcc dot gnu.org
2020-10-17 21:31 ` [Bug tree-optimization/97474] [8/9/10/11 Regression] produces wrong code with references to another field pinskia at gcc dot gnu.org
2020-10-17 21:40 ` jakub at gcc dot gnu.org
2020-10-19  7:33 ` rguenth at gcc dot gnu.org
2020-10-19  7:49 ` rguenth at gcc dot gnu.org [this message]
2020-10-19  8:35 ` rguenth at gcc dot gnu.org
2020-10-19  8:36 ` rguenth at gcc dot gnu.org
2020-10-19 21:32 ` joseph at codesourcery dot com
2020-10-20  6:39 ` [Bug c++/97474] " rguenth at gcc dot gnu.org
2020-10-20  6:47 ` jakub at gcc dot gnu.org
2020-10-20  6:50 ` jakub at gcc dot gnu.org
2021-01-25 16:32 ` jason at gcc dot gnu.org
2021-01-26  8:29 ` rguenther at suse dot de
2021-01-26 21:12 ` jason at gcc dot gnu.org
2021-01-26 22:11 ` cvs-commit at gcc dot gnu.org
2021-01-27  9:12 ` rguenther at suse dot de
2021-01-29 16:00 ` cvs-commit at gcc dot gnu.org
2021-02-03 15:56 ` [Bug c++/97474] [8/9 " jakub at gcc dot gnu.org
2021-05-14  9:54 ` [Bug c++/97474] [9 " jakub at gcc dot gnu.org
2021-06-01  8:18 ` rguenth at gcc dot gnu.org
2022-05-11 20:05 ` jason at gcc dot gnu.org
2022-05-11 20:13 ` pinskia at gcc dot gnu.org

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-97474-4-pB1r8eveAO@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).