[vm/aot] Only specialize devirtualized instance calls

Many instance calls get turned into static calls in our AOT compiler.
The typed data optimization pass accidentally tried to optimize all static
calls instead of only devirtualized instance calls.

Issue https://github.com/flutter/flutter/issues/35121

Change-Id: Ibe8a95ceed6abf5ff2608f076a98f55c40f43477
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107410
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
diff --git a/runtime/tests/vm/dart/regress_flutter35121_test.dart b/runtime/tests/vm/dart/regress_flutter35121_test.dart
new file mode 100644
index 0000000..a4d21b6
--- /dev/null
+++ b/runtime/tests/vm/dart/regress_flutter35121_test.dart
@@ -0,0 +1,15 @@
+// Copyright (c) 2019, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// This is a regression test for
+// https://github.com/flutter/flutter/issues/35121
+
+class A {
+  static List<int> values = const [1, 2, 3];
+  static int get length => values.length;
+}
+
+main() {
+  print(A.length);
+}
diff --git a/runtime/vm/compiler/call_specializer.cc b/runtime/vm/compiler/call_specializer.cc
index 7cf2dc1..0626731 100644
--- a/runtime/vm/compiler/call_specializer.cc
+++ b/runtime/vm/compiler/call_specializer.cc
@@ -1692,7 +1692,11 @@
 }
 
 void TypedDataSpecializer::VisitStaticCall(StaticCallInstr* call) {
-  TryInlineCall(call);
+  const Function& function = call->function();
+  if (!function.is_static()) {
+    ASSERT(call->ArgumentCount() > 0);
+    TryInlineCall(call);
+  }
 }
 
 void TypedDataSpecializer::TryInlineCall(TemplateDartCall<0>* call) {