OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/factory.h" | 7 #include "src/factory.h" |
8 #include "src/interpreter/bytecode-peephole-optimizer.h" | 8 #include "src/interpreter/bytecode-peephole-optimizer.h" |
9 #include "src/interpreter/constant-array-builder.h" | 9 #include "src/interpreter/constant-array-builder.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 CHECK_EQ(write_count(), 0); | 135 CHECK_EQ(write_count(), 0); |
136 optimizer()->Write(&second); | 136 optimizer()->Write(&second); |
137 CHECK_EQ(write_count(), 1); | 137 CHECK_EQ(write_count(), 1); |
138 CHECK_EQ(last_written(), first); | 138 CHECK_EQ(last_written(), first); |
139 optimizer()->FlushBasicBlock(); | 139 optimizer()->FlushBasicBlock(); |
140 CHECK_EQ(write_count(), 2); | 140 CHECK_EQ(write_count(), 2); |
141 CHECK_EQ(last_written().bytecode(), Bytecode::kJumpIfTrue); | 141 CHECK_EQ(last_written().bytecode(), Bytecode::kJumpIfTrue); |
142 CHECK_EQ(last_written().operand(0), second.operand(0)); | 142 CHECK_EQ(last_written().operand(0), second.operand(0)); |
143 } | 143 } |
144 | 144 |
| 145 TEST_F(BytecodePeepholeOptimizerTest, KeepToBooleanLogicalNot) { |
| 146 BytecodeNode first(Bytecode::kLdaNull); |
| 147 BytecodeNode second(Bytecode::kToBooleanLogicalNot); |
| 148 optimizer()->Write(&first); |
| 149 CHECK_EQ(write_count(), 0); |
| 150 optimizer()->Write(&second); |
| 151 CHECK_EQ(write_count(), 1); |
| 152 CHECK_EQ(last_written(), first); |
| 153 optimizer()->FlushBasicBlock(); |
| 154 CHECK_EQ(write_count(), 2); |
| 155 CHECK_EQ(last_written(), second); |
| 156 } |
| 157 |
| 158 TEST_F(BytecodePeepholeOptimizerTest, ElideToBooleanLogicalNot) { |
| 159 BytecodeNode first(Bytecode::kLdaTrue); |
| 160 BytecodeNode second(Bytecode::kToBooleanLogicalNot); |
| 161 optimizer()->Write(&first); |
| 162 CHECK_EQ(write_count(), 0); |
| 163 optimizer()->Write(&second); |
| 164 CHECK_EQ(write_count(), 1); |
| 165 CHECK_EQ(last_written(), first); |
| 166 optimizer()->FlushBasicBlock(); |
| 167 CHECK_EQ(write_count(), 2); |
| 168 CHECK_EQ(last_written().bytecode(), Bytecode::kLogicalNot); |
| 169 } |
| 170 |
145 // Tests covering BytecodePeepholeOptimizer::CanElideCurrent(). | 171 // Tests covering BytecodePeepholeOptimizer::CanElideCurrent(). |
146 | 172 |
147 TEST_F(BytecodePeepholeOptimizerTest, LdarRxLdarRy) { | 173 TEST_F(BytecodePeepholeOptimizerTest, LdarRxLdarRy) { |
148 BytecodeNode first(Bytecode::kLdar, Register(0).ToOperand(), | 174 BytecodeNode first(Bytecode::kLdar, Register(0).ToOperand(), |
149 OperandScale::kSingle); | 175 OperandScale::kSingle); |
150 BytecodeNode second(Bytecode::kLdar, Register(1).ToOperand(), | 176 BytecodeNode second(Bytecode::kLdar, Register(1).ToOperand(), |
151 OperandScale::kSingle); | 177 OperandScale::kSingle); |
152 optimizer()->Write(&first); | 178 optimizer()->Write(&first); |
153 optimizer()->FlushForOffset(); // Prevent CanElideLast removing |first|. | 179 optimizer()->FlushForOffset(); // Prevent CanElideLast removing |first|. |
154 CHECK_EQ(write_count(), 0); | 180 CHECK_EQ(write_count(), 0); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 CHECK_EQ(write_count(), 0); | 376 CHECK_EQ(write_count(), 0); |
351 optimizer()->FlushBasicBlock(); | 377 optimizer()->FlushBasicBlock(); |
352 CHECK_EQ(write_count(), 1); | 378 CHECK_EQ(write_count(), 1); |
353 second.source_info().Update(first.source_info()); | 379 second.source_info().Update(first.source_info()); |
354 CHECK_EQ(last_written(), second); | 380 CHECK_EQ(last_written(), second); |
355 } | 381 } |
356 | 382 |
357 } // namespace interpreter | 383 } // namespace interpreter |
358 } // namespace internal | 384 } // namespace internal |
359 } // namespace v8 | 385 } // namespace v8 |
OLD | NEW |