From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DD7F438515CD; Wed, 25 May 2022 14:14:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD7F438515CD From: "felix-gcc at fefe dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/105728] New: dead store to static var not optimized out Date: Wed, 25 May 2022 14:14:24 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 11.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: felix-gcc at fefe dot de 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 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: Wed, 25 May 2022 14:14:25 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105728 Bug ID: 105728 Summary: dead store to static var not optimized out Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: felix-gcc at fefe dot de Target Milestone: --- Consider this piece of test code: int dummy1() { static int removeme =3D 0; if (removeme) { return 0; } removeme =3D 1; return 0; } int dummy2() { static int removeme =3D 0; if (!removeme) removeme =3D 1; return 0; } int dummy3() { static int removeme =3D 0; removeme =3D 1; return 0; } To me, all of these do the same thing and should generate the same code. As nobody else can see removeme, and we aren't leaking its address, shouldn= 't the compiler be able to deduce that all accesses to removeme are inconsequential and can be removed? My gcc 11.3 generates a condidion and a store and a return 0 for dummy1, the same thing for dummy2, but for dummy3 it understands that it only needs to = emit a return 0.=