blob: 39a64e6d36cc42645ca77abe5e859cc00eddc7fc [file] [log] [blame]
Duncan Sands10109412008-12-31 20:21:34 +00001; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | not grep {nocapture *%%q}
Nick Lewycky84396532009-01-02 03:52:27 +00002; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep {nocapture *%%p} | count 6
Duncan Sands9e89ba32008-12-31 16:14:43 +00003@g = global i32* null ; <i32**> [#uses=1]
4
Duncan Sands10109412008-12-31 20:21:34 +00005define i32* @c1(i32* %q) {
6 ret i32* %q
Duncan Sands9e89ba32008-12-31 16:14:43 +00007}
8
Duncan Sands10109412008-12-31 20:21:34 +00009define void @c2(i32* %q) {
10 store i32* %q, i32** @g
Duncan Sands9e89ba32008-12-31 16:14:43 +000011 ret void
12}
13
Duncan Sands10109412008-12-31 20:21:34 +000014define void @c3(i32* %q) {
15 call void @c2(i32* %q)
Duncan Sands9e89ba32008-12-31 16:14:43 +000016 ret void
17}
18
Duncan Sands29ab02b2009-01-02 00:55:51 +000019define 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
24l0:
25 ret i1 0 ; escaping value not caught by def-use chaining.
26l1:
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
32define 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
Mike Stumpfe095f32009-05-04 18:40:41 +000042declare void @throw_if_bit_set(i8*, i8) readonly
43define i1 @c6(i8* %q, i8 %bit) {
44 invoke void @throw_if_bit_set(i8* %q, i8 %bit)
45 to label %ret0 unwind label %ret1
46ret0:
47 ret i1 0
48ret1:
49 ret i1 1
50}
51
Duncan Sands19784262009-05-07 18:08:34 +000052define i1* @lookup_bit(i32* %q, i32 %bitno) readnone nounwind {
53 %tmp = ptrtoint i32* %q to i32
54 %tmp2 = lshr i32 %tmp, %bitno
55 %bit = and i32 %tmp2, 1
56 %lookup = getelementptr [2 x i1]* @lookup_table, i32 0, i32 %bit
57 ret i1* %lookup
58}
59
60define i1 @c7(i32* %q, i32 %bitno) {
61 %ptr = call i1* @lookup_bit(i32* %q, i32 %bitno)
62 %val = load i1* %ptr
63 ret i1 %val
64}
65
66
Duncan Sands10109412008-12-31 20:21:34 +000067define i32 @nc1(i32* %q, i32* %p, i1 %b) {
68e:
69 br label %l
70l:
71 %x = phi i32* [ %p, %e ]
72 %y = phi i32* [ %q, %e ]
73 %tmp = bitcast i32* %x to i32* ; <i32*> [#uses=2]
74 %tmp2 = select i1 %b, i32* %tmp, i32* %y
75 %val = load i32* %tmp2 ; <i32> [#uses=1]
Duncan Sands9e89ba32008-12-31 16:14:43 +000076 store i32 0, i32* %tmp
Duncan Sands10109412008-12-31 20:21:34 +000077 store i32* %y, i32** @g
Duncan Sands9e89ba32008-12-31 16:14:43 +000078 ret i32 %val
79}
80
Duncan Sands10109412008-12-31 20:21:34 +000081define void @nc2(i32* %p, i32* %q) {
82 %1 = call i32 @nc1(i32* %q, i32* %p, i1 0) ; <i32> [#uses=0]
Duncan Sands9e89ba32008-12-31 16:14:43 +000083 ret void
84}
85
Duncan Sands10109412008-12-31 20:21:34 +000086define void @nc3(void ()* %p) {
87 call void %p()
Duncan Sands9e89ba32008-12-31 16:14:43 +000088 ret void
89}
Nick Lewycky6b056862009-01-02 03:46:56 +000090
Mike Stumpfe095f32009-05-04 18:40:41 +000091declare void @external(i8*) readonly nounwind
Nick Lewycky6b056862009-01-02 03:46:56 +000092define void @nc4(i8* %p) {
93 call void @external(i8* %p)
94 ret void
95}
96
Duncan Sands19784262009-05-07 18:08:34 +000097define void @nc5(void (i8*)* %f, i8* %p) {
98 call void %f(i8* %p) readonly nounwind
99 call void %f(i8* nocapture %p)
Nick Lewycky6b056862009-01-02 03:46:56 +0000100 ret void
101}