Index: src/compiler/ast-graph-builder.cc |
diff --git a/src/compiler/ast-graph-builder.cc b/src/compiler/ast-graph-builder.cc |
index 2da3cfe1b2f24ad42d67b4baf1459d37a175e421..9f6d17c3a872f077f9e1f4fb68b1fc797e1b588b 100644 |
--- a/src/compiler/ast-graph-builder.cc |
+++ b/src/compiler/ast-graph-builder.cc |
@@ -3289,6 +3289,13 @@ Node* AstGraphBuilder::BuildVariableLoad(Variable* variable, |
case VariableLocation::GLOBAL: |
case VariableLocation::UNALLOCATED: { |
// Global var, const, or let variable. |
+ Handle<Name> name = variable->name(); |
+ Handle<Object> constant_value = |
+ jsgraph()->isolate()->factory()->GlobalConstantFor(name); |
+ if (!constant_value.is_null()) { |
+ // Optimize global constants like "undefined", "Infinity", and "NaN". |
+ return jsgraph()->Constant(constant_value); |
+ } |
Node* script_context = current_context(); |
int slot_index = -1; |
if (variable->index() > 0) { |
@@ -3302,7 +3309,6 @@ Node* AstGraphBuilder::BuildVariableLoad(Variable* variable, |
} |
} |
Node* global = BuildLoadGlobalObject(); |
- Handle<Name> name = variable->name(); |
Node* value = BuildGlobalLoad(script_context, global, name, feedback, |
typeof_mode, slot_index); |
states.AddToNode(value, bailout_id, combine); |