Index: src/interpreter/bytecode-peephole-optimizer.cc |
diff --git a/src/interpreter/bytecode-peephole-optimizer.cc b/src/interpreter/bytecode-peephole-optimizer.cc |
index 1108d8304f855f74dcd5b3f6e2965104f068684c..8209b452a98fd286add8293eaafdff436fcee610 100644 |
--- a/src/interpreter/bytecode-peephole-optimizer.cc |
+++ b/src/interpreter/bytecode-peephole-optimizer.cc |
@@ -126,7 +126,7 @@ bool BytecodePeepholeOptimizer::CanElideCurrent( |
} else { |
// Additional candidates for eliding current: |
// (i) ToNumber if the last puts a number in the accumulator. |
- return false; |
+ return current->bytecode() == Bytecode::kNop; |
rmcilroy
2016/07/04 12:35:32
Can we do this in a separate CL please, so we can
oth
2016/07/04 14:56:24
Done.
|
} |
} |
@@ -188,6 +188,16 @@ void TransformLdaStarToLdrLdar(Bytecode new_bytecode, BytecodeNode* const last, |
current->set_bytecode(Bytecode::kLdar, current->operand(0)); |
} |
+void TransformToBinaryOpWithSmiOnRhs(Bytecode new_bytecode, |
+ BytecodeNode* const last, |
+ BytecodeNode* const current) { |
+ uint32_t smi_operand = last->operand(0); |
+ current->set_bytecode(new_bytecode, smi_operand, current->operand(0)); |
+ if (last->source_info().is_valid()) { |
+ current->source_info().Clone(last->source_info()); |
+ } |
+} |
+ |
} // namespace |
bool BytecodePeepholeOptimizer::TransformLastAndCurrentBytecodes( |
@@ -216,7 +226,50 @@ bool BytecodePeepholeOptimizer::TransformLastAndCurrentBytecodes( |
default: |
break; |
} |
+ } else if (last_.bytecode() == Bytecode::kLdaSmi && |
+ (!last_.source_info().is_valid() || |
+ !current->source_info().is_valid())) { |
+ switch (current->bytecode()) { |
+ case Bytecode::kAdd: |
+ TransformToBinaryOpWithSmiOnRhs(Bytecode::kAddSmi, &last_, current); |
+ InvalidateLast(); |
+ return true; |
+ case Bytecode::kSub: |
+ TransformToBinaryOpWithSmiOnRhs(Bytecode::kSubSmi, &last_, current); |
+ InvalidateLast(); |
+ return true; |
+ case Bytecode::kBitwiseOr: |
+ TransformToBinaryOpWithSmiOnRhs(Bytecode::kBitwiseOrSmi, &last_, |
+ current); |
+ InvalidateLast(); |
+ return true; |
+ case Bytecode::kBitwiseAnd: |
+ TransformToBinaryOpWithSmiOnRhs(Bytecode::kBitwiseAndSmi, &last_, |
+ current); |
+ InvalidateLast(); |
+ return true; |
+ case Bytecode::kShiftLeft: |
+ TransformToBinaryOpWithSmiOnRhs(Bytecode::kShiftLeftSmi, &last_, |
+ current); |
+ InvalidateLast(); |
+ return true; |
+ case Bytecode::kShiftRight: |
+ TransformToBinaryOpWithSmiOnRhs(Bytecode::kShiftRightSmi, &last_, |
+ current); |
+ InvalidateLast(); |
+ return true; |
+ default: |
+ break; |
+ } |
+ } else if (last_.bytecode() == Bytecode::kLdaZero && |
rmcilroy
2016/07/04 12:35:32
Can we not also do the LdaZero optimization for al
oth
2016/07/04 14:56:24
Done. This was skipped due to low numbers of occur
|
+ current->bytecode() == Bytecode::kBitwiseOr && |
+ !current->source_info().is_valid()) { |
+ current->set_bytecode(Bytecode::kBitwiseOrSmi, 0, current->operand(0)); |
+ current->source_info().Clone(last_.source_info()); |
+ InvalidateLast(); |
+ return true; |
} |
+ |
return false; |
} |
@@ -279,7 +332,6 @@ bool BytecodePeepholeOptimizer::CanElideLast( |
BytecodeNode* BytecodePeepholeOptimizer::Optimize(BytecodeNode* current) { |
TryToRemoveLastExpressionPosition(current); |
- |
if (TransformCurrentBytecode(current) || |
TransformLastAndCurrentBytecodes(current)) { |
return current; |