Skip to content

Commit

Permalink
[AMDGPU] Prevent Machine Copy Propagation from replacing live copy wi…
Browse files Browse the repository at this point in the history
…th the dead one

Differential revision: https://reviews.llvm.org/D38754

llvm-svn: 315908
  • Loading branch information
alex-t committed Oct 16, 2017
1 parent 259b190 commit 3828242
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
24 changes: 13 additions & 11 deletions llvm/lib/CodeGen/MachineCopyPropagation.cpp
Expand Up @@ -275,18 +275,20 @@ void MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) {
ClobberRegister(Reg);
}

// Remember Def is defined by the copy.
for (MCSubRegIterator SR(Def, TRI, /*IncludeSelf=*/true); SR.isValid();
++SR) {
CopyMap[*SR] = MI;
AvailCopyMap[*SR] = MI;
}
if (!MI->getOperand(0).isDead() && !MI->getOperand(1).isUndef()) {
// Remember Def is defined by the copy.
for (MCSubRegIterator SR(Def, TRI, /*IncludeSelf=*/true); SR.isValid();
++SR) {
CopyMap[*SR] = MI;
AvailCopyMap[*SR] = MI;
}

// Remember source that's copied to Def. Once it's clobbered, then
// it's no longer available for copy propagation.
RegList &DestList = SrcMap[Src];
if (!is_contained(DestList, Def))
DestList.push_back(Def);
// Remember source that's copied to Def. Once it's clobbered, then
// it's no longer available for copy propagation.
RegList &DestList = SrcMap[Src];
if (!is_contained(DestList, Def))
DestList.push_back(Def);
}

continue;
}
Expand Down
27 changes: 27 additions & 0 deletions llvm/test/CodeGen/AMDGPU/dead_copy.mir
@@ -0,0 +1,27 @@
# RUN: llc -o - %s -march=amdgcn -mcpu=fiji -run-pass=machine-cp -verify-machineinstrs | FileCheck -check-prefix=GCN %s

# GCN-LABEL: dead_copy
# GCN: bb.0
# GCN-NOT: dead %vgpr5 = COPY undef %vgpr11, implicit %exec
# GCN: %vgpr5 = COPY %vgpr11, implicit %exec

---
name: dead_copy

body: |
bb.0:
liveins: %vgpr11, %sgpr0, %sgpr1, %vgpr6, %vgpr7, %vgpr4
dead %vgpr5 = COPY undef %vgpr11, implicit %exec
%vgpr5 = COPY %vgpr11, implicit %exec
%sgpr14 = S_ADD_U32 %sgpr0, target-flags(amdgpu-gotprel) 1136, implicit-def %scc
%sgpr15 = S_ADDC_U32 %sgpr1, target-flags(amdgpu-gotprel32-lo) 0, implicit-def dead %scc, implicit %scc
%vgpr10 = COPY killed %sgpr14, implicit %exec
%vgpr11 = COPY killed %sgpr15, implicit %exec
FLAT_STORE_DWORDX4 %vgpr10_vgpr11, %vgpr4_vgpr5_vgpr6_vgpr7, 0, 0, 0, implicit %exec, implicit %flat_scr
...

0 comments on commit 3828242

Please sign in to comment.