--- old/src/hotspot/share/c1/c1_LIRGenerator.cpp 2019-02-18 07:28:18.695644232 -0800 +++ new/src/hotspot/share/c1/c1_LIRGenerator.cpp 2019-02-18 07:28:18.471636278 -0800 @@ -1648,6 +1648,18 @@ } } +bool LIRGenerator::needs_flattened_array_check(Value array, Value value) { + if (array->maybe_flattened_array()) { + return true; + } + if (array->as_Phi() != NULL && value->type()->is_object()) { + // Type info gets lost during Phi merging, but we might be storing into a + // flattened array, so we'd better check. + return true; + } + return false; +} + void LIRGenerator::check_flattened_array(LIRItem& array, CodeStub* slow_path) { LIR_Opr array_klass_reg = new_register(T_METADATA); @@ -1684,7 +1696,7 @@ } if (needs_store_check || x->check_boolean() - || is_loaded_flattened_array || x->array()->maybe_flattened_array()) { + || is_loaded_flattened_array || needs_flattened_array_check(x->array(), x->value())) { value.load_item(); } else { value.load_for_store(x->elt_type()); @@ -1729,7 +1741,7 @@ } else { StoreFlattenedArrayStub* slow_path = NULL; - if (x->array()->maybe_flattened_array()) { + if (needs_flattened_array_check(x->array(), x->value())) { // Check if we indeed have a flattened array index.load_item(); slow_path = new StoreFlattenedArrayStub(array.result(), index.result(), value.result(), state_for(x)); @@ -2046,7 +2058,7 @@ LIR_Opr result = rlock_result(x, x->elt_type()); LoadFlattenedArrayStub* slow_path = NULL; - if (x->array()->maybe_flattened_array()) { + if (needs_flattened_array_check(x->array(), x)) { index.load_item(); // Check if we indeed have a flattened array slow_path = new LoadFlattenedArrayStub(array.result(), index.result(), result, state_for(x)); --- old/src/hotspot/share/c1/c1_LIRGenerator.hpp 2019-02-18 07:28:19.351667526 -0800 +++ new/src/hotspot/share/c1/c1_LIRGenerator.hpp 2019-02-18 07:28:19.127659572 -0800 @@ -267,6 +267,7 @@ void do_vectorizedMismatch(Intrinsic* x); void access_flattened_array(bool is_load, LIRItem& array, LIRItem& index, LIRItem& obj_item); + bool needs_flattened_array_check(Value array, Value value); void check_flattened_array(LIRItem& array, CodeStub* slow_path); public: