------- Additional Comments From dberlin at gcc dot gnu dot org  2005-05-22 
22:24 -------
Subject: Re:  missed optimization due with
        const function and pulling out of loops

> on the other hand, we should not let the definition make the concept
> useless.  Being able to make

The definition actually matches what other compilers call "isolated" (no
access to global variables)  combined with the property called
"side-effect free" (calling multiple times with same parameters is same
as calling once).
We could of course, split these concepts if we wanted to.


> 
> int something(int i)
> {
>   static int a[100];
> 
>   if (a[i] == 0)
>     a[i] = somewhat_slow_computation;
>   return a[i];
> }
> 
> const is fairly useful.

> 
> Anyway, moving possibly non-executed const function may cause also
> other problems.  Consider
> 
> int my_fancy_divide(int x, int z) attribute(const)
> {
>   return x / z;
> }
> 
> while (...)
>   {
>     if (z != 0)
>       x = my_fancy_divide (x,z)
>   }

Uh, this may be const, but you can't move these out anyway because the
value of the parameters has changed, so i'm not sure what you are going
for.
> Thus you would also have to require the const function to be total.
> Making const still more and more useless.
> 
> 

const has a very specific definition already. Moving get_type2 out of
the loop is consistent with that definition.





-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21712

Reply via email to