From patchwork Mon Jul 31 17:04:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1815122 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=qSoG1hEt; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Okaa7VVf; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RF4Nt2Zntz20G9 for ; Tue, 1 Aug 2023 03:05:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 788583857BA4 for ; Mon, 31 Jul 2023 17:04:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 6452E3858C53 for ; Mon, 31 Jul 2023 17:04:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6452E3858C53 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id EC4D02203B; Mon, 31 Jul 2023 17:04:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1690823076; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=5rzIKYQavh6UDRvC7J2C/4SBq4DoDlZYjaUFw2G/KNw=; b=qSoG1hEtvvdzzSQpkDD2Oiej46vWgl67U1X43IO45uRXNQzPNsuFRYLvKqTZROTI2LFAAd 1Y2J6q74oIPnNW7OS+87crOAS0fJjVNJ4PqQgnao2qt6Fp2Q5UMlDXoQmVUcOPiHWZiKkD VzaYlsZFe2AwsSK4udEi3bFGa97dMkA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1690823076; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=5rzIKYQavh6UDRvC7J2C/4SBq4DoDlZYjaUFw2G/KNw=; b=Okaa7VVfmkJ+2eYOHSmaAJxR++lbQJ5ceufK4Rm8e9hEPiIk/Xm+DkUN+JwP/z5+DpG+8D edcxkAd5K06hcZDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DFA85133F7; Mon, 31 Jul 2023 17:04:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 7KzPNaTpx2TDJAAAMHmgww (envelope-from ); Mon, 31 Jul 2023 17:04:36 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: [PATCH] ipa-sra: Don't consider CLOBBERS as writes preventing splitting User-Agent: Notmuch/0.37 (https://notmuchmail.org) Emacs/28.2 (x86_64-suse-linux-gnu) Date: Mon, 31 Jul 2023 19:04:36 +0200 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_SOFTFAIL, 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-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, when IPA-SRA detects whether a parameter passed by reference is written to, it does not special case CLOBBERs which means it often bails out unnecessarily, especially when dealing with C++ destructors. Fixed by the obvious continue in the two relevant loops. The (slightly) more complex testcases in the PR need surprisingly more effort but the simple one can be fixed now easily by this patch and I'll work on the others incrementally. Bootstrapped and currently undergoing testsuite run on x86_64-linux. OK if it passes too? Thanks, Martin gcc/ChangeLog: 2023-07-31 Martin Jambor PR ipa/110378 * ipa-sra.cc (isra_track_scalar_value_uses): Ignore clobbers. (ptr_parm_has_nonarg_uses): Likewise. gcc/testsuite/ChangeLog: 2023-07-31 Martin Jambor PR ipa/110378 * g++.dg/ipa/pr110378-1.C: New test. --- gcc/ipa-sra.cc | 6 ++-- gcc/testsuite/g++.dg/ipa/pr110378-1.C | 47 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ipa/pr110378-1.C diff --git a/gcc/ipa-sra.cc b/gcc/ipa-sra.cc index c35e03b7abd..edba364f56e 100644 --- a/gcc/ipa-sra.cc +++ b/gcc/ipa-sra.cc @@ -898,7 +898,8 @@ isra_track_scalar_value_uses (function *fun, cgraph_node *node, tree name, FOR_EACH_IMM_USE_STMT (stmt, imm_iter, name) { - if (is_gimple_debug (stmt)) + if (is_gimple_debug (stmt) + || gimple_clobber_p (stmt)) continue; /* TODO: We could handle at least const builtin functions like arithmetic @@ -1056,7 +1057,8 @@ ptr_parm_has_nonarg_uses (cgraph_node *node, function *fun, tree parm, unsigned uses_ok = 0; use_operand_p use_p; - if (is_gimple_debug (stmt)) + if (is_gimple_debug (stmt) + || gimple_clobber_p (stmt)) continue; if (gimple_assign_single_p (stmt)) diff --git a/gcc/testsuite/g++.dg/ipa/pr110378-1.C b/gcc/testsuite/g++.dg/ipa/pr110378-1.C new file mode 100644 index 00000000000..aabe326b8b2 --- /dev/null +++ b/gcc/testsuite/g++.dg/ipa/pr110378-1.C @@ -0,0 +1,47 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-ipa-sra -fdump-tree-optimized-slim" } */ + +/* Test that even though destructors end with clobbering all of *this, it + should not prevent IPA-SRA. */ + +namespace { + + class foo + { + public: + int *a; + foo(int c) + { + a = new int[c]; + a[0] = 4; + } + __attribute__((noinline)) ~foo(); + int f () + { + return a[0] + 1; + } + }; + + volatile int v1 = 4; + + __attribute__((noinline)) foo::~foo() + { + delete[] a; + return; + } + + +} + +volatile int v2 = 20; + +int test (void) +{ + foo shouldnotexist(v2); + v2 = shouldnotexist.f(); + return 0; +} + + +/* { dg-final { scan-ipa-dump "Will split parameter 0" "sra" } } */ +/* { dg-final { scan-tree-dump-not "shouldnotexist" "optimized" } } */