Bug 58731 - wrong code (hangs) at -O3 on x86_64-linux-gnu
Summary: wrong code (hangs) at -O3 on x86_64-linux-gnu
Status: RESOLVED DUPLICATE of bug 58143
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2013-10-15 01:24 UTC by Zhendong Su
Modified: 2013-10-15 08:16 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-10-15 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-10-15 01:24:13 UTC
The current gcc trunk and gcc 4.8 produce wrong code that hangs for the following testcase on x86_64-linux when compiled at -O3 (in both 32-bit and 64-bit modes). 

This is a regression from 4.7.x.

The testcase also triggers a different issue at -O2: a spurious "undefined behavior" warning (see below). 

$ 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 20131014 (experimental) [trunk revision 203572] (GCC) 
$ 
$ gcc-trunk -O2 small.c; a.out
small.c: In function ‘main’:
cc1: warning: iteration 5u invokes undefined behavior [-Waggressive-loop-optimizations]
small.c:6:3: note: containing loop
   for (b = 4; b > -30; b--)
   ^
$ 
$ gcc-trunk -Os small.c; a.out
$
$ gcc-trunk -O3 small.c; a.out
^C
$ gcc-4.8 -O3 small.c; a.out
^C
$
$ gcc-4.7 -O3 small.c; a.out
$  


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


int a, b, c, d, e;

int
main ()
{
  for (b = 4; b > -30; b--)
    for (; c;)
      for (;;)
	{
	  e = a > 2147483647 - b;
	  if (d)
	    break;
	}
  return 0;
}
Comment 1 Richard Biener 2013-10-15 08:13:25 UTC
int a, b, c, d, e;

int
main ()
{
  for (b = 4; b > -30; b--)
    for (; c;)
      for (;;)
	{
	  e = a > 2147483647 - b;

the issue here is that PRE (and LIM) move 2147483647 - b outside the
for (;c;) loop entry test and thus make it always execute in the
outermost loop, triggering the undefined behavior at iteration 5.
Also warns at -O1 with -fstrict-overflow.

PR58134 and PR58227 are related (if not dups).
Comment 2 Richard Biener 2013-10-15 08:16:59 UTC
Disabling LIM fixes this, disabling PRE not (and PRE alone is not enough to
trigger it - even though it clearly may).

*** This bug has been marked as a duplicate of bug 58143 ***