1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=gvn -S | FileCheck %s
4 @a = external global i32 ; <ptr> [#uses=7]
6 define i32 @test1() nounwind {
9 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr @a, align 4
10 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[TMP0]], 4
11 ; CHECK-NEXT: br i1 [[TMP1]], label [[BB:%.*]], label [[BB1:%.*]]
13 ; CHECK-NEXT: br label [[BB8:%.*]]
15 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP0]], 5
16 ; CHECK-NEXT: br i1 [[TMP2]], label [[BB2:%.*]], label [[BB3:%.*]]
18 ; CHECK-NEXT: br label [[BB8]]
20 ; CHECK-NEXT: br i1 false, label [[BB4:%.*]], label [[BB5:%.*]]
22 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr @a, align 4
23 ; CHECK-NEXT: [[TMP4:%.*]] = add i32 [[TMP3]], 5
24 ; CHECK-NEXT: br label [[BB8]]
26 ; CHECK-NEXT: br i1 false, label [[BB6:%.*]], label [[BB7:%.*]]
28 ; CHECK-NEXT: [[TMP5:%.*]] = load i32, ptr @a, align 4
29 ; CHECK-NEXT: [[TMP6:%.*]] = add i32 [[TMP5]], 4
30 ; CHECK-NEXT: br label [[BB8]]
32 ; CHECK-NEXT: br label [[BB8]]
34 ; CHECK-NEXT: [[DOT0:%.*]] = phi i32 [ [[TMP0]], [[BB7]] ], [ poison, [[BB6]] ], [ poison, [[BB4]] ], [ 4, [[BB2]] ], [ 5, [[BB]] ]
35 ; CHECK-NEXT: ret i32 [[DOT0]]
38 %0 = load i32, ptr @a, align 4
39 %1 = icmp eq i32 %0, 4
40 br i1 %1, label %bb, label %bb1
46 %2 = load i32, ptr @a, align 4
47 %3 = icmp eq i32 %2, 5
48 br i1 %3, label %bb2, label %bb3
54 %4 = load i32, ptr @a, align 4
55 %5 = icmp eq i32 %4, 4
56 br i1 %5, label %bb4, label %bb5
59 %6 = load i32, ptr @a, align 4
64 %8 = load i32, ptr @a, align 4
65 %9 = icmp eq i32 %8, 5
66 br i1 %9, label %bb6, label %bb7
69 %10 = load i32, ptr @a, align 4
74 %12 = load i32, ptr @a, align 4
77 bb8: ; preds = %bb7, %bb6, %bb4, %bb2, %bb
78 %.0 = phi i32 [ %12, %bb7 ], [ %11, %bb6 ], [ %7, %bb4 ], [ 4, %bb2 ], [ 5, %bb ]
81 return: ; preds = %bb8
86 declare void @bar(i32)
88 define void @test3(i32 %x, i32 %y) {
89 ; CHECK-LABEL: @test3(
90 ; CHECK-NEXT: [[XZ:%.*]] = icmp eq i32 [[X:%.*]], 0
91 ; CHECK-NEXT: [[YZ:%.*]] = icmp eq i32 [[Y:%.*]], 0
92 ; CHECK-NEXT: [[Z:%.*]] = and i1 [[XZ]], [[YZ]]
93 ; CHECK-NEXT: br i1 [[Z]], label [[BOTH_ZERO:%.*]], label [[NOPE:%.*]]
95 ; CHECK-NEXT: call void @foo(i1 true)
96 ; CHECK-NEXT: call void @foo(i1 true)
97 ; CHECK-NEXT: call void @bar(i32 0)
98 ; CHECK-NEXT: call void @bar(i32 0)
99 ; CHECK-NEXT: ret void
101 ; CHECK-NEXT: call void @foo(i1 false)
102 ; CHECK-NEXT: ret void
104 %xz = icmp eq i32 %x, 0
105 %yz = icmp eq i32 %y, 0
107 br i1 %z, label %both_zero, label %nope
109 call void @foo(i1 %xz)
110 call void @foo(i1 %yz)
111 call void @bar(i32 %x)
112 call void @bar(i32 %y)
115 call void @foo(i1 %z)
119 define void @test3_select(i32 %x, i32 %y) {
120 ; CHECK-LABEL: @test3_select(
121 ; CHECK-NEXT: [[XZ:%.*]] = icmp eq i32 [[X:%.*]], 0
122 ; CHECK-NEXT: [[YZ:%.*]] = icmp eq i32 [[Y:%.*]], 0
123 ; CHECK-NEXT: [[Z:%.*]] = select i1 [[XZ]], i1 [[YZ]], i1 false
124 ; CHECK-NEXT: br i1 [[Z]], label [[BOTH_ZERO:%.*]], label [[NOPE:%.*]]
126 ; CHECK-NEXT: call void @foo(i1 true)
127 ; CHECK-NEXT: call void @foo(i1 true)
128 ; CHECK-NEXT: call void @bar(i32 0)
129 ; CHECK-NEXT: call void @bar(i32 0)
130 ; CHECK-NEXT: ret void
132 ; CHECK-NEXT: call void @foo(i1 false)
133 ; CHECK-NEXT: ret void
135 %xz = icmp eq i32 %x, 0
136 %yz = icmp eq i32 %y, 0
137 %z = select i1 %xz, i1 %yz, i1 false
138 br i1 %z, label %both_zero, label %nope
140 call void @foo(i1 %xz)
141 call void @foo(i1 %yz)
142 call void @bar(i32 %x)
143 call void @bar(i32 %y)
146 call void @foo(i1 %z)
150 define void @test3_or(i32 %x, i32 %y) {
151 ; CHECK-LABEL: @test3_or(
152 ; CHECK-NEXT: [[XZ:%.*]] = icmp ne i32 [[X:%.*]], 0
153 ; CHECK-NEXT: [[YZ:%.*]] = icmp ne i32 [[Y:%.*]], 0
154 ; CHECK-NEXT: [[Z:%.*]] = or i1 [[XZ]], [[YZ]]
155 ; CHECK-NEXT: br i1 [[Z]], label [[NOPE:%.*]], label [[BOTH_ZERO:%.*]]
157 ; CHECK-NEXT: call void @foo(i1 false)
158 ; CHECK-NEXT: call void @foo(i1 false)
159 ; CHECK-NEXT: call void @bar(i32 0)
160 ; CHECK-NEXT: call void @bar(i32 0)
161 ; CHECK-NEXT: ret void
163 ; CHECK-NEXT: call void @foo(i1 true)
164 ; CHECK-NEXT: ret void
166 %xz = icmp ne i32 %x, 0
167 %yz = icmp ne i32 %y, 0
169 br i1 %z, label %nope, label %both_zero
171 call void @foo(i1 %xz)
172 call void @foo(i1 %yz)
173 call void @bar(i32 %x)
174 call void @bar(i32 %y)
177 call void @foo(i1 %z)
181 define void @test3_or_select(i32 %x, i32 %y) {
182 ; CHECK-LABEL: @test3_or_select(
183 ; CHECK-NEXT: [[XZ:%.*]] = icmp ne i32 [[X:%.*]], 0
184 ; CHECK-NEXT: [[YZ:%.*]] = icmp ne i32 [[Y:%.*]], 0
185 ; CHECK-NEXT: [[Z:%.*]] = select i1 [[XZ]], i1 true, i1 [[YZ]]
186 ; CHECK-NEXT: br i1 [[Z]], label [[NOPE:%.*]], label [[BOTH_ZERO:%.*]]
188 ; CHECK-NEXT: call void @foo(i1 false)
189 ; CHECK-NEXT: call void @foo(i1 false)
190 ; CHECK-NEXT: call void @bar(i32 0)
191 ; CHECK-NEXT: call void @bar(i32 0)
192 ; CHECK-NEXT: ret void
194 ; CHECK-NEXT: call void @foo(i1 true)
195 ; CHECK-NEXT: ret void
197 %xz = icmp ne i32 %x, 0
198 %yz = icmp ne i32 %y, 0
199 %z = select i1 %xz, i1 true, i1 %yz
200 br i1 %z, label %nope, label %both_zero
202 call void @foo(i1 %xz)
203 call void @foo(i1 %yz)
204 call void @bar(i32 %x)
205 call void @bar(i32 %y)
208 call void @foo(i1 %z)
212 define void @test4(i1 %b, i32 %x) {
213 ; CHECK-LABEL: @test4(
214 ; CHECK-NEXT: br i1 [[B:%.*]], label [[SW:%.*]], label [[CASE3:%.*]]
216 ; CHECK-NEXT: switch i32 [[X:%.*]], label [[DEFAULT:%.*]] [
217 ; CHECK-NEXT: i32 0, label [[CASE0:%.*]]
218 ; CHECK-NEXT: i32 1, label [[CASE1:%.*]]
219 ; CHECK-NEXT: i32 2, label [[CASE0]]
220 ; CHECK-NEXT: i32 3, label [[CASE3]]
221 ; CHECK-NEXT: i32 4, label [[DEFAULT]]
224 ; CHECK-NEXT: call void @bar(i32 [[X]])
225 ; CHECK-NEXT: ret void
227 ; CHECK-NEXT: call void @bar(i32 [[X]])
228 ; CHECK-NEXT: ret void
230 ; CHECK-NEXT: call void @bar(i32 1)
231 ; CHECK-NEXT: ret void
233 ; CHECK-NEXT: call void @bar(i32 [[X]])
234 ; CHECK-NEXT: ret void
236 br i1 %b, label %sw, label %case3
238 switch i32 %x, label %default [
243 i32 4, label %default
246 call void @bar(i32 %x)
249 call void @bar(i32 %x)
252 call void @bar(i32 %x)
255 call void @bar(i32 %x)
259 define i1 @test5(i32 %x, i32 %y) {
260 ; CHECK-LABEL: @test5(
261 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
262 ; CHECK-NEXT: br i1 [[CMP]], label [[SAME:%.*]], label [[DIFFERENT:%.*]]
264 ; CHECK-NEXT: ret i1 false
266 ; CHECK-NEXT: ret i1 false
268 %cmp = icmp eq i32 %x, %y
269 br i1 %cmp, label %same, label %different
272 %cmp2 = icmp ne i32 %x, %y
276 %cmp3 = icmp eq i32 %x, %y
280 define i1 @test6(i32 %x, i32 %y) {
281 ; CHECK-LABEL: @test6(
282 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i32 [[X:%.*]], [[Y:%.*]]
283 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X]], [[Y]]
284 ; CHECK-NEXT: br i1 [[CMP]], label [[SAME:%.*]], label [[DIFFERENT:%.*]]
286 ; CHECK-NEXT: ret i1 false
288 ; CHECK-NEXT: ret i1 false
290 %cmp2 = icmp ne i32 %x, %y
291 %cmp = icmp eq i32 %x, %y
292 %cmp3 = icmp eq i32 %x, %y
293 br i1 %cmp, label %same, label %different
302 define i1 @test6_fp(float %x, float %y) {
303 ; CHECK-LABEL: @test6_fp(
304 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp une float [[X:%.*]], [[Y:%.*]]
305 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[X]], [[Y]]
306 ; CHECK-NEXT: br i1 [[CMP]], label [[SAME:%.*]], label [[DIFFERENT:%.*]]
308 ; CHECK-NEXT: ret i1 false
310 ; CHECK-NEXT: ret i1 false
312 %cmp2 = fcmp une float %x, %y
313 %cmp = fcmp oeq float %x, %y
314 %cmp3 = fcmp oeq float %x, %y
315 br i1 %cmp, label %same, label %different
324 define i1 @test7(i32 %x, i32 %y) {
325 ; CHECK-LABEL: @test7(
326 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]]
327 ; CHECK-NEXT: br i1 [[CMP]], label [[SAME:%.*]], label [[DIFFERENT:%.*]]
329 ; CHECK-NEXT: ret i1 false
331 ; CHECK-NEXT: ret i1 false
333 %cmp = icmp sgt i32 %x, %y
334 br i1 %cmp, label %same, label %different
337 %cmp2 = icmp sle i32 %x, %y
341 %cmp3 = icmp sgt i32 %x, %y
345 define i1 @test7_fp(float %x, float %y) {
346 ; CHECK-LABEL: @test7_fp(
347 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[X:%.*]], [[Y:%.*]]
348 ; CHECK-NEXT: br i1 [[CMP]], label [[SAME:%.*]], label [[DIFFERENT:%.*]]
350 ; CHECK-NEXT: ret i1 false
352 ; CHECK-NEXT: ret i1 false
354 %cmp = fcmp ogt float %x, %y
355 br i1 %cmp, label %same, label %different
358 %cmp2 = fcmp ule float %x, %y
362 %cmp3 = fcmp ogt float %x, %y
366 define i1 @test8(i32 %x, i32 %y) {
367 ; CHECK-LABEL: @test8(
368 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sle i32 [[X:%.*]], [[Y:%.*]]
369 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X]], [[Y]]
370 ; CHECK-NEXT: br i1 [[CMP]], label [[SAME:%.*]], label [[DIFFERENT:%.*]]
372 ; CHECK-NEXT: ret i1 false
374 ; CHECK-NEXT: ret i1 false
376 %cmp2 = icmp sle i32 %x, %y
377 %cmp = icmp sgt i32 %x, %y
378 %cmp3 = icmp sgt i32 %x, %y
379 br i1 %cmp, label %same, label %different
388 define i1 @test8_fp(float %x, float %y) {
389 ; CHECK-LABEL: @test8_fp(
390 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp ule float [[X:%.*]], [[Y:%.*]]
391 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[X]], [[Y]]
392 ; CHECK-NEXT: br i1 [[CMP]], label [[SAME:%.*]], label [[DIFFERENT:%.*]]
394 ; CHECK-NEXT: ret i1 false
396 ; CHECK-NEXT: ret i1 false
398 %cmp2 = fcmp ule float %x, %y
399 %cmp = fcmp ogt float %x, %y
400 %cmp3 = fcmp ogt float %x, %y
401 br i1 %cmp, label %same, label %different
411 define i32 @test9(i32 %i, i32 %j) {
412 ; CHECK-LABEL: @test9(
413 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I:%.*]], [[J:%.*]]
414 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[RET:%.*]]
416 ; CHECK-NEXT: ret i32 0
418 ; CHECK-NEXT: ret i32 5
420 %cmp = icmp eq i32 %i, %j
421 br i1 %cmp, label %cond_true, label %ret
424 %diff = sub i32 %i, %j
432 define i32 @test10(i32 %j, i32 %i) {
433 ; CHECK-LABEL: @test10(
434 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I:%.*]], [[J:%.*]]
435 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[RET:%.*]]
437 ; CHECK-NEXT: ret i32 0
439 ; CHECK-NEXT: ret i32 5
441 %cmp = icmp eq i32 %i, %j
442 br i1 %cmp, label %cond_true, label %ret
445 %diff = sub i32 %i, %j
452 declare i32 @yogibar()
454 define i32 @test11(i32 %x) {
455 ; CHECK-LABEL: @test11(
456 ; CHECK-NEXT: [[V0:%.*]] = call i32 @yogibar()
457 ; CHECK-NEXT: [[V1:%.*]] = call i32 @yogibar()
458 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[V0]], [[V1]]
459 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[NEXT:%.*]]
461 ; CHECK-NEXT: ret i32 [[V0]]
463 ; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[X:%.*]], [[V0]]
464 ; CHECK-NEXT: br i1 [[CMP2]], label [[COND_TRUE2:%.*]], label [[NEXT2:%.*]]
466 ; CHECK-NEXT: ret i32 [[X]]
468 ; CHECK-NEXT: ret i32 0
470 %v0 = call i32 @yogibar()
471 %v1 = call i32 @yogibar()
472 %cmp = icmp eq i32 %v0, %v1
473 br i1 %cmp, label %cond_true, label %next
479 %cmp2 = icmp eq i32 %x, %v0
480 br i1 %cmp2, label %cond_true2, label %next2
489 define i32 @test12(i32 %x) {
490 ; CHECK-LABEL: @test12(
491 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], 0
492 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
494 ; CHECK-NEXT: br label [[RET:%.*]]
496 ; CHECK-NEXT: br label [[RET]]
498 ; CHECK-NEXT: [[RES:%.*]] = phi i32 [ 0, [[COND_TRUE]] ], [ [[X]], [[COND_FALSE]] ]
499 ; CHECK-NEXT: ret i32 [[RES]]
501 %cmp = icmp eq i32 %x, 0
502 br i1 %cmp, label %cond_true, label %cond_false
511 %res = phi i32 [ %x, %cond_true ], [ %x, %cond_false ]
515 ; On the path from entry->if->end we know that ptr1==ptr2, so we can determine
516 ; that gep2 does not alias ptr1 on that path (as it would require that
517 ; ptr2==ptr2+2), so we can perform PRE of the load.
518 define i32 @test13(ptr %ptr1, ptr %ptr2) {
519 ; CHECK-LABEL: @test13(
521 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i32, ptr [[PTR2:%.*]], i32 1
522 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i32, ptr [[PTR2]], i32 2
523 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[PTR1:%.*]], [[PTR2]]
524 ; CHECK-NEXT: br i1 [[CMP]], label [[IF:%.*]], label [[END:%.*]]
526 ; CHECK-NEXT: [[VAL1:%.*]] = load i32, ptr [[GEP2]], align 4
527 ; CHECK-NEXT: br label [[END]]
529 ; CHECK-NEXT: [[PHI1:%.*]] = phi ptr [ [[PTR1]], [[IF]] ], [ [[GEP1]], [[ENTRY:%.*]] ]
530 ; CHECK-NEXT: [[PHI2:%.*]] = phi i32 [ [[VAL1]], [[IF]] ], [ 0, [[ENTRY]] ]
531 ; CHECK-NEXT: store i32 0, ptr [[PHI1]], align 4
532 ; CHECK-NEXT: [[VAL2:%.*]] = load i32, ptr [[GEP2]], align 4
533 ; CHECK-NEXT: [[RET:%.*]] = add i32 [[PHI2]], [[VAL2]]
534 ; CHECK-NEXT: ret i32 [[RET]]
537 %gep1 = getelementptr i32, ptr %ptr2, i32 1
538 %gep2 = getelementptr i32, ptr %ptr2, i32 2
539 %cmp = icmp eq ptr %ptr1, %ptr2
540 br i1 %cmp, label %if, label %end
544 %val1 = load i32, ptr %gep2, align 4
548 %phi1 = phi ptr [ %ptr1, %if ], [ %gep1, %entry ]
549 %phi2 = phi i32 [ %val1, %if ], [ 0, %entry ]
550 store i32 0, ptr %phi1, align 4
551 %val2 = load i32, ptr %gep2, align 4
552 %ret = add i32 %phi2, %val2
556 define void @test14(ptr %ptr1, ptr noalias %ptr2, i1 %b1, i1 %b2) {
557 ; CHECK-LABEL: @test14(
559 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i32, ptr [[PTR1:%.*]], i32 1
560 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i32, ptr [[PTR1]], i32 2
561 ; CHECK-NEXT: br label [[LOOP:%.*]]
563 ; CHECK-NEXT: br i1 [[B1:%.*]], label [[LOOP_IF1_CRIT_EDGE:%.*]], label [[THEN:%.*]]
564 ; CHECK: loop.if1_crit_edge:
565 ; CHECK-NEXT: [[VAL2_PRE:%.*]] = load i32, ptr [[GEP2]], align 4
566 ; CHECK-NEXT: br label [[IF1:%.*]]
568 ; CHECK-NEXT: [[VAL2:%.*]] = phi i32 [ [[VAL2_PRE]], [[LOOP_IF1_CRIT_EDGE]] ], [ [[VAL3:%.*]], [[LOOP_END:%.*]] ]
569 ; CHECK-NEXT: store i32 [[VAL2]], ptr [[GEP2]], align 4
570 ; CHECK-NEXT: store i32 0, ptr [[GEP1]], align 4
571 ; CHECK-NEXT: br label [[THEN]]
573 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[GEP2]], [[PTR2:%.*]]
574 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_END]], label [[IF2:%.*]]
576 ; CHECK-NEXT: br label [[LOOP_END]]
578 ; CHECK-NEXT: [[PHI3:%.*]] = phi ptr [ [[GEP2]], [[THEN]] ], [ [[PTR1]], [[IF2]] ]
579 ; CHECK-NEXT: [[VAL3]] = load i32, ptr [[GEP2]], align 4
580 ; CHECK-NEXT: store i32 [[VAL3]], ptr [[PHI3]], align 4
581 ; CHECK-NEXT: br i1 [[B2:%.*]], label [[LOOP]], label [[IF1]]
584 %gep1 = getelementptr inbounds i32, ptr %ptr1, i32 1
585 %gep2 = getelementptr inbounds i32, ptr %ptr1, i32 2
589 %phi1 = phi ptr [ %gep3, %loop.end ], [ %gep1, %entry ]
590 br i1 %b1, label %if1, label %then
594 %val2 = load i32, ptr %gep2, align 4
595 store i32 %val2, ptr %gep2, align 4
596 store i32 0, ptr %phi1, align 4
600 %cmp = icmp eq ptr %gep2, %ptr2
601 br i1 %cmp, label %loop.end, label %if2
607 %phi3 = phi ptr [ %gep2, %then ], [ %ptr1, %if2 ]
608 %val3 = load i32, ptr %gep2, align 4
609 store i32 %val3, ptr %phi3, align 4
610 %gep3 = getelementptr inbounds i32, ptr %ptr1, i32 1
611 br i1 %b2, label %loop, label %if1
614 ; Make sure that the call to use_ptr does not have %p1
615 define void @single_phi1(ptr %p0, ptr %p1, i8 %s) {
616 ; CHECK-LABEL: @single_phi1(
618 ; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P0:%.*]], align 8
619 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq ptr [[P2]], [[P1:%.*]]
620 ; CHECK-NEXT: br i1 [[CMP1]], label [[BB4:%.*]], label [[BB1:%.*]]
622 ; CHECK-NEXT: switch i8 [[S:%.*]], label [[BB2:%.*]] [
623 ; CHECK-NEXT: i8 0, label [[BB1]]
624 ; CHECK-NEXT: i8 1, label [[BB3:%.*]]
627 ; CHECK-NEXT: unreachable
629 ; CHECK-NEXT: br label [[BB4]]
631 ; CHECK-NEXT: call void @use_bool(i1 [[CMP1]])
632 ; CHECK-NEXT: call void @use_ptr(ptr [[P2]])
633 ; CHECK-NEXT: ret void
636 %p2 = load ptr, ptr %p0, align 8
637 %cmp1 = icmp eq ptr %p2, %p1
638 br i1 %cmp1, label %bb4, label %bb1
641 switch i8 %s, label %bb2 [
653 %phi1 = phi ptr [ %p2, %entry ], [ %p2, %bb3 ]
654 %cmp2 = icmp eq ptr %phi1, %p1
655 call void @use_bool(i1 %cmp2)
656 call void @use_ptr(ptr %phi1)
660 define void @single_phi2(ptr %p0, ptr %p1, i8 %s) {
661 ; CHECK-LABEL: @single_phi2(
663 ; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P0:%.*]], align 8
664 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq ptr [[P2]], [[P1:%.*]]
665 ; CHECK-NEXT: br i1 [[CMP1]], label [[BB4:%.*]], label [[BB1:%.*]]
667 ; CHECK-NEXT: switch i8 [[S:%.*]], label [[BB2:%.*]] [
668 ; CHECK-NEXT: i8 0, label [[BB1]]
669 ; CHECK-NEXT: i8 1, label [[BB3:%.*]]
672 ; CHECK-NEXT: br label [[BB4]]
674 ; CHECK-NEXT: br label [[BB4]]
676 ; CHECK-NEXT: call void @use_bool(i1 [[CMP1]])
677 ; CHECK-NEXT: call void @use_ptr(ptr [[P2]])
678 ; CHECK-NEXT: ret void
681 %p2 = load ptr, ptr %p0, align 8
682 %cmp1 = icmp eq ptr %p2, %p1
683 br i1 %cmp1, label %bb4, label %bb1
686 switch i8 %s, label %bb2 [
698 %phi1 = phi ptr [ %p2, %entry ], [ %p2, %bb2 ], [ %p2, %bb3 ]
699 %cmp2 = icmp eq ptr %phi1, %p1
700 call void @use_bool(i1 %cmp2)
701 call void @use_ptr(ptr %phi1)
705 define void @multiple_phi1(ptr %p0, ptr %p1, i8 %s) {
706 ; CHECK-LABEL: @multiple_phi1(
708 ; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P0:%.*]], align 8
709 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq ptr [[P2]], [[P1:%.*]]
710 ; CHECK-NEXT: br i1 [[CMP1]], label [[BB4:%.*]], label [[BB1:%.*]]
712 ; CHECK-NEXT: switch i8 [[S:%.*]], label [[BB2:%.*]] [
713 ; CHECK-NEXT: i8 0, label [[BB1]]
714 ; CHECK-NEXT: i8 1, label [[BB3:%.*]]
717 ; CHECK-NEXT: unreachable
719 ; CHECK-NEXT: br label [[BB4]]
721 ; CHECK-NEXT: call void @use_bool(i1 [[CMP1]])
722 ; CHECK-NEXT: br label [[BB5:%.*]]
724 ; CHECK-NEXT: call void @use_ptr(ptr [[P2]])
725 ; CHECK-NEXT: br label [[BB5]]
728 %p2 = load ptr, ptr %p0, align 8
729 %cmp1 = icmp eq ptr %p2, %p1
730 br i1 %cmp1, label %bb4, label %bb1
733 switch i8 %s, label %bb2 [
745 %phi1 = phi ptr [ %p2, %entry ], [ poison, %bb3 ]
746 %cmp2 = icmp eq ptr %phi1, %p1
747 call void @use_bool(i1 %cmp2)
751 %phi2 = phi ptr [ poison, %bb5 ], [ %phi1, %bb4 ]
752 call void @use_ptr(ptr %phi2)
756 define void @multiple_phi2(ptr %p0, ptr %p1, i8 %s) {
757 ; CHECK-LABEL: @multiple_phi2(
759 ; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P0:%.*]], align 8
760 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq ptr [[P2]], [[P1:%.*]]
761 ; CHECK-NEXT: br i1 [[CMP1]], label [[BB4:%.*]], label [[BB1:%.*]]
763 ; CHECK-NEXT: switch i8 [[S:%.*]], label [[BB2:%.*]] [
764 ; CHECK-NEXT: i8 0, label [[BB1]]
765 ; CHECK-NEXT: i8 1, label [[BB3:%.*]]
768 ; CHECK-NEXT: br label [[BB4]]
770 ; CHECK-NEXT: br label [[BB4]]
772 ; CHECK-NEXT: call void @use_bool(i1 [[CMP1]])
773 ; CHECK-NEXT: br label [[BB5:%.*]]
775 ; CHECK-NEXT: call void @use_ptr(ptr [[P2]])
776 ; CHECK-NEXT: br label [[BB5]]
779 %p2 = load ptr, ptr %p0, align 8
780 %cmp1 = icmp eq ptr %p2, %p1
781 br i1 %cmp1, label %bb4, label %bb1
784 switch i8 %s, label %bb2 [
796 %phi1 = phi ptr [ %p2, %entry ], [ %p2, %bb2 ], [ poison, %bb3 ]
797 %cmp2 = icmp eq ptr %phi1, %p1
798 call void @use_bool(i1 %cmp2)
802 %phi2 = phi ptr [ poison, %bb5 ], [ %phi1, %bb4 ]
803 call void @use_ptr(ptr %phi2)
807 define void @select_same_obj(i1 %c, ptr %p, i64 %x) {
808 ; CHECK-LABEL: @select_same_obj(
810 ; CHECK-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 [[X:%.*]]
811 ; CHECK-NEXT: [[P3:%.*]] = select i1 [[C:%.*]], ptr [[P]], ptr [[P2]]
812 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[P]], [[P3]]
813 ; CHECK-NEXT: br i1 [[CMP]], label [[IF:%.*]], label [[EXIT:%.*]]
815 ; CHECK-NEXT: call void @use_ptr(ptr [[P]])
816 ; CHECK-NEXT: call void @use_ptr(ptr [[P]])
817 ; CHECK-NEXT: ret void
819 ; CHECK-NEXT: ret void
822 %p2 = getelementptr i8, ptr %p, i64 %x
823 %p3 = select i1 %c, ptr %p, ptr %p2
824 %cmp = icmp eq ptr %p, %p3
825 br i1 %cmp, label %if, label %exit
828 call void @use_ptr(ptr %p)
829 call void @use_ptr(ptr %p3)
836 define void @select_different_obj(i1 %c, ptr %p, ptr %p2) {
837 ; CHECK-LABEL: @select_different_obj(
839 ; CHECK-NEXT: [[P3:%.*]] = select i1 [[C:%.*]], ptr [[P:%.*]], ptr [[P2:%.*]]
840 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[P]], [[P3]]
841 ; CHECK-NEXT: br i1 [[CMP]], label [[IF:%.*]], label [[EXIT:%.*]]
843 ; CHECK-NEXT: call void @use_ptr(ptr [[P]])
844 ; CHECK-NEXT: call void @use_ptr(ptr [[P3]])
845 ; CHECK-NEXT: ret void
847 ; CHECK-NEXT: ret void
850 %p3 = select i1 %c, ptr %p, ptr %p2
851 %cmp = icmp eq ptr %p, %p3
852 br i1 %cmp, label %if, label %exit
855 call void @use_ptr(ptr %p)
856 call void @use_ptr(ptr %p3)
863 define void @select_same_obj_is_select(i1 %c, ptr %p, ptr %p2, i64 %x) {
864 ; CHECK-LABEL: @select_same_obj_is_select(
866 ; CHECK-NEXT: [[P3:%.*]] = select i1 [[C:%.*]], ptr [[P:%.*]], ptr [[P2:%.*]]
867 ; CHECK-NEXT: [[P4:%.*]] = getelementptr i8, ptr [[P3]], i64 [[X:%.*]]
868 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[P3]], [[P4]]
869 ; CHECK-NEXT: br i1 [[CMP]], label [[IF:%.*]], label [[EXIT:%.*]]
871 ; CHECK-NEXT: call void @use_ptr(ptr [[P3]])
872 ; CHECK-NEXT: call void @use_ptr(ptr [[P3]])
873 ; CHECK-NEXT: ret void
875 ; CHECK-NEXT: ret void
878 %p3 = select i1 %c, ptr %p, ptr %p2
879 %p4 = getelementptr i8, ptr %p3, i64 %x
880 %cmp = icmp eq ptr %p3, %p4
881 br i1 %cmp, label %if, label %exit
884 call void @use_ptr(ptr %p3)
885 call void @use_ptr(ptr %p4)
892 define void @phi_same_obj(i1 %c, ptr %p, i64 %x) {
893 ; CHECK-LABEL: @phi_same_obj(
895 ; CHECK-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 [[X:%.*]]
896 ; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[JOIN:%.*]]
898 ; CHECK-NEXT: br label [[JOIN]]
900 ; CHECK-NEXT: [[P3:%.*]] = phi ptr [ [[P]], [[IF]] ], [ [[P2]], [[ENTRY:%.*]] ]
901 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[P]], [[P3]]
902 ; CHECK-NEXT: br i1 [[CMP]], label [[IF2:%.*]], label [[EXIT:%.*]]
904 ; CHECK-NEXT: call void @use_ptr(ptr [[P]])
905 ; CHECK-NEXT: call void @use_ptr(ptr [[P]])
906 ; CHECK-NEXT: ret void
908 ; CHECK-NEXT: ret void
911 %p2 = getelementptr i8, ptr %p, i64 %x
912 br i1 %c, label %if, label %join
918 %p3 = phi ptr [ %p, %if ], [ %p2, %entry ]
919 %cmp = icmp eq ptr %p, %p3
920 br i1 %cmp, label %if2, label %exit
923 call void @use_ptr(ptr %p)
924 call void @use_ptr(ptr %p3)
931 define void @phi_different_obj(i1 %c, ptr %p, ptr %p2) {
932 ; CHECK-LABEL: @phi_different_obj(
934 ; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[JOIN:%.*]]
936 ; CHECK-NEXT: br label [[JOIN]]
938 ; CHECK-NEXT: [[P3:%.*]] = phi ptr [ [[P:%.*]], [[IF]] ], [ [[P2:%.*]], [[ENTRY:%.*]] ]
939 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[P]], [[P3]]
940 ; CHECK-NEXT: br i1 [[CMP]], label [[IF2:%.*]], label [[EXIT:%.*]]
942 ; CHECK-NEXT: call void @use_ptr(ptr [[P]])
943 ; CHECK-NEXT: call void @use_ptr(ptr [[P3]])
944 ; CHECK-NEXT: ret void
946 ; CHECK-NEXT: ret void
949 br i1 %c, label %if, label %join
955 %p3 = phi ptr [ %p, %if ], [ %p2, %entry ]
956 %cmp = icmp eq ptr %p, %p3
957 br i1 %cmp, label %if2, label %exit
960 call void @use_ptr(ptr %p)
961 call void @use_ptr(ptr %p3)
968 define void @phi_same_obj_cycle(i1 %c, ptr %p, i64 %x) {
969 ; CHECK-LABEL: @phi_same_obj_cycle(
971 ; CHECK-NEXT: br label [[LOOP:%.*]]
973 ; CHECK-NEXT: [[P_IV:%.*]] = phi ptr [ [[P:%.*]], [[ENTRY:%.*]] ], [ [[P_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
974 ; CHECK-NEXT: [[P_NEXT]] = getelementptr i8, ptr [[P_IV]], i64 [[X:%.*]]
975 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[P_IV]], [[P]]
976 ; CHECK-NEXT: br i1 [[CMP]], label [[IF:%.*]], label [[LOOP_LATCH]]
978 ; CHECK-NEXT: call void @use_ptr(ptr [[P]])
979 ; CHECK-NEXT: call void @use_ptr(ptr [[P]])
980 ; CHECK-NEXT: br label [[LOOP_LATCH]]
982 ; CHECK-NEXT: br label [[LOOP]]
988 %p.iv = phi ptr [ %p, %entry ], [ %p.next, %loop.latch ]
989 %p.next = getelementptr i8, ptr %p.iv, i64 %x
990 %cmp = icmp eq ptr %p.iv, %p
991 br i1 %cmp, label %if, label %loop.latch
994 call void @use_ptr(ptr %p.iv)
995 call void @use_ptr(ptr %p)
1002 declare void @use_bool(i1)
1003 declare void @use_ptr(ptr)