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

Unified Diff: src/interpreter/bytecode-generator.cc

Issue 2793923002: [Interpreter] Optimize code of the form 'if (x === undefined)'. (Closed)
Patch Set: Rebase Created 3 years, 9 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/interpreter/bytecode-generator.h ('k') | src/interpreter/bytecode-peephole-optimizer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/interpreter/bytecode-generator.cc
diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc
index 14bfeb4d0230cc387445bb5f78d18fb697735f9c..06f819e4a99c4cdf9580091c073d5a6bce6d074e 100644
--- a/src/interpreter/bytecode-generator.cc
+++ b/src/interpreter/bytecode-generator.cc
@@ -3040,13 +3040,34 @@ void BytecodeGenerator::VisitBinaryOperation(BinaryOperation* binop) {
}
}
+void BytecodeGenerator::BuildLiteralCompareNil(Token::Value op, NilValue nil) {
+ if (execution_result()->IsTest()) {
+ TestResultScope* test_result = execution_result()->AsTest();
+ switch (test_result->fallthrough()) {
+ case TestFallthrough::kThen:
+ builder()->JumpIfNotNil(test_result->NewElseLabel(), op, nil);
+ break;
+ case TestFallthrough::kElse:
+ builder()->JumpIfNil(test_result->NewThenLabel(), op, nil);
+ break;
+ case TestFallthrough::kNone:
+ builder()
+ ->JumpIfNil(test_result->NewThenLabel(), op, nil)
+ .Jump(test_result->NewElseLabel());
+ }
+ test_result->SetResultConsumedByTest();
+ } else {
+ builder()->CompareNil(op, nil);
+ }
+}
+
void BytecodeGenerator::VisitCompareOperation(CompareOperation* expr) {
- // Emit a fast literal comparion for expressions of the form:
- // typeof(x) === 'string'.
- Expression* typeof_sub_expr;
+ Expression* sub_expr;
Literal* literal;
- if (expr->IsLiteralCompareTypeof(&typeof_sub_expr, &literal)) {
- VisitForTypeOfValue(typeof_sub_expr);
+ if (expr->IsLiteralCompareTypeof(&sub_expr, &literal)) {
+ // Emit a fast literal comparion for expressions of the form:
+ // typeof(x) === 'string'.
+ VisitForTypeOfValue(sub_expr);
builder()->SetExpressionPosition(expr);
TestTypeOfFlags::LiteralFlag literal_flag =
TestTypeOfFlags::GetFlagForLiteral(ast_string_constants(), literal);
@@ -3055,6 +3076,14 @@ void BytecodeGenerator::VisitCompareOperation(CompareOperation* expr) {
} else {
builder()->CompareTypeOf(literal_flag);
}
+ } else if (expr->IsLiteralCompareUndefined(&sub_expr)) {
+ VisitForAccumulatorValue(sub_expr);
+ builder()->SetExpressionPosition(expr);
+ BuildLiteralCompareNil(expr->op(), kUndefinedValue);
+ } else if (expr->IsLiteralCompareNull(&sub_expr)) {
+ VisitForAccumulatorValue(sub_expr);
+ builder()->SetExpressionPosition(expr);
+ BuildLiteralCompareNil(expr->op(), kNullValue);
} else {
Register lhs = VisitForRegisterValue(expr->left());
VisitForAccumulatorValue(expr->right());
« no previous file with comments | « src/interpreter/bytecode-generator.h ('k') | src/interpreter/bytecode-peephole-optimizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698