From patchwork Sat Jun 4 12:40:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 98722 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 41589B6FC9 for ; Sat, 4 Jun 2011 22:45:56 +1000 (EST) Received: (qmail 6834 invoked by alias); 4 Jun 2011 12:45:55 -0000 Received: (qmail 6823 invoked by uid 22791); 4 Jun 2011 12:45:52 -0000 X-SWARE-Spam-Status: No, hits=-5.8 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; Sat, 04 Jun 2011 12:45:30 +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 p54CjTj3011909 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 4 Jun 2011 08:45:29 -0400 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 p54CjHSB008925 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 4 Jun 2011 08:45:28 -0400 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 p54CjF7x023176 for ; Sat, 4 Jun 2011 09:45:16 -0300 Received: from livre.localdomain (aoliva@localhost.localdomain [127.0.0.1]) by livre.localdomain (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id p54CegWg007392; Sat, 4 Jun 2011 09:40:44 -0300 Received: (from aoliva@localhost) by livre.localdomain (8.14.3/8.14.3/Submit) id p54Cec5G007391; Sat, 4 Jun 2011 09:40:38 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: Re: [trunk<-vta] Re: [vtab] Permit coalescing of user variables References: <4702B1C0.80807@redhat.com> Date: Sat, 04 Jun 2011 09:40:38 -0300 In-Reply-To: (Alexandre Oliva's message of "Tue, 13 Oct 2009 18:11:07 -0300") 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 Oct 13, 2009, Alexandre Oliva wrote: > On Jun 1, 2009, Alexandre Oliva wrote: >> A long time ago, when variable tracking at assignments was just a >> distant dream, we ran into one of the first contentious points, which >> had to do with coalescing SSA names on copyrename. >> On the one hand, coalescing unrelated SSA names made for better code (at >> least in theory) but poorer debug information; on the other hand, >> refraining from coalescing them exploded compile-time memory use. >> We currently implement a trade-off by which variables inlined from other >> functions can be coalesced, so as to save compile-time memory, reduce >> abstraction penalties and retain debug information for out-of-line >> functions. >> The patch below (ping) implements two other possibilities: refraining >> from coalescing even inlined SSA names, which might enable better debug >> information to be generated, and enabling coalescing of all related >> variables, for better code at the expense of debug information. >> VTA doesn't really care which of the 3 possibilities is used, it works >> equally well with all of them. > On Jun 1, 2009, Alexandre Oliva also wrote: >> And the patch below changes the default so that we can optimize more. > This patch combines the two patches described above, now that VTA is > enabled by default. This is an updated version of the patch, adjusting the testcases that didn't expect this kind of variable coalescing. Regstrapped on x86_64-linux-gnu and i686-linux-gnu, along with a patch for a latent cprop problem that caused a compare-debug failure in the ada rts. Ok to install? for gcc/ChangeLog from Alexandre Oliva * common.opt (ftree-coalesce-inlined-vars): New. (ftree-coalesce-vars): New. * doc/invoke.texi: Document them. * tree-ssa-copyrename.c (copy_rename_partition_coalesce): Implement them. for gcc/testsuite/ChangeLog from Alexandre Oliva * g++.dg/tree-ssa/ivopts-2.C: Adjust for coalescing. * gcc.dg/tree-ssa/forwprop-11.c: Likewise. * gcc.dg/tree-ssa/ssa-fre-1.c: Likewise. * gcc.dg/guality/bswaptest.c: Avoid coalescing and early death of test variable. * gcc.dg/guality/clztest.c: Likewise. * gcc.dg/guality/ctztest.c: Likewise. * gcc.dg/guality/rotatetest.c: Likewise. Index: gcc/common.opt =================================================================== --- gcc/common.opt.orig 2011-06-04 09:00:30.005102549 -0300 +++ gcc/common.opt 2011-06-04 09:01:29.199347556 -0300 @@ -1898,6 +1898,14 @@ ftree-ch Common Report Var(flag_tree_ch) Optimization Enable loop header copying on trees +ftree-coalesce-inlined-vars +Common Report Var(flag_ssa_coalesce_vars,1) Init(2) RejectNegative Optimization +Enable coalescing of copy-related user variables that are inlined + +ftree-coalesce-vars +Common Report Var(flag_ssa_coalesce_vars,2) Optimization +Enable coalescing of all copy-related user variables + ftree-copyrename Common Report Var(flag_tree_copyrename) Optimization Replace SSA temporaries with better names in copies Index: gcc/tree-ssa-copyrename.c =================================================================== --- gcc/tree-ssa-copyrename.c.orig 2011-06-04 09:00:30.160103200 -0300 +++ gcc/tree-ssa-copyrename.c 2011-06-04 09:01:29.252347770 -0300 @@ -194,20 +194,21 @@ copy_rename_partition_coalesce (var_map ign1 = TREE_CODE (root1) == VAR_DECL && DECL_IGNORED_P (root1); ign2 = TREE_CODE (root2) == VAR_DECL && DECL_IGNORED_P (root2); - /* Never attempt to coalesce 2 user variables unless one is an inline - variable. */ + /* Refrain from coalescing user variables, if requested. */ if (!ign1 && !ign2) { - if (DECL_FROM_INLINE (root2)) + if (flag_ssa_coalesce_vars && DECL_FROM_INLINE (root2)) ign2 = true; - else if (DECL_FROM_INLINE (root1)) + else if (flag_ssa_coalesce_vars && DECL_FROM_INLINE (root1)) ign1 = true; - else + else if (flag_ssa_coalesce_vars != 2) { if (debug) fprintf (debug, " : 2 different USER vars. No coalesce.\n"); return false; } + else + ign2 = true; } /* If both values have default defs, we can't coalesce. If only one has a Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi.orig 2011-06-04 09:00:30.665105322 -0300 +++ gcc/doc/invoke.texi 2011-06-04 09:01:29.479348698 -0300 @@ -395,8 +395,8 @@ Objective-C and Objective-C++ Dialects}. -fsignaling-nans -fsingle-precision-constant -fsplit-ivs-in-unroller @gol -fsplit-wide-types -fstack-protector -fstack-protector-all @gol -fstrict-aliasing -fstrict-overflow -fthread-jumps -ftracer @gol --ftree-bit-ccp @gol --ftree-builtin-call-dce -ftree-ccp -ftree-ch -ftree-copy-prop @gol +-ftree-bit-ccp -ftree-builtin-call-dce -ftree-ccp -ftree-ch @gol +-ftree-coalesce-inline-vars -ftree-coalesce-vars -ftree-copy-prop @gol -ftree-copyrename -ftree-dce -ftree-dominator-opts -ftree-dse @gol -ftree-forwprop -ftree-fre -ftree-loop-if-convert @gol -ftree-loop-if-convert-stores -ftree-loop-im @gol @@ -7231,6 +7231,22 @@ temporaries to other variables at copy l variable names which more closely resemble the original variables. This flag is enabled by default at @option{-O} and higher. +@item -ftree-coalesce-inlined-vars +A more limited form of @option{-ftree-coalesce-vars}, that performs +the transformation if at least one of the variables was inlined. This +may harm debug information of such inlined variables, but it will keep +variables of the main function apart from each other, such that they +are more likely to contain the expected values in a debugging session. +This was the default in GCC versions older than 4.7. + +@item -ftree-coalesce-vars +Tell the compiler to attempt to combine small user variables that +don't need to live in memory, when it finds a copy between them. This +may severely limit the ability to debug an optimized program compiled +without @option{-fvar-tracking-assignments}. In the negated form, +this flag prevents SSA coalescing of user variables, including inlined +ones. This option is enabled by default. + @item -ftree-ter @opindex ftree-ter Perform temporary expression replacement during the SSA->normal phase. Single Index: gcc/testsuite/g++.dg/tree-ssa/ivopts-2.C =================================================================== --- gcc/testsuite/g++.dg/tree-ssa/ivopts-2.C.orig 2011-06-04 09:13:29.613784393 -0300 +++ gcc/testsuite/g++.dg/tree-ssa/ivopts-2.C 2011-06-04 09:16:24.688235836 -0300 @@ -7,5 +7,5 @@ void test (int *b, int *e, int stride) *p = 1; } -/* { dg-final { scan-tree-dump-times "PHI