Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit 4a85514

Browse files
committedDec 4, 2020
8257182: JCK test failures in integer / long rotation tests
Reviewed-by: mdoerr, vlivanov, thartmann, kvn
1 parent f33808f commit 4a85514

File tree

2 files changed

+94
-8
lines changed

2 files changed

+94
-8
lines changed
 

‎src/hotspot/share/opto/mulnode.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -1506,8 +1506,9 @@ const Type* RotateLeftNode::Value(PhaseGVN* phase) const {
15061506
return r1;
15071507
}
15081508
if (r1->is_con() && r2->is_con()) {
1509-
int shift = r2->get_con() & (BitsPerJavaInteger - 1); // semantics of Java shifts
1510-
return TypeInt::make((r1->get_con() << shift) | (r1->get_con() >> (32 - shift)));
1509+
juint r1_con = (juint)r1->get_con();
1510+
juint shift = (juint)(r2->get_con()) & (juint)(BitsPerJavaInteger - 1); // semantics of Java shifts
1511+
return TypeInt::make((r1_con << shift) | (r1_con >> (32 - shift)));
15111512
}
15121513
return TypeInt::INT;
15131514
} else {
@@ -1524,8 +1525,9 @@ const Type* RotateLeftNode::Value(PhaseGVN* phase) const {
15241525
return r1;
15251526
}
15261527
if (r1->is_con() && r2->is_con()) {
1527-
int shift = r2->get_con() & (BitsPerJavaLong - 1); // semantics of Java shifts
1528-
return TypeLong::make((r1->get_con() << shift) | (r1->get_con() >> (64 - shift)));
1528+
julong r1_con = (julong)r1->get_con();
1529+
julong shift = (julong)(r2->get_con()) & (julong)(BitsPerJavaLong - 1); // semantics of Java shifts
1530+
return TypeLong::make((r1_con << shift) | (r1_con >> (64 - shift)));
15291531
}
15301532
return TypeLong::LONG;
15311533
}
@@ -1583,8 +1585,9 @@ const Type* RotateRightNode::Value(PhaseGVN* phase) const {
15831585
return r1;
15841586
}
15851587
if (r1->is_con() && r2->is_con()) {
1586-
int shift = r2->get_con() & (BitsPerJavaInteger - 1); // semantics of Java shifts
1587-
return TypeInt::make((r1->get_con() >> shift) | (r1->get_con() << (32 - shift)));
1588+
juint r1_con = (juint)r1->get_con();
1589+
juint shift = (juint)(r2->get_con()) & (juint)(BitsPerJavaInteger - 1); // semantics of Java shifts
1590+
return TypeInt::make((r1_con >> shift) | (r1_con << (32 - shift)));
15881591
}
15891592
return TypeInt::INT;
15901593
} else {
@@ -1600,8 +1603,9 @@ const Type* RotateRightNode::Value(PhaseGVN* phase) const {
16001603
return r1;
16011604
}
16021605
if (r1->is_con() && r2->is_con()) {
1603-
int shift = r2->get_con() & (BitsPerJavaLong - 1); // semantics of Java shifts
1604-
return TypeLong::make((r1->get_con() >> shift) | (r1->get_con() << (64 - shift)));
1606+
julong r1_con = (julong)r1->get_con();
1607+
julong shift = (julong)(r2->get_con()) & (julong)(BitsPerJavaLong - 1); // semantics of Java shifts
1608+
return TypeLong::make((r1_con >> shift) | (r1_con << (64 - shift)));
16051609
}
16061610
return TypeLong::LONG;
16071611
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8257182
27+
* @requires vm.compiler2.enabled
28+
* @summary Test RotateLeftNode and RotateRightNode with negative even numbers which produces a wrong result due to
29+
* applying an arithemtic instead of a logical shift.
30+
* @run main/othervm -XX:CompileCommand=compileonly,compiler.c2.TestRotateNegativeEvenValues::run
31+
* -XX:CompileCommand=inline,compiler.c2.TestRotateNegativeEvenValues::test
32+
* -Xcomp -XX:-TieredCompilation compiler.c2.TestRotateNegativeEvenValues
33+
*/
34+
package compiler.c2;
35+
36+
public class TestRotateNegativeEvenValues {
37+
38+
public static void run() {
39+
test(1 << 31); // INT_MIN
40+
test(1L << 63); // LONG_MIN
41+
test(-1 << 10); // -1024
42+
test(-1L << 10); // -1024
43+
test(-1 << 20); // -1048576
44+
test(-1L << 20); // -1048576
45+
test(-2); // 111...10
46+
test(-2L); // 111...10
47+
test(-3546); // Random minus even number
48+
test(-3546L); // Random minus even number
49+
}
50+
51+
// Inlined such that negativeEvenNumber is a constant
52+
public static void test(int negativeEvenNumber) {
53+
for (int i = 1; i <= 1; i++) {
54+
int leftShift = negativeEvenNumber << -i;
55+
int rightShift = negativeEvenNumber >>> i;
56+
if ((leftShift | rightShift) != (rightShift | leftShift)) {
57+
int or1 = leftShift | rightShift;
58+
int or2 = rightShift | leftShift;
59+
throw new RuntimeException("Or operations are not equal:" + " " + or1 + " vs. "+ or2
60+
+ " - leftShift: " + leftShift + ", rightShift: " + rightShift);
61+
}
62+
}
63+
}
64+
65+
// Inlined such that negativeEvenNumber is a constant
66+
public static void test(long negativeEvenNumber) {
67+
for (int i = 1; i <= 1; i++) {
68+
long leftShift = negativeEvenNumber << -i;
69+
long rightShift = negativeEvenNumber >>> i;
70+
if ((leftShift | rightShift) != (rightShift | leftShift)) {
71+
long or1 = leftShift | rightShift;
72+
long or2 = rightShift | leftShift;
73+
throw new RuntimeException("Or operations are not equal:" + " " + or1 + " vs. "+ or2
74+
+ " - leftShift: " + leftShift + ", rightShift: " + rightShift);
75+
}
76+
}
77+
}
78+
79+
public static void main(String argv[]) {
80+
run();
81+
}
82+
}

0 commit comments

Comments
 (0)
This repository has been archived.