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

             Bug #: 51987
           Summary: [4.7 Regression] Predictive commoning wrong-code with
                    non-volatile asm
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: ja...@gcc.gnu.org
        ReportedBy: ja...@gcc.gnu.org


On s390 (31-bit) gcc 4.7 miscompiles _itoa.o and _itoa.os in glibc (which leads
to e.g. cc1 itself when using that glibc to crash on startup).

Here is a reduced testcase (for x86_64):

extern void abort (void);
union U { unsigned long l; struct { unsigned int l, h; } i; };

__attribute__((noinline, noclone)) void
foo (char *x, char *y)
{
  int i;
  for (i = 0; i < 64; i++)
    {
      union U u;
      asm ("movl %1, %k0; salq $32, %0" : "=r" (u.l) : "r" (i));
      x[i] = u.i.h;
      union U v;
      asm ("movl %1, %k0; salq $32, %0" : "=r" (v.l) : "r" (i));
      y[i] = v.i.h;
    }
}

int
main ()
{
  char a[64], b[64];
  int i;
  foo (a, b);
  for (i = 0; i < 64; i++)
    if (a[i] != i || b[i] != i)
      abort ();
  return 0;
}

This is miscompiled at -O3, predictive commoning ignores the references in the
inline-asm and happily moves loads of u.i.h and v.i.h before the loop, even
when it is initialized only by the inline asm inside of the loop.

The problem is that tree-data-ref.c (get_references_in_stmt) gives up on
GIMPLE_ASM only if it is volatile, and for non-volatile GIMPLE_ASM it just
(incorrectly) assumes it doesn't have any references.

Reply via email to