From patchwork Tue Nov 22 11:05:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 60967 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F01EF3851883 for ; Tue, 22 Nov 2022 11:05:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F01EF3851883 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669115147; bh=NvL6sPGExAzTkZs0SkFBcjGOB1jCBbYTpZLFrROzqgc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=xQc577jvHHQhw3LEO/XqPNXm5/anPETPRo+X4nm14TZa72vCRCLkLwXUL8W16C32O WDkxxbzPtLHdom1eRzH+ZKDw9TGSIWPrC6D31i+O74fs3nIDae2i7dO796L4Z62o7g qFc9+ZmCqRUTYweBsE24mBl6QFMvKR+En/xwZ7Aw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 588503858C50 for ; Tue, 22 Nov 2022 11:05:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 588503858C50 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 5FC8A1F86B for ; Tue, 22 Nov 2022 11:05:16 +0000 (UTC) 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 5A3D12C142 for ; Tue, 22 Nov 2022 11:05:16 +0000 (UTC) Date: Tue, 22 Nov 2022 11:05:16 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/107803 - abnormal cleanup from the SSA propagator User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, 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 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-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20221122110546.F01EF3851883@sourceware.org> The SSA propagator is missing abnormal cleanup which shows in a sanity check in the uninit engine (and missed CFG verification). The following adds that. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/107803 * tree-ssa-propagate.cc (substitute_and_fold_dom_walker): Add need_ab_cleanup member. (substitute_and_fold_dom_walker::before_dom_children): When a stmt can no longer transfer control flow abnormally set need_ab_cleanup. (substitute_and_fold_engine::substitute_and_fold): Cleanup abnormal control flow. * g++.dg/pr107803.C: New testcase. --- gcc/testsuite/g++.dg/pr107803.C | 19 +++++++++++++++++++ gcc/tree-ssa-propagate.cc | 20 ++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr107803.C diff --git a/gcc/testsuite/g++.dg/pr107803.C b/gcc/testsuite/g++.dg/pr107803.C new file mode 100644 index 00000000000..f814e968b69 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr107803.C @@ -0,0 +1,19 @@ +// { dg-do compile } +// { dg-options "-O -fno-tree-dominator-opts -fno-tree-fre -Wmaybe-uninitialized" } + +void printf(...); +void __sigsetjmp_cancel() __attribute__((__returns_twice__)); +int z, main_ret; +void func(void *) {} + +int +main() +{ + int x; + void (*__cancel_routine)(void *)(func); + __sigsetjmp_cancel(); + __cancel_routine(0); + if (main_ret) + x = z; + printf(x); +} diff --git a/gcc/tree-ssa-propagate.cc b/gcc/tree-ssa-propagate.cc index 9dc4bfd85bf..d8b0aed4564 100644 --- a/gcc/tree-ssa-propagate.cc +++ b/gcc/tree-ssa-propagate.cc @@ -671,12 +671,14 @@ public: stmts_to_remove.create (0); stmts_to_fixup.create (0); need_eh_cleanup = BITMAP_ALLOC (NULL); + need_ab_cleanup = BITMAP_ALLOC (NULL); } ~substitute_and_fold_dom_walker () { stmts_to_remove.release (); stmts_to_fixup.release (); BITMAP_FREE (need_eh_cleanup); + BITMAP_FREE (need_ab_cleanup); } edge before_dom_children (basic_block) final override; @@ -689,6 +691,7 @@ public: vec stmts_to_remove; vec stmts_to_fixup; bitmap need_eh_cleanup; + bitmap need_ab_cleanup; class substitute_and_fold_engine *substitute_and_fold_engine; @@ -838,8 +841,13 @@ substitute_and_fold_dom_walker::before_dom_children (basic_block bb) folded. */ did_replace = false; gimple *old_stmt = stmt; - bool was_noreturn = (is_gimple_call (stmt) - && gimple_call_noreturn_p (stmt)); + bool was_noreturn = false; + bool can_make_abnormal_goto = false; + if (is_gimple_call (stmt)) + { + was_noreturn = gimple_call_noreturn_p (stmt); + can_make_abnormal_goto = stmt_can_make_abnormal_goto (stmt); + } /* Replace real uses in the statement. */ did_replace |= substitute_and_fold_engine->replace_uses_in (stmt); @@ -905,6 +913,12 @@ substitute_and_fold_dom_walker::before_dom_children (basic_block bb) if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt)) bitmap_set_bit (need_eh_cleanup, bb->index); + /* If we turned a call with possible abnormal control transfer + into one that doesn't, remove abnormal edges. */ + if (can_make_abnormal_goto + && !stmt_can_make_abnormal_goto (stmt)) + bitmap_set_bit (need_ab_cleanup, bb->index); + /* If we turned a not noreturn call into a noreturn one schedule it for fixup. */ if (!was_noreturn @@ -1012,6 +1026,8 @@ substitute_and_fold_engine::substitute_and_fold (basic_block block) if (!bitmap_empty_p (walker.need_eh_cleanup)) gimple_purge_all_dead_eh_edges (walker.need_eh_cleanup); + if (!bitmap_empty_p (walker.need_ab_cleanup)) + gimple_purge_all_dead_abnormal_call_edges (walker.need_ab_cleanup); /* Fixup stmts that became noreturn calls. This may require splitting blocks and thus isn't possible during the dominator walk. Do this