As far as I can see the loop in the function f() always terminates without the
loop counter overflowing, but GCC cannot tell that it does.
$ g++-4.3-20070907 -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.3-20070907/configure --program-suffix=-4.3-20070907
--enable-language=c,c++ --prefix=/home/jack/opt --with-mpfr=/home/jack/opt
Thread model: posix
gcc version 4.3.0 20070907 (experimental) (GCC)
$ cat no_loop_opt.c
void f(unsigned int in)
{
unsigned int rnd_to_2 = (in - (in % 2));
unsigned int i;
for(i = 0; i != rnd_to_2; i += 2)
;
}
$ gcc-4.3-20070907 -O2 -Wall -Wextra -Wunsafe-loop-optimizations -c
no_loop_opt.c
no_loop_opt.c: In function f:
no_loop_opt.c:7: warning: cannot optimize loop, the loop counter may overflow
--
Summary: Missed optimization: cannot determine loop termination
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: lloyd at randombit dot net
GCC build triplet: x86_64-unknown-linux-gnu
GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34114