From d77525da5e120eeaccf2322340111b1d65c49211 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 3 Feb 2006 18:20:04 +0000 Subject: [PATCH] When rewriting frame instructions, emit the appropriate small-immediate instruction when possible. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25938 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86RegisterInfo.cpp | 34 ++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp index ceb0f3f2a3f..fdbe4225a06 100644 --- a/lib/Target/X86/X86RegisterInfo.cpp +++ b/lib/Target/X86/X86RegisterInfo.cpp @@ -467,9 +467,11 @@ eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, // factor out the amount the callee already popped. unsigned CalleeAmt = Old->getOperand(1).getImmedValue(); Amount -= CalleeAmt; - if (Amount) - New = BuildMI(X86::ADD32ri, 1, X86::ESP, + if (Amount) { + unsigned Opc = Amount < 128 ? X86::ADD32ri8 : X86::ADD32ri; + New = BuildMI(Opc, 1, X86::ESP, MachineOperand::UseAndDef).addZImm(Amount); + } } // Replace the pseudo instruction with a new instruction... @@ -480,8 +482,9 @@ eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, // something off the stack pointer, add it back. We do this until we have // more advanced stack pointer tracking ability. if (unsigned CalleeAmt = I->getOperand(1).getImmedValue()) { + unsigned Opc = CalleeAmt < 128 ? X86::SUB32ri8 : X86::SUB32ri; MachineInstr *New = - BuildMI(X86::SUB32ri, 1, X86::ESP, + BuildMI(Opc, 1, X86::ESP, MachineOperand::UseAndDef).addZImm(CalleeAmt); MBB.insert(I, New); } @@ -541,8 +544,8 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const { int EBPOffset = MFI->getObjectOffset(MFI->getObjectIndexBegin())+4; if (NumBytes) { // adjust stack pointer: ESP -= numbytes - MI= BuildMI(X86::SUB32ri, 1, X86::ESP, MachineOperand::UseAndDef) - .addZImm(NumBytes); + unsigned Opc = NumBytes < 128 ? X86::SUB32ri8 : X86::SUB32ri; + MI = BuildMI(Opc, 1, X86::ESP,MachineOperand::UseAndDef).addImm(NumBytes); MBB.insert(MBBI, MI); } @@ -578,8 +581,8 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const { if (NumBytes) { // adjust stack pointer: ESP -= numbytes - MI= BuildMI(X86::SUB32ri, 1, X86::ESP, MachineOperand::UseAndDef) - .addZImm(NumBytes); + unsigned Opc = NumBytes < 128 ? X86::SUB32ri8 : X86::SUB32ri; + MI= BuildMI(Opc, 1, X86::ESP, MachineOperand::UseAndDef).addImm(NumBytes); MBB.insert(MBBI, MI); } } @@ -619,11 +622,13 @@ void X86RegisterInfo::emitEpilogue(MachineFunction &MF, // instruction, merge the two instructions. if (MBBI != MBB.begin()) { MachineBasicBlock::iterator PI = prior(MBBI); - if (PI->getOpcode() == X86::ADD32ri && + if ((PI->getOpcode() == X86::ADD32ri || + PI->getOpcode() == X86::ADD32ri8) && PI->getOperand(0).getReg() == X86::ESP) { NumBytes += PI->getOperand(1).getImmedValue(); MBB.erase(PI); - } else if (PI->getOpcode() == X86::SUB32ri && + } else if ((PI->getOpcode() == X86::SUB32ri || + PI->getOpcode() == X86::SUB32ri8) && PI->getOperand(0).getReg() == X86::ESP) { NumBytes -= PI->getOperand(1).getImmedValue(); MBB.erase(PI); @@ -633,12 +638,15 @@ void X86RegisterInfo::emitEpilogue(MachineFunction &MF, } } - if (NumBytes > 0) - BuildMI(MBB, MBBI, X86::ADD32ri, 2) + if (NumBytes > 0) { + unsigned Opc = NumBytes < 128 ? X86::ADD32ri8 : X86::ADD32ri; + BuildMI(MBB, MBBI, Opc, 2) .addReg(X86::ESP, MachineOperand::UseAndDef).addZImm(NumBytes); - else if ((int)NumBytes < 0) - BuildMI(MBB, MBBI, X86::SUB32ri, 2) + } else if ((int)NumBytes < 0) { + unsigned Opc = -NumBytes < 128 ? X86::SUB32ri8 : X86::SUB32ri; + BuildMI(MBB, MBBI, Opc, 2) .addReg(X86::ESP, MachineOperand::UseAndDef).addZImm(-NumBytes); + } } } } -- 2.34.1