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 {
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;