Function-specific optimization flags and inlining

Bingfeng Mei bmei@broadcom.com
Wed Sep 8 10:43:00 GMT 2010


I tried with following code.
~/work/install-x86/bin/gcc tst.c -O2 -o a.out -save-temps
foo still gets inlined into main function.

If I use -O0 in the attribute, the foo is compiled with -O0
and not inlined. I am a bit confused now. 

Bingfeng

static void foo (int * __restrict__ a, int * __restrict__ b, int * __restrict__ c) __attribute__((optimize("-O1")));
static void foo (int * __restrict__ a, int * __restrict__ b, int * __restrict__ c)
{
   int i;
   for(i = 0; i < 100; i+=4)
     {
       a[i] = b[i] * c[i];
       a[i+1] = b[i+1] * c[i+1];
       a[i+2] = b[i+2] * c[i+2];
       a[i+3] = b[i+3] * c[i+3];
     }
}   

int a[100], b[100], c[100];

int main(int argc, char **argv)
{
  int i;
  for (i = 0; i < 100; i++)
  {
     b[i] = i;
     c[i] = 100 - i;
  }
  
  foo (a, b, c);
  return 0;
}
> -----Original Message-----
> From: Richard Guenther [mailto:richard.guenther@gmail.com]
> Sent: 08 September 2010 11:26
> To: Bingfeng Mei
> Cc: gcc@gcc.gnu.org
> Subject: Re: Function-specific optimization flags and inlining
> 
> On Wed, Sep 8, 2010 at 12:07 PM, Bingfeng Mei <bmei@broadcom.com> wrote:
> > Hello,
> > I found that currently if a function with specific optimization flags
> is inlined,
> > the flags are lost during compilation. This will happen much more
> often with
> > LTO (which still cannot handle it in bytecode). I wonder whether this
> > is the best way to do it. Maybe we just don't inline any function
> with
> > specific optimization flags or have an extra option to choose that.
> What do
> > you think?
> 
> I think they are already inlining-disabled.  Maybe check why it doesn't
> work for you?
> 
> Richard.
> 
> > Cheers,
> > Bingfeng Mei
> >
> >




More information about the Gcc mailing list