1 ; RUN: opt %s -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(i32*
12 ; CHECK: call void @llvm.dbg.value(metadata i32* %a, metadata !{{[0-9]+}},
13 ; CHECK-SAME: metadata !DIExpression(DW_OP_plus_uconst, 4, DW_OP_stack_value))
14 ; CHECK-NEXT: br label %sink1
16 define i32 @foo(i32 *%a) !dbg !7 {
18 %gep = getelementptr i32, i32 *%a, i32 1
19 call void @llvm.dbg.value(metadata i32 *%gep, metadata !16, metadata !12), !dbg !15
24 ; CHECK: call void @llvm.dbg.value(metadata i32* %gep,
25 ; CHECK-SAME: metadata !{{[0-9]+}}, metadata !DIExpression())
27 %0 = load i32, i32* %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: call void @llvm.dbg.value(metadata <vscale x 4 x i32>* undef,
37 ; CHECK-NEXT: br label %sink2
39 define i32 @bar(<vscale x 4 x i32>* %a, i32 %b) !dbg !70 {
41 %gep = getelementptr <vscale x 4 x i32>, <vscale x 4 x i32>* %a, i32 %b
42 call void @llvm.dbg.value(metadata <vscale x 4 x i32>* %gep, metadata !73, metadata !12), !dbg !74
47 ; CHECK: call void @llvm.dbg.value(metadata <vscale x 4 x i32>* %gep,
48 ; CHECK-SAME: metadata !{{[0-9]+}}, metadata !DIExpression())
50 ; CHECK-NEXT: extractelement
52 %0 = load <vscale x 4 x i32>, <vscale x 4 x i32>* %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
\r
58 ; only the last use is cloned into the sunk block, and that both of the
\r
59 ; original dbg.values are salvaged.
\r
61 ; CHECK-LABEL: define i32 @baz(i32*
\r
62 ; CHECK: call void @llvm.dbg.value(metadata i32* %a, metadata !{{[0-9]+}},
\r
63 ; CHECK-SAME: metadata !DIExpression(DW_OP_plus_uconst, 4, DW_OP_stack_value))
\r
64 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32* %a, metadata !{{[0-9]+}},
\r
65 ; CHECK-SAME: metadata !DIExpression(DW_OP_plus_uconst, 4, DW_OP_plus_uconst, 5, DW_OP_stack_value))
\r
66 ; CHECK-NEXT: br label %sink1
\r
68 define i32 @baz(i32 *%a) !dbg !80 {
\r
70 %gep = getelementptr i32, i32 *%a, i32 1
\r
71 call void @llvm.dbg.value(metadata i32 *%gep, metadata !83, metadata !12), !dbg !84
\r
72 call void @llvm.dbg.value(metadata i32 *%gep, metadata !83, metadata !DIExpression(DW_OP_plus_uconst, 5)), !dbg !85
\r
76 ; CHECK-LABEL: sink1:
\r
77 ; CHECK: call void @llvm.dbg.value(metadata i32* %gep,
\r
78 ; CHECK-SAME: metadata !{{[0-9]+}}, metadata !DIExpression(DW_OP_plus_uconst, 5))
\r
80 %0 = load i32, i32* %gep, align 4, !dbg !85
\r
81 ret i32 %0, !dbg !85
\r
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)
\r
109 !83 = !DILocalVariable(name: "l", scope: !80, file: !1, line: 2, type: !10)
\r
110 !84 = !DILocation(line: 5, column: 3, scope: !80)
\r
111 !85 = !DILocation(line: 6, column: 3, scope: !80)
\r