From patchwork Mon Nov 8 15:44:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 47220 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0EDBD3857009 for ; Mon, 8 Nov 2021 15:45:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id DFEAE3858016 for ; Mon, 8 Nov 2021 15:44:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DFEAE3858016 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id C692C21921 for ; Mon, 8 Nov 2021 15:44:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1636386245; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=hh6tpGR5HJZnyDU7DjAW0+cYXzAfqTMINFwS5U6PZJM=; b=UIy1mQIF+aMdevfFJdDNh12MSzUwQ8WDkbJOAsmAeQ4oEYeKQsL/c36MXxMfo7PRUcWDnv 0O9yrrLfNj8aXzJqLTB4CUNfMa3qFE71PIQH3kwf9OqyFD6B9No1NRPWInJmoNcUOTwl1p SE5CvKmDGE33dOaDIt6TWPHcbvSHbuU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1636386245; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=hh6tpGR5HJZnyDU7DjAW0+cYXzAfqTMINFwS5U6PZJM=; b=Q7WKBUB8T8Npk1PW6o24ht2KJXyLyEJujRVO82jUAnM9Qz7qgRjAetgOwjdXAvKCqz33B/ P0tet44IUPDFVSBQ== Received: from suse.cz (virgil.suse.cz [10.100.13.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id B293DA3B8A; Mon, 8 Nov 2021 15:44:05 +0000 (UTC) From: Martin Jambor To: GCC Patches Subject: [PATCH] ipa: Unshare expresseions before putting them into debug statements (PR 103099, PR 103107) User-Agent: Notmuch/0.33.2 (https://notmuchmail.org) Emacs/27.2 (x86_64-suse-linux-gnu) Date: Mon, 08 Nov 2021 16:44:05 +0100 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 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 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: , Cc: Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, my recent patch to improve debug experience when there are removed parameters (by ipa-sra or ipa-split) was not careful to unshare the expressions that were then put into debug statements, which manifests itself as PR 103099. This patch adds unsharing them using unshare_expr_without_location which is a bit more careful with stripping locations than what we were doing manually and so also fixes PR 103107. Bootstrapped an tested on x86_64-linux. OK for master? Thanks, Martin gcc/ChangeLog: 2021-11-08 Martin Jambor PR ipa/103099 PR ipa/103107 * tree-inline.c (remap_gimple_stmt): Unshare the expression without location before invoking remap_with_debug_expressions on it. * ipa-param-manipulation.c (ipa_param_body_adjustments::prepare_debug_expressions): Likewise. gcc/testsuite/ChangeLog: 2021-11-08 Martin Jambor PR ipa/103099 PR ipa/103107 * g++.dg/ipa/pr103099.C: New test. * gcc.dg/ipa/pr103107.c: Likewise. --- gcc/ipa-param-manipulation.c | 4 ++-- gcc/testsuite/g++.dg/ipa/pr103099.C | 25 +++++++++++++++++++++++++ gcc/testsuite/gcc.dg/ipa/pr103107.c | 17 +++++++++++++++++ gcc/tree-inline.c | 5 ++++- 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ipa/pr103099.C create mode 100644 gcc/testsuite/gcc.dg/ipa/pr103107.c diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c index c84d669521c..44f3bed2640 100644 --- a/gcc/ipa-param-manipulation.c +++ b/gcc/ipa-param-manipulation.c @@ -1185,8 +1185,8 @@ ipa_param_body_adjustments::prepare_debug_expressions (tree dead_ssa) return (*d != NULL_TREE); } - tree val = gimple_assign_rhs_to_tree (def); - SET_EXPR_LOCATION (val, UNKNOWN_LOCATION); + tree val + = unshare_expr_without_location (gimple_assign_rhs_to_tree (def)); remap_with_debug_expressions (&val); tree vexpr = make_node (DEBUG_EXPR_DECL); diff --git a/gcc/testsuite/g++.dg/ipa/pr103099.C b/gcc/testsuite/g++.dg/ipa/pr103099.C new file mode 100644 index 00000000000..5fb137d6799 --- /dev/null +++ b/gcc/testsuite/g++.dg/ipa/pr103099.C @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -g" } */ + +void pthread_mutex_unlock(int *); +int __gthread_mutex_unlock___mutex, unlock___trans_tmp_1; +struct Object { + void _change_notify() {} + bool _is_queued_for_deletion; +}; +struct ClassDB { + template static int bind_method(N, M); +}; +struct CanvasItemMaterial : Object { + bool particles_animation; + void set_particles_animation(bool); +}; +void CanvasItemMaterial::set_particles_animation(bool p_particles_anim) { + particles_animation = p_particles_anim; + if (unlock___trans_tmp_1) + pthread_mutex_unlock(&__gthread_mutex_unlock___mutex); + _change_notify(); +} +void CanvasItemMaterial_bind_methods() { + ClassDB::bind_method("", &CanvasItemMaterial::set_particles_animation); +} diff --git a/gcc/testsuite/gcc.dg/ipa/pr103107.c b/gcc/testsuite/gcc.dg/ipa/pr103107.c new file mode 100644 index 00000000000..3ea3fc55947 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr103107.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-Og -g -fipa-sra -fno-tree-dce" } */ + +typedef int __attribute__((__vector_size__ (8))) V; +V v; + +static void +bar (int i) +{ + V l = v + i; +} + +void +foo (void) +{ + bar (0); +} diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index d78e4392b69..53d664ec2e4 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1825,7 +1825,10 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id) tree value = gimple_debug_bind_get_value (stmt); if (id->param_body_adjs && id->param_body_adjs->m_dead_stmts.contains (stmt)) - id->param_body_adjs->remap_with_debug_expressions (&value); + { + value = unshare_expr_without_location (value); + id->param_body_adjs->remap_with_debug_expressions (&value); + } gdebug *copy = gimple_build_debug_bind (var, value, stmt); if (id->reset_location)