Bug 12340 - [3.3 regression] loop unroller + gcse produces wrong code
Summary: [3.3 regression] loop unroller + gcse produces wrong code
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.3.2
: P1 critical
Target Milestone: 3.3.2
Assignee: Eric Botcazou
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2003-09-19 15:10 UTC by Richard Biener
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
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 Richard Biener 2003-09-19 15:10:42 UTC
If compiling with -O2 -fno-exceptions -funroll-loops the testcase segfaults in a
destructor, with -fno-gcse added or -funroll-loops removed, the testcase is
fine. This problem does not appear on gcc 3.2.3 or gcc 3.4 with either
-funroll-loops or -fold-unroll-loops.

Testcase is available from

http://www.tat.physik.uni-tuebingen.de/~rguenth/gcc/brick_test1.bug.ii.gz

gcc-3.3 version tested is

g++-3.3 (GCC) 3.3.2 20030919 (prerelease)

Richard.
Comment 1 Eric Botcazou 2003-09-22 06:03:07 UTC
Any chance that you could shrink down the 50000-line testcase? Trying to do it
without knowing the code is a bit painful.
Comment 2 Richard Biener 2003-09-22 08:01:58 UTC
Subject: Re:  [3.3 regression] loop unroller + gcse
 produces wrong code

On 22 Sep 2003, ebotcazou at gcc dot gnu dot org wrote:

> ------- Additional Comments From ebotcazou at gcc dot gnu dot org  2003-09-22 06:03 -------
> Any chance that you could shrink down the 50000-line testcase? Trying to do it
> without knowing the code is a bit painful.

The testcase is

#include "Domain/Interval.h"
#include "Engine/BrickEngine.h"

#include "../../Engine/BrickBase.cpp"
#include "../../Utilities/Unique.cmpl.cpp"

namespace Pooma {
   int myContext_g;
}

typedef Engine<1,double,Brick>         Array_t;

int main(int argc, char *argv[])
{
    Interval<1> I(10);
    Array_t A(I);
    for (int i = 0; i < 10; i++)
      A(Loc<1>(i)) = 2.0 + i - i*i;
    return 0;
}

unfortunately, this pulls in nearly all of the POOMA library (although
most of it is unused, of course). Sadly delta is not very good/fast at
reducing C++ testcases. Maybe the tree-ssa pretty-printer can output
only the used parts? Or maybe you can assist me in reducing such C++
testcases (aka stripping unused parts of the code).

After all, the assembly file of the testcase is only 11k big and it seems
to be a problem with the destructor handling? But I can't see anything
obvious either.

Richard.

--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/

Comment 3 Eric Botcazou 2003-09-22 15:14:34 UTC
Is it mandatory to include the two *.cpp files? Can you break them apart and
include only the necessary bits?
Comment 4 Eric Botcazou 2003-09-22 15:17:09 UTC
The loop optimizer thinks the loop in main() is executed 6 times!!! I'm going to
teach it how to count :-)
Comment 5 Richard Biener 2003-09-22 15:25:16 UTC
Subject: Re:  [3.3 regression] loop unroller + gcse
 produces wrong code

On 22 Sep 2003, ebotcazou at gcc dot gnu dot org wrote:

> The loop optimizer thinks the loop in main() is executed 6 times!!! I'm going to
> teach it how to count :-)

I cannot see how this then should produce a SIGSEGV at destruction time,
but if it is true, then its worth to fix for sure ;)

Richard.

--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/

Comment 6 Eric Botcazou 2003-09-22 16:37:04 UTC
This fools the loop unroller, which produces code that overwrites some fields of
the object on the stack.
Comment 7 CVS Commits 2003-09-27 17:18:33 UTC
Subject: Bug 12340

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ebotcazou@gcc.gnu.org	2003-09-27 17:18:25

Modified files:
	gcc            : ChangeLog loop.h unroll.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/opt: unroll1.C 

Log message:
	PR optimization/12340
	* loop.h (struct induction): Document the new semantics
	of the 'same' field for bivs.
	* unroll.c (biv_total_increment): Don't count the same
	biv increment several times.
	(loop_iterations) [GENERAL_INDUCT]: Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.1196&r2=2.1197
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/loop.h.diff?cvsroot=gcc&r1=1.68&r2=1.69
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/unroll.c.diff?cvsroot=gcc&r1=1.202&r2=1.203
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3082&r2=1.3083
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/unroll1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 8 CVS Commits 2003-09-27 17:23:26 UTC
Subject: Bug 12340

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	ebotcazou@gcc.gnu.org	2003-09-27 17:23:23

Modified files:
	gcc            : ChangeLog loop.h unroll.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/opt: unroll1.C 

Log message:
	PR optimization/12340
	* loop.h (struct induction): Document the new semantics
	of the 'same' field for bivs.
	* unroll.c (biv_total_increment): Don't count the same
	biv increment several times.
	(loop_iterations) [GENERAL_INDUCT]: Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.755&r2=1.16114.2.756
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/loop.h.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.65&r2=1.65.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/unroll.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.184.2.5&r2=1.184.2.6
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.288&r2=1.2261.2.289
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/unroll1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1

Comment 9 Eric Botcazou 2003-09-27 17:26:07 UTC
See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg01649.html