This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [tree-ssa] Dce & infinite loops


Hello,

> >the simple conservative solution is to mark all back edges as 
> >neccesary.
> >You can do a bit better and use the results of simple loop analysis to
> >avoid doing this for back edges of loops for that you are sure that 
> >they terminate.
> >But you won't gain much by this in practice, since people usually do 
> >not
> >write useless loops.  Also it is not clear whether people really want 
> >such
> >loop to be optimized out (they might write it in order to make the
> >program wait).
> 
> It is important to remove loops that are empty, but can be shown
> to terminate. Even though programmers may not write such code,
> other optimizations may make all code invariant, resulting in an
> empty loop.

how often this happens? More precisely, could I see at least one
real-world example?

> True, long ago GCC did keep such loops, but that policy has been
> explicitly reversed later on. If someone wants to keep a loop,
> just make sure it has some external effect such as writing to
> volatile memory.
> 
> I fail to see why you would need to have any special hacks to
> prevent infinite loops from being optimized away.

These are no special hacks. The problem that was missed here is
that nontermination is (an ugly kind of) side effect.  So there
is no fundamental difference between handling this and handling
any other statement that may cause something observable, except
for the value produced.

Zdenek

> What is the
> logic that causes this? There seems to be a more fundamental
> problem if the optimizers determine that the function would
> return 0. What if the loop was replaced with a call to a
> function that is marked non-terminating?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]