[llvm] r356619 - Allow machine dce to remove uses in the same instruction
Stanislav Mekhanoshin via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 20 14:42:05 PDT 2019
Author: rampitec
Date: Wed Mar 20 14:42:05 2019
New Revision: 356619
URL: http://llvm.org/viewvc/llvm-project?rev=356619&view=rev
Log:
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
Added:
llvm/trunk/test/CodeGen/AMDGPU/dead-mi-use-same-intr.mir
Modified:
llvm/trunk/lib/CodeGen/DeadMachineInstructionElim.cpp
Modified: llvm/trunk/lib/CodeGen/DeadMachineInstructionElim.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/DeadMachineInstructionElim.cpp?rev=356619&r1=356618&r2=356619&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/DeadMachineInstructionElim.cpp (original)
+++ llvm/trunk/lib/CodeGen/DeadMachineInstructionElim.cpp Wed Mar 20 14:42:05 2019
@@ -81,9 +81,11 @@ bool DeadMachineInstructionElim::isDead(
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;
+ }
}
}
}
Added: llvm/trunk/test/CodeGen/AMDGPU/dead-mi-use-same-intr.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/dead-mi-use-same-intr.mir?rev=356619&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/dead-mi-use-same-intr.mir (added)
+++ llvm/trunk/test/CodeGen/AMDGPU/dead-mi-use-same-intr.mir Wed Mar 20 14:42:05 2019
@@ -0,0 +1,55 @@
+# RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs -run-pass dead-mi-elimination -o - %s | FileCheck -check-prefix=GCN %s
+
+# GCN-LABEL: name: dead_undef
+# GCN: bb.0:
+# GCN-NEXT: S_ENDPGM 0
+---
+name: dead_undef
+tracksRegLiveness: true
+registers:
+ - { id: 0, class: vgpr_32 }
+ - { id: 1, class: vgpr_32 }
+ - { id: 2, class: vgpr_32 }
+body: |
+ bb.0:
+ %0 = IMPLICIT_DEF
+ %1 = IMPLICIT_DEF
+ dead %2:vgpr_32 = V_MAC_F32_e32 %0:vgpr_32, %1:vgpr_32, undef %2:vgpr_32, implicit $exec
+ S_ENDPGM 0
+
+# GCN-LABEL: name: dead_defined
+# GCN: bb.0:
+# GCN-NEXT: S_ENDPGM 0
+---
+name: dead_defined
+tracksRegLiveness: true
+registers:
+ - { id: 0, class: vgpr_32 }
+ - { id: 1, class: vgpr_32 }
+ - { id: 2, class: vgpr_32 }
+body: |
+ bb.0:
+ %0 = IMPLICIT_DEF
+ %1 = IMPLICIT_DEF
+ %2 = IMPLICIT_DEF
+ dead %2:vgpr_32 = V_MAC_F32_e32 %0:vgpr_32, %1:vgpr_32, %2:vgpr_32, implicit $exec
+ S_ENDPGM 0
+
+# Probably this dead mac can be removed anyway.
+# GCN-LABEL: name: dead_def_live_use
+# GCN: dead %2:vgpr_32 = V_MAC_F32_e32 %0, %1, %2, implicit $exec
+---
+name: dead_def_live_use
+tracksRegLiveness: true
+registers:
+ - { id: 0, class: vgpr_32 }
+ - { id: 1, class: vgpr_32 }
+ - { id: 2, class: vgpr_32 }
+body: |
+ bb.0:
+ %0 = IMPLICIT_DEF
+ %1 = IMPLICIT_DEF
+ %2 = IMPLICIT_DEF
+ GLOBAL_STORE_DWORD undef $vgpr0_vgpr1, %2, 0, 0, 0, implicit $exec
+ dead %2:vgpr_32 = V_MAC_F32_e32 %0:vgpr_32, %1:vgpr_32, %2:vgpr_32, implicit $exec
+ S_ENDPGM 0
More information about the llvm-commits
mailing list