v8/test/js-perf-test/BytecodeHandlers/compare.js
jameslahm fce1047f00 Reland "[interpreter] Optimize strict equal boolean"
This is a reland of commit 62632c0805.
Reason for previous revert: Performance regressions crbug.com/1315724.
The reland only optimizes strict equal boolean literal like "a===true"
or "a===false", and we generate TestReferenceEqual rather than
TestStrictEqual for the comparasion. And also add typed optimization
for ReferenceEqual when all inputs are boolean with boolean constant.

Original change's description:
> [interpreter] Optimize strict equal boolean
>
> For strict equal boolean literal like "a===true"
> or "a===false", we could generate TestReferenceEqual
> rather than TestStrictEqual. And in `execution_result()->IsTest()`
> case, we could directly emit JumpIfTrue/JumpIfFalse.
>
> E.g.
> ```
> a === true
> ```
> Generated Bytecode From:
> ```
> LdaGlobal
> Star1
> LdaTrue
> TestEqualStrict
> ```
> To:
> ```
> LdaGlobal
> Star1
> LdaTrue
> TestReferenceEqual
> ```
>
> E.g.
> ```
> if (a === true)
> ```
> Generated Bytecode From:
> ```
> LdaGlobal
> Star1
> LdaTrue
> TestEqualStrict
> JumpIfFalse
> ```
> To
> ```
> LdaGlobal
> JumpIfTrue
> Jump
> ```
>
>
> Bug: v8:6403
> Change-Id: Ieaca147acd2d523ac0d2466e7861afb2d29a1310
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3568923
> Reviewed-by: Leszek Swirski <leszeks@chromium.org>
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Commit-Queue: 王澳 <wangao.james@bytedance.com>
> Cr-Commit-Position: refs/heads/main@{#79935}

Bug: v8:6403
Change-Id: I2ae3ab57dce85313af200fa522e3632af5c3a554
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3592039
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Jakob Linke <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80141}
2022-04-25 10:02:05 +00:00

272 lines
9.0 KiB
JavaScript

// Copyright 2017 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.
function addBenchmark(name, test) {
new BenchmarkSuite(name, [1000],
[
new Benchmark(name, false, false, 0, test)
]);
}
addBenchmark('Smi-StrictEquals-True', SmiStrictEqualsTrue);
addBenchmark('Smi-StrictEquals-False', SmiStrictEqualsFalse);
addBenchmark('Number-StrictEquals-True', NumberStrictEqualsTrue);
addBenchmark('Number-StrictEquals-False', NumberStrictEqualsFalse);
addBenchmark('String-StrictEquals-True', StringStrictEqualsTrue);
addBenchmark('String-StrictEquals-False', StringStrictEqualsFalse);
addBenchmark('SmiString-StrictEquals', MixedStrictEquals);
addBenchmark('Boolean-StrictEquals', BooleanStrictEquals);
addBenchmark('Smi-Equals-True', SmiEqualsTrue);
addBenchmark('Smi-Equals-False', SmiEqualsFalse);
addBenchmark('Number-Equals-True', NumberEqualsTrue);
addBenchmark('Number-Equals-False', NumberEqualsFalse);
addBenchmark('String-Equals-True', StringEqualsTrue);
addBenchmark('String-Equals-False', StringEqualsFalse);
addBenchmark('SmiString-Equals', MixedEquals);
addBenchmark('ObjectNull-Equals', ObjectEqualsNull);
addBenchmark('Smi-RelationalCompare', SmiRelationalCompare);
addBenchmark('Number-RelationalCompare', NumberRelationalCompare);
addBenchmark('String-RelationalCompare', StringRelationalCompare);
addBenchmark('SmiString-RelationalCompare', MixedRelationalCompare);
var null_object;
function strictEquals(a, b) {
for (var i = 0; i < 1000; ++i) {
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b; a === b;
}
}
function strictEqualsBoolean(a) {
var ret;
for (var i = 0; i < 1000; ++i) {
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === true) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
if (a === false) ret = true;
}
return ret;
}
function equals(a, b) {
for (var i = 0; i < 1000; ++i) {
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b; a == b;
}
}
// Relational comparison handlers are similar, so use one benchmark to measure
// all of them.
function relationalCompare(a, b) {
for (var i = 0; i < 1000; ++i) {
a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b;
a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b;
a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b; a > b;
a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b;
a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b;
a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b; a >= b;
a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b;
a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b;
a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b; a < b;
a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b;
a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b;
a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b; a <= b;
}
}
function SmiStrictEqualsFalse() {
strictEquals(10, 20);
}
function SmiStrictEqualsTrue() {
strictEquals(10, 10);
}
function NumberStrictEqualsFalse() {
strictEquals(0.3333, 0.3334);
}
function NumberStrictEqualsTrue() {
strictEquals(0.3333, 0.3333);
}
function StringStrictEqualsFalse() {
strictEquals("abc", "def");
}
function StringStrictEqualsTrue() {
strictEquals("abc", "abc");
}
function BooleanStrictEquals() {
strictEqualsBoolean("a");
strictEqualsBoolean(true);
strictEqualsBoolean(false);
}
function MixedStrictEquals() {
strictEquals(10, "10");
}
function SmiEqualsFalse() {
equals(10, 20);
}
function SmiEqualsTrue() {
equals(10, 10);
}
function NumberEqualsFalse() {
equals(0.3333, 0.3334);
}
function NumberEqualsTrue() {
equals(0.3333, 0.3333);
}
function StringEqualsFalse() {
equals("abc", "def");
}
function StringEqualsTrue() {
equals("abc", "abc");
}
function MixedEquals() {
equals(10, "10");
}
function ObjectEqualsNull(null_object) {
equals(null_object, null);
}
function SmiRelationalCompare() {
relationalCompare(10, 20);
}
function NumberRelationalCompare() {
relationalCompare(0.3333, 0.3334);
}
function StringRelationalCompare() {
relationalCompare("abc", "def");
}
function MixedRelationalCompare() {
relationalCompare(10, "10");
}