From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 0541F3986431 for ; Fri, 4 Sep 2020 10:22:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0541F3986431 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rguenther@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id E9EDFAEBF for ; Fri, 4 Sep 2020 10:22:23 +0000 (UTC) Date: Fri, 4 Sep 2020 12:22:22 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/96931 - clear ctrl-altering flag more aggressively Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , X-List-Received-Date: Fri, 04 Sep 2020 10:22:25 -0000 The testcase shows that we fail to clear gimple_call_ctrl_altering_p when the last abnormal edge goes away, causing an edge insert to a loop header edge when we have preheaders to split the edge unnecessarily. The following addresses this by more aggressively clearing the flag in cleanup_call_ctrl_altering_flag. Bootstrapped / tested on x86_64-unknown-linux-gnu, pushed to master. 2020-09-04 Richard Biener PR tree-optimization/96931 * tree-cfgcleanup.c (cleanup_call_ctrl_altering_flag): If there's a fallthru edge and no abnormal edge the call is no longer control-altering. (cleanup_control_flow_bb): Pass down the BB to cleanup_call_ctrl_altering_flag. * gcc.dg/pr96931.c: New testcase. --- gcc/testsuite/gcc.dg/pr96931.c | 19 +++++++++++++++++++ gcc/tree-cfgcleanup.c | 22 ++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr96931.c diff --git a/gcc/testsuite/gcc.dg/pr96931.c b/gcc/testsuite/gcc.dg/pr96931.c new file mode 100644 index 00000000000..94b8a1128ee --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96931.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fpredictive-commoning -fno-tree-loop-im" } */ + +int bl; + +void +p3 (void); + +void __attribute__ ((returns_twice)) +ie (void) +{ + p3 (); + + bl = 0; + for (;;) + ++bl; + + ie (); +} diff --git a/gcc/tree-cfgcleanup.c b/gcc/tree-cfgcleanup.c index 4763cd45a1c..f8169eef781 100644 --- a/gcc/tree-cfgcleanup.c +++ b/gcc/tree-cfgcleanup.c @@ -209,7 +209,7 @@ cleanup_control_expr_graph (basic_block bb, gimple_stmt_iterator gsi) to updated gimple_call_flags. */ static void -cleanup_call_ctrl_altering_flag (gimple *bb_end) +cleanup_call_ctrl_altering_flag (basic_block bb, gimple *bb_end) { if (!is_gimple_call (bb_end) || !gimple_call_ctrl_altering_p (bb_end)) @@ -220,6 +220,24 @@ cleanup_call_ctrl_altering_flag (gimple *bb_end) && !(flags & ECF_LOOPING_CONST_OR_PURE)) || (flags & ECF_LEAF)) gimple_call_set_ctrl_altering (bb_end, false); + else + { + edge_iterator ei; + edge e; + bool found = false; + FOR_EACH_EDGE (e, ei, bb->succs) + if (e->flags & EDGE_FALLTHRU) + found = true; + else if (e->flags & EDGE_ABNORMAL) + { + found = false; + break; + } + /* If there's no abnormal edge and a fallthru edge the call + isn't control-altering anymore. */ + if (found) + gimple_call_set_ctrl_altering (bb_end, false); + } } /* Try to remove superfluous control structures in basic block BB. Returns @@ -243,7 +261,7 @@ cleanup_control_flow_bb (basic_block bb) stmt = gsi_stmt (gsi); /* Try to cleanup ctrl altering flag for call which ends bb. */ - cleanup_call_ctrl_altering_flag (stmt); + cleanup_call_ctrl_altering_flag (bb, stmt); if (gimple_code (stmt) == GIMPLE_COND || gimple_code (stmt) == GIMPLE_SWITCH) -- 2.26.2