1 ; RUN: opt < %s -globalopt -S | FileCheck %s
3 declare token @llvm.call.preallocated.setup(i32)
4 declare i8* @llvm.call.preallocated.arg(token, i32)
5 declare i32 @__CxxFrameHandler3(...)
7 ; Don't touch functions with any musttail calls
8 define internal i32 @preallocated_musttail(i32* preallocated(i32) %p) {
9 ; CHECK-LABEL: define internal i32 @preallocated_musttail(i32* preallocated(i32) %p)
10 %rv = load i32, i32* %p
14 define i32 @call_preallocated_musttail(i32* preallocated(i32) %a) {
15 %r = musttail call i32 @preallocated_musttail(i32* preallocated(i32) %a)
18 ; CHECK-LABEL: define i32 @call_preallocated_musttail(i32* preallocated(i32) %a)
19 ; CHECK: musttail call i32 @preallocated_musttail(i32* preallocated(i32) %a)
21 define i32 @call_preallocated_musttail_without_musttail() {
22 %c = call token @llvm.call.preallocated.setup(i32 1)
23 %N = call i8* @llvm.call.preallocated.arg(token %c, i32 0) preallocated(i32)
24 %n = bitcast i8* %N to i32*
25 %r = call i32 @preallocated_musttail(i32* preallocated(i32) %n) ["preallocated"(token %c)]
28 ; CHECK-LABEL: define i32 @call_preallocated_musttail_without_musttail()
29 ; CHECK: call i32 @preallocated_musttail(i32* preallocated(i32) %n)
31 ; Check that only one alloca per preallocated arg
32 define internal i32 @preallocated(i32* preallocated(i32) %a) {
33 ; CHECK-LABEL: define internal fastcc i32 @preallocated(i32* %a)
34 %rv = load i32, i32* %a
38 declare void @foo(i8*)
40 define i32 @call_preallocated_multiple_args() {
41 ; CHECK-LABEL: define i32 @call_preallocated_multiple_args()
42 ; CHECK-NEXT: [[SS:%[0-9a-zA-Z_]+]] = call i8* @llvm.stacksave()
43 ; CHECK-NEXT: [[ARG0:%[0-9a-zA-Z_]+]] = alloca i32
44 ; CHECK-NEXT: [[ARG1:%[0-9a-zA-Z_]+]] = bitcast i32* [[ARG0]] to i8*
45 ; CHECK-NEXT: call void @foo(i8* [[ARG1]])
46 ; CHECK-NEXT: call void @foo(i8* [[ARG1]])
47 ; CHECK-NEXT: call void @foo(i8* [[ARG1]])
48 ; CHECK-NEXT: [[ARG2:%[0-9a-zA-Z_]+]] = bitcast i8* [[ARG1]] to i32*
49 ; CHECK-NEXT: call fastcc i32 @preallocated(i32* [[ARG2]])
50 ; CHECK-NEXT: call void @llvm.stackrestore(i8* [[SS]])
52 %c = call token @llvm.call.preallocated.setup(i32 1)
53 %a1 = call i8* @llvm.call.preallocated.arg(token %c, i32 0) preallocated(i32)
54 call void @foo(i8* %a1)
55 %a2 = call i8* @llvm.call.preallocated.arg(token %c, i32 0) preallocated(i32)
56 call void @foo(i8* %a2)
57 %a3 = call i8* @llvm.call.preallocated.arg(token %c, i32 0) preallocated(i32)
58 call void @foo(i8* %a3)
59 %b = bitcast i8* %a3 to i32*
60 %r = call i32 @preallocated(i32* preallocated(i32) %b) ["preallocated"(token %c)]
64 ; Don't touch functions with any invokes
65 define internal i32 @preallocated_invoke(i32* preallocated(i32) %p) {
66 ; CHECK-LABEL: define internal i32 @preallocated_invoke(i32* preallocated(i32) %p)
67 %rv = load i32, i32* %p
71 define i32 @call_preallocated_invoke() personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
72 %c = call token @llvm.call.preallocated.setup(i32 1)
73 %a = call i8* @llvm.call.preallocated.arg(token %c, i32 0) preallocated(i32)
74 %b = bitcast i8* %a to i32*
75 %r = invoke i32 @preallocated_invoke(i32* preallocated(i32) %b) ["preallocated"(token %c)]
76 to label %conta unwind label %contb
80 %s = catchswitch within none [label %catch] unwind to caller
82 %p = catchpad within %s []
83 catchret from %p to label %cont
87 ; CHECK-LABEL: define i32 @call_preallocated_invoke()
88 ; CHECK: invoke i32 @preallocated_invoke(i32* preallocated(i32) %b)