Skip to content

Commit 6b87d84

Browse files
[MachineSink] Some more preserving of debug location when rematerialising an instruction to replace a COPY (#73155)
Somewhat similar to ef9bcac ([MachineSink][AArch64] Preserve debug location when rematerialising an instruction to replace a COPY (#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.
1 parent 59edb43 commit 6b87d84

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

llvm/lib/CodeGen/MachineSink.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ bool MachineSinking::PerformSinkAndFold(MachineInstr &MI,
506506
MRI->clearKillFlags(UsedRegB);
507507

508508
for (auto &[SinkDst, MaybeAM] : SinkInto) {
509-
[[maybe_unused]] MachineInstr *New = nullptr;
509+
MachineInstr *New = nullptr;
510510
LLVM_DEBUG(dbgs() << "Sinking copy of"; MI.dump(); dbgs() << "into";
511511
SinkDst->dump());
512512
if (SinkDst->isCopy()) {
@@ -525,6 +525,8 @@ bool MachineSinking::PerformSinkAndFold(MachineInstr &MI,
525525
Register DstReg = SinkDst->getOperand(0).getReg();
526526
TII->reMaterialize(*SinkDst->getParent(), InsertPt, DstReg, 0, MI, *TRI);
527527
New = &*std::prev(InsertPt);
528+
if (!New->getDebugLoc())
529+
New->setDebugLoc(SinkDst->getDebugLoc());
528530
} else {
529531
// Fold instruction into the addressing mode of a memory instruction.
530532
New = TII->emitLdStWithAddr(*SinkDst, MaybeAM);

llvm/test/DebugInfo/AArch64/constant-dbgloc.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llc -filetype=asm %s -o - | FileCheck %s
1+
; RUN: llc -filetype=asm --aarch64-enable-sink-fold=true %s -o - | FileCheck %s
22

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

0 commit comments

Comments
 (0)