The optimizer creates wrong code for the loop in the attached program. When compiled with -O2, the resulting code will generate a segfault. If the "double a" member of the struct is removed, the program will get stuck in an infinite loop, rather than crash. The program behaves correctly with gcc 3.2.2 and 3.3, so this is a regression. Release: 3.4 20030403 (experimental) Environment: System: SunOS scooby 5.9 Generic_112233-04 sun4u sparc SUNW,Sun-Blade-100 Architecture: sun4 host: sparc-sun-solaris2.9 build: sparc-sun-solaris2.9 target: sparc-sun-solaris2.9 configured with: /scratch/gcc-repository/cvs/gcc/configure --prefix=/opt/local/gcc340 --enable-languages=c,c++,f77 --with-gnu-as --with-as=/opt/local/bin/gas How-To-Repeat: scooby> gcc -v -O2 c.c Reading specs from /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/specs Configured with: /scratch/gcc-repository/cvs/gcc/configure --prefix=/opt/local/gcc340 --enable-languages=c,c++,f77 --with-gnu-as --with-as=/opt/local/bin/gas Thread model: posix gcc version 3.4 20030403 (experimental) /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/cc1 -quiet -v -Dsparc -D__sparc__ -D__sparc -D__GCC_NEW_VARARGS__ -Acpu=sparc -Amachine=sparc c.c -quiet -dumpbase c.c -auxbase c -O2 -version -o /var/tmp//ccXLgTFq.s ignoring nonexistent directory "/opt/local/gcc340/sparc-sun-solaris2.9/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /opt/local/gcc340/include /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/include /usr/include End of search list. GNU C version 3.4 20030403 (experimental) (sparc-sun-solaris2.9) compiled by GNU C version 3.4 20030403 (experimental). GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 /opt/local/bin/gas -V -Qy -s -o /var/tmp//ccOfg7jT.o /var/tmp//ccXLgTFq.s GNU assembler version 2.13.2.1 (sparc-sun-solaris2.9) using BFD version 2.13.2.1 /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/collect2 -V -Y P,/usr/ccs/lib:/usr/lib -Qy /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/crt1.o /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/crti.o /usr/ccs/lib/values-Xa.o /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/crtbegin.o -L/opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4 -L/usr/ccs/bin -L/usr/ccs/lib -L/opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/../../.. /var/tmp//ccOfg7jT.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh -lc /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/crtend.o /opt/local/gcc340/lib/gcc-lib/sparc-sun-solaris2.9/3.4/crtn.o ld: Software Generation Utilities - Solaris Link Editors: 5.9-1.373 scooby> a.out Segmentation fault scooby> cat c.c struct { double a; int n[2]; } g = { 0., { 1, 2 } }; int k = 0; void b(int *j) {} int main() { int j; for( j=0; j < 2; j++ ) k = ( k > g.n[j] ) ? k : g.n[j]; k++; b(&j); return 0; }
Fix: Workaround: use lower level of optimization.
State-Changed-From-To: open->feedback State-Changed-Why: Does passing -fno-gcse-sm cure the problem?
From: Peter van Hoof <p.van-hoof@qub.ac.uk> To: ebotcazou@gcc.gnu.org, gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org, p.van-hoof@qub.ac.uk, gcc-gnats@gcc.gnu.org Cc: Subject: Re: optimization/10312: optimizer creates wrong code for loop Date: Fri, 04 Apr 2003 20:08:39 +0100 > Does passing -fno-gcse-sm cure the problem? Yes, that cures the problem. http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10312 -- Peter van Hoof APS Division - Physics Department Queen's University of Belfast Belfast BT7 1NN Northern Ireland Home Page: http://star.pst.qub.ac.uk/~pvh
Responsible-Changed-From-To: unassigned->rakdver Responsible-Changed-Why: Your store motion rewrite.
State-Changed-From-To: feedback->analyzed State-Changed-Why: Confirmed as a store motion bug.
From: Eric Botcazou <ebotcazou@libertysurf.fr> To: Peter van Hoof <p.van-hoof@qub.ac.uk> Cc: gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org Subject: Re: optimization/10312: optimizer creates wrong code for loop Date: Sat, 5 Apr 2003 00:00:04 +0200 > > Does passing -fno-gcse-sm cure the problem? > > Yes, that cures the problem. Ok. The regression was detected this morning on Sparc through the failure of FAIL: gcc.dg/20030324-1.c execution test See http://gcc.gnu.org/ml/gcc-patches/2003-04/msg00254.html I'm going to assign the PR to Zdenek. Thanks for the quick feedback. -- Eric Botcazou
Zdenek, the audit trail of this bug seems to indicate that it is fixed and you applied patches. Can you confirm this an close the bug? regards Christian
Subject: Re: [3.4 regression] [sparc] optimizer creates wrong code for loop Hello, > the audit trail of this bug seems to indicate that it is fixed > and you applied patches. Can you confirm this an close the bug? the bugreport actually covers two different bugs. One of them (failure of gcc.dg/20030324-1.c on Sparc) was in fact a latent bug in the loop optimizer and this is fixed. The rest is indeed a bug in store motion, but the patch to fix it http://gcc.gnu.org/ml/gcc-patches/2003-04/msg00328.html was not approved yet. Zdenek
I can't reproduce the problem with gcc version 3.4 20031025 (experimental) but it may still be latent.
Independent of whether the bug can currently be reproduced, killing off invalid reg notes is clearly the right thing. I'll approve the patch at http://gcc.gnu.org/ml/gcc-patches/2003-04/msg00328.html provided that the test case at http://gcc.gnu.org/ml/gcc-patches/2003-04/msg00529.html is also applied at the same time (if it hasn't been already).
Zdenek, do you plan to do anything about this PR?
Subject: Re: [3.4 regression] optimizer creates wrong code for loop Hello, > Zdenek, do you plan to do anything about this PR? when Zack approves the patch to fix it as he mentioned, I may check the fix in. Zdenek
Did he not approve it already?
Subject: Re: [3.4 regression] optimizer creates wrong code for loop Hello, > Did he not approve it already? I may be wrong, but the only thing I have seen so far is the comment that 'I'll approve the patch...' in bugzilla, which I didn't consider an approval. Zdenek
What do you consider an approval then?
Subject: Re: [3.4 regression] optimizer creates wrong code for loop Hello, > What do you consider an approval then? a sentence in present tense (and preferably sent to gcc-patches list) would do for me. Zdenek
Let me rephrase: what do you think Zack's comment means exactly? Why did he wrote it?
Subject: Re: [3.4 regression] optimizer creates wrong code for loop Hello, > Let me rephrase: what do you think Zack's comment means exactly? Why did he > wrote it? I agree he could have ment it as an approval; let's wait till he either confirms it or not. Zdenek
Agreed. Zack, we need you for an exegesis :-)
Subject: Re: [3.4 regression] optimizer creates wrong code for loop "ebotcazou at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes: > Zack, we need you for an exegesis :-) My earlier message was meant as an approval. zw
Subject: Re: [3.4 regression] optimizer creates wrong code for loop Hello, > Zdenek, do you plan to do anything about this PR? seems that Jeff Law has already applied the patch some time ago: 2003-09-15 Zdenek Dvorak <rakdver@atrey.karlin.mff.cuni.cz> Jeff Law <law@redhat.com> * gcse.c (remove_reachable_equiv_notes): New. replace_store_insn): Call it. Update antic list. (store_killed_in_insn): Take REG_EQUAL notes into account. (build_store_vectors, delete_store): Add parameter to replace_store_insn call. which is probably the reason why it does not reproduce any more. I will close the bug. Zdenek
Patch (http://gcc.gnu.org/ml/gcc-patches/2003-04/msg00328.html) was commited.
Subject: Re: [3.4 regression] optimizer creates wrong code for loop Please make sure the test case got added to the testsuite. zw
Subject: Bug 10312 CVSROOT: /cvs/gcc Module name: gcc Changes by: rakdver@gcc.gnu.org 2003-12-15 09:37:03 Modified files: gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.c-torture/execute: 20031214-1.c Log message: PR optimization/10312 * gcc.c-torture/execute/20031214-1.c: New. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3252&r2=1.3253 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20031214-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1