Index: src/hydrogen.cc |
diff --git a/src/hydrogen.cc b/src/hydrogen.cc |
index 58a9b78750bb7401bfdc9e167800f8f01d3ef078..541e9b90dfa5ac658f3ed99f197e14646819f4e7 100644 |
--- a/src/hydrogen.cc |
+++ b/src/hydrogen.cc |
@@ -7192,6 +7192,51 @@ void HOptimizedGraphBuilder::HandlePolymorphicStoreNamedField( |
HValue* value, |
SmallMapList* types, |
Handle<String> name) { |
+ if (types->length() <= kMaxStorePolymorphism) { |
+ int previous_field_offset = 0; |
+ bool previous_field_is_in_object = false; |
+ Representation previous_representation = Representation::None(); |
+ |
+ Handle<Map> map; |
+ LookupResult lookup(isolate()); |
+ int count; |
+ for (count = 0; count < types->length(); ++count) { |
+ map = types->at(count); |
+ if (!ComputeLoadStoreField(map, name, &lookup, false) || |
+ lookup.IsTransition()) { |
+ break; |
+ } |
+ Representation representation = lookup.representation(); |
+ int index = ComputeLoadStoreFieldIndex(map, &lookup); |
+ bool is_in_object = index < 0; |
+ int offset = index * kPointerSize; |
+ if (index < 0) { |
+ offset += map->instance_size(); |
+ } else { |
+ offset += FixedArray::kHeaderSize; |
+ } |
+ if (count == 0) { |
+ previous_field_offset = offset; |
+ previous_field_is_in_object = is_in_object; |
+ previous_representation = representation; |
+ } else if (offset != previous_field_offset || |
+ is_in_object != previous_field_is_in_object || |
+ !representation.IsCompatibleForStore( |
+ previous_representation)) { |
+ break; |
+ } |
+ } |
+ |
+ if (types->length() == count) { |
+ AddInstruction(new(zone()) HCheckNonSmi(object)); |
+ AddInstruction(HCheckMaps::New(object, types, zone())); |
+ HInstruction* instr = BuildStoreNamedField( |
+ object, name, value, map, &lookup); |
+ instr->set_position(expr->position()); |
+ return ast_context()->ReturnInstruction(instr, expr->id()); |
+ } |
+ } |
+ |
// TODO(ager): We should recognize when the prototype chains for different |
// maps are identical. In that case we can avoid repeatedly generating the |
// same prototype map checks. |