15a5c66815d2d77ce99328fd2edc58fa1b6e455e
[oota-llvm.git] / test / Transforms / Inline / dynamic_alloca_test.ll
1 ; Test that functions with dynamic allocas get inlined in a case where
2 ; naively inlining it would result in a miscompilation.
3 ; Functions with dynamic allocas can only be inlined into functions that
4 ; already have dynamic allocas.
5
6 ; RUN: opt < %s -inline -S | FileCheck %s
7 ;
8 ; FIXME: This test is xfailed because the inline cost rewrite disabled *all*
9 ; inlining of functions which contain a dynamic alloca. It should be re-enabled
10 ; once that functionality is restored.
11 ; XFAIL: *
12
13 declare void @ext(i32*)
14
15 define internal void @callee(i32 %N) {
16   %P = alloca i32, i32 %N
17   call void @ext(i32* %P)
18   ret void
19 }
20
21 define void @foo(i32 %N) {
22 ; CHECK: @foo
23 ; CHECK: alloca i32, i32 %{{.*}}
24 ; CHECK: call i8* @llvm.stacksave()
25 ; CHECK: alloca i32, i32 %{{.*}}
26 ; CHECK: call void @ext
27 ; CHECK: call void @llvm.stackrestore
28 ; CHECK: ret
29
30 entry:
31   %P = alloca i32, i32 %N
32   call void @ext(i32* %P)
33   br label %loop
34
35 loop:
36   %count = phi i32 [ 0, %entry ], [ %next, %loop ]
37   %next = add i32 %count, 1
38   call void @callee(i32 %N)
39   %cond = icmp eq i32 %count, 100000
40   br i1 %cond, label %out, label %loop
41
42 out:
43   ret void
44 }
45