[PATCH] D108641: [DebugInfo][InstrRef] Avoid a debug-info-affects-codegen scenario in MCP

Jeremy Morse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 15 02:42:10 PDT 2021


jmorse updated this revision to Diff 379943.
jmorse added a comment.

Rebase, fix comment, remove setIsDebug now that a different approach is used for that after D110105 <https://reviews.llvm.org/D110105>.

On the unit test front, I think D110105 <https://reviews.llvm.org/D110105> avoids this problem now, any register operand added to a debug instruction will now get the isDebug flag set on it.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108641/new/

https://reviews.llvm.org/D108641

Files:
  llvm/include/llvm/CodeGen/MachineRegisterInfo.h
  llvm/test/DebugInfo/ARM/machine-cp-updates-dbg-reg.mir


Index: llvm/test/DebugInfo/ARM/machine-cp-updates-dbg-reg.mir
===================================================================
--- llvm/test/DebugInfo/ARM/machine-cp-updates-dbg-reg.mir
+++ llvm/test/DebugInfo/ARM/machine-cp-updates-dbg-reg.mir
@@ -3,10 +3,13 @@
 ## Ensure that when the destination register of a copy instruction is used by a
 ## DBG_VALUE/DBG_VALUE_LIST, and then that instruction is deleted during copy
 ## propagation, the debug use is updated to the source register.
+##
+## Do the same for DBG_PHI instructions.
 
 # CHECK: ![[VAR_V:[0-9]+]] = !DILocalVariable(name: "v"
 # CHECK-LABEL: body:
 
+# CHECK: DBG_PHI $r0, 1
 # CHECK: DBG_VALUE $r0, $noreg, ![[VAR_V]], !DIExpression()
 # CHECK: DBG_VALUE_LIST ![[VAR_V]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 4, DW_OP_mul, DW_OP_plus, DW_OP_stack_value), $r0, 0
 
@@ -179,6 +182,7 @@
 
     dead renamable $r1 = LDRi12 undef renamable $r0, 0, 14 /* CC::al */, $noreg :: (volatile load (s32) from `i32* undef`)
     renamable $r4 = COPY killed renamable $r0
+    DBG_PHI $r4, 1
     DBG_VALUE $r4, $noreg, !30, !DIExpression(), debug-location !40
     DBG_VALUE_LIST !30, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 4, DW_OP_mul, DW_OP_plus, DW_OP_stack_value), $r4, 0, debug-location !40
     $r0 = COPY killed renamable $r4
Index: llvm/include/llvm/CodeGen/MachineRegisterInfo.h
===================================================================
--- llvm/include/llvm/CodeGen/MachineRegisterInfo.h
+++ llvm/include/llvm/CodeGen/MachineRegisterInfo.h
@@ -821,7 +821,7 @@
   /// deleted during LiveDebugVariables analysis.
   void markUsesInDebugValueAsUndef(Register Reg) const;
 
-  /// updateDbgUsersToReg - Update a collection of DBG_VALUE instructions
+  /// updateDbgUsersToReg - Update a collection of debug instructions
   /// to refer to the designated register.
   void updateDbgUsersToReg(MCRegister OldReg, MCRegister NewReg,
                            ArrayRef<MachineInstr *> Users) const {
@@ -829,21 +829,34 @@
     for (MCRegUnitIterator RUI(OldReg, getTargetRegisterInfo()); RUI.isValid();
          ++RUI)
       OldRegUnits.insert(*RUI);
-    for (MachineInstr *MI : Users) {
-      assert(MI->isDebugValue());
-      for (auto &Op : MI->debug_operands()) {
-        if (Op.isReg()) {
-          for (MCRegUnitIterator RUI(OldReg, getTargetRegisterInfo());
-               RUI.isValid(); ++RUI) {
-            if (OldRegUnits.contains(*RUI)) {
-              Op.setReg(NewReg);
-              break;
-            }
+
+    // If this operand is a register, check whether it overlaps with OldReg.
+    // If it does, replace with NewReg.
+    auto UpdateOp = [this, &NewReg, &OldReg, &OldRegUnits](MachineOperand &Op) {
+      if (Op.isReg()) {
+        for (MCRegUnitIterator RUI(OldReg, getTargetRegisterInfo());
+             RUI.isValid(); ++RUI) {
+          if (OldRegUnits.contains(*RUI)) {
+            Op.setReg(NewReg);
+            break;
           }
         }
       }
-      assert(MI->hasDebugOperandForReg(NewReg) &&
-             "Expected debug value to have some overlap with OldReg");
+    };
+
+    // Iterate through (possibly several) operands to DBG_VALUEs and update
+    // each. For DBG_PHIs, only one operand will be present.
+    for (MachineInstr *MI : Users) {
+      if (MI->isDebugValue()) {
+        for (auto &Op : MI->debug_operands())
+          UpdateOp(Op);
+        assert(MI->hasDebugOperandForReg(NewReg) &&
+               "Expected debug value to have some overlap with OldReg");
+      } else if (MI->isDebugPHI()) {
+        UpdateOp(MI->getOperand(0));
+      } else {
+        llvm_unreachable("Non-DBG_VALUE, Non-DBG_PHI debug instr updated");
+      }
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108641.379943.patch
Type: text/x-patch
Size: 3759 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211015/95a2084c/attachment.bin>


More information about the llvm-commits mailing list