Mercurial > hg > CbC > CbC_llvm
comparison test/Transforms/SROA/phi-and-select.ll @ 95:afa8332a0e37 LLVM3.8
LLVM 3.8
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 13 Oct 2015 17:48:58 +0900 |
parents | 54457678186b |
children | c2174574ed3a |
comparison
equal
deleted
inserted
replaced
84:f3e34b893a5f | 95:afa8332a0e37 |
---|---|
5 ; CHECK-LABEL: @test1( | 5 ; CHECK-LABEL: @test1( |
6 entry: | 6 entry: |
7 %a = alloca [2 x i32] | 7 %a = alloca [2 x i32] |
8 ; CHECK-NOT: alloca | 8 ; CHECK-NOT: alloca |
9 | 9 |
10 %a0 = getelementptr [2 x i32]* %a, i64 0, i32 0 | 10 %a0 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 0 |
11 %a1 = getelementptr [2 x i32]* %a, i64 0, i32 1 | 11 %a1 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 1 |
12 store i32 0, i32* %a0 | 12 store i32 0, i32* %a0 |
13 store i32 1, i32* %a1 | 13 store i32 1, i32* %a1 |
14 %v0 = load i32* %a0 | 14 %v0 = load i32, i32* %a0 |
15 %v1 = load i32* %a1 | 15 %v1 = load i32, i32* %a1 |
16 ; CHECK-NOT: store | 16 ; CHECK-NOT: store |
17 ; CHECK-NOT: load | 17 ; CHECK-NOT: load |
18 | 18 |
19 %cond = icmp sle i32 %v0, %v1 | 19 %cond = icmp sle i32 %v0, %v1 |
20 br i1 %cond, label %then, label %exit | 20 br i1 %cond, label %then, label %exit |
24 | 24 |
25 exit: | 25 exit: |
26 %phi = phi i32* [ %a1, %then ], [ %a0, %entry ] | 26 %phi = phi i32* [ %a1, %then ], [ %a0, %entry ] |
27 ; CHECK: phi i32 [ 1, %{{.*}} ], [ 0, %{{.*}} ] | 27 ; CHECK: phi i32 [ 1, %{{.*}} ], [ 0, %{{.*}} ] |
28 | 28 |
29 %result = load i32* %phi | 29 %result = load i32, i32* %phi |
30 ret i32 %result | 30 ret i32 %result |
31 } | 31 } |
32 | 32 |
33 define i32 @test2() { | 33 define i32 @test2() { |
34 ; CHECK-LABEL: @test2( | 34 ; CHECK-LABEL: @test2( |
35 entry: | 35 entry: |
36 %a = alloca [2 x i32] | 36 %a = alloca [2 x i32] |
37 ; CHECK-NOT: alloca | 37 ; CHECK-NOT: alloca |
38 | 38 |
39 %a0 = getelementptr [2 x i32]* %a, i64 0, i32 0 | 39 %a0 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 0 |
40 %a1 = getelementptr [2 x i32]* %a, i64 0, i32 1 | 40 %a1 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 1 |
41 store i32 0, i32* %a0 | 41 store i32 0, i32* %a0 |
42 store i32 1, i32* %a1 | 42 store i32 1, i32* %a1 |
43 %v0 = load i32* %a0 | 43 %v0 = load i32, i32* %a0 |
44 %v1 = load i32* %a1 | 44 %v1 = load i32, i32* %a1 |
45 ; CHECK-NOT: store | 45 ; CHECK-NOT: store |
46 ; CHECK-NOT: load | 46 ; CHECK-NOT: load |
47 | 47 |
48 %cond = icmp sle i32 %v0, %v1 | 48 %cond = icmp sle i32 %v0, %v1 |
49 %select = select i1 %cond, i32* %a1, i32* %a0 | 49 %select = select i1 %cond, i32* %a1, i32* %a0 |
50 ; CHECK: select i1 %{{.*}}, i32 1, i32 0 | 50 ; CHECK: select i1 %{{.*}}, i32 1, i32 0 |
51 | 51 |
52 %result = load i32* %select | 52 %result = load i32, i32* %select |
53 ret i32 %result | 53 ret i32 %result |
54 } | 54 } |
55 | 55 |
56 define i32 @test3(i32 %x) { | 56 define i32 @test3(i32 %x) { |
57 ; CHECK-LABEL: @test3( | 57 ; CHECK-LABEL: @test3( |
60 ; CHECK-NOT: alloca | 60 ; CHECK-NOT: alloca |
61 | 61 |
62 ; Note that we build redundant GEPs here to ensure that having different GEPs | 62 ; Note that we build redundant GEPs here to ensure that having different GEPs |
63 ; into the same alloca partation continues to work with PHI speculation. This | 63 ; into the same alloca partation continues to work with PHI speculation. This |
64 ; was the underlying cause of PR13926. | 64 ; was the underlying cause of PR13926. |
65 %a0 = getelementptr [2 x i32]* %a, i64 0, i32 0 | 65 %a0 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 0 |
66 %a0b = getelementptr [2 x i32]* %a, i64 0, i32 0 | 66 %a0b = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 0 |
67 %a1 = getelementptr [2 x i32]* %a, i64 0, i32 1 | 67 %a1 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 1 |
68 %a1b = getelementptr [2 x i32]* %a, i64 0, i32 1 | 68 %a1b = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 1 |
69 store i32 0, i32* %a0 | 69 store i32 0, i32* %a0 |
70 store i32 1, i32* %a1 | 70 store i32 1, i32* %a1 |
71 ; CHECK-NOT: store | 71 ; CHECK-NOT: store |
72 | 72 |
73 switch i32 %x, label %bb0 [ i32 1, label %bb1 | 73 switch i32 %x, label %bb0 [ i32 1, label %bb1 |
98 exit: | 98 exit: |
99 %phi = phi i32* [ %a1, %bb0 ], [ %a0, %bb1 ], [ %a0, %bb2 ], [ %a1, %bb3 ], | 99 %phi = phi i32* [ %a1, %bb0 ], [ %a0, %bb1 ], [ %a0, %bb2 ], [ %a1, %bb3 ], |
100 [ %a1b, %bb4 ], [ %a0b, %bb5 ], [ %a0b, %bb6 ], [ %a1b, %bb7 ] | 100 [ %a1b, %bb4 ], [ %a0b, %bb5 ], [ %a0b, %bb6 ], [ %a1b, %bb7 ] |
101 ; CHECK: phi i32 [ 1, %{{.*}} ], [ 0, %{{.*}} ], [ 0, %{{.*}} ], [ 1, %{{.*}} ], [ 1, %{{.*}} ], [ 0, %{{.*}} ], [ 0, %{{.*}} ], [ 1, %{{.*}} ] | 101 ; CHECK: phi i32 [ 1, %{{.*}} ], [ 0, %{{.*}} ], [ 0, %{{.*}} ], [ 1, %{{.*}} ], [ 1, %{{.*}} ], [ 0, %{{.*}} ], [ 0, %{{.*}} ], [ 1, %{{.*}} ] |
102 | 102 |
103 %result = load i32* %phi | 103 %result = load i32, i32* %phi |
104 ret i32 %result | 104 ret i32 %result |
105 } | 105 } |
106 | 106 |
107 define i32 @test4() { | 107 define i32 @test4() { |
108 ; CHECK-LABEL: @test4( | 108 ; CHECK-LABEL: @test4( |
109 entry: | 109 entry: |
110 %a = alloca [2 x i32] | 110 %a = alloca [2 x i32] |
111 ; CHECK-NOT: alloca | 111 ; CHECK-NOT: alloca |
112 | 112 |
113 %a0 = getelementptr [2 x i32]* %a, i64 0, i32 0 | 113 %a0 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 0 |
114 %a1 = getelementptr [2 x i32]* %a, i64 0, i32 1 | 114 %a1 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 1 |
115 store i32 0, i32* %a0 | 115 store i32 0, i32* %a0 |
116 store i32 1, i32* %a1 | 116 store i32 1, i32* %a1 |
117 %v0 = load i32* %a0 | 117 %v0 = load i32, i32* %a0 |
118 %v1 = load i32* %a1 | 118 %v1 = load i32, i32* %a1 |
119 ; CHECK-NOT: store | 119 ; CHECK-NOT: store |
120 ; CHECK-NOT: load | 120 ; CHECK-NOT: load |
121 | 121 |
122 %cond = icmp sle i32 %v0, %v1 | 122 %cond = icmp sle i32 %v0, %v1 |
123 %select = select i1 %cond, i32* %a0, i32* %a0 | 123 %select = select i1 %cond, i32* %a0, i32* %a0 |
124 ; CHECK-NOT: select | 124 ; CHECK-NOT: select |
125 | 125 |
126 %result = load i32* %select | 126 %result = load i32, i32* %select |
127 ret i32 %result | 127 ret i32 %result |
128 ; CHECK: ret i32 0 | 128 ; CHECK: ret i32 0 |
129 } | 129 } |
130 | 130 |
131 define i32 @test5(i32* %b) { | 131 define i32 @test5(i32* %b) { |
132 ; CHECK-LABEL: @test5( | 132 ; CHECK-LABEL: @test5( |
133 entry: | 133 entry: |
134 %a = alloca [2 x i32] | 134 %a = alloca [2 x i32] |
135 ; CHECK-NOT: alloca | 135 ; CHECK-NOT: alloca |
136 | 136 |
137 %a1 = getelementptr [2 x i32]* %a, i64 0, i32 1 | 137 %a1 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 1 |
138 store i32 1, i32* %a1 | 138 store i32 1, i32* %a1 |
139 ; CHECK-NOT: store | 139 ; CHECK-NOT: store |
140 | 140 |
141 %select = select i1 true, i32* %a1, i32* %b | 141 %select = select i1 true, i32* %a1, i32* %b |
142 ; CHECK-NOT: select | 142 ; CHECK-NOT: select |
143 | 143 |
144 %result = load i32* %select | 144 %result = load i32, i32* %select |
145 ; CHECK-NOT: load | 145 ; CHECK-NOT: load |
146 | 146 |
147 ret i32 %result | 147 ret i32 %result |
148 ; CHECK: ret i32 1 | 148 ; CHECK: ret i32 1 |
149 } | 149 } |
155 entry: | 155 entry: |
156 %a = alloca [2 x i32] | 156 %a = alloca [2 x i32] |
157 %c = alloca i32 | 157 %c = alloca i32 |
158 ; CHECK-NOT: alloca | 158 ; CHECK-NOT: alloca |
159 | 159 |
160 %a1 = getelementptr [2 x i32]* %a, i64 0, i32 1 | 160 %a1 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 1 |
161 store i32 1, i32* %a1 | 161 store i32 1, i32* %a1 |
162 | 162 |
163 %select = select i1 true, i32* %a1, i32* %b | 163 %select = select i1 true, i32* %a1, i32* %b |
164 %select2 = select i1 false, i32* %a1, i32* %b | 164 %select2 = select i1 false, i32* %a1, i32* %b |
165 %select3 = select i1 false, i32* %c, i32* %b | 165 %select3 = select i1 false, i32* %c, i32* %b |
170 ; constant folding of the select. | 170 ; constant folding of the select. |
171 call void @f(i32* %select2, i32* %select3) | 171 call void @f(i32* %select2, i32* %select3) |
172 ; CHECK: call void @f(i32* %[[select2]], i32* %[[select3]]) | 172 ; CHECK: call void @f(i32* %[[select2]], i32* %[[select3]]) |
173 | 173 |
174 | 174 |
175 %result = load i32* %select | 175 %result = load i32, i32* %select |
176 ; CHECK-NOT: load | 176 ; CHECK-NOT: load |
177 | 177 |
178 %dead = load i32* %c | 178 %dead = load i32, i32* %c |
179 | 179 |
180 ret i32 %result | 180 ret i32 %result |
181 ; CHECK: ret i32 1 | 181 ; CHECK: ret i32 1 |
182 } | 182 } |
183 | 183 |
188 entry: | 188 entry: |
189 %X = alloca i32 | 189 %X = alloca i32 |
190 br i1 undef, label %good, label %bad | 190 br i1 undef, label %good, label %bad |
191 | 191 |
192 good: | 192 good: |
193 %Y1 = getelementptr i32* %X, i64 0 | 193 %Y1 = getelementptr i32, i32* %X, i64 0 |
194 store i32 0, i32* %Y1 | 194 store i32 0, i32* %Y1 |
195 br label %exit | 195 br label %exit |
196 | 196 |
197 bad: | 197 bad: |
198 %Y2 = getelementptr i32* %X, i64 1 | 198 %Y2 = getelementptr i32, i32* %X, i64 1 |
199 store i32 0, i32* %Y2 | 199 store i32 0, i32* %Y2 |
200 br label %exit | 200 br label %exit |
201 | 201 |
202 exit: | 202 exit: |
203 %P = phi i32* [ %Y1, %good ], [ %Y2, %bad ] | 203 %P = phi i32* [ %Y1, %good ], [ %Y2, %bad ] |
204 ; CHECK: %[[phi:.*]] = phi i32 [ 0, %good ], | 204 ; CHECK: %[[phi:.*]] = phi i32 [ 0, %good ], |
205 %Z2 = load i32* %P | 205 %Z2 = load i32, i32* %P |
206 ret i32 %Z2 | 206 ret i32 %Z2 |
207 ; CHECK: ret i32 %[[phi]] | 207 ; CHECK: ret i32 %[[phi]] |
208 } | 208 } |
209 | 209 |
210 define i32 @test8(i32 %b, i32* %ptr) { | 210 define i32 @test8(i32 %b, i32* %ptr) { |
211 ; Ensure that we rewrite allocas to the used type when that use is hidden by | 211 ; Ensure that we rewrite allocas to the used type when that use is hidden by |
212 ; a PHI that can be speculated. | 212 ; a PHI that can be speculated. |
213 ; CHECK-LABEL: @test8( | 213 ; CHECK-LABEL: @test8( |
214 ; CHECK-NOT: alloca | 214 ; CHECK-NOT: alloca |
215 ; CHECK-NOT: load | 215 ; CHECK-NOT: load |
216 ; CHECK: %[[value:.*]] = load i32* %ptr | 216 ; CHECK: %[[value:.*]] = load i32, i32* %ptr |
217 ; CHECK-NOT: load | 217 ; CHECK-NOT: load |
218 ; CHECK: %[[result:.*]] = phi i32 [ undef, %else ], [ %[[value]], %then ] | 218 ; CHECK: %[[result:.*]] = phi i32 [ undef, %else ], [ %[[value]], %then ] |
219 ; CHECK-NEXT: ret i32 %[[result]] | 219 ; CHECK-NEXT: ret i32 %[[result]] |
220 | 220 |
221 entry: | 221 entry: |
230 %bitcast = bitcast float* %f to i32* | 230 %bitcast = bitcast float* %f to i32* |
231 br label %exit | 231 br label %exit |
232 | 232 |
233 exit: | 233 exit: |
234 %phi = phi i32* [ %bitcast, %else ], [ %ptr, %then ] | 234 %phi = phi i32* [ %bitcast, %else ], [ %ptr, %then ] |
235 %loaded = load i32* %phi, align 4 | 235 %loaded = load i32, i32* %phi, align 4 |
236 ret i32 %loaded | 236 ret i32 %loaded |
237 } | 237 } |
238 | 238 |
239 define i32 @test9(i32 %b, i32* %ptr) { | 239 define i32 @test9(i32 %b, i32* %ptr) { |
240 ; Same as @test8 but for a select rather than a PHI node. | 240 ; Same as @test8 but for a select rather than a PHI node. |
241 ; CHECK-LABEL: @test9( | 241 ; CHECK-LABEL: @test9( |
242 ; CHECK-NOT: alloca | 242 ; CHECK-NOT: alloca |
243 ; CHECK-NOT: load | 243 ; CHECK-NOT: load |
244 ; CHECK: %[[value:.*]] = load i32* %ptr | 244 ; CHECK: %[[value:.*]] = load i32, i32* %ptr |
245 ; CHECK-NOT: load | 245 ; CHECK-NOT: load |
246 ; CHECK: %[[result:.*]] = select i1 %{{.*}}, i32 undef, i32 %[[value]] | 246 ; CHECK: %[[result:.*]] = select i1 %{{.*}}, i32 undef, i32 %[[value]] |
247 ; CHECK-NEXT: ret i32 %[[result]] | 247 ; CHECK-NEXT: ret i32 %[[result]] |
248 | 248 |
249 entry: | 249 entry: |
250 %f = alloca float | 250 %f = alloca float |
251 store i32 0, i32* %ptr | 251 store i32 0, i32* %ptr |
252 %test = icmp ne i32 %b, 0 | 252 %test = icmp ne i32 %b, 0 |
253 %bitcast = bitcast float* %f to i32* | 253 %bitcast = bitcast float* %f to i32* |
254 %select = select i1 %test, i32* %bitcast, i32* %ptr | 254 %select = select i1 %test, i32* %bitcast, i32* %ptr |
255 %loaded = load i32* %select, align 4 | 255 %loaded = load i32, i32* %select, align 4 |
256 ret i32 %loaded | 256 ret i32 %loaded |
257 } | 257 } |
258 | 258 |
259 define float @test10(i32 %b, float* %ptr) { | 259 define float @test10(i32 %b, float* %ptr) { |
260 ; Don't try to promote allocas which are not elligible for it even after | 260 ; Don't try to promote allocas which are not elligible for it even after |
261 ; rewriting due to the necessity of inserting bitcasts when speculating a PHI | 261 ; rewriting due to the necessity of inserting bitcasts when speculating a PHI |
262 ; node. | 262 ; node. |
263 ; CHECK-LABEL: @test10( | 263 ; CHECK-LABEL: @test10( |
264 ; CHECK: %[[alloca:.*]] = alloca | 264 ; CHECK: %[[alloca:.*]] = alloca |
265 ; CHECK: %[[argvalue:.*]] = load float* %ptr | 265 ; CHECK: %[[argvalue:.*]] = load float, float* %ptr |
266 ; CHECK: %[[cast:.*]] = bitcast double* %[[alloca]] to float* | 266 ; CHECK: %[[cast:.*]] = bitcast double* %[[alloca]] to float* |
267 ; CHECK: %[[allocavalue:.*]] = load float* %[[cast]] | 267 ; CHECK: %[[allocavalue:.*]] = load float, float* %[[cast]] |
268 ; CHECK: %[[result:.*]] = phi float [ %[[allocavalue]], %else ], [ %[[argvalue]], %then ] | 268 ; CHECK: %[[result:.*]] = phi float [ %[[allocavalue]], %else ], [ %[[argvalue]], %then ] |
269 ; CHECK-NEXT: ret float %[[result]] | 269 ; CHECK-NEXT: ret float %[[result]] |
270 | 270 |
271 entry: | 271 entry: |
272 %f = alloca double | 272 %f = alloca double |
281 %bitcast = bitcast double* %f to float* | 281 %bitcast = bitcast double* %f to float* |
282 br label %exit | 282 br label %exit |
283 | 283 |
284 exit: | 284 exit: |
285 %phi = phi float* [ %bitcast, %else ], [ %ptr, %then ] | 285 %phi = phi float* [ %bitcast, %else ], [ %ptr, %then ] |
286 %loaded = load float* %phi, align 4 | 286 %loaded = load float, float* %phi, align 4 |
287 ret float %loaded | 287 ret float %loaded |
288 } | 288 } |
289 | 289 |
290 define float @test11(i32 %b, float* %ptr) { | 290 define float @test11(i32 %b, float* %ptr) { |
291 ; Same as @test10 but for a select rather than a PHI node. | 291 ; Same as @test10 but for a select rather than a PHI node. |
292 ; CHECK-LABEL: @test11( | 292 ; CHECK-LABEL: @test11( |
293 ; CHECK: %[[alloca:.*]] = alloca | 293 ; CHECK: %[[alloca:.*]] = alloca |
294 ; CHECK: %[[cast:.*]] = bitcast double* %[[alloca]] to float* | 294 ; CHECK: %[[cast:.*]] = bitcast double* %[[alloca]] to float* |
295 ; CHECK: %[[allocavalue:.*]] = load float* %[[cast]] | 295 ; CHECK: %[[allocavalue:.*]] = load float, float* %[[cast]] |
296 ; CHECK: %[[argvalue:.*]] = load float* %ptr | 296 ; CHECK: %[[argvalue:.*]] = load float, float* %ptr |
297 ; CHECK: %[[result:.*]] = select i1 %{{.*}}, float %[[allocavalue]], float %[[argvalue]] | 297 ; CHECK: %[[result:.*]] = select i1 %{{.*}}, float %[[allocavalue]], float %[[argvalue]] |
298 ; CHECK-NEXT: ret float %[[result]] | 298 ; CHECK-NEXT: ret float %[[result]] |
299 | 299 |
300 entry: | 300 entry: |
301 %f = alloca double | 301 %f = alloca double |
302 store double 0.0, double* %f | 302 store double 0.0, double* %f |
303 store float 0.0, float* %ptr | 303 store float 0.0, float* %ptr |
304 %test = icmp ne i32 %b, 0 | 304 %test = icmp ne i32 %b, 0 |
305 %bitcast = bitcast double* %f to float* | 305 %bitcast = bitcast double* %f to float* |
306 %select = select i1 %test, float* %bitcast, float* %ptr | 306 %select = select i1 %test, float* %bitcast, float* %ptr |
307 %loaded = load float* %select, align 4 | 307 %loaded = load float, float* %select, align 4 |
308 ret float %loaded | 308 ret float %loaded |
309 } | 309 } |
310 | 310 |
311 define i32 @test12(i32 %x, i32* %p) { | 311 define i32 @test12(i32 %x, i32* %p) { |
312 ; Ensure we don't crash or fail to nuke dead selects of allocas if no load is | 312 ; Ensure we don't crash or fail to nuke dead selects of allocas if no load is |
318 | 318 |
319 entry: | 319 entry: |
320 %a = alloca i32 | 320 %a = alloca i32 |
321 store i32 %x, i32* %a | 321 store i32 %x, i32* %a |
322 %dead = select i1 undef, i32* %a, i32* %p | 322 %dead = select i1 undef, i32* %a, i32* %p |
323 %load = load i32* %a | 323 %load = load i32, i32* %a |
324 ret i32 %load | 324 ret i32 %load |
325 } | 325 } |
326 | 326 |
327 define i32 @test13(i32 %x, i32* %p) { | 327 define i32 @test13(i32 %x, i32* %p) { |
328 ; Ensure we don't crash or fail to nuke dead phis of allocas if no load is ever | 328 ; Ensure we don't crash or fail to nuke dead phis of allocas if no load is ever |
340 loop: | 340 loop: |
341 %phi = phi i32* [ %p, %entry ], [ %a, %loop ] | 341 %phi = phi i32* [ %p, %entry ], [ %a, %loop ] |
342 br i1 undef, label %loop, label %exit | 342 br i1 undef, label %loop, label %exit |
343 | 343 |
344 exit: | 344 exit: |
345 %load = load i32* %a | 345 %load = load i32, i32* %a |
346 ret i32 %load | 346 ret i32 %load |
347 } | 347 } |
348 | 348 |
349 define i32 @test14(i1 %b1, i1 %b2, i32* %ptr) { | 349 define i32 @test14(i1 %b1, i1 %b2, i32* %ptr) { |
350 ; Check for problems when there are both selects and phis and one is | 350 ; Check for problems when there are both selects and phis and one is |
374 br label %exit | 374 br label %exit |
375 | 375 |
376 exit: | 376 exit: |
377 %f.phi = phi i32* [ %f, %then ], [ %f.select, %else ] | 377 %f.phi = phi i32* [ %f, %then ], [ %f.select, %else ] |
378 %g.phi = phi i32* [ %g, %then ], [ %ptr, %else ] | 378 %g.phi = phi i32* [ %g, %then ], [ %ptr, %else ] |
379 %f.loaded = load i32* %f.phi | 379 %f.loaded = load i32, i32* %f.phi |
380 %g.select = select i1 %b1, i32* %g, i32* %g.phi | 380 %g.select = select i1 %b1, i32* %g, i32* %g.phi |
381 %g.loaded = load i32* %g.select | 381 %g.loaded = load i32, i32* %g.select |
382 %result = add i32 %f.loaded, %g.loaded | 382 %result = add i32 %f.loaded, %g.loaded |
383 ret i32 %result | 383 ret i32 %result |
384 } | 384 } |
385 | 385 |
386 define i32 @PR13905() { | 386 define i32 @PR13905() { |
436 ; alloca. While this is a bit dubious, we were asserting on trying to | 436 ; alloca. While this is a bit dubious, we were asserting on trying to |
437 ; rewrite it. The trick is that the code using the value may carefully take | 437 ; rewrite it. The trick is that the code using the value may carefully take |
438 ; steps to only use the not-undef bits, and so we need to at least loosely | 438 ; steps to only use the not-undef bits, and so we need to at least loosely |
439 ; support this.. | 439 ; support this.. |
440 entry: | 440 entry: |
441 %a = alloca i64 | 441 %a = alloca i64, align 8 |
442 %b = alloca i8 | 442 %b = alloca i8, align 8 |
443 %ptr = alloca i64* | 443 %ptr = alloca i64*, align 8 |
444 ; CHECK-NOT: alloca | 444 ; CHECK-NOT: alloca |
445 | 445 |
446 %ptr.cast = bitcast i64** %ptr to i8** | 446 %ptr.cast = bitcast i64** %ptr to i8** |
447 store i64 0, i64* %a | 447 store i64 0, i64* %a, align 8 |
448 store i8 1, i8* %b | 448 store i8 1, i8* %b, align 8 |
449 store i64* %a, i64** %ptr | 449 store i64* %a, i64** %ptr, align 8 |
450 br i1 %flag, label %if.then, label %if.end | 450 br i1 %flag, label %if.then, label %if.end |
451 | 451 |
452 if.then: | 452 if.then: |
453 store i8* %b, i8** %ptr.cast | 453 store i8* %b, i8** %ptr.cast, align 8 |
454 br label %if.end | 454 br label %if.end |
455 ; CHECK-NOT: store | 455 ; CHECK-NOT: store |
456 ; CHECK: %[[ext:.*]] = zext i8 1 to i64 | 456 ; CHECK: %[[ext:.*]] = zext i8 1 to i64 |
457 | 457 |
458 if.end: | 458 if.end: |
459 %tmp = load i64** %ptr | 459 %tmp = load i64*, i64** %ptr, align 8 |
460 %result = load i64* %tmp | 460 %result = load i64, i64* %tmp, align 8 |
461 ; CHECK-NOT: load | 461 ; CHECK-NOT: load |
462 ; CHECK: %[[result:.*]] = phi i64 [ %[[ext]], %if.then ], [ 0, %entry ] | 462 ; CHECK: %[[result:.*]] = phi i64 [ %[[ext]], %if.then ], [ 0, %entry ] |
463 | 463 |
464 ret i64 %result | 464 ret i64 %result |
465 ; CHECK-NEXT: ret i64 %[[result]] | 465 ; CHECK-NEXT: ret i64 %[[result]] |
486 br label %end | 486 br label %end |
487 ; CHECK: %[[lo_cast:.*]] = bitcast i32 %[[lo]] to float | 487 ; CHECK: %[[lo_cast:.*]] = bitcast i32 %[[lo]] to float |
488 | 488 |
489 else: | 489 else: |
490 %a.raw = bitcast i64* %a to i8* | 490 %a.raw = bitcast i64* %a to i8* |
491 %a.raw.4 = getelementptr i8* %a.raw, i64 4 | 491 %a.raw.4 = getelementptr i8, i8* %a.raw, i64 4 |
492 %a.raw.4.f = bitcast i8* %a.raw.4 to float* | 492 %a.raw.4.f = bitcast i8* %a.raw.4 to float* |
493 br label %end | 493 br label %end |
494 ; CHECK: %[[hi_cast:.*]] = bitcast i32 %[[hi]] to float | 494 ; CHECK: %[[hi_cast:.*]] = bitcast i32 %[[hi]] to float |
495 | 495 |
496 end: | 496 end: |
497 %a.phi.f = phi float* [ %a.f, %then ], [ %a.raw.4.f, %else ] | 497 %a.phi.f = phi float* [ %a.f, %then ], [ %a.raw.4.f, %else ] |
498 %f = load float* %a.phi.f | 498 %f = load float, float* %a.phi.f |
499 ret float %f | 499 ret float %f |
500 ; CHECK: %[[phi:.*]] = phi float [ %[[lo_cast]], %then ], [ %[[hi_cast]], %else ] | 500 ; CHECK: %[[phi:.*]] = phi float [ %[[lo_cast]], %then ], [ %[[hi_cast]], %else ] |
501 ; CHECK-NOT: load | 501 ; CHECK-NOT: load |
502 ; CHECK: ret float %[[phi]] | 502 ; CHECK: ret float %[[phi]] |
503 } | 503 } |
514 %arr = alloca [4 x float], align 4 | 514 %arr = alloca [4 x float], align 4 |
515 ; CHECK-NOT: alloca | 515 ; CHECK-NOT: alloca |
516 br i1 %cond, label %then, label %else | 516 br i1 %cond, label %then, label %else |
517 | 517 |
518 then: | 518 then: |
519 %0 = getelementptr inbounds [4 x float]* %arr, i64 0, i64 3 | 519 %0 = getelementptr inbounds [4 x float], [4 x float]* %arr, i64 0, i64 3 |
520 store float 1.000000e+00, float* %0, align 4 | 520 store float 1.000000e+00, float* %0, align 4 |
521 br label %merge | 521 br label %merge |
522 | 522 |
523 else: | 523 else: |
524 %1 = getelementptr inbounds [4 x float]* %arr, i64 0, i64 3 | 524 %1 = getelementptr inbounds [4 x float], [4 x float]* %arr, i64 0, i64 3 |
525 store float 2.000000e+00, float* %1, align 4 | 525 store float 2.000000e+00, float* %1, align 4 |
526 br label %merge | 526 br label %merge |
527 | 527 |
528 merge: | 528 merge: |
529 %2 = phi float* [ %0, %then ], [ %1, %else ] | 529 %2 = phi float* [ %0, %then ], [ %1, %else ] |
530 store float 0.000000e+00, float* %temp, align 4 | 530 store float 0.000000e+00, float* %temp, align 4 |
531 %3 = load float* %2, align 4 | 531 %3 = load float, float* %2, align 4 |
532 ret float %3 | 532 ret float %3 |
533 } | 533 } |
534 | 534 |
535 ; A slightly complicated example for PR20425. | 535 ; A slightly complicated example for PR20425. |
536 ; | 536 ; |
544 %arr = alloca [4 x float], align 4 | 544 %arr = alloca [4 x float], align 4 |
545 ; CHECK-NOT: alloca | 545 ; CHECK-NOT: alloca |
546 br i1 %cond, label %then, label %else | 546 br i1 %cond, label %then, label %else |
547 | 547 |
548 then: | 548 then: |
549 %0 = getelementptr inbounds [4 x float]* %arr, i64 0, i64 3 | 549 %0 = getelementptr inbounds [4 x float], [4 x float]* %arr, i64 0, i64 3 |
550 store float 1.000000e+00, float* %0, align 4 | 550 store float 1.000000e+00, float* %0, align 4 |
551 br label %then2 | 551 br label %then2 |
552 | 552 |
553 then2: | 553 then2: |
554 %1 = phi float* [ %0, %then ] | 554 %1 = phi float* [ %0, %then ] |
555 store float 2.000000e+00, float* %1, align 4 | 555 store float 2.000000e+00, float* %1, align 4 |
556 br label %merge | 556 br label %merge |
557 | 557 |
558 else: | 558 else: |
559 %2 = getelementptr inbounds [4 x float]* %arr, i64 0, i64 3 | 559 %2 = getelementptr inbounds [4 x float], [4 x float]* %arr, i64 0, i64 3 |
560 store float 3.000000e+00, float* %2, align 4 | 560 store float 3.000000e+00, float* %2, align 4 |
561 br label %merge | 561 br label %merge |
562 | 562 |
563 merge: | 563 merge: |
564 %3 = phi float* [ %1, %then2 ], [ %2, %else ] | 564 %3 = phi float* [ %1, %then2 ], [ %2, %else ] |
565 store float 0.000000e+00, float* %temp, align 4 | 565 store float 0.000000e+00, float* %temp, align 4 |
566 %4 = load float* %3, align 4 | 566 %4 = load float, float* %3, align 4 |
567 ret float %4 | 567 ret float %4 |
568 } | 568 } |
569 | 569 |
570 %struct.S = type { i32 } | 570 %struct.S = type { i32 } |
571 | 571 |