From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 894193857BB6; Wed, 25 May 2022 16:21:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 894193857BB6 From: "hubicka at kam dot mff.cuni.cz" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/105728] dead store to static var not optimized out Date: Wed, 25 May 2022 16:21:37 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: hubicka at kam dot mff.cuni.cz 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: 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 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 16:21:37 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105728 --- Comment #1 from hubicka at kam dot mff.cuni.cz --- > 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, shoul= dn't > the compiler be able to deduce that all accesses to removeme are > inconsequential and can be removed? >=20 > 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 t= o emit > a return 0. GCC detects "write olny" variables and that is what matches for dummy3. I am not 100% sure it is valid to do the optimization in other two cases since when multiple threads are considered. In any case we lack tracking of constants stored to global variables which is something ipa-cp can be extended to. Honza=