[x86] Improve code generation for context materialization.
authorBenedikt Meurer <bmeurer@chromium.org>
Mon, 2 Mar 2015 09:09:33 +0000 (10:09 +0100)
committerBenedikt Meurer <bmeurer@chromium.org>
Mon, 2 Mar 2015 09:09:42 +0000 (09:09 +0000)
On Intel targets, it is cheaper to load the context from the frame
instead of loading the context as a constant (which usually involves a
PropertyCell because the context is in new space when we compile the
function).

R=jarin@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#26935}

src/compiler/ia32/code-generator-ia32.cc
src/compiler/x64/code-generator-x64.cc

index 7864d90a82672afc5c866125db897eb6b0b3f12c..3cb3d40539ca7a9e6e1a43d6275d86f6397a4277 100644 (file)
@@ -1119,7 +1119,19 @@ void CodeGenerator::AssembleMove(InstructionOperand* source,
     Constant src_constant = g.ToConstant(source);
     if (src_constant.type() == Constant::kHeapObject) {
       Handle<HeapObject> src = src_constant.ToHeapObject();
-      if (destination->IsRegister()) {
+      if (info()->IsOptimizing() && src.is_identical_to(info()->context())) {
+        // Loading the context from the frame is way cheaper than materializing
+        // the actual context heap object address.
+        if (destination->IsRegister()) {
+          Register dst = g.ToRegister(destination);
+          __ mov(dst, Operand(ebp, StandardFrameConstants::kContextOffset));
+        } else {
+          DCHECK(destination->IsStackSlot());
+          Operand dst = g.ToOperand(destination);
+          __ push(Operand(ebp, StandardFrameConstants::kContextOffset));
+          __ pop(dst);
+        }
+      } else if (destination->IsRegister()) {
         Register dst = g.ToRegister(destination);
         __ LoadHeapObject(dst, src);
       } else {
index db5a448adc9a0ee689421edeedbd843c58ad2dba..be28bf74d589b5ef08359d6349af79a277c88ef6 100644 (file)
@@ -1309,9 +1309,18 @@ void CodeGenerator::AssembleMove(InstructionOperand* source,
         case Constant::kExternalReference:
           __ Move(dst, src.ToExternalReference());
           break;
-        case Constant::kHeapObject:
-          __ Move(dst, src.ToHeapObject());
+        case Constant::kHeapObject: {
+          Handle<HeapObject> src_object = src.ToHeapObject();
+          if (info()->IsOptimizing() &&
+              src_object.is_identical_to(info()->context())) {
+            // Loading the context from the frame is way cheaper than
+            // materializing the actual context heap object address.
+            __ movp(dst, Operand(rbp, StandardFrameConstants::kContextOffset));
+          } else {
+            __ Move(dst, src_object);
+          }
           break;
+        }
         case Constant::kRpoNumber:
           UNREACHABLE();  // TODO(dcarney): load of labels on x64.
           break;