This is the mail archive of the
mailing list for the GCC project.
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: Florian Weimer <fw at deneb dot enyo dot de>
- Cc: gcc at gcc dot gnu dot org, dje at gcc dot gnu dot org
- Date: Sat, 1 Jan 2005 01:29:06 +0100
- Subject: Re: -funsafe-loop-optimizations
- References: <20041231211409.GA22814@atrey.karlin.mff.cuni.cz> <email@example.com>
> > several times some people sounded opinion that in addition to improving
> > analyses in loop optimizer, we might also add a flag that would enable
> > the compiler to assume that the compiled code does not contain loops
> > behaving in "weird" way (loops whose control induction variables
> > overflows, infinite loops with nontrivial exit conditions).
> Are these optimizations permitted by the C standard, the Ada standard
in general no; they may alter semantics of the program, if there happens
to be such a "weird" loop in the program.
> If not, the documentation should mention this fact, and it should
> provide proper documentation. With the current documentation, I have
> no idea whether it's safe to use this option for my code or not.
Almost surely yes. There are several patterns that might get
misscompiled with this flag, but none of them is likely to occur
in "normal" code (some of the constants in the examples need
to be replaced by variables with a given value, since with the explicit
constants loop optimizer recognizes that the loop is "weird" and will
not try to optimize it even with the -funsafe-loop-optimizations flag):
1) You write empty loops that may be infinite, although they have
nontrivial exit condition. E.g.
for (i = 1; i != 3; i *= 2)
2) You write loops whose control induction variable overflows, e.g.
for (i = 0; i != 1; i+=2)
for (i = 0; i <= MAX_UNSIGNED; i++)
for (i = 0; i < MAX_UNSIGNED - 2; i += 17)
In particular programs that might get misscompiled with
-funsafe-loop-optimizations are usually not portable,
since they depend on exact sizes of types.