[llvm] 2cb5308 - [DebugInfo][InstrRef] Copy instr-ref to replacement instrs in X86FixupSetCCPass (#159777)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 2 02:45:32 PDT 2025
Author: Orlando Cazalet-Hyams
Date: 2025-10-02T10:45:27+01:00
New Revision: 2cb530868ca1d6e66e950f4b247b0905ee95d7eb
URL: https://github.com/llvm/llvm-project/commit/2cb530868ca1d6e66e950f4b247b0905ee95d7eb
DIFF: https://github.com/llvm/llvm-project/commit/2cb530868ca1d6e66e950f4b247b0905ee95d7eb.diff
LOG: [DebugInfo][InstrRef] Copy instr-ref to replacement instrs in X86FixupSetCCPass (#159777)
...to preserve variable location coverage.
Fixes missing variable location coverage in #49818 reproducer
Added:
llvm/test/DebugInfo/X86/x86fixupsetcc-debug-instr-num.mir
Modified:
llvm/lib/Target/X86/X86FixupSetCC.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86FixupSetCC.cpp b/llvm/lib/Target/X86/X86FixupSetCC.cpp
index 2de89947c4519..ea93a575ec530 100644
--- a/llvm/lib/Target/X86/X86FixupSetCC.cpp
+++ b/llvm/lib/Target/X86/X86FixupSetCC.cpp
@@ -136,6 +136,12 @@ bool X86FixupSetCCPass::runOnMachineFunction(MachineFunction &MF) {
.addReg(ZeroReg)
.addReg(Reg0)
.addImm(X86::sub_8bit);
+
+ // Redirect the debug-instr-number to the setcc.
+ if (unsigned InstrNum = ZExt->peekDebugInstrNum())
+ MF.makeDebugValueSubstitution({InstrNum, 0},
+ {MI.getDebugInstrNum(), 0});
+
ToErase.push_back(ZExt);
}
}
diff --git a/llvm/test/DebugInfo/X86/x86fixupsetcc-debug-instr-num.mir b/llvm/test/DebugInfo/X86/x86fixupsetcc-debug-instr-num.mir
new file mode 100644
index 0000000000000..b7149f0155ae3
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/x86fixupsetcc-debug-instr-num.mir
@@ -0,0 +1,54 @@
+# RUN: llc %s --run-pass=x86-fixup-setcc -o - | FileCheck %s
+
+## Check the debug-isntr-number transfers from MOVZX32rr8 to the SETCC
+## after the mov is replaced with an INSERT_SUBREG, updating the substitutions
+## table.
+
+# CHECK: debugValueSubstitutions:
+# CHECK: - { srcinst: 1, srcop: 0, dstinst: 2, dstop: 0, subreg: 0 }
+
+# CHECK: %[[#]]:gr8 = SETCCr 15, implicit $eflags, debug-instr-number 2
+# CHECK: INSERT_SUBREG
+# CHECK-NOT: debug-instr-number
+# CHECK-NEXT: DBG_INSTR_REF ![[#]], !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0)
+
+--- |
+ source_filename = "reduced.ll"
+ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+ target triple = "x86_64-unknown-linux-gnu"
+
+ define i32 @main(i32 %call2) {
+ entry:
+ %cmp12 = icmp sgt i32 %call2, 0
+ %conv13 = zext i1 %cmp12 to i32
+ #dbg_value(i32 %conv13, !4, !DIExpression(), !8)
+ ret i32 %conv13
+ }
+
+ !llvm.dbg.cu = !{!0}
+ !llvm.module.flags = !{!3}
+
+ !0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 22.0.0git", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !2, splitDebugInlining: false, nameTableKind: None)
+ !1 = !DIFile(filename: "test.c", directory: "/")
+ !2 = !{}
+ !3 = !{i32 2, !"Debug Info Version", i32 3}
+ !4 = !DILocalVariable(name: "v_3", scope: !5, file: !1, line: 10, type: !7)
+ !5 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 5, type: !6, scopeLine: 6, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2, keyInstructions: true)
+ !6 = !DISubroutineType(types: !2)
+ !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+ !8 = !DILocation(line: 0, scope: !5)
+...
+---
+name: main
+body: |
+ bb.0.entry:
+ liveins: $edi
+
+ %0:gr32 = COPY $edi
+ TEST32rr %0, %0, implicit-def $eflags
+ %1:gr8 = SETCCr 15, implicit $eflags
+ %2:gr32 = MOVZX32rr8 killed %1, debug-instr-number 1
+ DBG_INSTR_REF !4, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !8
+ $eax = COPY %2
+ RET 0, $eax
+...
More information about the llvm-commits
mailing list