llvm.org GIT mirror llvm / 3f4c496
Merging r245588: ------------------------------------------------------------------------ r245588 | aprantl | 2015-08-20 14:23:56 -0400 (Thu, 20 Aug 2015) | 11 lines Fix a debug location handling bug in GVN. Caught by the famous "DebugLoc describes the currect SubProgram" assertion. When GVN is removing a nonlocal load it updates the debug location of the SSA value it replaced the load with with the one of the load. In the testcase this actually overwrites a valid debug location with an empty one. In reality GVN has to make an arbitrary choice between two equally valid debug locations. This patch changes to behavior to only update the location if the value doesn't already have a debug location. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_37@253571 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 3 years ago
2 changed file(s) with 137 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
17601760 if (isa(V))
17611761 V->takeName(LI);
17621762 if (Instruction *I = dyn_cast(V))
1763 I->setDebugLoc(LI->getDebugLoc());
1763 if (LI->getDebugLoc())
1764 I->setDebugLoc(LI->getDebugLoc());
17641765 if (V->getType()->getScalarType()->isPointerTy())
17651766 MD->invalidateCachedPointerInfo(V);
17661767 markInstructionForDeletion(LI);
0 ; RUN: opt < %s -O2 -gvn -S | FileCheck %s
1 ;
2 ; Produced at -O2 from:
3 ; struct context {
4 ; int cur_pid
5 ; };
6 ; int a, b, c, f, d;
7 ; int pid_for_task(int);
8 ; sample(struct context *p1)
9 ; {
10 ; if (c)
11 ; b = a;
12 ; if (a && p1->cur_pid)
13 ; sample_internal();
14 ; }
15 ; callback() {
16 ; f = pid_for_task(d);
17 ; sample(&f);
18 ; }
19
20 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
21 target triple = "arm64-apple-ios"
22
23 %struct.context = type { i32 }
24
25 @c = common global i32 0, align 4
26 @a = common global i32 0, align 4
27 @b = common global i32 0, align 4
28 @d = common global i32 0, align 4
29 @f = common global i32 0, align 4
30
31 ; Function Attrs: nounwind
32 declare i32 @sample_internal(...)
33
34 ; Function Attrs: nounwind
35 define i32 @callback() #0 {
36 entry:
37 %0 = load i32, i32* @d, align 4, !dbg !37
38
39 ; Verify that the call still has a debug location after GVN.
40 ; CHECK: %call = tail call i32 @pid_for_task(i32 %0) #{{[0-9]}}, !dbg
41 %call = tail call i32 @pid_for_task(i32 %0) #3, !dbg !37
42
43 store i32 %call, i32* @f, align 4, !dbg !37
44 tail call void @llvm.dbg.value(metadata %struct.context* bitcast (i32* @f to %struct.context*), i64 0, metadata !25, metadata !26) #3, !dbg !38
45 %1 = load i32, i32* @c, align 4, !dbg !40
46 %tobool.i = icmp eq i32 %1, 0, !dbg !40
47 %.pr.i = load i32, i32* @a, align 4, !dbg !41
48 br i1 %tobool.i, label %if.end.i, label %if.then.i, !dbg !42
49
50 if.then.i: ; preds = %entry
51 store i32 %.pr.i, i32* @b, align 4, !dbg !43
52 br label %if.end.i, !dbg !43
53
54 if.end.i: ; preds = %if.then.i, %entry
55 %tobool1.i = icmp eq i32 %.pr.i, 0, !dbg !41
56
57 ; This instruction has no debug location -- in this
58 ; particular case it was removed by a bug in SimplifyCFG.
59 %2 = load i32, i32* @f, align 4
60
61 ; GVN is supposed to replace the load of @f with a direct reference to %call.
62 ; CHECK: %tobool2.i = icmp eq i32 %call, 0, !dbg
63 %tobool2.i = icmp eq i32 %2, 0, !dbg !41
64
65 %or.cond = or i1 %tobool1.i, %tobool2.i, !dbg !41
66 br i1 %or.cond, label %sample.exit, label %if.then.3.i, !dbg !41
67
68 if.then.3.i: ; preds = %if.end.i
69 %call.i = tail call i32 bitcast (i32 (...)* @sample_internal to i32 ()*)() #3, !dbg !44
70 br label %sample.exit, !dbg !44
71
72 sample.exit: ; preds = %if.end.i, %if.then.3.i
73 ret i32 undef, !dbg !45
74 }
75
76 declare i32 @pid_for_task(i32) #1
77
78 ; Function Attrs: nounwind readnone
79 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2
80
81 attributes #0 = { nounwind }
82 attributes #2 = { nounwind readnone }
83 attributes #3 = { nounwind }
84
85 !llvm.dbg.cu = !{!0}
86 !llvm.module.flags = !{!22, !23}
87 !llvm.ident = !{!24}
88
89 !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)
90 !1 = !DIFile(filename: "test.c", directory: "/")
91 !2 = !{}
92 !3 = !{!4, !13}
93 !4 = !DISubprogram(name: "sample", scope: !5, file: !5, line: 6, type: !6, isLocal: false, isDefinition: true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: false, variables: !2)
94 !5 = !DIFile(filename: "test.i", directory: "/")
95 !6 = !DISubroutineType(types: !7)
96 !7 = !{!8, !9}
97 !8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
98 !9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64, align: 64)
99 !10 = !DICompositeType(tag: DW_TAG_structure_type, name: "context", file: !5, line: 1, size: 32, align: 32, elements: !11)
100 !11 = !{!12}
101 !12 = !DIDerivedType(tag: DW_TAG_member, name: "cur_pid", scope: !10, file: !5, line: 2, baseType: !8, size: 32, align: 32)
102 !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)
103 !14 = !DISubroutineType(types: !15)
104 !15 = !{!8}
105 !16 = !{!17, !18, !19, !20, !21}
106 !17 = !DIGlobalVariable(name: "a", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @a)
107 !18 = !DIGlobalVariable(name: "b", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @b)
108 !19 = !DIGlobalVariable(name: "c", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @c)
109 !20 = !DIGlobalVariable(name: "f", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @f)
110 !21 = !DIGlobalVariable(name: "d", scope: !0, file: !5, line: 4, type: !8, isLocal: false, isDefinition: true, variable: i32* @d)
111 !22 = !{i32 2, !"Dwarf Version", i32 2}
112 !23 = !{i32 2, !"Debug Info Version", i32 3}
113 !24 = !{!"clang version 3.8.0 (trunk 244473) (llvm/trunk 244644)"}
114 !25 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "p1", arg: 1, scope: !4, file: !5, line: 6, type: !9)
115 !26 = !DIExpression()
116 !27 = !DILocation(line: 6, scope: !4)
117 !28 = !DILocation(line: 8, scope: !29)
118 !29 = distinct !DILexicalBlock(scope: !4, file: !5, line: 8)
119 !30 = !DILocation(line: 10, scope: !31)
120 !31 = distinct !DILexicalBlock(scope: !4, file: !5, line: 10)
121 !32 = !DILocation(line: 8, scope: !4)
122 !33 = !DILocation(line: 9, scope: !29)
123 !34 = !DILocation(line: 10, scope: !4)
124 !35 = !DILocation(line: 11, scope: !31)
125 !36 = !DILocation(line: 12, scope: !4)
126 !37 = !DILocation(line: 14, scope: !13)
127 !38 = !DILocation(line: 6, scope: !4, inlinedAt: !39)
128 !39 = distinct !DILocation(line: 15, scope: !13)
129 !40 = !DILocation(line: 8, scope: !29, inlinedAt: !39)
130 !41 = !DILocation(line: 10, scope: !31, inlinedAt: !39)
131 !42 = !DILocation(line: 8, scope: !4, inlinedAt: !39)
132 !43 = !DILocation(line: 9, scope: !29, inlinedAt: !39)
133 !44 = !DILocation(line: 11, scope: !31, inlinedAt: !39)
134 !45 = !DILocation(line: 16, scope: !13)