blob: 3027acd35c7da2072c7d37c4eacd01d66767e7ec [file] [log] [blame]
Nick Lewyckyd4659ad2011-12-23 18:41:31 +00001; RUN: opt < %s -functionattrs -S | FileCheck %s
Duncan Sands9e89ba32008-12-31 16:14:43 +00002@g = global i32* null ; <i32**> [#uses=1]
3
Nick Lewyckyd4659ad2011-12-23 18:41:31 +00004; CHECK: define i32* @c1(i32* %q)
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
Nick Lewyckyd4659ad2011-12-23 18:41:31 +00009; CHECK: define void @c2(i32* %q)
Duncan Sands10109412008-12-31 20:21:34 +000010define void @c2(i32* %q) {
11 store i32* %q, i32** @g
Duncan Sands9e89ba32008-12-31 16:14:43 +000012 ret void
13}
14
Nick Lewyckyd4659ad2011-12-23 18:41:31 +000015; CHECK: define void @c3(i32* %q)
Duncan Sands10109412008-12-31 20:21:34 +000016define void @c3(i32* %q) {
17 call void @c2(i32* %q)
Duncan Sands9e89ba32008-12-31 16:14:43 +000018 ret void
19}
20
Nick Lewyckyd4659ad2011-12-23 18:41:31 +000021; CHECK: define i1 @c4(i32* %q, i32 %bitno)
Duncan Sands29ab02b2009-01-02 00:55:51 +000022define i1 @c4(i32* %q, i32 %bitno) {
23 %tmp = ptrtoint i32* %q to i32
24 %tmp2 = lshr i32 %tmp, %bitno
25 %bit = trunc i32 %tmp2 to i1
26 br i1 %bit, label %l1, label %l0
27l0:
28 ret i1 0 ; escaping value not caught by def-use chaining.
29l1:
30 ret i1 1 ; escaping value not caught by def-use chaining.
31}
32
33@lookup_table = global [2 x i1] [ i1 0, i1 1 ]
34
Nick Lewyckyd4659ad2011-12-23 18:41:31 +000035; CHECK: define i1 @c5(i32* %q, i32 %bitno)
Duncan Sands29ab02b2009-01-02 00:55:51 +000036define i1 @c5(i32* %q, i32 %bitno) {
37 %tmp = ptrtoint i32* %q to i32
38 %tmp2 = lshr i32 %tmp, %bitno
39 %bit = and i32 %tmp2, 1
40 ; subtle escape mechanism follows
41 %lookup = getelementptr [2 x i1]* @lookup_table, i32 0, i32 %bit
42 %val = load i1* %lookup
43 ret i1 %val
44}
45
Mike Stumpfe095f32009-05-04 18:40:41 +000046declare void @throw_if_bit_set(i8*, i8) readonly
Nick Lewyckyd4659ad2011-12-23 18:41:31 +000047
48; CHECK: define i1 @c6(i8* %q, i8 %bit)
Mike Stumpfe095f32009-05-04 18:40:41 +000049define i1 @c6(i8* %q, i8 %bit) {
50 invoke void @throw_if_bit_set(i8* %q, i8 %bit)
51 to label %ret0 unwind label %ret1
52ret0:
53 ret i1 0
54ret1:
Bill Wendlingaeaa9a82011-09-01 00:58:03 +000055 %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
56 cleanup
Mike Stumpfe095f32009-05-04 18:40:41 +000057 ret i1 1
58}
59
Bill Wendlingaeaa9a82011-09-01 00:58:03 +000060declare i32 @__gxx_personality_v0(...)
61
Duncan Sands19784262009-05-07 18:08:34 +000062define i1* @lookup_bit(i32* %q, i32 %bitno) readnone nounwind {
63 %tmp = ptrtoint i32* %q to i32
64 %tmp2 = lshr i32 %tmp, %bitno
65 %bit = and i32 %tmp2, 1
66 %lookup = getelementptr [2 x i1]* @lookup_table, i32 0, i32 %bit
67 ret i1* %lookup
68}
69
Nick Lewyckyd4659ad2011-12-23 18:41:31 +000070; CHECK: define i1 @c7(i32* %q, i32 %bitno)
Duncan Sands19784262009-05-07 18:08:34 +000071define i1 @c7(i32* %q, i32 %bitno) {
72 %ptr = call i1* @lookup_bit(i32* %q, i32 %bitno)
73 %val = load i1* %ptr
74 ret i1 %val
75}
76
77
Nick Lewyckyd4659ad2011-12-23 18:41:31 +000078; CHECK: define i32 @nc1(i32* %q, i32* nocapture %p, i1 %b)
Duncan Sands10109412008-12-31 20:21:34 +000079define i32 @nc1(i32* %q, i32* %p, i1 %b) {
80e:
81 br label %l
82l:
83 %x = phi i32* [ %p, %e ]
84 %y = phi i32* [ %q, %e ]
85 %tmp = bitcast i32* %x to i32* ; <i32*> [#uses=2]
86 %tmp2 = select i1 %b, i32* %tmp, i32* %y
87 %val = load i32* %tmp2 ; <i32> [#uses=1]
Duncan Sands9e89ba32008-12-31 16:14:43 +000088 store i32 0, i32* %tmp
Duncan Sands10109412008-12-31 20:21:34 +000089 store i32* %y, i32** @g
Duncan Sands9e89ba32008-12-31 16:14:43 +000090 ret i32 %val
91}
92
Nick Lewyckyd4659ad2011-12-23 18:41:31 +000093; CHECK: define void @nc2(i32* nocapture %p, i32* %q)
Duncan Sands10109412008-12-31 20:21:34 +000094define void @nc2(i32* %p, i32* %q) {
95 %1 = call i32 @nc1(i32* %q, i32* %p, i1 0) ; <i32> [#uses=0]
Duncan Sands9e89ba32008-12-31 16:14:43 +000096 ret void
97}
98
Nick Lewyckyd4659ad2011-12-23 18:41:31 +000099; CHECK: define void @nc3(void ()* nocapture %p)
Duncan Sands10109412008-12-31 20:21:34 +0000100define void @nc3(void ()* %p) {
101 call void %p()
Duncan Sands9e89ba32008-12-31 16:14:43 +0000102 ret void
103}
Nick Lewycky6b056862009-01-02 03:46:56 +0000104
Mike Stumpfe095f32009-05-04 18:40:41 +0000105declare void @external(i8*) readonly nounwind
Nick Lewyckyd4659ad2011-12-23 18:41:31 +0000106; CHECK: define void @nc4(i8* nocapture %p)
Nick Lewycky6b056862009-01-02 03:46:56 +0000107define void @nc4(i8* %p) {
108 call void @external(i8* %p)
109 ret void
110}
111
Nick Lewyckyd4659ad2011-12-23 18:41:31 +0000112; CHECK: define void @nc5(void (i8*)* nocapture %f, i8* nocapture %p)
Duncan Sands19784262009-05-07 18:08:34 +0000113define void @nc5(void (i8*)* %f, i8* %p) {
114 call void %f(i8* %p) readonly nounwind
115 call void %f(i8* nocapture %p)
Nick Lewycky6b056862009-01-02 03:46:56 +0000116 ret void
117}
Nick Lewyckyb48a1892011-12-28 23:24:21 +0000118
119; CHECK: define void @test1_1(i8* nocapture %x1_1, i8* %y1_1)
120define void @test1_1(i8* %x1_1, i8* %y1_1) {
121 call i8* @test1_2(i8* %x1_1, i8* %y1_1)
122 store i32* null, i32** @g
123 ret void
124}
125
126; CHECK: define i8* @test1_2(i8* nocapture %x1_2, i8* %y1_2)
127define i8* @test1_2(i8* %x1_2, i8* %y1_2) {
128 call void @test1_1(i8* %x1_2, i8* %y1_2)
129 store i32* null, i32** @g
130 ret i8* %y1_2
131}
132
133; CHECK: define void @test2(i8* nocapture %x2)
134define void @test2(i8* %x2) {
135 call void @test2(i8* %x2)
136 store i32* null, i32** @g
137 ret void
138}
139
140; CHECK: define void @test3(i8* nocapture %x3, i8* nocapture %y3, i8* nocapture %z3)
141define void @test3(i8* %x3, i8* %y3, i8* %z3) {
142 call void @test3(i8* %z3, i8* %y3, i8* %x3)
143 store i32* null, i32** @g
144 ret void
145}
146
147; CHECK: define void @test4_1(i8* %x4_1)
148define void @test4_1(i8* %x4_1) {
149 call i8* @test4_2(i8* %x4_1, i8* %x4_1, i8* %x4_1)
150 store i32* null, i32** @g
151 ret void
152}
153
154; CHECK: define i8* @test4_2(i8* nocapture %x4_2, i8* %y4_2, i8* nocapture %z4_2)
155define i8* @test4_2(i8* %x4_2, i8* %y4_2, i8* %z4_2) {
156 call void @test4_1(i8* null)
157 store i32* null, i32** @g
158 ret i8* %y4_2
159}
160
161declare i8* @test5_1(i8* %x5_1)
162
163; CHECK: define void @test5_2(i8* %x5_2)
164define void @test5_2(i8* %x5_2) {
165 call i8* @test5_1(i8* %x5_2)
166 store i32* null, i32** @g
167 ret void
168}
169
170declare void @test6_1(i8* %x6_1, i8* nocapture %y6_1, ...)
171
172; CHECK: define void @test6_2(i8* %x6_2, i8* nocapture %y6_2, i8* %z6_2)
173define void @test6_2(i8* %x6_2, i8* %y6_2, i8* %z6_2) {
174 call void (i8*, i8*, ...)* @test6_1(i8* %x6_2, i8* %y6_2, i8* %z6_2)
175 store i32* null, i32** @g
176 ret void
177}
178