public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* x86 failure on loop reversal
@ 1998-04-03 21:52 Joern Rennecke
  1998-04-08  2:13 ` Jim Wilson
  0 siblings, 1 reply; 8+ messages in thread
From: Joern Rennecke @ 1998-04-03 21:52 UTC (permalink / raw)
  To: Torbjorn Granlund, wilson, law; +Cc: egcs

The appended tests fails for egcs at -O2.  This is a synthetic test to
demonstrate a bug I found while looking for some possible improvements
to check_dbra_loop: when the initial value is normalized, an overflow
can occur.
I suggest that if we did a normalisation that results in a negative initial
value, we change the comparison into an unsigned one.
Actually, we could do this change always when we erverse the loop, and then
we could do away with the NONNEG note.  However, changing a signed compare
into an unsigned compare might fail sometimes (depending on how well we
can grok the RTL and what the target accepts), so it is better not to have
to rely on this.

int
f()
{
  int j = 1;
  int i;
  for (i = -0x80000000; i < 0x60000000; i += 0x10000000) j <<= 1;
  return j;
}

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

^ permalink raw reply	[flat|nested] 8+ messages in thread
* RE: x86 failure on loop reversal
@ 1998-04-06 17:35 Kaz Kylheku
  1998-04-06 15:25 ` Joern Rennecke
  0 siblings, 1 reply; 8+ messages in thread
From: Kaz Kylheku @ 1998-04-06 17:35 UTC (permalink / raw)
  To: 'Joern Rennecke', Torbjorn Granlund, wilson, law; +Cc: egcs

On Thursday, April 02, 1998 5:13 PM, Joern Rennecke 
[SMTP:amylaar@cygnus.co.uk] wrote:
> The appended tests fails for egcs at -O2.  This is a synthetic test to
> demonstrate a bug I found while looking for some possible improvements
> to check_dbra_loop: when the initial value is normalized, an overflow
> can occur.
> I suggest that if we did a normalisation that results in a negative initial
> value, we change the comparison into an unsigned one.
> Actually, we could do this change always when we erverse the loop, and then
> we could do away with the NONNEG note.  However, changing a signed compare
> into an unsigned compare might fail sometimes (depending on how well we
> can grok the RTL and what the target accepts), so it is better not to have
> to rely on this.
>
> int
> f()
> {
>   int j = 1;
>   int i;
>   for (i = -0x80000000; i < 0x60000000; i += 0x10000000) j <<= 1;
>   return j;
> }

Could you explain in more detail what you are trying to demonstrate?

Assuming 32 bit, two's complement longs, the constant 0x80000000 is simply out
of the range of the long type, which is -0x80000000 to 0x7FFFFFFF. The sign is
not part of the integral constant, what you have is an out-of-range positive 
constant
that is negated. I don't have my copy of the C standard handy today, but I 
would
guess that the effect of writing an out-of-range integral constant is 
undefined.

To create a constant expression which evaluates to the most negative long
value (assuming, again, 32 bit, two's complement), you must write:

	-0x7FFFFFFF - 1

This value has no additive inverse that is representable in a long, and so 
cannot
be formed by negating a positive constant.





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1998-04-08 13:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-03 21:52 x86 failure on loop reversal Joern Rennecke
1998-04-08  2:13 ` Jim Wilson
1998-04-08  2:13   ` Jeffrey A Law
1998-04-08  2:13   ` Joern Rennecke
1998-04-08  2:13     ` Jeffrey A Law
1998-04-08 13:11       ` Jim Wilson
1998-04-06 17:35 Kaz Kylheku
1998-04-06 15:25 ` Joern Rennecke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).