This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: optimization/10087: [3.3/3.4 regression] optimizer produces wrong code when indexing 2D array
- From: bangerth at dealii dot org
- To: gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org, p dot van-hoof at qub dot ac dot uk
- Date: 14 Mar 2003 23:45:18 -0000
- Subject: Re: optimization/10087: [3.3/3.4 regression] optimizer produces wrong code when indexing 2D array
- Reply-to: bangerth at dealii dot org, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org, p dot van-hoof at qub dot ac dot uk, gcc-gnats at gcc dot gnu dot org
Old Synopsis: optimizer produces wrong code when indexing malloc'ed 2D array
New Synopsis: [3.3/3.4 regression] optimizer produces wrong code when indexing 2D array
State-Changed-From-To: open->analyzed
State-Changed-By: bangerth
State-Changed-When: Fri Mar 14 23:45:17 2003
State-Changed-Why:
Confirmed also on x86 linux. Here's a slightly modified example:
--------------------------
void b(int*,int*);
typedef struct {
double T1;
char c;
} S;
int main(void)
{
int i,j;
double s;
S x1[2][2];
S *x[2] = { x1[0], x1[1] };
S **E = x;
for( i=0; i < 2; i++ )
for( j=0; j < 2; j++ )
E[j][i].T1 = 1;
for( i=0; i < 2; i++ )
for( j=0; j < 2; j++ )
s = E[j][i].T1;
b(&j,&i);
printf( "result %.6e\n", s);
return 0;
}
void b(int *i, int *j) {}
-------------------------------
This yields different results with and without -O2:
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/gcc x.c
g/x> ./a.out
result 1.000000e+00
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/gcc x.c -O2
g/x> ./a.out
result 2.171654e+00
The same holds for 3.3, but 3.2.2 is ok, so it's a regression.
W.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10087