x86 failure on loop reversal

Joern Rennecke amylaar@cygnus.co.uk
Wed Apr 8 02:13:00 GMT 1998


> The existing test is (FOO >= 0).  Changing that to an unsigned test doesn't
> look very useful, as it will be always true.  I suggest we just avoid
> reversing the loop in this case.  This is rare enough, and tricky enough,
> that I don't think we need to handle it.
> 
> How about something like this?  If this is OK, I will add the testcase and
> check in the patch at the same time.
> 
> Mon Apr  6 20:08:43 1998  Jim Wilson  <wilson@cygnus.com>
> 
> 	* loop.c (check_dbra_loop): When normalize comparison_val, add check
> 	to verify it is non-negative.

Yes, this works.  I set out to do a more elaborate change that adds new
optimization, but it turned out to be somewhat more complex that I first
thought.  So it's probably best to install your bug fix first, then we
can talk about my optimization patch.

Here is a version of the testcase that avoids the -0x80000000 problem:

int
f()
{
  int j = 1;
  long i;
  for (i = -0x70000000L; i < 0x60000000L; i += 0x10000000L) j <<= 1;
  return j;
}

int
main ()
{
  if (f () != 8192)
    abort ();
  return 0;
}



More information about the Gcc mailing list