This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

How inlined are inlined functions?



I've noticed that I get worse code when I used inlined functions than
I do when I use a macro.  I understand that argument passing to
inlined functions is not right, and Mark Mitchell is working on this,
but the problem I'm seeing seems to be related to the returned value.

The code generated is correct, so this isn't a bug report, but I'm
curious as to why some of the optimizations GCC usually brings to bear
don't seem to be working here.  If inlined functions are generally not
handled as well as macros, I may be unable to use them.


Here's my code:

#ifdef INLINE

extern inline int
ptr_bit_clear (int *x)
{
  return ! (*x & 1);
}
#endif

#ifdef MACRO

#define ptr_bit_clear(x) (! (*(x) & 1))

#endif

extern int
foo (int *x)
{
  if (ptr_bit_clear (x))
    return bar ();
}


I'm using EGCS 2.91.66, on Red Hat GNU/Linux 6.1, on a Pentium.  The
command is `gcc -c -O2 -save-temps'.  Here is a diff of the two
assembly files:

*** inline2.macro.s     Fri Dec  3 11:30:30 1999
--- inline2.inline.s    Fri Dec  3 11:30:30 1999
***************
*** 9,18 ****
        pushl %ebp
        movl %esp,%ebp
        movl 8(%ebp),%eax
!       testb $1,(%eax)
!       jne .L2
        call bar
! .L2:
        leave
        ret
  .Lfe1:
--- 9,20 ----
        pushl %ebp
        movl %esp,%ebp
        movl 8(%ebp),%eax
!       movl (%eax),%eax
!       xorb $1,%al
!       testb $1,%al
!       je .L3
        call bar
! .L3:
        leave
        ret
  .Lfe1:



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]