From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24565 invoked by alias); 22 Jun 2012 08:30:57 -0000 Received: (qmail 24546 invoked by uid 22791); 22 Jun 2012 08:30:54 -0000 X-SWARE-Spam-Status: No, hits=-4.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-ob0-f175.google.com (HELO mail-ob0-f175.google.com) (209.85.214.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 22 Jun 2012 08:30:39 +0000 Received: by obcva7 with SMTP id va7so1745363obc.20 for ; Fri, 22 Jun 2012 01:30:39 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.147.98 with SMTP id tj2mr1014688obb.11.1340353839355; Fri, 22 Jun 2012 01:30:39 -0700 (PDT) Received: by 10.76.82.4 with HTTP; Fri, 22 Jun 2012 01:30:39 -0700 (PDT) In-Reply-To: References: <4FE26AFC.3000703@redhat.com> Date: Fri, 22 Jun 2012 08:50:00 -0000 Message-ID: Subject: Re: New option to turn off stack reuse for temporaries From: Richard Guenther To: Xinliang David Li Cc: Jason Merrill , GCC Patches , Michael Matz Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2012-06/txt/msg01451.txt.bz2 On Thu, Jun 21, 2012 at 8:27 PM, Xinliang David Li wro= te: > On Thu, Jun 21, 2012 at 2:21 AM, Richard Guenther > wrote: >> On Thu, Jun 21, 2012 at 7:28 AM, Xinliang David Li = wrote: >>> I modified the documentation and it now looks like this: >>> >>> @item -ftemp-stack-reuse >>> @opindex ftemp_stack_reuse >>> This option enables stack space reuse for temporaries. The default is o= n. >>> The lifetime of a compiler generated temporary is well defined by the C= ++ >>> standard. When a lifetime of a temporary ends, and if the temporary liv= es >>> in memory, an optimizing compiler has the freedom to reuse its stack >>> space with other temporaries or scoped local variables whose live range >>> does not overlap with it. However some of the legacy code relies on >>> the behavior of older compilers in which temporaries' stack space is >>> not reused, the aggressive stack reuse can lead to runtime errors. This >>> option is used to control the temporary stack reuse optimization. >>> >>> Does it look ok? >> >> The flag is not restricted to the C++ compiler and applies to all automa= tic >> variables. =A0The description is very much C++ specific though - I think >> it should mention the concept of scopes. >> >> Also even with this flag there is no guarantee we cannot figure out life= time >> in other ways, for example if the temporary gets promoted to a register. > > That should not be an issue then -- if the compiler can figure out the > live range via data flow analysis (instead of relying on > assertions/markers), the stack reuse or register promotion based on > that should always be safe (assuming no bugs in the analysis). > >> Also with this patch you remove code motion barriers which might cause >> other issues. > > What other issues? It enables more potential code motion, but on the > other hand, causes more conservative stack reuse. As far I can tell, > the handling of temporaries is added independently after the clobber > for scoped variables are introduced. This option can be used to > restore the older behavior (in handling temps). Well, it does not really restore the old behavior (if you mean before adding CLOBBERS, not before the single patch that might have used those for gimplifying WITH_CLEANUP_EXPR). You say it disables stack-slot sharing for those decls but it also does other things via side-effects of no longer emitting the CLOBBER. I say it's better to disable the stack-slot sharing. Richard. > thanks, > > David > >> >> A more "proper" place to fix this is when we actually do the stack reuse, >> in cfgexpand. >> >> So no, I don't think the patch is ok as-is. >> >> Thanks, >> Richard. >> >>> thanks, >>> >>> David >>> >>> On Wed, Jun 20, 2012 at 5:29 PM, Jason Merrill wrote: >>>> The documentation needs to explain more what the option controls, and = why >>>> you might want it on or off. =A0Other than that it looks fine. >>>> >>>> Jason