From 0a11829ab23ac478226cdf97cc0434dd4557abff Mon Sep 17 00:00:00 2001 From: Stanislav Mekhanoshin Date: Wed, 20 Mar 2019 21:42:05 +0000 Subject: Allow machine dce to remove uses in the same instruction Machine DCE cannot remove a dead definition if there are non-dbg uses. A use however can be in the same instruction: dead %0 = INST %0 Such instructions sometimes created by Detect dead lanes pass. Allow this instruction to be deleted despite the use if the only use belongs to the same instruction. Differential Revision: https://reviews.llvm.org/D59565 llvm-svn: 356619 --- llvm/lib/CodeGen/DeadMachineInstructionElim.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'llvm/lib/CodeGen/DeadMachineInstructionElim.cpp') diff --git a/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp b/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp index 36c7de67f5d..049ce706330 100644 --- a/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp +++ b/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp @@ -81,9 +81,11 @@ bool DeadMachineInstructionElim::isDead(const MachineInstr *MI) const { if (LivePhysRegs.test(Reg) || MRI->isReserved(Reg)) return false; } else { - if (!MRI->use_nodbg_empty(Reg)) - // This def has a non-debug use. Don't delete the instruction! - return false; + 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; + } } } } -- cgit v1.2.3