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