public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/53138] New: [4.7/4.8 Regression] spaceship operator miscompiled
@ 2012-04-27  9:27 bonzini at gnu dot org
  2012-04-27  9:30 ` [Bug target/53138] " bonzini at gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: bonzini at gnu dot org @ 2012-04-27  9:27 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53138

             Bug #: 53138
           Summary: [4.7/4.8 Regression] spaceship operator miscompiled
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: bonzini@gnu.org
        ReportedBy: bonzini@gnu.org
            Target: x86_64-pc-linux-gnu


This program is miscompiled at -O2:

typedef struct sreal
{
  unsigned sig;        /* Significant.  */
  int exp;        /* Exponent.  */
} sreal;

sreal_compare (sreal *a, sreal *b)
{
  if (a->exp > b->exp)
    return 1;
  if (a->exp < b->exp)
    return -1;
  if (a->sig > b->sig)
    return 1;
  return -(a->sig < b->sig);
}

sreal a[] = {
   { 0, 0 },
   { 1, 0 },
   { 0, 1 },
   { 1, 1 }
};

int main()
{
  int i, j;
  for (i = 0; i <= 3; i++) {
    for (j = 0; j < 3; j++) {
      if (i < j && sreal_compare(&a[i], &a[j]) != -1) abort();
      if (i == j && sreal_compare(&a[i], &a[j]) != 0) abort();
      if (i > j && sreal_compare(&a[i], &a[j]) != 1) abort();
    }
  }
}

The problem is that the comparison on sig is compiled to this:

    movl    (%rsi), %ecx
    cmpl    %ecx, (%rdi)
    sbbl    %edx, %edx
    cmovbe    %edx, %eax
    ret

but sbbl only preserves the carry flag, not the zero flag.


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

end of thread, other threads:[~2012-04-30 10:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-27  9:27 [Bug target/53138] New: [4.7/4.8 Regression] spaceship operator miscompiled bonzini at gnu dot org
2012-04-27  9:30 ` [Bug target/53138] " bonzini at gnu dot org
2012-04-27 10:41 ` rguenth at gcc dot gnu.org
2012-04-27 12:18 ` bonzini at gnu dot org
2012-04-30  8:58 ` [Bug target/53138] [4.7 " uros at gcc dot gnu.org
2012-04-30  9:56 ` uros at gcc dot gnu.org
2012-04-30 10:23 ` uros at gcc dot gnu.org
2012-04-30 10:27 ` ubizjak at gmail dot com

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).