[llvm] [MachineSink] Some more preserving of debug location when rematerialising an instruction to replace a COPY (PR #73155)

Momchil Velikov via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 23 06:01:17 PST 2023


https://github.com/momchil-velikov updated https://github.com/llvm/llvm-project/pull/73155

>From 09f5177393ce0634c0a673bd42d08c6aaed31617 Mon Sep 17 00:00:00 2001
From: Momchil Velikov <momchil.velikov at arm.com>
Date: Wed, 22 Nov 2023 17:19:01 +0000
Subject: [PATCH 1/2] [MachineSink] Some more preserving of debug location when
 rematerialising an instruction to replace a COPY

Somewhet similar to ef9bcace834e63f25bbbc5e8e2b615f89d85fb2f
([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.
---
 llvm/lib/CodeGen/MachineSink.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp
index 48f5a21406f08a8..83d775055dfd733 100644
--- a/llvm/lib/CodeGen/MachineSink.cpp
+++ b/llvm/lib/CodeGen/MachineSink.cpp
@@ -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()) {
@@ -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);

>From 89c1af2aed299b52b7ff04f59db63446cfa2d07f Mon Sep 17 00:00:00 2001
From: Momchil Velikov <momchil.velikov at arm.com>
Date: Thu, 23 Nov 2023 13:55:59 +0000
Subject: [PATCH 2/2] Enable sink-and-fold for the test

---
 llvm/test/DebugInfo/AArch64/constant-dbgloc.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/DebugInfo/AArch64/constant-dbgloc.ll b/llvm/test/DebugInfo/AArch64/constant-dbgloc.ll
index 1281123360bfff3..98ea453b2f9458c 100644
--- a/llvm/test/DebugInfo/AArch64/constant-dbgloc.ll
+++ b/llvm/test/DebugInfo/AArch64/constant-dbgloc.ll
@@ -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"



More information about the llvm-commits mailing list