This is the mail archive of the gcc-patches@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]

Re: Loop unroll fixes


Bernd Schmidt wrote:
> I've looked at it for a bit.  I do not think the patch is correct, we can
> run into essentially the same bug with the following testcase:
> 
>   int m[20];
>   unsigned int c = 5;
>   int main ()
>   {
>     extern int m[];
>     unsigned int i = 0xFFFFFFFF, k, sum = 0;
> 
>     do {
> 	sum++;
>     } while (++i < c);
> 
>     printf ("%d\n", sum);
>   }
> 
> The "bogus iteration count" test is done incorrectly here as well: with
> doloop optimization, we exit after one iteration; without it we exit after
> six, which is correct.
> I'm currently thinking a better fix for both problems would be to do the
> "bogus iteration count test" slightly differently - increment or decrement
> the initial value as necessary, then do the comparison against the final
> value.

You are right, initial_value should be advanced by the increment before
the compare both in unroll.c (near line 979) and in doloop.c (in the
non-unroll case).  But it is still true that you do not want to do this
for != loops, so that patch in doloop.c is still necessary.  What you
refer above is a different bug, that was there before, and I certainly
did not notice that so I did not fix it.  The old code with signed
compare happened to work correctly here because of the overflow after the
first iteration.  If you use signed int and the loop goes from 0x7FFFFFFF
to -0x7FFFFFFB in the above example, the 3.0.1 release code will be
wrong too.

Zoli


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