[llvm] r327842 - AMDGPU: Don't leave dead illegal VGPR->SGPR copies
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 19 07:07:15 PDT 2018
Author: arsenm
Date: Mon Mar 19 07:07:15 2018
New Revision: 327842
URL: http://llvm.org/viewvc/llvm-project?rev=327842&view=rev
Log:
AMDGPU: Don't leave dead illegal VGPR->SGPR copies
Normally DCE kills these, but at -O0 these get left behind
leaving suspicious looking illegal copies.
Replace with IMPLICIT_DEF to avoid iterator issues.
Modified:
llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp
llvm/trunk/test/CodeGen/AMDGPU/control-flow-fastregalloc.ll
llvm/trunk/test/CodeGen/AMDGPU/si-fix-sgpr-copies.mir
Modified: llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp?rev=327842&r1=327841&r2=327842&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp Mon Mar 19 07:07:15 2018
@@ -3923,6 +3923,13 @@ void SIInstrInfo::moveToVALU(MachineInst
MRI.replaceRegWith(DstReg, Inst.getOperand(1).getReg());
MRI.clearKillFlags(Inst.getOperand(1).getReg());
Inst.getOperand(0).setReg(DstReg);
+
+ // Make sure we don't leave around a dead VGPR->SGPR copy. Normally
+ // these are deleted later, but at -O0 it would leave a suspicious
+ // looking illegal copy of an undef register.
+ for (unsigned I = Inst.getNumOperands() - 1; I != 0; --I)
+ Inst.RemoveOperand(I);
+ Inst.setDesc(get(AMDGPU::IMPLICIT_DEF));
continue;
}
Modified: llvm/trunk/test/CodeGen/AMDGPU/control-flow-fastregalloc.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/control-flow-fastregalloc.ll?rev=327842&r1=327841&r2=327842&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/control-flow-fastregalloc.ll (original)
+++ llvm/trunk/test/CodeGen/AMDGPU/control-flow-fastregalloc.ll Mon Mar 19 07:07:15 2018
@@ -41,16 +41,17 @@
; GCN: {{^}}BB{{[0-9]+}}_1: ; %if
; GCN: s_mov_b32 m0, -1
; GCN: ds_read_b32 [[LOAD1:v[0-9]+]]
-; GCN: s_waitcnt lgkmcnt(0)
; GCN: buffer_load_dword [[RELOAD_LOAD0:v[0-9]+]], off, s[0:3], s7 offset:[[LOAD0_OFFSET]] ; 4-byte Folded Reload
+; GCN: s_waitcnt vmcnt(0) lgkmcnt(0)
+
; Spill val register
; GCN: v_add_i32_e32 [[VAL:v[0-9]+]], vcc, [[LOAD1]], [[RELOAD_LOAD0]]
; GCN: buffer_store_dword [[VAL]], off, s[0:3], s7 offset:[[VAL_OFFSET:[0-9]+]] ; 4-byte Folded Spill
; VMEM: [[ENDIF]]:
+
; Reload and restore exec mask
-; VGPR: s_waitcnt lgkmcnt(0)
; VGPR: v_readlane_b32 s[[S_RELOAD_SAVEEXEC_LO:[0-9]+]], [[SPILL_VGPR]], [[SAVEEXEC_LO_LANE]]
; VGPR: v_readlane_b32 s[[S_RELOAD_SAVEEXEC_HI:[0-9]+]], [[SPILL_VGPR]], [[SAVEEXEC_HI_LANE]]
Modified: llvm/trunk/test/CodeGen/AMDGPU/si-fix-sgpr-copies.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/si-fix-sgpr-copies.mir?rev=327842&r1=327841&r2=327842&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/si-fix-sgpr-copies.mir (original)
+++ llvm/trunk/test/CodeGen/AMDGPU/si-fix-sgpr-copies.mir Mon Mar 19 07:07:15 2018
@@ -1,7 +1,6 @@
# RUN: llc -march=amdgcn -run-pass si-fix-sgpr-copies %s -o - | FileCheck %s -check-prefixes=GCN
---- |
- define amdgpu_kernel void @phi_visit_order() { ret void }
+---
name: phi_visit_order
tracksRegLiveness: true
@@ -37,4 +36,39 @@ body: |
S_BRANCH %bb.1
...
+
+---
+
+# GCN-LABEL: name: dead_illegal_virtreg_copy
+# GCN: %0:vgpr_32 = COPY $vgpr0
+# GCN: %1:sreg_32_xm0 = IMPLICIT_DEF
+# GCN: S_ENDPGM implicit %0
+
+name: dead_illegal_virtreg_copy
+tracksRegLiveness: true
+
+body: |
+ bb.0:
+ liveins: $vgpr0
+ %0:vgpr_32 = COPY $vgpr0
+ %1:sreg_32_xm0 = COPY %0
+ S_ENDPGM implicit %1
+...
+
---
+
+# GCN-LABEL: name: dead_illegal_physreg_copy
+# GCN %2:vgpr_32 = COPY $vgpr0
+# GCN: %1:sreg_32_xm0 = IMPLICIT_DEF
+# GCN: S_ENDPGM implicit %2
+
+name: dead_illegal_physreg_copy
+tracksRegLiveness: true
+
+body: |
+ bb.0:
+ liveins: $vgpr0
+ %0:sreg_32_xm0 = COPY $vgpr0
+ %1:sreg_32_xm0 = COPY %0
+ S_ENDPGM implicit %1
+...
More information about the llvm-commits
mailing list