Bug 17474 - [4.0 Regression] Compiling at -01 yields different results
Summary: [4.0 Regression] Compiling at -01 yields different results
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Zdenek Dvorak
URL:
Keywords: wrong-code
Depends on:
Blocks: 18693
  Show dependency treegraph
 
Reported: 2004-09-14 05:48 UTC by Rutger Ovidius
Modified: 2004-12-05 21:02 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-09-15 03:41:02


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rutger Ovidius 2004-09-14 05:48:32 UTC
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++;
      }
    }

  }

}
Comment 1 Andrew Pinski 2004-09-14 06:07:08 UTC
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;
Comment 2 Andrew Pinski 2004-09-15 03:41:02 UTC
Confirmed, -fno-ivopts fixes the problem.
Comment 3 Giovanni Bajo 2004-09-17 01:49:59 UTC
Assigning to Zdenek, as ivopts is his beast.
Comment 4 Zdenek Dvorak 2004-09-19 21:53:43 UTC
Patch:

http://gcc.gnu.org/ml/gcc-patches/2004-09/msg01897.html
Comment 5 Zdenek Dvorak 2004-09-24 20:43:06 UTC
And one more patch:

http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02591.html
Comment 6 GCC Commits 2004-09-25 11:07:13 UTC
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

Comment 7 Nathanael C. Nerode 2004-11-27 02:14:23 UTC
One of the patches is in; the other one generated a lot of debate and is 
apparently not sufficient, so removing patch tag. 
Comment 8 Andrew Pinski 2004-12-05 21:02:28 UTC
The testcase has already been fixed so closing.