1 ; RUN: opt < %s -O2 -gvn -S | FileCheck %s
3 ; Produced at -O2 from:
8 ; int pid_for_task(int);
9 ; sample(struct context *p1)
13 ; if (a && p1->cur_pid)
17 ; f = pid_for_task(d);
21 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
22 target triple = "arm64-apple-ios"
24 %struct.context = type { i32 }
26 @c = common global i32 0, align 4
27 @a = common global i32 0, align 4
28 @b = common global i32 0, align 4
29 @d = common global i32 0, align 4
30 @f = common global i32 0, align 4
32 ; Function Attrs: nounwind
33 declare i32 @sample_internal(...)
35 ; Function Attrs: nounwind
36 define i32 @callback() #0 {
38 %0 = load i32, i32* @d, align 4, !dbg !37
40 ; Verify that the call still has a debug location after GVN.
41 ; CHECK: %call = tail call i32 @pid_for_task(i32 %0) #{{[0-9]}}, !dbg
42 %call = tail call i32 @pid_for_task(i32 %0) #3, !dbg !37
44 store i32 %call, i32* @f, align 4, !dbg !37
45 tail call void @llvm.dbg.value(metadata %struct.context* bitcast (i32* @f to %struct.context*), i64 0, metadata !25, metadata !26) #3, !dbg !38
46 %1 = load i32, i32* @c, align 4, !dbg !40
47 %tobool.i = icmp eq i32 %1, 0, !dbg !40
48 %.pr.i = load i32, i32* @a, align 4, !dbg !41
49 br i1 %tobool.i, label %if.end.i, label %if.then.i, !dbg !42
51 if.then.i: ; preds = %entry
52 store i32 %.pr.i, i32* @b, align 4, !dbg !43
53 br label %if.end.i, !dbg !43
55 if.end.i: ; preds = %if.then.i, %entry
56 %tobool1.i = icmp eq i32 %.pr.i, 0, !dbg !41
58 ; This instruction has no debug location -- in this
59 ; particular case it was removed by a bug in SimplifyCFG.
60 %2 = load i32, i32* @f, align 4
62 ; GVN is supposed to replace the load of @f with a direct reference to %call.
63 ; CHECK: %tobool2.i = icmp eq i32 %call, 0, !dbg
64 %tobool2.i = icmp eq i32 %2, 0, !dbg !41
66 %or.cond = or i1 %tobool1.i, %tobool2.i, !dbg !41
67 br i1 %or.cond, label %sample.exit, label %if.then.3.i, !dbg !41
69 if.then.3.i: ; preds = %if.end.i
70 %call.i = tail call i32 bitcast (i32 (...)* @sample_internal to i32 ()*)() #3, !dbg !44
71 br label %sample.exit, !dbg !44
73 sample.exit: ; preds = %if.end.i, %if.then.3.i
74 ret i32 undef, !dbg !45
77 declare i32 @pid_for_task(i32) #1
79 ; Function Attrs: nounwind readnone
80 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2
82 attributes #0 = { nounwind }
83 attributes #2 = { nounwind readnone }
84 attributes #3 = { nounwind }
87 !llvm.module.flags = !{!22, !23}
90 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (trunk 244473) (llvm/trunk 244644)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3, globals: !16)
91 !1 = !DIFile(filename: "test.c", directory: "/")
94 !4 = !DISubprogram(name: "sample", scope: !5, file: !5, line: 6, type: !6, isLocal: false, isDefinition: true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: false, variables: !2)
95 !5 = !DIFile(filename: "test.i", directory: "/")
96 !6 = !DISubroutineType(types: !7)
98 !8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
99 !9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64, align: 64)
100 !10 = !DICompositeType(tag: DW_TAG_structure_type, name: "context", file: !5, line: 1, size: 32, align: 32, elements: !11)
102 !12 = !DIDerivedType(tag: DW_TAG_member, name: "cur_pid", scope: !10, file: !5, line: 2, baseType: !8, size: 32, align: 32)
103 !13 = !DISubprogram(name: "callback", scope: !5, file: !5, line: 13, type: !14, isLocal: false, isDefinition: true, scopeLine: 13, isOptimized: false, function: i32 ()* @callback, variables: !2)
104 !14 = !DISubroutineType(types: !15)
106 !16 = !{!17, !18, !19, !20, !21}
107 !17 = !DIGlobalVariable(name: "a", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @a)
108 !18 = !DIGlobalVariable(name: "b", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @b)
109 !19 = !DIGlobalVariable(name: "c", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @c)
110 !20 = !DIGlobalVariable(name: "f", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @f)
111 !21 = !DIGlobalVariable(name: "d", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @d)
112 !22 = !{i32 2, !"Dwarf Version", i32 2}
113 !23 = !{i32 2, !"Debug Info Version", i32 3}
114 !24 = !{!"clang version 3.8.0 (trunk 244473) (llvm/trunk 244644)"}
115 !25 = !DILocalVariable(name: "p1", arg: 1, scope: !4, file: !5, line: 6, type: !9)
116 !26 = !DIExpression()
117 !27 = !DILocation(line: 6, scope: !4)
118 !28 = !DILocation(line: 8, scope: !29)
119 !29 = distinct !DILexicalBlock(scope: !4, file: !5, line: 8)
120 !30 = !DILocation(line: 10, scope: !31)
121 !31 = distinct !DILexicalBlock(scope: !4, file: !5, line: 10)
122 !32 = !DILocation(line: 8, scope: !4)
123 !33 = !DILocation(line: 9, scope: !29)
124 !34 = !DILocation(line: 10, scope: !4)
125 !35 = !DILocation(line: 11, scope: !31)
126 !36 = !DILocation(line: 12, scope: !4)
127 !37 = !DILocation(line: 14, scope: !13)
128 !38 = !DILocation(line: 6, scope: !4, inlinedAt: !39)
129 !39 = distinct !DILocation(line: 15, scope: !13)
130 !40 = !DILocation(line: 8, scope: !29, inlinedAt: !39)
131 !41 = !DILocation(line: 10, scope: !31, inlinedAt: !39)
132 !42 = !DILocation(line: 8, scope: !4, inlinedAt: !39)
133 !43 = !DILocation(line: 9, scope: !29, inlinedAt: !39)
134 !44 = !DILocation(line: 11, scope: !31, inlinedAt: !39)
135 !45 = !DILocation(line: 16, scope: !13)