aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Target/X86/X86RegisterInfo.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-02-03 18:20:04 +0000
committerChris Lattner <sabre@nondot.org>2006-02-03 18:20:04 +0000
commitd77525da5e120eeaccf2322340111b1d65c49211 (patch)
tree0a65249c790e0d0066229bb6ee08bbd731077bb7 /lib/Target/X86/X86RegisterInfo.cpp
parent3e1798086b2cb4b1f96fcbb1b8a084c8af092363 (diff)
downloadexternal_llvm-d77525da5e120eeaccf2322340111b1d65c49211.zip
external_llvm-d77525da5e120eeaccf2322340111b1d65c49211.tar.gz
external_llvm-d77525da5e120eeaccf2322340111b1d65c49211.tar.bz2
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
Diffstat (limited to 'lib/Target/X86/X86RegisterInfo.cpp')
-rw-r--r--lib/Target/X86/X86RegisterInfo.cpp34
1 files changed, 21 insertions, 13 deletions
diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp
index ceb0f3f..fdbe422 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);
+ }
}
}
}