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

> > ------- Additional Comments From rakdver at gcc dot gnu dot org  2005-05-22 
> > 21:36 -------
> > Do you still believe we should move gettype2 out of the loop???
> 
> Okay, let's compromise.
> If i move cgraph do noreturn and infinite loop detection, so that we
> know everything we can about do_something and gettype2 that is possible,
> and we detect neither for do_something, are you still going to claim
> that we shouldn't move it out of the loop?

If we know that do_something must return (which would currently only be
the case if it was const or pure), gettype2 will be moved out of the loop.

> ISTM that presuming a call in a loop is incredibly expensive seems
> wrong, when that call is const. Your case seems the very extreme corner
> case, not the common case.
> 
> People mark const on simple calls (remember, const can't read from
> anything but readonly memory (*) ), not huge monster calls that do lots of
> stuff.

Except when they don't :-)  Moving 'pure' functions out of loops without
checking whether they must be executed or nor causes correctness
problems.  For 'const' functions this is more interesting, as there
are definitions of 'const' that allow things that would make it
incorrect, and definitions that don't (especially (*) is by no means
accepted by everyone -- mentioning it at a mailing list is a good start
for a flame war).  As you claim, const functions usually are fast, so
by not moving them we do not cause a disaster.  By moving them, we can.


-- 


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

Reply via email to