1; RUN: opt < %s -passes=instcombine -instcombine-lower-dbg-declare=0 -S \ 2; RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=NOLOWER 3; RUN: opt < %s -passes=instcombine -instcombine-lower-dbg-declare=1 -S | FileCheck %s 4 5; RUN: opt < %s -passes=instcombine -instcombine-lower-dbg-declare=0 -S --try-experimental-debuginfo-iterators \ 6; RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=NOLOWER 7; RUN: opt < %s -passes=instcombine -instcombine-lower-dbg-declare=1 -S --try-experimental-debuginfo-iterators | FileCheck %s 8 9target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 10target triple = "x86_64--linux" 11 12%struct.TwoRegs = type { i64, i64 } 13 14declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone 15 16declare i64 @llvm.objectsize.i64.p0(ptr, i1) nounwind readnone 17 18declare ptr @passthru_callee(ptr, i32, i64, i64) 19 20define ptr @passthru(ptr %a, i32 %b, i64 %c) !dbg !1 { 21entry: 22 %a.addr = alloca ptr, align 8 23 %b.addr = alloca i32, align 4 24 %c.addr = alloca i64, align 8 25 store ptr %a, ptr %a.addr, align 8 26 call void @llvm.dbg.declare(metadata ptr %a.addr, metadata !0, metadata !DIExpression()), !dbg !16 27 store i32 %b, ptr %b.addr, align 4 28 call void @llvm.dbg.declare(metadata ptr %b.addr, metadata !7, metadata !DIExpression()), !dbg !18 29 store i64 %c, ptr %c.addr, align 8 30 call void @llvm.dbg.declare(metadata ptr %c.addr, metadata !9, metadata !DIExpression()), !dbg !20 31 %tmp = load ptr, ptr %a.addr, align 8, !dbg !21 32 %tmp1 = load i32, ptr %b.addr, align 4, !dbg !21 33 %tmp2 = load i64, ptr %c.addr, align 8, !dbg !21 34 %tmp3 = load ptr, ptr %a.addr, align 8, !dbg !21 35 %0 = call i64 @llvm.objectsize.i64.p0(ptr %tmp3, i1 false), !dbg !21 36 %call = call ptr @passthru_callee(ptr %tmp, i32 %tmp1, i64 %tmp2, i64 %0), !dbg !21 37 ret ptr %call, !dbg !21 38} 39 40; CHECK-LABEL: define ptr @passthru(ptr %a, i32 %b, i64 %c) 41; CHECK-NOT: alloca 42; CHECK-NOT: store 43; CHECK-NOT: #dbg_declare 44; CHECK: #dbg_value(ptr %a, {{.*}}) 45; CHECK-NOT: store 46; CHECK: #dbg_value(i32 %b, {{.*}}) 47; CHECK-NOT: store 48; CHECK: #dbg_value(i64 %c, {{.*}}) 49; CHECK-NOT: store 50; CHECK: call ptr @passthru_callee(ptr %a, i32 %b, i64 %c, i64 %{{.*}}) 51 52declare void @tworegs_callee(i64, i64) 53 54; Lowering dbg.declare in instcombine doesn't handle this case very well. 55 56define void @tworegs(i64 %o.coerce0, i64 %o.coerce1) !dbg !31 { 57entry: 58 %o = alloca %struct.TwoRegs, align 8 59 %0 = getelementptr inbounds { i64, i64 }, ptr %o, i32 0, i32 0 60 store i64 %o.coerce0, ptr %0, align 8 61 %1 = getelementptr inbounds { i64, i64 }, ptr %o, i32 0, i32 1 62 store i64 %o.coerce1, ptr %1, align 8 63 call void @llvm.dbg.declare(metadata ptr %o, metadata !35, metadata !DIExpression()), !dbg !32 64 %2 = getelementptr inbounds { i64, i64 }, ptr %o, i32 0, i32 0, !dbg !33 65 %3 = load i64, ptr %2, align 8, !dbg !33 66 %4 = getelementptr inbounds { i64, i64 }, ptr %o, i32 0, i32 1, !dbg !33 67 %5 = load i64, ptr %4, align 8, !dbg !33 68 call void @tworegs_callee(i64 %3, i64 %5), !dbg !33 69 ret void, !dbg !33 70} 71 72; NOLOWER-LABEL: define void @tworegs(i64 %o.coerce0, i64 %o.coerce1) 73; NOLOWER-NOT: alloca 74; NOLOWER-NOT: store 75; NOLOWER-NOT: #dbg_declare 76; Here we want to find: call void @llvm.dbg.value(metadata i64 %o.coerce0, metadata [[VARIABLE_O]], metadata !DIExpression(DW_OP_LLVM_fragment, 0, 64)) 77; NOLOWER: #dbg_value(i64 poison, {{.*}}) 78; NOLOWER-NOT: store 79; Here we want to find: call void @llvm.dbg.value(metadata i64 %o.coerce1, metadata [[VARIABLE_O]], metadata !DIExpression(DW_OP_LLVM_fragment, 64, 64)) 80; NOLOWER: #dbg_value(i64 poison, {{.*}}) 81; NOLOWER-NOT: store 82; NOLOWER: call void @tworegs_callee(i64 %o.coerce0, i64 %o.coerce1) 83 84 85!llvm.dbg.cu = !{!3} 86!llvm.module.flags = !{!30} 87 88!0 = !DILocalVariable(name: "a", line: 78, arg: 1, scope: !1, file: !2, type: !6) 89!1 = distinct !DISubprogram(name: "passthru", line: 79, isLocal: true, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !3, scopeLine: 79, file: !27, scope: !2, type: !4, retainedNodes: !25) 90!2 = !DIFile(filename: "string.h", directory: "Game") 91!3 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.0 (trunk 127710)", isOptimized: true, emissionKind: FullDebug, file: !28, enums: !29, retainedTypes: !29) 92!4 = !DISubroutineType(types: !5) 93!5 = !{!6} 94!6 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, scope: !3, baseType: null) 95!7 = !DILocalVariable(name: "b", line: 78, arg: 2, scope: !1, file: !2, type: !8) 96!8 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 97!9 = !DILocalVariable(name: "c", line: 78, arg: 3, scope: !1, file: !2, type: !12) 98!12 = !DIBasicType(tag: DW_TAG_base_type, name: "long unsigned int", size: 64, align: 64, encoding: DW_ATE_unsigned) 99!16 = !DILocation(line: 78, column: 28, scope: !1) 100!18 = !DILocation(line: 78, column: 40, scope: !1) 101!20 = !DILocation(line: 78, column: 54, scope: !1) 102!21 = !DILocation(line: 80, column: 3, scope: !22) 103!22 = distinct !DILexicalBlock(line: 80, column: 3, file: !27, scope: !23) 104!23 = distinct !DILexicalBlock(line: 79, column: 1, file: !27, scope: !1) 105!25 = !{!0, !7, !9} 106!27 = !DIFile(filename: "string.h", directory: "Game") 107!28 = !DIFile(filename: "bits.c", directory: "Game") 108!29 = !{} 109!30 = !{i32 1, !"Debug Info Version", i32 3} 110 111!31 = distinct !DISubprogram(name: "tworegs", scope: !28, file: !28, line: 4, type: !4, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: true, unit: !3, retainedNodes: !34) 112!32 = !DILocation(line: 4, column: 23, scope: !31) 113!33 = !DILocation(line: 5, column: 3, scope: !31) 114!34 = !{!35} 115!35 = !DILocalVariable(name: "o", arg: 1, scope: !31, file: !28, line: 4, type: !36) 116!36 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "TwoRegs", file: !28, line: 1, size: 128, elements: !37) 117!37 = !{!38, !39} 118!38 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !36, file: !28, line: 1, baseType: !12, size: 64) 119!39 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !36, file: !28, line: 1, baseType: !12, size: 64) 120!40 = !DISubroutineType(types: !41) 121!41 = !{!36} 122