Skip to content

Commit 76a533d

Browse files
committed
MachineCopyPropagation: Do not remove copies preserved by regmask
9e436c2daa44 tries to handle register masks and sub-registers, it avoids clobbering RegUnit presreved by regmask. But it then introduces invalid pointer issues. We delete the copies without invalidate all the use in the CopyInfo, so we dereferenced invalid pointers in next interation, causing asserts.
1 parent 08bda1c commit 76a533d

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

llvm/lib/CodeGen/MachineCopyPropagation.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,18 +1018,30 @@ void MachineCopyPropagation::ForwardCopyPropagateBlock(MachineBasicBlock &MBB) {
10181018
continue;
10191019
}
10201020

1021-
LLVM_DEBUG(dbgs() << "MCP: Removing copy due to regmask clobbering: ";
1022-
MaybeDead->dump());
1023-
10241021
// Invalidate all entries in the copy map which are not preserved by
10251022
// this register mask.
1026-
for (unsigned RegUnit : TRI->regunits(Reg))
1023+
bool MIRefedinCopyInfo = false;
1024+
for (unsigned RegUnit : TRI->regunits(Reg)) {
10271025
if (!PreservedRegUnits.test(RegUnit))
10281026
Tracker.clobberRegUnit(RegUnit, *TRI, *TII, UseCopyInstr);
1027+
else {
1028+
if (MaybeDead == Tracker.findCopyForUnit(RegUnit, *TRI)) {
1029+
MIRefedinCopyInfo = true;
1030+
}
1031+
}
1032+
}
10291033

10301034
// erase() will return the next valid iterator pointing to the next
10311035
// element after the erased one.
10321036
DI = MaybeDeadCopies.erase(DI);
1037+
1038+
// Preserved by RegMask, DO NOT remove copy
1039+
if (MIRefedinCopyInfo)
1040+
continue;
1041+
1042+
LLVM_DEBUG(dbgs() << "MCP: Removing copy due to regmask clobbering: ";
1043+
MaybeDead->dump());
1044+
10331045
MaybeDead->eraseFromParent();
10341046
Changed = true;
10351047
++NumDeletes;

0 commit comments

Comments
 (0)