1; RUN: llc -O2 < %s | FileCheck %s
2; RUN: llc -O2 -regalloc=basic < %s | FileCheck %s
3target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
4target triple = "x86_64-apple-darwin10"
5
6%struct.a = type { i32, %struct.a* }
7
8@llvm.used = appending global [1 x i8*] [i8* bitcast (i8* (%struct.a*)* @bar to i8*)], section "llvm.metadata" ; <[1 x i8*]*> [#uses=0]
9
10define i8* @bar(%struct.a* %myvar) nounwind optsize noinline ssp {
11entry:
12  tail call void @llvm.dbg.value(metadata %struct.a* %myvar, i64 0, metadata !8, metadata !MDExpression()), !dbg !MDLocation(scope: !9)
13  %0 = getelementptr inbounds %struct.a, %struct.a* %myvar, i64 0, i32 0, !dbg !28 ; <i32*> [#uses=1]
14  %1 = load i32, i32* %0, align 8, !dbg !28            ; <i32> [#uses=1]
15  tail call void @foo(i32 %1) nounwind optsize noinline ssp, !dbg !28
16  %2 = bitcast %struct.a* %myvar to i8*, !dbg !30 ; <i8*> [#uses=1]
17  ret i8* %2, !dbg !30
18}
19
20declare void @foo(i32) nounwind optsize noinline ssp
21
22declare void @llvm.dbg.value(metadata, i64, metadata, metadata) nounwind readnone
23
24!llvm.dbg.cu = !{!2}
25!llvm.module.flags = !{!38}
26
27!0 = !MDGlobalVariable(name: "ret", line: 7, isLocal: false, isDefinition: true, scope: !1, file: !1, type: !3)
28!1 = !MDFile(filename: "foo.c", directory: "/tmp/")
29!2 = !MDCompileUnit(language: DW_LANG_C89, producer: "4.2.1 (Based on Apple Inc. build 5658) (LLVM build)", isOptimized: true, emissionKind: 1, file: !36, enums: !37, retainedTypes: !37, subprograms: !32, globals: !31, imports:  !37)
30!3 = !MDBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
31!4 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "x", line: 12, arg: 0, scope: !5, file: !1, type: !3)
32!5 = !MDSubprogram(name: "foo", linkageName: "foo", line: 13, isLocal: false, isDefinition: true, virtualIndex: 6, isOptimized: true, scopeLine: 13, file: !36, scope: !1, type: !6, function: void (i32)* @foo, variables: !33)
33!6 = !MDSubroutineType(types: !7)
34!7 = !{null, !3}
35!8 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "myvar", line: 17, arg: 0, scope: !9, file: !1, type: !13)
36!9 = !MDSubprogram(name: "bar", linkageName: "bar", line: 17, isLocal: false, isDefinition: true, virtualIndex: 6, isOptimized: true, scopeLine: 17, file: !36, scope: !1, type: !10, function: i8* (%struct.a*)* @bar, variables: !34)
37!10 = !MDSubroutineType(types: !11)
38!11 = !{!12, !13}
39!12 = !MDDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, file: !36, scope: !1, baseType: null)
40!13 = !MDDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, file: !36, scope: !1, baseType: !14)
41!14 = !MDCompositeType(tag: DW_TAG_structure_type, name: "a", line: 2, size: 128, align: 64, file: !36, scope: !1, elements: !15)
42!15 = !{!16, !17}
43!16 = !MDDerivedType(tag: DW_TAG_member, name: "c", line: 3, size: 32, align: 32, file: !36, scope: !14, baseType: !3)
44!17 = !MDDerivedType(tag: DW_TAG_member, name: "d", line: 4, size: 64, align: 64, offset: 64, file: !36, scope: !14, baseType: !13)
45!18 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "argc", line: 22, arg: 0, scope: !19, file: !1, type: !3)
46!19 = !MDSubprogram(name: "main", linkageName: "main", line: 22, isLocal: false, isDefinition: true, virtualIndex: 6, isOptimized: true, scopeLine: 22, file: !36, scope: !1, type: !20, variables: !35)
47!20 = !MDSubroutineType(types: !21)
48!21 = !{!3, !3, !22}
49!22 = !MDDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, file: !36, scope: !1, baseType: !23)
50!23 = !MDDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, file: !36, scope: !1, baseType: !24)
51!24 = !MDBasicType(tag: DW_TAG_base_type, name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
52!25 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "argv", line: 22, arg: 0, scope: !19, file: !1, type: !22)
53!26 = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "e", line: 23, scope: !27, file: !1, type: !14)
54!27 = distinct !MDLexicalBlock(line: 22, column: 0, file: !36, scope: !19)
55!28 = !MDLocation(line: 18, scope: !29)
56!29 = distinct !MDLexicalBlock(line: 17, column: 0, file: !36, scope: !9)
57!30 = !MDLocation(line: 19, scope: !29)
58!31 = !{!0}
59!32 = !{!5, !9, !19}
60!33 = !{!4}
61!34 = !{!8}
62!35 = !{!18, !25, !26}
63!36 = !MDFile(filename: "foo.c", directory: "/tmp/")
64!37 = !{}
65
66; The variable bar:myvar changes registers after the first movq.
67; It is cobbered by popq %rbx
68; CHECK: movq
69; CHECK-NEXT: [[LABEL:Ltmp[0-9]*]]
70; CHECK: .loc	1 19 0
71; CHECK: popq
72; CHECK-NEXT: [[CLOBBER:Ltmp[0-9]*]]
73
74
75; CHECK: Ldebug_loc0:
76; CHECK-NEXT: [[SET1:.*]] = Lfunc_begin0-Lfunc_begin0
77; CHECK-NEXT: .quad   [[SET1]]
78; CHECK-NEXT: [[SET2:.*]] = [[LABEL]]-Lfunc_begin0
79; CHECK-NEXT: .quad   [[SET2]]
80; CHECK-NEXT: Lset{{.*}} = Ltmp{{.*}}-Ltmp{{.*}}               ## Loc expr size
81; CHECK-NEXT: .short  Lset{{.*}}
82; CHECK-NEXT: Ltmp{{.*}}:
83; CHECK-NEXT: .byte   85
84; CHECK-NEXT: Ltmp{{.*}}:
85; CHECK-NEXT: [[SET3:.*]] = [[LABEL]]-Lfunc_begin0
86; CHECK-NEXT: .quad   [[SET3]]
87; CHECK-NEXT: [[SET4:.*]] = [[CLOBBER]]-Lfunc_begin0
88; CHECK-NEXT: .quad   [[SET4]]
89; CHECK-NEXT: Lset{{.*}} = Ltmp{{.*}}-Ltmp{{.*}}               ## Loc expr size
90; CHECK-NEXT: .short  Lset{{.*}}
91; CHECK-NEXT: Ltmp{{.*}}:
92; CHECK-NEXT: .byte   83
93; CHECK-NEXT: Ltmp{{.*}}:
94!38 = !{i32 1, !"Debug Info Version", i32 3}
95