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
13declare void @ext(i32*)
14
15define internal void @callee(i32 %N) {
16  %P = alloca i32, i32 %N
17  call void @ext(i32* %P)
18  ret void
19}
20
21define void @foo(i32 %N) {
22; CHECK-LABEL: @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
30entry:
31  %P = alloca i32, i32 %N
32  call void @ext(i32* %P)
33  br label %loop
34
35loop:
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
42out:
43  ret void
44}
45
46