1 ; RUN: opt -objc-arc-contract -S < %s | FileCheck %s
3 declare i8* @llvm.objc.autoreleaseReturnValue(i8*)
6 ; Check that ARC contraction replaces the function return with the value
7 ; returned by @llvm.objc.autoreleaseReturnValue.
9 ; CHECK-LABEL: define i32* @autoreleaseRVTailCall(
10 ; CHECK: %[[V0:[0-9]+]] = tail call i8* @llvm.objc.autoreleaseReturnValue(
11 ; CHECK: %[[V1:[0-9]+]] = bitcast i8* %[[V0]] to i32*
12 ; CHECK: ret i32* %[[V1]]
14 define i32* @autoreleaseRVTailCall() {
16 %2 = bitcast i8* %1 to i32*
17 %3 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %1)
21 declare i32* @foo2(i32);
23 ; CHECK-LABEL: define i32* @autoreleaseRVTailCallPhi(
24 ; CHECK: %[[PHIVAL:.*]] = phi i8* [ %{{.*}}, %bb1 ], [ %{{.*}}, %bb2 ]
25 ; CHECK: %[[RETVAL:.*]] = phi i32* [ %{{.*}}, %bb1 ], [ %{{.*}}, %bb2 ]
26 ; CHECK: %[[V4:.*]] = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %[[PHIVAL]])
27 ; CHECK: %[[V0:.*]] = bitcast i8* %[[V4]] to i32*
28 ; CHECK: ret i32* %[[V0]]
30 define i32* @autoreleaseRVTailCallPhi(i1 %cond) {
32 br i1 %cond, label %bb1, label %bb2
34 %v0 = call i32* @foo2(i32 1)
35 %v1 = bitcast i32* %v0 to i8*
38 %v2 = call i32* @foo2(i32 2)
39 %v3 = bitcast i32* %v2 to i8*
42 %phival = phi i8* [ %v1, %bb1 ], [ %v3, %bb2 ]
43 %retval = phi i32* [ %v0, %bb1 ], [ %v2, %bb2 ]
44 %v4 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %phival)