From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 96BFE385B800; Mon, 5 Jun 2023 08:11:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96BFE385B800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685952662; bh=gjguslKt8JxHsZE/qerwV5QVXJAEoRszKGCppgXIKIM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WElVJxABtJREAyOPMwf30av1fG0oOZJ9zVqw2X1fosesv6wJ+jpoRPhnXQOzBfKRc aoVFHRPPGhMGf0ruveZpo3/cIjsyzwFzDwSamvCVfy6VkDj65Fa7xa1veT8vjTOors amwJRS2xOADuzoNN3FpxqQyk2cYE139PGApZDyJ0= From: "rguenther at suse dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/110035] Missed optimization for dependent assignment statements Date: Mon, 05 Jun 2023 08:11:01 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: rguenther at suse dot de X-Bugzilla-Status: NEW 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=3D110035 --- Comment #10 from rguenther at suse dot de --- On Mon, 5 Jun 2023, ptk.prasertsuk at gmail dot com wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110035 >=20 > --- Comment #9 from Pontakorn Prasertsuk --- > (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 analysi= s can > > > prove that `new` call has no side effect to other memory location. Th= is is > > > indicated by `noalias` keyword at the return value of the `new` call = (_Znwm). > > >=20 > > > 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 p= ointer > > > to allocated storage disjoint from the storage for any other object > > > accessible to the caller." > > >=20 > > > Is this possible for GCC alias analysis pass? > >=20 > > > MyClass c =3D a; > > > MyClass *b =3D new MyClass; > > > *b =3D c; > >=20 > > the point is that 'new' can alter the value of 'a', GCC already knows t= hat > > 'b' is distinct from c and a but that's not the relevant thing. It loo= ks > > like LLVM creates wrong-code here. >=20 > In what case can 'new' alter 'a'? I thought memory allocation functions s= uch 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=20 implementation that does fancy stuff behind the scenes, including in the above case altering 'a'. Welcome to C++ ...=