Thread model: win32 gcc version 4.0.0 20040913 (experimental) gcj --main=codes codes.java (works) gcj -O1 --main=codes codes.java (gives different results) class codes { static int[] lengths; static int[] codeValues; public static void main(String[] args) { lengths = new int[] {6,0,0,7,5,5,4,5,4,4,4,3,3,3,3,4,4,7,0}; codeValues = new int[lengths.length]; for (int i = 0; i < codeValues.length; i++) { codeValues[i] = i; } // Sort the values. Primary key is code size. Secondary key is value. for (int i = 0; i < lengths.length - 1; i++) { for (int j = i + 1; j < lengths.length; j++) { if (lengths[j] < lengths[i] || (lengths[j] == lengths[i] && codeValues[j] < codeValues[i])) { int tmp; tmp = lengths[j]; lengths[j] = lengths[i]; lengths[i] = tmp; tmp = codeValues[j]; codeValues[j] = codeValues[i]; codeValues[i] = tmp; } } } int[] codes = new int[lengths.length]; int lastLength = 0; int code = 0; for (int i = 0; i < lengths.length; i++) { while (lastLength != lengths[i]) { lastLength++; code <<= 1; System.out.println("SET CODE: " + code); } if (lastLength != 0) { codes[i] = code; System.out.println("(Should be equal) SET CODES[" + i + "] = " + code + " = " + codes[i]); code++; } } } }
These all look wrong: - T.235_214 = codes_85->data[i_910]; + codes_880 = T.291_849; + T.235_214 = *codes_880; - codes_85->data[i_910] = code_19; + T.287_876 = &codes_85->data[0]; + T.288_873 = (<unnamed type>) i_910; + T.289_856 = (int *) T.288_873; + T.290_851 = T.289_856 * 4B; + T.291_849 = T.290_851 + T.287_876; + codes_847 = T.291_849; + codes_847->length = code_298;
Confirmed, -fno-ivopts fixes the problem.
Assigning to Zdenek, as ivopts is his beast.
Patch: http://gcc.gnu.org/ml/gcc-patches/2004-09/msg01897.html
And one more patch: http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02591.html
Subject: Bug 17474 CVSROOT: /cvs/gcc Module name: gcc Changes by: rakdver@gcc.gnu.org 2004-09-25 11:06:46 Modified files: gcc : ChangeLog tree-ssa-ccp.c Log message: PR tree-optimization/17474 * tree-ssa-ccp.c (maybe_fold_offset_to_component_ref): Determine offset of the field correctly when DECL_FIELD_BIT_OFFSET != 0. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.5618&r2=2.5619 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-ssa-ccp.c.diff?cvsroot=gcc&r1=2.44&r2=2.45
One of the patches is in; the other one generated a lot of debate and is apparently not sufficient, so removing patch tag.
The testcase has already been fixed so closing.