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 13BD43858C5F for ; Fri, 10 Feb 2023 10:12:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 13BD43858C5F 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 relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 086333FDC2; Fri, 10 Feb 2023 10:12:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1676023950; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=/x2P90qfE3dCmNnHhoyhFotQaXAuN3K/dUbqUwx1Z/k=; b=LgV0XpY731weFfHgVn9IDYdr5YXzyx2dVUbpB7wY9wT5UIkPMxksvnW0q9TIxdbdphiPIW XxNpQyOO9knIMJFqEW9nE7oJe3qxyIi42uT8lhb9DDEHzWRzmqRA72iWDqB8YLNKrAJNKV iZD2wFFiXN71KnTt6Hddi4FvpKpIKdo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1676023950; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=/x2P90qfE3dCmNnHhoyhFotQaXAuN3K/dUbqUwx1Z/k=; b=r9CVozYtmIcRtYNWTzLYcsEK5dO7O3UJ1fNDzaKztt5cWLqTGcTkGzd4X65OgGpTmuJ5Ia nE6ZnDZpieWbzIBA== 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 E702C2C141; Fri, 10 Feb 2023 10:12:29 +0000 (UTC) Date: Fri, 10 Feb 2023 10:12:29 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: Jan Hubicka Subject: [PATCH] tree-optimization/106722 - fix CD-DCE edge marking User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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 List-Id: Message-ID: <20230210101229.KTZeeSm7hmy0tk2zN0LI8op2K3WihcMBsAgHBXsB5PU@z> The following fixes a latent issue when we mark control edges but end up with marking a block with no stmts necessary. In this case we fail to mark dependent control edges of that block. Bootstrapped and tested on x86_64-unknown-linux-gnu. Does this look OK? Thanks, Richard. PR tree-optimization/106722 * tree-ssa-dce.cc (mark_last_stmt_necessary): Return whether we marked a stmt. (mark_control_dependent_edges_necessary): When mark_last_stmt_necessary didn't mark any stmt make sure to mark its control dependent edges. (propagate_necessity): Likewise. * gcc.dg/torture/pr108737.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr108737.c | 19 +++++++++++++++++++ gcc/tree-ssa-dce.cc | 20 +++++++++++++------- 2 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr108737.c diff --git a/gcc/testsuite/gcc.dg/torture/pr108737.c b/gcc/testsuite/gcc.dg/torture/pr108737.c new file mode 100644 index 00000000000..c8388bcabeb --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr108737.c @@ -0,0 +1,19 @@ +/* { dg-do run } */ + +extern void exit (int); +extern void abort (void); + +void __attribute__((noipa)) foo () { exit (0); } + +void __attribute__((noipa)) blah (int x) +{ + while (1) { + if(x) foo(); + } +} + +int main() +{ + blah (1); + abort (); +} diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc index b2fe9f4f55e..21b3294fc86 100644 --- a/gcc/tree-ssa-dce.cc +++ b/gcc/tree-ssa-dce.cc @@ -327,17 +327,23 @@ mark_stmt_if_obviously_necessary (gimple *stmt, bool aggressive) /* Mark the last statement of BB as necessary. */ -static void +static bool mark_last_stmt_necessary (basic_block bb) { gimple *stmt = last_stmt (bb); - bitmap_set_bit (last_stmt_necessary, bb->index); + if (!bitmap_set_bit (last_stmt_necessary, bb->index)) + return true; + bitmap_set_bit (bb_contains_live_stmts, bb->index); /* We actually mark the statement only if it is a control statement. */ if (stmt && is_ctrl_stmt (stmt)) - mark_stmt_necessary (stmt, true); + { + mark_stmt_necessary (stmt, true); + return true; + } + return false; } @@ -369,8 +375,8 @@ mark_control_dependent_edges_necessary (basic_block bb, bool ignore_self) continue; } - if (!bitmap_bit_p (last_stmt_necessary, cd_bb->index)) - mark_last_stmt_necessary (cd_bb); + if (!mark_last_stmt_necessary (cd_bb)) + mark_control_dependent_edges_necessary (cd_bb, false); } if (!skipped) @@ -790,8 +796,8 @@ propagate_necessity (bool aggressive) if (gimple_bb (stmt) != get_immediate_dominator (CDI_POST_DOMINATORS, arg_bb)) { - if (!bitmap_bit_p (last_stmt_necessary, arg_bb->index)) - mark_last_stmt_necessary (arg_bb); + if (!mark_last_stmt_necessary (arg_bb)) + mark_control_dependent_edges_necessary (arg_bb, false); } else if (arg_bb != ENTRY_BLOCK_PTR_FOR_FN (cfun) && !bitmap_bit_p (visited_control_parents, -- 2.35.3