Skip to content
Permalink
Browse files
8262128: [lworld] C1's ValueNumbering optimization does not correctly…
… handle delayed accesses

Reviewed-by: fparain
  • Loading branch information
TobiHartmann committed Feb 23, 2021
1 parent 11cda28 commit 1c9a7a9a47093b5788a39141a72b414d2934227c
@@ -1016,7 +1016,7 @@ LEAF(LoadIndexed, AccessIndexed)
void set_delayed(DelayedLoadIndexed* delayed) { _delayed = delayed; }

// generic
HASHING4(LoadIndexed, !should_profile(), type()->tag(), array()->subst(), index()->subst(), vt())
HASHING4(LoadIndexed, delayed() == NULL && !should_profile(), type()->tag(), array()->subst(), index()->subst(), vt())
};

class DelayedLoadIndexed : public CompilationResourceObj {
@@ -1037,10 +1037,10 @@ class DelayedLoadIndexed : public CompilationResourceObj {
_offset += offset;
}

LoadIndexed* load_instr() { return _load_instr; }
ValueStack* state_before() { return _state_before; }
ciField* field() { return _field; }
int offset() { return _offset; }
LoadIndexed* load_instr() const { return _load_instr; }
ValueStack* state_before() const { return _state_before; }
ciField* field() const { return _field; }
int offset() const { return _offset; }
};

LEAF(StoreIndexed, AccessIndexed)
@@ -2301,9 +2301,7 @@ void LIRGenerator::do_LoadIndexed(LoadIndexed* x) {
} else if (x->delayed() != NULL) {
assert(x->array()->is_loaded_flattened_array(), "must be");
LIR_Opr result = rlock_result(x, x->delayed()->field()->type()->basic_type());
access_sub_element(array, index, result,
x->delayed() == NULL ? 0 : x->delayed()->field(),
x->delayed() == NULL ? 0 : x->delayed()->offset());
access_sub_element(array, index, result, x->delayed()->field(), x->delayed()->offset());
} else if (x->array() != NULL && x->array()->is_loaded_flattened_array() &&
x->array()->declared_type()->as_flat_array_klass()->element_klass()->as_inline_klass()->is_empty()) {
// Load the default instance instead of reading the element
@@ -23,7 +23,7 @@

/**
* @test
* @bug 8260034 8260225 8260283 8261037 8261874
* @bug 8260034 8260225 8260283 8261037 8261874 8262128
* @summary Generated inline type tests.
* @run main/othervm -Xbatch
* compiler.valhalla.inlinetypes.TestGenerated
@@ -48,6 +48,11 @@
int[] c = new int[5];
}

primitive class MyValue3 {
int[] intArray = new int[1];
float[] floatArray = new float[1];
}

public class TestGenerated {
EmptyValue f1 = new EmptyValue();
EmptyValue f2 = new EmptyValue();
@@ -136,11 +141,29 @@ void test9(boolean b) {
}
}

int[] f6 = new int[1];

void test10(MyValue3[] array) {
float[] floatArray = array[0].floatArray;
if (f6 == f6) {
f6 = array[0].intArray;
}
}

void test11(MyValue3[] array) {
float[] floatArray = array[0].floatArray;
if (array[0].intArray[0] != 42) {
throw new RuntimeException("test11 failed");
}
}

public static void main(String[] args) {
TestGenerated t = new TestGenerated();
EmptyValue[] array1 = { new EmptyValue() };
MyValue1[] array2 = new MyValue1[10];
MyValue1[] array3 = { new MyValue1() };
MyValue3[] array4 = { new MyValue3() };
array4[0].intArray[0] = 42;

for (int i = 0; i < 50_000; ++i) {
t.test1(array1);
@@ -152,6 +175,8 @@ public static void main(String[] args) {
t.test7(false);
t.test8(array3);
t.test9(true);
t.test10(array4);
t.test11(array4);
}
}
}

0 comments on commit 1c9a7a9

Please sign in to comment.