Skip to content

Commit f5eacbe

Browse files
8371534: C2: Missed Ideal optimization opportunity with AndL and URShiftL
Reviewed-by: thartmann, mhaessig
1 parent bbeb6bf commit f5eacbe

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/hotspot/share/opto/phaseX.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,11 +2550,12 @@ void PhaseIterGVN::add_users_of_use_to_worklist(Node* n, Node* use, Unique_Node_
25502550
}
25512551
}
25522552
}
2553-
// If changed AndI/AndL inputs, check RShift users for "(x & mask) >> shift" optimization opportunity
2553+
// If changed AndI/AndL inputs, check RShift/URShift users for "(x & mask) >> shift" optimization opportunity
25542554
if (use_op == Op_AndI || use_op == Op_AndL) {
25552555
for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
25562556
Node* u = use->fast_out(i2);
2557-
if (u->Opcode() == Op_RShiftI || u->Opcode() == Op_RShiftL) {
2557+
if (u->Opcode() == Op_RShiftI || u->Opcode() == Op_RShiftL ||
2558+
u->Opcode() == Op_URShiftI || u->Opcode() == Op_URShiftL) {
25582559
worklist.push(u);
25592560
}
25602561
}

test/hotspot/jtreg/compiler/c2/TestMaskAndRShiftReorder.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323

2424
/*
2525
* @test
26-
* @bug 8361700
26+
* @bug 8361700 8371534
2727
* @summary An expression of the form "(x & mask) >> shift", where the mask
2828
* is a constant, should be transformed to "(x >> shift) & (mask >> shift)"
2929
* VerifyIterativeGVN checks that this optimization was applied
3030
* @run main/othervm -Xcomp -XX:+IgnoreUnrecognizedVMOptions
31-
* -XX:CompileCommand=compileonly,compiler.c2.TestMaskAndRShiftReorder::test
31+
* -XX:CompileCommand=compileonly,compiler.c2.TestMaskAndRShiftReorder::test*
3232
* -XX:VerifyIterativeGVN=1110 compiler.c2.TestMaskAndRShiftReorder
3333
* @run main compiler.c2.TestMaskAndRShiftReorder
3434
*
@@ -41,20 +41,45 @@ public class TestMaskAndRShiftReorder {
4141

4242

4343
public static void main(String[] strArr) {
44-
test();
44+
// No known reproducer with URShiftI so far
45+
testRShiftI();
46+
testRShiftL();
47+
testURShiftL();
4548
}
4649

47-
static long test() {
50+
static void testRShiftI() {
4851
int x = 10;
4952
int y = -17;
50-
int iArr[] = new int[10];
5153
for (int i = 1; i < 7; i++) {
5254
for (int j = 1; j < 2; j++) {
5355
x <<= lFld;
5456
}
5557
y &= x;
5658
y >>= 1;
5759
}
58-
return iArr.length;
60+
}
61+
62+
static void testRShiftL() {
63+
long x = 10;
64+
long y = -17L;
65+
for (int i = 1; i < 7; i++) {
66+
for (int j = 1; j < 2; j++) {
67+
x <<= lFld;
68+
}
69+
y &= x;
70+
y >>= 1;
71+
}
72+
}
73+
74+
static void testURShiftL() {
75+
long x = 10;
76+
long y = -17L;
77+
for (int i = 1; i < 7; i++) {
78+
for (int j = 1; j < 2; j++) {
79+
x <<= lFld;
80+
}
81+
y &= x;
82+
y >>>= 1;
83+
}
5984
}
6085
}

0 commit comments

Comments
 (0)