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 wrongcode when indexing 2D array
- From: Steven Bosscher <s dot bosscher at student dot tudelft dot nl>
- To: p dot van-hoof at qub dot ac dot uk, gcc-gnats at gcc dot gnu dot org,gcc-bugs at gcc dot gnu dot org, nobody at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org
- Date: Sat, 15 Mar 2003 01:48:02 +0100
- Subject: Re: optimization/10087: [3.3/3.4 regression] optimizer produces wrongcode when indexing 2D array
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10087
A little more information...
A slightly smaller test case is:
----------------------------
static void
b (int *i, int *j)
{
}
int
main (void)
{
int i, j;
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;
b (&j, &i);
printf ("result %.6e\n", E[1][1].T1);
return 0;
}
----------------------------
The line "E[j][i] =..." seems to be the problem:
With j first, then i, the output is wrong (and you get a segfault as a
bonus).
With i first, then j ("E[i][j]=..") you get the correct result.
# gcc-3.3 -O t.c
# a.out
result 1.000000e+00
# gcc-3.3 t.c -O -fstrength-reduce -fstrict-aliasing -fforce-mem -fgcse
# a.out
result 2.676500e+00
Segmentation fault
Again, disable any of these four options and you get the expected output.
(For the record, this is on i586-pc-linux-gnu.)
Greetz
Steven