This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Gcc-3.0 unroll bug
- To: jbuck at synopsys dot COM (Joe Buck)
- Subject: Re: Gcc-3.0 unroll bug
- From: Zoltan Hidvegi <hzoli at hzoli dot 2y dot net>
- Date: Fri, 20 Jul 2001 17:17:26 -0500 (CDT)
- Cc: hzoli at hzoli dot 2y dot net, edmar at motorola dot com, gcc at gcc dot gnu dot org
Joe Buck wrote:
> > > Consider the following for statement:
> > > for (i = UINT_MAX - 1; i > 5; i++)
> > > This statement should execute 2 times because, after that,
> > > the i.v. will turn 0 and the condition (i > 5) will be false.
> >
> > Try the patch in
> >
> > http://gcc.gnu.org/ml/gcc-patches/2001-07/msg01080.html
> >
> > Also note that the behavior is undefined in the ANSI C++ standard
> > (probably in C as well).
>
> ?? If i is unsigned, the behavior is defined; incrementing an unsigned
> with value UINT_MAX-1 portably gives zero. The C and C++ standards
> mandate that arithmetic on unsigned integers is modulo (UINT_MAX+1)
> arithmetic.
OK, I've found that in the C++ standard now, I misinterpreted section 5
of the C++ standard, since I did not read 3.9.1. Anyway, the referenced
patch does fix this correctly. The bigger problem is loops like this:
foo(unsigned int j){unsigned int i; for (i = ~0-39; i < j; i += 4);}
foo(~0) is an infinite loop by the standard, but gcc -O2 with
count-register architectures makes it into a finite branch. That's
because it has to calculate how many times the loop will be executed in
advance. If you have to deal with overflows resulting in infinite loops
here, that would require extra code to be generated for every such loop,
even if they would never overflow :-(.
Zoli