This is an archive of the discontinued LLVM Phabricator instance.

[RegisterCoalescer] Avoid coalescing erased Copy
AbandonedPublic

Authored by guopeilin on Jun 28 2021, 5:59 AM.

Diff Detail

Event Timeline

guopeilin created this revision.Jun 28 2021, 5:59 AM
guopeilin requested review of this revision.Jun 28 2021, 5:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2021, 5:59 AM
guopeilin added a comment.EditedJun 28 2021, 6:07 AM

Sometimes the CurrList may have two identical instructions that will be coalesced later. Once the first one coalesced, it will be removed from its parent, this will make the second identical instruction become illegal at the same time which getParent will be a nullptr. In this case, we should avoid coalescing erased instruction.<br>
The test case will trigger an Assertion like the following:

llvm-project/llvm/include/llvm/CodeGen/MachineOperand.h:359: llvm::Register llvm::MachineOperand::getReg() const: Assertion `isReg() && "This is not a register operand!"' failed.

Also recorded in Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=50919

qcolombet requested changes to this revision.Jul 7 2021, 11:50 AM
qcolombet added inline comments.
llvm/lib/CodeGen/RegisterCoalescer.cpp
3869

Sometimes the CurrList may have two identical instructions that will be coalesced later. Once the first one coalesced, it will be removed from its parent, this will make the second identical instruction become illegal at the same time which getParent will be a nullptr.

When that happens the instruction should be part of ErasedInst and we would skip it in the next conditional block.

Why is it not happening?

BTW

Once the first one coalesced, it will be removed from its parent,

It is removed or erased? If the latter, accessing the pointer is UB, so testing getParent is invalid.

This revision now requires changes to proceed.Jul 7 2021, 11:50 AM
guopeilin abandoned this revision.Aug 16 2021, 6:59 PM