From patchwork Thu Jan 6 10:11:16 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 77699 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 6DD37B70B3 for ; Thu, 6 Jan 2011 21:12:45 +1100 (EST) Received: (qmail 28891 invoked by alias); 6 Jan 2011 10:12:41 -0000 Received: (qmail 28877 invoked by uid 22791); 6 Jan 2011 10:12:40 -0000 X-SWARE-Spam-Status: No, hits=-5.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, 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; Thu, 06 Jan 2011 10:11:31 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p06ABUHv009384 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 6 Jan 2011 05:11:30 -0500 Received: from freie.oliva.athome.lsd.ic.unicamp.br (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p06ABRpE024423 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 6 Jan 2011 05:11:29 -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 p06ABRNR029346 for ; Thu, 6 Jan 2011 08:11:27 -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 p06ABOiV013909; Thu, 6 Jan 2011 08:11:24 -0200 Received: (from aoliva@localhost) by livre.localdomain (8.14.3/8.14.3/Submit) id p06ABNUq013907; Thu, 6 Jan 2011 08:11:23 -0200 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [PR debug/47106] account used vars only once Date: Thu, 06 Jan 2011 08:11:16 -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 This -fcompare-debug failure occurs because we remove variables from the lexical blocks in the compilation without debug info, but we account the stack space they won't use in the compilation with debug info, which leads to different inlining decisions when stack-growth limits are set. It turns out that the use of TREE_USED in the stack frame size estimation functions seems to be misguided: we initially set it for all local decls that don't appear in lexical blocks (not shown in patch), then account the size of all LOCAL_DECLs that have it set (which means accounting only those that don't appear in lexical blocks), set it on all LOCAL_DECLs, and then account the size of decls in lexical blocks if they have TREE_USED (which means accounting only those that are in LOCAL_DECLs, not accounting those that aren't). I fixed it so that we leave TREE_USED alone after initialization: we account variables that aren't in lexical blocks while looping over LOCAL_DECLs, and then account all variables in lexical blocks, as long as they are actually used, which avoids accounting declarations retained only for purposes of debug information generation. I suppose restoring the assignment and test of TREE_USED would also work, but AFAICT it would just waste CPU cycles. This was regstrapped on x86_{32,64}-linux-gnu. I also bootstrapped it with BOOT_CFLAGS='-O2 -g -fpartial-inlining -flto -fconserve-stack', and regstrapping succeeded except for gfortran.dg/realloc_on_assign_2.exe at all torture levels: stage3 f951 fails to compile it, although a non-bootstrap f951 does, on both x86_{32,64}. From that I concluded that stage[23]s are miscompiled with these BOOT_CFLAGS above, even before my patch, but I haven't debugged or investigated that any further. Ok to install? for gcc/ChangeLog from Alexandre Oliva PR debug/47106 * cfgexpand.c (account_used_vars_for_block): Only account vars that are annotated as used. (estimated_stack_frame_size): Don't set TREE_USED. Index: gcc/cfgexpand.c =================================================================== --- gcc/cfgexpand.c.orig 2010-12-30 18:05:43.930553884 -0200 +++ gcc/cfgexpand.c 2011-01-04 02:39:50.745382341 -0200 @@ -1325,7 +1325,7 @@ account_used_vars_for_block (tree block, /* Expand all variables at this level. */ for (t = BLOCK_VARS (block); t ; t = DECL_CHAIN (t)) - if (TREE_USED (t)) + if (var_ann (t) && var_ann (t)->used) size += expand_one_var (t, toplevel, false); /* Expand all variables at containing levels. */ @@ -1389,9 +1389,10 @@ estimated_stack_frame_size (tree decl) FOR_EACH_LOCAL_DECL (cfun, ix, var) { + /* TREE_USED marks local variables that do not appear in lexical + blocks. We don't want to expand those that do twice. */ if (TREE_USED (var)) size += expand_one_var (var, true, false); - TREE_USED (var) = 1; } size += account_used_vars_for_block (outer_block, true);