Using gcc 4.0.1 : Using built-in specs. Target: i686-pc-linux-gnu Configured with: /data1/vondele/gcc-401/gcc/configure -- prefix=/data1/vondele/gcc-401/result --with-gmp-dir=/data1/vondele/gmp-4.1.4/ - -with-mpfr=/home/vondele/ --enable-languages=c,f95 Thread model: posix gcc version 4.0.1 The following program generates wrong results (-1 instead of 4 for the second number printed out) if compiled with -O. It works fine with gcc 3.3.4 and the portland group c compiler: #include <stdio.h> void sub(int *m) { int index, l, count; l = 2; for(count=2; count>0; count--, l++) { index = l*l+1; printf("%d\n", m[index-2*l]); m[index+1] = -1; } } int main(void) { int i, m[20]; for(i=0; i<20; i++) m[i] = i; sub(m); for(i=0; i<20; i++) printf("%d ", m[i]); putchar('\n'); } vondele> gcc test.c vondele> ./a.out 1 4 0 1 2 3 4 5 -1 7 8 9 10 -1 12 13 14 15 16 17 18 19 vondele> gcc -O test.c vondele> ./a.out 1 -1 0 1 2 3 4 5 -1 7 8 9 10 -1 12 13 14 15 16 17 18 19
This might already be fixed in 4.0.2.
Confirmed, smaller testcase: void abort (void); int main (void) { int j, a, b; for (j = 0; j < 2; j++) { a = j * j; b = a - 2 * j; } if (b != -1) abort (); return 0; } This bug fixed (or masked) on mainline by this patch: 2005-05-06 Zdenek Dvorak <dvorakz@suse.cz> PR tree-optimization/19401 * tree-flow.h (tree_unroll_loops_completely): Declaration changed. * tree-ssa-loop-ivcanon.c (enum unroll_level): New. ...
Mainline seems to be really fixed, even with complete loop unrolling disabled. 4.0.2 as of 20050728 is still affected by the bug (you can hide it there, too, with specifying -fpeel-loops, which enables complete unrolling). Must be a IVOPTs or scalar evolution problem (the latter got some fixes on the mainline).
GCC 4.0.2 (CVS) does this: ivcanon dump: # b_9 = PHI <b_3(1)>; <L2>:; if (b_9 != -1) goto <L3>; else goto <L4>; <L3>:; printf (&"%d\n"[0], b_9); abort (); .ivopts dump: # b_9 = PHI <b_3(1)>; <L2>:; if (b_9 != -1) goto <L3>; else goto <L4>; <L3>:; printf (&"%d\n"[0], b_9); abort (); Looks like final value replacement screws up.
Definitely IVopts.
Seems like a duplicate of PR22442 to me.
(In reply to comment #6) > Seems like a duplicate of PR22442 to me. Even if this is a dup, tescase from that bug does not fail on 4.0 and vice versa ;) Testcase from this bug still fails on 4.0 branch.
Subject: Re: [4.0 Regression] wrong results at -O on x86 > > Seems like a duplicate of PR22442 to me. > > Even if this is a dup, tescase from that bug does not fail on 4.0 and > vice versa ;) > Testcase from this bug still fails on 4.0 branch. The patch for PR22442 should fix the problem. The underlying problem seems to be the same, it just shows up in a different optimizer this time.
> The patch for PR22442 should fix the problem. has anybody updated this patch so far or can it be applied as is ?
Created attachment 10121 [details] patch for gcc-4_0-branch (same as in http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22442#c5) (In reply to comment #9) > > The patch for PR22442 should fix the problem. > > has anybody updated this patch so far or can it be applied as is ? just do: svn merge -r 101961:101962 svn://gcc.gnu.org/svn/gcc/trunk/gcc/tree-chrec.c gcc/tree-chrec.c in your working copy of gcc-4_0-branch (see detailed instructions how to use subversion here: http://gcc.gnu.org/wiki/SvnHelp ) Zdenek, please apply this patch to gcc-4_0-branch too.
> > svn merge -r 101961:101962 svn://gcc.gnu.org/svn/gcc/trunk/gcc/tree-chrec.c > gcc/tree-chrec.c > Yes, this fixes the problem for me (tested on _4_0_1_release). This really should be applied to the branch I think.
Zdenek, ping! Please apply patch for this bug to gcc-4_0-branch.
Still causing trouble with gcc version 4.0.3 20060103 (prerelease)
PING!!!
Subject: Bug 23282 Author: rakdver Date: Wed Jan 18 23:31:16 2006 New Revision: 109920 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109920 Log: PR tree-optimization/23282 * tree-chrec.c (chrec_fold_multiply_poly_poly): Associate chrecs correctly. PR tree-optimization/23282 * gcc.c-torture/execute/pr23282.c: New test. Added: branches/gcc-4_0-branch/gcc/testsuite/gcc.c-torture/execute/pr23282.c Modified: branches/gcc-4_0-branch/gcc/ChangeLog branches/gcc-4_0-branch/gcc/testsuite/ChangeLog branches/gcc-4_0-branch/gcc/tree-chrec.c
Fixed.