diff --git a/src/share/vm/opto/mulnode.cpp b/src/share/vm/opto/mulnode.cpp index b9dc06bb3690b0712e5c29590cc46b75199d8381..af62a5fae762ed7a6ef6d2a64c279fe6bbe368a3 100644 --- a/src/share/vm/opto/mulnode.cpp +++ b/src/share/vm/opto/mulnode.cpp @@ -608,16 +608,14 @@ Node *AndLNode::Ideal(PhaseGVN *phase, bool can_reshape) { } // Are we masking a long that was converted from an int with a mask - // that fits in 32-bits? Commute them and use an AndINode. - if (op == Op_ConvI2L && (mask & CONST64(0xFFFFFFFF00000000)) == 0) { - // If we are doing an UI2L conversion (i.e. the mask is - // 0x00000000FFFFFFFF) we cannot convert the AndL to an AndI - // because the AndI would be optimized away later in Identity. - if (mask != CONST64(0x00000000FFFFFFFF)) { - Node* andi = new (phase->C, 3) AndINode(in1->in(1), phase->intcon(mask)); - andi = phase->transform(andi); - return new (phase->C, 2) ConvI2LNode(andi); - } + // that fits in 32-bits? Commute them and use an AndINode. Don't + // convert masks which would cause a sign extension of the integer + // value. This check includes UI2L masks (0x00000000FFFFFFFF) which + // would be optimized away later in Identity. + if (op == Op_ConvI2L && (mask & CONST64(0xFFFFFFFF80000000)) == 0) { + Node* andi = new (phase->C, 3) AndINode(in1->in(1), phase->intcon(mask)); + andi = phase->transform(andi); + return new (phase->C, 2) ConvI2LNode(andi); } // Masking off sign bits? Dont make them! diff --git a/test/compiler/6863155/Test6863155.java b/test/compiler/6863155/Test6863155.java new file mode 100644 index 0000000000000000000000000000000000000000..b77090bff616ae3d66544abdada2138444328327 --- /dev/null +++ b/test/compiler/6863155/Test6863155.java @@ -0,0 +1,43 @@ +/* + * 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 6863155 + * @summary Server compiler generates incorrect code (x86, long, bitshift, bitmask) + * + * @run main/othervm -Xcomp -XX:CompileOnly=Test6863155.test Test6863155 + */ + +public class Test6863155 { + private static long test(byte b) { + return b << 24 & 0xff000000L; + } + + public static void main(String... args) { + long result = test((byte) 0xc2); + long expected = 0x00000000c2000000L; + if (result != expected) + throw new InternalError(Long.toHexString(result) + " != " + Long.toHexString(expected)); + } +}