public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* asm in inline function invalidating function attributes?
@ 2011-10-16  3:29 Ulrich Drepper
  2011-10-16 18:52 ` Richard Guenther
  2011-10-17  4:08 ` Jakub Jelinek
  0 siblings, 2 replies; 9+ messages in thread
From: Ulrich Drepper @ 2011-10-16  3:29 UTC (permalink / raw)
  To: gcc

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;
}

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-10-17 14:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-16  3:29 asm in inline function invalidating function attributes? Ulrich Drepper
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

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).