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; } 16target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128" 17target 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 23define void @f3() #0 !dbg !12 { 24entry: 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 34land.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 38if.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 48if.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 52f1.exit: ; preds = %if.end.i, %if.then.3.i 53 ret void, !dbg !45 54} 55 56declare i32 @f2(i32) 57declare i32 @f4(...) 58 59; Function Attrs: nounwind readnone 60declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2 61 62attributes #0 = { nounwind } 63attributes #2 = { nounwind readnone } 64attributes #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: FullDebug, enums: !2, globals: !15) 71!1 = !DIFile(filename: "test.c", directory: "/") 72!2 = !{} 73!4 = distinct !DISubprogram(name: "f1", scope: !1, file: !1, line: 2, type: !6, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !10) 74!6 = !DISubroutineType(types: !7) 75!7 = !{null, !8} 76!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64, align: 64) 77!9 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 78!10 = !{!11} 79!11 = !DILocalVariable(name: "p1", arg: 1, scope: !4, file: !1, line: 2, type: !8) 80!12 = distinct !DISubprogram(name: "f3", scope: !1, file: !1, line: 9, type: !13, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2) 81!13 = !DISubroutineType(types: !14) 82!14 = !{null} 83!15 = !{!16, !17} 84!16 = !DIGlobalVariable(name: "a", scope: !0, file: !1, line: 1, type: !9, isLocal: false, isDefinition: true, variable: i32* @a) 85!17 = !DIGlobalVariable(name: "b", scope: !0, file: !1, line: 1, type: !9, isLocal: false, isDefinition: true, variable: i32* @b) 86!18 = !{i32 2, !"Dwarf Version", i32 2} 87!19 = !{i32 2, !"Debug Info Version", i32 3} 88!20 = !{!"clang version 3.8.0 (trunk 245562) (llvm/trunk 245569)"} 89!21 = !DIExpression() 90!22 = !DILocation(line: 2, scope: !4) 91!23 = !DILocation(line: 3, scope: !24) 92!24 = distinct !DILexicalBlock(scope: !4, file: !1, line: 3) 93!25 = !{!26, !26, i64 0} 94!26 = !{!"int", !27, i64 0} 95!27 = !{!"omnipotent char", !28, i64 0} 96!28 = !{!"Simple C/C++ TBAA"} 97!29 = !DILocation(line: 3, scope: !4) 98!30 = !DILocation(line: 4, scope: !24) 99!31 = !DILocation(line: 5, scope: !32) 100!32 = distinct !DILexicalBlock(scope: !4, file: !1, line: 5) 101!33 = !DILocation(line: 5, scope: !4) 102!34 = !DILocation(line: 6, scope: !32) 103!35 = !DILocation(line: 7, scope: !4) 104!36 = !DILocation(line: 5, scope: !32, inlinedAt: !37) 105!37 = distinct !DILocation(line: 11, scope: !12) 106!38 = !DILocation(line: 10, scope: !12) 107!39 = !DILocation(line: 2, scope: !4, inlinedAt: !37) 108!40 = !DILocation(line: 3, scope: !24, inlinedAt: !37) 109!41 = !DILocation(line: 3, scope: !4, inlinedAt: !37) 110!42 = !DILocation(line: 4, scope: !24, inlinedAt: !37) 111!43 = !DILocation(line: 5, scope: !4, inlinedAt: !37) 112!44 = !DILocation(line: 6, scope: !32, inlinedAt: !37) 113!45 = !DILocation(line: 12, scope: !12) 114