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 5 6@__bar = external hidden global i8* 7@__baz = external hidden global i8* 8 9; rdar://8819685 10define i8* @_foo() { 11entry: 12; CHECK-LABEL: __foo{{>?}}: 13 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 18; CHECK: bne 19 20bb1: 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 29 30bb2: 31 %6 = call i8* @strdup(i8* %3) nounwind 32 store i8* %6, i8** @__baz, align 4 33 br label %bb3 34 35bb3: 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} 41 ret i8* %.0 42} 43 44declare noalias i8* @strdup(i8* nocapture) nounwind 45declare i32 @_called_func(i8*, i32*) nounwind 46 47; Simple variable ending up *at* sp. 48define void @test_simple_var() { 49; CHECK-LABEL: test_simple_var{{>?}}: 50 51 %addr32 = alloca i32 52 %addr8 = bitcast i32* %addr32 to i8* 53 54; CHECK: mov r0, sp 55; CHECK-NOT: adds r0 56; CHECK: bl 57 call void @take_ptr(i8* %addr8) 58 ret void 59} 60 61; Simple variable ending up at aligned offset from sp. 62define void @test_local_var_addr_aligned() { 63; CHECK-LABEL: test_local_var_addr_aligned{{>?}}: 64 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* 69 70; CHECK: add r0, sp, #{{[0-9]+}} 71; CHECK: bl 72 call void @take_ptr(i8* %addr1) 73 74; CHECK: mov r0, sp 75; CHECK-NOT: add r0 76; CHECK: bl 77 call void @take_ptr(i8* %addr2) 78 79 ret void 80} 81 82; Simple variable ending up at aligned offset from sp. 83define 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 88 89; CHECK: add [[RTMP:r[0-9]+]], sp, #1020 90; CHECK: adds [[RTMP]], #8 91; CHECK: bl 92 call void @take_ptr(i8* %addr1) 93 94 ret void 95} 96 97; Max range addressable with tADDrSPi 98define 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 102 103; CHECK: add r0, sp, #1020 104; CHECK-NEXT: bl 105 call void @take_ptr(i8* %addr1) 106 107 ret void 108} 109 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. 113define 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 117 118; CHECK: add r0, sp, #1020 119; CHECK: adds r0, #248 120; CHECK-NEXT: bl 121 call void @take_ptr(i8* %addr1) 122 123 ret void 124} 125 126declare void @take_ptr(i8*) 127