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