[objc-arc] Teach the ARC optimizer that objc_sync_enter/objc_sync_exit do not modify...
[oota-llvm.git] / test / Transforms / ObjCARC / gvn.ll
1 ; RUN: opt -S -basicaa -objc-arc-aa -gvn < %s | FileCheck %s
2
3 @x = common global i8* null, align 8
4
5 declare i8* @objc_retain(i8*)
6 declare i32 @objc_sync_start(i8*)
7 declare i32 @objc_sync_stop(i8*)
8
9 ; GVN should be able to eliminate this redundant load, with ARC-specific
10 ; alias analysis.
11
12 ; CHECK: define i8* @test0(i32 %n)
13 ; CHECK-NEXT: entry:
14 ; CHECK-NEXT: %s = load i8** @x
15 ; CHECK-NOT: load
16 ; CHECK: ret i8* %s
17 ; CHECK-NEXT: }
18 define i8* @test0(i32 %n) nounwind {
19 entry:
20   %s = load i8** @x
21   %0 = tail call i8* @objc_retain(i8* %s) nounwind
22   %t = load i8** @x
23   ret i8* %t
24 }
25
26 ; CHECK: define i8* @test1(i32 %n)
27 ; CHECK-NEXT: entry:
28 ; CHECK-NEXT: %s = load i8** @x
29 ; CHECK-NEXT: call i32 @objc_sync_start
30 ; CHECK-NEXT: call i32 @objc_sync_stop
31 ; CHECK-NEXT: ret i8* %s
32 ; CHECK-NEXT: }
33 define i8* @test1(i32 %n) nounwind {
34 entry:
35   %s = load i8** @x
36   %0 = call i32 @objc_sync_start(i8* %s)
37   %t = load i8** @x
38   %1 = call i32 @objc_sync_stop(i8* %s)
39   ret i8* %t
40 }