From patchwork Tue Apr 5 14:12:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1613472 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ynYRx27C; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KXqP40LRhz9sBJ for ; Wed, 6 Apr 2022 00:13:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CBA6638515F6 for ; Tue, 5 Apr 2022 14:13:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CBA6638515F6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1649167987; bh=kMpoSup4us+hMbz8yZsXNBMHOzvHuBKZQnDXcdYg3LA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ynYRx27CekDMi4gOIXb6Gz0YfSUZkTQv/PtAePbd8lqYgDs3z6QoNH9ST3JPh+nki KON7RY5wyIqMK5aEMcjOPmwOvTTYv/c2tSh4fE6VayJv0kol2bO8aT2zxOm3Nf2pzi Sihma9TGfPGs/c0WUa8EZ0G8+GgFtqpZEG/7qneY= 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 4FCAB3857C4A for ; Tue, 5 Apr 2022 14:12:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4FCAB3857C4A 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-out2.suse.de (Postfix) with ESMTPS id 2EED81F390 for ; Tue, 5 Apr 2022 14:12:46 +0000 (UTC) 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 1BD0013522 for ; Tue, 5 Apr 2022 14:12:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id J8eNBV5OTGKrRwAAMHmgww (envelope-from ) for ; Tue, 05 Apr 2022 14:12:46 +0000 Date: Tue, 5 Apr 2022 16:12:45 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] debug/105158 - improve debug stmt retaining for forwarder removal MIME-Version: 1.0 Message-Id: <20220405141246.1BD0013522@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Currently when we cannot move debug stmt from a forwarder to the destination block we drop/reset them. But in some cases as for the testcase we can move them to the predecessor when that has a single successor and we can insert after the last stmt of the block. That allows us to preserve debug info here. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Queued for stage1. 2022-04-05 Richard Biener PR debug/105158 * tree-cfgcleanup.cc (move_debug_stmts_from_forwarder): Move debug stmts to the predecessor if moving to the destination is not possible. (remove_forwarder_block): Adjust. (remove_forwarder_block_with_phi): Likewise. --- gcc/tree-cfgcleanup.cc | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/gcc/tree-cfgcleanup.cc b/gcc/tree-cfgcleanup.cc index 6c05ef2464e..893619eaaa4 100644 --- a/gcc/tree-cfgcleanup.cc +++ b/gcc/tree-cfgcleanup.cc @@ -468,15 +468,34 @@ phi_alternatives_equal (basic_block dest, edge e1, edge e2) return true; } -/* Move debug stmts from the forwarder block SRC to DEST. */ +/* Move debug stmts from the forwarder block SRC to DEST or PRED. */ static void -move_debug_stmts_from_forwarder (basic_block src, basic_block dest, - bool dest_single_pred_p) +move_debug_stmts_from_forwarder (basic_block src, + basic_block dest, bool dest_single_pred_p, + basic_block pred, bool pred_single_succ_p) { if (!MAY_HAVE_DEBUG_STMTS) return; + /* If we cannot move to the destination but to the predecessor do that. */ + if (!dest_single_pred_p && pred_single_succ_p) + { + gimple_stmt_iterator gsi_to = gsi_last_bb (pred); + if (gsi_end_p (gsi_to) || !stmt_ends_bb_p (gsi_stmt (gsi_to))) + { + for (gimple_stmt_iterator gsi = gsi_after_labels (src); + !gsi_end_p (gsi);) + { + gimple *debug = gsi_stmt (gsi); + gcc_assert (is_gimple_debug (debug)); + gsi_move_after (&gsi, &gsi_to); + } + return; + } + } + + /* Else move to DEST or drop/reset them. */ gimple_stmt_iterator gsi_to = gsi_after_labels (dest); for (gimple_stmt_iterator gsi = gsi_after_labels (src); !gsi_end_p (gsi);) { @@ -627,7 +646,8 @@ remove_forwarder_block (basic_block bb) /* Move debug statements. Reset them if the destination does not have a single predecessor. */ - move_debug_stmts_from_forwarder (bb, dest, dest_single_pred_p); + move_debug_stmts_from_forwarder (bb, dest, dest_single_pred_p, + pred, pred && single_succ_p (pred)); bitmap_set_bit (cfgcleanup_altered_bbs, dest->index); @@ -1309,7 +1329,8 @@ remove_forwarder_block_with_phi (basic_block bb) /* Move debug statements. Reset them if the destination does not have a single predecessor. */ - move_debug_stmts_from_forwarder (bb, dest, dest_single_pred_p); + move_debug_stmts_from_forwarder (bb, dest, dest_single_pred_p, + pred, pred && single_succ_p (pred)); /* Update the dominators. */ dombb = get_immediate_dominator (CDI_DOMINATORS, bb);