Add tests for two types of traps that escape analysis
[oota-llvm.git] / test / Transforms / FunctionAttrs / 2008-12-31-NoCapture.ll
1 ; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | not grep {nocapture *%%q}
2 ; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep {nocapture *%%p} | count 3
3 @g = global i32* null           ; <i32**> [#uses=1]
4
5 define i32* @c1(i32* %q) {
6         ret i32* %q
7 }
8
9 define void @c2(i32* %q) {
10         store i32* %q, i32** @g
11         ret void
12 }
13
14 define void @c3(i32* %q) {
15         call void @c2(i32* %q)
16         ret void
17 }
18
19 define i1 @c4(i32* %q, i32 %bitno) {
20         %tmp = ptrtoint i32* %q to i32
21         %tmp2 = lshr i32 %tmp, %bitno
22         %bit = trunc i32 %tmp2 to i1
23         br i1 %bit, label %l1, label %l0
24 l0:
25         ret i1 0 ; escaping value not caught by def-use chaining.
26 l1:
27         ret i1 1 ; escaping value not caught by def-use chaining.
28 }
29
30 @lookup_table = global [2 x i1] [ i1 0, i1 1 ]
31
32 define i1 @c5(i32* %q, i32 %bitno) {
33         %tmp = ptrtoint i32* %q to i32
34         %tmp2 = lshr i32 %tmp, %bitno
35         %bit = and i32 %tmp2, 1
36         ; subtle escape mechanism follows
37         %lookup = getelementptr [2 x i1]* @lookup_table, i32 0, i32 %bit
38         %val = load i1* %lookup
39         ret i1 %val
40 }
41
42 define i32 @nc1(i32* %q, i32* %p, i1 %b) {
43 e:
44         br label %l
45 l:
46         %x = phi i32* [ %p, %e ]
47         %y = phi i32* [ %q, %e ]
48         %tmp = bitcast i32* %x to i32*          ; <i32*> [#uses=2]
49         %tmp2 = select i1 %b, i32* %tmp, i32* %y
50         %val = load i32* %tmp2          ; <i32> [#uses=1]
51         store i32 0, i32* %tmp
52         store i32* %y, i32** @g
53         ret i32 %val
54 }
55
56 define void @nc2(i32* %p, i32* %q) {
57         %1 = call i32 @nc1(i32* %q, i32* %p, i1 0)              ; <i32> [#uses=0]
58         ret void
59 }
60
61 define void @nc3(void ()* %p) {
62         call void %p()
63         ret void
64 }