This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] Dce & infinite loops
Hello,
> > > > I may be wrong, but IIRC it is incorrect to remove infinite loops, as
> > > > happens currently for example for the following code:
> > > >
> > > > int main(void)
> > > > {
> > > > unsigned i;
> > > >
> > > > for (i = 1; i != 0; i+=2);
> > > >
> > > > return 0;
> > > > }
> > >
> > > Removing an infinte loop is indeed wrong. Hence this comment
> > > in tree-ssa-dce.c:
> > >
> > > /* Some blocks don't have an immediate post dominator. This can happen
> > > for example with infinite loops. Removing an infinite loop is an
> > > inappropriate transformation anyway... */
> > >
> > > If we remove that infinite loop, you found a bug.
> >
> > the problem is that the loop in the example above has an exit (that is
> > never taken); therefore the code in tree-ssa-dce.c you cite does not
> > handle it.
>
> I know, and I'm not sure how to deal with this. It seems kind of silly
> to need something like IV/loop analysis to decide whether or not some
> code is dead.
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).
Zdenek