Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/hotspot/share/opto/phaseX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2550,11 +2550,12 @@ void PhaseIterGVN::add_users_of_use_to_worklist(Node* n, Node* use, Unique_Node_
}
}
}
// If changed AndI/AndL inputs, check RShift users for "(x & mask) >> shift" optimization opportunity
// If changed AndI/AndL inputs, check RShift/URShift users for "(x & mask) >> shift" optimization opportunity
if (use_op == Op_AndI || use_op == Op_AndL) {
for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
Node* u = use->fast_out(i2);
if (u->Opcode() == Op_RShiftI || u->Opcode() == Op_RShiftL) {
if (u->Opcode() == Op_RShiftI || u->Opcode() == Op_RShiftL ||
u->Opcode() == Op_URShiftI || u->Opcode() == Op_URShiftL) {
worklist.push(u);
}
}
Expand Down
37 changes: 31 additions & 6 deletions test/hotspot/jtreg/compiler/c2/TestMaskAndRShiftReorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

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


public static void main(String[] strArr) {
test();
// No known reproducer with URShiftI so far
testRShiftI();
testRShiftL();
testURShiftL();
}

static long test() {
static void testRShiftI() {
int x = 10;
int y = -17;
int iArr[] = new int[10];
for (int i = 1; i < 7; i++) {
for (int j = 1; j < 2; j++) {
x <<= lFld;
}
y &= x;
y >>= 1;
}
return iArr.length;
}

static void testRShiftL() {
long x = 10;
long y = -17L;
for (int i = 1; i < 7; i++) {
for (int j = 1; j < 2; j++) {
x <<= lFld;
}
y &= x;
y >>= 1;
}
}

static void testURShiftL() {
long x = 10;
long y = -17L;
for (int i = 1; i < 7; i++) {
for (int j = 1; j < 2; j++) {
x <<= lFld;
}
y &= x;
y >>>= 1;
}
}
}