Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Unified Diff: test/cctest/interpreter/test-bytecode-generator.cc

Issue 1435283002: [Interpreter] Adds an optimization to remove redundant Ldar/Star. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased the patch Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/cctest/interpreter/test-bytecode-generator.cc
diff --git a/test/cctest/interpreter/test-bytecode-generator.cc b/test/cctest/interpreter/test-bytecode-generator.cc
index 6fda07b83b3d129cad22853d7f0fe68f07dd4862..9aa4cf85c24a364792d619f674f04ba34270d406 100644
--- a/test/cctest/interpreter/test-bytecode-generator.cc
+++ b/test/cctest/interpreter/test-bytecode-generator.cc
@@ -264,10 +264,9 @@ TEST(PrimitiveExpressions) {
{"var x = 0; return x;",
kPointerSize,
1,
- 6,
+ 4,
{B(LdaZero), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(Return)},
0},
{"var x = 0; return x + 3;",
@@ -407,10 +406,9 @@ TEST(LogicalExpressions) {
{"var x = 0; return x || 3;",
1 * kPointerSize,
1,
- 10,
+ 8,
{B(LdaZero), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(JumpIfToBooleanTrue), U8(4), //
B(LdaSmi8), U8(3), //
B(Return)},
@@ -430,10 +428,9 @@ TEST(LogicalExpressions) {
{"var x = 0; return x && 3;",
1 * kPointerSize,
1,
- 10,
+ 8,
{B(LdaZero), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(JumpIfToBooleanFalse), U8(4), //
B(LdaSmi8), U8(3), //
B(Return)},
@@ -453,10 +450,9 @@ TEST(LogicalExpressions) {
{"var x = 0; return x || (1, 2, 3);",
1 * kPointerSize,
1,
- 10,
+ 8,
{B(LdaZero), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(JumpIfToBooleanTrue), U8(4), //
B(LdaSmi8), U8(3), //
B(Return)},
@@ -589,10 +585,9 @@ TEST(LogicalExpressions) {
{"var x = 1; return x && 3 || 0, 1;",
1 * kPointerSize,
1,
- 16,
+ 14,
{B(LdaSmi8), U8(1), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(JumpIfToBooleanFalse), U8(4), //
B(LdaSmi8), U8(3), //
B(JumpIfToBooleanTrue), U8(3), //
@@ -1663,11 +1658,10 @@ TEST(IfConditions) {
{"function f() { var a = 1; if (a) { a += 1; } else { return 2; } } f();",
1 * kPointerSize,
1,
- 21,
+ 19,
{
B(LdaSmi8), U8(1), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(JumpIfToBooleanFalse), U8(10), //
B(LdaSmi8), U8(1), //
B(Add), R(0), //
@@ -1718,11 +1712,11 @@ TEST(IfConditions) {
{helper.factory()->NewNumberFromInt(200), unused, unused, unused, unused,
unused}},
{"function f(z) { var a = 0; var b = 0; if (a === 0.01) { "
- REPEAT_32(SPACE, "b = a; a = b; ")
+ REPEAT_64(SPACE, "b = a; a = b; ")
" return 200; } else { return -200; } } f(0.001)",
2 * kPointerSize,
2,
- 276,
+ 278,
{
B(LdaZero), //
B(Star), R(0), //
@@ -1731,10 +1725,9 @@ TEST(IfConditions) {
B(LdaConstant), U8(0), //
B(TestEqualStrict), R(0), //
B(JumpIfFalseConstant), U8(2), //
- REPEAT_32(COMMA, //
- B(Ldar), R(0), //
+ B(Ldar), R(0), //
+ REPEAT_64(COMMA, //
B(Star), R(1), //
- B(Ldar), R(1), //
B(Star), R(0)), //
B(LdaConstant), U8(1), //
B(Return), //
@@ -1745,14 +1738,14 @@ TEST(IfConditions) {
4,
{helper.factory()->NewHeapNumber(0.01),
helper.factory()->NewNumberFromInt(200),
- helper.factory()->NewNumberFromInt(261),
+ helper.factory()->NewNumberFromInt(263),
helper.factory()->NewNumberFromInt(-200), unused, unused}},
{"function f() { var a = 0; var b = 0; if (a) { "
- REPEAT_32(SPACE, "b = a; a = b; ")
+ REPEAT_64(SPACE, "b = a; a = b; ")
" return 200; } else { return -200; } } f()",
2 * kPointerSize,
1,
- 274,
+ 276,
{
B(LdaZero), //
B(Star), R(0), //
@@ -1760,10 +1753,9 @@ TEST(IfConditions) {
B(Star), R(1), //
B(Ldar), R(0), //
B(JumpIfToBooleanFalseConstant), U8(1), //
- REPEAT_32(COMMA, //
- B(Ldar), R(0), //
+ B(Ldar), R(0), //
+ REPEAT_64(COMMA, //
B(Star), R(1), //
- B(Ldar), R(1), //
B(Star), R(0)), //
B(LdaConstant), U8(0), //
B(Return), //
@@ -1773,7 +1765,7 @@ TEST(IfConditions) {
B(Return)}, //
3,
{helper.factory()->NewNumberFromInt(200),
- helper.factory()->NewNumberFromInt(261),
+ helper.factory()->NewNumberFromInt(263),
helper.factory()->NewNumberFromInt(-200), unused, unused, unused}},
{"function f(a, b) {\n"
@@ -1820,11 +1812,10 @@ TEST(IfConditions) {
"f();",
1 * kPointerSize,
1,
- 15,
+ 13,
{
B(LdaZero), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(JumpIfToBooleanFalse), U8(5), //
B(LdaSmi8), U8(20), //
B(Return), //
@@ -1834,8 +1825,7 @@ TEST(IfConditions) {
B(Return)
},
0,
- {unused, unused, unused, unused, unused, unused}}
- };
+ {unused, unused, unused, unused, unused, unused}}};
for (size_t i = 0; i < arraysize(snippets); i++) {
Handle<BytecodeArray> bytecode_array =
@@ -1907,7 +1897,7 @@ TEST(DeclareGlobals) {
{"var a = 1;\na=2;",
4 * kPointerSize,
1,
- 38,
+ 36,
{
B(LdaConstant), U8(0), //
B(Star), R(1), //
@@ -1925,7 +1915,6 @@ TEST(DeclareGlobals) {
B(StaGlobalSloppy), U8(1), //
U8(store_vector->GetIndex(store_slot_2)), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(Return) //
},
2,
@@ -1934,7 +1923,7 @@ TEST(DeclareGlobals) {
{"function f() {}\nf();",
3 * kPointerSize,
1,
- 29,
+ 27,
{
B(LdaConstant), U8(0), //
B(Star), R(1), //
@@ -1948,7 +1937,6 @@ TEST(DeclareGlobals) {
B(Star), R(1), //
B(Call), R(1), R(2), U8(0), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(Return) //
},
2,
@@ -2195,16 +2183,16 @@ TEST(BasicLoops) {
},
0},
{"var x = 10;"
- "var y = 1;"
- "do {"
- " y = y * 12;"
- " x = x - 1;"
- "} while(x);"
- "return y;",
- 2 * kPointerSize,
- 1,
- 27,
- {
+ "var y = 1;"
+ "do {"
+ " y = y * 12;"
+ " x = x - 1;"
+ "} while(x);"
+ "return y;",
+ 2 * kPointerSize,
+ 1,
+ 27,
+ {
B(LdaSmi8), U8(10), //
B(Star), R(0), //
B(LdaSmi8), U8(1), //
@@ -2219,7 +2207,7 @@ TEST(BasicLoops) {
B(JumpIfToBooleanTrue), U8(-14), //
B(Ldar), R(1), //
B(Return), //
- },
+ },
0},
{"var y = 1;"
"for (var x = 10; x; --x) {"
@@ -2324,11 +2312,10 @@ TEST(BasicLoops) {
"return x;",
1 * kPointerSize,
1,
- 6,
+ 4,
{
B(LdaZero), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(Return), //
},
0},
@@ -2457,18 +2444,16 @@ TEST(UnaryOperators) {
"return y;",
3 * kPointerSize,
1,
- 20,
+ 16,
{
B(LdaConstant), U8(0), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(Mul), R(0), //
B(Star), R(2), //
B(LdaSmi8), U8(1), //
B(Sub), R(2), //
B(LdaUndefined), //
B(Star), R(1), //
- B(Ldar), R(1), //
B(Return), //
},
1,
@@ -2539,11 +2524,10 @@ TEST(Typeof) {
"}; f();",
kPointerSize,
1,
- 8,
+ 6,
{
B(LdaSmi8), U8(13), //
- B(Star), R(0), // TODO(oth): Ldar R(X) following Star R(X)
- B(Ldar), R(0), // could be culled in bytecode array builder.
+ B(Star), R(0), //
B(TypeOf), //
B(Return), //
}},
@@ -3532,11 +3516,10 @@ TEST(Throw) {
{"var a = 1; if (a) { throw 'Error'; };",
1 * kPointerSize,
1,
- 13,
+ 11,
{
B(LdaSmi8), U8(1), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(JumpIfToBooleanFalse), U8(5), //
B(LdaConstant), U8(0), //
B(Throw), //
@@ -3924,11 +3907,10 @@ TEST(CountOperators) {
{"var a = 1; return ++a;",
1 * kPointerSize,
1,
- 11,
+ 9,
{
B(LdaSmi8), U8(1), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(ToNumber), //
B(Inc), //
B(Star), R(0), //
@@ -3937,11 +3919,10 @@ TEST(CountOperators) {
{"var a = 1; return a++;",
2 * kPointerSize,
1,
- 15,
+ 13,
{
B(LdaSmi8), U8(1), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(ToNumber), //
B(Star), R(1), //
B(Inc), //
@@ -3952,11 +3933,10 @@ TEST(CountOperators) {
{"var a = 1; return --a;",
1 * kPointerSize,
1,
- 11,
+ 9,
{
B(LdaSmi8), U8(1), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(ToNumber), //
B(Dec), //
B(Star), R(0), //
@@ -3965,11 +3945,10 @@ TEST(CountOperators) {
{"var a = 1; return a--;",
2 * kPointerSize,
1,
- 15,
+ 13,
{
B(LdaSmi8), U8(1), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(ToNumber), //
B(Star), R(1), //
B(Dec), //
@@ -4397,11 +4376,10 @@ TEST(CreateArguments) {
{"function f() { return arguments; }",
1 * kPointerSize,
1,
- 6,
+ 4,
{
B(CreateMappedArguments), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(Return), //
}},
{"function f() { return arguments[0]; }",
@@ -4418,11 +4396,10 @@ TEST(CreateArguments) {
{"function f() { 'use strict'; return arguments; }",
1 * kPointerSize,
1,
- 6,
+ 4,
{
B(CreateUnmappedArguments), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(Return), //
}},
{"function f(a) { return arguments[0]; }",
@@ -4444,7 +4421,7 @@ TEST(CreateArguments) {
{"function f(a, b, c) { return arguments; }",
2 * kPointerSize,
4,
- 28,
+ 26,
{
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
U8(1), //
@@ -4457,17 +4434,15 @@ TEST(CreateArguments) {
B(StaContextSlot), R(1), U8(first_context_slot), //
B(CreateMappedArguments), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(Return), //
}},
{"function f(a, b, c) { 'use strict'; return arguments; }",
1 * kPointerSize,
4,
- 6,
+ 4,
{
B(CreateUnmappedArguments), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(Return), //
}},
};
@@ -4544,33 +4519,30 @@ TEST(ForIn) {
"for (var p in x) { return p; }",
5 * kPointerSize,
1,
- 52,
+ 46,
{
B(LdaConstant), U8(0), //
B(Star), R(1), //
- B(Ldar), R(1), //
- B(JumpIfUndefined), U8(44), //
- B(JumpIfNull), U8(42), //
+ B(JumpIfUndefined), U8(40), //
+ B(JumpIfNull), U8(38), //
B(ToObject), //
B(Star), R(3), //
B(CallRuntime), U16(Runtime::kGetPropertyNamesFast), R(3), U8(1), //
B(ForInPrepare), R(3), //
- B(JumpIfUndefined), U8(30), //
+ B(JumpIfUndefined), U8(26), //
B(Star), R(4), //
B(LdaZero), //
B(Star), R(3), //
B(ForInDone), R(4), //
- B(JumpIfTrue), U8(21), //
+ B(JumpIfTrue), U8(17), //
B(ForInNext), R(4), R(3), //
- B(JumpIfUndefined), U8(11), //
+ B(JumpIfUndefined), U8(7), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(Star), R(2), //
- B(Ldar), R(2), //
B(Return), //
B(Ldar), R(3), //
B(Inc), //
- B(Jump), U8(-23), //
+ B(Jump), U8(-19), //
B(LdaUndefined), //
B(Return), //
},
@@ -4580,35 +4552,33 @@ TEST(ForIn) {
"for (var p in [1,2,3]) { x += p; }",
5 * kPointerSize,
1,
- 57,
+ 53,
{
B(LdaZero), //
B(Star), R(1), //
B(LdaConstant), U8(0), //
B(CreateArrayLiteral), U8(0), U8(simple_flags), //
- B(JumpIfUndefined), U8(47), //
- B(JumpIfNull), U8(45), //
+ B(JumpIfUndefined), U8(43), //
+ B(JumpIfNull), U8(41), //
B(ToObject), //
B(Star), R(3), //
B(CallRuntime), U16(Runtime::kGetPropertyNamesFast), R(3), U8(1), //
B(ForInPrepare), R(3), //
- B(JumpIfUndefined), U8(33), //
+ B(JumpIfUndefined), U8(29), //
B(Star), R(4), //
B(LdaZero), //
B(Star), R(3), //
B(ForInDone), R(4), //
- B(JumpIfTrue), U8(24), //
+ B(JumpIfTrue), U8(20), //
B(ForInNext), R(4), R(3), //
- B(JumpIfUndefined), U8(14), //
+ B(JumpIfUndefined), U8(10), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(Star), R(2), //
- B(Ldar), R(2), //
B(Add), R(1), //
B(Star), R(1), //
B(Ldar), R(3), //
B(Inc), //
- B(Jump), U8(-26), //
+ B(Jump), U8(-22), //
B(LdaUndefined), //
B(Return), //
},
@@ -4771,13 +4741,12 @@ TEST(Switch) {
"}\n",
2 * kPointerSize,
1,
- 30,
+ 28,
{
B(LdaSmi8), U8(1), //
B(Star), R(1), // The tag variable is allocated as a
- B(Ldar), R(1), // local by the parser, hence this
- B(Star), R(0), // strange shuffling.
- B(LdaSmi8), U8(1), //
+ B(Star), R(0), // local by the parser, hence the store
+ B(LdaSmi8), U8(1), // to another local register.
B(TestEqualStrict), R(0), //
B(JumpIfTrue), U8(10), //
B(LdaSmi8), U8(2), //
@@ -4798,11 +4767,10 @@ TEST(Switch) {
"}\n",
2 * kPointerSize,
1,
- 36,
+ 34,
{
B(LdaSmi8), U8(1), //
B(Star), R(1), //
- B(Ldar), R(1), //
B(Star), R(0), //
B(LdaSmi8), U8(1), //
B(TestEqualStrict), R(0), //
@@ -4827,11 +4795,10 @@ TEST(Switch) {
"}\n",
2 * kPointerSize,
1,
- 34,
+ 32,
{
B(LdaSmi8), U8(1), //
B(Star), R(1), //
- B(Ldar), R(1), //
B(Star), R(0), //
B(LdaSmi8), U8(1), //
B(TestEqualStrict), R(0), //
@@ -4856,11 +4823,10 @@ TEST(Switch) {
"}\n",
2 * kPointerSize,
1,
- 34,
+ 32,
{
B(LdaSmi8), U8(1), //
B(Star), R(1), //
- B(Ldar), R(1), //
B(Star), R(0), //
B(LdaSmi8), U8(2), //
B(TestEqualStrict), R(0), //
@@ -4885,11 +4851,10 @@ TEST(Switch) {
"}\n",
2 * kPointerSize,
1,
- 43,
+ 41,
{
B(LdaSmi8), U8(1), //
B(Star), R(1), //
- B(Ldar), R(1), //
B(TypeOf), //
B(Star), R(0), //
B(LdaSmi8), U8(2), //
@@ -4918,11 +4883,10 @@ TEST(Switch) {
"}\n",
2 * kPointerSize,
1,
- 31,
+ 29,
{
B(LdaSmi8), U8(1), //
B(Star), R(1), //
- B(Ldar), R(1), //
B(Star), R(0), //
B(Ldar), R(1), //
B(TypeOf), //
@@ -4946,11 +4910,10 @@ TEST(Switch) {
"}\n",
2 * kPointerSize,
1,
- 288,
+ 286,
{
B(LdaSmi8), U8(1), //
B(Star), R(1), //
- B(Ldar), R(1), //
B(Star), R(0), //
B(LdaSmi8), U8(1), //
B(TestEqualStrict), R(0), //
@@ -4982,11 +4945,10 @@ TEST(Switch) {
"}\n",
3 * kPointerSize,
1,
- 54,
+ 52,
{
B(LdaSmi8), U8(1), //
B(Star), R(2), //
- B(Ldar), R(2), //
B(Star), R(0), //
B(LdaSmi8), U8(1), //
B(TestEqualStrict), R(0), //
@@ -5033,11 +4995,10 @@ TEST(BasicBlockToBoolean) {
{"var a = 1; if (a || a < 0) { return 1; }",
1 * kPointerSize,
1,
- 18,
+ 16,
{
B(LdaSmi8), U8(1), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(JumpIfToBooleanTrue), U8(5), //
B(LdaZero), //
B(TestLessThan), R(0), //
@@ -5050,11 +5011,10 @@ TEST(BasicBlockToBoolean) {
{"var a = 1; if (a && a < 0) { return 1; }",
1 * kPointerSize,
1,
- 18,
+ 16,
{
B(LdaSmi8), U8(1), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(JumpIfToBooleanFalse), U8(5), //
B(LdaZero), //
B(TestLessThan), R(0), //
@@ -5067,11 +5027,10 @@ TEST(BasicBlockToBoolean) {
{"var a = 1; a = (a || a < 0) ? 2 : 3;",
1 * kPointerSize,
1,
- 23,
+ 21,
{
B(LdaSmi8), U8(1), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(JumpIfToBooleanTrue), U8(5), //
B(LdaZero), //
B(TestLessThan), R(0), //
@@ -5127,11 +5086,10 @@ TEST(DeadCodeRemoval) {
{"var a = 1; if (a) { return 1; }; return 2;",
1 * kPointerSize,
1,
- 14,
+ 12,
{
B(LdaSmi8), U8(1), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(JumpIfToBooleanFalse), U8(5), //
B(LdaSmi8), U8(1), //
B(Return), //
@@ -5170,13 +5128,12 @@ TEST(ThisFunction) {
{"var f;\n f = function f() { return f; }",
1 * kPointerSize,
1,
- 10,
+ 8,
{
B(LdaTheHole), //
B(Star), R(0), //
B(Ldar), R(closure), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(Return), //
}},
};
@@ -5197,12 +5154,70 @@ TEST(NewTarget) {
{"return new.target;",
1 * kPointerSize,
1,
- 10,
+ 8,
{
B(CallRuntime), U16(Runtime::kGetNewTarget), R(0), U8(0), //
B(Star), R(0), //
- B(Ldar), R(0), //
B(Return), //
+ }}
+ };
+
+ for (size_t i = 0; i < arraysize(snippets); i++) {
+ Handle<BytecodeArray> bytecode_array =
+ helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
+ CheckBytecodeArrayEqual(snippets[i], bytecode_array);
+ }
+}
+
+
+TEST(RemoveRedundantLdar) {
+ InitializedHandleScope handle_scope;
+ BytecodeGeneratorHelper helper;
+
+ ExpectedSnippet<int> snippets[] = {
+ {"var ld_a = 1;\n" // This test is to check Ldar does not
+ "while(true) {\n" // get removed if the preceding Star is
+ " ld_a = ld_a + ld_a;\n" // in a different basicblock.
+ " if (ld_a > 10) break;\n"
+ "}\n"
+ "return ld_a;",
+ 1 * kPointerSize,
+ 1,
+ 23,
+ {
+ B(LdaSmi8), U8(1), //
+ B(Star), R(0), //
+ B(Ldar), R(0), // This load should not be removed as it
+ B(Add), R(0), // is the target of the branch.
+ B(Star), R(0), //
+ B(LdaSmi8), U8(10), //
+ B(TestGreaterThan), R(0), //
+ B(JumpIfFalse), U8(4), //
+ B(Jump), U8(4), //
+ B(Jump), U8(-14), //
+ B(Ldar), R(0), //
+ B(Return)
+ }},
+ {"var ld_a = 1;\n"
+ "do {\n"
+ " ld_a = ld_a + ld_a;\n"
+ " if (ld_a > 10) continue;\n"
+ "} while(false);\n"
+ "return ld_a;",
+ 1 * kPointerSize,
+ 1,
+ 19,
+ {
+ B(LdaSmi8), U8(1), //
+ B(Star), R(0), //
+ B(Add), R(0), //
+ B(Star), R(0), //
+ B(LdaSmi8), U8(10), //
+ B(TestGreaterThan), R(0), //
+ B(JumpIfFalse), U8(4), //
+ B(Jump), U8(2), //
+ B(Ldar), R(0), //
+ B(Return)
}},
};
« no previous file with comments | « src/interpreter/bytecode-generator.cc ('k') | test/unittests/interpreter/bytecode-array-builder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698