1; RUN: llc < %s -disable-fp-elim -mtriple x86_64-apple-darwin11 -mcpu corei7 | FileCheck -check-prefix=ASM %s
2; RUN: llc < %s -disable-fp-elim -mtriple x86_64-apple-darwin11 -mcpu corei7 -filetype=obj -o - \
3; RUN:  | llvm-objdump -triple x86_64-apple-darwin11 -unwind-info - \
4; RUN:  | FileCheck -check-prefix=CU %s
5; RUN: llc < %s -disable-fp-elim -mtriple x86_64-apple-darwin11 -mcpu corei7 \
6; RUN:  | llvm-mc -triple x86_64-apple-darwin11 -filetype=obj -o - \
7; RUN:  | llvm-objdump -triple x86_64-apple-darwin11 -unwind-info - \
8; RUN:  | FileCheck -check-prefix=FROM-ASM %s
9
10; RUN: llc < %s -mtriple x86_64-apple-macosx10.8.0 -mcpu corei7 -filetype=obj -o - \
11; RUN:  | llvm-objdump -triple x86_64-apple-macosx10.8.0 -unwind-info - \
12; RUN:  | FileCheck -check-prefix=NOFP-CU %s
13; RUN: llc < %s -mtriple x86_64-apple-darwin11 -mcpu corei7 \
14; RUN:  | llvm-mc -triple x86_64-apple-darwin11 -filetype=obj -o - \
15; RUN:  | llvm-objdump -triple x86_64-apple-darwin11 -unwind-info - \
16; RUN:  | FileCheck -check-prefix=NOFP-FROM-ASM %s
17
18%ty = type { i8* }
19
20@gv = external global i32
21
22; This is aligning the stack with a push of a random register.
23; ASM: pushq %rax
24
25; Even though we can't encode %rax into the compact unwind, We still want to be
26; able to generate a compact unwind encoding in this particular case.
27
28; CU:    Contents of __compact_unwind section:
29; CU-NEXT:      Entry at offset 0x0:
30; CU-NEXT:        start:                0x0 _test0
31; CU-NEXT:        length:               0x1e
32; CU-NEXT:        compact encoding:     0x01010001
33
34; FROM-ASM:    Contents of __compact_unwind section:
35; FROM-ASM-NEXT:      Entry at offset 0x0:
36; FROM-ASM-NEXT:        start:                0x0 _test0
37; FROM-ASM-NEXT:        length:               0x1e
38; FROM-ASM-NEXT:        compact encoding:     0x01010001
39
40define i8* @test0(i64 %size) {
41  %addr = alloca i64, align 8
42  %tmp20 = load i32* @gv, align 4
43  %tmp21 = call i32 @bar()
44  %tmp25 = load i64* %addr, align 8
45  %tmp26 = inttoptr i64 %tmp25 to %ty*
46  %tmp29 = getelementptr inbounds %ty* %tmp26, i64 0, i32 0
47  %tmp34 = load i8** %tmp29, align 8
48  %tmp35 = getelementptr inbounds i8* %tmp34, i64 %size
49  store i8* %tmp35, i8** %tmp29, align 8
50  ret i8* null
51}
52
53declare i32 @bar()
54
55%"struct.dyld::MappedRanges" = type { [400 x %struct.anon], %"struct.dyld::MappedRanges"* }
56%struct.anon = type { %class.ImageLoader*, i64, i64 }
57%class.ImageLoader = type { i32 (...)**, i8*, i8*, i32, i64, i64, i32, i32, %"struct.ImageLoader::recursive_lock"*, i16, i16, [4 x i8] }
58%"struct.ImageLoader::recursive_lock" = type { i32, i32 }
59
60@G1 = external hidden global %"struct.dyld::MappedRanges", align 8
61
62declare void @OSMemoryBarrier() optsize
63
64; Test the code below uses UNWIND_X86_64_MODE_STACK_IMMD compact unwind
65; encoding.
66
67; NOFP-CU:      Entry at offset 0x20:
68; NOFP-CU-NEXT:        start:                0x1d _test1
69; NOFP-CU-NEXT:        length:               0x42
70; NOFP-CU-NEXT:        compact encoding:     0x02040c0a
71
72; NOFP-FROM-ASM:      Entry at offset 0x20:
73; NOFP-FROM-ASM-NEXT:        start:                0x1d _test1
74; NOFP-FROM-ASM-NEXT:        length:               0x42
75; NOFP-FROM-ASM-NEXT:        compact encoding:     0x02040c0a
76
77define void @test1(%class.ImageLoader* %image) optsize ssp uwtable {
78entry:
79  br label %for.cond1.preheader
80
81for.cond1.preheader:                              ; preds = %for.inc10, %entry
82  %p.019 = phi %"struct.dyld::MappedRanges"* [ @G1, %entry ], [ %1, %for.inc10 ]
83  br label %for.body3
84
85for.body3:                                        ; preds = %for.inc, %for.cond1.preheader
86  %indvars.iv = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next, %for.inc ]
87  %image4 = getelementptr inbounds %"struct.dyld::MappedRanges"* %p.019, i64 0, i32 0, i64 %indvars.iv, i32 0
88  %0 = load %class.ImageLoader** %image4, align 8
89  %cmp5 = icmp eq %class.ImageLoader* %0, %image
90  br i1 %cmp5, label %if.then, label %for.inc
91
92if.then:                                          ; preds = %for.body3
93  tail call void @OSMemoryBarrier() optsize
94  store %class.ImageLoader* null, %class.ImageLoader** %image4, align 8
95  br label %for.inc
96
97for.inc:                                          ; preds = %if.then, %for.body3
98  %indvars.iv.next = add i64 %indvars.iv, 1
99  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
100  %exitcond = icmp eq i32 %lftr.wideiv, 400
101  br i1 %exitcond, label %for.inc10, label %for.body3
102
103for.inc10:                                        ; preds = %for.inc
104  %next = getelementptr inbounds %"struct.dyld::MappedRanges"* %p.019, i64 0, i32 1
105  %1 = load %"struct.dyld::MappedRanges"** %next, align 8
106  %cmp = icmp eq %"struct.dyld::MappedRanges"* %1, null
107  br i1 %cmp, label %for.end11, label %for.cond1.preheader
108
109for.end11:                                        ; preds = %for.inc10
110  ret void
111}
112