Index: test/unittests/interpreter/bytecode-array-builder-unittest.cc |
diff --git a/test/unittests/interpreter/bytecode-array-builder-unittest.cc b/test/unittests/interpreter/bytecode-array-builder-unittest.cc |
index 68995a714af9d52dc21803c6a1c9338b55972abd..a050d5bcfdb9c561ec0f3ce3c17e5a60a3dac27f 100644 |
--- a/test/unittests/interpreter/bytecode-array-builder-unittest.cc |
+++ b/test/unittests/interpreter/bytecode-array-builder-unittest.cc |
@@ -6,6 +6,7 @@ |
#include "src/interpreter/bytecode-array-builder.h" |
#include "src/interpreter/bytecode-array-iterator.h" |
+#include "src/interpreter/bytecode-label.h" |
#include "src/interpreter/bytecode-register-allocator.h" |
#include "test/unittests/test-utils.h" |
@@ -277,6 +278,19 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { |
.StoreLookupSlot(wide_name, LanguageMode::SLOPPY) |
.StoreLookupSlot(wide_name, LanguageMode::STRICT); |
+ // Emit loads which will be transformed to Ldr equivalents by the peephole |
+ // optimizer. |
+ builder.LoadNamedProperty(reg, name, 0) |
+ .StoreAccumulatorInRegister(reg) |
+ .LoadKeyedProperty(reg, 0) |
+ .StoreAccumulatorInRegister(reg) |
+ .LoadContextSlot(reg, 1) |
+ .StoreAccumulatorInRegister(reg) |
+ .LoadGlobal(name, 0, TypeofMode::NOT_INSIDE_TYPEOF) |
+ .StoreAccumulatorInRegister(reg) |
+ .LoadUndefined() |
+ .StoreAccumulatorInRegister(reg); |
+ |
// CreateClosureWide |
Handle<SharedFunctionInfo> shared_info2 = factory->NewSharedFunctionInfo( |
factory->NewStringFromStaticChars("function_b"), MaybeHandle<Code>(), |
@@ -352,12 +366,20 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { |
// Insert entry for nop bytecode as this often gets optimized out. |
scorecard[Bytecodes::ToByte(Bytecode::kNop)] = 1; |
- // Insert entries for bytecodes only emiited by peephole optimizer. |
- scorecard[Bytecodes::ToByte(Bytecode::kLdrNamedProperty)] = 1; |
- scorecard[Bytecodes::ToByte(Bytecode::kLdrKeyedProperty)] = 1; |
- scorecard[Bytecodes::ToByte(Bytecode::kLdrGlobal)] = 1; |
- scorecard[Bytecodes::ToByte(Bytecode::kLdrContextSlot)] = 1; |
- scorecard[Bytecodes::ToByte(Bytecode::kLdrUndefined)] = 1; |
+ if (!FLAG_ignition_peephole) { |
+ // Insert entries for bytecodes only emitted by peephole optimizer. |
+ scorecard[Bytecodes::ToByte(Bytecode::kLdrNamedProperty)] = 1; |
+ scorecard[Bytecodes::ToByte(Bytecode::kLdrKeyedProperty)] = 1; |
+ scorecard[Bytecodes::ToByte(Bytecode::kLdrGlobal)] = 1; |
+ scorecard[Bytecodes::ToByte(Bytecode::kLdrContextSlot)] = 1; |
+ scorecard[Bytecodes::ToByte(Bytecode::kLdrUndefined)] = 1; |
+ scorecard[Bytecodes::ToByte(Bytecode::kLogicalNot)] = 1; |
+ scorecard[Bytecodes::ToByte(Bytecode::kJump)] = 1; |
+ scorecard[Bytecodes::ToByte(Bytecode::kJumpIfTrue)] = 1; |
+ scorecard[Bytecodes::ToByte(Bytecode::kJumpIfFalse)] = 1; |
+ scorecard[Bytecodes::ToByte(Bytecode::kJumpIfTrueConstant)] = 1; |
+ scorecard[Bytecodes::ToByte(Bytecode::kJumpIfFalseConstant)] = 1; |
+ } |
// Check return occurs at the end and only once in the BytecodeArray. |
CHECK_EQ(final_bytecode, Bytecode::kReturn); |
@@ -470,6 +492,11 @@ TEST_F(BytecodeArrayBuilderTest, Constants) { |
CHECK_EQ(array->constant_pool()->length(), 3); |
} |
+static Bytecode PeepholeToBoolean(Bytecode jump_bytecode) { |
+ return FLAG_ignition_peephole |
+ ? Bytecodes::GetJumpWithoutToBoolean(jump_bytecode) |
+ : jump_bytecode; |
+} |
TEST_F(BytecodeArrayBuilderTest, ForwardJumps) { |
static const int kFarJumpDistance = 256; |
@@ -520,14 +547,16 @@ TEST_F(BytecodeArrayBuilderTest, ForwardJumps) { |
// Ignore compare operation. |
iterator.Advance(); |
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrue); |
+ CHECK_EQ(iterator.current_bytecode(), |
+ PeepholeToBoolean(Bytecode::kJumpIfToBooleanTrue)); |
CHECK_EQ(iterator.GetImmediateOperand(0), 14); |
iterator.Advance(); |
// Ignore compare operation. |
iterator.Advance(); |
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalse); |
+ CHECK_EQ(iterator.current_bytecode(), |
+ PeepholeToBoolean(Bytecode::kJumpIfToBooleanFalse)); |
CHECK_EQ(iterator.GetImmediateOperand(0), 10); |
iterator.Advance(); |
@@ -553,7 +582,8 @@ TEST_F(BytecodeArrayBuilderTest, ForwardJumps) { |
// Ignore compare operation. |
iterator.Advance(); |
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrueConstant); |
+ CHECK_EQ(iterator.current_bytecode(), |
+ PeepholeToBoolean(Bytecode::kJumpIfToBooleanTrueConstant)); |
CHECK_EQ(*iterator.GetConstantForIndexOperand(0), |
Smi::FromInt(kFarJumpDistance - 4)); |
iterator.Advance(); |
@@ -561,7 +591,8 @@ TEST_F(BytecodeArrayBuilderTest, ForwardJumps) { |
// Ignore compare operation. |
iterator.Advance(); |
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalseConstant); |
+ CHECK_EQ(iterator.current_bytecode(), |
+ PeepholeToBoolean(Bytecode::kJumpIfToBooleanFalseConstant)); |
CHECK_EQ(*iterator.GetConstantForIndexOperand(0), |
Smi::FromInt(kFarJumpDistance - 8)); |
iterator.Advance(); |
@@ -628,13 +659,15 @@ TEST_F(BytecodeArrayBuilderTest, BackwardJumps) { |
iterator.Advance(); |
// Ignore compare operation. |
iterator.Advance(); |
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrue); |
+ CHECK_EQ(iterator.current_bytecode(), |
+ PeepholeToBoolean(Bytecode::kJumpIfToBooleanTrue)); |
CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
CHECK_EQ(iterator.GetImmediateOperand(0), -2); |
iterator.Advance(); |
// Ignore compare operation. |
iterator.Advance(); |
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalse); |
+ CHECK_EQ(iterator.current_bytecode(), |
+ PeepholeToBoolean(Bytecode::kJumpIfToBooleanFalse)); |
CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
CHECK_EQ(iterator.GetImmediateOperand(0), -2); |
iterator.Advance(); |
@@ -675,13 +708,15 @@ TEST_F(BytecodeArrayBuilderTest, BackwardJumps) { |
iterator.Advance(); |
// Ignore compare operation. |
iterator.Advance(); |
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalse); |
+ CHECK_EQ(iterator.current_bytecode(), |
+ PeepholeToBoolean(Bytecode::kJumpIfToBooleanFalse)); |
CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble); |
CHECK_EQ(iterator.GetImmediateOperand(0), -409); |
iterator.Advance(); |
// Ignore compare operation. |
iterator.Advance(); |
- CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrue); |
+ CHECK_EQ(iterator.current_bytecode(), |
+ PeepholeToBoolean(Bytecode::kJumpIfToBooleanTrue)); |
CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble); |
CHECK_EQ(iterator.GetImmediateOperand(0), -419); |
iterator.Advance(); |