1 ; RUN: llc < %s -mtriple=thumbv6-apple-darwin | FileCheck %s
2 ; RUN: llc < %s -mtriple=thumbv6-apple-darwin -regalloc=basic | FileCheck %s
3 ; RUN: llc < %s -o %t -filetype=obj -mtriple=thumbv6-apple-darwin
4 ; RUN: llvm-objdump --no-print-imm-hex --triple=thumbv6-apple-darwin -d %t | FileCheck %s
6 @__bar = external hidden global ptr
7 @__baz = external hidden global ptr
12 ; CHECK-LABEL: __foo{{>?}}:
14 %size = alloca i32, align 4
15 %0 = load ptr, ptr @__bar, align 4
16 %1 = icmp eq ptr %0, null
17 br i1 %1, label %bb1, label %bb3
21 store i32 1026, ptr %size, align 4
22 %2 = alloca [1026 x i8], align 1
23 ; CHECK: mov [[R0:r[0-9]+]], sp
24 ; CHECK: adds {{r[0-9]+}}, [[R0]], {{r[0-9]+}}
25 %3 = call i32 @_called_func(ptr %2, ptr %size) nounwind
26 %4 = icmp eq i32 %3, 0
27 br i1 %4, label %bb2, label %bb3
30 %5 = call ptr @strdup(ptr %2) nounwind
31 store ptr %5, ptr @__baz, align 4
35 %.0 = phi ptr [ %0, %entry ], [ %5, %bb2 ], [ %2, %bb1 ]
36 ; CHECK: subs r6, r7, #7
37 ; CHECK-NEXT: subs r6, #1
38 ; CHECK-NEXT: mov sp, r6
39 ; CHECK-NEXT: pop {r4, r6, r7, pc}
43 declare noalias ptr @strdup(ptr nocapture) nounwind
44 declare i32 @_called_func(ptr, ptr) nounwind
46 ; Simple variable ending up *at* sp.
47 define void @test_simple_var() {
48 ; CHECK-LABEL: test_simple_var{{>?}}:
55 call void @take_ptr(ptr %addr32)
59 ; Simple variable ending up at aligned offset from sp.
60 define void @test_local_var_addr_aligned() {
61 ; CHECK-LABEL: test_local_var_addr_aligned{{>?}}:
63 %addr1.32 = alloca i32
64 %addr2.32 = alloca i32
66 ; CHECK: add r0, sp, #{{[0-9]+}}
68 call void @take_ptr(ptr %addr1.32)
73 call void @take_ptr(ptr %addr2.32)
78 ; Simple variable ending up at aligned offset from sp.
79 define void @test_local_var_big_offset() {
80 ; CHECK-LABEL: test_local_var_big_offset{{>?}}:
81 %addr1.32 = alloca i32, i32 257
82 %addr2.32 = alloca i32, i32 257
84 ; CHECK: add [[RTMP:r[0-9]+]], sp, #1020
85 ; CHECK: adds [[RTMP]], #8
87 call void @take_ptr(ptr %addr1.32)
92 ; Max range addressable with tADDrSPi
93 define void @test_local_var_offset_1020() {
94 ; CHECK-LABEL: test_local_var_offset_1020
95 %addr1 = alloca i8, i32 4
96 %addr2 = alloca i8, i32 1020
98 ; CHECK: add r0, sp, #1020
100 call void @take_ptr(ptr %addr1)
105 ; Max range addressable with tADDrSPi + tADDi8 is 1275, however the automatic
106 ; 4-byte aligning of objects on the stack combined with 8-byte stack alignment
107 ; means that 1268 is the max offset we can use.
108 define void @test_local_var_offset_1268() {
109 ; CHECK-LABEL: test_local_var_offset_1268
110 %addr1 = alloca i8, i32 1
111 %addr2 = alloca i8, i32 1268
113 ; CHECK: add r0, sp, #1020
114 ; CHECK: adds r0, #248
116 call void @take_ptr(ptr %addr1)
121 declare void @take_ptr(ptr)