From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 07C643858D35 for ; Wed, 28 Jun 2023 12:32:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 07C643858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 05D801F8CC; Wed, 28 Jun 2023 12:32:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1687955572; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Wx5yOwJVpndBYT0qSZTmtFpcMm65ANqFu1PLCkXFHz4=; b=JfrVA8hCubispO6xLscHxhLpqRbjmOw374NVarP7QZ4mKEhJft/T+szYjySBDdP1BgUTJz CKfroMng6TKEiBvHRXuY5cKwrmVQ/9l95wX33p+TwgNZS69GFBfNvhpCBT7wJBHxs+jHMA 9+8c00S9CFclnHCOxIVx2HtrLWdPSuA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1687955572; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Wx5yOwJVpndBYT0qSZTmtFpcMm65ANqFu1PLCkXFHz4=; b=Nu3Eegwcz41XjhRAP7ZC694QQKNs7dx0pey6sKy3Ugs3tN9D//0gnJcRd6k5Y9X3kfFB3H dWUk94k+qI6938Cg== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id ED6A72C308; Wed, 28 Jun 2023 12:32:51 +0000 (UTC) Date: Wed, 28 Jun 2023 12:32:51 +0000 (UTC) From: Richard Biener To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] tree-optimization/110434 - avoid ={v} {CLOBBER} from NRV In-Reply-To: Message-ID: References: <20230628102150.620743857B8E@sourceware.org> User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,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 List-Id: On Wed, 28 Jun 2023, Jakub Jelinek wrote: > On Wed, Jun 28, 2023 at 10:21:45AM +0000, Richard Biener via Gcc-patches wrote: > > When NRV replaces a local variable with it also replaces > > occurences in clobbers. This leads to being clobbered > > before the return of it which is strictly invalid but harmless in > > practice since there's no pass after NRV which would remove > > earlier stores. > > > > The following fixes this nevertheless. > > > > Bootstrapped and tested on x86_64-unknown-linux-gnu, OK? > > > > Thanks, > > Richard. > > > > PR tree-optimization/110434 > > * tree-nrv.cc (pass_nrv::execute): Remove CLOBBERs of > > VAR we replace with . > > This is in a loop over all basic blocks in a function. > Do we want to kill all clobbers, or just the ones at the end of functions > (i.e. after the = VAR; assignment that we also remove)? > Complication is that doesn't necessarily have to be just the rest of > a single basic block, but all basic blocks from that point until end of > function. > I mean, if we have > var = whatever; > use (var); > var = {CLOBBER}; > ... > var = whatever_else; > = var; > var = {CLOBBER}; > killing the first clobber might result in missed optimizations later on. As said there's nothing run after NRV. > > On the other side, could there be partial clobbers for the var -> , > var.fld = {CLOBBER}; > ? Or even worse, indirect clobbers (MEM_REF with SSA_NAME pointing to > var or parts of it)? We know that 'var' is not address taken, not sure about the partial clobbers. We could deal with this in the walk_gimple_op case and simply remove a clobber when data.modified. I went at it under the presumption that never goes out of scope so we shouldn't have any CLOBBER for it. You could also say that NRV should operate flow-sensitive, going from returns backwards and simply stop replacing when the var it substitutes for is clobbered. I'll do the adjustment handling var.fld = {CLOBBER}; If we don't remove earlier clobbers shouldn't that prevent the NRV then? Richard.