Skip to content

Commit db89b6b

Browse files
committed
[DebugInfo][InstrRef] Copy instr-ref to replacement instrs in X86FixupSetCCPass
...to preserve variable location coverage. Partially fixes missing variable coverage mentioned in #49818 (the locations go missing again later in regalloc in that example).
1 parent e859265 commit db89b6b

File tree

2 files changed

+57
-5
lines changed

2 files changed

+57
-5
lines changed

llvm/lib/Target/X86/X86FixupSetCC.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,15 @@ bool X86FixupSetCCPass::runOnMachineFunction(MachineFunction &MF) {
131131
ZeroReg);
132132
}
133133

134-
BuildMI(*ZExt->getParent(), ZExt, ZExt->getDebugLoc(),
135-
TII->get(X86::INSERT_SUBREG), ZExt->getOperand(0).getReg())
136-
.addReg(ZeroReg)
137-
.addReg(Reg0)
138-
.addImm(X86::sub_8bit);
134+
MachineInstr *NewMI =
135+
BuildMI(*ZExt->getParent(), ZExt, ZExt->getDebugLoc(),
136+
TII->get(X86::INSERT_SUBREG), ZExt->getOperand(0).getReg())
137+
.addReg(ZeroReg)
138+
.addReg(Reg0)
139+
.addImm(X86::sub_8bit);
140+
// Copy the debug info instr-ref number from the zext to its replacement.
141+
if (unsigned InstrNum = ZExt->peekDebugInstrNum())
142+
NewMI->setDebugInstrNum(InstrNum);
139143
ToErase.push_back(ZExt);
140144
}
141145
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# RUN: llc %s --run-pass=x86-fixup-setcc -o - | FileCheck %s
2+
3+
## Check the debug-isntr-number transfers from MOVZX32rr8
4+
## to its replacement INSERT_SUBREG.
5+
6+
# CHECK: %[[#]]:gr32 = INSERT_SUBREG %[[#]], %[[#]], %subreg.sub_8bit, debug-instr-number 1
7+
# CHECK-NEXT: DBG_INSTR_REF !4, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0)
8+
9+
--- |
10+
source_filename = "reduced.ll"
11+
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"
12+
target triple = "x86_64-unknown-linux-gnu"
13+
14+
define i32 @main(i32 %call2) {
15+
entry:
16+
%cmp12 = icmp sgt i32 %call2, 0
17+
%conv13 = zext i1 %cmp12 to i32
18+
#dbg_value(i32 %conv13, !4, !DIExpression(), !8)
19+
ret i32 %conv13
20+
}
21+
22+
!llvm.dbg.cu = !{!0}
23+
!llvm.module.flags = !{!3}
24+
25+
!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)
26+
!1 = !DIFile(filename: "test.c", directory: "/")
27+
!2 = !{}
28+
!3 = !{i32 2, !"Debug Info Version", i32 3}
29+
!4 = !DILocalVariable(name: "v_3", scope: !5, file: !1, line: 10, type: !7)
30+
!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)
31+
!6 = !DISubroutineType(types: !2)
32+
!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
33+
!8 = !DILocation(line: 0, scope: !5)
34+
...
35+
---
36+
name: main
37+
body: |
38+
bb.0.entry:
39+
liveins: $edi
40+
41+
%0:gr32 = COPY $edi
42+
TEST32rr %0, %0, implicit-def $eflags
43+
%1:gr8 = SETCCr 15, implicit $eflags
44+
%2:gr32 = MOVZX32rr8 killed %1, debug-instr-number 1
45+
DBG_INSTR_REF !4, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !8
46+
$eax = COPY %2
47+
RET 0, $eax
48+
...

0 commit comments

Comments
 (0)