public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ptk.prasertsuk at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/110035] Missed optimization for dependent assignment statements
Date: Tue, 06 Jun 2023 05:46:40 +0000	[thread overview]
Message-ID: <bug-110035-4-isuuURF9tt@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110035-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #11 from Pontakorn Prasertsuk <ptk.prasertsuk at gmail dot com> ---
(In reply to rguenther@suse.de from comment #10)
> On Mon, 5 Jun 2023, ptk.prasertsuk at gmail dot com wrote:
> 
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110035
> > 
> > --- Comment #9 from Pontakorn Prasertsuk <ptk.prasertsuk at gmail dot com> ---
> > (In reply to Richard Biener from comment #8)
> > > (In reply to Pontakorn Prasertsuk from comment #7)
> > > > For the LLVM IR code of the snippet I provided, Clang's alias analysis can
> > > > prove that `new` call has no side effect to other memory location. This is
> > > > indicated by `noalias` keyword at the return value of the `new` call (_Znwm).
> > > > 
> > > > According to Clang's Language Reference:
> > > > "On function return values, the noalias attribute indicates that the
> > > > function acts like a system memory allocation function, returning a pointer
> > > > to allocated storage disjoint from the storage for any other object
> > > > accessible to the caller."
> > > > 
> > > > Is this possible for GCC alias analysis pass?
> > > 
> > > >   MyClass c = a;
> > > >   MyClass *b = new MyClass;
> > > >   *b = c;
> > > 
> > > the point is that 'new' can alter the value of 'a', GCC already knows that
> > > 'b' is distinct from c and a but that's not the relevant thing.  It looks
> > > like LLVM creates wrong-code here.
> > 
> > In what case can 'new' alter 'a'? I thought memory allocation functions such as
> > 'malloc, 'calloc' and 'new' cannot alias other memory locations than its return
> > value.
> 
> 'new' can be overridden by the user, you can declare your own 
> implementation that does fancy stuff behind the scenes, including
> in the above case altering 'a'.  Welcome to C++ ...

I assume you are referring to this case: https://godbolt.org/z/z4Y7YdxWE

Clang indeed assumes that 'new' is non-alias and this feature can be turned off
by using -fno-assume-sane-operator-new

However, can we safely assume that 'malloc' and 'calloc' are non-alias as well?

  parent reply	other threads:[~2023-06-06  5:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30  8:35 [Bug tree-optimization/110035] New: " ptk.prasertsuk at gmail dot com
2023-05-30 11:55 ` [Bug tree-optimization/110035] " rguenth at gcc dot gnu.org
2023-05-30 16:45 ` pinskia at gcc dot gnu.org
2023-05-30 17:22 ` pinskia at gcc dot gnu.org
2023-05-31  1:20 ` ptk.prasertsuk at gmail dot com
2023-05-31  1:46 ` ptk.prasertsuk at gmail dot com
2023-05-31  6:34 ` rguenther at suse dot de
2023-06-03  0:23 ` ptk.prasertsuk at gmail dot com
2023-06-05  7:16 ` rguenth at gcc dot gnu.org
2023-06-05  7:58 ` ptk.prasertsuk at gmail dot com
2023-06-05  8:11 ` rguenther at suse dot de
2023-06-06  5:46 ` ptk.prasertsuk at gmail dot com [this message]
2023-06-06  5:49 ` ptk.prasertsuk at gmail dot com
2023-06-06  8:17 ` rguenther at suse dot de
2023-06-06  8:29 ` rguenth at gcc dot gnu.org
2023-06-06  9:12 ` amonakov at gcc dot gnu.org
2023-06-06 11:54 ` rguenther at suse dot de
2024-05-24  7:50 ` user202729 at protonmail dot com

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-110035-4-isuuURF9tt@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).