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 ]
37 ; CHECK: subs r4, r7, #7
38 ; CHECK-NEXT: subs r4, #1
39 ; CHECK-NEXT: mov sp, r4
40 ; CHECK-NEXT: pop {r4, r6, r7, pc}
44 declare noalias i8* @strdup(i8* nocapture) nounwind
45 declare i32 @_called_func(i8*, i32*) nounwind
47 ; Simple variable ending up *at* sp.
48 define void @test_simple_var() {
49 ; CHECK-LABEL: test_simple_var:
52 %addr8 = bitcast i32* %addr32 to i8*
57 call void @take_ptr(i8* %addr8)
61 ; Simple variable ending up at aligned offset from sp.
62 define void @test_local_var_addr_aligned() {
63 ; CHECK-LABEL: test_local_var_addr_aligned:
65 %addr1.32 = alloca i32
66 %addr1 = bitcast i32* %addr1.32 to i8*
67 %addr2.32 = alloca i32
68 %addr2 = bitcast i32* %addr2.32 to i8*
70 ; CHECK: add r0, sp, #{{[0-9]+}}
72 call void @take_ptr(i8* %addr1)
77 call void @take_ptr(i8* %addr2)
82 ; Simple variable ending up at aligned offset from sp.
83 define void @test_local_var_big_offset() {
84 ; CHECK-LABEL: test_local_var_big_offset:
85 %addr1.32 = alloca i32, i32 257
86 %addr1 = bitcast i32* %addr1.32 to i8*
87 %addr2.32 = alloca i32, i32 257
89 ; CHECK: add [[RTMP:r[0-9]+]], sp, #1020
90 ; CHECK: adds [[RTMP]], #8
92 call void @take_ptr(i8* %addr1)
97 ; Max range addressable with tADDrSPi
98 define void @test_local_var_offset_1020() {
99 ; CHECK-LABEL: test_local_var_offset_1020
100 %addr1 = alloca i8, i32 4
101 %addr2 = alloca i8, i32 1020
103 ; CHECK: add r0, sp, #1020
105 call void @take_ptr(i8* %addr1)
110 ; Max range addressable with tADDrSPi + tADDi8 is 1275, however the automatic
111 ; 4-byte aligning of objects on the stack combined with 8-byte stack alignment
112 ; means that 1268 is the max offset we can use.
113 define void @test_local_var_offset_1268() {
114 ; CHECK-LABEL: test_local_var_offset_1268
115 %addr1 = alloca i8, i32 1
116 %addr2 = alloca i8, i32 1268
118 ; CHECK: add r0, sp, #1020
119 ; CHECK: adds r0, #248
121 call void @take_ptr(i8* %addr1)
126 declare void @take_ptr(i8*)