From 3181caa065de90e5ee2bbd15935a2274e3c95bd6 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 19 Mar 2009 17:15:43 +0000 Subject: [PATCH] Fix PEI to not walk off the start of a block when an updated instruction is the first in its block. This is PR3842. llvm-svn: 67304 --- lib/CodeGen/PrologEpilogInserter.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/PrologEpilogInserter.cpp b/lib/CodeGen/PrologEpilogInserter.cpp index 39f96133bd1..ab63f4933ff 100644 --- a/lib/CodeGen/PrologEpilogInserter.cpp +++ b/lib/CodeGen/PrologEpilogInserter.cpp @@ -533,11 +533,15 @@ void PEI::replaceFrameIndices(MachineFunction &Fn) { SPAdj += Size; - MachineBasicBlock::iterator PrevI = prior(I); + MachineBasicBlock::iterator PrevI = BB->end(); + if (I != BB->begin()) PrevI = prior(I); TRI.eliminateCallFramePseudoInstr(Fn, *BB, I); // Visit the instructions created by eliminateCallFramePseudoInstr(). - I = next(PrevI); + if (PrevI == BB->end()) + I = BB->begin(); // The replaced instr was the first in the block. + else + I = next(PrevI); continue; }