3a9466a89c
Remove the NumberConstant right hand side limitation for the speculative number operation optimization, and extend the logic to also deal with SpeculativeToNumber, which is common when dealing with postfix increment and array operations. Also add appropriate tests for all the relevant cases, specifically we mjsunit tests to increase the general coverage for the various cases here (in addition to dedicated unittests). Bug: v8:8015 Change-Id: I8c92f98490c63b07eb19686efd404322979e57c4 Reviewed-on: https://chromium-review.googlesource.com/1235919 Reviewed-by: Jaroslav Sevcik <jarin@chromium.org> Commit-Queue: Benedikt Meurer <bmeurer@chromium.org> Cr-Commit-Position: refs/heads/master@{#56072}
135 lines
3.2 KiB
JavaScript
135 lines
3.2 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
|
|
|
|
// Test the RedundancyElimination::ReduceSpeculativeNumberOperation()
|
|
// TurboFan optimization for the case of SpeculativeNumberAdd with
|
|
// Number feedback.
|
|
(function() {
|
|
function bar(i) {
|
|
return ++i;
|
|
}
|
|
bar(0.1);
|
|
|
|
function foo(a, i) {
|
|
const x = a[i];
|
|
const y = a[bar(i)];
|
|
return x + y;
|
|
}
|
|
|
|
assertEquals(3, foo([1, 2], 0));
|
|
assertEquals(3, foo([1, 2], 0));
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
assertEquals(3, foo([1, 2], 0));
|
|
})();
|
|
|
|
// Test the RedundancyElimination::ReduceSpeculativeNumberOperation()
|
|
// TurboFan optimization for the case of SpeculativeNumberAdd with
|
|
// NumberOrOddball feedback.
|
|
(function() {
|
|
function bar(i) {
|
|
return ++i;
|
|
}
|
|
assertEquals(NaN, bar(undefined));
|
|
|
|
function foo(a, i) {
|
|
const x = a[i];
|
|
const y = a[bar(i)];
|
|
return x + y;
|
|
}
|
|
|
|
assertEquals(3, foo([1, 2], 0));
|
|
assertEquals(3, foo([1, 2], 0));
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
assertEquals(3, foo([1, 2], 0));
|
|
})();
|
|
|
|
// Test the RedundancyElimination::ReduceSpeculativeNumberOperation()
|
|
// TurboFan optimization for the case of SpeculativeNumberSubtract with
|
|
// Number feedback.
|
|
(function() {
|
|
function bar(i) {
|
|
return --i;
|
|
}
|
|
assertEquals(-0.9, bar(0.1));
|
|
|
|
function foo(a, i) {
|
|
const x = a[i];
|
|
const y = a[bar(i)];
|
|
return x + y;
|
|
}
|
|
|
|
assertEquals(3, foo([1, 2], 1));
|
|
assertEquals(3, foo([1, 2], 1));
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
assertEquals(3, foo([1, 2], 1));
|
|
})();
|
|
|
|
// Test the RedundancyElimination::ReduceSpeculativeNumberOperation()
|
|
// TurboFan optimization for the case of SpeculativeNumberSubtract with
|
|
// NumberOrOddball feedback.
|
|
(function() {
|
|
function bar(i) {
|
|
return --i;
|
|
}
|
|
assertEquals(NaN, bar(undefined));
|
|
|
|
function foo(a, i) {
|
|
const x = a[i];
|
|
const y = a[bar(i)];
|
|
return x + y;
|
|
}
|
|
|
|
assertEquals(3, foo([1, 2], 1));
|
|
assertEquals(3, foo([1, 2], 1));
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
assertEquals(3, foo([1, 2], 1));
|
|
})();
|
|
|
|
// Test the RedundancyElimination::ReduceSpeculativeNumberOperation()
|
|
// TurboFan optimization for the case of SpeculativeToNumber.
|
|
(function() {
|
|
function foo(a, i) {
|
|
const x = a[i];
|
|
const y = i++;
|
|
return x + y;
|
|
}
|
|
|
|
assertEquals(1, foo([1, 2], 0));
|
|
assertEquals(1, foo([1, 2], 0));
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
assertEquals(1, foo([1, 2], 0));
|
|
})();
|
|
|
|
// Test the RedundancyElimination::ReduceSpeculativeNumberOperation()
|
|
// TurboFan optimization for the case of SpeculativeSafeIntegerAdd.
|
|
(function() {
|
|
function foo(a, i) {
|
|
const x = a[i];
|
|
const y = a[++i];
|
|
return x + y;
|
|
}
|
|
|
|
assertEquals(3, foo([1, 2], 0));
|
|
assertEquals(3, foo([1, 2], 0));
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
assertEquals(3, foo([1, 2], 0));
|
|
})();
|
|
|
|
// Test the RedundancyElimination::ReduceSpeculativeNumberOperation()
|
|
// TurboFan optimization for the case of SpeculativeSafeIntegerSubtract.
|
|
(function() {
|
|
function foo(a, i) {
|
|
const x = a[i];
|
|
const y = a[--i];
|
|
return x + y;
|
|
}
|
|
|
|
assertEquals(3, foo([1, 2], 1));
|
|
assertEquals(3, foo([1, 2], 1));
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
assertEquals(3, foo([1, 2], 1));
|
|
})();
|