Skip to content

Commit

Permalink
[MachineSink] Some more preserving of debug location when rematerial…
Browse files Browse the repository at this point in the history
…ising an instruction to replace a COPY (llvm#73155)

Somewhat similar to ef9bcac
([MachineSink][AArch64] Preserve debug location when rematerialising
an instruction to replace a COPY (llvm#72685))
reuse the debug location of the COPY, iff the rematerialised instruction
did not have a location.

Fixes a regression in `DebugInfo/AArch64/constant-dbgloc.ll` after
enabling sink-and-fold.
  • Loading branch information
momchil-velikov authored Nov 24, 2023
1 parent 59edb43 commit 6b87d84
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion llvm/lib/CodeGen/MachineSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ bool MachineSinking::PerformSinkAndFold(MachineInstr &MI,
MRI->clearKillFlags(UsedRegB);

for (auto &[SinkDst, MaybeAM] : SinkInto) {
[[maybe_unused]] MachineInstr *New = nullptr;
MachineInstr *New = nullptr;
LLVM_DEBUG(dbgs() << "Sinking copy of"; MI.dump(); dbgs() << "into";
SinkDst->dump());
if (SinkDst->isCopy()) {
Expand All @@ -525,6 +525,8 @@ bool MachineSinking::PerformSinkAndFold(MachineInstr &MI,
Register DstReg = SinkDst->getOperand(0).getReg();
TII->reMaterialize(*SinkDst->getParent(), InsertPt, DstReg, 0, MI, *TRI);
New = &*std::prev(InsertPt);
if (!New->getDebugLoc())
New->setDebugLoc(SinkDst->getDebugLoc());
} else {
// Fold instruction into the addressing mode of a memory instruction.
New = TII->emitLdStWithAddr(*SinkDst, MaybeAM);
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/DebugInfo/AArch64/constant-dbgloc.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: llc -filetype=asm %s -o - | FileCheck %s
; RUN: llc -filetype=asm --aarch64-enable-sink-fold=true %s -o - | FileCheck %s

target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
target triple = "aarch64--linux-gnueabihf"
Expand Down

0 comments on commit 6b87d84

Please sign in to comment.