From patchwork Wed Dec 22 03:54:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 76358 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 52017B70A3 for ; Wed, 22 Dec 2010 14:55:24 +1100 (EST) Received: (qmail 16026 invoked by alias); 22 Dec 2010 03:55:23 -0000 Received: (qmail 16017 invoked by uid 22791); 22 Dec 2010 03:55:22 -0000 X-SWARE-Spam-Status: No, hits=-5.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_TM, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 22 Dec 2010 03:55:18 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oBM3tGCC023455 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 21 Dec 2010 22:55:16 -0500 Received: from freie.oliva.athome.lsd.ic.unicamp.br (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oBM3tEf1019233 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 21 Dec 2010 22:55:16 -0500 Received: from livre.localdomain (livre-to-gw.oliva.athome.lsd.ic.unicamp.br [172.31.160.19]) by freie.oliva.athome.lsd.ic.unicamp.br (8.14.4/8.14.4) with ESMTP id oBM3tExp019421; Wed, 22 Dec 2010 01:55:14 -0200 Received: from livre.localdomain (aoliva@localhost [127.0.0.1]) by livre.localdomain (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id oBM3seQu008470; Wed, 22 Dec 2010 01:54:40 -0200 Received: (from aoliva@localhost) by livre.localdomain (8.14.3/8.14.3/Submit) id oBM3sdFJ008469; Wed, 22 Dec 2010 01:54:39 -0200 From: Alexandre Oliva To: Richard Guenther Cc: gcc-patches@gcc.gnu.org Subject: Re: [PR debug/46931] don't crash propagating removed DEFs into debug stmts References: Date: Wed, 22 Dec 2010 01:54:39 -0200 In-Reply-To: (Alexandre Oliva's message of "Tue, 21 Dec 2010 04:58:32 -0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 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 On Dec 21, 2010, Alexandre Oliva wrote: > The is_gimple_min_invariant() test was a last-minute thought that was > supposed to be extended so as to handle the case at hand but not other > expressions that can't be moved about, but that I forgot about before > testing and posting the patch. Oops ;-) Here's a revised version. Regression-tested on x86_64-linux-gnu after bootstrap with BOOT_CFLAGS='-O2 -g -ftree-vectorize'. for gcc/ChangeLog from Alexandre Oliva PR debug/46931 * tree-ssa.c (insert_debug_temp_for_var_def): Handle removed assignments. Index: gcc/tree-ssa.c =================================================================== --- gcc/tree-ssa.c.orig 2010-12-18 06:04:11.804255840 -0200 +++ gcc/tree-ssa.c 2010-12-21 05:05:56.394238678 -0200 @@ -305,6 +305,8 @@ insert_debug_temp_for_var_def (gimple_st gimple def_stmt = NULL; int usecount = 0; tree value = NULL; + tree value_unshare = NULL; + tree temp_value = NULL; if (!MAY_HAVE_DEBUG_STMTS) return; @@ -421,6 +423,30 @@ insert_debug_temp_for_var_def (gimple_st || is_gimple_min_invariant (value))) || is_gimple_reg (value)) value = unshare_expr (value); + else if (!gsi && !gimple_bb (def_stmt)) + { + if (is_gimple_val (value)) + value_unshare = value; + else if (TREE_SIDE_EFFECTS (value) + || TREE_THIS_VOLATILE (value) + || !is_gimple_assign (def_stmt)) + value_unshare = NULL; + else if (!gimple_assign_single_p (def_stmt)) + value_unshare = value; + else if (gimple_has_volatile_ops (def_stmt)) + value_unshare = NULL; + else + { + enum tree_code_class tcc; + tcc = TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)); + if (tcc == tcc_reference || tcc == tcc_declaration) + value_unshare = NULL; + else + value_unshare = value; + } + + value = NULL; + } else { gimple def_temp; @@ -454,13 +480,48 @@ insert_debug_temp_for_var_def (gimple_st if (!gimple_debug_bind_p (stmt)) continue; + /* If we have a value that needs unsharing, unshare it. Then, + if the debug stmt binds to VAR, we can replace it, otherwise + we'll create a debug temp, bind it to the unshared value + right before STMT, and replace uses of VAR with the debug + temp. We reuse the same temp for multiple uses, but we don't + attempt to avoid emitting debug temps that would be dominated + by identical debug bind stmts. */ + if (value_unshare) + { + value = unshare_expr (value_unshare); + if (gimple_debug_bind_get_value (stmt) != var) + { + gimple def_temp; + gimple_stmt_iterator ngsi = gsi_for_stmt (stmt); + + if (!temp_value) + { + temp_value = make_node (DEBUG_EXPR_DECL); + + DECL_ARTIFICIAL (temp_value) = 1; + TREE_TYPE (temp_value) = TREE_TYPE (value); + if (DECL_P (value)) + DECL_MODE (temp_value) = DECL_MODE (value); + else + DECL_MODE (temp_value) = TYPE_MODE (TREE_TYPE (value)); + } + + def_temp = gimple_build_debug_bind (temp_value, value, + def_stmt); + + gsi_insert_before (&ngsi, def_temp, GSI_SAME_STMT); + + value = temp_value; + } + } + if (value) FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter) - /* unshare_expr is not needed here. vexpr is either a + /* unshare_expr is not needed here. value is either a SINGLE_RHS, that can be safely shared, some other RHS that was unshared when we found it had a single debug - use, or a DEBUG_EXPR_DECL, that can be safely - shared. */ + use, or a DEBUG_EXPR_DECL, that can be safely shared. */ SET_USE (use_p, value); else gimple_debug_bind_reset_value (stmt);