Bug 10312 - [3.4 regression] optimizer creates wrong code for loop
Summary: [3.4 regression] optimizer creates wrong code for loop
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.4.0
: P3 critical
Target Milestone: 3.4.0
Assignee: Zdenek Dvorak
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2003-04-04 18:56 UTC by p.van-hoof
Modified: 2004-01-17 04:22 UTC (History)
4 users (show)

See Also:
Host: sparc-sun-solaris2.9
Target: sparc-sun-solaris2.9
Build: sparc-sun-solaris2.9
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 p.van-hoof 2003-04-04 18:56:00 UTC
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;
}
Comment 1 p.van-hoof 2003-04-04 18:56:00 UTC
Fix:
Workaround: use lower level of optimization.
Comment 2 Eric Botcazou 2003-04-04 19:03:28 UTC
State-Changed-From-To: open->feedback
State-Changed-Why: Does passing -fno-gcse-sm cure the problem?
Comment 3 p.van-hoof 2003-04-04 20:08:39 UTC
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
 
Comment 4 Eric Botcazou 2003-04-04 22:02:19 UTC
Responsible-Changed-From-To: unassigned->rakdver
Responsible-Changed-Why: Your store motion rewrite.
Comment 5 Eric Botcazou 2003-04-04 22:02:19 UTC
State-Changed-From-To: feedback->analyzed
State-Changed-Why: Confirmed as a store motion bug.
Comment 6 Eric Botcazou 2003-04-05 00:00:04 UTC
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
Comment 7 Christian Ehrhardt 2003-07-28 16:08:03 UTC
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

Comment 8 Zdenek Dvorak 2003-07-29 21:27:00 UTC
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
Comment 9 Eric Botcazou 2003-10-28 08:37:57 UTC
I can't reproduce the problem with gcc version 3.4 20031025 (experimental) but
it may still be latent.
Comment 10 Zack Weinberg 2003-12-02 00:20:36 UTC
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).
Comment 11 Eric Botcazou 2003-12-13 08:30:28 UTC
Zdenek, do you plan to do anything about this PR?
Comment 12 Zdenek Dvorak 2003-12-13 08:37:00 UTC
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
Comment 13 Eric Botcazou 2003-12-13 08:40:22 UTC
Did he not approve it already?
Comment 14 Zdenek Dvorak 2003-12-13 08:45:00 UTC
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
Comment 15 Eric Botcazou 2003-12-13 08:50:39 UTC
What do you consider an approval then?
Comment 16 Zdenek Dvorak 2003-12-13 08:59:57 UTC
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
Comment 17 Eric Botcazou 2003-12-13 09:04:37 UTC
Let me rephrase: what do you think Zack's comment means exactly? Why did he
wrote it?
Comment 18 Zdenek Dvorak 2003-12-13 09:06:35 UTC
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
Comment 19 Eric Botcazou 2003-12-13 09:13:36 UTC
Agreed.

Zack, we need you for an exegesis :-)
Comment 20 Zack Weinberg 2003-12-13 19:48:22 UTC
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
Comment 21 Zdenek Dvorak 2003-12-13 20:04:47 UTC
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
Comment 22 Zdenek Dvorak 2003-12-13 20:07:39 UTC
Patch (http://gcc.gnu.org/ml/gcc-patches/2003-04/msg00328.html) was
commited.
Comment 23 Zack Weinberg 2003-12-13 20:15:50 UTC
Subject: Re:  [3.4 regression] optimizer creates
 wrong code for loop


Please make sure the test case got added to the testsuite.

zw
Comment 24 GCC Commits 2003-12-15 09:37:09 UTC
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