1 ; RUN: opt %s -passes=instcombine -S | FileCheck %s
3 ; Test sinking of dbg.values when instcombine sinks associated instructions.
5 declare void @llvm.dbg.value(metadata, metadata, metadata)
7 ; This GEP is sunk, but can be folded into a DIExpression. Check that it
8 ; gets folded. The dbg.value should be duplicated in the block its sunk
9 ; into, to maximise liveness.
11 ; CHECK-LABEL: define i32 @foo(ptr
12 ; CHECK: #dbg_value(ptr %a, !{{[0-9]+}},
13 ; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, 4, DW_OP_stack_value),
14 ; CHECK-NEXT: br label %sink1
16 define i32 @foo(ptr %a) !dbg !7 {
18 %gep = getelementptr i32, ptr %a, i32 1
19 call void @llvm.dbg.value(metadata ptr %gep, metadata !16, metadata !12), !dbg !15
24 ; CHECK: #dbg_value(ptr %gep,
25 ; CHECK-SAME: !{{[0-9]+}}, !DIExpression(),
27 %0 = load i32, ptr %gep, align 4, !dbg !15
31 ; In this example the GEP cannot (yet) be salvaged. Check that not only is the
32 ; dbg.value sunk, but an undef dbg.value is left to terminate any earlier
35 ; CHECK-LABEL: define i32 @bar(
36 ; CHECK: #dbg_value(ptr poison,
37 ; CHECK-NEXT: br label %sink2
39 define i32 @bar(ptr %a, i32 %b) !dbg !70 {
41 %gep = getelementptr <vscale x 4 x i32>, ptr %a, i32 %b
42 call void @llvm.dbg.value(metadata ptr %gep, metadata !73, metadata !12), !dbg !74
47 ; CHECK: #dbg_value(ptr %gep,
48 ; CHECK-SAME: !{{[0-9]+}}, !DIExpression(),
50 ; CHECK-NEXT: extractelement
52 %0 = load <vscale x 4 x i32>, ptr %gep
53 %extract = extractelement <vscale x 4 x i32> %0, i32 1
57 ; This GEP is sunk, and has multiple debug uses in the same block. Check that
58 ; only the last use is cloned into the sunk block, and that both of the
59 ; original dbg.values are salvaged.
61 ; CHECK-LABEL: define i32 @baz(ptr
62 ; CHECK: #dbg_value(ptr %a, !{{[0-9]+}},
63 ; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, 4, DW_OP_stack_value),
64 ; CHECK-NEXT: #dbg_value(ptr %a, !{{[0-9]+}},
65 ; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, 9, DW_OP_stack_value),
66 ; CHECK-NEXT: br label %sink1
68 define i32 @baz(ptr %a) !dbg !80 {
70 %gep = getelementptr i32, ptr %a, i32 1
71 call void @llvm.dbg.value(metadata ptr %gep, metadata !83, metadata !12), !dbg !84
72 call void @llvm.dbg.value(metadata ptr %gep, metadata !83, metadata !DIExpression(DW_OP_plus_uconst, 5)), !dbg !85
77 ; CHECK: #dbg_value(ptr %gep,
78 ; CHECK-SAME: !{{[0-9]+}}, !DIExpression(DW_OP_plus_uconst, 5),
80 %0 = load i32, ptr %gep, align 4, !dbg !85
85 !llvm.module.flags = !{!3, !4, !5}
88 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
89 !1 = !DIFile(filename: "a.c", directory: ".")
91 !3 = !{i32 2, !"Dwarf Version", i32 4}
92 !4 = !{i32 2, !"Debug Info Version", i32 3}
93 !5 = !{i32 1, !"PIC Level", i32 2}
95 !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
96 !8 = !DISubroutineType(types: !9)
98 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
99 !11 = !DILocalVariable(name: "j", scope: !7, file: !1, line: 2, type: !10)
100 !12 = !DIExpression()
101 !15 = !DILocation(line: 5, column: 3, scope: !7)
102 !16 = !DILocalVariable(name: "h", scope: !7, file: !1, line: 4, type: !10)
103 !70 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 2, type: !71, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
104 !71 = !DISubroutineType(types: !72)
105 !72 = !{!10, !10, !10}
106 !73 = !DILocalVariable(name: "k", scope: !70, file: !1, line: 2, type: !10)
107 !74 = !DILocation(line: 5, column: 3, scope: !70)
108 !80 = distinct !DISubprogram(name: "baz", scope: !1, file: !1, line: 2, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
109 !83 = !DILocalVariable(name: "l", scope: !80, file: !1, line: 2, type: !10)
110 !84 = !DILocation(line: 5, column: 3, scope: !80)
111 !85 = !DILocation(line: 6, column: 3, scope: !80)