1 ; RUN: opt -passes=objc-arc -S < %s | FileCheck %s
4 %struct.__NSConstantString_tag = type { ptr, i32, ptr, i64 }
5 %struct.__block_descriptor = type { i64, i64 }
7 @__CFConstantStringClassReference = external global [0 x i32]
8 @.str = private unnamed_addr constant [4 x i8] c"abc\00", section "__TEXT,__cstring,cstring_literals", align 1
9 @.str1 = private unnamed_addr constant [4 x i8] c"def\00", section "__TEXT,__cstring,cstring_literals", align 1
10 @_unnamed_cfstring_ = private global %struct.__NSConstantString_tag { ptr @__CFConstantStringClassReference, i32 1992, ptr @.str, i64 3 }, section "__DATA,__cfstring", align 8 #0
11 @_unnamed_cfstring_.1 = private global %struct.__NSConstantString_tag { ptr @__CFConstantStringClassReference, i32 1992, ptr @.str1, i64 3 }, section "__DATA,__cfstring", align 8 #0
12 @_unnamed_cfstring_wo_attr = private global %struct.__NSConstantString_tag { ptr @__CFConstantStringClassReference, i32 1992, ptr @.str1, i64 3 }, section "__DATA,__cfstring", align 8
13 @_NSConcreteGlobalBlock = external global ptr
14 @.str.1 = private unnamed_addr constant [6 x i8] c"v8@?0\00", align 1
15 @"__block_descriptor_32_e5_v8@?0l" = linkonce_odr hidden unnamed_addr constant { i64, i64, ptr, ptr } { i64 0, i64 32, ptr @.str.1, ptr null }, align 8
16 @__block_literal_global = internal constant { ptr, i32, i32, ptr, ptr } { ptr @_NSConcreteGlobalBlock, i32 1342177280, i32 0, ptr @__globalBlock_block_invoke, ptr @"__block_descriptor_32_e5_v8@?0l" }, align 8 #0
18 ; CHECK-LABEL: define ptr @stringLiteral()
20 ; CHECK: ret ptr @_unnamed_cfstring_
22 define ptr @stringLiteral() {
23 %1 = tail call ptr @llvm.objc.retain(ptr @_unnamed_cfstring_)
24 %2 = call ptr @llvm.objc.autorelease(ptr @_unnamed_cfstring_)
25 ret ptr @_unnamed_cfstring_
28 ; CHECK-LABEL: define ptr @stringLiteral1()
29 ; CHECK-NEXT: call ptr @llvm.objc.retain(
30 ; CHECK-NEXT: call ptr @llvm.objc.autorelease(
33 define ptr @stringLiteral1() {
34 %1 = tail call ptr @llvm.objc.retain(ptr @_unnamed_cfstring_wo_attr)
35 %2 = call ptr @llvm.objc.autorelease(ptr @_unnamed_cfstring_wo_attr)
36 ret ptr @_unnamed_cfstring_wo_attr
39 ; CHECK-LABEL: define ptr @globalBlock()
41 ; CHECK-NEXT: ret ptr @__block_literal_global
43 define ptr @globalBlock() {
44 %1 = tail call ptr @llvm.objc.retainBlock(ptr @__block_literal_global)
45 %2 = tail call ptr @llvm.objc.retainBlock(ptr %1)
46 tail call void @llvm.objc.release(ptr %1)
47 %3 = tail call ptr @llvm.objc.autoreleaseReturnValue(ptr %2)
51 define internal void @__globalBlock_block_invoke(ptr nocapture readnone) {
56 ; CHECK: define ptr @test_conditional0(
57 ; CHECK: %[[PHI0:.*]] = phi ptr [ @_unnamed_cfstring_, %{{.*}} ], [ null, %{{.*}} ]
59 ; CHECK: %[[PHI1:.*]] = phi ptr [ @_unnamed_cfstring_, %{{.*}} ], [ %[[PHI0]], %{{.*}} ]
60 ; CHECK-NEXT: %[[PHI2:.*]] = phi ptr [ @_unnamed_cfstring_, %{{.*}} ], [ %{{.*}}, %{{.*}} ]
61 ; CHECK-NEXT: %[[V5:.*]] = tail call ptr @llvm.objc.autoreleaseReturnValue(ptr %[[PHI2]])
62 ; CHECK-NEXT: ret ptr %[[PHI2]]
64 define ptr @test_conditional0(i32 %i, ptr %b) {
66 %v0 = icmp eq i32 %i, 1
67 br i1 %v0, label %bb2, label %bb1
70 %v1 = icmp eq i32 %i, 2
71 br i1 %v1, label %bb2, label %return
74 %phi0 = phi ptr [ @_unnamed_cfstring_, %entry ], [ null, %bb1 ]
78 %phi1 = phi ptr [ @_unnamed_cfstring_, %bb1 ], [ %phi0, %bb2 ]
79 %phi2 = phi ptr [ @_unnamed_cfstring_, %bb1 ], [ %b, %bb2 ]
80 %v3 = tail call ptr @llvm.objc.autoreleaseReturnValue(ptr %phi1)
81 %v5 = tail call ptr @llvm.objc.autoreleaseReturnValue(ptr %phi2)
85 ; CHECK-LABEL: define void @test_conditional1(
86 ; CHECK-NOT: @llvm.objc
89 define void @test_conditional1(i32 %i) {
91 %v0 = add nsw i32 %i, -1
92 %c1 = icmp eq i32 %v0, 0
93 br i1 %c1, label %while.end, label %while.body
96 %v1 = phi i32 [ %v5, %if.end ], [ %v0, %entry ]
97 %v2 = phi ptr [ %v4, %if.end ], [ @_unnamed_cfstring_.1, %entry ]
98 %v3 = tail call ptr @llvm.objc.retain(ptr %v2)
99 %cmp = icmp eq i32 %v1, 2
100 br i1 %cmp, label %if.then, label %if.end
103 call void @llvm.objc.release(ptr %v2)
107 %v4 = phi ptr [ @_unnamed_cfstring_, %if.then ], [ %v2, %while.body ]
108 call void @llvm.objc.release(ptr %v2)
109 %v5 = add nsw i32 %v1, -1
110 %tobool = icmp eq i32 %v5, 0
111 br i1 %tobool, label %while.end, label %while.body
114 %v6 = phi ptr [ null, %entry ], [ %v4, %if.end ]
115 call void @llvm.objc.release(ptr %v6)
121 declare ptr @llvm.objc.retain(ptr) local_unnamed_addr
122 declare ptr @llvm.objc.autoreleaseReturnValue(ptr) local_unnamed_addr
123 declare ptr @llvm.objc.retainBlock(ptr) local_unnamed_addr
124 declare void @llvm.objc.release(ptr) local_unnamed_addr
125 declare ptr @llvm.objc.autorelease(ptr) local_unnamed_addr
127 attributes #0 = { "objc_arc_inert" }