[vm/compiler] Use CompileType of Values instead of Definitions in TypedDataOptimizer

Sometimes our compiler loses type information on [Definition]s but
retains the more precise [CompileType] on the [Value]s, so use
the [Value]s [CompileType].

Issue https://github.com/dart-lang/sdk/issues/43534

Change-Id: Ibb3610f389ec55025655a8f0ac78a33a6269063d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165360
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
This commit is contained in:
Martin Kustermann 2020-10-01 11:36:32 +00:00 committed by commit-bot@chromium.org
parent 014552370a
commit 9c59897fc4
2 changed files with 59 additions and 3 deletions

View file

@ -451,6 +451,61 @@ ISOLATE_UNIT_TEST_CASE(IRTest_TypedDataAOT_FunctionalIndexError) {
}
}
ISOLATE_UNIT_TEST_CASE(IRTest_TypedDataAOT_Regress43534) {
const char* kScript =
R"(
import 'dart:typed_data';
@pragma('vm:never-inline')
void callWith<T>(void Function(T arg) fun, T arg) {
fun(arg);
}
void test() {
callWith<Uint8List>((Uint8List list) {
if (list[0] != 0) throw 'a';
}, Uint8List(10));
}
)";
const auto& root_library = Library::Handle(LoadTestScript(kScript));
Invoke(root_library, "test");
const auto& test_function =
Function::Handle(GetFunction(root_library, "test"));
const auto& closures = GrowableObjectArray::Handle(
Isolate::Current()->object_store()->closure_functions());
auto& function = Function::Handle();
for (intptr_t i = closures.Length() - 1; 0 <= i; ++i) {
function ^= closures.At(i);
if (function.parent_function() == test_function.raw()) {
break;
}
function = Function::null();
}
RELEASE_ASSERT(!function.IsNull());
TestPipeline pipeline(function, CompilerPass::kAOT);
FlowGraph* flow_graph = pipeline.RunPasses({});
auto entry = flow_graph->graph_entry()->normal_entry();
EXPECT(entry != nullptr);
ILMatcher cursor(flow_graph, entry, /*trace=*/true);
RELEASE_ASSERT(cursor.TryMatch(
{
kMatchAndMoveGoto,
kMatchAndMoveBranchFalse,
kMatchAndMoveAssertAssignable,
kMatchAndMoveGoto,
kMatchAndMoveLoadField,
kMatchAndMoveGenericCheckBound,
kMatchAndMoveLoadUntagged,
kMatchAndMoveLoadIndexed,
kMatchAndMoveBranchFalse,
kMoveGlob,
kMatchReturn,
},
kMoveGlob));
}
#endif // defined(DART_PRECOMPILER)
} // namespace dart

View file

@ -1571,16 +1571,17 @@ void TypedDataSpecializer::TryInlineCall(TemplateDartCall<0>* call) {
const intptr_t receiver_index = call->FirstArgIndex();
CompileType* receiver_type = call->ArgumentAt(receiver_index + 0)->Type();
CompileType* receiver_type =
call->ArgumentValueAt(receiver_index + 0)->Type();
CompileType* index_type = nullptr;
if (is_index_get || is_index_set) {
index_type = call->ArgumentAt(receiver_index + 1)->Type();
index_type = call->ArgumentValueAt(receiver_index + 1)->Type();
}
CompileType* value_type = nullptr;
if (is_index_set) {
value_type = call->ArgumentAt(receiver_index + 2)->Type();
value_type = call->ArgumentValueAt(receiver_index + 2)->Type();
}
auto& type_class = Class::Handle(zone_);