From patchwork Fri Jul 1 21:21:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 102971 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 A8BA3B6F5B for ; Sat, 2 Jul 2011 07:22:06 +1000 (EST) Received: (qmail 865 invoked by alias); 1 Jul 2011 21:22:05 -0000 Received: (qmail 857 invoked by uid 22791); 1 Jul 2011 21:22:04 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_TM, T_RP_MATCHES_RCVD 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; Fri, 01 Jul 2011 21:21:51 +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.14.4/8.14.4) with ESMTP id p61LLpLh009362 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 1 Jul 2011 17:21:51 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p61LLoqj020551 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 1 Jul 2011 17:21:50 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p61LLnYe002181 for ; Fri, 1 Jul 2011 23:21:49 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p61LLn3L002179 for gcc-patches@gcc.gnu.org; Fri, 1 Jul 2011 23:21:49 +0200 Date: Fri, 1 Jul 2011 23:21:48 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix tree-into-ssa.c for debug stmts (PR debug/49602) Message-ID: <20110701212148.GK16443@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! For debug stmt uses, we don't want any PHI nodes to be created just because of them, so the debug uses need to be ignored during decisions which PHI nodes to add. Unfortunately that means get_current_def can't be always trusted. The following patch trusts it in a few cases where I'm reasonably sure it is trustable. Perhaps some more cases could be added in the future if anyone has ideas... Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2011-07-01 Jakub Jelinek PR debug/49602 * tree-into-ssa.c (rewrite_debug_stmt_uses): Disregard get_current_def return value if it can't be trusted to be the current value of the variable in the current bb. * gcc.dg/pr49602.c: New test. Jakub --- gcc/tree-into-ssa.c.jj 2011-06-23 10:13:58.000000000 +0200 +++ gcc/tree-into-ssa.c 2011-07-01 20:39:40.000000000 +0200 @@ -1343,7 +1343,41 @@ rewrite_debug_stmt_uses (gimple stmt) } } else - def = get_current_def (var); + { + def = get_current_def (var); + /* Check if get_current_def can be trusted. */ + if (def) + { + basic_block bb = gimple_bb (stmt); + basic_block def_bb + = SSA_NAME_IS_DEFAULT_DEF (def) + ? NULL : gimple_bb (SSA_NAME_DEF_STMT (def)); + + /* If definition is in current bb, it is fine. */ + if (bb == def_bb) + ; + /* If definition bb doesn't dominate the current bb, + it can't be used. */ + else if (def_bb && !dominated_by_p (CDI_DOMINATORS, bb, def_bb)) + def = NULL; + /* If there is just one definition and dominates the current + bb, it is fine. */ + else if (get_phi_state (var) == NEED_PHI_STATE_NO) + ; + else + { + struct def_blocks_d *db_p = get_def_blocks_for (var); + + /* If there are some non-debug uses in the current bb, + it is fine. */ + if (bitmap_bit_p (db_p->livein_blocks, bb->index)) + ; + /* Otherwise give up for now. */ + else + def = NULL; + } + } + } if (def == NULL) { gimple_debug_bind_reset_value (stmt); --- gcc/testsuite/gcc.dg/pr49602.c.jj 2011-07-01 20:42:44.000000000 +0200 +++ gcc/testsuite/gcc.dg/pr49602.c 2011-07-01 18:49:04.000000000 +0200 @@ -0,0 +1,17 @@ +/* PR debug/49602 */ +/* { dg-do compile } */ +/* { dg-options "-g -O2" } */ + +static void +foo (int *x) +{ +} + +void +bar (int *x) +{ + int i; + for (i = 0; i == 1; ++i) + x = 0; + foo (x); +}