Skip to content

[MachineSink] Drop debug info for instructions deleted by sink-and-fold #71443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions llvm/lib/CodeGen/MachineSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,30 +510,23 @@ bool MachineSinking::PerformSinkAndFold(MachineInstr &MI,
LLVM_DEBUG(dbgs() << "Sinking copy of"; MI.dump(); dbgs() << "into";
SinkDst->dump());
if (SinkDst->isCopy()) {
// TODO: After performing the sink-and-fold, the original instruction is
// deleted. Its value is still available (in a hard register), so if there
// are debug instructions which refer to the (now deleted) virtual
// register they could be updated to refer to the hard register, in
// principle. However, it's not clear how to do that, moreover in some
// cases the debug instructions may need to be replicated proportionally
// to the number of the COPY instructions replaced and in some extreme
// cases we can end up with quadratic increase in the number of debug
// instructions.

// Sink a copy of the instruction, replacing a COPY instruction.
MachineBasicBlock::iterator InsertPt = SinkDst->getIterator();
Register DstReg = SinkDst->getOperand(0).getReg();
TII->reMaterialize(*SinkDst->getParent(), InsertPt, DstReg, 0, MI, *TRI);
// If the original instruction did not have source location, reuse a one
// from the COPY.
// Reuse the source location from the COPY.
New = &*std::prev(InsertPt);
if (const DebugLoc &NewLoc = New->getDebugLoc(); !NewLoc)
New->setDebugLoc(SinkDst->getDebugLoc());
// Sink DBG_VALUEs, which refer to the original instruction's destination
// (DefReg).
MachineBasicBlock &SinkMBB = *SinkDst->getParent();
auto &DbgUsers = SeenDbgUsers[DefReg];
for (auto &U : DbgUsers) {
MachineInstr *DbgMI = U.getPointer();
if (U.getInt())
continue;
MachineInstr *NewDbgMI = SinkDst->getMF()->CloneMachineInstr(DbgMI);
SinkMBB.insertAfter(InsertPt, NewDbgMI);
for (auto &SrcMO : DbgMI->getDebugOperandsForReg(DefReg)) {
auto &DstMO = NewDbgMI->getOperand(SrcMO.getOperandNo());
DstMO.setReg(DstReg);
}
}
New->setDebugLoc(SinkDst->getDebugLoc());
} else {
// Fold instruction into the addressing mode of a memory instruction.
New = TII->emitLdStWithAddr(*SinkDst, MaybeAM);
Expand Down
304 changes: 0 additions & 304 deletions llvm/test/CodeGen/AArch64/sink-and-fold-dbg-value-crash.mir

This file was deleted.

Loading