From 3c616b45e7f843c64426da74076e6d9e31f4c904 Mon Sep 17 00:00:00 2001 From: Misha Brukman Date: Mon, 26 Jul 2004 16:22:52 +0000 Subject: [PATCH] Fix subtracting values > 2^15 in the prologue/epilogue, by Nate Begeman. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15234 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/PowerPC/PowerPCRegisterInfo.cpp | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/Target/PowerPC/PowerPCRegisterInfo.cpp b/lib/Target/PowerPC/PowerPCRegisterInfo.cpp index d1fdf1f4ace..c8211f64f8d 100644 --- a/lib/Target/PowerPC/PowerPCRegisterInfo.cpp +++ b/lib/Target/PowerPC/PowerPCRegisterInfo.cpp @@ -218,8 +218,19 @@ void PowerPCRegisterInfo::emitPrologue(MachineFunction &MF) const { MFI->setStackSize(NumBytes); // adjust stack pointer: r1 -= numbytes - if (NumBytes) { - MI = BuildMI(PPC32::STWU, 2, PPC32::R1).addSImm(-NumBytes).addReg(PPC32::R1); + if (NumBytes <= 32768) { + MI = BuildMI(PPC32::STWU, 3).addReg(PPC32::R1).addSImm(-NumBytes) + .addReg(PPC32::R1); + MBB.insert(MBBI, MI); + } else { + int NegNumbytes = -NumBytes; + MI = BuildMI(PPC32::LIS, 1, PPC32::R0).addSImm(NegNumbytes >> 16); + MBB.insert(MBBI, MI); + MI = BuildMI(PPC32::ORI, 2, PPC32::R0).addReg(PPC32::R0) + .addImm(NegNumbytes & 0xFFFF); + MBB.insert(MBBI, MI); + MI = BuildMI(PPC32::STWUX, 3).addReg(PPC32::R1).addReg(PPC32::R1) + .addReg(PPC32::R0); MBB.insert(MBBI, MI); } } @@ -247,8 +258,13 @@ void PowerPCRegisterInfo::emitEpilogue(MachineFunction &MF, MBB.insert(MBBI, MI); } // Adjust stack pointer back - MI = BuildMI(PPC32::ADDI, 2, PPC32::R1).addReg(PPC32::R1).addSImm(NumBytes); - MBB.insert(MBBI, MI); + if (NumBytes <= 32767) { + MI = BuildMI(PPC32::ADDI, 2, PPC32::R1).addReg(PPC32::R1).addSImm(NumBytes); + MBB.insert(MBBI, MI); + } else { + MI = BuildMI(PPC32::LWZ, 2, PPC32::R1).addSImm(0).addReg(PPC32::R1); + MBB.insert(MBBI, MI); + } } #include "PowerPCGenRegisterInfo.inc"