1 ; RUN: opt -S -passes=objc-arc < %s | FileCheck %s
3 declare void @use_pointer(ptr)
4 declare ptr @returner()
5 declare ptr @llvm.objc.retain(ptr)
6 declare ptr @llvm.objc.autoreleaseReturnValue(ptr)
7 declare ptr @llvm.objc.retainAutoreleasedReturnValue(ptr)
9 ; Clean up residue left behind after inlining.
11 ; CHECK-LABEL: define void @test0(
13 ; CHECK-NEXT: ret void
15 define void @test0(ptr %call.i) {
17 %0 = tail call ptr @llvm.objc.retain(ptr %call.i) nounwind
18 %1 = tail call ptr @llvm.objc.autoreleaseReturnValue(ptr %0) nounwind
22 ; Same as test0, but with slightly different use arrangements.
24 ; CHECK-LABEL: define void @test1(
26 ; CHECK-NEXT: ret void
28 define void @test1(ptr %call.i) {
30 %0 = tail call ptr @llvm.objc.retain(ptr %call.i) nounwind
31 %1 = tail call ptr @llvm.objc.autoreleaseReturnValue(ptr %call.i) nounwind
35 ; Delete a retainRV+autoreleaseRV even if the pointer is used.
37 ; CHECK-LABEL: define void @test24(
39 ; CHECK-NEXT: call void @use_pointer(ptr %p)
40 ; CHECK-NEXT: ret void
42 define void @test24(ptr %p) {
44 call ptr @llvm.objc.autoreleaseReturnValue(ptr %p) nounwind
45 call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %p) nounwind
46 call void @use_pointer(ptr %p)
50 ; Check that we can delete the autoreleaseRV+retainAutoreleasedRV pair even in
51 ; presence of instructions added by the inliner as part of the return sequence.
53 ; 1) Noop instructions: bitcasts and zero-indices GEPs.
55 ; CHECK-LABEL: define ptr @testNoop(
57 ; CHECK-NEXT: ret ptr %call.i
59 define ptr @testNoop(ptr %call.i) {
61 %0 = tail call ptr @llvm.objc.autoreleaseReturnValue(ptr %call.i) nounwind
62 %1 = tail call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %call.i) nounwind
66 ; 2) Lifetime markers.
68 declare void @llvm.lifetime.start.p0(i64, ptr)
69 declare void @llvm.lifetime.end.p0(i64, ptr)
71 ; CHECK-LABEL: define ptr @testLifetime(
73 ; CHECK-NEXT: %obj = alloca i8
74 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 8, ptr %obj)
75 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 8, ptr %obj)
76 ; CHECK-NEXT: ret ptr %call.i
78 define ptr @testLifetime(ptr %call.i) {
81 call void @llvm.lifetime.start.p0(i64 8, ptr %obj)
82 %0 = tail call ptr @llvm.objc.autoreleaseReturnValue(ptr %call.i) nounwind
83 call void @llvm.lifetime.end.p0(i64 8, ptr %obj)
84 %1 = tail call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %call.i) nounwind
88 ; 3) Dynamic alloca markers.
90 declare ptr @llvm.stacksave()
91 declare void @llvm.stackrestore(ptr)
93 ; CHECK-LABEL: define ptr @testStack(
95 ; CHECK-NEXT: %save = tail call ptr @llvm.stacksave.p0()
96 ; CHECK-NEXT: %obj = alloca i8, i8 %arg
97 ; CHECK-NEXT: call void @llvm.stackrestore.p0(ptr %save)
98 ; CHECK-NEXT: ret ptr %call.i
100 define ptr @testStack(ptr %call.i, i8 %arg) {
102 %save = tail call ptr @llvm.stacksave()
103 %obj = alloca i8, i8 %arg
104 %0 = tail call ptr @llvm.objc.autoreleaseReturnValue(ptr %call.i) nounwind
105 call void @llvm.stackrestore(ptr %save)
106 %1 = tail call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %call.i) nounwind