1; RUN: opt -S < %s -passes='function(mem2reg),require<verify>' | FileCheck %s 2; RUN: opt -S < %s -passes='function(mem2reg),require<verify>' --try-experimental-debuginfo-iterators | FileCheck %s 3 4target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 5target triple = "x86_64-apple-macosx10.13.0" 6 7; Original source (with some whitespace removed): 8; 9; extern int *getp(); 10; extern int cond(); 11; int get1() { return *getp(); } 12; int get2(int *p) { return *p; } 13; int bug(int *p) { 14; if (cond()) return get1(); 15; else return get2(p); 16; } 17 18define i32 @get1() !dbg !8 { 19 %1 = call ptr (...) @getp(), !dbg !12 20 %2 = load i32, ptr %1, align 4, !dbg !13 21 ret i32 %2, !dbg !14 22} 23 24declare ptr @getp(...) 25 26define i32 @get2(ptr) !dbg !15 { 27 %2 = alloca ptr, align 8 28 store ptr %0, ptr %2, align 8 29 call void @llvm.dbg.declare(metadata ptr %2, metadata !19, metadata !DIExpression()), !dbg !20 30 %3 = load ptr, ptr %2, align 8, !dbg !21 31 %4 = load i32, ptr %3, align 4, !dbg !22 32 ret i32 %4, !dbg !23 33} 34 35declare void @llvm.dbg.declare(metadata, metadata, metadata) 36 37; CHECK-LABEL: define i32 @bug 38define i32 @bug(ptr) !dbg !24 { 39 %2 = alloca i32, align 4 40 %3 = alloca ptr, align 8 41 store ptr %0, ptr %3, align 8 42 call void @llvm.dbg.declare(metadata ptr %3, metadata !25, metadata !DIExpression()), !dbg !26 43 %4 = call i32 (...) @cond(), !dbg !27 44 %5 = icmp ne i32 %4, 0, !dbg !27 45 br i1 %5, label %6, label %8, !dbg !29 46 47; <label>:6: ; preds = %1 48 %7 = call i32 @get1(), !dbg !30 49 store i32 %7, ptr %2, align 4, !dbg !31 50 br label %11, !dbg !31 51 52; <label>:8: ; preds = %1 53 %9 = load ptr, ptr %3, align 8, !dbg !32 54 %10 = call i32 @get2(ptr %9), !dbg !33 55 store i32 %10, ptr %2, align 4, !dbg !34 56 br label %11, !dbg !34 57 58; <label>:11: ; preds = %8, %6 59 %12 = load i32, ptr %2, align 4, !dbg !35 60 ret i32 %12, !dbg !35 61 62 ; CHECK: [[phi:%.*]] = phi i32 [ {{.*}} ], [ {{.*}} ], !dbg [[mergedLoc:![0-9]+]] 63 ; CHECK-NEXT: ret i32 [[phi]], !dbg [[retLoc:![0-9]+]] 64} 65 66; CHECK: [[commonScope:![0-9]+]] = distinct !DILexicalBlock(scope: {{.*}}, file: !1, line: 15, column: 7) 67; CHECK: [[mergedLoc]] = !DILocation(line: 0, scope: [[commonScope]]) 68; CHECK: [[retLoc]] = !DILocation(line: 23, column: 1 69 70declare i32 @cond(...) 71 72!llvm.dbg.cu = !{!0} 73!llvm.module.flags = !{!3, !4, !5, !6} 74!llvm.ident = !{!7} 75 76!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Apple LLVM version 9.1.0 (clang-902.2.37.2)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) 77!1 = !DIFile(filename: "bug.c", directory: "/bug") 78!2 = !{} 79!3 = !{i32 2, !"Dwarf Version", i32 4} 80!4 = !{i32 2, !"Debug Info Version", i32 3} 81!5 = !{i32 1, !"wchar_size", i32 4} 82!6 = !{i32 7, !"PIC Level", i32 2} 83!7 = !{!"Apple LLVM version 9.1.0 (clang-902.2.37.2)"} 84!8 = distinct !DISubprogram(name: "get1", scope: !1, file: !1, line: 6, type: !9, isLocal: false, isDefinition: true, scopeLine: 6, isOptimized: false, unit: !0, retainedNodes: !2) 85!9 = !DISubroutineType(types: !10) 86!10 = !{!11} 87!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 88!12 = !DILocation(line: 7, column: 11, scope: !8) 89!13 = !DILocation(line: 7, column: 10, scope: !8) 90!14 = !DILocation(line: 7, column: 3, scope: !8) 91!15 = distinct !DISubprogram(name: "get2", scope: !1, file: !1, line: 10, type: !16, isLocal: false, isDefinition: true, scopeLine: 10, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2) 92!16 = !DISubroutineType(types: !17) 93!17 = !{!11, !18} 94!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64) 95!19 = !DILocalVariable(name: "p", arg: 1, scope: !15, file: !1, line: 10, type: !18) 96!20 = !DILocation(line: 10, column: 15, scope: !15) 97!21 = !DILocation(line: 11, column: 11, scope: !15) 98!22 = !DILocation(line: 11, column: 10, scope: !15) 99!23 = !DILocation(line: 11, column: 3, scope: !15) 100!24 = distinct !DISubprogram(name: "bug", scope: !1, file: !1, line: 14, type: !16, isLocal: false, isDefinition: true, scopeLine: 14, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2) 101!25 = !DILocalVariable(name: "p", arg: 1, scope: !24, file: !1, line: 14, type: !18) 102!26 = !DILocation(line: 14, column: 14, scope: !24) 103!27 = !DILocation(line: 15, column: 7, scope: !28) 104!28 = distinct !DILexicalBlock(scope: !24, file: !1, line: 15, column: 7) 105!29 = !DILocation(line: 15, column: 7, scope: !24) 106!30 = !DILocation(line: 16, column: 12, scope: !28) 107!31 = !DILocation(line: 16, column: 5, scope: !28) 108!32 = !DILocation(line: 18, column: 17, scope: !28) 109!33 = !DILocation(line: 18, column: 12, scope: !28) 110!34 = !DILocation(line: 18, column: 5, scope: !28) 111!35 = !DILocation(line: 23, column: 1, scope: !24) 112