1 ; RUN: opt -objc-arc -S < %s | FileCheck %s
3 declare void @alterRefCount()
5 declare void @readOnlyFunc(i8*, i8*)
7 @g0 = global i8* 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 i8* @llvm.objc.retain(i8* %x)
13 ; CHECK: call void @llvm.objc.release(i8* %x)
15 define i32 @test(i8* %x, i8* %y, i8 %z, i32 %i) {
16 %i.addr = alloca i32, align 4
17 store i32 %i, i32* %i.addr, align 4
18 %v1 = tail call i8* @llvm.objc.retain(i8* %x)
20 call void @llvm.dbg.declare(metadata i32* %i.addr, metadata !9, metadata !DIExpression()), !dbg !10
21 call void @alterRefCount()
22 tail call void @llvm.objc.release(i8* %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 i8*, i8** @g0, align 8
35 %v1 = tail call i8* @llvm.objc.retain(i8* %v0)
36 tail call void @use(i8* %v0)
37 tail call void @alterRefCount()
38 tail call void @llvm.objc.release(i8* %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(i8* %obj, i8* null)
47 ; call void @llvm.objc.release(i8* %obj) #1, !clang.imprecise_release !2
49 ; %2 = tail call i8* @llvm.objc.retain(i8* %obj)
51 ; Ideally, the retain/release pairs in BB if.then should be removed.
53 define void @test3(i8* %obj, i1 %cond) {
54 ; CHECK-LABEL: @test3(
55 ; CHECK-NEXT: [[TMP2:%.*]] = tail call i8* @llvm.objc.retain(i8* [[OBJ:%.*]])
56 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
58 ; CHECK-NEXT: call void @readOnlyFunc(i8* [[OBJ]], i8* 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(i8* [[OBJ]])
65 ; CHECK-NEXT: br label [[JOIN]]
67 ; CHECK-NEXT: call void @llvm.objc.release(i8* [[OBJ]]) {{.*}}, !clang.imprecise_release !2
68 ; CHECK-NEXT: ret void
70 %v0 = call i8* @llvm.objc.retain(i8* %obj)
71 br i1 %cond, label %if.then, label %if.else
74 call void @readOnlyFunc(i8* %obj, i8* null) #0
76 call void @alterRefCount()
80 call void @alterRefCount()
81 call void @use(i8* %obj)
85 call void @llvm.objc.release(i8* %obj), !clang.imprecise_release !9
89 define void @test4(i8* %obj0, i8* %obj1, i1 %cond) {
90 ; CHECK-LABEL: @test4(
91 ; CHECK-NEXT: [[TMP3:%.*]] = tail call i8* @llvm.objc.retain(i8* [[OBJ0:%.*]])
92 ; CHECK-NEXT: [[TMP2:%.*]] = tail call i8* @llvm.objc.retain(i8* [[OBJ1:%.*]])
93 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
95 ; CHECK-NEXT: call void @readOnlyFunc(i8* [[OBJ0]], i8* [[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(i8* [[OBJ0]])
102 ; CHECK-NEXT: call void @use(i8* [[OBJ1]])
103 ; CHECK-NEXT: br label [[JOIN]]
105 ; CHECK-NEXT: call void @llvm.objc.release(i8* [[OBJ0]]) {{.*}}, !clang.imprecise_release !2
106 ; CHECK-NEXT: call void @llvm.objc.release(i8* [[OBJ1]]) {{.*}}, !clang.imprecise_release !2
107 ; CHECK-NEXT: ret void
109 %v0 = call i8* @llvm.objc.retain(i8* %obj0)
110 %v1 = call i8* @llvm.objc.retain(i8* %obj1)
111 br i1 %cond, label %if.then, label %if.else
114 call void @readOnlyFunc(i8* %obj0, i8* %obj1) #0
116 call void @alterRefCount()
120 call void @alterRefCount()
121 call void @use(i8* %obj0)
122 call void @use(i8* %obj1)
126 call void @llvm.objc.release(i8* %obj0), !clang.imprecise_release !9
127 call void @llvm.objc.release(i8* %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(i8* %obj, i1 %cond0, i1 %cond1) {
135 ; CHECK-LABEL: @test5(
136 ; CHECK-NEXT: [[V0:%.*]] = tail call i8* @llvm.objc.retain(i8* [[OBJ:%.*]])
137 ; CHECK-NEXT: br i1 [[COND0:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
139 ; CHECK-NEXT: call void @readOnlyFunc(i8* [[OBJ]], i8* 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(i8* [[OBJ]])
152 ; CHECK-NEXT: br label [[JOIN]]
154 ; CHECK-NEXT: call void @llvm.objc.release(i8* [[OBJ]])
155 ; CHECK-NEXT: ret void
157 %v0 = call i8* @llvm.objc.retain(i8* %obj)
158 br i1 %cond0, label %if.then, label %if.else
161 call void @readOnlyFunc(i8* %obj, i8* null) #0
162 br i1 %cond1, label %if.then2, label %if.else2
172 call void @alterRefCount()
176 call void @alterRefCount()
177 call void @use(i8* %obj)
181 call void @llvm.objc.release(i8* %obj), !clang.imprecise_release !9
185 declare void @llvm.dbg.declare(metadata, metadata, metadata)
186 declare i8* @llvm.objc.retain(i8*) local_unnamed_addr
187 declare void @llvm.objc.release(i8*) 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)