1 ; RUN: opt -S -objc-arc < %s | FileCheck %s
3 declare void @use_pointer(i8*)
4 declare i8* @returner()
5 declare i8* @llvm.objc.retain(i8*)
6 declare i8* @llvm.objc.autoreleaseReturnValue(i8*)
7 declare i8* @llvm.objc.retainAutoreleasedReturnValue(i8*)
9 ; Clean up residue left behind after inlining.
11 ; CHECK-LABEL: define void @test0(
13 ; CHECK-NEXT: ret void
15 define void @test0(i8* %call.i) {
17 %0 = tail call i8* @llvm.objc.retain(i8* %call.i) nounwind
18 %1 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %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(i8* %call.i) {
30 %0 = tail call i8* @llvm.objc.retain(i8* %call.i) nounwind
31 %1 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %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(i8* %p)
40 ; CHECK-NEXT: ret void
42 define void @test24(i8* %p) {
44 call i8* @llvm.objc.autoreleaseReturnValue(i8* %p) nounwind
45 call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %p) nounwind
46 call void @use_pointer(i8* %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 i8* @testNoop(
57 ; CHECK-NEXT: %noop0 = bitcast i8* %call.i to i64*
58 ; CHECK-NEXT: %noop1 = getelementptr i8, i8* %call.i, i32 0
59 ; CHECK-NEXT: ret i8* %call.i
61 define i8* @testNoop(i8* %call.i) {
63 %0 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %call.i) nounwind
64 %noop0 = bitcast i8* %call.i to i64*
65 %noop1 = getelementptr i8, i8* %call.i, i32 0
66 %1 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %call.i) nounwind
70 ; 2) Lifetime markers.
72 declare void @llvm.lifetime.start.p0i8(i64, i8*)
73 declare void @llvm.lifetime.end.p0i8(i64, i8*)
75 ; CHECK-LABEL: define i8* @testLifetime(
77 ; CHECK-NEXT: %obj = alloca i8
78 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* %obj)
79 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* %obj)
80 ; CHECK-NEXT: ret i8* %call.i
82 define i8* @testLifetime(i8* %call.i) {
85 call void @llvm.lifetime.start.p0i8(i64 8, i8* %obj)
86 %0 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %call.i) nounwind
87 call void @llvm.lifetime.end.p0i8(i64 8, i8* %obj)
88 %1 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %call.i) nounwind
92 ; 3) Dynamic alloca markers.
94 declare i8* @llvm.stacksave()
95 declare void @llvm.stackrestore(i8*)
97 ; CHECK-LABEL: define i8* @testStack(
99 ; CHECK-NEXT: %save = tail call i8* @llvm.stacksave()
100 ; CHECK-NEXT: %obj = alloca i8, i8 %arg
101 ; CHECK-NEXT: call void @llvm.stackrestore(i8* %save)
102 ; CHECK-NEXT: ret i8* %call.i
104 define i8* @testStack(i8* %call.i, i8 %arg) {
106 %save = tail call i8* @llvm.stacksave()
107 %obj = alloca i8, i8 %arg
108 %0 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %call.i) nounwind
109 call void @llvm.stackrestore(i8* %save)
110 %1 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %call.i) nounwind