blob: 50a2d9756648d68823aebaa4b8e4af91e2c50bf2 [file] [log] [blame]
John McCalld935e9c2011-06-15 23:37:01 +00001; RUN: opt -objc-arc-contract -S < %s | FileCheck %s
2
3target datalayout = "e-p:64:64:64"
4
5declare i8* @objc_retain(i8*)
6declare void @objc_release(i8*)
Dan Gohman61708d32012-05-08 23:34:08 +00007declare void @use_pointer(i8*)
John McCalld935e9c2011-06-15 23:37:01 +00008
9@x = external global i8*
10
Stephen Lina76289a2013-07-14 01:50:49 +000011; CHECK-LABEL: define void @test0(
John McCalld935e9c2011-06-15 23:37:01 +000012; CHECK: entry:
Bill Wendlinga0323742013-02-22 09:09:42 +000013; CHECK-NEXT: tail call void @objc_storeStrong(i8** @x, i8* %p) [[NUW:#[0-9]+]]
John McCalld935e9c2011-06-15 23:37:01 +000014; CHECK-NEXT: ret void
Michael Gottesmanb33b6cb2013-04-27 05:25:54 +000015; CHECK-NEXT: }
John McCalld935e9c2011-06-15 23:37:01 +000016define void @test0(i8* %p) {
17entry:
18 %0 = tail call i8* @objc_retain(i8* %p) nounwind
19 %tmp = load i8** @x, align 8
20 store i8* %0, i8** @x, align 8
21 tail call void @objc_release(i8* %tmp) nounwind
22 ret void
23}
24
25; Don't do this if the load is volatile.
26
27; CHECK: define void @test1(i8* %p) {
28; CHECK-NEXT: entry:
Bill Wendlinga0323742013-02-22 09:09:42 +000029; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %p) [[NUW]]
Eli Friedman02e737b2011-08-12 22:50:01 +000030; CHECK-NEXT: %tmp = load volatile i8** @x, align 8
John McCalld935e9c2011-06-15 23:37:01 +000031; CHECK-NEXT: store i8* %0, i8** @x, align 8
Bill Wendlinga0323742013-02-22 09:09:42 +000032; CHECK-NEXT: tail call void @objc_release(i8* %tmp) [[NUW]]
John McCalld935e9c2011-06-15 23:37:01 +000033; CHECK-NEXT: ret void
34; CHECK-NEXT: }
35define void @test1(i8* %p) {
36entry:
37 %0 = tail call i8* @objc_retain(i8* %p) nounwind
Chris Lattner6a144a22011-11-27 06:54:59 +000038 %tmp = load volatile i8** @x, align 8
John McCalld935e9c2011-06-15 23:37:01 +000039 store i8* %0, i8** @x, align 8
40 tail call void @objc_release(i8* %tmp) nounwind
41 ret void
42}
43
44; Don't do this if the store is volatile.
45
46; CHECK: define void @test2(i8* %p) {
47; CHECK-NEXT: entry:
Bill Wendlinga0323742013-02-22 09:09:42 +000048; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %p) [[NUW]]
John McCalld935e9c2011-06-15 23:37:01 +000049; CHECK-NEXT: %tmp = load i8** @x, align 8
Eli Friedman02e737b2011-08-12 22:50:01 +000050; CHECK-NEXT: store volatile i8* %0, i8** @x, align 8
Bill Wendlinga0323742013-02-22 09:09:42 +000051; CHECK-NEXT: tail call void @objc_release(i8* %tmp) [[NUW]]
John McCalld935e9c2011-06-15 23:37:01 +000052; CHECK-NEXT: ret void
53; CHECK-NEXT: }
54define void @test2(i8* %p) {
55entry:
56 %0 = tail call i8* @objc_retain(i8* %p) nounwind
57 %tmp = load i8** @x, align 8
Chris Lattner6a144a22011-11-27 06:54:59 +000058 store volatile i8* %0, i8** @x, align 8
John McCalld935e9c2011-06-15 23:37:01 +000059 tail call void @objc_release(i8* %tmp) nounwind
60 ret void
61}
Dan Gohman61708d32012-05-08 23:34:08 +000062
Filipe Cabecinhas5c433052012-05-09 14:43:50 +000063; Don't do this if there's a use of the old pointer value between the store
Dan Gohman61708d32012-05-08 23:34:08 +000064; and the release.
65
66; CHECK: define void @test3(i8* %newValue) {
67; CHECK-NEXT: entry:
Bill Wendlinga0323742013-02-22 09:09:42 +000068; CHECK-NEXT: %x0 = tail call i8* @objc_retain(i8* %newValue) [[NUW]]
Dan Gohman61708d32012-05-08 23:34:08 +000069; CHECK-NEXT: %x1 = load i8** @x, align 8
70; CHECK-NEXT: store i8* %x0, i8** @x, align 8
71; CHECK-NEXT: tail call void @use_pointer(i8* %x1), !clang.arc.no_objc_arc_exceptions !0
Bill Wendlinga0323742013-02-22 09:09:42 +000072; CHECK-NEXT: tail call void @objc_release(i8* %x1) [[NUW]], !clang.imprecise_release !0
Dan Gohman61708d32012-05-08 23:34:08 +000073; CHECK-NEXT: ret void
74; CHECK-NEXT: }
75define void @test3(i8* %newValue) {
76entry:
77 %x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
78 %x1 = load i8** @x, align 8
79 store i8* %newValue, i8** @x, align 8
80 tail call void @use_pointer(i8* %x1), !clang.arc.no_objc_arc_exceptions !0
81 tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
82 ret void
83}
84
85; Like test3, but with an icmp use instead of a call, for good measure.
86
87; CHECK: define i1 @test4(i8* %newValue, i8* %foo) {
88; CHECK-NEXT: entry:
Bill Wendlinga0323742013-02-22 09:09:42 +000089; CHECK-NEXT: %x0 = tail call i8* @objc_retain(i8* %newValue) [[NUW]]
Dan Gohman61708d32012-05-08 23:34:08 +000090; CHECK-NEXT: %x1 = load i8** @x, align 8
91; CHECK-NEXT: store i8* %x0, i8** @x, align 8
92; CHECK-NEXT: %t = icmp eq i8* %x1, %foo
Bill Wendlinga0323742013-02-22 09:09:42 +000093; CHECK-NEXT: tail call void @objc_release(i8* %x1) [[NUW]], !clang.imprecise_release !0
Dan Gohman61708d32012-05-08 23:34:08 +000094; CHECK-NEXT: ret i1 %t
95; CHECK-NEXT: }
96define i1 @test4(i8* %newValue, i8* %foo) {
97entry:
98 %x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
99 %x1 = load i8** @x, align 8
100 store i8* %newValue, i8** @x, align 8
101 %t = icmp eq i8* %x1, %foo
102 tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
103 ret i1 %t
104}
105
106; Do form an objc_storeStrong here, because the use is before the store.
107
108; CHECK: define i1 @test5(i8* %newValue, i8* %foo) {
109; CHECK: %t = icmp eq i8* %x1, %foo
Bill Wendlinga0323742013-02-22 09:09:42 +0000110; CHECK: tail call void @objc_storeStrong(i8** @x, i8* %newValue) [[NUW]]
Michael Gottesmanb33b6cb2013-04-27 05:25:54 +0000111; CHECK: }
Dan Gohman61708d32012-05-08 23:34:08 +0000112define i1 @test5(i8* %newValue, i8* %foo) {
113entry:
114 %x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
115 %x1 = load i8** @x, align 8
116 %t = icmp eq i8* %x1, %foo
117 store i8* %newValue, i8** @x, align 8
118 tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
119 ret i1 %t
120}
121
122; Like test5, but the release is before the store.
123
124; CHECK: define i1 @test6(i8* %newValue, i8* %foo) {
125; CHECK: %t = icmp eq i8* %x1, %foo
Bill Wendlinga0323742013-02-22 09:09:42 +0000126; CHECK: tail call void @objc_storeStrong(i8** @x, i8* %newValue) [[NUW]]
Michael Gottesmanb33b6cb2013-04-27 05:25:54 +0000127; CHECK: }
Dan Gohman61708d32012-05-08 23:34:08 +0000128define i1 @test6(i8* %newValue, i8* %foo) {
129entry:
130 %x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
131 %x1 = load i8** @x, align 8
132 tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
133 %t = icmp eq i8* %x1, %foo
134 store i8* %newValue, i8** @x, align 8
135 ret i1 %t
136}
137
Dan Gohmanf8b19d02012-05-09 23:08:33 +0000138; Like test0, but there's no store, so don't form an objc_storeStrong.
139
Stephen Lina76289a2013-07-14 01:50:49 +0000140; CHECK-LABEL: define void @test7(
Dan Gohmanf8b19d02012-05-09 23:08:33 +0000141; CHECK-NEXT: entry:
Bill Wendlinga0323742013-02-22 09:09:42 +0000142; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %p) [[NUW]]
Dan Gohmanf8b19d02012-05-09 23:08:33 +0000143; CHECK-NEXT: %tmp = load i8** @x, align 8
Bill Wendlinga0323742013-02-22 09:09:42 +0000144; CHECK-NEXT: tail call void @objc_release(i8* %tmp) [[NUW]]
Dan Gohmanf8b19d02012-05-09 23:08:33 +0000145; CHECK-NEXT: ret void
146; CHECK-NEXT: }
147define void @test7(i8* %p) {
148entry:
149 %0 = tail call i8* @objc_retain(i8* %p) nounwind
150 %tmp = load i8** @x, align 8
151 tail call void @objc_release(i8* %tmp) nounwind
152 ret void
153}
154
155; Like test0, but there's no retain, so don't form an objc_storeStrong.
156
Stephen Lina76289a2013-07-14 01:50:49 +0000157; CHECK-LABEL: define void @test8(
Dan Gohmanf8b19d02012-05-09 23:08:33 +0000158; CHECK-NEXT: entry:
159; CHECK-NEXT: %tmp = load i8** @x, align 8
160; CHECK-NEXT: store i8* %p, i8** @x, align 8
Bill Wendlinga0323742013-02-22 09:09:42 +0000161; CHECK-NEXT: tail call void @objc_release(i8* %tmp) [[NUW]]
Dan Gohmanf8b19d02012-05-09 23:08:33 +0000162; CHECK-NEXT: ret void
163; CHECK-NEXT: }
164define void @test8(i8* %p) {
165entry:
166 %tmp = load i8** @x, align 8
167 store i8* %p, i8** @x, align 8
168 tail call void @objc_release(i8* %tmp) nounwind
169 ret void
170}
171
Dan Gohman61708d32012-05-08 23:34:08 +0000172!0 = metadata !{}
Bill Wendlinga0323742013-02-22 09:09:42 +0000173
174; CHECK: attributes [[NUW]] = { nounwind }