Skip to content

Commit 2cb5308

Browse files
authored
[DebugInfo][InstrRef] Copy instr-ref to replacement instrs in X86FixupSetCCPass (#159777)
...to preserve variable location coverage. Fixes missing variable location coverage in #49818 reproducer
1 parent eb803df commit 2cb5308

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

llvm/lib/Target/X86/X86FixupSetCC.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ bool X86FixupSetCCPass::runOnMachineFunction(MachineFunction &MF) {
136136
.addReg(ZeroReg)
137137
.addReg(Reg0)
138138
.addImm(X86::sub_8bit);
139+
140+
// Redirect the debug-instr-number to the setcc.
141+
if (unsigned InstrNum = ZExt->peekDebugInstrNum())
142+
MF.makeDebugValueSubstitution({InstrNum, 0},
143+
{MI.getDebugInstrNum(), 0});
144+
139145
ToErase.push_back(ZExt);
140146
}
141147
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# RUN: llc %s --run-pass=x86-fixup-setcc -o - | FileCheck %s
2+
3+
## Check the debug-isntr-number transfers from MOVZX32rr8 to the SETCC
4+
## after the mov is replaced with an INSERT_SUBREG, updating the substitutions
5+
## table.
6+
7+
# CHECK: debugValueSubstitutions:
8+
# CHECK: - { srcinst: 1, srcop: 0, dstinst: 2, dstop: 0, subreg: 0 }
9+
10+
# CHECK: %[[#]]:gr8 = SETCCr 15, implicit $eflags, debug-instr-number 2
11+
# CHECK: INSERT_SUBREG
12+
# CHECK-NOT: debug-instr-number
13+
# CHECK-NEXT: DBG_INSTR_REF ![[#]], !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0)
14+
15+
--- |
16+
source_filename = "reduced.ll"
17+
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"
18+
target triple = "x86_64-unknown-linux-gnu"
19+
20+
define i32 @main(i32 %call2) {
21+
entry:
22+
%cmp12 = icmp sgt i32 %call2, 0
23+
%conv13 = zext i1 %cmp12 to i32
24+
#dbg_value(i32 %conv13, !4, !DIExpression(), !8)
25+
ret i32 %conv13
26+
}
27+
28+
!llvm.dbg.cu = !{!0}
29+
!llvm.module.flags = !{!3}
30+
31+
!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)
32+
!1 = !DIFile(filename: "test.c", directory: "/")
33+
!2 = !{}
34+
!3 = !{i32 2, !"Debug Info Version", i32 3}
35+
!4 = !DILocalVariable(name: "v_3", scope: !5, file: !1, line: 10, type: !7)
36+
!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)
37+
!6 = !DISubroutineType(types: !2)
38+
!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
39+
!8 = !DILocation(line: 0, scope: !5)
40+
...
41+
---
42+
name: main
43+
body: |
44+
bb.0.entry:
45+
liveins: $edi
46+
47+
%0:gr32 = COPY $edi
48+
TEST32rr %0, %0, implicit-def $eflags
49+
%1:gr8 = SETCCr 15, implicit $eflags
50+
%2:gr32 = MOVZX32rr8 killed %1, debug-instr-number 1
51+
DBG_INSTR_REF !4, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !8
52+
$eax = COPY %2
53+
RET 0, $eax
54+
...

0 commit comments

Comments
 (0)