optimization/10087: [3.3/3.4 regression] optimizer produces wrong code when indexing 2D array
Steven Bosscher
s.bosscher@student.tudelft.nl
Sat Mar 15 01:55:00 GMT 2003
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
More information about the Gcc-bugs
mailing list