From ed461e0fafbd0b905cb716df108000bcd6ecf3d4 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 26 Aug 2005 22:18:32 +0000 Subject: [PATCH] Make this code safe for when loadRegFromStackSlot inserts multiple instructions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23108 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/PrologEpilogInserter.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/PrologEpilogInserter.cpp b/lib/CodeGen/PrologEpilogInserter.cpp index c5bc2337fd7..c855eb2a0f8 100644 --- a/lib/CodeGen/PrologEpilogInserter.cpp +++ b/lib/CodeGen/PrologEpilogInserter.cpp @@ -217,13 +217,25 @@ void PEI::saveCallerSavedRegisters(MachineFunction &Fn) { while (I2 != MBB->begin() && TII.isTerminatorInstr((--I2)->getOpcode())) I = I2; + bool AtStart = I2 == MBB->begin(); + MachineBasicBlock::iterator BeforeI = I; + if (!AtStart) + --BeforeI; + // Restore all registers immediately before the return and any terminators // that preceed it. for (unsigned i = 0, e = RegsToSave.size(); i != e; ++i) { RegInfo->loadRegFromStackSlot(*MBB, I, RegsToSave[i], StackSlots[i]); assert(I != MBB->begin() && "loadRegFromStackSlot didn't insert any code!"); - --I; // Insert in reverse order + // Insert in reverse order. loadRegFromStackSlot can insert multiple + // instructions. + if (AtStart) + I = MBB->begin(); + else { + I = BeforeI; + ++I; + } } } }