Inline immutable property loads
authorverwaest@chromium.org <verwaest@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 11 Apr 2014 13:07:10 +0000 (13:07 +0000)
committerverwaest@chromium.org <verwaest@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 11 Apr 2014 13:07:10 +0000 (13:07 +0000)
When a non-configurable, non-writable field is
read from a constant holder, the load is
eliminated and replaced with the direct value
of the field

BUG=
R=verwaest@chromium.org

Review URL: https://codereview.chromium.org/232853002

Patch from Petka Antonov <p.antonov@partner.samsung.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20690 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/hydrogen.cc

index 96f4e78..cf34517 100644 (file)
@@ -5341,6 +5341,24 @@ HCheckMaps* HOptimizedGraphBuilder::AddCheckMap(HValue* object,
 HInstruction* HOptimizedGraphBuilder::BuildLoadNamedField(
     PropertyAccessInfo* info,
     HValue* checked_object) {
+  // See if this is a load for an immutable property
+  if (checked_object->ActualValue()->IsConstant() &&
+      info->lookup()->IsCacheable() &&
+      info->lookup()->IsReadOnly() && info->lookup()->IsDontDelete()) {
+    Handle<Object> object(
+        HConstant::cast(checked_object->ActualValue())->handle(isolate()));
+
+    if (object->IsJSObject()) {
+      LookupResult lookup(isolate());
+      Handle<JSObject>::cast(object)->Lookup(*info->name(), &lookup);
+      Handle<Object> value(lookup.GetLazyValue(), isolate());
+
+      if (!value->IsTheHole()) {
+        return New<HConstant>(value);
+      }
+    }
+  }
+
   HObjectAccess access = info->access();
   if (access.representation().IsDouble()) {
     // Load the heap number.