AMDGPU: Don't delete instructions if S_ENDPGM has implicit uses
This can leave behind the uses with the defs removed.
Since this should only really happen in tests, it's not worth the
effort of trying to handle this.
llvm-svn: 340866
diff --git a/llvm/lib/Target/AMDGPU/SIOptimizeExecMaskingPreRA.cpp b/llvm/lib/Target/AMDGPU/SIOptimizeExecMaskingPreRA.cpp
index 7b678d1..e53d876 100644
--- a/llvm/lib/Target/AMDGPU/SIOptimizeExecMaskingPreRA.cpp
+++ b/llvm/lib/Target/AMDGPU/SIOptimizeExecMaskingPreRA.cpp
@@ -119,7 +119,14 @@
// Try to remove unneeded instructions before s_endpgm.
if (MBB.succ_empty()) {
- if (MBB.empty() || MBB.back().getOpcode() != AMDGPU::S_ENDPGM)
+ if (MBB.empty())
+ continue;
+
+ // Skip this if the endpgm has any implicit uses, otherwise we would need
+ // to be careful to update / remove them.
+ MachineInstr &Term = MBB.back();
+ if (Term.getOpcode() != AMDGPU::S_ENDPGM ||
+ Term.getNumOperands() != 0)
continue;
SmallVector<MachineBasicBlock*, 4> Blocks({&MBB});