This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

Re: [doc] empty loops


Hello,

> Also, playing with empty loops, I was shocked after looking at the code
> created for the recursive variant of
> 
> void foo(void)
> {
>         for (int i=0; i<1000; ++i)
>                 ;
> }
> 
> namely:
> 
> static inline void foo3(int i)
> {
>         if (!(i<1000))
>                 return;
>         ++i;
>         foo3(i);
> }
> void foo4(void)
> {
>         foo3(0);
> }
> 
> I thought Zednek contributed a patch for optimizing these
> tail-recursive functions
> some time ago.

could you please explain what exactlu shocks you here?  Tail recursion
elimination on this example works perfectly fine for me.

> Even for a standard n! implementation we suck.

Not that much; iv optimizations could do a bit better job in
this case, but the code that we produce basically is

int fact(int n)
{
  i = 0;
  m = 1;

  while (n - i != 0)
    {
      m *= n - i;
      i++;
    }
}

which is not that bad.

Zdenek


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