[PATCH] D114365: [DebugInfo][6/N][InstrRef] Ignore stack-pointer clobbers on call instructions even more

Jeremy Morse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 22 05:48:02 PST 2021


jmorse created this revision.
jmorse added reviewers: StephenTozer, Orlando, TWeaver.
Herald added a subscriber: hiraditya.
jmorse requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Avoid un-necessarily recreating DBG_VALUEs on call instructions.

In LiveDebugValues, we choose to ignore any clobbers of the stack pointer by call instructions, because they're irrelevant to our model of the machine. Otherwise, SP based locations could be terminated un-necessarily. In InstrRefBasedLDV::transferRegisterDef, we correctly ignore such clobbers when updating what values are in which registers (MTracker), but we tell the block variable location tracker (TTracker) that the stack pointer has been clobbered. This caused the modified test to fail as an un-necessary DBG_VALUE was created.

This patch just corrects what we're already trying to do: as well as ignoring stack-pointer clobbers by calls for register tracking, also ignore them for variable location tracking, and don't report the clobber to TTracker.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114365

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


Index: llvm/test/DebugInfo/X86/dbg-addr.ll
===================================================================
--- llvm/test/DebugInfo/X86/dbg-addr.ll
+++ llvm/test/DebugInfo/X86/dbg-addr.ll
@@ -1,4 +1,4 @@
-; RUN: llc %s -o %t.s -experimental-debug-variable-locations=false
+; 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
Index: llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
===================================================================
--- llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -1297,6 +1297,10 @@
   } 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.
@@ -1307,7 +1311,7 @@
     // 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?
@@ -1351,11 +1355,14 @@
   // Look for any clobbers performed by a register mask. Only test locations
   // that are actually being tracked.
   for (auto L : MTracker->locations()) {
-    // Stack locations can't be clobbered by regmasks.
+    // Stack locations can't be clobbered by regmasks
     if (MTracker->isSpill(L.Idx))
       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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114365.388892.patch
Type: text/x-patch
Size: 2244 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211122/ae22069e/attachment.bin>


More information about the llvm-commits mailing list