Further reduce the IR in this testcase based on a further reduction
[oota-llvm.git] / test / DebugInfo / gvn.ll
1 ; RUN: opt < %s -gvn -S | FileCheck %s
2 ;
3 ; Produced at -O2 from:
4 ; int a, b;
5 ; void f1(int *p1) {
6 ;   if (b)
7 ;     a = 1;
8 ;   if (a && *p1)
9 ;     f4();
10 ; }
11 ; int f2(int);
12 ; void f3(void) {
13 ;   a = f2(1);
14 ;   f1(&a);
15 ; }
16 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
17 target triple = "arm64-apple-ios"
18
19 @a = common global i32 0, align 4
20 @b = common global i32 0, align 4
21
22 ; Function Attrs: nounwind
23 declare i32 @sample_internal(...)
24
25 ; Function Attrs: nounwind
26 define void @f3() #0 {
27 entry:
28   ; Verify that the call still has a debug location after GVN.
29   ; CHECK: %call = tail call i32 @f2(i32 1) #{{[0-9]}}, !dbg
30   %call = tail call i32 @f2(i32 1) #3, !dbg !36
31   store i32 %call, i32* @a, align 4, !dbg !36, !tbaa !25
32   tail call void @llvm.dbg.value(metadata i32* @a, i64 0, metadata !11, metadata !21) #3, !dbg !39
33   %0 = load i32, i32* @b, align 4, !dbg !39, !tbaa !25
34   %tobool.i = icmp eq i32 %0, 0, !dbg !39
35   br i1 %tobool.i, label %if.end.i, label %land.lhs.true.i.thread, !dbg !40
36
37 land.lhs.true.i.thread:                           ; preds = %entry
38   store i32 1, i32* @a, align 4, !dbg !41, !tbaa !25
39   br label %if.then.3.i, !dbg !42
40
41 if.end.i:                                         ; preds = %entry
42   ; This instruction has no debug location -- in this
43   ; particular case it was removed by a bug in SimplifyCFG.
44   %.pr = load i32, i32* @a, align 4
45
46   ; GVN is supposed to replace the load of %.pr with a direct reference to %call.
47   ; CHECK: %tobool2.i = icmp eq i32 %call, 0, !dbg
48   %tobool2.i = icmp eq i32 %.pr, 0, !dbg !43
49   br i1 %tobool2.i, label %f1.exit, label %if.then.3.i, !dbg !43
50
51 if.then.3.i:                                      ; preds = %if.end.i, %land.lhs.true.i.thread
52   %call.i = tail call i32 bitcast (i32 (...)* @f4 to i32 ()*)() #3, !dbg !44
53   br label %f1.exit, !dbg !44
54
55 f1.exit:                                          ; preds = %if.end.i, %if.then.3.i
56   ret void, !dbg !45
57 }
58
59 declare i32 @f2(i32)
60 declare i32 @f4(...)
61
62 ; Function Attrs: nounwind readnone
63 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2
64
65 attributes #0 = { nounwind }
66 attributes #2 = { nounwind readnone }
67 attributes #3 = { nounwind }
68
69 !llvm.dbg.cu = !{!0}
70 !llvm.module.flags = !{!18, !19}
71 !llvm.ident = !{!20}
72
73 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (trunk 245562) (llvm/trunk 245569)", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3, globals: !15)
74 !1 = !DIFile(filename: "test.c", directory: "/")
75 !2 = !{}
76 !3 = !{!4, !12}
77 !4 = !DISubprogram(name: "f1", scope: !1, file: !1, line: 2, type: !6, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, variables: !10)
78 !6 = !DISubroutineType(types: !7)
79 !7 = !{null, !8}
80 !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64, align: 64)
81 !9 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
82 !10 = !{!11}
83 !11 = !DILocalVariable(name: "p1", arg: 1, scope: !4, file: !1, line: 2, type: !8)
84 !12 = !DISubprogram(name: "f3", scope: !1, file: !1, line: 9, type: !13, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: true, function: void ()* @f3, variables: !2)
85 !13 = !DISubroutineType(types: !14)
86 !14 = !{null}
87 !15 = !{!16, !17}
88 !16 = !DIGlobalVariable(name: "a", scope: !0, file: !1, line: 1, type: !9, isLocal: false, isDefinition: true, variable: i32* @a)
89 !17 = !DIGlobalVariable(name: "b", scope: !0, file: !1, line: 1, type: !9, isLocal: false, isDefinition: true, variable: i32* @b)
90 !18 = !{i32 2, !"Dwarf Version", i32 2}
91 !19 = !{i32 2, !"Debug Info Version", i32 3}
92 !20 = !{!"clang version 3.8.0 (trunk 245562) (llvm/trunk 245569)"}
93 !21 = !DIExpression()
94 !22 = !DILocation(line: 2, scope: !4)
95 !23 = !DILocation(line: 3, scope: !24)
96 !24 = distinct !DILexicalBlock(scope: !4, file: !1, line: 3)
97 !25 = !{!26, !26, i64 0}
98 !26 = !{!"int", !27, i64 0}
99 !27 = !{!"omnipotent char", !28, i64 0}
100 !28 = !{!"Simple C/C++ TBAA"}
101 !29 = !DILocation(line: 3, scope: !4)
102 !30 = !DILocation(line: 4, scope: !24)
103 !31 = !DILocation(line: 5, scope: !32)
104 !32 = distinct !DILexicalBlock(scope: !4, file: !1, line: 5)
105 !33 = !DILocation(line: 5, scope: !4)
106 !34 = !DILocation(line: 6, scope: !32)
107 !35 = !DILocation(line: 7, scope: !4)
108 !36 = !DILocation(line: 5, scope: !32, inlinedAt: !37)
109 !37 = distinct !DILocation(line: 11, scope: !12)
110 !38 = !DILocation(line: 10, scope: !12)
111 !39 = !DILocation(line: 2, scope: !4, inlinedAt: !37)
112 !40 = !DILocation(line: 3, scope: !24, inlinedAt: !37)
113 !41 = !DILocation(line: 3, scope: !4, inlinedAt: !37)
114 !42 = !DILocation(line: 4, scope: !24, inlinedAt: !37)
115 !43 = !DILocation(line: 5, scope: !4, inlinedAt: !37)
116 !44 = !DILocation(line: 6, scope: !32, inlinedAt: !37)
117 !45 = !DILocation(line: 12, scope: !12)