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

Unified Diff: test/unittests/interpreter/bytecode-peephole-optimizer-unittest.cc

Issue 2111923002: [interpreter] Introduce binary op bytecodes for Smi operand. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 5 months 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
« no previous file with comments | « test/unittests/interpreter/bytecode-array-iterator-unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/interpreter/bytecode-peephole-optimizer-unittest.cc
diff --git a/test/unittests/interpreter/bytecode-peephole-optimizer-unittest.cc b/test/unittests/interpreter/bytecode-peephole-optimizer-unittest.cc
index 671bdf88734f66cead3560772186855909975264..168e0a732294f72182cffc104807a5268447de5e 100644
--- a/test/unittests/interpreter/bytecode-peephole-optimizer-unittest.cc
+++ b/test/unittests/interpreter/bytecode-peephole-optimizer-unittest.cc
@@ -24,6 +24,11 @@ class BytecodePeepholeOptimizerTest : public BytecodePipelineStage,
peephole_optimizer_(&constant_array_builder_, this) {}
~BytecodePeepholeOptimizerTest() override {}
+ void Reset() {
+ last_written_.set_bytecode(Bytecode::kIllegal);
+ write_count_ = 0;
+ }
+
void Write(BytecodeNode* node) override {
write_count_++;
last_written_.Clone(node);
@@ -489,6 +494,84 @@ TEST_F(BytecodePeepholeOptimizerTest, MergeLdaUndefinedStar) {
CHECK_EQ(last_written().bytecode(), third.bytecode());
}
+TEST_F(BytecodePeepholeOptimizerTest, MergeLdaSmiWithBinaryOp) {
+ Bytecode operator_replacement_pairs[][2] = {
+ {Bytecode::kAdd, Bytecode::kAddSmi},
+ {Bytecode::kSub, Bytecode::kSubSmi},
+ {Bytecode::kBitwiseAnd, Bytecode::kBitwiseAndSmi},
+ {Bytecode::kBitwiseOr, Bytecode::kBitwiseOrSmi},
+ {Bytecode::kShiftLeft, Bytecode::kShiftLeftSmi},
+ {Bytecode::kShiftRight, Bytecode::kShiftRightSmi}};
+
+ for (auto operator_replacement : operator_replacement_pairs) {
+ uint32_t imm_operand = 17;
+ BytecodeNode first(Bytecode::kLdaSmi, imm_operand);
+ first.source_info().Clone({3, true});
+ uint32_t reg_operand = Register(0).ToOperand();
+ BytecodeNode second(operator_replacement[0], reg_operand);
+ optimizer()->Write(&first);
+ optimizer()->Write(&second);
+ Flush();
+ CHECK_EQ(write_count(), 1);
+ CHECK_EQ(last_written().bytecode(), operator_replacement[1]);
+ CHECK_EQ(last_written().operand_count(), 2);
+ CHECK_EQ(last_written().operand(0), imm_operand);
+ CHECK_EQ(last_written().operand(1), reg_operand);
+ CHECK_EQ(last_written().source_info(), first.source_info());
+ Reset();
+ }
+}
+
+TEST_F(BytecodePeepholeOptimizerTest, NotMergingLdaSmiWithBinaryOp) {
+ Bytecode operator_replacement_pairs[][2] = {
+ {Bytecode::kAdd, Bytecode::kAddSmi},
+ {Bytecode::kSub, Bytecode::kSubSmi},
+ {Bytecode::kBitwiseAnd, Bytecode::kBitwiseAndSmi},
+ {Bytecode::kBitwiseOr, Bytecode::kBitwiseOrSmi},
+ {Bytecode::kShiftLeft, Bytecode::kShiftLeftSmi},
+ {Bytecode::kShiftRight, Bytecode::kShiftRightSmi}};
+
+ for (auto operator_replacement : operator_replacement_pairs) {
+ uint32_t imm_operand = 17;
+ BytecodeNode first(Bytecode::kLdaSmi, imm_operand);
+ first.source_info().Clone({3, true});
+ uint32_t reg_operand = Register(0).ToOperand();
+ BytecodeNode second(operator_replacement[0], reg_operand);
+ second.source_info().Clone({4, true});
+ optimizer()->Write(&first);
+ optimizer()->Write(&second);
+ CHECK_EQ(last_written(), first);
+ Flush();
+ CHECK_EQ(last_written(), second);
+ Reset();
+ }
+}
+
+TEST_F(BytecodePeepholeOptimizerTest, MergeLdaZeroWithBinaryOp) {
+ Bytecode operator_replacement_pairs[][2] = {
+ {Bytecode::kAdd, Bytecode::kAddSmi},
+ {Bytecode::kSub, Bytecode::kSubSmi},
+ {Bytecode::kBitwiseAnd, Bytecode::kBitwiseAndSmi},
+ {Bytecode::kBitwiseOr, Bytecode::kBitwiseOrSmi},
+ {Bytecode::kShiftLeft, Bytecode::kShiftLeftSmi},
+ {Bytecode::kShiftRight, Bytecode::kShiftRightSmi}};
+
+ for (auto operator_replacement : operator_replacement_pairs) {
+ BytecodeNode first(Bytecode::kLdaZero);
+ uint32_t reg_operand = Register(0).ToOperand();
+ BytecodeNode second(operator_replacement[0], reg_operand);
+ optimizer()->Write(&first);
+ optimizer()->Write(&second);
+ Flush();
+ CHECK_EQ(write_count(), 1);
+ CHECK_EQ(last_written().bytecode(), operator_replacement[1]);
+ CHECK_EQ(last_written().operand_count(), 2);
+ CHECK_EQ(last_written().operand(0), 0);
+ CHECK_EQ(last_written().operand(1), reg_operand);
+ Reset();
+ }
+}
+
} // namespace interpreter
} // namespace internal
} // namespace v8
« no previous file with comments | « test/unittests/interpreter/bytecode-array-iterator-unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698