https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68730

            Bug ID: 68730
           Summary: wrong code at -O3 on x86_64-linux-gnu (in 32-bit mode)
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: su at cs dot ucdavis.edu
  Target Milestone: ---

The current gcc trunk miscompiles the following code on x86_64-linux-gnu at -O3
in the 32-bit mode (but not in the 64-bit mode). 

This is a regression from 5.3.x. 

-fno-tree-vrp makes the miscompilation disappear. 


$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk/configure --prefix=/usr/local/gcc-trunk
--enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
gcc version 6.0.0 20151204 (experimental) [trunk revision 231299] (GCC) 
$ 
$ gcc-trunk -m32 -O2 small.c; ./a.out
-28479
-28479
1
$ gcc-trunk -m64 -O3 small.c; ./a.out
-28479
-28479
1
$ gcc-5.3 -m32 -O3 small.c; ./a.out
-28479
-28479
1
$ 
$ gcc-trunk -m32 -O3 -fno-tree-vrp small.c; ./a.out
-28479
-28479
1
$ 
$ gcc-trunk -m32 -O3 small.c
$ timeout -s 9 10 ./a.out
-28479
-28479
-32319
Killed
$ 


---------------------------------------------------


int printf (const char *, ...);

int b, d, e;
unsigned long long c = 4100543410106915;

void
fn1 ()
{
  short f, g = 4 % c;
  int h = c;
  if (h)
    {
      int i = ~c;
      if (~c)
        i = 25662;
      f = g = i;
      h = c - g + ~-f;
      c = ~(c * h - f);
    }
  f = g;
  unsigned long long k = g || c;
  short l = c ^ g ^ k;
  if (g > 25662 || c == 74074520320 || !(g < 2))
    {
      k = c;
      l = g;
      c = ~((k && c) + ~l);
      f = ~(f * (c ^ k) | l);
      if (c > k)
        printf ("%d\n", f);
    }
  short m = -f;
  unsigned long long n = c;
  c = m * f | n % c;
  if (n)
    printf ("%d\n", f);
  while (f < -31807)
    ;
  c = ~(n | c) | f;
  if (n < c)
    printf ("%lld\n", (long long) f);
  for (; d;)
    for (; e;)
      for (;;)
        ;
  c = h;
  c = l % c;
}

int
main ()
{
  for (; b < 2; b++)
    fn1 ();
  return 0;
}

Reply via email to