[llvm] 133e25f - [DebugInfo][InstrRef] Ignore SP clobbers on call instructions even more

Jeremy Morse via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 24 09:26:22 PST 2021


Author: Jeremy Morse
Date: 2021-11-24T17:25:48Z
New Revision: 133e25f946f87916da0e165855298c5f3394b752

URL: https://github.com/llvm/llvm-project/commit/133e25f946f87916da0e165855298c5f3394b752
DIFF: https://github.com/llvm/llvm-project/commit/133e25f946f87916da0e165855298c5f3394b752.diff

LOG: [DebugInfo][InstrRef] Ignore SP clobbers on call instructions even more

Avoid un-necessarily recreating DBG_VALUEs on call instructions.

In LiveDebugvalues we choose to ignore any clobbers of SP by call
instructions, as they're irrelevant to our model of the machine. We
currently do so for tracking register values (MTracker); do the same for
tracking variable locations (TTracker).

Test modified to endure that a duplicate DBG_VALUE is not created after the
call in struction in this test.

Differential Revision: https://reviews.llvm.org/D114365

Added: 
    

Modified: 
    llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
    llvm/test/DebugInfo/X86/dbg-addr.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
index a4eb3094612bb..4b19df04da143 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -1288,6 +1288,10 @@ void InstrRefBasedLDV::transferRegisterDef(MachineInstr &MI) {
   } else if (MI.isMetaInstruction())
     return;
 
+  auto IgnoreSPAlias = [this, &MI](Register R) -> bool {
+    return MI.isCall() && MTracker->SPAliases.count(R);
+  };
+
   // Find the regs killed by MI, and find regmasks of preserved regs.
   // Max out the number of statically allocated elements in `DeadRegs`, as this
   // prevents fallback to std::set::count() operations.
@@ -1298,7 +1302,7 @@ void InstrRefBasedLDV::transferRegisterDef(MachineInstr &MI) {
     // Determine whether the operand is a register def.
     if (MO.isReg() && MO.isDef() && MO.getReg() &&
         Register::isPhysicalRegister(MO.getReg()) &&
-        !(MI.isCall() && MTracker->SPAliases.count(MO.getReg()))) {
+        !IgnoreSPAlias(MO.getReg())) {
       // Remove ranges of all aliased registers.
       for (MCRegAliasIterator RAI(MO.getReg(), TRI, true); RAI.isValid(); ++RAI)
         // FIXME: Can we break out of this loop early if no insertion occurs?
@@ -1347,6 +1351,9 @@ void InstrRefBasedLDV::transferRegisterDef(MachineInstr &MI) {
       continue;
 
     Register Reg = MTracker->LocIdxToLocID[L.Idx];
+    if (IgnoreSPAlias(Reg))
+      continue;
+
     for (auto *MO : RegMaskPtrs)
       if (MO->clobbersPhysReg(Reg))
         TTracker->clobberMloc(L.Idx, MI.getIterator(), false);

diff  --git a/llvm/test/DebugInfo/X86/dbg-addr.ll b/llvm/test/DebugInfo/X86/dbg-addr.ll
index ffdd90e711d0d..f55686fafebc3 100644
--- a/llvm/test/DebugInfo/X86/dbg-addr.ll
+++ b/llvm/test/DebugInfo/X86/dbg-addr.ll
@@ -1,13 +1,20 @@
+;; Run twice -- once with DBG_VALUEs, once with instruction referencing.
 ; RUN: llc %s -o %t.s -experimental-debug-variable-locations=false
 ; RUN: llvm-mc -triple x86_64--linux %t.s -filetype=obj -o %t.o
 ; RUN: FileCheck < %t.s %s
 ; RUN: llvm-dwarfdump %t.o | FileCheck %s --check-prefix=DWARF
+; RUN: llc %s -o %t.s -experimental-debug-variable-locations=true
+; RUN: llvm-mc -triple x86_64--linux %t.s -filetype=obj -o %t.o
+; RUN: FileCheck < %t.s %s
+; RUN: llvm-dwarfdump %t.o | FileCheck %s --check-prefix=DWARF
+
 
 ; Unlike dbg.declare, dbg.addr should be lowered to DBG_VALUE instructions. It
 ; is control-dependent.
 
 ; CHECK-LABEL: use_dbg_addr:
 ; CHECK: #DEBUG_VALUE: use_dbg_addr:o <- [$rsp+0]
+; CHECK-NOT: #DEBUG_VALUE:
 
 ; DWARF: DW_TAG_variable
 ; DWARF-NEXT:              DW_AT_location (DW_OP_fbreg +0)


        


More information about the llvm-commits mailing list