From patchwork Wed May 15 08:20:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 1099889 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-500726-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="GrbNhSU+"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 453nYz4rr9z9s4V for ; Wed, 15 May 2019 18:20:53 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=goWwdpc1zoPSG/yn JLvGnA4w4REt5lmkioGdTkY/BjLwa+vLIRoe1R5HMcvPEqpps6D0SuAMXf24p6zT Pb33wgQkBZ/AeNGs7XZJW9ItgWcq9Jg4xAlZCXLyBCqAy92nv2oSsHgprmwKV24Q +WPpe0mh1H0O8k6MsVF2qC7B2Vw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=ZzXVXC5fi9WeQTDAz+8PyU Cqu64=; b=GrbNhSU+zgVqAfx7UGrzwOqJPHdAWmVxrMqrJjrp0+phtXTS3oJ81d NDuAKqa20jMIwF+gA5XYAIpwRcqIcLQpTl2lBxOmc9tmQsu6TRs7Xac21gDx56Ai 0ac30e064E7q9PVh5kxPlplQcif7L1u3r58kthjsDdDQzrw0ftIj4= Received: (qmail 52745 invoked by alias); 15 May 2019 08:20:47 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 52734 invoked by uid 89); 15 May 2019 08:20:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=hay, free!, consolidate, che X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 15 May 2019 08:20:45 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6C37B0AA6 for ; Wed, 15 May 2019 08:20:43 +0000 (UTC) Received: from free.home (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8B3D15C1A3; Wed, 15 May 2019 08:20:43 +0000 (UTC) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTP id x4F8KTCf422128; Wed, 15 May 2019 05:20:29 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org, law@redhat.com Subject: preserve more debug stmts in gimple jump threading Date: Wed, 15 May 2019 05:20:29 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Gimple jump threading does not duplicate forwarder blocks that might be present before or after the second copied block. This silently drops debug binds and markers that might be present in them. This patch attempts to preserve them. For blocks after either copied block, we attempt to append debug stmts to the copied block, if it does not end with a block-ending stmt. Failing that, for blocks between both copied blocks, we prepend its debug stmts to the copy of the second block. If everything fails, we still drop debug stmts on the floor, though preexisting code consolidates debug binds in the block that threading flows into, so only markers are really lost. We can't do much better than that without conditional binds and markers, or debug stmts in edges, or somesuch. If we append debug stmts to a reusable template block, we copy it after splitting out the debug stmts, and before putting them back. Regstrapped on x86_64-linux-gnu and i686-linux-gnu. Ok to install? for gcc/ChangeLog * tree-ssa-threadupdate.c (struct ssa_local_info_t): Add field template_last_to_copy. (ssa_create_duplicates): Set it, and use it. Attempt to preserve more debug stmts. --- gcc/tree-ssa-threadupdate.c | 68 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c index bccef879db03..d63154317746 100644 --- a/gcc/tree-ssa-threadupdate.c +++ b/gcc/tree-ssa-threadupdate.c @@ -235,6 +235,12 @@ struct ssa_local_info_t and sharing a template for that block is considerably more difficult. */ basic_block template_block; + /* If we append debug stmts to the template block after creating it, + this iterator won't be the last one in the block, and further + copies of the template block shouldn't get debug stmts after + it. */ + gimple_stmt_iterator template_last_to_copy; + /* Blocks duplicated for the thread. */ bitmap duplicate_blocks; @@ -1124,6 +1130,8 @@ ssa_create_duplicates (struct redirection_data **slot, create_block_for_threading ((*path)[1]->e->src, rd, 0, &local_info->duplicate_blocks); local_info->template_block = rd->dup_blocks[0]; + local_info->template_last_to_copy + = gsi_last_bb (local_info->template_block); /* We do not create any outgoing edges for the template. We will take care of that in a later traversal. That way we do not @@ -1131,14 +1139,74 @@ ssa_create_duplicates (struct redirection_data **slot, } else { + gimple_seq seq = NULL; + if (gsi_stmt (local_info->template_last_to_copy) + != gsi_stmt (gsi_last_bb (local_info->template_block))) + seq = gsi_split_seq_after (local_info->template_last_to_copy); create_block_for_threading (local_info->template_block, rd, 0, &local_info->duplicate_blocks); + if (seq) + gsi_insert_seq_after (&local_info->template_last_to_copy, + seq, GSI_SAME_STMT); /* Go ahead and wire up outgoing edges and update PHIs for the duplicate block. */ ssa_fix_duplicate_block_edges (rd, local_info); } + if (MAY_HAVE_DEBUG_STMTS) + { + /* Copy debug stmts from each NO_COPY src block to the block + that would have been its predecessor, if we can append to it + (we can't add stmts after a block-ending stmt), or prepending + to the duplicate of the successor, if there is one. If + there's no duplicate successor, we'll mostly drop the blocks + on the floor; propagate_threaded_block_debug_into, called + elsewhere, will consolidate and preserve the effects of the + binds, but none of the markers. */ + gimple_stmt_iterator copy_to = gsi_last_bb (rd->dup_blocks[0]); + if (!gsi_end_p (copy_to)) + { + if (stmt_ends_bb_p (gsi_stmt (copy_to))) + { + if (rd->dup_blocks[1]) + copy_to = gsi_after_labels (rd->dup_blocks[1]); + else + copy_to = gsi_none (); + } + else + gsi_next (©_to); + } + for (unsigned int i = 2, j = 0; i < path->length (); i++) + if ((*path)[i]->type == EDGE_NO_COPY_SRC_BLOCK + && gsi_bb (copy_to)) + { + for (gimple_stmt_iterator gsi = gsi_start_bb ((*path)[i]->e->src); + !gsi_end_p (gsi); gsi_next (&gsi)) + { + if (!is_gimple_debug (gsi_stmt (gsi))) + continue; + gimple *stmt = gsi_stmt (gsi); + gimple *copy = gimple_copy (stmt); + gsi_insert_before (©_to, copy, GSI_SAME_STMT); + } + } + else if ((*path)[i]->type == EDGE_COPY_SRC_BLOCK + || (*path)[i]->type == EDGE_COPY_SRC_JOINER_BLOCK) + { + j++; + gcc_assert (j < 2); + copy_to = gsi_last_bb (rd->dup_blocks[j]); + if (!gsi_end_p (copy_to)) + { + if (stmt_ends_bb_p (gsi_stmt (copy_to))) + copy_to = gsi_none (); + else + gsi_next (©_to); + } + } + } + /* Keep walking the hash table. */ return 1; }