Bug 59047 - [4.9 Regression] wrong code for bitfields at -O3 on x86_64-linux-gnu
Summary: [4.9 Regression] wrong code for bitfields at -O3 on x86_64-linux-gnu
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Richard Biener
URL:
Keywords: wrong-code
Depends on:
Blocks: 58653
  Show dependency treegraph
 
Reported: 2013-11-08 09:21 UTC by Zhendong Su
Modified: 2013-11-18 15:13 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 4.8.2
Known to fail: 4.9.0
Last reconfirmed: 2013-11-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zhendong Su 2013-11-08 09:21:05 UTC
The current gcc trunk miscompiles the following testcase on x86_64-linux-gnu at -O3 (in both 32-bit and 64-bit modes). 

This is a regression from 4.8.x.

$ 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 20131108 (experimental) [trunk revision 204560] (GCC) 
$ 
$ gcc-trunk -O2 small.c; a.out
1
$ gcc-4.8.2 -O3 small.c; a.out
1
$ 
$ gcc-trunk -O3 small.c; a.out
0
$ 


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


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

struct
{
  int f0;
  int f1:1;
  int f2:2;
} a = {0, 0, 1};

int b, c, *d, e, f;

int
fn1 ()
{
  for (; b < 1; ++b)
    {
      for (e = 0; e < 1; e = 1)
	{
	  int **g = &d;
	  *g = &c;
	} 
      *d = 0;
      f = a.f1;
      if (f)
	return 0;
    }
  return 0;
}

int
main ()
{
  fn1 ();
  printf ("%d\n", b);
  return 0;
}
Comment 1 Marek Polacek 2013-11-08 10:14:18 UTC
Confirmed.
Comment 2 Richard Biener 2013-11-08 10:27:11 UTC
Triggered by predictive commoning fix.  Mine.
Comment 3 Richard Biener 2013-11-08 12:49:13 UTC
Author: rguenth
Date: Fri Nov  8 12:49:10 2013
New Revision: 204566

URL: http://gcc.gnu.org/viewcvs?rev=204566&root=gcc&view=rev
Log:
2013-11-08  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/59047
	* tree-predcom.c (ref_at_iteration): Handle bitfield accesses
	properly.

	* gcc.dg/torture/pr59047.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr59047.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-predcom.c
Comment 4 Richard Biener 2013-11-08 12:49:30 UTC
Fixed.
Comment 5 Richard Biener 2013-11-18 15:13:17 UTC
Author: rguenth
Date: Mon Nov 18 15:13:14 2013
New Revision: 204965

URL: http://gcc.gnu.org/viewcvs?rev=204965&root=gcc&view=rev
Log:
2013-11-18  Richard Biener  <rguenther@suse.de>

	Backport from mainline
	2013-10-21  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/58794
	* fold-const.c (operand_equal_p): Compare FIELD_DECL operand
	of COMPONENT_REFs with OEP_CONSTANT_ADDRESS_OF left in place.

	* c-c++-common/torture/pr58794-1.c: New testcase.
	* c-c++-common/torture/pr58794-2.c: Likewise.

	2013-10-21  Richard Biener  <rguenther@suse.de>

	PR middle-end/58742
	* fold-const.c (fold_binary_loc): Fold ((T) (X /[ex] C)) * C
	to (T) X for sign-changing conversions (or no conversion).

	* c-c++-common/fold-divmul-1.c: New testcase.

	2013-11-06  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/58653
	* tree-predcom.c (ref_at_iteration): Rewrite to generate
	a MEM_REF.
	(prepare_initializers_chain): Adjust.

	* gcc.dg/tree-ssa/predcom-6.c: New testcase.
	* gcc.dg/tree-ssa/predcom-7.c: Likewise.

	PR tree-optimization/59047
	* tree-predcom.c (ref_at_iteration): Handle bitfield accesses
	properly.

	* gcc.dg/torture/pr59047.c: New testcase.

	2013-10-15  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/58143
	* tree-ssa-loop-im.c (arith_code_with_undefined_signed_overflow):
	New function.
	(rewrite_to_defined_overflow): Likewise.
	(move_computations_dom_walker::before_dom): Rewrite stmts
	with undefined signed overflow that are not always executed
	into unsigned arithmetic.

	* gcc.dg/torture/pr58143-1.c: New testcase.
	* gcc.dg/torture/pr58143-2.c: Likewise.
	* gcc.dg/torture/pr58143-3.c: Likewise.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/c-c++-common/fold-divmul-1.c
    branches/gcc-4_8-branch/gcc/testsuite/c-c++-common/torture/pr58794-1.c
    branches/gcc-4_8-branch/gcc/testsuite/c-c++-common/torture/pr58794-2.c
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/torture/pr58143-1.c
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/torture/pr58143-2.c
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/torture/pr58143-3.c
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/torture/pr59047.c
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/tree-ssa/predcom-6.c
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/tree-ssa/predcom-7.c
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/fold-const.c
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_8-branch/gcc/tree-predcom.c
    branches/gcc-4_8-branch/gcc/tree-ssa-loop-im.c