1 ; RUN: opt < %s -passes=partial-inliner -S -skip-partial-inlining-cost-analysis | FileCheck %s
3 @stat = external global i32, align 4
5 define i32 @vararg(i32 %count, ...) {
7 %vargs = alloca ptr, align 8
8 %stat1 = load i32, ptr @stat, align 4
9 %cmp = icmp slt i32 %stat1, 0
10 br i1 %cmp, label %bb2, label %bb1
13 %vg1 = add nsw i32 %stat1, 1
14 store i32 %vg1, ptr @stat, align 4
15 call void @llvm.va_start(ptr %vargs)
16 %va1 = va_arg ptr %vargs, i32
17 call void @foo(i32 %count, i32 %va1) #2
18 call void @llvm.va_end(ptr %vargs)
21 bb2: ; preds = %bb1, %entry
22 %res = phi i32 [ 1, %bb1 ], [ 0, %entry ]
26 declare void @foo(i32, i32)
27 declare void @llvm.va_start(ptr)
28 declare void @llvm.va_end(ptr)
30 define i32 @caller1(i32 %arg) {
32 %tmp = tail call i32 (i32, ...) @vararg(i32 %arg)
35 ; CHECK-LABEL: @caller1
37 ; CHECK-NEXT: call void (i32, ptr, i32, ...) @vararg.3.bb1(i32 %stat1.i, ptr %vargs.i, i32 %arg)
39 define i32 @caller2(i32 %arg, float %arg2) {
41 %tmp = tail call i32 (i32, ...) @vararg(i32 %arg, i32 10, float %arg2)
45 ; CHECK-LABEL: @caller2
47 ; CHECK-NEXT: call void (i32, ptr, i32, ...) @vararg.3.bb1(i32 %stat1.i, ptr %vargs.i, i32 %arg, i32 10, float %arg2)
49 ; Test case to check that we do not extract a vararg function, if va_end is in
50 ; a block that is not outlined.
51 define i32 @vararg_not_legal(i32 %count, ...) {
53 %vargs = alloca ptr, align 8
54 %stat1 = load i32, ptr @stat, align 4
55 %cmp = icmp slt i32 %stat1, 0
56 br i1 %cmp, label %bb2, label %bb1
59 %vg1 = add nsw i32 %stat1, 1
60 store i32 %vg1, ptr @stat, align 4
61 call void @llvm.va_start(ptr %vargs)
62 %va1 = va_arg ptr %vargs, i32
63 call void @foo(i32 %count, i32 %va1)
66 bb2: ; preds = %bb1, %entry
67 %res = phi i32 [ 1, %bb1 ], [ 0, %entry ]
68 %ptr = phi ptr [ %vargs, %bb1 ], [ %vargs, %entry]
69 call void @llvm.va_end(ptr %ptr)
73 ; CHECK-LABEL: @caller3
74 ; CHECK: tail call i32 (i32, ...) @vararg_not_legal(i32 %arg, i32 %arg)
75 define i32 @caller3(i32 %arg) {
77 %res = tail call i32 (i32, ...) @vararg_not_legal(i32 %arg, i32 %arg)
83 define signext i32 @vararg2(ptr %l, ...) {
86 br i1 %c, label %cleanup, label %cond.end
88 cond.end: ; preds = %entry
89 %call51 = call ptr @err(ptr nonnull %l)
92 cleanup: ; preds = %entry
96 define ptr @caller_with_signext(ptr %foo) {
98 %call1 = tail call signext i32 (ptr, ...) @vararg2(ptr %foo, i32 signext 8)
102 ; CHECK-LABEL: @caller_with_signext
104 ; CHECK-NEXT: call void (ptr, ...) @vararg2.1.cond.end(ptr %foo, i32 signext 8)