1 ; RUN: opt < %s -partial-inliner -S -skip-partial-inlining-cost-analysis | FileCheck %s
2 ; RUN: opt < %s -passes=partial-inliner -S -skip-partial-inlining-cost-analysis | FileCheck %s
4 @stat = external global i32, align 4
6 define i32 @vararg(i32 %count, ...) {
8 %vargs = alloca i8*, align 8
9 %stat1 = load i32, i32* @stat, align 4
10 %cmp = icmp slt i32 %stat1, 0
11 br i1 %cmp, label %bb2, label %bb1
14 %vg1 = add nsw i32 %stat1, 1
15 store i32 %vg1, i32* @stat, align 4
16 %vargs1 = bitcast i8** %vargs to i8*
17 call void @llvm.va_start(i8* %vargs1)
18 %va1 = va_arg i8** %vargs, i32
19 call void @foo(i32 %count, i32 %va1) #2
20 call void @llvm.va_end(i8* %vargs1)
23 bb2: ; preds = %bb1, %entry
24 %res = phi i32 [ 1, %bb1 ], [ 0, %entry ]
28 declare void @foo(i32, i32)
29 declare void @llvm.va_start(i8*)
30 declare void @llvm.va_end(i8*)
32 define i32 @caller1(i32 %arg) {
34 %tmp = tail call i32 (i32, ...) @vararg(i32 %arg)
37 ; CHECK-LABEL: @caller1
39 ; CHECK-NEXT: call void (i32, i8**, i32, ...) @vararg.3.bb1(i32 %stat1.i, i8** %vargs.i, i32 %arg)
41 define i32 @caller2(i32 %arg, float %arg2) {
43 %tmp = tail call i32 (i32, ...) @vararg(i32 %arg, i32 10, float %arg2)
47 ; CHECK-LABEL: @caller2
49 ; CHECK-NEXT: call void (i32, i8**, i32, ...) @vararg.3.bb1(i32 %stat1.i, i8** %vargs.i, i32 %arg, i32 10, float %arg2)
51 ; Test case to check that we do not extract a vararg function, if va_end is in
52 ; a block that is not outlined.
53 define i32 @vararg_not_legal(i32 %count, ...) {
55 %vargs = alloca i8*, align 8
56 %vargs0 = bitcast i8** %vargs to i8*
57 %stat1 = load i32, i32* @stat, align 4
58 %cmp = icmp slt i32 %stat1, 0
59 br i1 %cmp, label %bb2, label %bb1
62 %vg1 = add nsw i32 %stat1, 1
63 store i32 %vg1, i32* @stat, align 4
64 %vargs1 = bitcast i8** %vargs to i8*
65 call void @llvm.va_start(i8* %vargs1)
66 %va1 = va_arg i8** %vargs, i32
67 call void @foo(i32 %count, i32 %va1)
70 bb2: ; preds = %bb1, %entry
71 %res = phi i32 [ 1, %bb1 ], [ 0, %entry ]
72 %ptr = phi i8* [ %vargs1, %bb1 ], [ %vargs0, %entry]
73 call void @llvm.va_end(i8* %ptr)
77 ; CHECK-LABEL: @caller3
78 ; CHECK: tail call i32 (i32, ...) @vararg_not_legal(i32 %arg, i32 %arg)
79 define i32 @caller3(i32 %arg) {
81 %res = tail call i32 (i32, ...) @vararg_not_legal(i32 %arg, i32 %arg)
85 declare i32* @err(i32*)
87 define signext i32 @vararg2(i32 * %l, ...) {
89 br i1 undef, label %cleanup, label %cond.end
91 cond.end: ; preds = %entry
92 %call51 = call i32* @err(i32* nonnull %l)
95 cleanup: ; preds = %entry
99 define i32* @caller_with_signext(i32* %foo) {
101 %call1 = tail call signext i32 (i32*, ...) @vararg2(i32* %foo, i32 signext 8)
105 ; CHECK-LABEL: @caller_with_signext
107 ; CHECK-NEXT: call void (i32*, ...) @vararg2.1.cond.end(i32* %foo, i32 signext 8)