------- Additional Comments From joseph at codesourcery dot com 2005-02-13 20:38 ------- Subject: Re: [4.0 Regression] LIM is pulling out a pure function even though there is something which can modify global memory
On Sun, 13 Feb 2005, drow at gcc dot gnu dot org wrote: > I've suggested when talking to someone else about this that they should be > assumed not to trap at the points where they are called. That would allow > calls to them to be removed, although still limit code motion. > > It's a pity there's no rigorous definition of the current meaning of pure. I would say that a pure function is a pure but not necessarily total function of its arguments and those parts of the state of the machine visible to it: you can move or remove calls to pure functions as long as in the abstract machine the function would have been called with the particular machine state with which it does get called. So strlen is pure and "if (s) strlen(s);" is valid and the strlen call can't be moved before the test for NULL. Similarly a const function is a pure but not necessarily total function of the values of its arguments only: so a square root function which doesn't set errno or floating point exception flags could be "const" and a call to it should not be moved before a test that the argument is nonnegative. Where there are optimizations depending on the function being total - not trapping even if you call it with arguments with which the program never calls it in the abstract machine model - perhaps an additional attribute "total" should be added which can be used in conjunction with "const" or "pure". (Though I'm not sure how many real functions are going to be "pure" and "total" but not "const".) -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19828