[VM] Fix flow graph builder to not generate different code in unoptimized/optimized mode

Change-Id: I752be6bd97dcd892ea6ba5d7fdd30575d4cee489
Reviewed-on: https://dart-review.googlesource.com/c/84720
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
diff --git a/runtime/observatory/tests/service/service_kernel.status b/runtime/observatory/tests/service/service_kernel.status
index 57670e29..c6010cb 100644
--- a/runtime/observatory/tests/service/service_kernel.status
+++ b/runtime/observatory/tests/service/service_kernel.status
@@ -43,7 +43,6 @@
 set_name_rpc_test: RuntimeError
 set_vm_name_rpc_test: RuntimeError
 simple_reload_test: RuntimeError
-step_through_arithmetic_test: RuntimeError
 unused_changes_in_last_reload_test: RuntimeError
 valid_source_locations_test: RuntimeError
 
@@ -61,7 +60,6 @@
 evaluate_activation_test/scope: RuntimeError # http://dartbug.com/20047
 pause_on_unhandled_async_exceptions2_test: Pass, Slow
 positive_token_pos_test: RuntimeError # Issue 34746
-step_through_arithmetic_test: RuntimeError # probably constant evaluator pre-evaluating e.g. 1+2
 unused_changes_in_last_reload_test: RuntimeError
 
 [ $compiler == dartkp ]
diff --git a/runtime/tests/vm/dart/entrypoints/static_this_test.dart b/runtime/tests/vm/dart/entrypoints/static_this_test.dart
index fc9253e..8b962ed 100644
--- a/runtime/tests/vm/dart/entrypoints/static_this_test.dart
+++ b/runtime/tests/vm/dart/entrypoints/static_this_test.dart
@@ -2,8 +2,8 @@
 // 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.
 //
-// VMOptions=--enable-testing-pragmas --no-background-compilation --enable-inlining-annotations --optimization-counter-threshold=10
-// VMOptions=--enable-testing-pragmas --no-background-compilation --enable-inlining-annotations --optimization-counter-threshold=10 -Denable_inlining=true
+// VMOptions=--enable-testing-pragmas --no-background-compilation --enable-inlining-annotations --optimization-counter-threshold=5
+// VMOptions=--enable-testing-pragmas --no-background-compilation --enable-inlining-annotations --optimization-counter-threshold=5 -Denable_inlining=true
 
 // Test that 'StaticCall's against "this" go through the unchecked entry-point.
 
diff --git a/runtime/tests/vm/dart/entrypoints/super_test.dart b/runtime/tests/vm/dart/entrypoints/super_test.dart
index 2a17e61..e923180 100644
--- a/runtime/tests/vm/dart/entrypoints/super_test.dart
+++ b/runtime/tests/vm/dart/entrypoints/super_test.dart
@@ -2,8 +2,8 @@
 // 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.
 //
-// VMOptions=--enable-testing-pragmas --no-background-compilation --enable-inlining-annotations --optimization-counter-threshold=10 -Denable_inlining=true
-// VMOptions=--enable-testing-pragmas --no-background-compilation --enable-inlining-annotations --optimization-counter-threshold=10
+// VMOptions=--enable-testing-pragmas --no-background-compilation --enable-inlining-annotations --optimization-counter-threshold=5 -Denable_inlining=true
+// VMOptions=--enable-testing-pragmas --no-background-compilation --enable-inlining-annotations --optimization-counter-threshold=5
 
 // Test that 'StaticCall's against "super" go through the unchecked entrypoint.
 
diff --git a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
index 4f860f8..8524fd8 100644
--- a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
+++ b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
@@ -35,10 +35,6 @@
   return klass;
 }
 
-bool StreamingFlowGraphBuilder::optimizing() {
-  return flow_graph_builder_->optimizing_;
-}
-
 FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfFieldInitializer() {
   FieldHelper field_helper(this);
   field_helper.ReadUntilExcluding(FieldHelper::kInitializer);
@@ -3508,11 +3504,6 @@
   }
 }
 
