From: Evan Cheng Date: Wed, 18 Jul 2007 21:26:06 +0000 (+0000) Subject: Use MOV instead of LEA to restore ESP if callee-saved frame size is 0; if previous... X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=3c46eefba2e2c0ab6e5aae18229c52a49b4fde29;p=oota-llvm.git Use MOV instead of LEA to restore ESP if callee-saved frame size is 0; if previous instruction updates esp, fold it in. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40018 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp index da65db03e4b..b64d864d65f 100644 --- a/lib/Target/X86/X86RegisterInfo.cpp +++ b/lib/Target/X86/X86RegisterInfo.cpp @@ -1361,17 +1361,7 @@ void X86RegisterInfo::emitEpilogue(MachineFunction &MF, --MBBI; } - // If dynamic alloca is used, then reset esp to point to the last - // callee-saved slot before popping them off! - if (MFI->hasVarSizedObjects()) { - unsigned Opc = Is64Bit ? X86::LEA64r : X86::LEA32r; - MachineInstr *MI = addRegOffset(BuildMI(TII.get(Opc), StackPtr), - FramePtr, -CSSize); - MBB.insert(MBBI, MI); - NumBytes = 0; - } - - if (NumBytes) { // adjust stack pointer back: ESP += numbytes + if (NumBytes || MFI->hasVarSizedObjects()) { // If there is an ADD32ri or SUB32ri of ESP immediately before this // instruction, merge the two instructions. if (MBBI != MBB.begin()) { @@ -1389,11 +1379,27 @@ void X86RegisterInfo::emitEpilogue(MachineFunction &MF, MBB.erase(PI); } } + } - if (NumBytes) - emitSPUpdate(MBB, MBBI, StackPtr, NumBytes, Is64Bit, TII); + // If dynamic alloca is used, then reset esp to point to the last + // callee-saved slot before popping them off! + if (MFI->hasVarSizedObjects()) { + unsigned Opc = Is64Bit ? X86::LEA64r : X86::LEA32r; + if (CSSize) { + MachineInstr *MI = addRegOffset(BuildMI(TII.get(Opc), StackPtr), + FramePtr, -CSSize); + MBB.insert(MBBI, MI); + } else + BuildMI(MBB, MBBI, TII.get(Is64Bit ? X86::MOV64rr : X86::MOV32rr),StackPtr). + addReg(FramePtr); + + NumBytes = 0; } + // adjust stack pointer back: ESP += numbytes + if (NumBytes) + emitSPUpdate(MBB, MBBI, StackPtr, NumBytes, Is64Bit, TII); + // We're returning from function via eh_return. if (RetOpcode == X86::EH_RETURN) { MBBI = prior(MBB.end());