Skip to content

Commit 6a05c6b

Browse files
committed
[MachineCopyPropagation] BackwardPropagatableCopy: add check for hasOverlappingMultipleDef
In MachineCopyPropagation::BackwardPropagatableCopy(), a check is added for multiple destination registers. The copy propagation is avoided if the copied destination register is the same register as another destination on the same instruction. A new test is added. This used to fail on ARM like this: error: unpredictable instruction, RdHi and RdLo must be different umull r9, r9, lr, r0 Reviewed By: lkail Differential Revision: https://reviews.llvm.org/D82638
1 parent 62beb7c commit 6a05c6b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

llvm/lib/CodeGen/MachineCopyPropagation.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ class MachineCopyPropagation : public MachineFunctionPass {
288288
const MachineInstr &UseI,
289289
unsigned UseIdx);
290290
bool hasImplicitOverlap(const MachineInstr &MI, const MachineOperand &Use);
291+
bool hasOverlappingMultipleDef(const MachineInstr &MI,
292+
const MachineOperand &MODef, Register Def);
291293

292294
/// Candidates for deletion.
293295
SmallSetVector<MachineInstr *, 8> MaybeDeadCopies;
@@ -461,6 +463,21 @@ bool MachineCopyPropagation::hasImplicitOverlap(const MachineInstr &MI,
461463
return false;
462464
}
463465

466+
/// For an MI that has multiple definitions, check whether \p MI has
467+
/// a definition that overlaps with another of its definitions.
468+
/// For example, on ARM: umull r9, r9, lr, r0
469+
/// The umull instruction is unpredictable unless RdHi and RdLo are different.
470+
bool MachineCopyPropagation::hasOverlappingMultipleDef(
471+
const MachineInstr &MI, const MachineOperand &MODef, Register Def) {
472+
for (const MachineOperand &MIDef : MI.defs()) {
473+
if ((&MIDef != &MODef) && MIDef.isReg() &&
474+
TRI->regsOverlap(Def, MIDef.getReg()))
475+
return true;
476+
}
477+
478+
return false;
479+
}
480+
464481
/// Look for available copies whose destination register is used by \p MI and
465482
/// replace the use in \p MI with the copy's source register.
466483
void MachineCopyPropagation::forwardUses(MachineInstr &MI) {
@@ -786,6 +803,9 @@ void MachineCopyPropagation::propagateDefs(MachineInstr &MI) {
786803
if (hasImplicitOverlap(MI, MODef))
787804
continue;
788805

806+
if (hasOverlappingMultipleDef(MI, MODef, Def))
807+
continue;
808+
789809
LLVM_DEBUG(dbgs() << "MCP: Replacing " << printReg(MODef.getReg(), TRI)
790810
<< "\n with " << printReg(Def, TRI) << "\n in "
791811
<< MI << " from " << *Copy);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# RUN: llc -mtriple=arm-eabi -O1 -run-pass=machine-cp %s -o - \
2+
# RUN: -verify-machineinstrs -simplify-mir | FileCheck %s
3+
4+
name: h
5+
body: |
6+
bb.0:
7+
8+
dead renamable $r9, renamable $r0 = UMULL renamable $lr, killed renamable $r0, 14 /* CC::al */, $noreg, $noreg
9+
10+
; CHECK: dead renamable $r9, renamable $r0 = UMULL renamable $lr, killed renamable $r0, 14 /* CC::al */, $noreg, $noreg
11+
12+
renamable $r9 = COPY killed renamable $r0
13+
...

0 commit comments

Comments
 (0)