1; RUN: opt -objc-arc -S < %s | FileCheck %s 2 3declare void @llvm.objc.release(i8* %x) 4declare i8* @llvm.objc.retain(i8* %x) 5declare i8* @llvm.objc.autorelease(i8* %x) 6declare i8* @llvm.objc.autoreleaseReturnValue(i8* %x) 7declare i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %x) 8declare i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8* %x) 9declare i8* @tmp(i8*) 10 11; Never tail call objc_autorelease. 12 13; CHECK: define i8* @test0(i8* %x) [[NUW:#[0-9]+]] { 14; CHECK: %tmp0 = call i8* @llvm.objc.autorelease(i8* %x) [[NUW]] 15; CHECK: %tmp1 = call i8* @llvm.objc.autorelease(i8* %x) [[NUW]] 16; CHECK: } 17define i8* @test0(i8* %x) nounwind { 18entry: 19 %tmp0 = call i8* @llvm.objc.autorelease(i8* %x) 20 %tmp1 = tail call i8* @llvm.objc.autorelease(i8* %x) 21 22 ret i8* %x 23} 24 25; Always tail call autoreleaseReturnValue. 26 27; CHECK: define i8* @test1(i8* %x) [[NUW]] { 28; CHECK: %tmp0 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %x) [[NUW]] 29; CHECK: %tmp1 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %x) [[NUW]] 30; CHECK: } 31define i8* @test1(i8* %x) nounwind { 32entry: 33 %tmp0 = call i8* @llvm.objc.autoreleaseReturnValue(i8* %x) 34 %tmp1 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %x) 35 ret i8* %x 36} 37 38; Always tail call objc_retain. 39 40; CHECK: define i8* @test2(i8* %x) [[NUW]] { 41; CHECK: %tmp0 = tail call i8* @llvm.objc.retain(i8* %x) [[NUW]] 42; CHECK: %tmp1 = tail call i8* @llvm.objc.retain(i8* %x) [[NUW]] 43; CHECK: } 44define i8* @test2(i8* %x) nounwind { 45entry: 46 %tmp0 = call i8* @llvm.objc.retain(i8* %x) 47 %tmp1 = tail call i8* @llvm.objc.retain(i8* %x) 48 ret i8* %x 49} 50 51; Always tail call objc_retainAutoreleasedReturnValue unless it's annotated with 52; notail. 53; CHECK: define i8* @test3(i8* %x) [[NUW]] { 54; CHECK: %tmp0 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %y) [[NUW]] 55; CHECK: %tmp1 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %z) [[NUW]] 56; CHECK: %tmp2 = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %z2) [[NUW]] 57; CHECK: } 58define i8* @test3(i8* %x) nounwind { 59entry: 60 %y = call i8* @tmp(i8* %x) 61 %tmp0 = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %y) 62 %z = call i8* @tmp(i8* %x) 63 %tmp1 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %z) 64 %z2 = call i8* @tmp(i8* %x) 65 %tmp2 = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %z2) 66 ret i8* %x 67} 68 69; By itself, we should never change whether or not objc_release is tail called. 70 71; CHECK: define void @test4(i8* %x) [[NUW]] { 72; CHECK: call void @llvm.objc.release(i8* %x) [[NUW]] 73; CHECK: tail call void @llvm.objc.release(i8* %x) [[NUW]] 74; CHECK: } 75define void @test4(i8* %x) nounwind { 76entry: 77 call void @llvm.objc.release(i8* %x) 78 tail call void @llvm.objc.release(i8* %x) 79 ret void 80} 81 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 i8* @test5(i8* %x) [[NUW]] { 85; CHECK: %tmp0 = call i8* @llvm.objc.autorelease(i8* %x) [[NUW]] 86; CHECK: } 87define i8* @test5(i8* %x) nounwind { 88entry: 89 %tmp0 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %x) 90 ret i8* %tmp0 91} 92 93; Always tail call llvm.objc.unsafeClaimAutoreleasedReturnValue. 94; CHECK: define i8* @test6(i8* %x) [[NUW]] { 95; CHECK: %tmp0 = tail call i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8* %y) [[NUW]] 96; CHECK: %tmp1 = tail call i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8* %z) [[NUW]] 97; CHECK: } 98define i8* @test6(i8* %x) nounwind { 99entry: 100 %y = call i8* @tmp(i8* %x) 101 %tmp0 = call i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8* %y) 102 %z = call i8* @tmp(i8* %x) 103 %tmp1 = tail call i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8* %z) 104 ret i8* %x 105} 106 107; CHECK: attributes [[NUW]] = { nounwind } 108 109