[vm/bytecode] Recognize identical() in bytecode flow graph builder

This optimization is performed in AST-based flow graph builder and
it is needed for optimizer to constant fold certain things
(e.g. testing endianness in typed data getters).

Replicating it in bytecode flow graph builder to keep parity with
AST-based flow graph builder.

Bug: FL-203.
Change-Id: Id28bcccc75c5d5184801574dbe10b74b86711d50
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97400
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Aart Bik <ajcbik@google.com>
diff --git a/runtime/vm/compiler/frontend/bytecode_flow_graph_builder.cc b/runtime/vm/compiler/frontend/bytecode_flow_graph_builder.cc
index f5f3c3a..0c0b448 100644
--- a/runtime/vm/compiler/frontend/bytecode_flow_graph_builder.cc
+++ b/runtime/vm/compiler/frontend/bytecode_flow_graph_builder.cc
@@ -707,10 +707,24 @@
   }
 
   const Function& target = Function::Cast(ConstantAt(DecodeOperandD()).value());
+  const intptr_t argc = DecodeOperandA().value();
+
+  // Recognize identical() call.
+  // Note: similar optimization is performed in AST flow graph builder - see
+  // StreamingFlowGraphBuilder::BuildStaticInvocation, special_case_identical.
+  // TODO(alexmarkov): find a better place for this optimization.
+  if (target.name() == Symbols::Identical().raw()) {
+    const auto& owner = Class::Handle(Z, target.Owner());
+    if (owner.IsTopLevel() && (owner.library() == Library::CoreLibrary())) {
+      ASSERT(argc == 2);
+      code_ += B->StrictCompare(Token::kEQ_STRICT, /*number_check=*/true);
+      return;
+    }
+  }
+
   const Array& arg_desc_array =
       Array::Cast(ConstantAt(DecodeOperandD(), 1).value());
   const ArgumentsDescriptor arg_desc(arg_desc_array);
-  intptr_t argc = DecodeOperandA().value();
 
   ArgumentArray arguments = GetArguments(argc);
 
diff --git a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
index 95b52d3..431d88f 100644
--- a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
+++ b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
@@ -3048,6 +3048,8 @@
                                   NULL));
 
   // Special case identical(x, y) call.
+  // Note: similar optimization is performed in bytecode flow graph builder -
+  // see BytecodeFlowGraphBuilder::BuildDirectCall().
   // TODO(27590) consider moving this into the inliner and force inline it
   // there.
   if (special_case_identical) {