1 ; RUN: opt -passes=objc-arc -S < %s | FileCheck %s
3 declare void @alterRefCount()
5 declare void @readOnlyFunc(ptr, ptr)
7 @g0 = global ptr null, align 8
9 ; Check that ARC optimizer doesn't reverse the order of the retain call and the
10 ; release call when there are debug instructions.
12 ; CHECK: call ptr @llvm.objc.retain(ptr %x)
13 ; CHECK: call void @llvm.objc.release(ptr %x)
15 define i32 @test(ptr %x, ptr %y, i8 %z, i32 %i) {
16 %i.addr = alloca i32, align 4
17 store i32 %i, ptr %i.addr, align 4
18 %v1 = tail call ptr @llvm.objc.retain(ptr %x)
20 call void @llvm.dbg.declare(metadata ptr %i.addr, metadata !9, metadata !DIExpression()), !dbg !10
21 call void @alterRefCount()
22 tail call void @llvm.objc.release(ptr %x)
26 ; ARC optimizer shouldn't move the release call, which is a precise release call
27 ; past the call to @alterRefCount.
29 ; CHECK-LABEL: define void @test2(
30 ; CHECK: call void @alterRefCount(
31 ; CHECK: call void @llvm.objc.release(
33 define void @test2() {
34 %v0 = load ptr, ptr @g0, align 8
35 %v1 = tail call ptr @llvm.objc.retain(ptr %v0)
36 tail call void @use(ptr %v0)
37 tail call void @alterRefCount()
38 tail call void @llvm.objc.release(ptr %v0)
42 ; Check that code motion is disabled in @test3 and @test4.
43 ; Previously, ARC optimizer would move the release past the retain.
46 ; call void @readOnlyFunc(ptr %obj, ptr null)
47 ; call void @llvm.objc.release(ptr %obj) #1, !clang.imprecise_release !2
49 ; %2 = tail call ptr @llvm.objc.retain(ptr %obj)
51 ; Ideally, the retain/release pairs in BB if.then should be removed.
53 define void @test3(ptr %obj, i1 %cond) {
54 ; CHECK-LABEL: @test3(
55 ; CHECK-NEXT: [[TMP2:%.*]] = tail call ptr @llvm.objc.retain(ptr [[OBJ:%.*]])
56 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
58 ; CHECK-NEXT: call void @readOnlyFunc(ptr [[OBJ]], ptr null)
59 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 1, 2
60 ; CHECK-NEXT: call void @alterRefCount()
61 ; CHECK-NEXT: br label [[JOIN:%.*]]
63 ; CHECK-NEXT: call void @alterRefCount()
64 ; CHECK-NEXT: call void @use(ptr [[OBJ]])
65 ; CHECK-NEXT: br label [[JOIN]]
67 ; CHECK-NEXT: call void @llvm.objc.release(ptr [[OBJ]]) {{.*}}, !clang.imprecise_release !2
68 ; CHECK-NEXT: ret void
70 %v0 = call ptr @llvm.objc.retain(ptr %obj)
71 br i1 %cond, label %if.then, label %if.else
74 call void @readOnlyFunc(ptr %obj, ptr null) #0
76 call void @alterRefCount()
80 call void @alterRefCount()
81 call void @use(ptr %obj)
85 call void @llvm.objc.release(ptr %obj), !clang.imprecise_release !9
89 define void @test4(ptr %obj0, ptr %obj1, i1 %cond) {
90 ; CHECK-LABEL: @test4(
91 ; CHECK-NEXT: [[TMP3:%.*]] = tail call ptr @llvm.objc.retain(ptr [[OBJ0:%.*]])
92 ; CHECK-NEXT: [[TMP2:%.*]] = tail call ptr @llvm.objc.retain(ptr [[OBJ1:%.*]])
93 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
95 ; CHECK-NEXT: call void @readOnlyFunc(ptr [[OBJ0]], ptr [[OBJ1]])
96 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 1, 2
97 ; CHECK-NEXT: call void @alterRefCount()
98 ; CHECK-NEXT: br label [[JOIN:%.*]]
100 ; CHECK-NEXT: call void @alterRefCount()
101 ; CHECK-NEXT: call void @use(ptr [[OBJ0]])
102 ; CHECK-NEXT: call void @use(ptr [[OBJ1]])
103 ; CHECK-NEXT: br label [[JOIN]]
105 ; CHECK-NEXT: call void @llvm.objc.release(ptr [[OBJ0]]) {{.*}}, !clang.imprecise_release !2
106 ; CHECK-NEXT: call void @llvm.objc.release(ptr [[OBJ1]]) {{.*}}, !clang.imprecise_release !2
107 ; CHECK-NEXT: ret void
109 %v0 = call ptr @llvm.objc.retain(ptr %obj0)
110 %v1 = call ptr @llvm.objc.retain(ptr %obj1)
111 br i1 %cond, label %if.then, label %if.else
114 call void @readOnlyFunc(ptr %obj0, ptr %obj1) #0
116 call void @alterRefCount()
120 call void @alterRefCount()
121 call void @use(ptr %obj0)
122 call void @use(ptr %obj1)
126 call void @llvm.objc.release(ptr %obj0), !clang.imprecise_release !9
127 call void @llvm.objc.release(ptr %obj1), !clang.imprecise_release !9
131 ; In this test, insertion points for the retain and release calls that could be
132 ; eliminated are in different blocks (bb1 and if.then).
134 define void @test5(ptr %obj, i1 %cond0, i1 %cond1) {
135 ; CHECK-LABEL: @test5(
136 ; CHECK-NEXT: [[V0:%.*]] = tail call ptr @llvm.objc.retain(ptr [[OBJ:%.*]])
137 ; CHECK-NEXT: br i1 [[COND0:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
139 ; CHECK-NEXT: call void @readOnlyFunc(ptr [[OBJ]], ptr null)
140 ; CHECK-NEXT: br i1 [[COND1:%.*]], label [[IF_THEN2:%.*]], label [[IF_ELSE2:%.*]]
142 ; CHECK-NEXT: br label [[BB1:%.*]]
144 ; CHECK-NEXT: br label [[BB1]]
146 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 1, 2
147 ; CHECK-NEXT: call void @alterRefCount()
148 ; CHECK-NEXT: br label [[JOIN:%.*]]
150 ; CHECK-NEXT: call void @alterRefCount()
151 ; CHECK-NEXT: call void @use(ptr [[OBJ]])
152 ; CHECK-NEXT: br label [[JOIN]]
154 ; CHECK-NEXT: call void @llvm.objc.release(ptr [[OBJ]])
155 ; CHECK-NEXT: ret void
157 %v0 = call ptr @llvm.objc.retain(ptr %obj)
158 br i1 %cond0, label %if.then, label %if.else
161 call void @readOnlyFunc(ptr %obj, ptr null) #0
162 br i1 %cond1, label %if.then2, label %if.else2
172 call void @alterRefCount()
176 call void @alterRefCount()
177 call void @use(ptr %obj)
181 call void @llvm.objc.release(ptr %obj), !clang.imprecise_release !9
185 declare void @llvm.dbg.declare(metadata, metadata, metadata)
186 declare ptr @llvm.objc.retain(ptr) local_unnamed_addr
187 declare void @llvm.objc.release(ptr) local_unnamed_addr
189 attributes #0 = { readonly }
191 !llvm.module.flags = !{!0, !1}
193 !0 = !{i32 2, !"Dwarf Version", i32 4}
194 !1 = !{i32 2, !"Debug Info Version", i32 3}
195 !2 = !DILocalVariable(name: "i", arg: 1, scope: !3, file: !4, line: 1, type: !7)
196 !3 = distinct !DISubprogram(name: "test", scope: !4, file: !4, line: 1, type: !5, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !8, retainedNodes: !9)
197 !4 = !DIFile(filename: "test.m", directory: "dir")
198 !5 = !DISubroutineType(types: !6)
200 !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
201 !8 = distinct !DICompileUnit(language: DW_LANG_ObjC, file: !4, isOptimized: false, runtimeVersion: 2, emissionKind: FullDebug, enums: !9, nameTableKind: None)
203 !10 = !DILocation(line: 1, column: 14, scope: !3)