Home | History | Annotate | Download | only in ARM
      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
     10 define i8* @_foo() {
     11 entry:
     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 		
     20 bb1:
     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 	
     30 bb2:
     31 	%6 = call i8* @strdup(i8* %3) nounwind
     32 	store i8* %6, i8** @__baz, align 4
     33 	br label %bb3
     34 	
     35 bb3:
     36 	%.0 = phi i8* [ %0, %entry ], [ %6, %bb2 ], [ %3, %bb1 ]
     37 ; CHECK: subs    r4, #5
     38 ; CHECK-NEXT: mov     sp, r4
     39 ; CHECK-NEXT: pop     {r4, r5, r6, r7, pc}
     40 	ret i8* %.0
     41 }
     42 
     43 declare noalias i8* @strdup(i8* nocapture) nounwind
     44 declare i32 @_called_func(i8*, i32*) nounwind
     45 
     46 ; Simple variable ending up *at* sp.
     47 define void @test_simple_var() {
     48 ; CHECK-LABEL: test_simple_var:
     49 
     50   %addr32 = alloca i32
     51   %addr8 = bitcast i32* %addr32 to i8*
     52 
     53 ; CHECK: mov r0, sp
     54 ; CHECK-NOT: adds r0
     55 ; CHECK: blx
     56   call void @take_ptr(i8* %addr8)
     57   ret void
     58 }
     59 
     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:
     63 
     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*
     68 
     69 ; CHECK: add r0, sp, #{{[0-9]+}}
     70 ; CHECK: blx
     71   call void @take_ptr(i8* %addr1)
     72 
     73 ; CHECK: mov r0, sp
     74 ; CHECK-NOT: add r0
     75 ; CHECK: blx
     76   call void @take_ptr(i8* %addr2)
     77 
     78   ret void
     79 }
     80 
     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
     87 
     88 ; CHECK: add [[RTMP:r[0-9]+]], sp, #1020
     89 ; CHECK: adds [[RTMP]], #8
     90 ; CHECK: blx
     91   call void @take_ptr(i8* %addr1)
     92 
     93   ret void
     94 }
     95 
     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
    101 
    102 ; CHECK: add r0, sp, #1020
    103 ; CHECK-NEXT: blx
    104   call void @take_ptr(i8* %addr1)
    105 
    106   ret void
    107 }
    108 
    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
    116 
    117 ; CHECK: add r0, sp, #1020
    118 ; CHECK: adds r0, #248
    119 ; CHECK-NEXT: blx
    120   call void @take_ptr(i8* %addr1)
    121 
    122   ret void
    123 }
    124 
    125 declare void @take_ptr(i8*)
    126