Skip to content

Commit 6568294

Browse files
author
Sameer AbuAsal
committed
[RegisterCoalescer] Account for instructions deleted by removePartialredunduncy and in WorkList
Summary: removePartialRedundency optimization introduces a state in the RegisterCoalescer where an instruction pointed to in the WorkList is deleted from the MBB and then removed from the ErasedList. This patch updates the ErasedList to be used globally by not erasing erased Instructions from it to solve the problem. The patch also accounts for the case where an Instruction was previously deleted and the same memory was reused by BuildMI to create a new instruction. Reviewers: kparzysz, qcolombet Reviewed By: qcolombet Subscribers: MatzeB, qcolombet, llvm-commits Differential Revision: https://reviews.llvm.org/D34902 llvm-svn: 306915
1 parent c1c1783 commit 6568294

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

llvm/lib/CodeGen/RegisterCoalescer.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,11 @@ bool RegisterCoalescer::removePartialRedundancy(const CoalescerPair &CP,
979979
IntB.createDeadDef(NewCopyIdx, LIS->getVNInfoAllocator());
980980
for (LiveInterval::SubRange &SR : IntB.subranges())
981981
SR.createDeadDef(NewCopyIdx, LIS->getVNInfoAllocator());
982+
983+
// If the newly created Instruction has an address of an instruction that was
984+
// deleted before (object recycled by the allocator) it needs to be removed from
985+
// the deleted list.
986+
ErasedInstrs.erase(NewCopyMI);
982987
} else {
983988
DEBUG(dbgs() << "\tremovePartialRedundancy: Remove the copy from BB#"
984989
<< MBB.getNumber() << '\t' << CopyMI);
@@ -989,6 +994,8 @@ bool RegisterCoalescer::removePartialRedundancy(const CoalescerPair &CP,
989994
// While updating the live-ranges, we only look at slot indices and
990995
// never go back to the instruction.
991996
LIS->RemoveMachineInstrFromMaps(CopyMI);
997+
// Mark instructions as deleted.
998+
ErasedInstrs.insert(&CopyMI);
992999
CopyMI.eraseFromParent();
9931000

9941001
// Update the liveness.
@@ -3095,7 +3102,7 @@ copyCoalesceWorkList(MutableArrayRef<MachineInstr*> CurrList) {
30953102
continue;
30963103
// Skip instruction pointers that have already been erased, for example by
30973104
// dead code elimination.
3098-
if (ErasedInstrs.erase(CurrList[i])) {
3105+
if (ErasedInstrs.count(CurrList[i])) {
30993106
CurrList[i] = nullptr;
31003107
continue;
31013108
}

0 commit comments

Comments
 (0)