JS: add tests for support of 'for' statement in TemporaryAssignmentElimination

This commit is contained in:
Alexey Andreev
2016-07-15 17:05:37 +03:00
parent f8b96a1c62
commit b5f9287bfa
6 changed files with 110 additions and 2 deletions
@@ -128,8 +128,6 @@ internal class TemporaryAssignmentElimination(private val root: JsBlock) {
x.condition?.let { accept(it) }
x.body?.let { accept(it) }
x.incrementExpression?.let { accept(it) }
super.visitFor(x)
}
}.accept(root)
@@ -34,4 +34,8 @@ class TemporaryAssignmentEliminationTest : BasicOptimizerTest("temporary-assignm
@Test fun tryCatch() = box()
@Test fun ifWithoutElse() = box()
@Test fun forInitVariables() = box()
@Test fun forInitExpressionPreventsOptimization() = box()
}
@@ -0,0 +1,27 @@
function test(x) {
var $tmp;
if (x > 9) {
$tmp = 9;
}
else {
$tmp = x;
}
var y = $tmp;
var result = x;
for (var i = $tmp; i < 10; ++i) {
result += i;
}
return result + y;
}
function box() {
var result = test(11);
if (result != 29) return "fail1: " + result;
result = test(8);
if (result != 33) return "fail2: " + result;
return "OK";
}
@@ -0,0 +1,27 @@
function test(x) {
var $tmp;
if (x > 9) {
$tmp = 9;
}
else {
$tmp = x;
}
var y = $tmp;
var result = x;
for (var i = $tmp; i < 10; ++i) {
result += i;
}
return result + y;
}
function box() {
var result = test(11);
if (result != 29) return "fail1: " + result;
result = test(8);
if (result != 33) return "fail2: " + result;
return "OK";
}
@@ -0,0 +1,26 @@
function test(x) {
var $tmp;
if (x > 9) {
$tmp = 9;
}
else {
$tmp = x;
}
var result = x;
for (var i = $tmp; i < 10; ++i) {
result += i;
}
return result;
}
function box() {
var result = test(11);
if (result != 20) return "fail1: " + result;
result = test(8);
if (result != 25) return "fail2: " + result;
return "OK";
}
@@ -0,0 +1,26 @@
function test(x) {
var $tmp;
if (x > 9) {
$tmp = 9;
}
else {
$tmp = x;
}
var result = x;
for (var i = $tmp; i < 10; ++i) {
result += i;
}
return result;
}
function box() {
var result = test(11);
if (result != 20) return "fail1: " + result;
result = test(8);
if (result != 25) return "fail2: " + result;
return "OK";
}