From patchwork Mon Jul 16 13:29:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 944411 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-481616-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="mIx1x7uh"; 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 41TklY07npz9rxs for ; Mon, 16 Jul 2018 23:29:11 +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:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=BNIa5q8VfIW6ui/nG45Cp4WnGELflV7gjcAlzM20fB4xF5b8Sz 9Yelg41QwpW4RYBm9O8zKFlq6iT9INjRNLKlKqSSZFYMP+XtMzpSXy5REyjzqf/L bKMp/v/fP4ZUJz7NI9Um4HCAqPaqFk4acDzgY1/zm4/d1H8FGKDmy56Pw= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=5weWMVdEO6fg8quqeXGvzYVvYQw=; b=mIx1x7uhYo89tIZz/Yci GecukljLhzogNCNvaK7vHom+Z+jrktoy2TsDkCMn2L4ntElyOG7SJD9b5HZQnjFz h0CCD/WvIfncIL5eX6DOg3SEMUW2ZG3ZMUreoXFj2NdbSRXCkjowqAQgovh6pGM9 ieXM/xpBGnb5ScsAibAgRy0= Received: (qmail 123351 invoked by alias); 16 Jul 2018 13:29:04 -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 123341 invoked by uid 89); 16 Jul 2018 13:29:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=hoisting, micro, undocumented X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Jul 2018 13:29:02 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9EF6AAD4C; Mon, 16 Jul 2018 13:28:59 +0000 (UTC) Date: Mon, 16 Jul 2018 15:29:10 +0200 From: Tom de Vries To: gcc-patches@gcc.gnu.org Cc: Richard Biener , Jakub Jelinek , Jim Wilson Subject: [RFC][debug] Add -fadd-debug-nops Message-ID: <20180716132909.633uvqxojzgg3wg6@delia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170912 (1.9.0) X-IsSubscribed: yes Hi, this is an idea that I'm currently playing around with: adding nops in an optimized application with debug info can improve the debug info. Consider f.i. this gdb session in foo of pr54200-2.c (using -Os): ... (gdb) n 26 return a; /* { dg-final { gdb-test . "(int)a" "6" } } */ (gdb) p a 'a' has unknown type; cast it to its declared type (gdb) n main () at pr54200-2.c:34 34 return 0; ... The problem is that the scope in which a is declared ends at .LBE7, and the statement .loc for line 26 ends up attached to the ret insn: ... .loc 1 24 11 addl %edx, %eax .LVL1: # DEBUG a => ax .loc 1 26 7 is_stmt 1 .LBE7: .loc 1 28 1 is_stmt 0 ret .cfi_endproc ... This patch fixes the problem (for Og and Os, the 'DEBUG a => ax' is missing for O1 and higher) by adding a nop before the ret insn: ... .loc 1 24 11 addl %edx, %eax .LVL1: # DEBUG a => ax .loc 1 26 7 is_stmt 1 + nop .LBE7: .loc 1 28 1 is_stmt 0 ret .cfi_endproc ... and instead we have: ... (gdb) n 26 return a; /* { dg-final { gdb-test . "(int)a" "6" } } */ (gdb) p a $1 = 6 (gdb) n main () at pr54200-2.c:34 34 return 0; ... Any comments? Thanks, - Tom [debug] Add -fadd-debug-nops --- gcc/common.opt | 4 ++++ gcc/testsuite/gcc.dg/guality/pr54200-2.c | 37 ++++++++++++++++++++++++++++++++ gcc/var-tracking.c | 16 ++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/gcc/common.opt b/gcc/common.opt index c29abdb5cb1..8e2876d2b8e 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1504,6 +1504,10 @@ Common Report Var(flag_hoist_adjacent_loads) Optimization Enable hoisting adjacent loads to encourage generating conditional move instructions. +fadd-debug-nops +Common Report Var(flag_add_debug_nops) Optimization +Add nops if that improves debugging of optimized code + fkeep-gc-roots-live Common Undocumented Report Var(flag_keep_gc_roots_live) Optimization ; Always keep a pointer to a live memory block diff --git a/gcc/testsuite/gcc.dg/guality/pr54200-2.c b/gcc/testsuite/gcc.dg/guality/pr54200-2.c new file mode 100644 index 00000000000..2694f7401e2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/guality/pr54200-2.c @@ -0,0 +1,37 @@ +/* { dg-do run } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-Og" "-Os" "-O0" } } */ +/* { dg-options "-g -fadd-debug-nops -DMAIN" } */ + +#include "prevent-optimization.h" + +int o ATTRIBUTE_USED; + +void +bar (void) +{ + o = 2; +} + +int __attribute__((noinline,noclone)) +foo (int z, int x, int b) +{ + if (x == 1) + { + bar (); + return z; + } + else + { + int a = (x + z) + b; + /* Add cast to prevent unsupported. */ + return a; /* { dg-final { gdb-test . "(int)a" "6" } } */ + } +} + +#ifdef MAIN +int main () +{ + foo (3, 2, 1); + return 0; +} +#endif diff --git a/gcc/var-tracking.c b/gcc/var-tracking.c index 5537fa64085..230845a38a0 100644 --- a/gcc/var-tracking.c +++ b/gcc/var-tracking.c @@ -9994,6 +9994,15 @@ reemit_marker_as_note (rtx_insn *insn) } } +static void +emit_nop_before (rtx_insn *insn) +{ + rtx_insn *insert_after = PREV_INSN (insn); + while (INSN_LOCATION (insert_after) == INSN_LOCATION (insn)) + insert_after = PREV_INSN (insert_after); + emit_insn_after (gen_nop (), insert_after); +} + /* Allocate and initialize the data structures for variable tracking and parse the RTL to get the micro operations. */ @@ -10224,6 +10233,13 @@ vt_initialize (void) continue; } + /* Add debug nops before ret insn. */ + if (optimize + && flag_add_debug_nops + && cfun->debug_nonbind_markers + && returnjump_p (insn)) + emit_nop_before (insn); + if (MAY_HAVE_DEBUG_BIND_INSNS) { if (CALL_P (insn))