Index: src/compiler/ia32/code-generator-ia32.cc |
diff --git a/src/compiler/ia32/code-generator-ia32.cc b/src/compiler/ia32/code-generator-ia32.cc |
index 2b8cf08cb71e81eb286fbed3009e2a33484fb48d..2e54e2a6341654c0e5bee142b65cba715c7c34b6 100644 |
--- a/src/compiler/ia32/code-generator-ia32.cc |
+++ b/src/compiler/ia32/code-generator-ia32.cc |
@@ -649,7 +649,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( |
break; |
} |
case kArchRet: |
- AssembleReturn(); |
+ AssembleReturn(instr->InputAt(0)); |
break; |
case kArchStackPointer: |
__ mov(i.OutputRegister(), esp); |
@@ -1981,8 +1981,7 @@ void CodeGenerator::AssembleConstructFrame() { |
} |
} |
- |
-void CodeGenerator::AssembleReturn() { |
+void CodeGenerator::AssembleReturn(InstructionOperand* pop) { |
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); |
const RegList saves = descriptor->CalleeSavedRegisters(); |
@@ -1994,22 +1993,41 @@ void CodeGenerator::AssembleReturn() { |
} |
} |
+ // Might need ecx for scratch if pop_size is too big or if there is a variable |
+ // pop count. |
+ DCHECK_EQ(0u, descriptor->CalleeSavedRegisters() & ecx.bit()); |
+ size_t pop_size = descriptor->StackParameterCount() * kPointerSize; |
+ IA32OperandConverter g(this, nullptr); |
if (descriptor->IsCFunctionCall()) { |
AssembleDeconstructFrame(); |
} else if (frame_access_state()->has_frame()) { |
- // Canonicalize JSFunction return sites for now. |
- if (return_label_.is_bound()) { |
- __ jmp(&return_label_); |
- return; |
+ // Canonicalize JSFunction return sites for now if they always have the same |
+ // number of return args. |
+ if (pop->IsImmediate() && g.ToConstant(pop).ToInt32() == 0) { |
+ if (return_label_.is_bound()) { |
+ __ jmp(&return_label_); |
+ return; |
+ } else { |
+ __ bind(&return_label_); |
+ AssembleDeconstructFrame(); |
+ } |
} else { |
- __ bind(&return_label_); |
AssembleDeconstructFrame(); |
} |
} |
- size_t pop_size = descriptor->StackParameterCount() * kPointerSize; |
- // Might need ecx for scratch if pop_size is too big. |
+ DCHECK_EQ(0u, descriptor->CalleeSavedRegisters() & edx.bit()); |
DCHECK_EQ(0u, descriptor->CalleeSavedRegisters() & ecx.bit()); |
- __ Ret(static_cast<int>(pop_size), ecx); |
+ if (pop->IsImmediate()) { |
+ DCHECK_EQ(Constant::kInt32, g.ToConstant(pop).type()); |
+ pop_size += g.ToConstant(pop).ToInt32() * kPointerSize; |
+ __ Ret(static_cast<int>(pop_size), ecx); |
+ } else { |
+ Register pop_reg = g.ToRegister(pop); |
+ Register scratch_reg = pop_reg.is(ecx) ? edx : ecx; |
+ __ pop(scratch_reg); |
+ __ lea(esp, Operand(esp, pop_reg, times_4, static_cast<int>(pop_size))); |
+ __ jmp(scratch_reg); |
+ } |
} |