-static bool IsNumberLiteral(Tag tag) {
-  return tag == kNegativeIntLiteral || tag == kPositiveIntLiteral ||
-         tag == kSpecializedIntLiteral || tag == kDoubleLiteral;
-}
-
 Fragment StreamingFlowGraphBuilder::BuildMethodInvocation(TokenPosition* p) {
   const intptr_t offset = ReaderOffset() - 1;     // Include the tag.
   const TokenPosition position = ReadPosition();  // read position.
@@ -3526,39 +3517,6 @@
       call_site_attributes_metadata_helper_.GetCallSiteAttributes(offset);
 
   const Tag receiver_tag = PeekTag();  // peek tag for receiver.
-  if (IsNumberLiteral(receiver_tag) &&
-      (!optimizing() || constant_evaluator_.IsCached(offset))) {
-    const intptr_t before_branch_offset = ReaderOffset();
-
-    SkipExpression();  // read receiver (it's just a number literal).
-
-    const String& name = ReadNameAsMethodName();  // read name.
-    const Token::Kind token_kind =
-        MethodTokenRecognizer::RecognizeTokenKind(name);
-    intptr_t argument_count = PeekArgumentsCount() + 1;
-
-    if ((argument_count == 1) && (token_kind == Token::kNEGATE)) {
-      const Object& result = Object::ZoneHandle(
-          Z, constant_evaluator_.EvaluateExpressionSafe(offset));
-      if (!result.IsError()) {
-        SkipArguments();               // read arguments.
-        SkipCanonicalNameReference();  // read interface_target_reference.
-        return Constant(result);
-      }
-    } else if ((argument_count == 2) &&
-               Token::IsBinaryArithmeticOperator(token_kind) &&
-               IsNumberLiteral(PeekArgumentsFirstPositionalTag())) {
-      const Object& result = Object::ZoneHandle(
-          Z, constant_evaluator_.EvaluateExpressionSafe(offset));
-      if (!result.IsError()) {
-        SkipArguments();               // read arguments.
-        SkipCanonicalNameReference();  // read interface_target_reference.
-        return Constant(result);
-      }
-    }
-
-    SetOffset(before_branch_offset);
-  }
 
   bool is_unchecked_closure_call = false;
   bool is_unchecked_call = false;
diff --git a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.h b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.h
index 6a1e201..b16d914 100644
--- a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.h
+++ b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.h
@@ -54,8 +54,6 @@
   Fragment BuildStatementAt(intptr_t kernel_offset);
 
  private:
-  bool optimizing();
-
   Thread* thread() const { return flow_graph_builder_->thread_; }
 
   FlowGraph* BuildGraphOfFieldInitializer();
diff --git a/tests/co19_2/co19_2-kernel.status b/tests/co19_2/co19_2-kernel.status
index fdd0648..0a53b90 100644
--- a/tests/co19_2/co19_2-kernel.status
+++ b/tests/co19_2/co19_2-kernel.status
@@ -304,6 +304,11 @@
 LanguageFeatures/regression/34803_t02: Crash
 LibTest/async/Future/Future_A01_t01: CompileTimeError
 
+[ $arch == simdbc64 && $compiler == dartk ]
+LibTest/collection/ListBase/ListBase_class_A01_t02: Crash # Issue http://dartbug.com/35242
+LibTest/collection/ListMixin/ListMixin_class_A01_t02: Crash  # Issue http://dartbug.com/35242
+LibTest/core/List/List_class_A01_t02: Crash # Issue http://dartbug.com/35242
+
 [ $arch == simdbc64 && $system == macos && ($compiler == dartk || $compiler == dartkb) ]
 LanguageFeatures/Subtyping/static/generated/function_type_function_arguments_binding_A04_t02: Crash, Pass
 LibTest/io/Directory/watch_A01_t02: RuntimeError, Pass