1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc < %s -mtriple=thumbv7-apple-darwin9 -relocation-model=pic -o - | FileCheck %s --check-prefix=CHECK-PIC
3; RUN: llc < %s -mtriple=thumbv7-apple-ios -relocation-model=pic -mcpu=swift -mattr=+no-movt | FileCheck %s --check-prefix=CHECK-NOMOVT
4
5%struct.anon = type { void ()* }
6%struct.one_atexit_routine = type { %struct.anon, i32, i8* }
7@__dso_handle = external global { }		; <{ }*> [#uses=1]
8@llvm.used = appending global [1 x i8*] [i8* bitcast (i32 (void ()*)* @atexit to i8*)], section "llvm.metadata"		; <[1 x i8*]*> [#uses=0]
9
10define i32 @atexit(void ()* %func) {
11; CHECK-PIC-LABEL: atexit:
12; CHECK-PIC:       @ %bb.0: @ %entry
13; CHECK-PIC-NEXT:    str lr, [sp, #-4]!
14; CHECK-PIC-NEXT:    sub sp, #12
15; CHECK-PIC-NEXT:    movw r1, :lower16:(L___dso_handle$non_lazy_ptr-(LPC0_0+4))
16; CHECK-PIC-NEXT:    movs r2, #0
17; CHECK-PIC-NEXT:    movt r1, :upper16:(L___dso_handle$non_lazy_ptr-(LPC0_0+4))
18; CHECK-PIC-NEXT:    strd r0, r2, [sp]
19; CHECK-PIC-NEXT:  LPC0_0:
20; CHECK-PIC-NEXT:    add r1, pc
21; CHECK-PIC-NEXT:    mov r0, sp
22; CHECK-PIC-NEXT:    ldr r1, [r1]
23; CHECK-PIC-NEXT:    bl _atexit_common
24; CHECK-PIC-NEXT:    add sp, #12
25; CHECK-PIC-NEXT:    ldr lr, [sp], #4
26; CHECK-PIC-NEXT:    bx lr
27;
28; CHECK-NOMOVT-LABEL: atexit:
29; CHECK-NOMOVT:       @ %bb.0: @ %entry
30; CHECK-NOMOVT-NEXT:    str lr, [sp, #-4]!
31; CHECK-NOMOVT-NEXT:    sub sp, #12
32; CHECK-NOMOVT-NEXT:    str r0, [sp]
33; CHECK-NOMOVT-NEXT:    movs r0, #0
34; CHECK-NOMOVT-NEXT:    str r0, [sp, #4]
35; CHECK-NOMOVT-NEXT:    ldr r0, LCPI0_0
36; CHECK-NOMOVT-NEXT:  LPC0_0:
37; CHECK-NOMOVT-NEXT:    add r0, pc
38; CHECK-NOMOVT-NEXT:    ldr r1, [r0]
39; CHECK-NOMOVT-NEXT:    mov r0, sp
40; CHECK-NOMOVT-NEXT:    bl _atexit_common
41; CHECK-NOMOVT-NEXT:    add sp, #12
42; CHECK-NOMOVT-NEXT:    ldr lr, [sp], #4
43; CHECK-NOMOVT-NEXT:    bx lr
44; CHECK-NOMOVT-NEXT:    .p2align 2
45; CHECK-NOMOVT-NEXT:  @ %bb.1:
46; CHECK-NOMOVT-NEXT:    .data_region
47; CHECK-NOMOVT-NEXT:  LCPI0_0:
48; CHECK-NOMOVT-NEXT:    .long L___dso_handle$non_lazy_ptr-(LPC0_0+4)
49; CHECK-NOMOVT-NEXT:    .end_data_region
50entry:
51  %r = alloca %struct.one_atexit_routine, align 4		; <%struct.one_atexit_routine*> [#uses=3]
52  %0 = getelementptr %struct.one_atexit_routine, %struct.one_atexit_routine* %r, i32 0, i32 0, i32 0		; <void ()**> [#uses=1]
53  store void ()* %func, void ()** %0, align 4
54  %1 = getelementptr %struct.one_atexit_routine, %struct.one_atexit_routine* %r, i32 0, i32 1		; <i32*> [#uses=1]
55  store i32 0, i32* %1, align 4
56  %2 = call  i32 @atexit_common(%struct.one_atexit_routine* %r, i8* bitcast ({ }* @__dso_handle to i8*)) nounwind		; <i32> [#uses=1]
57  ret i32 %2
58}
59
60declare i32 @atexit_common(%struct.one_atexit_routine*, i8*) nounwind
61