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

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: 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 | « src/compiler/bytecode-graph-builder.cc ('k') | src/interpreter/bytecode-pipeline.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..cd668d4a67fa1d551a81605e7941b929e17a77af 100644
--- a/src/interpreter/bytecode-peephole-optimizer.cc
+++ b/src/interpreter/bytecode-peephole-optimizer.cc
@@ -125,7 +125,8 @@ bool BytecodePeepholeOptimizer::CanElideCurrent(
return true;
} else {
// Additional candidates for eliding current:
- // (i) ToNumber if the last puts a number in the accumulator.
+ // (i) current is Nop.
+ // (ii) ToNumber if the last puts a number in the accumulator.
return false;
}
}
@@ -188,6 +189,18 @@ 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) {
+ DCHECK(Bytecodes::IsLdaSmiOrLdaZero(last->bytecode()));
+ uint32_t imm_operand =
+ last->bytecode() == Bytecode::kLdaSmi ? last->operand(0) : 0;
+ current->set_bytecode(new_bytecode, imm_operand, current->operand(0));
+ if (last->source_info().is_valid()) {
+ current->source_info().Clone(last->source_info());
+ }
+}
+
} // namespace
bool BytecodePeepholeOptimizer::TransformLastAndCurrentBytecodes(
@@ -216,7 +229,43 @@ bool BytecodePeepholeOptimizer::TransformLastAndCurrentBytecodes(
default:
break;
}
+ } else if (Bytecodes::IsLdaSmiOrLdaZero(last_.bytecode()) &&
+ (!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;
+ }
}
+
return false;
}
@@ -279,7 +328,6 @@ bool BytecodePeepholeOptimizer::CanElideLast(
BytecodeNode* BytecodePeepholeOptimizer::Optimize(BytecodeNode* current) {
TryToRemoveLastExpressionPosition(current);
-
if (TransformCurrentBytecode(current) ||
TransformLastAndCurrentBytecodes(current)) {
return current;
« no previous file with comments | « src/compiler/bytecode-graph-builder.cc ('k') | src/interpreter/bytecode-pipeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698