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

Unified Diff: src/interpreter/bytecode-peephole-optimizer.cc

Issue 2111923002: [interpreter] Introduce binary op bytecodes for Smi operand. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Tweak a name. 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
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;

Powered by Google App Engine
This is Rietveld 408576698