Bug 58277 - [4.7 Regression] wrong code at -O3
Summary: [4.7 Regression] wrong code at -O3
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 4.7.4
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-29 23:30 UTC by Zhendong Su
Modified: 2014-05-07 16:19 UTC (History)
2 users (show)

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


Attachments
testcase (554 bytes, text/x-c)
2013-08-29 23:31 UTC, Zhendong Su
Details
another testcase for both 32-bit and 64-bit modes (513 bytes, text/x-c)
2013-08-29 23:40 UTC, Zhendong Su
Details
gcc49-pr58277.patch (1.59 KB, patch)
2013-08-30 09:31 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zhendong Su 2013-08-29 23:30:25 UTC
The current gcc trunk (as well as gcc 4.7 and 4.8) produces wrong code for the attached testcase on x86_64-linux when compiled at -O3 in 32-bit mode. It is a regression from 4.6.x.  

This one has been quite nasty to reduce; the attached testcase is the simplest I was able to get. I believe it doesn't have any undefined behavior. 


$ 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 --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 20130829 (experimental) [trunk revision 202067] (GCC) 
$ gcc-trunk -m32 -O2 small.c
$ a.out
0
$ gcc-4.6 -m32 -O3 small.c
$ a.out
0
$ gcc-trunk -m32 -O3 small.c
$ a.out
0
Aborted (core dumped)
$ gcc-4.7 -m32 -O3 small.c
$ a.out
0
Aborted (core dumped)
$ gcc-4.8 -m32 -O3 small.c
$ a.out
0
Aborted (core dumped)
$
Comment 1 Zhendong Su 2013-08-29 23:31:25 UTC
Created attachment 30725 [details]
testcase
Comment 2 Zhendong Su 2013-08-29 23:39:51 UTC
I'm also attaching a related testcase (small2.c) for both 32-bit and 64-bit modes. 

$ gcc-trunk -m64 -O2 small2.c
$ a.out
$ gcc-4.6 -m64 -O3 small2.c
$ a.out
$ gcc-4.7 -m64 -O3 small2.c
$ a.out
Aborted (core dumped)
$ gcc-4.8 -m64 -O3 small2.c
$ a.out
Aborted (core dumped)
$ gcc-trunk -m64 -O3 small2.c
$ a.out
Aborted (core dumped)
$
Comment 3 Zhendong Su 2013-08-29 23:40:53 UTC
Created attachment 30726 [details]
another testcase for both 32-bit and 64-bit modes
Comment 4 Jakub Jelinek 2013-08-30 07:39:27 UTC
Both testcases started to fail with r181172.
Comment 5 Marek Polacek 2013-08-30 08:00:44 UTC
Thus confirmed.
Comment 6 Jakub Jelinek 2013-08-30 08:02:23 UTC
But, skimming through the dumps, it looks like it is the strlen pass that removes the important n = 0; store.
Comment 7 Jakub Jelinek 2013-08-30 09:31:03 UTC
Created attachment 30728 [details]
gcc49-pr58277.patch

Untested fix.
Comment 8 Jakub Jelinek 2013-08-30 12:41:19 UTC
Author: jakub
Date: Fri Aug 30 12:41:17 2013
New Revision: 202104

URL: http://gcc.gnu.org/viewcvs?rev=202104&root=gcc&view=rev
Log:
	PR tree-optimization/58277
	* tree-ssa-strlen.c (strlen_enter_block): If do_invalidate gave up
	after seeing too many stmts with vdef in between dombb and current
	bb, invalidate everything.

	* gcc.c-torture/execute/pr58277-1.c: New test.
	* gcc.c-torture/execute/pr58277-2.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr58277-1.c
    trunk/gcc/testsuite/gcc.c-torture/execute/pr58277-2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-strlen.c
Comment 9 Jakub Jelinek 2013-08-30 12:53:49 UTC
Author: jakub
Date: Fri Aug 30 12:53:47 2013
New Revision: 202105

URL: http://gcc.gnu.org/viewcvs?rev=202105&root=gcc&view=rev
Log:
	PR tree-optimization/58277
	* tree-ssa-strlen.c (strlen_enter_block): If do_invalidate gave up
	after seeing too many stmts with vdef in between dombb and current
	bb, invalidate everything.

	* gcc.c-torture/execute/pr58277-1.c: New test.
	* gcc.c-torture/execute/pr58277-2.c: New test.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/gcc.c-torture/execute/pr58277-1.c
    branches/gcc-4_8-branch/gcc/testsuite/gcc.c-torture/execute/pr58277-2.c
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_8-branch/gcc/tree-ssa-strlen.c
Comment 10 Jakub Jelinek 2013-08-30 12:58:48 UTC
Fixed for 4.8+ so far, thanks for reporting it.
Comment 11 Zhendong Su 2013-08-30 16:46:13 UTC
(In reply to Jakub Jelinek from comment #10)
> Fixed for 4.8+ so far, thanks for reporting it.

Thanks Jakub. Wow, that's quick! You folks are wonderful.
Comment 12 Jakub Jelinek 2014-05-07 16:01:56 UTC
Author: jakub
Date: Wed May  7 16:01:24 2014
New Revision: 210171

URL: http://gcc.gnu.org/viewcvs?rev=210171&root=gcc&view=rev
Log:
	Backported from mainline
	2013-08-30  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/58277
	* tree-ssa-strlen.c (strlen_enter_block): If do_invalidate gave up
	after seeing too many stmts with vdef in between dombb and current
	bb, invalidate everything.

	* gcc.c-torture/execute/pr58277-1.c: New test.
	* gcc.c-torture/execute/pr58277-2.c: New test.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/gcc.c-torture/execute/pr58277-1.c
    branches/gcc-4_7-branch/gcc/testsuite/gcc.c-torture/execute/pr58277-2.c
Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_7-branch/gcc/tree-ssa-strlen.c
Comment 13 Jakub Jelinek 2014-05-07 16:19:02 UTC
Fixed.