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 -triple=thumbv6-apple-darwin -d %t | FileCheck %s
6 @__bar = external hidden global i8*
7 @__baz = external hidden global i8*
14 %size = alloca i32, align 4
15 %0 = load i8*, i8** @__bar, align 4
16 %1 = icmp eq i8* %0, null
17 br i1 %1, label %bb1, label %bb3
21 store i32 1026, i32* %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 = getelementptr inbounds [1026 x i8], [1026 x i8]* %2, i32 0, i32 0
26 %4 = call i32 @_called_func(i8* %3, i32* %size) nounwind
27 %5 = icmp eq i32 %4, 0
28 br i1 %5, label %bb2, label %bb3
31 %6 = call i8* @strdup(i8* %3) nounwind
32 store i8* %6, i8** @__baz, align 4
36 %.0 = phi i8* [ %0, %entry ], [ %6, %bb2 ], [ %3, %bb1 ]
38 ; CHECK-NEXT: mov sp, r4
39 ; CHECK-NEXT: pop {r4, r5, r6, r7, pc}
43 declare noalias i8* @strdup(i8* nocapture) nounwind
44 declare i32 @_called_func(i8*, i32*) nounwind
46 ; Simple variable ending up *at* sp.
47 define void @test_simple_var() {
48 ; CHECK-LABEL: test_simple_var:
51 %addr8 = bitcast i32* %addr32 to i8*
56 call void @take_ptr(i8* %addr8)
60 ; Simple variable ending up at aligned offset from sp.
61 define void @test_local_var_addr_aligned() {
62 ; CHECK-LABEL: test_local_var_addr_aligned:
64 %addr1.32 = alloca i32
65 %addr1 = bitcast i32* %addr1.32 to i8*
66 %addr2.32 = alloca i32
67 %addr2 = bitcast i32* %addr2.32 to i8*
69 ; CHECK: add r0, sp, #{{[0-9]+}}
71 call void @take_ptr(i8* %addr1)
76 call void @take_ptr(i8* %addr2)
81 ; Simple variable ending up at aligned offset from sp.
82 define void @test_local_var_big_offset() {
83 ; CHECK-LABEL: test_local_var_big_offset:
84 %addr1.32 = alloca i32, i32 257
85 %addr1 = bitcast i32* %addr1.32 to i8*
86 %addr2.32 = alloca i32, i32 257
88 ; CHECK: add [[RTMP:r[0-9]+]], sp, #1020
89 ; CHECK: adds [[RTMP]], #8
91 call void @take_ptr(i8* %addr1)
96 ; Max range addressable with tADDrSPi
97 define void @test_local_var_offset_1020() {
98 ; CHECK-LABEL: test_local_var_offset_1020
99 %addr1 = alloca i8, i32 4
100 %addr2 = alloca i8, i32 1020
102 ; CHECK: add r0, sp, #1020
104 call void @take_ptr(i8* %addr1)
109 ; Max range addressable with tADDrSPi + tADDi8 is 1275, however the automatic
110 ; 4-byte aligning of objects on the stack combined with 8-byte stack alignment
111 ; means that 1268 is the max offset we can use.
112 define void @test_local_var_offset_1268() {
113 ; CHECK-LABEL: test_local_var_offset_1268
114 %addr1 = alloca i8, i32 1
115 %addr2 = alloca i8, i32 1268
117 ; CHECK: add r0, sp, #1020
118 ; CHECK: adds r0, #248
120 call void @take_ptr(i8* %addr1)
125 declare void @take_ptr(i8*)