[llvm] ee7ea10 - [CodeGen] PHIEliminationImpl::LowerPHINode: Fix assertion failure when all phi operands are undefined (#209013)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 24 07:21:00 PDT 2026


Author: rdevshp
Date: 2026-07-24T16:20:54+02:00
New Revision: ee7ea10c141cbf69ff10a25bfde05bd8e67b295f

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

LOG: [CodeGen] PHIEliminationImpl::LowerPHINode: Fix assertion failure when all phi operands are undefined (#209013)

IncomingReg is only set to a register when allPhiOperandsUndefined does
not hold. Changes PHIEliminationImpl::LowerPHINode to check IncomingReg
before using it for debug phi.

Fixes #206324

Assisted-by: Codex

Added: 
    llvm/test/DebugInfo/MIR/InstrRef/undef-phi-through-regalloc.mir

Modified: 
    llvm/lib/CodeGen/PHIElimination.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/PHIElimination.cpp b/llvm/lib/CodeGen/PHIElimination.cpp
index 1feeb0deb155f..054e24bc02069 100644
--- a/llvm/lib/CodeGen/PHIElimination.cpp
+++ b/llvm/lib/CodeGen/PHIElimination.cpp
@@ -424,7 +424,7 @@ void PHIEliminationImpl::LowerPHINode(MachineBasicBlock &MBB,
         MBB, AfterPHIsIt, MPhi->getDebugLoc(), IncomingReg, DestReg);
   }
 
-  if (MPhi->peekDebugInstrNum()) {
+  if (MPhi->peekDebugInstrNum() && IncomingReg) {
     // If referred to by debug-info, store where this PHI was.
     MachineFunction *MF = MBB.getParent();
     unsigned ID = MPhi->peekDebugInstrNum();

diff  --git a/llvm/test/DebugInfo/MIR/InstrRef/undef-phi-through-regalloc.mir b/llvm/test/DebugInfo/MIR/InstrRef/undef-phi-through-regalloc.mir
new file mode 100644
index 0000000000000..68c4589798078
--- /dev/null
+++ b/llvm/test/DebugInfo/MIR/InstrRef/undef-phi-through-regalloc.mir
@@ -0,0 +1,40 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+# RUN: llc %s -o - -mtriple=x86_64-unknown-unknown \
+# RUN:    -experimental-debug-variable-locations \
+# RUN:    -run-pass=phi-node-elimination,livedebugvars,greedy,virtregrewriter \
+# RUN:    | FileCheck %s
+#
+# This test checks phi-node-elimination does not create a debug phi
+# with invalid register reference
+
+--- |
+  define void @f() !dbg !2 {
+    ret void
+  }
+
+  !llvm.dbg.cu = !{!0}
+  !llvm.module.flags = !{!1}
+  !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !DIFile(filename: "x", directory: ""), emissionKind: FullDebug)
+  !1 = !{i32 2, !"Debug Info Version", i32 3}
+  !2 = distinct !DISubprogram(scope: !0, type: !DISubroutineType(types: !{null}), unit: !0, retainedNodes: !{!6})
+  !6 = !DILocalVariable(scope: !2)
+...
+---
+name: f
+debugInstrRef: true
+body: |
+  ; CHECK-LABEL: name: f
+  ; CHECK: bb.0:
+  ; CHECK-NEXT:   successors: %bb.1(0x80000000)
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT: bb.1:
+  ; CHECK-NEXT:   dead renamable $al = IMPLICIT_DEF
+  ; CHECK-NEXT:   DBG_INSTR_REF !7, !DIExpression(), dbg-instr-ref(1, 0), debug-location !DILocation(line: 0, scope: !3)
+  ; CHECK-NEXT:   RET 0
+  bb.0:
+    successors: %bb.1
+  bb.1:
+    %0:gr8 = PHI undef %0:gr8, %bb.0, debug-instr-number 1
+    DBG_INSTR_REF !6, !DIExpression(), dbg-instr-ref(1, 0), debug-location !DILocation(line: 0, scope: !2)
+    RET 0
+...


        


More information about the llvm-commits mailing list