blob: 61c607dc007ef603ecac57b42572ca714ccb960b [file] [log] [blame]
Duncan Sands10109412008-12-31 20:21:34 +00001; 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
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
Duncan Sands10109412008-12-31 20:21:34 +000042define i32 @nc1(i32* %q, i32* %p, i1 %b) {
43e:
44 br label %l
45l:
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]
Duncan Sands9e89ba32008-12-31 16:14:43 +000051 store i32 0, i32* %tmp
Duncan Sands10109412008-12-31 20:21:34 +000052 store i32* %y, i32** @g
Duncan Sands9e89ba32008-12-31 16:14:43 +000053 ret i32 %val
54}
55
Duncan Sands10109412008-12-31 20:21:34 +000056define void @nc2(i32* %p, i32* %q) {
57 %1 = call i32 @nc1(i32* %q, i32* %p, i1 0) ; <i32> [#uses=0]
Duncan Sands9e89ba32008-12-31 16:14:43 +000058 ret void
59}
60
Duncan Sands10109412008-12-31 20:21:34 +000061define void @nc3(void ()* %p) {
62 call void %p()
Duncan Sands9e89ba32008-12-31 16:14:43 +000063 ret void
64}