From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 0A58E384BC01 for ; Wed, 7 Sep 2022 11:38:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0A58E384BC01 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 F2F0233D2D for ; Wed, 7 Sep 2022 11:38:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1662550698; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=hDlcqoTIMrmxujv9oL02ZsNsx/ub6M31NdnEN2Ez750=; b=DrbORKiuwfTMc57se/DeljZTGIpcGJKlfkP5UOD166l+50WgQxAN2At8VA+xIiUtrwb4tl QqfEVforkMOWVLcGPDsw3E0sAVptXUqGn20Hstury3MCquaL6F+d8zyjbkceD8atjCq89K cGMYEEVRUps4WH8nPTd6gPvTbSa0La4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1662550699; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=hDlcqoTIMrmxujv9oL02ZsNsx/ub6M31NdnEN2Ez750=; b=I39cRBQRC6+J7P12OcE/b0C2eqkZeDr0EqkqSVAeRK9nVyPj7+2HB9tk9SL/Gwha94a4UW T39iT+s/LD8YVvBg== 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 DF93D13486 for ; Wed, 7 Sep 2022 11:38:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YjOCNaqCGGNfaAAAMHmgww (envelope-from ) for ; Wed, 07 Sep 2022 11:38:18 +0000 Date: Wed, 7 Sep 2022 13:38:18 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/106866 - avoid dead abnormal edges from DCE MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20220907113818.DF93D13486@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.9 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,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 List-Id: When DCE clears cfun->calls_setjmp then suddenly we don't need any abnormal call edges anymore. The following makes sure to prune them which otherwise can confuse other passes. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/106866 * tree-ssa-dce.cc (eliminate_unnecessary_stmts): When we changed cfun->calls_setjmp make sure to purge all abnormal call edges. * gcc.dg/uninit-pr106866.c: New testcase. --- gcc/testsuite/gcc.dg/uninit-pr106866.c | 38 ++++++++++++++++++++ gcc/tree-ssa-dce.cc | 48 ++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/uninit-pr106866.c diff --git a/gcc/testsuite/gcc.dg/uninit-pr106866.c b/gcc/testsuite/gcc.dg/uninit-pr106866.c new file mode 100644 index 00000000000..530e274118c --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-pr106866.c @@ -0,0 +1,38 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fno-ipa-pure-const -Wuninitialized" } */ + +int n; + +void +empty (int) +{ +} + +int +bar (int x) +{ + return n + x + 1; +} + +__attribute__ ((pure, returns_twice)) int +foo (void) +{ + int uninitialized; + + if (n) + { + if (bar (0)) + return 0; + + __builtin_unreachable (); + } + + while (uninitialized < 1) /* { dg-warning "uninitialized" } */ + { + foo (); + empty (bar (0) == foo ()); + ++uninitialized; + } + + return 0; +} diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc index daf0782b0e1..54e5d8c2923 100644 --- a/gcc/tree-ssa-dce.cc +++ b/gcc/tree-ssa-dce.cc @@ -1313,6 +1313,7 @@ eliminate_unnecessary_stmts (bool aggressive) if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, "\nEliminating unnecessary statements:\n"); + bool had_setjmp = cfun->calls_setjmp; clear_special_calls (); /* Walking basic blocks and statements in reverse order avoids @@ -1496,19 +1497,48 @@ eliminate_unnecessary_stmts (bool aggressive) something_changed |= remove_dead_phis (bb); } - - /* Since we don't track liveness of virtual PHI nodes, it is possible that we - rendered some PHI nodes unreachable while they are still in use. - Mark them for renaming. */ + /* First remove queued edges. */ if (!to_remove_edges.is_empty ()) { - basic_block prev_bb; - /* Remove edges. We've delayed this to not get bogus debug stmts during PHI node removal. */ for (unsigned i = 0; i < to_remove_edges.length (); ++i) remove_edge (to_remove_edges[i]); cfg_altered = true; + } + /* When we cleared calls_setjmp we can purge all abnormal edges. Do so. */ + if (cfun->calls_setjmp != had_setjmp) + { + gcc_assert (!cfun->calls_setjmp); + /* Make sure we only remove the edges, not dominated blocks. Using + gimple_purge_dead_abnormal_call_edges would do that and we + cannot free dominators yet. */ + FOR_EACH_BB_FN (bb, cfun) + if (gcall *stmt = safe_dyn_cast (last_stmt (bb))) + if (!stmt_can_make_abnormal_goto (stmt)) + { + edge_iterator ei; + edge e; + for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); ) + { + if (e->flags & EDGE_ABNORMAL) + { + if (e->flags & EDGE_FALLTHRU) + e->flags &= ~EDGE_ABNORMAL; + else + remove_edge (e); + cfg_altered = true; + } + else + ei_next (&ei); + } + } + } + + /* Now remove the unreachable blocks. */ + if (cfg_altered) + { + basic_block prev_bb; find_unreachable_blocks (); @@ -1518,9 +1548,13 @@ eliminate_unnecessary_stmts (bool aggressive) { prev_bb = bb->prev_bb; - if (!bitmap_bit_p (bb_contains_live_stmts, bb->index) + if ((bb_contains_live_stmts + && !bitmap_bit_p (bb_contains_live_stmts, bb->index)) || !(bb->flags & BB_REACHABLE)) { + /* Since we don't track liveness of virtual PHI nodes, it is + possible that we rendered some PHI nodes unreachable while + they are still in use. Mark them for renaming. */ for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) if (virtual_operand_p (gimple_phi_result (gsi.phi ()))) -- 2.35.3