From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32194 invoked by alias); 16 Oct 2011 10:32:05 -0000 Received: (qmail 32185 invoked by uid 22791); 16 Oct 2011 10:32:04 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-gx0-f175.google.com (HELO mail-gx0-f175.google.com) (209.85.161.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 16 Oct 2011 10:31:51 +0000 Received: by ggnq1 with SMTP id q1so2560777ggn.20 for ; Sun, 16 Oct 2011 03:31:50 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.44.9 with SMTP id a9mr1352056obm.61.1318761110420; Sun, 16 Oct 2011 03:31:50 -0700 (PDT) Received: by 10.182.14.226 with HTTP; Sun, 16 Oct 2011 03:31:50 -0700 (PDT) In-Reply-To: References: Date: Sun, 16 Oct 2011 18:52:00 -0000 Message-ID: Subject: Re: asm in inline function invalidating function attributes? From: Richard Guenther To: Ulrich Drepper Cc: gcc@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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-10/txt/msg00241.txt.bz2 On Sat, Oct 15, 2011 at 11:52 PM, Ulrich Drepper wrote: > I think gcc should allow the programmer to tell it something about a > function return value even if the function is inlined and the compiler > can see all the code. =A0Consider the code below. > > If NOINLINE is defined the compiler will call g once. =A0No need to do > anything after the h() call since the function is marked const. > > If NOINLINE is not defined and the compiler sees the asm statement it > will expand the function body twice. =A0Don't worry about the content of > the asm, this is correct in the case I care about. =A0What I expect is > that gcc still respects that the function is marked const and performs > the same optimization as in the case when the function is not inlined. > > Is there anything I miss how to achieve this? =A0I don't think so in > which case, do people agree that this should be changed? It's difficult to do this in general given that we give up for statements in most optimization passes that would make the function not auto-discovered as const (that is, a volatile asm such as yours). So the case boils down to a optimization phase ordering issue. While we do CSE before inlining the function the CSE opportunity is only discovered after doing loop invariant motion - which is done way after we inlined the function (and you can probably see that the asm() is not considered loop invariant either). The question is now, of course why you need to emit calls from an asm() statement, something which isn't guaranteed to work anyway (IIRC). Richard. > > extern int **g(void) __attribute__((const, nothrow)); > #ifndef NOINLINE > extern inline int ** __attribute__((always_inline, const, nothrow, > gnu_inline, artificial)) g(void) { > =A0int **p; > =A0asm ("call g@plt" : "=3Da" (p)); > =A0return p; > } > #endif > > #define pr(c) ((*g())[c] & 0x80) > > extern void h(void); > > int > f(const char *s) > { > =A0int c =3D 0; > =A0for (int i =3D 0; i < 20; ++i) > =A0 =A0c |=3D pr(s[i]); > > =A0h(); > > =A0for (int i =3D 20; i < 40; ++i) > =A0 =A0c |=3D pr(s[i]); > > =A0return c; > } >