Index: src/hydrogen.cc |
diff --git a/src/hydrogen.cc b/src/hydrogen.cc |
index 756c6ee6d4b3e967190bd4db0bc8020f4bbd8651..57e63963c0ec29ba61a5442cf9ab120070739819 100644 |
--- a/src/hydrogen.cc |
+++ b/src/hydrogen.cc |
@@ -5464,7 +5464,9 @@ void HOptimizedGraphBuilder::VisitVariableProxy(VariableProxy* expr) { |
if (type == kUseCell) { |
Handle<PropertyCell> cell = it.GetPropertyCell(); |
top_info()->dependencies()->AssumePropertyCell(cell); |
- if (it.property_details().cell_type() == PropertyCellType::kConstant) { |
+ auto cell_type = it.property_details().cell_type(); |
+ if (cell_type == PropertyCellType::kConstant || |
+ cell_type == PropertyCellType::kUndefined) { |
Handle<Object> constant_object(cell->value(), isolate()); |
if (constant_object->IsConsString()) { |
constant_object = |
@@ -5473,9 +5475,37 @@ void HOptimizedGraphBuilder::VisitVariableProxy(VariableProxy* expr) { |
HConstant* constant = New<HConstant>(constant_object); |
return ast_context()->ReturnInstruction(constant, expr->id()); |
} else { |
+ auto access = HObjectAccess::ForPropertyCellValue(); |
+ UniqueSet<Map>* field_maps = nullptr; |
+ if (cell_type == PropertyCellType::kConstantType) { |
+ switch (cell->GetConstantType()) { |
+ case PropertyCellConstantType::kSmi: |
+ access = access.WithRepresentation(Representation::Smi()); |
+ break; |
+ case PropertyCellConstantType::kStableMap: { |
+ // Check that the map really is stable. The heap object could |
+ // have mutated without the cell updating state. In that case, |
+ // make no promises about the loaded value except that it's a |
+ // heap object. |
+ access = |
+ access.WithRepresentation(Representation::HeapObject()); |
+ Handle<Map> map(HeapObject::cast(cell->value())->map()); |
+ if (map->is_stable()) { |
+ field_maps = new (zone()) |
+ UniqueSet<Map>(Unique<Map>::CreateImmovable(map), zone()); |
+ } |
+ break; |
+ } |
+ } |
+ } |
HConstant* cell_constant = Add<HConstant>(cell); |
- HLoadNamedField* instr = New<HLoadNamedField>( |
- cell_constant, nullptr, HObjectAccess::ForPropertyCellValue()); |
+ HLoadNamedField* instr; |
+ if (field_maps == nullptr) { |
+ instr = New<HLoadNamedField>(cell_constant, nullptr, access); |
+ } else { |
+ instr = New<HLoadNamedField>(cell_constant, nullptr, access, |
+ field_maps, HType::HeapObject()); |
+ } |
instr->ClearDependsOnFlag(kInobjectFields); |
instr->SetDependsOnFlag(kGlobalVars); |
return ast_context()->ReturnInstruction(instr, expr->id()); |
@@ -6649,7 +6679,9 @@ void HOptimizedGraphBuilder::HandleGlobalVariableAssignment( |
if (type == kUseCell) { |
Handle<PropertyCell> cell = it.GetPropertyCell(); |
top_info()->dependencies()->AssumePropertyCell(cell); |
- if (it.property_details().cell_type() == PropertyCellType::kConstant) { |
+ auto cell_type = it.property_details().cell_type(); |
+ if (cell_type == PropertyCellType::kConstant || |
+ cell_type == PropertyCellType::kUndefined) { |
Handle<Object> constant(cell->value(), isolate()); |
if (value->IsConstant()) { |
HConstant* c_value = HConstant::cast(value); |
@@ -6673,8 +6705,24 @@ void HOptimizedGraphBuilder::HandleGlobalVariableAssignment( |
} |
} |
HConstant* cell_constant = Add<HConstant>(cell); |
- HInstruction* instr = Add<HStoreNamedField>( |
- cell_constant, HObjectAccess::ForPropertyCellValue(), value); |
+ auto access = HObjectAccess::ForPropertyCellValue(); |
+ if (cell_type == PropertyCellType::kConstantType) { |
+ switch (cell->GetConstantType()) { |
+ case PropertyCellConstantType::kSmi: |
+ access = access.WithRepresentation(Representation::Smi()); |
+ break; |
+ case PropertyCellConstantType::kStableMap: { |
+ // The map may no longer be stable, deopt if it's ever different from |
+ // what is currently there, which will allow for restablization. |
+ Handle<Map> map(HeapObject::cast(cell->value())->map()); |
+ Add<HCheckHeapObject>(value); |
+ value = Add<HCheckMaps>(value, map); |
+ access = access.WithRepresentation(Representation::HeapObject()); |
+ break; |
+ } |
+ } |
+ } |
+ HInstruction* instr = Add<HStoreNamedField>(cell_constant, access, value); |
instr->ClearChangesFlag(kInobjectFields); |
instr->SetChangesFlag(kGlobalVars); |
if (instr->HasObservableSideEffects()) { |