blob: fda2ff4cbfcbf76bb4539cd2c7f45255ab4724e2 [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*)
7
8@x = external global i8*
9
10; CHECK: define void @test0(
11; CHECK: entry:
12; CHECK-NEXT: call void @objc_storeStrong(i8** @x, i8* %p) nounwind
13; CHECK-NEXT: ret void
14define void @test0(i8* %p) {
15entry:
16 %0 = tail call i8* @objc_retain(i8* %p) nounwind
17 %tmp = load i8** @x, align 8
18 store i8* %0, i8** @x, align 8
19 tail call void @objc_release(i8* %tmp) nounwind
20 ret void
21}
22
23; Don't do this if the load is volatile.
24
25; CHECK: define void @test1(i8* %p) {
26; CHECK-NEXT: entry:
27; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %p) nounwind
Eli Friedman02e737b2011-08-12 22:50:01 +000028; CHECK-NEXT: %tmp = load volatile i8** @x, align 8
John McCalld935e9c2011-06-15 23:37:01 +000029; CHECK-NEXT: store i8* %0, i8** @x, align 8
30; CHECK-NEXT: tail call void @objc_release(i8* %tmp) nounwind
31; CHECK-NEXT: ret void
32; CHECK-NEXT: }
33define void @test1(i8* %p) {
34entry:
35 %0 = tail call i8* @objc_retain(i8* %p) nounwind
Chris Lattner6a144a22011-11-27 06:54:59 +000036 %tmp = load volatile i8** @x, align 8
John McCalld935e9c2011-06-15 23:37:01 +000037 store i8* %0, i8** @x, align 8
38 tail call void @objc_release(i8* %tmp) nounwind
39 ret void
40}
41
42; Don't do this if the store is volatile.
43
44; CHECK: define void @test2(i8* %p) {
45; CHECK-NEXT: entry:
46; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %p) nounwind
47; CHECK-NEXT: %tmp = load i8** @x, align 8
Eli Friedman02e737b2011-08-12 22:50:01 +000048; CHECK-NEXT: store volatile i8* %0, i8** @x, align 8
John McCalld935e9c2011-06-15 23:37:01 +000049; CHECK-NEXT: tail call void @objc_release(i8* %tmp) nounwind
50; CHECK-NEXT: ret void
51; CHECK-NEXT: }
52define void @test2(i8* %p) {
53entry:
54 %0 = tail call i8* @objc_retain(i8* %p) nounwind
55 %tmp = load i8** @x, align 8
Chris Lattner6a144a22011-11-27 06:54:59 +000056 store volatile i8* %0, i8** @x, align 8
John McCalld935e9c2011-06-15 23:37:01 +000057 tail call void @objc_release(i8* %tmp) nounwind
58 ret void
59}