Index: llvm/lib/CodeGen/ModuloSchedule.cpp =================================================================== --- llvm/lib/CodeGen/ModuloSchedule.cpp +++ llvm/lib/CodeGen/ModuloSchedule.cpp @@ -1658,8 +1658,8 @@ // we don't need the phi anymore. if (getStage(Def) == Stage) { Register PhiReg = MI.getOperand(0).getReg(); - MRI.replaceRegWith(MI.getOperand(0).getReg(), - Def->getOperand(0).getReg()); + assert(Def->findRegisterDefOperandIdx(MI.getOperand(1).getReg()) != -1); + MRI.replaceRegWith(MI.getOperand(0).getReg(), MI.getOperand(1).getReg()); MI.getOperand(0).setReg(PhiReg); PhiToDelete.push_back(&MI); }