From patchwork Sun Jul 8 09:22:41 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: 940916 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-481189-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="KUDNAjdt"; 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 41Njg11fB8z9s1b for ; Sun, 8 Jul 2018 19:22:50 +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:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=e8riKYzr3LCjQExJr LzlmNWz4iU+bv0ilmRvNinbzN/IE2OPbAP9zInvkE20Ubrx2b2v+OsFLexUvX6tm yMvsoqzqynnmG8hJ0j4yKLwe5Lt2YsR/TsyYb1YfUM1uTQhkOvXbWIk1UQUCW/U7 WpdNHL0CLseRu/7wKva1JO46eQ= 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:references:mime-version :content-type:in-reply-to; s=default; bh=ewrqmzARops7ihI9bKLZjQ3 FQk8=; b=KUDNAjdtsnMdL2kAg+3lY9OMeJvehQoUAAXZlS5DW7Tpan0RnC/Z1OH YM48spWad4uCKINYAtpyLC0dPdaWxjG4gGyRkSlE0QrGiF4vBaBoWoVZWIljtv7L jS72gbKWiWwT8MhlXF34zFb0T2i0ThNQ3xWK1mpIiJiHH9jBZb/c= Received: (qmail 117390 invoked by alias); 8 Jul 2018 09:22:42 -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 117379 invoked by uid 89); 8 Jul 2018 09:22:41 -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=optimal, improving, 2087 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; Sun, 08 Jul 2018 09:22:38 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 93F61AEB1; Sun, 8 Jul 2018 09:22:36 +0000 (UTC) Date: Sun, 8 Jul 2018 11:22:41 +0200 From: Tom de Vries To: Richard Biener Cc: Jakub Jelinek , GCC Patches Subject: [PATCH][debug] Handle debug references to skipped params Message-ID: <20180708092241.ysxxwnxk757uuspy@delia> References: <20180701191137.GQ7166@tucnak> <948b1fdd-9e53-2d65-7c72-99460a2fec1e@suse.de> <20180702081604.GR7166@tucnak> <2e0f12a5-803e-6f24-505e-574dd2ea4ba9@suse.de> <04c6e772-70f4-a786-13d9-7017382d7142@suse.de> <20180705112558.mphxe2sz7mozvcur@delia> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170912 (1.9.0) X-IsSubscribed: yes On Fri, Jul 06, 2018 at 04:38:50PM +0200, Richard Biener wrote: > On Fri, Jul 6, 2018 at 12:47 PM Tom de Vries wrote: > > On 07/05/2018 01:39 PM, Richard Biener wrote: > I now also spotted the code in remap_ssa_name that is supposed to handle > this it seems and for the testcase we only give up because the PARM_DECL is > remapped to a VAR_DECL. So I suppose it is to be handled via the > debug-args stuff > which probably lacks in the area of versioning. > > Your patch feels like it adds stuff ontop of existing mechanisms that > should "just work" > with the correct setup at the correct places... > Hmm, I realized that I may be complicating things, by trying to do an optimal fix in a single patch, so I decided to write two patches, one with a fix, and then one improving the fix to be more optimal. Also, I suspect that the "just work" approach is this: ... # DEBUG D#8 s=> iD.1900 # DEBUG iD.1949 => D#8 # DEBUG D#6 s=> iD.1949 ... whereas previously I tried to map 'D#6' on iD.1900 directly. First patch OK for trunk? [debug] Handle debug references to skipped params When compiling guality/vla-1.c with -O3 -g, vla a in f1 is optimized away, but f1 still contains a debug expression describing the upper bound of the vla (D.1914): ... __attribute__((noinline)) f1 (intD.6 iD.1900) { saved_stack.1_2 = __builtin_stack_save (); # DEBUG BEGIN_STMT # DEBUG D#3 => i_1(D) + 1 # DEBUG D#2 => (long intD.8) D#3 # DEBUG D#1 => D#2 + -1 # DEBUG D.1914 => (sizetype) D#1 ... Then f1 is cloned to a version f1.constprop with no parameters, eliminating parameter i, and 'DEBUG D#3 => i_1(D) + 1' turns into 'D#3 => NULL'. This patch fixes that by defining debug expressions for default defs of eliminated parameters in remap_ssa_name: ... __attribute__((noinline)) f1.constprop () { intD.6 iD.1949; # DEBUG D#8 s=> iD.1900 # DEBUG iD.1949 => D#8 + # DEBUG D#6 s=> iD.1949 saved_stack.1_1 = __builtin_stack_save (); # DEBUG BEGIN_STMT - # DEBUG D#3 => NULL + # DEBUG D#3 => D#6 + 1 # DEBUG D#2 => (long intD.8) D#3 # DEBUG D#1 => D#2 + -1 # DEBUG D.1951 => (sizetype) D#1 ... Bootstrapped and reg-tested on x86_64. 2018-07-07 Tom de Vries * cfgexpand.c (expand_debug_source_expr): Handle VAR_DECL. * tree-inline.c (remap_ssa_name): Handle default def ssa_name mapping onto VAR_DECL with abstract origin. * gcc.dg/vla-1.c: New test. --- gcc/cfgexpand.c | 4 ++++ gcc/testsuite/gcc.dg/vla-1.c | 25 +++++++++++++++++++++++++ gcc/tree-inline.c | 4 +++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 9b91279282e..d6e3c382085 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -5141,6 +5141,10 @@ expand_debug_source_expr (tree exp) switch (TREE_CODE (exp)) { + case VAR_DECL: + if (DECL_ABSTRACT_ORIGIN (exp)) + return expand_debug_source_expr (DECL_ABSTRACT_ORIGIN (exp)); + break; case PARM_DECL: { mode = DECL_MODE (exp); diff --git a/gcc/testsuite/gcc.dg/vla-1.c b/gcc/testsuite/gcc.dg/vla-1.c new file mode 100644 index 00000000000..0c19feffd2b --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-1.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-g -O3 -fdump-tree-optimized" } */ + +int __attribute__((noinline)) +f1 (int i) +{ + char a[i + 1]; + char b[i + 2]; + b[1] = 3; + a[0] = 5; + return a[0] + b[1]; +} + +int +main () +{ + volatile int j; + int x = 5; + j = f1 (x); + return 0; +} + +/* One debug source bind is generated for the parameter, and two to describe the + sizes of a and b. */ +/* { dg-final { scan-tree-dump-times " s=> i" 3 "optimized" } } */ diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 427ef959740..6fbd8c3ca61 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -208,7 +208,9 @@ remap_ssa_name (tree name, copy_body_data *id) n = id->decl_map->get (val); if (n != NULL) val = *n; - if (TREE_CODE (val) != PARM_DECL) + if (TREE_CODE (val) != PARM_DECL + && !(TREE_CODE (val) == VAR_DECL + && DECL_ABSTRACT_ORIGIN (val))) { processing_debug_stmt = -1; return name;