1 ; RUN: opt -passes=objc-arc -S < %s | FileCheck %s
3 declare void @llvm.objc.release(ptr %x)
4 declare ptr @llvm.objc.retain(ptr %x)
5 declare ptr @llvm.objc.autorelease(ptr %x)
6 declare ptr @llvm.objc.autoreleaseReturnValue(ptr %x)
7 declare ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %x)
8 declare ptr @llvm.objc.unsafeClaimAutoreleasedReturnValue(ptr %x)
11 ; Never tail call objc_autorelease.
13 ; CHECK: define ptr @test0(ptr %x) [[NUW:#[0-9]+]] {
14 ; CHECK: %tmp0 = call ptr @llvm.objc.autorelease(ptr %x) [[NUW]]
15 ; CHECK: %tmp1 = call ptr @llvm.objc.autorelease(ptr %x) [[NUW]]
17 define ptr @test0(ptr %x) nounwind {
19 %tmp0 = call ptr @llvm.objc.autorelease(ptr %x)
20 %tmp1 = tail call ptr @llvm.objc.autorelease(ptr %x)
25 ; Always tail call autoreleaseReturnValue.
27 ; CHECK: define ptr @test1(ptr %x) [[NUW]] {
28 ; CHECK: %tmp0 = tail call ptr @llvm.objc.autoreleaseReturnValue(ptr %x) [[NUW]]
29 ; CHECK: %tmp1 = tail call ptr @llvm.objc.autoreleaseReturnValue(ptr %x) [[NUW]]
31 define ptr @test1(ptr %x) nounwind {
33 %tmp0 = call ptr @llvm.objc.autoreleaseReturnValue(ptr %x)
34 %tmp1 = tail call ptr @llvm.objc.autoreleaseReturnValue(ptr %x)
38 ; Always tail call objc_retain.
40 ; CHECK: define ptr @test2(ptr %x) [[NUW]] {
41 ; CHECK: %tmp0 = tail call ptr @llvm.objc.retain(ptr %x) [[NUW]]
42 ; CHECK: %tmp1 = tail call ptr @llvm.objc.retain(ptr %x) [[NUW]]
44 define ptr @test2(ptr %x) nounwind {
46 %tmp0 = call ptr @llvm.objc.retain(ptr %x)
47 %tmp1 = tail call ptr @llvm.objc.retain(ptr %x)
51 ; Always tail call objc_retainAutoreleasedReturnValue unless it's annotated with
53 ; CHECK: define ptr @test3(ptr %x) [[NUW]] {
54 ; CHECK: %tmp0 = tail call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %y) [[NUW]]
55 ; CHECK: %tmp1 = tail call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %z) [[NUW]]
56 ; CHECK: %tmp2 = notail call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %z2) [[NUW]]
58 define ptr @test3(ptr %x) nounwind {
60 %y = call ptr @tmp(ptr %x)
61 %tmp0 = call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %y)
62 %z = call ptr @tmp(ptr %x)
63 %tmp1 = tail call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %z)
64 %z2 = call ptr @tmp(ptr %x)
65 %tmp2 = notail call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %z2)
69 ; By itself, we should never change whether or not objc_release is tail called.
71 ; CHECK: define void @test4(ptr %x) [[NUW]] {
72 ; CHECK: call void @llvm.objc.release(ptr %x) [[NUW]]
73 ; CHECK: tail call void @llvm.objc.release(ptr %x) [[NUW]]
75 define void @test4(ptr %x) nounwind {
77 call void @llvm.objc.release(ptr %x)
78 tail call void @llvm.objc.release(ptr %x)
82 ; If we convert a tail called @llvm.objc.autoreleaseReturnValue to an
83 ; @llvm.objc.autorelease, ensure that the tail call is removed.
84 ; CHECK: define ptr @test5(ptr %x) [[NUW]] {
85 ; CHECK: %tmp0 = call ptr @llvm.objc.autorelease(ptr %x) [[NUW]]
87 define ptr @test5(ptr %x) nounwind {
89 %tmp0 = tail call ptr @llvm.objc.autoreleaseReturnValue(ptr %x)
93 ; Always tail call llvm.objc.unsafeClaimAutoreleasedReturnValue.
94 ; CHECK: define ptr @test6(ptr %x) [[NUW]] {
95 ; CHECK: %tmp0 = tail call ptr @llvm.objc.unsafeClaimAutoreleasedReturnValue(ptr %y) [[NUW]]
96 ; CHECK: %tmp1 = tail call ptr @llvm.objc.unsafeClaimAutoreleasedReturnValue(ptr %z) [[NUW]]
98 define ptr @test6(ptr %x) nounwind {
100 %y = call ptr @tmp(ptr %x)
101 %tmp0 = call ptr @llvm.objc.unsafeClaimAutoreleasedReturnValue(ptr %y)
102 %z = call ptr @tmp(ptr %x)
103 %tmp1 = tail call ptr @llvm.objc.unsafeClaimAutoreleasedReturnValue(ptr %z)
107 ; CHECK: attributes [[NUW]] = { nounwind }