Index: lib/Target/Mips/MipsHazardSchedule.cpp =================================================================== --- lib/Target/Mips/MipsHazardSchedule.cpp +++ lib/Target/Mips/MipsHazardSchedule.cpp @@ -92,6 +92,15 @@ return new MipsHazardSchedule(); } +// Find the next real instruction from the current position. +static Iter getNextMachineInstr(Iter Position) { + Iter I = Position, E = Position->getParent()->end(); + while (I != E && I->isTransient()) + I++; + + return I; +} + bool MipsHazardSchedule::runOnMachineFunction(MachineFunction &MF) { const MipsSubtarget *STI = @@ -114,14 +123,14 @@ bool InsertNop = false; // Next instruction in the basic block. if (std::next(I) != FI->end() && - !TII->SafeInForbiddenSlot(*std::next(I))) { + !TII->SafeInForbiddenSlot(*getNextMachineInstr(std::next(I)))) { InsertNop = true; } else { // Next instruction in the physical successor basic block. for (auto *Succ : FI->successors()) { if (FI->isLayoutSuccessor(Succ) && - Succ->getFirstNonDebugInstr() != Succ->end() && - !TII->SafeInForbiddenSlot(*Succ->getFirstNonDebugInstr())) { + getNextMachineInstr(Succ->begin()) != Succ->end() && + !TII->SafeInForbiddenSlot(*getNextMachineInstr(Succ->begin()))) { InsertNop = true; break; }