From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 698643858C52 for ; Thu, 10 Nov 2022 15:14:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 698643858C52 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 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 93BF6228F7 for ; Thu, 10 Nov 2022 15:14:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1668093274; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=own6zNlhMdMHQpMcpidLhe0p0oEgSlCLkwMl4H8c+xE=; b=Ye5ZdWWiH8hLelZT2q/WLTtSTKlFKoiWSS9elFGNg8EGwwQPQS2aGHtVUi/7HceiYae1W8 Up3ykzfpHhPfcjAlfvB5hxyRJmYqzW+oAQlAT8j1wi+kfJhZ8Kucq0G2YZNY4OV5c+Fa9W hkyM4OjGyoUBowOModXwjgaFWLBilzA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1668093274; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=own6zNlhMdMHQpMcpidLhe0p0oEgSlCLkwMl4H8c+xE=; b=wQtoeMinOL7crxX7EOh0V8RlnlAlNqwS7SA/Asb8gnkWOwNOW5xEjFawXIO5ANBA/V0oVO Jhric9KZugW/mkAA== 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 7F16613B58 for ; Thu, 10 Nov 2022 15:14:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ZPLiHVoVbWNfPwAAMHmgww (envelope-from ) for ; Thu, 10 Nov 2022 15:14:34 +0000 Date: Thu, 10 Nov 2022 16:14:34 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Make last DCE remove empty loops MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20221110151434.7F16613B58@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP 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: The following makes the last DCE pass CD-DCE and in turn the last CD-DCE pass a DCE one. That ensues we remove empty loops that become empty between the two. I've also moved the tail-call pass after DCE since DCE can only improve things here. The two testcases were the only ones scanning cddce3 so I've changed them to scan the dce7 pass that's now in this place. The testcases scanning dce7 also work when that's in the earlier position. Bootstrapped and tested on x86_64-unknown-linux-gnu, I'm going to push this tomorrow if there are no comments. Richard. PR tree-optimization/84646 * tree-ssa-dce.cc (pass_dce::set_pass_param): Add param wheter to run update-address-taken. (pass_dce::execute): Honor it. * passes.def: Exchange last DCE and CD-DCE invocations. Swap pass_tail_calls and the last DCE. * g++.dg/tree-ssa/pr106922.C: Continue to scan earlier DCE dump. * gcc.dg/tree-ssa/20030808-1.c: Likewise. --- gcc/passes.def | 8 ++++---- gcc/testsuite/g++.dg/tree-ssa/pr106922.C | 4 ++-- gcc/testsuite/gcc.dg/tree-ssa/20030808-1.c | 6 +++--- gcc/tree-ssa-dce.cc | 15 +++++++++++++-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/gcc/passes.def b/gcc/passes.def index 193b5794749..462e9afad61 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -346,8 +346,8 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_ccp, true /* nonzero_p */); NEXT_PASS (pass_warn_restrict); NEXT_PASS (pass_dse); - NEXT_PASS (pass_cd_dce, true /* update_address_taken_p */); - /* After late CD DCE we rewrite no longer addressed locals into SSA + NEXT_PASS (pass_dce, true /* update_address_taken_p */); + /* After late DCE we rewrite no longer addressed locals into SSA form if possible. */ NEXT_PASS (pass_forwprop); NEXT_PASS (pass_sink_code, true /* unsplit edges */); @@ -355,12 +355,12 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_fold_builtins); NEXT_PASS (pass_optimize_widening_mul); NEXT_PASS (pass_store_merging); - NEXT_PASS (pass_tail_calls); /* If DCE is not run before checking for uninitialized uses, we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c). However, this also causes us to misdiagnose cases that should be real warnings (e.g., testsuite/gcc.dg/pr18501.c). */ - NEXT_PASS (pass_dce); + NEXT_PASS (pass_cd_dce, false /* update_address_taken_p */); + NEXT_PASS (pass_tail_calls); /* Split critical edges before late uninit warning to reduce the number of false positives from it. */ NEXT_PASS (pass_split_crit_edges); diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr106922.C b/gcc/testsuite/g++.dg/tree-ssa/pr106922.C index 2aec4975aa8..4b6a4ad7f6c 100644 --- a/gcc/testsuite/g++.dg/tree-ssa/pr106922.C +++ b/gcc/testsuite/g++.dg/tree-ssa/pr106922.C @@ -1,5 +1,5 @@ // { dg-require-effective-target c++20 } -// { dg-options "-O2 -fdump-tree-cddce3" } +// { dg-options "-O2 -fdump-tree-dce7" } template struct __new_allocator { void deallocate(int *, int) { operator delete(0); } @@ -87,4 +87,4 @@ void testfunctionfoo() { } } -// { dg-final { scan-tree-dump-not "m_initialized" "cddce3" } } +// { dg-final { scan-tree-dump-not "m_initialized" "dce7" } } diff --git a/gcc/testsuite/gcc.dg/tree-ssa/20030808-1.c b/gcc/testsuite/gcc.dg/tree-ssa/20030808-1.c index 456f6f27128..7d4a1383ca4 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/20030808-1.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/20030808-1.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O1 -fdump-tree-cddce3" } */ +/* { dg-options "-O1 -fdump-tree-dce7" } */ extern void abort (void); @@ -33,8 +33,8 @@ delete_dead_jumptables () /* There should be no loads of ->code. If any exist, then we failed to optimize away all the IF statements and the statements feeding their conditions. */ -/* { dg-final { scan-tree-dump-times "->code" 0 "cddce3"} } */ +/* { dg-final { scan-tree-dump-times "->code" 0 "dce7"} } */ /* There should be no IF statements. */ -/* { dg-final { scan-tree-dump-times "if " 0 "cddce3"} } */ +/* { dg-final { scan-tree-dump-times "if " 0 "dce7"} } */ diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc index 54e5d8c2923..187d58bdd37 100644 --- a/gcc/tree-ssa-dce.cc +++ b/gcc/tree-ssa-dce.cc @@ -2005,14 +2005,25 @@ class pass_dce : public gimple_opt_pass { public: pass_dce (gcc::context *ctxt) - : gimple_opt_pass (pass_data_dce, ctxt) + : gimple_opt_pass (pass_data_dce, ctxt), update_address_taken_p (false) {} /* opt_pass methods: */ opt_pass * clone () final override { return new pass_dce (m_ctxt); } + void set_pass_param (unsigned n, bool param) final override + { + gcc_assert (n == 0); + update_address_taken_p = param; + } bool gate (function *) final override { return flag_tree_dce != 0; } - unsigned int execute (function *) final override { return tree_ssa_dce (); } + unsigned int execute (function *) final override + { + return (tree_ssa_dce () + | (update_address_taken_p ? TODO_update_address_taken : 0)); + } +private: + bool update_address_taken_p; }; // class pass_dce } // anon namespace -- 2.35.3