From patchwork Thu Jun 21 17:04:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 932826 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-480215-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="pfQy67JC"; 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 41BSjf5KdRz9s2L for ; Fri, 22 Jun 2018 03:04:37 +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=aRCIX1DKJ3qiNS3S 8PfeRPwo1IZ24cFwyqrJszbdTtW0iEd/6LYDunT87kS4WMtK0asjLRbNsl4rmVxs DvY23I3tcnxlaFRh1vlaYR7bSQZ6dcXV5UFoPxhZh3I5BqZn5PqWZ9UaRcOtz3R2 dXRwS88tjDNnN/5uapoFNWN0/gc= 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=00+6xuairZuQl6cNlQHosP Se1R0=; b=pfQy67JCYW0xTgPGrZ83dh/uUcPcvDpecFYbOOh2/0zlFTivXpY6BH pbT5B12h4jB/frdvIfK7RWoVg/K8EU+wcNS8swK+0jJiopfytd+yiEVvsGLG42MF jVZIqpMhg/WIBSii/LoJ1nafVQAIrEnNMkw8RAoSnOVM66WzXbzLk= Received: (qmail 45437 invoked by alias); 21 Jun 2018 17:04:30 -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 45417 invoked by uid 89); 21 Jun 2018 17:04:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=UD:cfgrtl.c, cfgrtl.c, cfgrtlc, jump_p X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Jun 2018 17:04:28 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 21C4F81C18 for ; Thu, 21 Jun 2018 19:04:26 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MR03Ut8qH3fx for ; Thu, 21 Jun 2018 19:04:26 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id EA06D8139F for ; Thu, 21 Jun 2018 19:04:25 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: Do not emit unnecessary NOPs at -O0 Date: Thu, 21 Jun 2018 19:04:23 +0200 Message-ID: <1529603927.Q0ovV4Gg7X@polaris> MIME-Version: 1.0 When code is compiled at -O0, the RTL middle-end makes sure that location information is preserved as much as possible by generating NOPs with the location information (goto_locus) present on edges in the CFG, if it thinks that these edges are the only place where a particular location is mentioned. The attached patch prevents this from happening in a couple of cases: 1. if the function has the DECL_IGNORED_P flag set, 2. if the NOP is emitted by merge_blocks and the 2nd block is a forwarder block whose outgoing edge has no location, because in this case the location of the to-be-elided edge is copied onto the aforementioned outgoing edge. Tested (GCC and GDB) on x86-64/Linux, applied on the mainline. 2018-06-21 Eric Botcazou * cfgrtl.c (fixup_reorder_chain): Do not emit NOPs in DECL_IGNORED_P functions. (rtl_merge_blocks): Likewise. Do not emit a NOP if the location of the edge can be forwarded. (cfg_layout_merge_blocks): Likewise. Index: cfgrtl.c =================================================================== --- cfgrtl.c (revision 261832) +++ cfgrtl.c (working copy) @@ -813,10 +813,14 @@ emit_nop_for_unique_locus_between (basic static void rtl_merge_blocks (basic_block a, basic_block b) { + /* If B is a forwarder block whose outgoing edge has no location, we'll + propagate the locus of the edge between A and B onto it. */ + const bool forward_edge_locus + = (b->flags & BB_FORWARDER_BLOCK) != 0 + && LOCATION_LOCUS (EDGE_SUCC (b, 0)->goto_locus) == UNKNOWN_LOCATION; rtx_insn *b_head = BB_HEAD (b), *b_end = BB_END (b), *a_end = BB_END (a); rtx_insn *del_first = NULL, *del_last = NULL; rtx_insn *b_debug_start = b_end, *b_debug_end = b_end; - bool forwarder_p = (b->flags & BB_FORWARDER_BLOCK) != 0; int b_empty = 0; if (dump_file) @@ -887,9 +891,11 @@ rtl_merge_blocks (basic_block a, basic_b BB_HEAD (b) = b_empty ? NULL : b_head; delete_insn_chain (del_first, del_last, true); - /* When not optimizing and the edge is the only place in RTL which holds - some unique locus, emit a nop with that locus in between. */ - if (!optimize) + /* If not optimizing, preserve the locus of the single edge between + blocks A and B if necessary by emitting a nop. */ + if (!optimize + && !forward_edge_locus + && !DECL_IGNORED_P (current_function_decl)) { emit_nop_for_unique_locus_between (a, b); a_end = BB_END (a); @@ -918,9 +924,7 @@ rtl_merge_blocks (basic_block a, basic_b df_bb_delete (b->index); - /* If B was a forwarder block, propagate the locus on the edge. */ - if (forwarder_p - && LOCATION_LOCUS (EDGE_SUCC (b, 0)->goto_locus) == UNKNOWN_LOCATION) + if (forward_edge_locus) EDGE_SUCC (b, 0)->goto_locus = EDGE_SUCC (a, 0)->goto_locus; if (dump_file) @@ -3916,9 +3920,9 @@ fixup_reorder_chain (void) force_nonfallthru (e); } - /* Ensure goto_locus from edges has some instructions with that locus - in RTL. */ - if (!optimize) + /* Ensure goto_locus from edges has some instructions with that locus in RTL + when not optimizing. */ + if (!optimize && !DECL_IGNORED_P (current_function_decl)) FOR_EACH_BB_FN (bb, cfun) { edge e; @@ -4605,7 +4609,11 @@ cfg_layout_can_merge_blocks_p (basic_blo static void cfg_layout_merge_blocks (basic_block a, basic_block b) { - bool forwarder_p = (b->flags & BB_FORWARDER_BLOCK) != 0; + /* If B is a forwarder block whose outgoing edge has no location, we'll + propagate the locus of the edge between A and B onto it. */ + const bool forward_edge_locus + = (b->flags & BB_FORWARDER_BLOCK) != 0 + && LOCATION_LOCUS (EDGE_SUCC (b, 0)->goto_locus) == UNKNOWN_LOCATION; rtx_insn *insn; gcc_checking_assert (cfg_layout_can_merge_blocks_p (a, b)); @@ -4626,9 +4634,11 @@ cfg_layout_merge_blocks (basic_block a, try_redirect_by_replacing_jump (EDGE_SUCC (a, 0), b, true); gcc_assert (!JUMP_P (BB_END (a))); - /* When not optimizing and the edge is the only place in RTL which holds - some unique locus, emit a nop with that locus in between. */ - if (!optimize) + /* If not optimizing, preserve the locus of the single edge between + blocks A and B if necessary by emitting a nop. */ + if (!optimize + && !forward_edge_locus + && !DECL_IGNORED_P (current_function_decl)) emit_nop_for_unique_locus_between (a, b); /* Move things from b->footer after a->footer. */ @@ -4695,9 +4705,7 @@ cfg_layout_merge_blocks (basic_block a, df_bb_delete (b->index); - /* If B was a forwarder block, propagate the locus on the edge. */ - if (forwarder_p - && LOCATION_LOCUS (EDGE_SUCC (b, 0)->goto_locus) == UNKNOWN_LOCATION) + if (forward_edge_locus) EDGE_SUCC (b, 0)->goto_locus = EDGE_SUCC (a, 0)->goto_locus; if (dump_file)