1 ; RUN: opt -S -passes=callsite-splitting -o - < %s | FileCheck %s --check-prefixes=CHECK,CHECK-DEBUG
2 ; RUN: opt -S -strip-debug -passes=callsite-splitting -o - < %s | FileCheck %s
4 define internal i16 @bar(i16 %p1, i16 %p2) {
5 %_tmp3 = mul i16 %p2, %p1
9 define i16 @foo(i16 %in) {
11 %a = alloca i16, align 4, !DIAssignID !12
12 call void @llvm.dbg.assign(metadata i1 undef, metadata !11, metadata !DIExpression(), metadata !12, metadata ptr %a, metadata !DIExpression()), !dbg !8
13 store i16 7, ptr %a, align 4, !DIAssignID !13
17 %0 = icmp ne i16 %in, 0
18 br i1 %0, label %bb2, label %CallsiteBB
24 %1 = phi i16 [ 0, %bb1 ], [ 1, %bb2 ]
25 %c = phi i16 [ 2, %bb1 ], [ 3, %bb2 ]
26 %p = phi ptr [ %a, %bb1 ], [ %a, %bb2 ]
27 call void @llvm.dbg.value(metadata i16 %1, metadata !7, metadata !DIExpression()), !dbg !8
28 call void @llvm.dbg.value(metadata i16 %c, metadata !7, metadata !DIExpression()), !dbg !8
29 call void @llvm.dbg.value(metadata !DIArgList(i16 %1, i16 %c), metadata !7, metadata !DIExpression()), !dbg !8
30 call void @llvm.dbg.value(metadata !DIArgList(i16 %c, i16 %c), metadata !7, metadata !DIExpression()), !dbg !8
31 call void @llvm.dbg.assign(metadata i16 %1, metadata !11, metadata !DIExpression(), metadata !13, metadata ptr %a, metadata !DIExpression()), !dbg !8
32 call void @llvm.dbg.assign(metadata i16 %c, metadata !11, metadata !DIExpression(), metadata !13, metadata ptr %a, metadata !DIExpression()), !dbg !8
33 call void @llvm.dbg.assign(metadata i16 %1, metadata !11, metadata !DIExpression(), metadata !13, metadata ptr %p, metadata !DIExpression()), !dbg !8
34 %2 = call i16 @bar(i16 %1, i16 5)
38 ; Function Attrs: nounwind readnone speculatable
39 declare void @llvm.dbg.value(metadata, metadata, metadata) #0
40 declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
42 attributes #0 = { nounwind readnone speculatable }
45 !llvm.module.flags = !{!2, !3}
48 !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "My Compiler")
49 !1 = !DIFile(filename: "foo.c", directory: "/bar")
50 !2 = !{i32 2, !"Dwarf Version", i32 4}
51 !3 = !{i32 2, !"Debug Info Version", i32 3}
52 !4 = !{!"My Compiler"}
53 !5 = !DIBasicType(name: "int", size: 16, encoding: DW_ATE_signed)
54 !6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 4, unit: !0)
55 !7 = !DILocalVariable(name: "c", scope: !6, line: 5, type: !5)
56 !8 = !DILocation(line: 5, column: 7, scope: !6)
57 !11 = !DILocalVariable(name: "a", scope: !6, line: 6, type: !5)
58 !12 = distinct !DIAssignID()
59 !13 = distinct !DIAssignID()
61 ; The optimization should trigger even in the presence of the dbg.value in
65 ; CHECK-LABEL: bb1.split:
66 ; CHECK-DEBUG: #dbg_value(i16 0, ![[DBG_1:[0-9]+]], {{.*}}
67 ; CHECK-DEBUG: #dbg_value(i16 2, ![[DBG_1]], {{.*}}
68 ; CHECK-DEBUG: #dbg_value(!DIArgList(i16 0, i16 2), {{.*}}
69 ; CHECK-DEBUG: #dbg_value(!DIArgList(i16 2, i16 2), {{.*}}
70 ; CHECK-DEBUG: #dbg_assign(i16 0, ![[DBG_2:[0-9]+]], {{.*}}
71 ; CHECK-DEBUG: #dbg_assign(i16 2, ![[DBG_2]], {{.*}}
72 ; CHECK-DEBUG: #dbg_assign(i16 0, ![[DBG_2]], !DIExpression(), ![[ID_1:[0-9]+]], ptr %a, {{.*}}
73 ; CHECK: [[TMP1:%[0-9]+]] = call i16 @bar(i16 0, i16 5)
75 ; CHECK-LABEL: bb2.split:
76 ; CHECK-DEBUG: #dbg_value(i16 1, ![[DBG_1]], {{.*}}
77 ; CHECK-DEBUG: #dbg_value(i16 3, ![[DBG_1]], {{.*}}
78 ; CHECK-DEBUG: #dbg_value(!DIArgList(i16 1, i16 3), {{.*}}
79 ; CHECK-DEBUG: #dbg_value(!DIArgList(i16 3, i16 3), {{.*}}
80 ; CHECK-DEBUG: #dbg_assign(i16 1, ![[DBG_2]], {{.*}}
81 ; CHECK-DEBUG: #dbg_assign(i16 3, ![[DBG_2]], {{.*}}
82 ; CHECK-DEBUG: #dbg_assign(i16 1, ![[DBG_2]], !DIExpression(), ![[ID_1:[0-9]+]], ptr %a, {{.*}}
83 ; CHECK: [[TMP2:%[0-9]+]] = call i16 @bar(i16 1, i16 5)
85 ; CHECK-LABEL: CallsiteBB
86 ; CHECK: %phi.call = phi i16 [ [[TMP2]], %bb2.split ], [ [[TMP1]], %bb1.split
88 ; CHECK-DEBUG-DAG: ![[DBG_1]] = !DILocalVariable(name: "c"{{.*}})
89 ; CHECK-DEBUG-DAG: ![[DBG_2]] = !DILocalVariable(name: "a"{{.*}})
90 ; CHECK-DEBUG-DAG: ![[ID_1]] = distinct !DIAssignID()