1 ; RUN: opt -objc-arc -S < %s | FileCheck %s
3 declare void @objc_release(i8* %x)
4 declare i8* @objc_retain(i8* %x)
5 declare i8* @objc_autorelease(i8* %x)
6 declare i8* @objc_autoreleaseReturnValue(i8* %x)
7 declare i8* @objc_retainAutoreleasedReturnValue(i8* %x)
10 ; Never tail call objc_autorelease.
12 ; CHECK: define i8* @test0(i8* %x) [[NUW:#[0-9]+]] {
13 ; CHECK: %tmp0 = call i8* @objc_autorelease(i8* %x) [[NUW]]
14 ; CHECK: %tmp1 = call i8* @objc_autorelease(i8* %x) [[NUW]]
16 define i8* @test0(i8* %x) nounwind {
18 %tmp0 = call i8* @objc_autorelease(i8* %x)
19 %tmp1 = tail call i8* @objc_autorelease(i8* %x)
24 ; Always tail call autoreleaseReturnValue.
26 ; CHECK: define i8* @test1(i8* %x) [[NUW]] {
27 ; CHECK: %tmp0 = tail call i8* @objc_autoreleaseReturnValue(i8* %x) [[NUW]]
28 ; CHECK: %tmp1 = tail call i8* @objc_autoreleaseReturnValue(i8* %x) [[NUW]]
30 define i8* @test1(i8* %x) nounwind {
32 %tmp0 = call i8* @objc_autoreleaseReturnValue(i8* %x)
33 %tmp1 = tail call i8* @objc_autoreleaseReturnValue(i8* %x)
37 ; Always tail call objc_retain.
39 ; CHECK: define i8* @test2(i8* %x) [[NUW]] {
40 ; CHECK: %tmp0 = tail call i8* @objc_retain(i8* %x) [[NUW]]
41 ; CHECK: %tmp1 = tail call i8* @objc_retain(i8* %x) [[NUW]]
43 define i8* @test2(i8* %x) nounwind {
45 %tmp0 = call i8* @objc_retain(i8* %x)
46 %tmp1 = tail call i8* @objc_retain(i8* %x)
50 ; Always tail call objc_retainAutoreleasedReturnValue.
51 ; CHECK: define i8* @test3(i8* %x) [[NUW]] {
52 ; CHECK: %tmp0 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %y) [[NUW]]
53 ; CHECK: %tmp1 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %z) [[NUW]]
55 define i8* @test3(i8* %x) nounwind {
57 %y = call i8* @tmp(i8* %x)
58 %tmp0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %y)
59 %z = call i8* @tmp(i8* %x)
60 %tmp1 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %z)
64 ; By itself, we should never change whether or not objc_release is tail called.
66 ; CHECK: define void @test4(i8* %x) [[NUW]] {
67 ; CHECK: call void @objc_release(i8* %x) [[NUW]]
68 ; CHECK: tail call void @objc_release(i8* %x) [[NUW]]
70 define void @test4(i8* %x) nounwind {
72 call void @objc_release(i8* %x)
73 tail call void @objc_release(i8* %x)
77 ; If we convert a tail called @objc_autoreleaseReturnValue to an
78 ; @objc_autorelease, ensure that the tail call is removed.
79 ; CHECK: define i8* @test5(i8* %x) [[NUW]] {
80 ; CHECK: %tmp0 = call i8* @objc_autorelease(i8* %x) [[NUW]]
82 define i8* @test5(i8* %x) nounwind {
84 %tmp0 = tail call i8* @objc_autoreleaseReturnValue(i8* %x)
88 ; CHECK: attributes [[NUW]] = { nounwind }