Skip to content

Conversation

@pcc
Copy link
Contributor

@pcc pcc commented Dec 20, 2025

Previously we were unconditionally setting operand 0 to a register which
is the metadata operand with DEBUG_VALUE_LIST, which led to assertion
failures. DEBUG_VALUE_LIST register operands start with operand 2,
so enumerate them and clear any that are already registers.

Exposed by #172962. No test because I'm not sure how to test this on
its own.

Created using spr 1.3.6-beta.1
@llvmbot llvmbot added the llvm:SelectionDAG SelectionDAGISel as well label Dec 20, 2025
@pcc pcc requested a review from efriedma-quic December 20, 2025 03:23
@llvmbot
Copy link
Member

llvmbot commented Dec 20, 2025

@llvm/pr-subscribers-llvm-selectiondag

Author: Peter Collingbourne (pcc)

Changes

Previously we were unconditionally setting operand 0 to a register which
is the metadata operand with DEBUG_VALUE_LIST, which led to assertion
failures. DEBUG_VALUE_LIST register operands start with operand 2,
so enumerate them and clear any that are already registers.

Exposed by #172962. No test because I'm not sure how to test this on
its own.


Full diff: https://github.com/llvm/llvm-project/pull/173133.diff

1 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp (+7-1)
diff --git a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
index 4f4fb9c759ad7..c66549235a8a0 100644
--- a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
@@ -1083,7 +1083,13 @@ EmitSchedule(MachineBasicBlock::iterator &InsertPos) {
 
       // The DBG_VALUE was referencing a value produced by a terminator. By
       // moving the DBG_VALUE, the referenced value also needs invalidating.
-      MI.getOperand(0).ChangeToRegister(0, false);
+      if (MI.isDebugValueList()) {
+        for (auto &Op : MI.operands())
+          if (Op.isReg())
+            Op.ChangeToRegister(0, false);
+      } else {
+        MI.getOperand(0).ChangeToRegister(0, false);
+      }
       MI.moveBefore(&*FirstTerm);
     }
   }

if (MI.isDebugValueList()) {
for (auto &Op : MI.operands())
if (Op.isReg())
Op.ChangeToRegister(0, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Op.ChangeToRegister(0, false);
Op.ChangeToRegister(Register(), false);

if (Op.isReg())
Op.ChangeToRegister(0, false);
} else {
MI.getOperand(0).ChangeToRegister(0, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MI.getOperand(0).ChangeToRegister(0, false);
MI.getOperand(0).ChangeToRegister(Register(), false);

// moving the DBG_VALUE, the referenced value also needs invalidating.
MI.getOperand(0).ChangeToRegister(0, false);
if (MI.isDebugValueList()) {
for (auto &Op : MI.operands())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto &Op : MI.operands())
for (MachineOperand &Op : MI.operands())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:SelectionDAG SelectionDAGISel as well

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants