public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ulrich Drepper <drepper@gmail.com>
To: gcc@gcc.gnu.org
Subject: asm in inline function invalidating function attributes?
Date: Sun, 16 Oct 2011 03:29:00 -0000	[thread overview]
Message-ID: <CAOPLpQc7=Qj=eR8ijiNiYcjNu2err+FfBDmy5LSJ0b7XJkyXUw@mail.gmail.com> (raw)

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.  Consider the code below.

If NOINLINE is defined the compiler will call g once.  No 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.  Don't worry about the content of
the asm, this is correct in the case I care about.  What 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?  I don't think so in
which case, do people agree that this should be changed?


extern int **g(void) __attribute__((const, nothrow));
#ifndef NOINLINE
extern inline int ** __attribute__((always_inline, const, nothrow,
gnu_inline, artificial)) g(void) {
  int **p;
  asm ("call g@plt" : "=a" (p));
  return p;
}
#endif

#define pr(c) ((*g())[c] & 0x80)

extern void h(void);

int
f(const char *s)
{
  int c = 0;
  for (int i = 0; i < 20; ++i)
    c |= pr(s[i]);

  h();

  for (int i = 20; i < 40; ++i)
    c |= pr(s[i]);

  return c;
}

             reply	other threads:[~2011-10-15 21:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-16  3:29 Ulrich Drepper [this message]
2011-10-16 18:52 ` Richard Guenther
2011-10-16 23:37   ` Ulrich Drepper
2011-10-17  8:53     ` Andi Kleen
2011-10-17 11:11       ` Richard Guenther
2011-10-17 16:20         ` Ulrich Drepper
2011-10-17 16:28         ` Andi Kleen
2011-10-17  4:08 ` Jakub Jelinek
2011-10-17  6:57   ` Ulrich Drepper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOPLpQc7=Qj=eR8ijiNiYcjNu2err+FfBDmy5LSJ0b7XJkyXUw@mail.gmail.com' \
    --to=drepper@gmail.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).