1 ; RUN: opt -objc-arc -S < %s | FileCheck %s
4 %struct.__NSConstantString_tag = type { i32*, i32, i8*, 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 { i32* getelementptr inbounds ([0 x i32], [0 x i32]* @__CFConstantStringClassReference, i32 0, i32 0), i32 1992, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i64 3 }, section "__DATA,__cfstring", align 8 #0
11 @_unnamed_cfstring_.1 = private global %struct.__NSConstantString_tag { i32* getelementptr inbounds ([0 x i32], [0 x i32]* @__CFConstantStringClassReference, i32 0, i32 0), i32 1992, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i32 0, i32 0), i64 3 }, section "__DATA,__cfstring", align 8 #0
12 @_unnamed_cfstring_wo_attr = private global %struct.__NSConstantString_tag { i32* getelementptr inbounds ([0 x i32], [0 x i32]* @__CFConstantStringClassReference, i32 0, i32 0), i32 1992, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str1, i32 0, i32 0), i64 3 }, section "__DATA,__cfstring", align 8
13 @_NSConcreteGlobalBlock = external global i8*
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, i8*, i8* } { i64 0, i64 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* null }, align 8
16 @__block_literal_global = internal constant { i8**, i32, i32, i8*, %struct.__block_descriptor* } { i8** @_NSConcreteGlobalBlock, i32 1342177280, i32 0, i8* bitcast (void (i8*)* @__globalBlock_block_invoke to i8*), %struct.__block_descriptor* bitcast ({ i64, i64, i8*, i8* }* @"__block_descriptor_32_e5_v8@?0l" to %struct.__block_descriptor*) }, align 8 #0
18 ; CHECK-LABEL: define %0* @stringLiteral()
20 ; CHECK: ret %0* bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_ to %0*)
22 define %0* @stringLiteral() {
23 %1 = tail call i8* @llvm.objc.retain(i8* bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_ to i8*))
24 %2 = call i8* @llvm.objc.autorelease(i8* bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_ to i8*))
25 ret %0* bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_ to %0*)
28 ; CHECK-LABEL: define %0* @stringLiteral1()
29 ; CHECK-NEXT: call i8* @llvm.objc.retain(
30 ; CHECK-NEXT: call i8* @llvm.objc.autorelease(
33 define %0* @stringLiteral1() {
34 %1 = tail call i8* @llvm.objc.retain(i8* bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_wo_attr to i8*))
35 %2 = call i8* @llvm.objc.autorelease(i8* bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_wo_attr to i8*))
36 ret %0* bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_wo_attr to %0*)
39 ; CHECK-LABEL: define void (...)* @globalBlock()
41 ; CHECK: %[[V1:.*]] = bitcast i8* bitcast ({ i8**, i32, i32, i8*, %struct.__block_descriptor* }* @__block_literal_global to i8*) to void (...)*
42 ; CHECK-NEXT: ret void (...)* %[[V1]]
44 define void (...)* @globalBlock() {
45 %1 = tail call i8* @llvm.objc.retainBlock(i8* bitcast ({ i8**, i32, i32, i8*, %struct.__block_descriptor* }* @__block_literal_global to i8*))
46 %2 = tail call i8* @llvm.objc.retainBlock(i8* %1)
47 %3 = bitcast i8* %2 to void (...)*
48 tail call void @llvm.objc.release(i8* %1)
49 %4 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %2)
53 define internal void @__globalBlock_block_invoke(i8* nocapture readnone) {
58 ; CHECK: define %[[V0:.*]]* @test_conditional0(
59 ; CHECK: %[[PHI0:.*]] = phi %[[V0]]* [ bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_ to %[[V0]]*), %{{.*}} ], [ null, %{{.*}} ]
61 ; CHECK: %[[PHI1:.*]] = phi %[[V0]]* [ bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_ to %[[V0]]*), %{{.*}} ], [ %[[PHI0]], %{{.*}} ]
62 ; CHECK-NEXT: %[[PHI2:.*]] = phi %[[V0]]* [ bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_ to %[[V0]]*), %{{.*}} ], [ %{{.*}}, %{{.*}} ]
63 ; CHECK-NEXT: %[[V2:.*]] = bitcast %[[V0]]* %[[PHI1]] to i8*
64 ; CHECK-NEXT: %[[V4:.*]] = bitcast %[[V0]]* %[[PHI2]] to i8*
65 ; CHECK-NEXT: %[[V5:.*]] = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %[[V4]])
66 ; CHECK-NEXT: ret %[[V0]]* %[[PHI2]]
68 define %0* @test_conditional0(i32 %i, %0* %b) {
70 %v0 = icmp eq i32 %i, 1
71 br i1 %v0, label %bb2, label %bb1
74 %v1 = icmp eq i32 %i, 2
75 br i1 %v1, label %bb2, label %return
78 %phi0 = phi %0* [ bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_ to %0*), %entry ], [ null, %bb1 ]
82 %phi1 = phi %0* [ bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_ to %0*), %bb1 ], [ %phi0, %bb2 ]
83 %phi2 = phi %0* [ bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_ to %0*), %bb1 ], [ %b, %bb2 ]
84 %v2 = bitcast %0* %phi1 to i8*
85 %v3 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %v2)
86 %v4 = bitcast %0* %phi2 to i8*
87 %v5 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %v4)
91 ; CHECK-LABEL: define void @test_conditional1(
92 ; CHECK-NOT: @llvm.objc
95 define void @test_conditional1(i32 %i) {
97 %v0 = add nsw i32 %i, -1
98 %c1 = icmp eq i32 %v0, 0
99 br i1 %c1, label %while.end, label %while.body
102 %v1 = phi i32 [ %v5, %if.end ], [ %v0, %entry ]
103 %v2 = phi i8* [ %v4, %if.end ], [ bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_.1 to i8*), %entry ]
104 %v3 = tail call i8* @llvm.objc.retain(i8* %v2)
105 %cmp = icmp eq i32 %v1, 2
106 br i1 %cmp, label %if.then, label %if.end
109 call void @llvm.objc.release(i8* %v2)
113 %v4 = phi i8* [ bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_ to i8*), %if.then ], [ %v2, %while.body ]
114 call void @llvm.objc.release(i8* %v2)
115 %v5 = add nsw i32 %v1, -1
116 %tobool = icmp eq i32 %v5, 0
117 br i1 %tobool, label %while.end, label %while.body
120 %v6 = phi i8* [ null, %entry ], [ %v4, %if.end ]
121 call void @llvm.objc.release(i8* %v6)
127 declare i8* @llvm.objc.retain(i8*) local_unnamed_addr
128 declare i8* @llvm.objc.autoreleaseReturnValue(i8*) local_unnamed_addr
129 declare i8* @llvm.objc.retainBlock(i8*) local_unnamed_addr
130 declare void @llvm.objc.release(i8*) local_unnamed_addr
131 declare i8* @llvm.objc.autorelease(i8*) local_unnamed_addr
133 attributes #0 = { "objc_arc_inert" }