Skip to content

Commit 07ebd74

Browse files
Tim Renouftrenouf
authored andcommitted
MCP: Fixed bug with dest overlapping copy source
In MachineCopyPropagation, when propagating the source of a copy into the operand of a later instruction, bail if a destination overlaps (partly defines) the copy source. If the instruction where the substitution is happening is also a copy, allowing the propagation confuses the tracking mechanism. Differential Revision: https://reviews.llvm.org/D69953 Change-Id: Ic570754f878f2d91a4a50a9bdcf96fbaa240726d
1 parent 22a535e commit 07ebd74

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

llvm/lib/CodeGen/MachineCopyPropagation.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,15 @@ void MachineCopyPropagation::forwardUses(MachineInstr &MI) {
432432
if (hasImplicitOverlap(MI, MOUse))
433433
continue;
434434

435+
// Check that the instruction is not a copy that partially overwrites the
436+
// original copy source that we are about to use. The tracker mechanism
437+
// cannot cope with that.
438+
if (MI.isCopy() && MI.modifiesRegister(CopySrcReg, TRI) &&
439+
!MI.definesRegister(CopySrcReg)) {
440+
LLVM_DEBUG(dbgs() << "MCP: Copy source overlap with dest in " << MI);
441+
continue;
442+
}
443+
435444
if (!DebugCounter::shouldExecute(FwdCounter)) {
436445
LLVM_DEBUG(dbgs() << "MCP: Skipping forwarding due to debug counter:\n "
437446
<< MI);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# RUN: llc -march=amdgcn -mcpu=gfx1010 %s -o - -run-pass machine-cp -verify-machineinstrs | FileCheck %s
2+
#
3+
# The MachineCopyPropagation bug being tested propagates s[60:67] into the copy
4+
# into s[56:63], and then uses s[60:67] in the following
5+
# IMAGE_SAMPLE_V3_V2_gfx10, even though it has just overwritten half of it.
6+
7+
# CHECK-LABEL: name: _amdgpu_ps_main
8+
# CHECK-NOT: IMAGE_SAMPLE_V3_V2_gfx10 {{.*}} $sgpr60_sgpr61_sgpr62_sgpr63_sgpr64_sgpr65_sgpr66_sgpr67
9+
# CHECK: IMAGE_SAMPLE_V3_V2_gfx10 {{.*}} $sgpr88_sgpr89_sgpr90_sgpr91_sgpr92_sgpr93_sgpr94_sgpr95
10+
11+
---
12+
name: _amdgpu_ps_main
13+
body: |
14+
bb.0:
15+
successors:
16+
liveins: $sgpr2, $sgpr3, $sgpr96, $sgpr97, $sgpr98, $sgpr99, $vgpr0, $vgpr1, $vgpr2, $vgpr3, $vgpr5, $vgpr70, $vgpr71
17+
18+
renamable $sgpr8_sgpr9 = S_GETPC_B64
19+
renamable $sgpr8 = COPY killed renamable $sgpr2
20+
renamable $sgpr60_sgpr61_sgpr62_sgpr63_sgpr64_sgpr65_sgpr66_sgpr67 = S_LOAD_DWORDX8_IMM renamable $sgpr8_sgpr9, 144, 0, 0 :: (invariant load 32, align 16, addrspace 4)
21+
renamable $sgpr88_sgpr89_sgpr90_sgpr91_sgpr92_sgpr93_sgpr94_sgpr95 = COPY killed renamable $sgpr60_sgpr61_sgpr62_sgpr63_sgpr64_sgpr65_sgpr66_sgpr67
22+
renamable $vgpr4 = IMAGE_GET_LOD_V1_V2_gfx10 renamable $vgpr70_vgpr71, renamable $sgpr88_sgpr89_sgpr90_sgpr91_sgpr92_sgpr93_sgpr94_sgpr95, renamable $sgpr96_sgpr97_sgpr98_sgpr99, 2, 1, 0, 0, 0, 0, 0, 0, 0, implicit $exec
23+
renamable $sgpr56_sgpr57_sgpr58_sgpr59_sgpr60_sgpr61_sgpr62_sgpr63 = COPY killed renamable $sgpr88_sgpr89_sgpr90_sgpr91_sgpr92_sgpr93_sgpr94_sgpr95
24+
renamable $vgpr12_vgpr13_vgpr14 = IMAGE_SAMPLE_V3_V2_gfx10 renamable $vgpr70_vgpr71, renamable $sgpr56_sgpr57_sgpr58_sgpr59_sgpr60_sgpr61_sgpr62_sgpr63, renamable $sgpr96_sgpr97_sgpr98_sgpr99, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, implicit $exec :: (dereferenceable load 12, align 16)
25+
S_ENDPGM 0
26+
27+
...

0 commit comments

Comments
 (0)