v8/test/mjsunit/compiler/redundancy-elimination.js
Georg Neis 53c1525df2 [turbofan] Distinguish two further modes of CheckBounds
Extend the flag parameter with a bit that decides if the input should
be converted (-0 to 0, and a string to the array index it represents).
Instruct redundancy elimination to never replace x with CheckBounds(x)
when this CheckBounds is of the converting kind.

Bug: chromium:1070892, chromium:1071743
Change-Id: I3125a6e267d56dae6bf6cb2f5f52d27ef65d7c79
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2157365
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Nico Hartmann <nicohartmann@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67408}
2020-04-27 19:45:35 +00:00

199 lines
5.1 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
// 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;
}
%PrepareFunctionForOptimization(foo);
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;
}
%PrepareFunctionForOptimization(foo);
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;
}
%PrepareFunctionForOptimization(foo);
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;
}
%PrepareFunctionForOptimization(foo);
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;
}
%PrepareFunctionForOptimization(foo);
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;
}
%PrepareFunctionForOptimization(foo);
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;
}
%PrepareFunctionForOptimization(foo);
assertEquals(3, foo([1, 2], 1));
assertEquals(3, foo([1, 2], 1));
%OptimizeFunctionOnNextCall(foo);
assertEquals(3, foo([1, 2], 1));
})();
// Test the RedundancyElimination::ReduceSpeculativeNumberComparison()
// TurboFan optimization for the case of SpeculativeNumberEqual.
(function() {
function foo(a, i) {
const x = a[i];
if (i === 0) return x;
return i;
}
%PrepareFunctionForOptimization(foo);
assertEquals(1, foo([1, 2], 0));
assertEquals(1, foo([1, 2], 1));
%OptimizeFunctionOnNextCall(foo);
assertEquals(1, foo([1, 2], 0));
assertEquals(1, foo([1, 2], 1));
assertOptimized(foo);
assertEquals(9, foo([9, 2], -0));
})();
// Test the RedundancyElimination::ReduceSpeculativeNumberComparison()
// TurboFan optimization for the case of SpeculativeNumberLessThan.
(function() {
function foo(a, i) {
const x = a[i];
if (i < 1) return x;
return i;
}
%PrepareFunctionForOptimization(foo);
assertEquals(1, foo([1, 2], 0));
assertEquals(1, foo([1, 2], 1));
%OptimizeFunctionOnNextCall(foo);
assertEquals(1, foo([1, 2], 0));
assertEquals(1, foo([1, 2], 1));
assertOptimized(foo);
assertEquals(9, foo([9, 2], -0));
})();
// Test the RedundancyElimination::ReduceSpeculativeNumberComparison()
// TurboFan optimization for the case of SpeculativeNumberLessThanOrEqual.
(function() {
function foo(a, i) {
const x = a[i];
if (i <= 0) return x;
return i;
}
%PrepareFunctionForOptimization(foo);
assertEquals(1, foo([1, 2], 0));
assertEquals(1, foo([1, 2], 1));
%OptimizeFunctionOnNextCall(foo);
assertEquals(1, foo([1, 2], 0));
assertEquals(1, foo([1, 2], 1));
assertOptimized(foo);
assertEquals(9, foo([9, 2], -0));
})();