1; RUN: llc < %s -mtriple=thumb-apple-ios | FileCheck %s --check-prefix=CHECK --check-prefix=IOS 2; RUN: llc < %s -mtriple=thumb-none-eabi | FileCheck %s --check-prefix=CHECK --check-prefix=EABI 3; RUN: llc < %s -o %t -filetype=obj -mtriple=thumbv6-apple-ios 4; RUN: llvm-objdump -triple=thumbv6-apple-ios -d %t | FileCheck %s --check-prefix=CHECK --check-prefix=IOS 5; RUN: llc < %s -o %t -filetype=obj -mtriple=thumbv6-none-eabi 6; RUN: llvm-objdump -triple=thumbv6-none-eabi -d %t | FileCheck %s --check-prefix=CHECK --check-prefix=EABI 7 8; Largest stack for which a single tADDspi/tSUBspi is enough 9define void @test1() { 10; CHECK-LABEL: test1: 11; CHECK: sub sp, #508 12; CHECK: add sp, #508 13 %tmp = alloca [ 508 x i8 ] , align 4 14 ret void 15} 16 17; Largest stack for which three tADDspi/tSUBspis are enough 18define void @test100() { 19; CHECK-LABEL: test100: 20; CHECK: sub sp, #508 21; CHECK: sub sp, #508 22; CHECK: sub sp, #508 23; EABI: add sp, #508 24; EABI: add sp, #508 25; EABI: add sp, #508 26; IOS: subs r4, r7, #4 27; IOS: mov sp, r4 28 %tmp = alloca [ 1524 x i8 ] , align 4 29 ret void 30} 31 32; Smallest stack for which we use a constant pool 33define void @test2() { 34; CHECK-LABEL: test2: 35; CHECK: ldr r0, 36; CHECK: add sp, r0 37; EABI: ldr r0, 38; EABI: add sp, r0 39; IOS: subs r4, r7, #4 40; IOS: mov sp, r4 41 %tmp = alloca [ 1528 x i8 ] , align 4 42 ret void 43} 44 45define i32 @test3() { 46; CHECK-LABEL: test3: 47; CHECK: ldr r1, 48; CHECK: add sp, r1 49; CHECK: ldr r1, 50; CHECK: add r1, sp 51; EABI: ldr r1, 52; EABI: add sp, r1 53; IOS: subs r4, r7, #4 54; IOS: mov sp, r4 55 %retval = alloca i32, align 4 56 %tmp = alloca i32, align 4 57 %a = alloca [805306369 x i8], align 16 58 store i32 0, i32* %tmp 59 %tmp1 = load i32, i32* %tmp 60 ret i32 %tmp1 61} 62 63; Here, the adds get optimized out because they are dead, but the calculation 64; of the address of stack_a is dead but not optimized out. When the address 65; calculation gets expanded to two instructions, we need to avoid reading a 66; dead register. 67; No CHECK lines (just test for crashes), as we hope this will be optimised 68; better in future. 69define i32 @test4() { 70entry: 71 %stack_a = alloca i8, align 1 72 %stack_b = alloca [256 x i32*], align 4 73 %int = ptrtoint i8* %stack_a to i32 74 %add = add i32 %int, 1 75 br label %block2 76 77block2: 78 %add2 = add i32 %add, 1 79 ret i32 0 80} 81