1; RUN: opt < %s -passes=globalopt -S | FileCheck %s 2 3declare token @llvm.call.preallocated.setup(i32) 4declare i8* @llvm.call.preallocated.arg(token, i32) 5declare i32 @__CxxFrameHandler3(...) 6 7; Don't touch functions with any musttail calls 8define 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 11 ret i32 %rv 12} 13 14define i32 @call_preallocated_musttail(i32* preallocated(i32) %a) { 15 %r = musttail call i32 @preallocated_musttail(i32* preallocated(i32) %a) 16 ret i32 %r 17} 18; CHECK-LABEL: define i32 @call_preallocated_musttail(i32* preallocated(i32) %a) 19; CHECK: musttail call i32 @preallocated_musttail(i32* preallocated(i32) %a) 20 21define 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)] 26 ret i32 %r 27} 28; CHECK-LABEL: define i32 @call_preallocated_musttail_without_musttail() 29; CHECK: call i32 @preallocated_musttail(i32* preallocated(i32) %n) 30 31; Check that only one alloca per preallocated arg 32define internal i32 @preallocated(i32* preallocated(i32) %a) { 33; CHECK-LABEL: define internal fastcc i32 @preallocated(i32* %a) 34 %rv = load i32, i32* %a 35 ret i32 %rv 36} 37 38declare void @foo(i8*) 39 40define 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]]) 51; CHECK-NEXT: ret 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)] 61 ret i32 %r 62} 63 64; Don't touch functions with any invokes 65define 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 68 ret i32 %rv 69} 70 71define 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 77conta: 78 ret i32 %r 79contb: 80 %s = catchswitch within none [label %catch] unwind to caller 81catch: 82 %p = catchpad within %s [] 83 catchret from %p to label %cont 84cont: 85 ret i32 42 86} 87; CHECK-LABEL: define i32 @call_preallocated_invoke() 88; CHECK: invoke i32 @preallocated_invoke(i32* preallocated(i32) %b) 89