xref: /llvm-project/llvm/test/CodeGen/Thumb2/pic-load.ll (revision b5b663aac17415625340eb29c8010832bfc4c21c)
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 { ptr }
6%struct.one_atexit_routine = type { %struct.anon, i32, ptr }
7@__dso_handle = external global { }		; <ptr> [#uses=1]
8@llvm.used = appending global [1 x ptr] [ptr @atexit], section "llvm.metadata"		; <ptr> [#uses=0]
9
10define i32 @atexit(ptr %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		; <ptr> [#uses=3]
52  %0 = getelementptr %struct.one_atexit_routine, ptr %r, i32 0, i32 0, i32 0		; <ptr> [#uses=1]
53  store ptr %func, ptr %0, align 4
54  %1 = getelementptr %struct.one_atexit_routine, ptr %r, i32 0, i32 1		; <ptr> [#uses=1]
55  store i32 0, ptr %1, align 4
56  %2 = call  i32 @atexit_common(ptr %r, ptr @__dso_handle) nounwind		; <i32> [#uses=1]
57  ret i32 %2
58}
59
60declare i32 @atexit_common(ptr, ptr) nounwind
61