v8/test/mjsunit/compiler/abstract-equal-undetectable.js
Ross McIlroy 31a3cfbc10 [Test] Add PrepareForOptimization to mjsunit/compiler
BUG=v8:8801

Change-Id: I9d9d9824c6c9ad0176bbfd3723da1b578b17c256
Reviewed-on: https://chromium-review.googlesource.com/c/1495555
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Mythri Alle <mythria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60001}
2019-03-04 12:25:41 +00:00

127 lines
2.8 KiB
JavaScript

// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --opt --noalways-opt
const undetectable = %GetUndetectable();
// Known undetectable abstract equality.
(function() {
const a = undetectable;
const b = {};
function foo() { return a == b; }
%PrepareFunctionForOptimization(foo);
assertFalse(foo());
assertFalse(foo());
%OptimizeFunctionOnNextCall(foo);
assertFalse(foo());
})();
// Known undetectable/null abstract equality.
(function() {
const a = undetectable;
const b = null;
function foo() { return a == b; }
%PrepareFunctionForOptimization(foo);
assertTrue(foo());
assertTrue(foo());
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo());
})();
// Known undetectable/receiver abstract equality.
(function() {
const a = null;
const b = undetectable;
function foo() { return a == b; }
%PrepareFunctionForOptimization(foo);
assertTrue(foo());
assertTrue(foo());
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo());
})();
// Known undetectable/undefined abstract equality.
(function() {
const a = undetectable;
const b = undefined;
function foo() { return a == b; }
%PrepareFunctionForOptimization(foo);
assertTrue(foo());
assertTrue(foo());
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo());
})();
// Known undefined/undetectable abstract equality.
(function() {
const a = undefined;
const b = undetectable;
function foo() { return a == b; }
%PrepareFunctionForOptimization(foo);
assertTrue(foo());
assertTrue(foo());
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo());
})();
// Known undetectable on one side strict equality with receiver.
(function() {
const a = {};
const b = undetectable;
function foo(a) { return a == b; }
%PrepareFunctionForOptimization(foo);
assertTrue(foo(b));
assertFalse(foo(a));
assertTrue(foo(b));
assertFalse(foo(a));
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo(b));
assertFalse(foo(a));
// TurboFan doesn't need to bake in feedback, since it sees the undetectable.
assertFalse(foo(1));
assertOptimized(foo);
})();
// Unknown undetectable on one side strict equality with receiver.
(function() {
const a = undetectable;
const b = {};
function foo(a, b) { return a == b; }
%PrepareFunctionForOptimization(foo);
assertTrue(foo(b, b));
assertFalse(foo(a, b));
assertTrue(foo(a, a));
assertFalse(foo(b, a));
assertTrue(foo(a, null));
assertFalse(foo(b, null));
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo(b, b));
assertFalse(foo(a, b));
assertTrue(foo(a, a));
assertFalse(foo(b, a));
assertTrue(foo(a, null));
assertFalse(foo(b, null));
assertOptimized(foo);
// TurboFan bakes in feedback on the inputs.
assertFalse(foo(1));
assertUnoptimized(foo);
})();