This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Use malloca instead alloca


On Sat, Jan 12, 2013 at 02:38:57PM -0800, Paul Eggert wrote:
> On 01/12/2013 02:24 PM, Rich Felker wrote:
> >> gcc does not optimize alloca
> >> > well so type[constant] is faster than alloca(constant). This is bug in
> >> > gcc and can be fixed.
> > No, this _cannot_ be fixed. If any non-static-sized objects
> 
> Surely GCC can be fixed so that a function that does this first:
> 
>    char *p = alloca (100);
> 
> is executed with code that's no slower than if the function had
> done this first:
> 
>    char buf[100];
>    char *p = buf;
> 
> Currently, GCC doesn't do this optimization, but I don't see any
> reason why it couldn't.
> 
> There are other optimizations involving alloca (constant) that
> GCC couldn't do, but the ones that OndÅej are talking about
> seem doable.

Debian llvm-gcc-4.2 does that.

I found this by using c++ code that was something like this.

inline int bar(int x, int no){
  ary = alloca(no);
  stuff(x,ary);  
}

int foo(int x){
  bar(x,64);
}

Problem with this code is that gcc does not inline functions containing alloca.
icc does inline this but also inlines bar(x,1<<30);

I rewrote bar as a macro as I did not know how do these optimizations in
general. 


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