From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E86403858C83; Wed, 28 Sep 2022 10:55:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E86403858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664362552; bh=jD2Ivsizyr2TkHa+nJ1YLgd8VqU8XhBj9tYNJiOp4oM=; h=From:To:Subject:Date:From; b=NiIev+xBcTBdZnApeJiiLCF516qxB2uBOEDN/xmPZkI4aODkRDnlnUHbvj7xaW8V0 45HdqFM1KncOMKonUNnHtX69Z20gVM6+3FFvA+ceUeDzzAoHgnllW/GpBTzNEIe+WF TQbIRmDlHPpgUrFn5eCwGWweSRxcLE3FwmL/ksIw= From: "fxue at os dot amperecomputing.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107066] New: Field initialized before ctor is mis-optimized away by DSE Date: Wed, 28 Sep 2022 10:55:52 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: fxue at os dot amperecomputing.com 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D107066 Bug ID: 107066 Summary: Field initialized before ctor is mis-optimized away by DSE Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: fxue at os dot amperecomputing.com Target Milestone: --- By means of user-defined new operator, it is possible that a field is initialized before constructor. #include class A { public: int f1; int f2; A() : f2(2) { } void *operator new(size_t size) { void *mem =3D ::operator new(size); A *obj =3D static_cast(mem); obj->f1 =3D 1; return obj; } }; A* foo () { return new A(); } The original gimple code of foo() is: struct A * foo () { void * D.2444; void * _9; : _9 =3D operator new (8);=20 MEM[(struct A *)_9].f1 =3D 1; MEM[(struct A *)_9] =3D{v} {CLOBBER}; MEM[(struct A *)_9].f2 =3D 2; return _9; } In gimple, there exists a pseudo clobber statement marking beginning of constructor code. Although the statement is of no side effect, it is regard= ed as normal store by DSE when determining store redundancy. Consequently, DSE thought that "MEM[(struct A *)_9].f1 =3D 1" was killed by "MEM[(struct A *)= _9] =3D{v} {CLOBBER}", and removed it. After DSE pass,the foo becomes: struct A * foo () { void * D.2444; void * _9; : _9 =3D operator new (8); MEM[(struct A *)_9] =3D{v} {CLOBBER}; MEM[(struct A *)_9].f2 =3D 2; return _9; }=