From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id E9E6E3857BB1; Wed, 25 May 2022 16:21:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E9E6E3857BB1 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id ABB8D281B54; Wed, 25 May 2022 18:21:28 +0200 (CEST) Date: Wed, 25 May 2022 18:21:28 +0200 From: Jan Hubicka To: felix-gcc at fefe dot de Cc: gcc-bugs@gcc.gnu.org Subject: Re: [Bug c/105728] New: dead store to static var not optimized out Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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:36 -0000 > 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. 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