Bug 58677 - wrong code at -O1 on x86_64-linux-gnu
Summary: wrong code at -O1 on x86_64-linux-gnu
Status: RESOLVED DUPLICATE of bug 58570
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-10 05:10 UTC by Zhendong Su
Modified: 2013-10-10 15:19 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zhendong Su 2013-10-10 05:10:19 UTC
The current gcc trunk miscompiles the attached testcase on x86_64-linux at (only) -O1 in 64-bit mode. 

This is a regression from 4.8.x.

This one was quite tough to reduce. The attached testcase is the best I was able to get so far. 


$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk/configure --enable-languages=c,c++,objc,obj-c++,fortran,lto --disable-werror --enable-checking=release --with-gmp=/usr/local/gcc-trunk --with-mpfr=/usr/local/gcc-trunk --with-mpc=/usr/local/gcc-trunk --with-cloog=/usr/local/gcc-trunk --prefix=/usr/local/gcc-trunk
Thread model: posix
gcc version 4.9.0 20131009 (experimental) [trunk revision 203302] (GCC) 
$ 
$ gcc-trunk -O0 small.c; a.out
0
0
1
$ gcc-4.8 -O1 small.c; a.out
0
0
1
$ gcc-trunk -m32 -O1 small.c; a.out
0
0
1
$ clang-trunk -O1 small.c; a.out
0
0
1
$ gcc-trunk -O1 small.c; a.out
0
0
0
$ 


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


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

#pragma pack(1)
struct S
{
  unsigned int f0:7;
  int f1:19;
  unsigned int f2:22;
  int f3:25;
} k[6][8];

int a, b, c, e, h, l, m, n, o, *p = &h, **q = &p, r, s;
unsigned int d[256];

static void
fn1 ()
{
  for (a = 0; a < 256; a++)
    d[a] = a;
}

static void
fn2 (unsigned int p1, char *p2, int p3)
{
  e = d[e ^ p1];
  printf ("%s%X\n", p2, e);
}

static int *
fn3 (int p1, int p2)
{
  for (s = 10; s > 2; s = -6)
    for (r = 0; r < 6; r++)
      for (n = 0; n < 8; n++)
	{
	  struct S t = { 1, -195, 321, 4857 };
	  k[r][n] = t;
	}
  return *q;
}

static int
fn4 ()
{
  *q = fn3 (l, b);
  return c;
}

int
main (int argc, char *argv[])
{
  int v = 0;
  if (argc == 2)
    v = 1;
  fn1 ();
  fn4 ();
  fn2 (m, "", v);
  fn2 (o, "", v);
  fn2 (k[0][0].f0, "", v);
  return 0;
}
Comment 1 Mikael Pettersson 2013-10-10 11:51:45 UTC
Started with r202525 (PR58404 missed-optimization fix), stopped with r203315 (PR58570 wrong-code fix).  The cause of PR58570 was not r202525.

Can you check if the original testcase works on current trunk?
Comment 2 Richard Biener 2013-10-10 12:02:23 UTC
(In reply to Mikael Pettersson from comment #1)
> Started with r202525 (PR58404 missed-optimization fix), stopped with r203315
> (PR58570 wrong-code fix).  The cause of PR58570 was not r202525.
> 
> Can you check if the original testcase works on current trunk?

But r202525 will expose more opportunities for the code with the bug
that was fixed by r203315 so it makes sense.

*** This bug has been marked as a duplicate of bug 58570 ***
Comment 3 Zhendong Su 2013-10-10 15:19:00 UTC
(In reply to Mikael Pettersson from comment #1)
> Started with r202525 (PR58404 missed-optimization fix), stopped with r203315
> (PR58570 wrong-code fix).  The cause of PR58570 was not r202525.
> 
> Can you check if the original testcase works on current trunk?

Just checked; it works. Thanks.