Index: lib/CodeGen/TargetSchedule.cpp =================================================================== --- lib/CodeGen/TargetSchedule.cpp +++ lib/CodeGen/TargetSchedule.cpp @@ -154,12 +154,15 @@ /// is independent of use operands. Def operands may be reordered with uses or /// merged with uses without affecting the def index (e.g. before/after /// regalloc). However, an instruction's def operands must never be reordered -/// with respect to each other. +/// with respect to each other. We need to skip implicit def operands (added +/// by regalloc) that are not part of the MCInstrDesc. static unsigned findDefIdx(const MachineInstr *MI, unsigned DefOperIdx) { + const MCInstrDesc &MID = MI->getDesc(); unsigned DefIdx = 0; for (unsigned i = 0; i != DefOperIdx; ++i) { const MachineOperand &MO = MI->getOperand(i); - if (MO.isReg() && MO.isDef()) + if (MO.isReg() && MO.isDef() && + (!MO.isImplicit() || MID.hasImplicitDefOfPhysReg(MO.getReg()))) ++DefIdx; } return DefIdx;