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: 128790 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2146332vqg; Mon, 31 Jul 2023 10:05:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlE0vr4l75EjHr73SuOLZbUAxgKyiOpTSXWEi6wn89/WBJcB+M0h1vERaqdKzVEaK/+mN30Q X-Received: by 2002:a17:906:32cd:b0:99b:e5c3:2e55 with SMTP id k13-20020a17090632cd00b0099be5c32e55mr329883ejk.38.1690823130850; Mon, 31 Jul 2023 10:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690823130; cv=none; d=google.com; s=arc-20160816; b=I9k65WONuKUhxMGz+Fzivg4lhsa7q7xiSR/WxjSiSEYgHPr6DxAV2heE1Wm1AIMt0S 0GB2S4MeOnjT06RpaBWB7kfTian42fusZRylWSm9iJIU6GQtfyvBo1VhQncokyXYawwK /wSSqs2NHPuUzlSVEbSDeXfMvHg0wNC52z1N9s/1PTQm7wfjdWn7eBiCeizvdNoLjfDP e7qDQ+KFoQQVLW13plgKzcPKVipVHMonmwQNIGCCN9m6xAzEg1RcfzS8bQ+/fbxhQ6M/ nciUh2Jo7P/t/DjS7Z7Jkc2h6oKBm1krpcZVeq1cXjbO17kpZ8RItHG8XNuvFgf4QtTz wD1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:message-id:date :user-agent:subject:cc:to:from:dkim-signature:dkim-signature :dmarc-filter:delivered-to; bh=5rzIKYQavh6UDRvC7J2C/4SBq4DoDlZYjaUFw2G/KNw=; fh=ojMLEOaapByEVR9nrTirX35o9/JiRBceNKXtBAeyNsg=; b=Sp+rT6HqPKL3y+AKv9UooxeCGzAzUy4xREFCwZcXpYa9i2eBUwvAcUEZj8Y0sh42MN GAesV1ghS73frI8Zj3gy9q0h1Oii3iVY8Y050uM6LhLeTnEjtWKU7a2TQs3m9/aYE/b6 YkRwETgqHQsf1bI5F/V6OBBExEDwqvAzaOzcEPt7Zj9AZ6Oo875rXh9hfpngF+pNdg1w RKGgLwOUd+n3i38EdtB1BdZtq64PH22D+kk0yNaNNgm62mmbarObCUIaGNOAnW+K47Rf PioQiylwkpsjkrqwvQPizXhXLqtpbNw8ZERQogA+xnw1pIb6P4iZNBi69Xm8eACA466D ih3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=qSoG1hEt; dkim=neutral (no key) header.i=@gcc.gnu.org header.s=susede2_ed25519; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id i9-20020a170906a28900b0098d52a2bc16si7525973ejz.438.2023.07.31.10.05.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 10:05:30 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=qSoG1hEt; dkim=neutral (no key) header.i=@gcc.gnu.org header.s=susede2_ed25519; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 19D333857739 for ; Mon, 31 Jul 2023 17:05:12 +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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772956555183759101 X-GMAIL-MSGID: 1772956555183759101 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" } } */