Fix many regressions on x86 by avoiding dereferencing the end iterator.

llvm-svn: 42738
This commit is contained in:
Chris Lattner 2007-10-07 21:53:12 +00:00
parent 7cdae91966
commit 8dd66ab3b2
1 changed files with 38 additions and 35 deletions

View File

@ -1481,47 +1481,50 @@ void emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI,
static static
void mergeSPUpdatesUp(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, void mergeSPUpdatesUp(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI,
unsigned StackPtr, uint64_t *NumBytes = NULL) { unsigned StackPtr, uint64_t *NumBytes = NULL) {
if (MBBI != MBB.begin()) { if (MBBI == MBB.begin()) return;
MachineBasicBlock::iterator PI = prior(MBBI);
unsigned Opc = PI->getOpcode(); MachineBasicBlock::iterator PI = prior(MBBI);
if ((Opc == X86::ADD64ri32 || Opc == X86::ADD64ri8 || unsigned Opc = PI->getOpcode();
Opc == X86::ADD32ri || Opc == X86::ADD32ri8) && if ((Opc == X86::ADD64ri32 || Opc == X86::ADD64ri8 ||
PI->getOperand(0).getReg() == StackPtr) { Opc == X86::ADD32ri || Opc == X86::ADD32ri8) &&
if (NumBytes) PI->getOperand(0).getReg() == StackPtr) {
*NumBytes += PI->getOperand(2).getImm(); if (NumBytes)
MBB.erase(PI); *NumBytes += PI->getOperand(2).getImm();
} else if ((Opc == X86::SUB64ri32 || Opc == X86::SUB64ri8 || MBB.erase(PI);
Opc == X86::SUB32ri || Opc == X86::SUB32ri8) && } else if ((Opc == X86::SUB64ri32 || Opc == X86::SUB64ri8 ||
PI->getOperand(0).getReg() == StackPtr) { Opc == X86::SUB32ri || Opc == X86::SUB32ri8) &&
if (NumBytes) PI->getOperand(0).getReg() == StackPtr) {
*NumBytes -= PI->getOperand(2).getImm(); if (NumBytes)
MBB.erase(PI); *NumBytes -= PI->getOperand(2).getImm();
} MBB.erase(PI);
} }
} }
// mergeSPUpdatesUp - Merge two stack-manipulating instructions lower iterator. // mergeSPUpdatesUp - Merge two stack-manipulating instructions lower iterator.
static static
void mergeSPUpdatesDown(MachineBasicBlock &MBB,MachineBasicBlock::iterator &MBBI, void mergeSPUpdatesDown(MachineBasicBlock &MBB,
MachineBasicBlock::iterator &MBBI,
unsigned StackPtr, uint64_t *NumBytes = NULL) { unsigned StackPtr, uint64_t *NumBytes = NULL) {
if (MBBI != MBB.end()) { if (MBBI == MBB.end()) return;
MachineBasicBlock::iterator NI = next(MBBI);
unsigned Opc = NI->getOpcode(); MachineBasicBlock::iterator NI = next(MBBI);
if ((Opc == X86::ADD64ri32 || Opc == X86::ADD64ri8 || if (NI == MBB.end()) return;
Opc == X86::ADD32ri || Opc == X86::ADD32ri8) &&
NI->getOperand(0).getReg() == StackPtr) { unsigned Opc = NI->getOpcode();
if (NumBytes) if ((Opc == X86::ADD64ri32 || Opc == X86::ADD64ri8 ||
*NumBytes -= NI->getOperand(2).getImm(); Opc == X86::ADD32ri || Opc == X86::ADD32ri8) &&
MBB.erase(NI); NI->getOperand(0).getReg() == StackPtr) {
MBBI = NI; if (NumBytes)
} else if ((Opc == X86::SUB64ri32 || Opc == X86::SUB64ri8 || *NumBytes -= NI->getOperand(2).getImm();
Opc == X86::SUB32ri || Opc == X86::SUB32ri8) && MBB.erase(NI);
NI->getOperand(0).getReg() == StackPtr) { MBBI = NI;
if (NumBytes) } else if ((Opc == X86::SUB64ri32 || Opc == X86::SUB64ri8 ||
*NumBytes += NI->getOperand(2).getImm(); Opc == X86::SUB32ri || Opc == X86::SUB32ri8) &&
MBB.erase(NI); NI->getOperand(0).getReg() == StackPtr) {
MBBI = NI; if (NumBytes)
} *NumBytes += NI->getOperand(2).getImm();
MBB.erase(NI);
MBBI = NI;
} }
} }