From: Evan Cheng Date: Thu, 26 Apr 2007 01:09:28 +0000 (+0000) Subject: Fix for PR1348. If stack inc / dec amount is > 32-bits, issue a series of add / sub... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a24ddddf68cc29cdcc93c572a98651c3f3be18a1;p=oota-llvm.git Fix for PR1348. If stack inc / dec amount is > 32-bits, issue a series of add / sub instructions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36456 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp index ee74d1afeba..52ab7f0945d 100644 --- a/lib/Target/X86/X86RegisterInfo.cpp +++ b/lib/Target/X86/X86RegisterInfo.cpp @@ -1023,6 +1023,30 @@ X86RegisterInfo::processFunctionBeforeFrameFinalized(MachineFunction &MF) const{ } } +/// emitSPUpdate - Emit a series of instructions to increment / decrement the +/// stack pointer by a constant value. +static +void emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, + unsigned StackPtr, int64_t NumBytes, bool Is64Bit, + const TargetInstrInfo &TII) { + bool isSub = NumBytes < 0; + uint64_t Offset = isSub ? -NumBytes : NumBytes; + unsigned Opc = isSub + ? ((Offset < 128) ? + (Is64Bit ? X86::SUB64ri8 : X86::SUB32ri8) : + (Is64Bit ? X86::SUB64ri32 : X86::SUB32ri)) + : ((Offset < 128) ? + (Is64Bit ? X86::ADD64ri8 : X86::ADD32ri8) : + (Is64Bit ? X86::ADD64ri32 : X86::ADD32ri)); + uint64_t Chunk = (1LL << 31) - 1; + + while (Offset) { + uint64_t ThisVal = (Offset > Chunk) ? Chunk : Offset; + BuildMI(MBB, MBBI, TII.get(Opc), StackPtr).addReg(StackPtr).addImm(ThisVal); + Offset -= ThisVal; + } +} + void X86RegisterInfo::emitPrologue(MachineFunction &MF) const { MachineBasicBlock &MBB = MF.front(); // Prolog goes in entry BB MachineBasicBlock::iterator MBBI = MBB.begin(); @@ -1075,11 +1099,7 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const { MBB.insert(MBBI, MI); } } else { - unsigned Opc = (NumBytes < 128) ? - (Is64Bit ? X86::SUB64ri8 : X86::SUB32ri8) : - (Is64Bit ? X86::SUB64ri32 : X86::SUB32ri); - MI= BuildMI(TII.get(Opc), StackPtr).addReg(StackPtr).addImm(NumBytes); - MBB.insert(MBBI, MI); + emitSPUpdate(MBB, MBBI, StackPtr, -(int64_t)NumBytes, Is64Bit, TII); } } @@ -1206,19 +1226,8 @@ void X86RegisterInfo::emitEpilogue(MachineFunction &MF, } } - if (NumBytes > 0) { - unsigned Opc = (NumBytes < 128) ? - (Is64Bit ? X86::ADD64ri8 : X86::ADD32ri8) : - (Is64Bit ? X86::ADD64ri32 : X86::ADD32ri); - BuildMI(MBB, MBBI, TII.get(Opc), StackPtr) - .addReg(StackPtr).addImm(NumBytes); - } else if ((int)NumBytes < 0) { - unsigned Opc = (-NumBytes < 128) ? - (Is64Bit ? X86::SUB64ri8 : X86::SUB32ri8) : - (Is64Bit ? X86::SUB64ri32 : X86::SUB32ri); - BuildMI(MBB, MBBI, TII.get(Opc), StackPtr) - .addReg(StackPtr).addImm(-NumBytes); - } + if (NumBytes) + emitSPUpdate(MBB, MBBI, StackPtr, NumBytes, Is64Bit, TII); } } }