Re-apply r110655 with fixes. Epilogue must restore sp from fp if the function stack...
[oota-llvm.git] / test / CodeGen / Thumb2 / 2010-08-10-VarSizedAllocaBug.ll
1 ; RUN: llc < %s -mtriple=thumbv7-apple-darwin -mcpu=cortex-a8 -O3 | FileCheck %s
2
3 @.str = private constant [4 x i8] c"%d\0A\00", align 4 ; <[4 x i8]*> [#uses=1]
4
5 define internal fastcc i32 @Callee(i32 %i) nounwind {
6 entry:
7 ; CHECK: Callee:
8   %0 = icmp eq i32 %i, 0                          ; <i1> [#uses=1]
9   br i1 %0, label %bb2, label %bb
10
11 bb:                                               ; preds = %entry
12   %1 = alloca [1000 x i8], align 4                ; <[1000 x i8]*> [#uses=1]
13   %.sub = getelementptr inbounds [1000 x i8]* %1, i32 0, i32 0 ; <i8*> [#uses=2]
14   %2 = call i32 (i8*, i32, i32, i8*, ...)* @__sprintf_chk(i8* %.sub, i32 0, i32 1000, i8* getelementptr inbounds ([4 x i8]* @.str, i32 0, i32 0), i32 %i) nounwind ; <i32> [#uses=0]
15   %3 = load i8* %.sub, align 4                    ; <i8> [#uses=1]
16   %4 = sext i8 %3 to i32                          ; <i32> [#uses=1]
17   ret i32 %4
18
19 bb2:                                              ; preds = %entry
20 ; Must restore sp from fp here
21 ; CHECK: mov sp, r7
22 ; CHECK: sub sp, #8
23 ; CHECK: pop
24   ret i32 0
25 }
26
27 declare i32 @__sprintf_chk(i8*, i32, i32, i8*, ...) nounwind
28
29 define i32 @main() nounwind {
30 ; CHECK: main:
31 bb.nph:
32   br label %bb
33
34 bb:                                               ; preds = %bb, %bb.nph
35   %0 = phi i32 [ 0, %bb.nph ], [ %3, %bb ]        ; <i32> [#uses=2]
36   %j.01 = phi i32 [ 0, %bb.nph ], [ %2, %bb ]     ; <i32> [#uses=1]
37   %1 = tail call fastcc i32 @Callee(i32 %0) nounwind ; <i32> [#uses=1]
38   %2 = add nsw i32 %1, %j.01                      ; <i32> [#uses=2]
39   %3 = add nsw i32 %0, 1                          ; <i32> [#uses=2]
40   %exitcond = icmp eq i32 %3, 10000               ; <i1> [#uses=1]
41   br i1 %exitcond, label %bb2, label %bb
42
43 bb2:                                              ; preds = %bb
44 ; No need to restore sp from fp here.
45 ; CHECK: printf
46 ; CHECK-NOT: mov sp, r7
47 ; CHECK-NOT: sub sp, #12
48 ; CHECK: pop
49   %4 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([4 x i8]* @.str, i32 0, i32 0), i32 %2) nounwind ; <i32> [#uses=0]
50   ret i32 0
51 }
52
53 declare i32 @printf(i8* nocapture, ...) nounwind