# HG changeset patch # User twisti # Date 1233653952 28800 # Node ID b7549fd4792ef8aaa6d6bc02e3dfb2e845cff23d # Parent fc6a5ae3fef5ebacfa896dbb3ae37715e388e282 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 diff -r fc6a5ae3fef5 -r b7549fd4792e src/share/vm/opto/mulnode.cpp --- a/src/share/vm/opto/mulnode.cpp Sat Dec 20 09:59:01 2008 -0800 +++ b/src/share/vm/opto/mulnode.cpp Tue Feb 03 01:39:12 2009 -0800 @@ -1,5 +1,5 @@ /* - * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -449,9 +449,10 @@ // needed either. if( lop == Op_URShiftI ) { const TypeInt *t12 = phase->type( load->in(2) )->isa_int(); - if( t12 && t12->is_con() ) { - int shift_con = t12->get_con(); - int mask = max_juint >> shift_con; + if( t12 && t12->is_con() ) { // Shift is by a constant + int shift = t12->get_con(); + shift &= BitsPerJavaInteger - 1; // semantics of Java shifts + int mask = max_juint >> shift; if( (mask&con) == mask ) // If AND is useless, skip it return load; } @@ -579,9 +580,10 @@ // needed either. if( lop == Op_URShiftL ) { const TypeInt *t12 = phase->type( usr->in(2) )->isa_int(); - if( t12 && t12->is_con() ) { - int shift_con = t12->get_con(); - jlong mask = max_julong >> shift_con; + if( t12 && t12->is_con() ) { // Shift is by a constant + int shift = t12->get_con(); + shift &= BitsPerJavaLong - 1; // semantics of Java shifts + jlong mask = max_julong >> shift; if( (mask&con) == mask ) // If AND is useless, skip it return usr; } @@ -605,8 +607,8 @@ const TypeInt *t12 = phase->type(rsh->in(2))->isa_int(); if( t12 && t12->is_con() ) { // Shift is by a constant int shift = t12->get_con(); - shift &= (BitsPerJavaInteger*2)-1; // semantics of Java shifts - const jlong sign_bits_mask = ~(((jlong)CONST64(1) << (jlong)(BitsPerJavaInteger*2 - shift)) -1); + shift &= BitsPerJavaLong - 1; // semantics of Java shifts + const jlong sign_bits_mask = ~(((jlong)CONST64(1) << (jlong)(BitsPerJavaLong - shift)) -1); // If the AND'ing of the 2 masks has no bits, then only original shifted // bits survive. NO sign-extension bits survive the maskings. if( (sign_bits_mask & mask) == 0 ) { @@ -786,7 +788,7 @@ // Check for ((x & ((CONST64(1)<<(64-c0))-1)) << c0) which ANDs off high bits // before shifting them away. - const jlong bits_mask = ((jlong)CONST64(1) << (jlong)(BitsPerJavaInteger*2 - con)) - CONST64(1); + const jlong bits_mask = ((jlong)CONST64(1) << (jlong)(BitsPerJavaLong - con)) - CONST64(1); if( add1_op == Op_AndL && phase->type(add1->in(2)) == TypeLong::make( bits_mask ) ) return new (phase->C, 3) LShiftLNode( add1->in(1), in(2) ); @@ -820,7 +822,7 @@ return TypeLong::LONG; uint shift = r2->get_con(); - shift &= (BitsPerJavaInteger*2)-1; // semantics of Java shifts + shift &= BitsPerJavaLong - 1; // semantics of Java shifts // Shift by a multiple of 64 does nothing: if (shift == 0) return t1; @@ -1235,7 +1237,7 @@ if ( con == 0 ) return NULL; // let Identity() handle a 0 shift count // note: mask computation below does not work for 0 shift count // We'll be wanting the right-shift amount as a mask of that many bits - const jlong mask = (((jlong)CONST64(1) << (jlong)(BitsPerJavaInteger*2 - con)) -1); + const jlong mask = (((jlong)CONST64(1) << (jlong)(BitsPerJavaLong - con)) -1); // Check for ((x << z) + Y) >>> z. Replace with x + con>>>z // The idiom for rounding to a power of 2 is "(Q+(2^z-1)) >>> z". @@ -1302,7 +1304,7 @@ if (r2->is_con()) { uint shift = r2->get_con(); - shift &= (2*BitsPerJavaInteger)-1; // semantics of Java shifts + shift &= BitsPerJavaLong - 1; // semantics of Java shifts // Shift by a multiple of 64 does nothing: if (shift == 0) return t1; // Calculate reasonably aggressive bounds for the result. @@ -1325,7 +1327,7 @@ const TypeLong* tl = TypeLong::make(lo, hi, MAX2(r1->_widen,r2->_widen)); #ifdef ASSERT // Make sure we get the sign-capture idiom correct. - if (shift == (2*BitsPerJavaInteger)-1) { + if (shift == BitsPerJavaLong - 1) { if (r1->_lo >= 0) assert(tl == TypeLong::ZERO, ">>>63 of + is 0"); if (r1->_hi < 0) assert(tl == TypeLong::ONE, ">>>63 of - is +1"); } diff -r fc6a5ae3fef5 -r b7549fd4792e src/share/vm/utilities/globalDefinitions.hpp --- a/src/share/vm/utilities/globalDefinitions.hpp Sat Dec 20 09:59:01 2008 -0800 +++ b/src/share/vm/utilities/globalDefinitions.hpp Tue Feb 03 01:39:12 2009 -0800 @@ -1,5 +1,5 @@ /* - * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -74,6 +74,7 @@ extern int BitsPerHeapOop; const int BitsPerJavaInteger = 32; +const int BitsPerJavaLong = 64; const int BitsPerSize_t = size_tSize * BitsPerByte; // Size of a char[] needed to represent a jint as a string in decimal. diff -r fc6a5ae3fef5 -r b7549fd4792e test/compiler/6795362/Test6795362.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/compiler/6795362/Test6795362.java Tue Feb 03 01:39:12 2009 -0800 @@ -0,0 +1,48 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6795362 + * @summary 32bit server compiler leads to wrong results on solaris-x86 + * + * @run main/othervm -Xcomp -XX:CompileOnly=Test6795362.sub Test6795362 + */ + +public class Test6795362 { + public static void main(String[] args) + { + sub(); + + if (var_bad != 0) + throw new InternalError(var_bad + " != 0"); + } + + static long var_bad = -1L; + + static void sub() + { + var_bad >>= 65; + var_bad /= 65; + } +}