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