Skip to content

Commit 4e1b9d3

Browse files
authored
[mir-strip-debug] Fix debug location info strip for bundled instructions (#113676)
Fix bug that `mir-strip-debug` pass does not remove debug location from bundled instructions. Problem arises during testing that debug info does not affect optimization passes output (`llvm-lit` with ` -Dllc="llc -debugify-and-strip-all-safe"`), when pass operates on MIR with bundled instructions + memory operands. Let mir test check looks like: ``` CHECK-NEXT: BUNDLE { CHECK-NEXT: $r3 = LD $r1, $r2 :: (load (s64) from %ir.a, !tbaa !2) CHECK-NEXT: } ``` So as `mir-strip-debug` pass does not process bundled instructions, running `llc -debugify-and-strip-all-safe` on the test will produce the following output: ``` BUNDLE { $r3 = LD $r1, $r2, debug-location !DILocation(line: 3, column: 1, scope: <0x608cb2b99b10>) :: (load (s64) from %ir.a, !tbaa !2) } ``` And test will fail, but it shouldn't. Seems like the root cause is that `mir-strip-debug` pass should remove debug location from bundled instructions.
1 parent d661aea commit 4e1b9d3

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

llvm/lib/CodeGen/MachineStripDebug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct StripDebugMachineModule : public ModulePass {
5050
continue;
5151
MachineFunction &MF = *MaybeMF;
5252
for (MachineBasicBlock &MBB : MF) {
53-
for (MachineInstr &MI : llvm::make_early_inc_range(MBB)) {
53+
for (MachineInstr &MI : llvm::make_early_inc_range(MBB.instrs())) {
5454
if (MI.isDebugInstr()) {
5555
// FIXME: We should remove all of them. However, AArch64 emits an
5656
// invalid `DBG_VALUE $lr` with only one operand instead of
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# RUN: llc -run-pass=mir-strip-debug -o - %s | FileCheck %s
2+
# RUN: llc -run-pass=mir-strip-debug,mir-debugify,mir-strip-debug -o - %s | FileCheck %s
3+
4+
--- |
5+
source_filename = "loc-only.ll"
6+
7+
define i32 @test(i32 %a, i32 %b) !dbg !6 {
8+
%add = add i32 %a, 2, !dbg !12
9+
call void @llvm.dbg.value(metadata i32 %add, metadata !9, metadata !DIExpression()), !dbg !12
10+
%sub = sub i32 %add, %b, !dbg !13
11+
call void @llvm.dbg.value(metadata i32 %sub, metadata !11, metadata !DIExpression()), !dbg !13
12+
ret i32 %sub, !dbg !14
13+
}
14+
15+
declare void @llvm.dbg.value(metadata, metadata, metadata)
16+
17+
!llvm.dbg.cu = !{!0}
18+
; CHECK-NOT: !llvm.dbg.cu
19+
!llvm.debugify = !{!3, !4}
20+
; CHECK-NOT: !llvm.debugify
21+
!llvm.module.flags = !{!5}
22+
; CHECK-NOT: !llvm.module.flags
23+
24+
; CHECK-NOT: !DI
25+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
26+
!1 = !DIFile(filename: "<stdin>", directory: "/")
27+
!2 = !{}
28+
!3 = !{i32 3}
29+
!4 = !{i32 2}
30+
!5 = !{i32 2, !"Debug Info Version", i32 3}
31+
!6 = distinct !DISubprogram(name: "test", linkageName: "test", scope: null, file: !1, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
32+
!7 = !DISubroutineType(types: !2)
33+
!8 = !{!9, !11}
34+
!9 = !DILocalVariable(name: "1", scope: !6, file: !1, line: 1, type: !10)
35+
!10 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)
36+
!11 = !DILocalVariable(name: "2", scope: !6, file: !1, line: 2, type: !10)
37+
!12 = !DILocation(line: 1, column: 1, scope: !6)
38+
!13 = !DILocation(line: 2, column: 1, scope: !6)
39+
!14 = !DILocation(line: 3, column: 1, scope: !6)
40+
41+
...
42+
---
43+
name: test
44+
body: |
45+
bb.1 (%ir-block.0):
46+
%0:_(s32) = G_IMPLICIT_DEF
47+
%1:_(s32) = G_IMPLICIT_DEF
48+
BUNDLE {
49+
%2:_(s32) = G_CONSTANT i32 2, debug-location !DILocation(line: 0, scope: !6)
50+
%3:_(s32) = G_ADD %0, %1, debug-location !12
51+
}
52+
53+
; CHECK-LABEL: body:
54+
; CHECK-NOT: debug-location
55+
; CHECK-NOT: !DI
56+
; CHECK-NEXT: bb
57+
; CHECK-NEXT: %0:_(s32) = G_IMPLICIT_DEF{{$}}
58+
; CHECK-NEXT: %1:_(s32) = G_IMPLICIT_DEF{{$}}
59+
; CHECK-NEXT: BUNDLE {
60+
; CHECK-NEXT: %2:_(s32) = G_CONSTANT i32 2{{$}}
61+
; CHECK-NEXT: %3:_(s32) = G_ADD %0, %1{{$}}
62+
; CHECK-NEXT: }
63+
...

0 commit comments

Comments
 (0)