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 i32* undef,
37 ; CHECK-NEXT: br label %sink2
39 define i32 @bar(i32 *%a, i32 %b) !dbg !70 {
41 %gep = getelementptr i32, i32 *%a, i32 %b
42 call void @llvm.dbg.value(metadata i32* %gep, metadata !73, metadata !12), !dbg !74
47 ; CHECK: call void @llvm.dbg.value(metadata i32* %gep,
48 ; CHECK-SAME: metadata !{{[0-9]+}}, metadata !DIExpression())
51 %0 = load i32, i32* %gep
56 !llvm.module.flags = !{!3, !4, !5}
59 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
60 !1 = !DIFile(filename: "a.c", directory: ".")
62 !3 = !{i32 2, !"Dwarf Version", i32 4}
63 !4 = !{i32 2, !"Debug Info Version", i32 3}
64 !5 = !{i32 1, !"PIC Level", i32 2}
66 !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)
67 !8 = !DISubroutineType(types: !9)
69 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
70 !11 = !DILocalVariable(name: "j", scope: !7, file: !1, line: 2, type: !10)
72 !15 = !DILocation(line: 5, column: 3, scope: !7)
73 !16 = !DILocalVariable(name: "h", scope: !7, file: !1, line: 4, type: !10)
74 !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)
75 !71 = !DISubroutineType(types: !72)
76 !72 = !{!10, !10, !10}
77 !73 = !DILocalVariable(name: "k", scope: !70, file: !1, line: 2, type: !10)
78 !74 = !DILocation(line: 5, column: 3, scope: !70)