6795362: 32bit server compiler leads to wrong results on solaris-x86

Tue, 03 Feb 2009 01:39:12 -0800

author
twisti
date
Tue, 03 Feb 2009 01:39:12 -0800
changeset 994
7628781568e1
parent 993
3b5ac9e7e6ea
child 995
b79faa366fbd

6795362: 32bit server compiler leads to wrong results on solaris-x86
Summary: The C2 compiler leads to wrong results on solaris-i486 (32-bit) for a testcase given in the CR.
Reviewed-by: never, rasbold

src/share/vm/opto/mulnode.cpp file | annotate | diff | comparison | revisions
src/share/vm/utilities/globalDefinitions.hpp file | annotate | diff | comparison | revisions
test/compiler/6795362/Test6795362.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/opto/mulnode.cpp	Mon Jan 26 16:22:12 2009 +0100
     1.2 +++ b/src/share/vm/opto/mulnode.cpp	Tue Feb 03 01:39:12 2009 -0800
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * Copyright 1997-2009 Sun Microsystems, Inc.  All Rights Reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -449,9 +449,10 @@
    1.11      // needed either.
    1.12      if( lop == Op_URShiftI ) {
    1.13        const TypeInt *t12 = phase->type( load->in(2) )->isa_int();
    1.14 -      if( t12 && t12->is_con() ) {
    1.15 -        int shift_con = t12->get_con();
    1.16 -        int mask = max_juint >> shift_con;
    1.17 +      if( t12 && t12->is_con() ) {  // Shift is by a constant
    1.18 +        int shift = t12->get_con();
    1.19 +        shift &= BitsPerJavaInteger - 1;  // semantics of Java shifts
    1.20 +        int mask = max_juint >> shift;
    1.21          if( (mask&con) == mask )  // If AND is useless, skip it
    1.22            return load;
    1.23        }
    1.24 @@ -579,9 +580,10 @@
    1.25      // needed either.
    1.26      if( lop == Op_URShiftL ) {
    1.27        const TypeInt *t12 = phase->type( usr->in(2) )->isa_int();
    1.28 -      if( t12 && t12->is_con() ) {
    1.29 -        int shift_con = t12->get_con();
    1.30 -        jlong mask = max_julong >> shift_con;
    1.31 +      if( t12 && t12->is_con() ) {  // Shift is by a constant
    1.32 +        int shift = t12->get_con();
    1.33 +        shift &= BitsPerJavaLong - 1;  // semantics of Java shifts
    1.34 +        jlong mask = max_julong >> shift;
    1.35          if( (mask&con) == mask )  // If AND is useless, skip it
    1.36            return usr;
    1.37        }
    1.38 @@ -605,8 +607,8 @@
    1.39      const TypeInt *t12 = phase->type(rsh->in(2))->isa_int();
    1.40      if( t12 && t12->is_con() ) { // Shift is by a constant
    1.41        int shift = t12->get_con();
    1.42 -      shift &= (BitsPerJavaInteger*2)-1;  // semantics of Java shifts
    1.43 -      const jlong sign_bits_mask = ~(((jlong)CONST64(1) << (jlong)(BitsPerJavaInteger*2 - shift)) -1);
    1.44 +      shift &= BitsPerJavaLong - 1;  // semantics of Java shifts
    1.45 +      const jlong sign_bits_mask = ~(((jlong)CONST64(1) << (jlong)(BitsPerJavaLong - shift)) -1);
    1.46        // If the AND'ing of the 2 masks has no bits, then only original shifted
    1.47        // bits survive.  NO sign-extension bits survive the maskings.
    1.48        if( (sign_bits_mask & mask) == 0 ) {
    1.49 @@ -786,7 +788,7 @@
    1.50  
    1.51    // Check for ((x & ((CONST64(1)<<(64-c0))-1)) << c0) which ANDs off high bits
    1.52    // before shifting them away.
    1.53 -  const jlong bits_mask = ((jlong)CONST64(1) << (jlong)(BitsPerJavaInteger*2 - con)) - CONST64(1);
    1.54 +  const jlong bits_mask = ((jlong)CONST64(1) << (jlong)(BitsPerJavaLong - con)) - CONST64(1);
    1.55    if( add1_op == Op_AndL &&
    1.56        phase->type(add1->in(2)) == TypeLong::make( bits_mask ) )
    1.57      return new (phase->C, 3) LShiftLNode( add1->in(1), in(2) );
    1.58 @@ -820,7 +822,7 @@
    1.59      return TypeLong::LONG;
    1.60  
    1.61    uint shift = r2->get_con();
    1.62 -  shift &= (BitsPerJavaInteger*2)-1;  // semantics of Java shifts
    1.63 +  shift &= BitsPerJavaLong - 1;  // semantics of Java shifts
    1.64    // Shift by a multiple of 64 does nothing:
    1.65    if (shift == 0)  return t1;
    1.66  
    1.67 @@ -1235,7 +1237,7 @@
    1.68    if ( con == 0 ) return NULL;  // let Identity() handle a 0 shift count
    1.69                                // note: mask computation below does not work for 0 shift count
    1.70    // We'll be wanting the right-shift amount as a mask of that many bits
    1.71 -  const jlong mask = (((jlong)CONST64(1) << (jlong)(BitsPerJavaInteger*2 - con)) -1);
    1.72 +  const jlong mask = (((jlong)CONST64(1) << (jlong)(BitsPerJavaLong - con)) -1);
    1.73  
    1.74    // Check for ((x << z) + Y) >>> z.  Replace with x + con>>>z
    1.75    // The idiom for rounding to a power of 2 is "(Q+(2^z-1)) >>> z".
    1.76 @@ -1302,7 +1304,7 @@
    1.77  
    1.78    if (r2->is_con()) {
    1.79      uint shift = r2->get_con();
    1.80 -    shift &= (2*BitsPerJavaInteger)-1;  // semantics of Java shifts
    1.81 +    shift &= BitsPerJavaLong - 1;  // semantics of Java shifts
    1.82      // Shift by a multiple of 64 does nothing:
    1.83      if (shift == 0)  return t1;
    1.84      // Calculate reasonably aggressive bounds for the result.
    1.85 @@ -1325,7 +1327,7 @@
    1.86      const TypeLong* tl = TypeLong::make(lo, hi, MAX2(r1->_widen,r2->_widen));
    1.87      #ifdef ASSERT
    1.88      // Make sure we get the sign-capture idiom correct.
    1.89 -    if (shift == (2*BitsPerJavaInteger)-1) {
    1.90 +    if (shift == BitsPerJavaLong - 1) {
    1.91        if (r1->_lo >= 0) assert(tl == TypeLong::ZERO, ">>>63 of + is 0");
    1.92        if (r1->_hi < 0)  assert(tl == TypeLong::ONE,  ">>>63 of - is +1");
    1.93      }
     2.1 --- a/src/share/vm/utilities/globalDefinitions.hpp	Mon Jan 26 16:22:12 2009 +0100
     2.2 +++ b/src/share/vm/utilities/globalDefinitions.hpp	Tue Feb 03 01:39:12 2009 -0800
     2.3 @@ -1,5 +1,5 @@
     2.4  /*
     2.5 - * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
     2.6 + * Copyright 1997-2009 Sun Microsystems, Inc.  All Rights Reserved.
     2.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.8   *
     2.9   * This code is free software; you can redistribute it and/or modify it
    2.10 @@ -74,6 +74,7 @@
    2.11  extern int BitsPerHeapOop;
    2.12  
    2.13  const int BitsPerJavaInteger = 32;
    2.14 +const int BitsPerJavaLong    = 64;
    2.15  const int BitsPerSize_t      = size_tSize * BitsPerByte;
    2.16  
    2.17  // Size of a char[] needed to represent a jint as a string in decimal.
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/compiler/6795362/Test6795362.java	Tue Feb 03 01:39:12 2009 -0800
     3.3 @@ -0,0 +1,48 @@
     3.4 +/*
     3.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    3.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    3.24 + * have any questions.
    3.25 + */
    3.26 +
    3.27 +/**
    3.28 + * @test
    3.29 + * @bug 6795362
    3.30 + * @summary 32bit server compiler leads to wrong results on solaris-x86
    3.31 + *
    3.32 + * @run main/othervm -Xcomp -XX:CompileOnly=Test6795362.sub Test6795362
    3.33 + */
    3.34 +
    3.35 +public class Test6795362 {
    3.36 +    public static void main(String[] args)
    3.37 +    {
    3.38 +        sub();
    3.39 +
    3.40 +        if (var_bad != 0)
    3.41 +            throw new InternalError(var_bad + " != 0");
    3.42 +    }
    3.43 +
    3.44 +    static long var_bad = -1L;
    3.45 +
    3.46 +    static void sub()
    3.47 +    {
    3.48 +        var_bad >>= 65;
    3.49 +        var_bad /= 65;
    3.50 +    }
    3.51 +}

mercurial