> Jan Hubicka: > > >There are also few annotations that I would like to add to functions > >declared in headers where GCC don't know if they are finite so it is not > >sure it can remove call to them even if it can prove there are no side > >effects otherwise. > > Hi, > > You may be interested in 6.5p5 of the latest standard draft (N2857) which > states: > > "A loop that, outside of the for-init-statement in the case of a for > statement, > - makes no calls to library I/O functions, and > - does not access or modify volatile objects, and > - performs no synchronization operations (1.10) or atomic operations > (Clause 29) > may be assumed by the implementation to terminate. [ Note: This is intended > to allow compiler transformations, such as removal of empty loops, even > when termination cannot be proven. -end note ]" > > This new rule has been introduced by the memory model changes.
This indeed is interesting :) It would make those pure/const annotations on STL loops redundant and save us some SCEV analyzis in pure/const pass as well as in empty loop removal and CD-DCE. (in fact they are kind of optimization challenge as by inlining function we lose the hint, so I would need to work out some extra code maintaining info about finiteness of the function). On mainline I enabled infinite loop removal at -funsafe-loop-optimizations. I would suggest adding -fempty-loops-terminate and make it default for C++? It does not apply for C, right? What about loops formed by infinite recursion? Honza