1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=instcombine -S < %s | FileCheck %s
4 define void @test_bitcast_1(i1 %c, ptr %ptr) {
5 ; CHECK-LABEL: @test_bitcast_1(
7 ; CHECK-NEXT: br i1 [[C:%.*]], label [[B0:%.*]], label [[B1:%.*]]
9 ; CHECK-NEXT: call void @use(ptr [[PTR:%.*]])
10 ; CHECK-NEXT: br label [[END:%.*]]
12 ; CHECK-NEXT: br label [[END]]
14 ; CHECK-NEXT: store i8 0, ptr [[PTR]], align 1
15 ; CHECK-NEXT: ret void
18 br i1 %c, label %b0, label %b1
21 call void @use(ptr %ptr)
28 %p = phi ptr [ %ptr, %b0 ], [ %ptr, %b1 ]
33 define void @test_bitcast_2(i1 %c, ptr %ptr) {
34 ; CHECK-LABEL: @test_bitcast_2(
36 ; CHECK-NEXT: br i1 [[C:%.*]], label [[B0:%.*]], label [[B1:%.*]]
38 ; CHECK-NEXT: br label [[END:%.*]]
40 ; CHECK-NEXT: call void @use(ptr [[PTR:%.*]])
41 ; CHECK-NEXT: br label [[END]]
43 ; CHECK-NEXT: store i8 0, ptr [[PTR]], align 1
44 ; CHECK-NEXT: ret void
47 br i1 %c, label %b0, label %b1
53 call void @use(ptr %ptr)
57 %p = phi ptr [ %ptr, %b0 ], [ %ptr, %b1 ]
63 define void @test_bitcast_3(i1 %c, ptr %ptr) {
64 ; CHECK-LABEL: @test_bitcast_3(
66 ; CHECK-NEXT: [[LOAD_PTR:%.*]] = load ptr, ptr [[PTR:%.*]], align 8
67 ; CHECK-NEXT: br i1 [[C:%.*]], label [[B0:%.*]], label [[B1:%.*]]
69 ; CHECK-NEXT: br label [[END:%.*]]
71 ; CHECK-NEXT: call void @use(ptr [[LOAD_PTR]])
72 ; CHECK-NEXT: br label [[END]]
74 ; CHECK-NEXT: store i8 0, ptr [[LOAD_PTR]], align 1
75 ; CHECK-NEXT: ret void
78 %load.ptr = load ptr, ptr %ptr
79 br i1 %c, label %b0, label %b1
85 call void @use(ptr %load.ptr)
89 %p = phi ptr [ %load.ptr, %b0 ], [ %load.ptr, %b1 ]
94 define void @test_bitcast_loads_in_different_bbs(i1 %c, ptr %ptr.0, ptr %ptr.1) {
95 ; CHECK-LABEL: @test_bitcast_loads_in_different_bbs(
97 ; CHECK-NEXT: br i1 [[C:%.*]], label [[B0:%.*]], label [[B1:%.*]]
99 ; CHECK-NEXT: [[LOAD_PTR_0:%.*]] = load ptr, ptr [[PTR_0:%.*]], align 8
100 ; CHECK-NEXT: call void @use(ptr [[LOAD_PTR_0]])
101 ; CHECK-NEXT: br label [[END:%.*]]
103 ; CHECK-NEXT: [[LOAD_PTR_1:%.*]] = load ptr, ptr [[PTR_1:%.*]], align 8
104 ; CHECK-NEXT: br label [[END]]
106 ; CHECK-NEXT: [[P:%.*]] = phi ptr [ [[LOAD_PTR_0]], [[B0]] ], [ [[LOAD_PTR_1]], [[B1]] ]
107 ; CHECK-NEXT: store i8 0, ptr [[P]], align 1
108 ; CHECK-NEXT: ret void
111 br i1 %c, label %b0, label %b1
114 %load.ptr.0 = load ptr, ptr %ptr.0
115 call void @use(ptr %load.ptr.0)
119 %load.ptr.1 = load ptr, ptr %ptr.1
123 %p = phi ptr [ %load.ptr.0, %b0 ], [ %load.ptr.1, %b1 ]
128 define void @test_gep_1(i1 %c, ptr %ptr) {
129 ; CHECK-LABEL: @test_gep_1(
131 ; CHECK-NEXT: br i1 [[C:%.*]], label [[B0:%.*]], label [[B1:%.*]]
133 ; CHECK-NEXT: call void @use.i32(ptr [[PTR:%.*]])
134 ; CHECK-NEXT: br label [[END:%.*]]
136 ; CHECK-NEXT: br label [[END]]
138 ; CHECK-NEXT: store i32 0, ptr [[PTR]], align 4
139 ; CHECK-NEXT: ret void
142 br i1 %c, label %b0, label %b1
145 call void @use.i32(ptr %ptr)
152 %p = phi ptr [ %ptr, %b0 ], [ %ptr, %b1 ]
157 define void @test_bitcast_not_foldable(i1 %c, ptr %ptr.0, ptr %ptr.1) {
158 ; CHECK-LABEL: @test_bitcast_not_foldable(
160 ; CHECK-NEXT: br i1 [[C:%.*]], label [[B0:%.*]], label [[B1:%.*]]
162 ; CHECK-NEXT: br label [[END:%.*]]
164 ; CHECK-NEXT: call void @use(ptr [[PTR_1:%.*]])
165 ; CHECK-NEXT: br label [[END]]
167 ; CHECK-NEXT: [[P:%.*]] = phi ptr [ [[PTR_0:%.*]], [[B0]] ], [ [[PTR_1]], [[B1]] ]
168 ; CHECK-NEXT: store i8 0, ptr [[P]], align 1
169 ; CHECK-NEXT: ret void
172 br i1 %c, label %b0, label %b1
178 call void @use(ptr %ptr.1)
182 %p = phi ptr [ %ptr.0, %b0 ], [ %ptr.1, %b1 ]
187 define void @test_bitcast_with_extra_use(i1 %c, ptr %ptr) {
188 ; CHECK-LABEL: @test_bitcast_with_extra_use(
190 ; CHECK-NEXT: br i1 [[C:%.*]], label [[B0:%.*]], label [[B1:%.*]]
192 ; CHECK-NEXT: call void @use(ptr [[PTR:%.*]])
193 ; CHECK-NEXT: br label [[END:%.*]]
195 ; CHECK-NEXT: br label [[END]]
197 ; CHECK-NEXT: store i8 0, ptr [[PTR]], align 1
198 ; CHECK-NEXT: ret void
201 br i1 %c, label %b0, label %b1
204 call void @use(ptr %ptr)
211 %p = phi ptr [ %ptr, %b0 ], [ %ptr, %b1 ]
216 define void @test_bitcast_different_bases(i1 %c, ptr %ptr.0, ptr %ptr.1) {
217 ; CHECK-LABEL: @test_bitcast_different_bases(
219 ; CHECK-NEXT: br i1 [[C:%.*]], label [[B0:%.*]], label [[B1:%.*]]
221 ; CHECK-NEXT: call void @use(ptr [[PTR_0:%.*]])
222 ; CHECK-NEXT: br label [[END:%.*]]
224 ; CHECK-NEXT: br label [[END]]
226 ; CHECK-NEXT: [[P:%.*]] = phi ptr [ [[PTR_0]], [[B0]] ], [ [[PTR_1:%.*]], [[B1]] ]
227 ; CHECK-NEXT: store i8 0, ptr [[P]], align 1
228 ; CHECK-NEXT: ret void
231 br i1 %c, label %b0, label %b1
234 call void @use(ptr %ptr.0)
241 %p = phi ptr [ %ptr.0, %b0 ], [ %ptr.1, %b1 ]
246 define void @test_bitcast_gep_chains(i1 %c, ptr %ptr) {
247 ; CHECK-LABEL: @test_bitcast_gep_chains(
249 ; CHECK-NEXT: br i1 [[C:%.*]], label [[B0:%.*]], label [[B1:%.*]]
251 ; CHECK-NEXT: call void @use(ptr [[PTR:%.*]])
252 ; CHECK-NEXT: br label [[END:%.*]]
254 ; CHECK-NEXT: call void @use.i32(ptr [[PTR]])
255 ; CHECK-NEXT: br label [[END]]
257 ; CHECK-NEXT: store i8 0, ptr [[PTR]], align 1
258 ; CHECK-NEXT: ret void
261 br i1 %c, label %b0, label %b1
264 call void @use(ptr %ptr)
268 call void @use.i32(ptr %ptr)
272 %p = phi ptr [ %ptr, %b0 ], [ %ptr, %b1 ]
277 define void @test_4_incoming_values_different_bases_1(i32 %c, ptr %ptr.0, ptr %ptr.1) {
278 ; CHECK-LABEL: @test_4_incoming_values_different_bases_1(
280 ; CHECK-NEXT: switch i32 [[C:%.*]], label [[END_2:%.*]] [
281 ; CHECK-NEXT: i32 0, label [[B0:%.*]]
282 ; CHECK-NEXT: i32 1, label [[B1:%.*]]
283 ; CHECK-NEXT: i32 2, label [[B2:%.*]]
284 ; CHECK-NEXT: i32 3, label [[B3:%.*]]
287 ; CHECK-NEXT: call void @use(ptr [[PTR_0:%.*]])
288 ; CHECK-NEXT: br label [[END:%.*]]
290 ; CHECK-NEXT: br label [[END]]
292 ; CHECK-NEXT: br label [[END]]
294 ; CHECK-NEXT: br label [[END]]
296 ; CHECK-NEXT: [[P:%.*]] = phi ptr [ [[PTR_0]], [[B0]] ], [ [[PTR_1:%.*]], [[B1]] ], [ [[PTR_0]], [[B2]] ], [ [[PTR_0]], [[B3]] ]
297 ; CHECK-NEXT: store i8 0, ptr [[P]], align 1
298 ; CHECK-NEXT: ret void
300 ; CHECK-NEXT: ret void
303 switch i32 %c, label %end.2 [ i32 0, label %b0
309 call void @use(ptr %ptr.0)
322 %p = phi ptr [ %ptr.0, %b0 ], [ %ptr.1, %b1 ], [ %ptr.0, %b2 ], [ %ptr.0, %b3]
330 define void @test_4_incoming_values_different_bases_2(i32 %c, ptr %ptr.0, ptr %ptr.1) {
331 ; CHECK-LABEL: @test_4_incoming_values_different_bases_2(
333 ; CHECK-NEXT: switch i32 [[C:%.*]], label [[END_2:%.*]] [
334 ; CHECK-NEXT: i32 0, label [[B0:%.*]]
335 ; CHECK-NEXT: i32 1, label [[B1:%.*]]
336 ; CHECK-NEXT: i32 2, label [[B2:%.*]]
337 ; CHECK-NEXT: i32 3, label [[B3:%.*]]
340 ; CHECK-NEXT: br label [[END:%.*]]
342 ; CHECK-NEXT: call void @use(ptr [[PTR_0:%.*]])
343 ; CHECK-NEXT: br label [[END]]
345 ; CHECK-NEXT: br label [[END]]
347 ; CHECK-NEXT: br label [[END]]
349 ; CHECK-NEXT: [[P:%.*]] = phi ptr [ [[PTR_1:%.*]], [[B0]] ], [ [[PTR_0]], [[B1]] ], [ [[PTR_0]], [[B2]] ], [ [[PTR_0]], [[B3]] ]
350 ; CHECK-NEXT: store i8 0, ptr [[P]], align 1
351 ; CHECK-NEXT: ret void
353 ; CHECK-NEXT: ret void
356 switch i32 %c, label %end.2 [ i32 0, label %b0
365 call void @use(ptr %ptr.0)
375 %p = phi ptr [ %ptr.1, %b0 ], [ %ptr.0, %b1 ], [ %ptr.0, %b2 ], [ %ptr.0, %b3]
383 define void @test_4_incoming_values_different_bases_3(i32 %c, ptr %ptr.0, ptr %ptr.1) {
384 ; CHECK-LABEL: @test_4_incoming_values_different_bases_3(
386 ; CHECK-NEXT: switch i32 [[C:%.*]], label [[END_2:%.*]] [
387 ; CHECK-NEXT: i32 0, label [[B0:%.*]]
388 ; CHECK-NEXT: i32 1, label [[B1:%.*]]
389 ; CHECK-NEXT: i32 2, label [[B2:%.*]]
390 ; CHECK-NEXT: i32 3, label [[B3:%.*]]
393 ; CHECK-NEXT: br label [[END:%.*]]
395 ; CHECK-NEXT: br label [[END]]
397 ; CHECK-NEXT: call void @use(ptr [[PTR_0:%.*]])
398 ; CHECK-NEXT: br label [[END]]
400 ; CHECK-NEXT: br label [[END]]
402 ; CHECK-NEXT: [[P:%.*]] = phi ptr [ [[PTR_0]], [[B0]] ], [ [[PTR_0]], [[B1]] ], [ [[PTR_0]], [[B2]] ], [ [[PTR_1:%.*]], [[B3]] ]
403 ; CHECK-NEXT: store i8 0, ptr [[P]], align 1
404 ; CHECK-NEXT: ret void
406 ; CHECK-NEXT: ret void
409 switch i32 %c, label %end.2 [ i32 0, label %b0
421 call void @use(ptr %ptr.0)
428 %p = phi ptr [ %ptr.0, %b0 ], [ %ptr.0, %b1 ], [ %ptr.0, %b2 ], [ %ptr.1, %b3]
436 define void @test_addrspacecast_1(i1 %c, ptr %ptr) {
437 ; CHECK-LABEL: @test_addrspacecast_1(
439 ; CHECK-NEXT: br i1 [[C:%.*]], label [[B0:%.*]], label [[B1:%.*]]
441 ; CHECK-NEXT: br label [[END:%.*]]
443 ; CHECK-NEXT: [[CAST_1:%.*]] = addrspacecast ptr [[PTR:%.*]] to ptr addrspace(1)
444 ; CHECK-NEXT: call void @use.i8.addrspace1(ptr addrspace(1) [[CAST_1]])
445 ; CHECK-NEXT: br label [[END]]
447 ; CHECK-NEXT: [[P:%.*]] = addrspacecast ptr [[PTR]] to ptr addrspace(1)
448 ; CHECK-NEXT: store i8 0, ptr addrspace(1) [[P]], align 1
449 ; CHECK-NEXT: ret void
452 %cast.0 = addrspacecast ptr %ptr to ptr addrspace(1)
453 %cast.1 = addrspacecast ptr %ptr to ptr addrspace(1)
454 br i1 %c, label %b0, label %b1
460 call void @use.i8.addrspace1(ptr addrspace(1) %cast.1)
464 %p = phi ptr addrspace(1) [ %cast.0, %b0 ], [ %cast.1, %b1 ]
465 store i8 0, ptr addrspace(1) %p
469 declare void @use(ptr)
470 declare void @use.i32(ptr)
471 declare void @use.i8.addrspace1(ptr addrspace(1))