Skip to content
Permalink
Browse files
8262025: [lworld] C2 should optimize acmp of the same inline type
Reviewed-by: dsimms
  • Loading branch information
TobiHartmann committed Feb 22, 2021
1 parent f421b93 commit 11cda281f3035eb576068f8549fed27b38773575
Showing 3 changed files with 73 additions and 0 deletions.
@@ -2176,6 +2176,12 @@ void Parse::do_acmp(BoolTest::mask btest, Node* left, Node* right) {
return;
}

// Check for equality before potentially allocating
if (left == right) {
do_if(btest, makecon(TypeInt::CC_EQ));
return;
}

// Allocate inline type operands and re-execute on deoptimization
if (left->is_InlineType()) {
PreserveReexecuteState preexecs(this);
@@ -3645,4 +3645,70 @@ public void test134_verifier(boolean warmup) {
// Expected
}
}

// Test that acmp of the same inline object is removed
@Test(failOn = ALLOC + LOAD + STORE + NULL_CHECK_TRAP + TRAP)
public static boolean test135() {
MyValue1 val = MyValue1.createWithFieldsInline(rI, rL);
return val == val;
}

@DontCompile
public void test135_verifier(boolean warmup) {
Asserts.assertTrue(test135());
}

// Same as test135 but with .ref
@Test(failOn = ALLOC + LOAD + STORE + NULL_CHECK_TRAP + TRAP)
public static boolean test136(boolean b) {
MyValue1.ref val = MyValue1.createWithFieldsInline(rI, rL);
if (b) {
val = null;
}
return val == val;
}

@DontCompile
public void test136_verifier(boolean warmup) {
Asserts.assertTrue(test136(false));
Asserts.assertTrue(test136(true));
}

static final primitive class SimpleInlineType {
final int x;
public SimpleInlineType(int x) {
this.x = x;
}
}

// Test that acmp of different inline objects with same content is removed
@Test(failOn = ALLOC + LOAD + STORE + NULL_CHECK_TRAP + TRAP)
public static boolean test137(int i) {
SimpleInlineType val1 = new SimpleInlineType(i);
SimpleInlineType val2 = new SimpleInlineType(i);
return val1 == val2;
}

@DontCompile
public void test137_verifier(boolean warmup) {
Asserts.assertTrue(test137(rI));
}

// Same as test137 but with .ref
@Test(failOn = ALLOC + LOAD + STORE + NULL_CHECK_TRAP + TRAP)
public static boolean test138(int i, boolean b) {
SimpleInlineType.ref val1 = new SimpleInlineType(i);
SimpleInlineType.ref val2 = new SimpleInlineType(i);
if (b) {
val1 = null;
val2 = null;
}
return val1 == val2;
}

@DontCompile
public void test138_verifier(boolean warmup) {
Asserts.assertTrue(test138(rI, false));
Asserts.assertTrue(test138(rI, true));
}
}
@@ -173,6 +173,7 @@ public void testAlot() {
if (a != b) throw new RuntimeException("Substitutability test failed" + a + " != " + b);
}
}
System.gc();
} while (ref.get() != null);
}

0 comments on commit 11cda28

Please sign in to comment.