------- Additional Comments From rakdver at atrey dot karlin dot mff dot cuni 
dot cz  2005-05-22 22:31 -------
Subject: Re:  missed optimization due with const function and pulling out of 
loops

> > 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.

I would assume meaning should be clean, once you fix the obvious typo
you noticed.

int my_fancy_divide(int x, int z) attribute(const)
{
  return x / z;
}

while (...)
  {
    if (z != 0)
      y = my_fancy_divide (x,z)
  }

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

The definition by no means is formulated precisely, in particular it is
not entirely clear what "reading memory" means.


-- 


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

Reply via email to