From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24255 invoked by alias); 15 Mar 2003 00:56:00 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 24232 invoked by uid 71); 15 Mar 2003 00:56:00 -0000 Date: Sat, 15 Mar 2003 00:56:00 -0000 Message-ID: <20030315005600.24229.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Steven Bosscher Subject: Re: optimization/10087: [3.3/3.4 regression] optimizer produces wrong code when indexing 2D array Reply-To: Steven Bosscher X-SW-Source: 2003-03/txt/msg00921.txt.bz2 List-Id: The following reply was made to PR optimization/10087; it has been noted by GNATS. From: Steven Bosscher To: p.van-hoof@qub.ac.uk, gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-prs@gcc.gnu.org Cc: Subject: Re: optimization/10087: [3.3/3.4 regression] optimizer produces wrong code when indexing 2D array Date: Sat, 15 Mar 2003 01:48:02 +0100 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