From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4611 invoked by alias); 3 Aug 2011 14:55:37 -0000 Received: (qmail 4601 invoked by uid 22791); 3 Aug 2011 14:55:36 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mo-p00-ob.rzone.de (HELO mo-p00-ob.rzone.de) (81.169.146.161) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 03 Aug 2011 14:55:23 +0000 X-RZG-AUTH: :LXoWVUeid/7A29J/hMvvT2k715jHQaJercGObUOFkj18odoYNahU4Q== X-RZG-CLASS-ID: mo00 Received: from [192.168.0.22] (business-188-111-022-002.static.arcor-ip.net [188.111.22.2]) by smtp.strato.de (klopstock mo4) (RZmta 26.2) with ESMTPA id h00e3an73EeN1Y ; Wed, 3 Aug 2011 16:54:39 +0200 (MEST) Message-ID: <4E39612E.3050402@gjlay.de> Date: Wed, 03 Aug 2011 14:55:00 -0000 From: Georg-Johann Lay User-Agent: Thunderbird 2.0.0.24 (X11/20100302) MIME-Version: 1.0 To: Richard Guenther CC: Michael Matz , Ulrich Weigand , Ian Lance Taylor , Mikael Pettersson , Michael Walle , Hans-Peter Nilsson , Richard Henderson , gcc@gcc.gnu.org Subject: Re: libgcc: strange optimization References: <201108030911.p739BZri018360@d06av02.portsmouth.uk.ibm.com> <4E3919EA.2080002@gjlay.de> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2011-08/txt/msg00069.txt.bz2 Richard Guenther wrote: > On Wed, Aug 3, 2011 at 3:27 PM, Michael Matz wrote: >> Hi, >> >> On Wed, 3 Aug 2011, Richard Guenther wrote: >> >>>> Yes, that's reasonable. As I understand the docs, in code like >>>> >>>> void foo () >>>> { >>>> register int var asm ("r1") = 10; >>>> asm (";; use r1"); >>>> } >>>> >>>> there is nothing that connects var to the asm and assuming that >>>> r1 holds 10 in the asm is a user error. >>>> >>>> The only place where the asm attached to a variable needs to have >>>> effect are the inline asm sequences that explicitly refer to >>>> respective variables. If there is no inline asm referencing a >>>> local register variable, there is on difference to a non-register >>>> auto variable; there could even be a warning that in such a case >>>> that >>>> >>>> register int var asm ("r1") = 10; >>>> >>>> is equivalent to >>>> >>>> int var = 10; >>>> >>>> This would render local register variables even more functional >>>> because no one needed to care if there were implicit library calls or >>>> things like that. >>> Yes, I like that idea. >> I do too. Except it doesn't work :) >> >> There's a common idiom of accessing registers read-only by declaring local >> register vars. E.g. to (*grasp*) the stack pointer. There won't be a DEF >> for that register var, and hence at use-points we couldn't reload any >> sensible values into those registers (and we really shouldn't clobber the >> stack pointer in this way). >> >> We could introduce that special semantic only for non-reserved registers, >> and require no writes to register vars for reserved registers. >> >> Or we could simply do: >> >> if (any_local_reg_vars) >> optimize = 0; >> >> But I already see people wanting to _do_ optimization also with local reg >> vars, "just not the wrong optimizations" ;-/ Definitely yes. As I wrote above, if you see asm it's not unlikely that it is a piece of performance critical code. > I'd say we should start rejecting all these bogus constructs by default > (maybe accepting them with -fpermissive and then, well, maybe generate > some dwim code). That is, local register var decls are only valid > with an initializer, they are implicitly constant (you can't re-assign to them). > Reserved registers are a no-go (like %esp), either global or local. Would that help? Like in code static inline void foo (int arg) { register const int reg asm ("r1") = arg; asm ("..."::"r"(reg)); } And with output constraints like "=r,0" or "+r". Or in local blocks: static inline void foo (int arg) { register const int reg asm ("r1") = arg; ... { register const int reg2 asm ("r1") = reg; asm ("..."::"r"(reg2)); } } Do the current optimizers shred inline asm with ordinary constraints but without local registers? If yes, there is a considerable problem in the optimizers and/or in GCC. If not, why can't local register variables work similarly, i.e. propagate the register information into respective asms and forget about it for the variables? Johann > Richard. > >> Ciao, >> Michael.