Index: lib/CodeGen/DeadMachineInstructionElim.cpp =================================================================== --- lib/CodeGen/DeadMachineInstructionElim.cpp +++ lib/CodeGen/DeadMachineInstructionElim.cpp @@ -77,24 +77,32 @@ // Examine each operand. for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { const MachineOperand &MO = MI->getOperand(i); - if (MO.isReg() && MO.isDef()) { - unsigned Reg = MO.getReg(); - if (TargetRegisterInfo::isPhysicalRegister(Reg)) { - // Don't delete live physreg defs, or any reserved register defs. - // Do not remove physreg defs if we have LIS as we may be unable - // to accurately recompute its liveness. - if (LivePhysRegs.test(Reg) || MRI->isReserved(Reg) || LIS) + if (!MO.isReg()) + continue; + + unsigned Reg = MO.getReg(); + // Do not remove physreg defs or uses if we have LIS as we may be unable + // to accurately recompute its liveness. + if (LIS && TargetRegisterInfo::isPhysicalRegister(Reg) && + MRI->isAllocatable(Reg)) + return false; + + if (!MO.isDef()) + continue; + + if (TargetRegisterInfo::isPhysicalRegister(Reg)) { + // Don't delete live physreg defs, or any reserved register defs. + if (LivePhysRegs.test(Reg) || MRI->isReserved(Reg) || LIS) + return false; + } else { + // An instruction can also use its def in case if it is a tied operand. + // TODO: Technically we can also remove it if def dominates the use. + // This can happen when two instructions define different subregs + // of the same register. + for (const MachineInstr &Use : MRI->use_nodbg_instructions(Reg)) { + if (&Use != MI) + // This def has a non-debug use. Don't delete the instruction! return false; - } else { - // An instruction can also use its def in case if it is a tied operand. - // TODO: Technically we can also remove it if def dominates the use. - // This can happen when two instructions define different subregs - // of the same register. - for (const MachineInstr &Use : MRI->use_nodbg_instructions(Reg)) { - if (&Use != MI) - // This def has a non-debug use. Don't delete the instruction! - return false; - } } } }