1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -sink-common-insts -S | FileCheck %s
3 ; RUN: opt < %s -passes='simplifycfg<sink-common-insts>' -S | FileCheck %s
5 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
6 target triple = "x86_64-pc-linux-gnu"
8 define zeroext i1 @test1(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) {
11 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[NBLKS:%.*]], [[BLKSB:%.*]]
12 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ule i32 [[ADD]], [[BLKSA:%.*]]
13 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge i32 [[BLKSA]], [[NBLKS]]
14 ; CHECK-NEXT: [[CMP2_SINK:%.*]] = select i1 [[FLAG:%.*]], i1 [[CMP]], i1 [[CMP2]]
15 ; CHECK-NEXT: [[FROMBOOL3:%.*]] = zext i1 [[CMP2_SINK]] to i8
16 ; CHECK-NEXT: [[TOBOOL4:%.*]] = icmp ne i8 [[FROMBOOL3]], 0
17 ; CHECK-NEXT: ret i1 [[TOBOOL4]]
20 br i1 %flag, label %if.then, label %if.else
23 %cmp = icmp uge i32 %blksA, %nblks
24 %frombool1 = zext i1 %cmp to i8
28 %add = add i32 %nblks, %blksB
29 %cmp2 = icmp ule i32 %add, %blksA
30 %frombool3 = zext i1 %cmp2 to i8
34 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ]
35 %tobool4 = icmp ne i8 %obeys.0, 0
39 define zeroext i1 @test2(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) {
40 ; CHECK-LABEL: @test2(
42 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[NBLKS:%.*]], [[BLKSB:%.*]]
43 ; CHECK-NEXT: [[ADD_SINK:%.*]] = select i1 [[FLAG:%.*]], i32 [[NBLKS]], i32 [[ADD]]
44 ; CHECK-NEXT: [[CMP2:%.*]] = icmp uge i32 [[BLKSA:%.*]], [[ADD_SINK]]
45 ; CHECK-NEXT: [[FROMBOOL3:%.*]] = zext i1 [[CMP2]] to i8
46 ; CHECK-NEXT: [[TOBOOL4:%.*]] = icmp ne i8 [[FROMBOOL3]], 0
47 ; CHECK-NEXT: ret i1 [[TOBOOL4]]
50 br i1 %flag, label %if.then, label %if.else
53 %cmp = icmp uge i32 %blksA, %nblks
54 %frombool1 = zext i1 %cmp to i8
58 %add = add i32 %nblks, %blksB
59 %cmp2 = icmp uge i32 %blksA, %add
60 %frombool3 = zext i1 %cmp2 to i8
64 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ]
65 %tobool4 = icmp ne i8 %obeys.0, 0
69 declare i32 @foo(i32, i32) nounwind readnone
71 define i32 @test3(i1 zeroext %flag, i32 %x, i32 %y) {
72 ; CHECK-LABEL: @test3(
74 ; CHECK-NEXT: [[X_Y:%.*]] = select i1 [[FLAG:%.*]], i32 [[X:%.*]], i32 [[Y:%.*]]
75 ; CHECK-NEXT: [[X1:%.*]] = call i32 @foo(i32 [[X_Y]], i32 0) #[[ATTR0:[0-9]+]]
76 ; CHECK-NEXT: [[Y1:%.*]] = call i32 @foo(i32 [[X_Y]], i32 1) #[[ATTR0]]
77 ; CHECK-NEXT: [[RET:%.*]] = add i32 [[X1]], [[Y1]]
78 ; CHECK-NEXT: ret i32 [[RET]]
81 br i1 %flag, label %if.then, label %if.else
84 %x0 = call i32 @foo(i32 %x, i32 0) nounwind readnone
85 %y0 = call i32 @foo(i32 %x, i32 1) nounwind readnone
89 %x1 = call i32 @foo(i32 %y, i32 0) nounwind readnone
90 %y1 = call i32 @foo(i32 %y, i32 1) nounwind readnone
94 %xx = phi i32 [ %x0, %if.then ], [ %x1, %if.else ]
95 %yy = phi i32 [ %y0, %if.then ], [ %y1, %if.else ]
96 %ret = add i32 %xx, %yy
101 define i32 @test4(i1 zeroext %flag, i32 %x, ptr %y) {
102 ; CHECK-LABEL: @test4(
104 ; CHECK-NEXT: [[DOT:%.*]] = select i1 [[FLAG:%.*]], i32 5, i32 7
105 ; CHECK-NEXT: [[B:%.*]] = add i32 [[X:%.*]], [[DOT]]
106 ; CHECK-NEXT: store i32 [[B]], ptr [[Y:%.*]], align 4
107 ; CHECK-NEXT: ret i32 1
110 br i1 %flag, label %if.then, label %if.else
127 define i32 @test5(i1 zeroext %flag, i32 %x, ptr %y) {
128 ; CHECK-LABEL: @test5(
130 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
132 ; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], 5
133 ; CHECK-NEXT: store volatile i32 [[A]], ptr [[Y:%.*]], align 4
134 ; CHECK-NEXT: br label [[IF_END:%.*]]
136 ; CHECK-NEXT: [[B:%.*]] = add i32 [[X]], 7
137 ; CHECK-NEXT: store i32 [[B]], ptr [[Y]], align 4
138 ; CHECK-NEXT: br label [[IF_END]]
140 ; CHECK-NEXT: ret i32 1
143 br i1 %flag, label %if.then, label %if.else
147 store volatile i32 %a, ptr %y
160 define i32 @test6(i1 zeroext %flag, i32 %x, ptr %y) {
161 ; CHECK-LABEL: @test6(
163 ; CHECK-NEXT: [[DOT:%.*]] = select i1 [[FLAG:%.*]], i32 5, i32 7
164 ; CHECK-NEXT: [[B:%.*]] = add i32 [[X:%.*]], [[DOT]]
165 ; CHECK-NEXT: store volatile i32 [[B]], ptr [[Y:%.*]], align 4
166 ; CHECK-NEXT: ret i32 1
169 br i1 %flag, label %if.then, label %if.else
173 store volatile i32 %a, ptr %y
178 store volatile i32 %b, ptr %y
186 define i32 @test7(i1 zeroext %flag, i32 %x, ptr %y) {
187 ; CHECK-LABEL: @test7(
189 ; CHECK-NEXT: [[DOT:%.*]] = select i1 [[FLAG:%.*]], i32 5, i32 7
190 ; CHECK-NEXT: [[W:%.*]] = load volatile i32, ptr [[Y:%.*]], align 4
191 ; CHECK-NEXT: [[B:%.*]] = add i32 [[W]], [[DOT]]
192 ; CHECK-NEXT: store volatile i32 [[B]], ptr [[Y]], align 4
193 ; CHECK-NEXT: ret i32 1
196 br i1 %flag, label %if.then, label %if.else
199 %z = load volatile i32, ptr %y
201 store volatile i32 %a, ptr %y
205 %w = load volatile i32, ptr %y
207 store volatile i32 %b, ptr %y
215 ; %z and %w are in different blocks. We shouldn't sink the add because
216 ; there may be intervening memory instructions.
217 define i32 @test8(i1 zeroext %flag, i32 %x, ptr %y) {
218 ; CHECK-LABEL: @test8(
220 ; CHECK-NEXT: [[Z:%.*]] = load volatile i32, ptr [[Y:%.*]], align 4
221 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
223 ; CHECK-NEXT: [[A:%.*]] = add i32 [[Z]], 5
224 ; CHECK-NEXT: br label [[IF_END:%.*]]
226 ; CHECK-NEXT: [[W:%.*]] = load volatile i32, ptr [[Y]], align 4
227 ; CHECK-NEXT: [[B:%.*]] = add i32 [[W]], 7
228 ; CHECK-NEXT: br label [[IF_END]]
230 ; CHECK-NEXT: [[B_SINK:%.*]] = phi i32 [ [[B]], [[IF_ELSE]] ], [ [[A]], [[IF_THEN]] ]
231 ; CHECK-NEXT: store volatile i32 [[B_SINK]], ptr [[Y]], align 4
232 ; CHECK-NEXT: ret i32 1
235 %z = load volatile i32, ptr %y
236 br i1 %flag, label %if.then, label %if.else
240 store volatile i32 %a, ptr %y
244 %w = load volatile i32, ptr %y
246 store volatile i32 %b, ptr %y
254 ; The extra store in %if.then means %z and %w are not equivalent.
255 define i32 @test9(i1 zeroext %flag, i32 %x, ptr %y, ptr %p) {
256 ; CHECK-LABEL: @test9(
258 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
260 ; CHECK-NEXT: store i32 7, ptr [[P:%.*]], align 4
261 ; CHECK-NEXT: [[Z:%.*]] = load volatile i32, ptr [[Y:%.*]], align 4
262 ; CHECK-NEXT: store i32 6, ptr [[P]], align 4
263 ; CHECK-NEXT: [[A:%.*]] = add i32 [[Z]], 5
264 ; CHECK-NEXT: br label [[IF_END:%.*]]
266 ; CHECK-NEXT: [[W:%.*]] = load volatile i32, ptr [[Y]], align 4
267 ; CHECK-NEXT: [[B:%.*]] = add i32 [[W]], 7
268 ; CHECK-NEXT: br label [[IF_END]]
270 ; CHECK-NEXT: [[B_SINK:%.*]] = phi i32 [ [[B]], [[IF_ELSE]] ], [ [[A]], [[IF_THEN]] ]
271 ; CHECK-NEXT: store volatile i32 [[B_SINK]], ptr [[Y]], align 4
272 ; CHECK-NEXT: ret i32 1
275 br i1 %flag, label %if.then, label %if.else
279 %z = load volatile i32, ptr %y
282 store volatile i32 %a, ptr %y
286 %w = load volatile i32, ptr %y
288 store volatile i32 %b, ptr %y
296 %struct.anon = type { i32, i32 }
298 ; The GEP indexes a struct type so cannot have a variable last index.
299 define i32 @test10(i1 zeroext %flag, i32 %x, ptr %y, ptr %s) {
300 ; CHECK-LABEL: @test10(
302 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
304 ; CHECK-NEXT: call void @bar(i32 5)
305 ; CHECK-NEXT: br label [[IF_END:%.*]]
307 ; CHECK-NEXT: call void @bar(i32 6)
308 ; CHECK-NEXT: [[GEPB:%.*]] = getelementptr inbounds [[STRUCT_ANON:%.*]], ptr [[S:%.*]], i32 0, i32 1
309 ; CHECK-NEXT: br label [[IF_END]]
311 ; CHECK-NEXT: [[GEPB_SINK:%.*]] = phi ptr [ [[GEPB]], [[IF_ELSE]] ], [ [[S]], [[IF_THEN]] ]
312 ; CHECK-NEXT: store volatile i32 [[X:%.*]], ptr [[GEPB_SINK]], align 4
313 ; CHECK-NEXT: ret i32 1
316 br i1 %flag, label %if.then, label %if.else
319 call void @bar(i32 5)
320 store volatile i32 %x, ptr %s
324 call void @bar(i32 6)
325 %gepb = getelementptr inbounds %struct.anon, ptr %s, i32 0, i32 1
326 store volatile i32 %x, ptr %gepb
334 ; The shufflevector's mask operand cannot be merged in a PHI.
335 define i32 @test11(i1 zeroext %flag, i32 %w, <2 x i32> %x, <2 x i32> %y) {
336 ; CHECK-LABEL: @test11(
338 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
340 ; CHECK-NEXT: [[DUMMY:%.*]] = add i32 [[W:%.*]], 5
341 ; CHECK-NEXT: [[SV1:%.*]] = shufflevector <2 x i32> [[X:%.*]], <2 x i32> [[Y:%.*]], <2 x i32> <i32 0, i32 1>
342 ; CHECK-NEXT: br label [[IF_END:%.*]]
344 ; CHECK-NEXT: [[DUMMY1:%.*]] = add i32 [[W]], 6
345 ; CHECK-NEXT: [[SV2:%.*]] = shufflevector <2 x i32> [[X]], <2 x i32> [[Y]], <2 x i32> <i32 1, i32 0>
346 ; CHECK-NEXT: br label [[IF_END]]
348 ; CHECK-NEXT: [[P:%.*]] = phi <2 x i32> [ [[SV1]], [[IF_THEN]] ], [ [[SV2]], [[IF_ELSE]] ]
349 ; CHECK-NEXT: ret i32 1
352 br i1 %flag, label %if.then, label %if.else
355 %dummy = add i32 %w, 5
356 %sv1 = shufflevector <2 x i32> %x, <2 x i32> %y, <2 x i32> <i32 0, i32 1>
360 %dummy1 = add i32 %w, 6
361 %sv2 = shufflevector <2 x i32> %x, <2 x i32> %y, <2 x i32> <i32 1, i32 0>
365 %p = phi <2 x i32> [ %sv1, %if.then ], [ %sv2, %if.else ]
370 ; We can't common an intrinsic!
371 define i32 @test12(i1 zeroext %flag, i32 %w, i32 %x, i32 %y) {
372 ; CHECK-LABEL: @test12(
374 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
376 ; CHECK-NEXT: [[DUMMY:%.*]] = add i32 [[W:%.*]], 5
377 ; CHECK-NEXT: [[SV1:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X:%.*]], i1 false)
378 ; CHECK-NEXT: br label [[IF_END:%.*]]
380 ; CHECK-NEXT: [[DUMMY1:%.*]] = add i32 [[W]], 6
381 ; CHECK-NEXT: [[SV2:%.*]] = call i32 @llvm.cttz.i32(i32 [[X]], i1 false)
382 ; CHECK-NEXT: br label [[IF_END]]
384 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ [[SV1]], [[IF_THEN]] ], [ [[SV2]], [[IF_ELSE]] ]
385 ; CHECK-NEXT: ret i32 1
388 br i1 %flag, label %if.then, label %if.else
391 %dummy = add i32 %w, 5
392 %sv1 = call i32 @llvm.ctlz.i32(i32 %x, i1 false)
396 %dummy1 = add i32 %w, 6
397 %sv2 = call i32 @llvm.cttz.i32(i32 %x, i1 false)
401 %p = phi i32 [ %sv1, %if.then ], [ %sv2, %if.else ]
405 declare i32 @llvm.ctlz.i32(i32 %x, i1 immarg) readnone
406 declare i32 @llvm.cttz.i32(i32 %x, i1 immarg) readnone
409 ; The TBAA metadata should be properly combined.
410 define i32 @test13(i1 zeroext %flag, i32 %x, ptr %y) {
411 ; CHECK-LABEL: @test13(
413 ; CHECK-NEXT: [[DOT:%.*]] = select i1 [[FLAG:%.*]], i32 5, i32 7
414 ; CHECK-NEXT: [[W:%.*]] = load volatile i32, ptr [[Y:%.*]], align 4
415 ; CHECK-NEXT: [[B:%.*]] = add i32 [[W]], [[DOT]]
416 ; CHECK-NEXT: store volatile i32 [[B]], ptr [[Y]], align 4, !tbaa [[TBAA4:![0-9]+]]
417 ; CHECK-NEXT: ret i32 1
420 br i1 %flag, label %if.then, label %if.else
423 %z = load volatile i32, ptr %y
425 store volatile i32 %a, ptr %y, !tbaa !3
429 %w = load volatile i32, ptr %y
431 store volatile i32 %b, ptr %y, !tbaa !4
438 !0 = !{ !"an example type tree" }
440 !2 = !{ !"float", !0 }
441 !3 = !{ !"const float", !2, i64 0 }
442 !4 = !{ !"special float", !2, i64 1 }
445 ; The call should be commoned.
446 define i32 @test13a(i1 zeroext %flag, i32 %w, i32 %x, i32 %y) {
447 ; CHECK-LABEL: @test13a(
449 ; CHECK-NEXT: [[X_Y:%.*]] = select i1 [[FLAG:%.*]], i32 [[X:%.*]], i32 [[Y:%.*]]
450 ; CHECK-NEXT: [[SV2:%.*]] = call i32 @bar(i32 [[X_Y]])
451 ; CHECK-NEXT: ret i32 1
454 br i1 %flag, label %if.then, label %if.else
457 %sv1 = call i32 @bar(i32 %x)
461 %sv2 = call i32 @bar(i32 %y)
465 %p = phi i32 [ %sv1, %if.then ], [ %sv2, %if.else ]
468 declare i32 @bar(i32)
471 ; The load should be commoned.
472 define i32 @test14(i1 zeroext %flag, i32 %w, i32 %x, i32 %y, ptr %s) {
473 ; CHECK-LABEL: @test14(
475 ; CHECK-NEXT: [[DOT:%.*]] = select i1 [[FLAG:%.*]], i32 1, i32 4
476 ; CHECK-NEXT: [[DOT2:%.*]] = select i1 [[FLAG]], i32 56, i32 57
477 ; CHECK-NEXT: [[DUMMY2:%.*]] = add i32 [[X:%.*]], [[DOT]]
478 ; CHECK-NEXT: [[GEPB:%.*]] = getelementptr inbounds [[STRUCT_ANON:%.*]], ptr [[S:%.*]], i32 0, i32 1
479 ; CHECK-NEXT: [[SV2:%.*]] = load i32, ptr [[GEPB]], align 4
480 ; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[SV2]], [[DOT2]]
481 ; CHECK-NEXT: ret i32 1
484 br i1 %flag, label %if.then, label %if.else
487 %dummy = add i32 %x, 1
488 %gepa = getelementptr inbounds %struct.anon, ptr %s, i32 0, i32 1
489 %sv1 = load i32, ptr %gepa
490 %cmp1 = icmp eq i32 %sv1, 56
494 %dummy2 = add i32 %x, 4
495 %gepb = getelementptr inbounds %struct.anon, ptr %s, i32 0, i32 1
496 %sv2 = load i32, ptr %gepb
497 %cmp2 = icmp eq i32 %sv2, 57
498 call void @llvm.dbg.value(metadata i32 0, metadata !9, metadata !DIExpression()), !dbg !11
502 %p = phi i1 [ %cmp1, %if.then ], [ %cmp2, %if.else ]
506 declare void @llvm.dbg.value(metadata, metadata, metadata)
507 !llvm.module.flags = !{!5, !6}
510 !5 = !{i32 2, !"Dwarf Version", i32 4}
511 !6 = !{i32 2, !"Debug Info Version", i32 3}
512 !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !10)
513 !8 = distinct !DISubprogram(name: "foo", unit: !7)
514 !9 = !DILocalVariable(name: "b", line: 1, arg: 2, scope: !8)
515 !10 = !DIFile(filename: "a.c", directory: "a/b")
516 !11 = !DILocation(line: 1, column: 14, scope: !8)
519 ; The load should be commoned.
520 define i32 @test15(i1 zeroext %flag, i32 %w, i32 %x, i32 %y, ptr %s) {
521 ; CHECK-LABEL: @test15(
523 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
525 ; CHECK-NEXT: call void @bar(i32 1)
526 ; CHECK-NEXT: br label [[IF_END:%.*]]
528 ; CHECK-NEXT: call void @bar(i32 4)
529 ; CHECK-NEXT: [[GEPB:%.*]] = getelementptr inbounds [[STRUCT_ANON:%.*]], ptr [[S:%.*]], i32 0, i32 1
530 ; CHECK-NEXT: br label [[IF_END]]
532 ; CHECK-NEXT: [[GEPB_SINK:%.*]] = phi ptr [ [[GEPB]], [[IF_ELSE]] ], [ [[S]], [[IF_THEN]] ]
533 ; CHECK-NEXT: [[DOTSINK:%.*]] = phi i64 [ 57, [[IF_ELSE]] ], [ 56, [[IF_THEN]] ]
534 ; CHECK-NEXT: [[SV2:%.*]] = load i32, ptr [[GEPB_SINK]], align 4
535 ; CHECK-NEXT: [[EXT2:%.*]] = zext i32 [[SV2]] to i64
536 ; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i64 [[EXT2]], [[DOTSINK]]
537 ; CHECK-NEXT: ret i32 1
540 br i1 %flag, label %if.then, label %if.else
543 call void @bar(i32 1)
544 %sv1 = load i32, ptr %s
545 %ext1 = zext i32 %sv1 to i64
546 %cmp1 = icmp eq i64 %ext1, 56
550 call void @bar(i32 4)
551 %gepb = getelementptr inbounds %struct.anon, ptr %s, i32 0, i32 1
552 %sv2 = load i32, ptr %gepb
553 %ext2 = zext i32 %sv2 to i64
554 %cmp2 = icmp eq i64 %ext2, 57
558 %p = phi i1 [ %cmp1, %if.then ], [ %cmp2, %if.else ]
563 define zeroext i1 @test_crash(i1 zeroext %flag, ptr %i4, ptr %m, ptr %n) {
564 ; CHECK-LABEL: @test_crash(
566 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
568 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[I4:%.*]], align 4
569 ; CHECK-NEXT: br label [[IF_END:%.*]]
571 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr [[M:%.*]], align 4
572 ; CHECK-NEXT: [[TMP4:%.*]] = load i32, ptr [[N:%.*]], align 4
573 ; CHECK-NEXT: br label [[IF_END]]
575 ; CHECK-NEXT: [[TMP4_SINK:%.*]] = phi i32 [ [[TMP4]], [[IF_ELSE]] ], [ -1, [[IF_THEN]] ]
576 ; CHECK-NEXT: [[TMP3_SINK:%.*]] = phi i32 [ [[TMP3]], [[IF_ELSE]] ], [ [[TMP1]], [[IF_THEN]] ]
577 ; CHECK-NEXT: [[TMP5:%.*]] = add i32 [[TMP3_SINK]], [[TMP4_SINK]]
578 ; CHECK-NEXT: store i32 [[TMP5]], ptr [[I4]], align 4
579 ; CHECK-NEXT: ret i1 true
582 br i1 %flag, label %if.then, label %if.else
585 %tmp1 = load i32, ptr %i4
586 %tmp2 = add i32 %tmp1, -1
587 store i32 %tmp2, ptr %i4
591 %tmp3 = load i32, ptr %m
592 %tmp4 = load i32, ptr %n
593 %tmp5 = add i32 %tmp3, %tmp4
594 store i32 %tmp5, ptr %i4
601 ; No checks for test_crash - just ensure it doesn't crash!
603 define zeroext i1 @test16(i1 zeroext %flag, i1 zeroext %flag2, i32 %blksA, i32 %blksB, i32 %nblks) {
604 ; CHECK-LABEL: @test16(
606 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
608 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge i32 [[BLKSA:%.*]], [[NBLKS:%.*]]
609 ; CHECK-NEXT: [[FROMBOOL1:%.*]] = zext i1 [[CMP]] to i8
610 ; CHECK-NEXT: br label [[IF_END:%.*]]
612 ; CHECK-NEXT: br i1 [[FLAG2:%.*]], label [[IF_THEN2:%.*]], label [[IF_END]]
614 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[NBLKS]], [[BLKSB:%.*]]
615 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ule i32 [[ADD]], [[BLKSA]]
616 ; CHECK-NEXT: [[FROMBOOL3:%.*]] = zext i1 [[CMP2]] to i8
617 ; CHECK-NEXT: br label [[IF_END]]
619 ; CHECK-NEXT: [[OBEYS_0:%.*]] = phi i8 [ [[FROMBOOL1]], [[IF_THEN]] ], [ [[FROMBOOL3]], [[IF_THEN2]] ], [ 0, [[IF_ELSE]] ]
620 ; CHECK-NEXT: [[TOBOOL4:%.*]] = icmp ne i8 [[OBEYS_0]], 0
621 ; CHECK-NEXT: ret i1 [[TOBOOL4]]
624 br i1 %flag, label %if.then, label %if.else
627 %cmp = icmp uge i32 %blksA, %nblks
628 %frombool1 = zext i1 %cmp to i8
632 br i1 %flag2, label %if.then2, label %if.end
635 %add = add i32 %nblks, %blksB
636 %cmp2 = icmp ule i32 %add, %blksA
637 %frombool3 = zext i1 %cmp2 to i8
641 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.then2 ], [ 0, %if.else ]
642 %tobool4 = icmp ne i8 %obeys.0, 0
647 define zeroext i1 @test16a(i1 zeroext %flag, i1 zeroext %flag2, i32 %blksA, i32 %blksB, i32 %nblks, ptr %p) {
648 ; CHECK-LABEL: @test16a(
650 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
652 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge i32 [[BLKSA:%.*]], [[NBLKS:%.*]]
653 ; CHECK-NEXT: br label [[IF_END_SINK_SPLIT:%.*]]
655 ; CHECK-NEXT: br i1 [[FLAG2:%.*]], label [[IF_THEN2:%.*]], label [[IF_END:%.*]]
657 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[NBLKS]], [[BLKSB:%.*]]
658 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ule i32 [[ADD]], [[BLKSA]]
659 ; CHECK-NEXT: br label [[IF_END_SINK_SPLIT]]
660 ; CHECK: if.end.sink.split:
661 ; CHECK-NEXT: [[CMP2_SINK:%.*]] = phi i1 [ [[CMP2]], [[IF_THEN2]] ], [ [[CMP]], [[IF_THEN]] ]
662 ; CHECK-NEXT: [[FROMBOOL3:%.*]] = zext i1 [[CMP2_SINK]] to i8
663 ; CHECK-NEXT: store i8 [[FROMBOOL3]], ptr [[P:%.*]], align 1
664 ; CHECK-NEXT: br label [[IF_END]]
666 ; CHECK-NEXT: ret i1 true
669 br i1 %flag, label %if.then, label %if.else
672 %cmp = icmp uge i32 %blksA, %nblks
673 %frombool1 = zext i1 %cmp to i8
674 store i8 %frombool1, ptr %p
678 br i1 %flag2, label %if.then2, label %if.end
681 %add = add i32 %nblks, %blksB
682 %cmp2 = icmp ule i32 %add, %blksA
683 %frombool3 = zext i1 %cmp2 to i8
684 store i8 %frombool3, ptr %p
692 define zeroext i1 @test17(i32 %flag, i32 %blksA, i32 %blksB, i32 %nblks) {
693 ; CHECK-LABEL: @test17(
695 ; CHECK-NEXT: switch i32 [[FLAG:%.*]], label [[IF_END:%.*]] [
696 ; CHECK-NEXT: i32 0, label [[IF_THEN:%.*]]
697 ; CHECK-NEXT: i32 1, label [[IF_THEN2:%.*]]
700 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge i32 [[BLKSA:%.*]], [[NBLKS:%.*]]
701 ; CHECK-NEXT: br label [[IF_END_SINK_SPLIT:%.*]]
703 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[NBLKS]], [[BLKSB:%.*]]
704 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ule i32 [[ADD]], [[BLKSA]]
705 ; CHECK-NEXT: br label [[IF_END_SINK_SPLIT]]
706 ; CHECK: if.end.sink.split:
707 ; CHECK-NEXT: [[CMP2_SINK:%.*]] = phi i1 [ [[CMP2]], [[IF_THEN2]] ], [ [[CMP]], [[IF_THEN]] ]
708 ; CHECK-NEXT: [[FROMBOOL3:%.*]] = call i8 @i1toi8(i1 [[CMP2_SINK]])
709 ; CHECK-NEXT: br label [[IF_END]]
711 ; CHECK-NEXT: [[OBEYS_0:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[FROMBOOL3]], [[IF_END_SINK_SPLIT]] ]
712 ; CHECK-NEXT: [[TOBOOL4:%.*]] = icmp ne i8 [[OBEYS_0]], 0
713 ; CHECK-NEXT: ret i1 [[TOBOOL4]]
716 switch i32 %flag, label %if.end [
717 i32 0, label %if.then
718 i32 1, label %if.then2
722 %cmp = icmp uge i32 %blksA, %nblks
723 %frombool1 = call i8 @i1toi8(i1 %cmp)
727 %add = add i32 %nblks, %blksB
728 %cmp2 = icmp ule i32 %add, %blksA
729 %frombool3 = call i8 @i1toi8(i1 %cmp2)
733 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.then2 ], [ 0, %entry ]
734 %tobool4 = icmp ne i8 %obeys.0, 0
737 declare i8 @i1toi8(i1)
743 define zeroext i1 @test18(i32 %flag, i32 %blksA, i32 %blksB, i32 %nblks) {
744 ; CHECK-LABEL: @test18(
746 ; CHECK-NEXT: switch i32 [[FLAG:%.*]], label [[IF_THEN3:%.*]] [
747 ; CHECK-NEXT: i32 0, label [[IF_THEN:%.*]]
748 ; CHECK-NEXT: i32 1, label [[IF_THEN2:%.*]]
751 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge i32 [[BLKSA:%.*]], [[NBLKS:%.*]]
752 ; CHECK-NEXT: br label [[IF_END:%.*]]
754 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[NBLKS]], [[BLKSB:%.*]]
755 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ule i32 [[ADD]], [[BLKSA]]
756 ; CHECK-NEXT: br label [[IF_END]]
758 ; CHECK-NEXT: [[ADD2:%.*]] = add i32 [[NBLKS]], [[BLKSA]]
759 ; CHECK-NEXT: [[CMP3:%.*]] = icmp ule i32 [[ADD2]], [[BLKSA]]
760 ; CHECK-NEXT: br label [[IF_END]]
762 ; CHECK-NEXT: [[CMP3_SINK:%.*]] = phi i1 [ [[CMP3]], [[IF_THEN3]] ], [ [[CMP2]], [[IF_THEN2]] ], [ [[CMP]], [[IF_THEN]] ]
763 ; CHECK-NEXT: [[FROMBOOL4:%.*]] = zext i1 [[CMP3_SINK]] to i8
764 ; CHECK-NEXT: [[TOBOOL4:%.*]] = icmp ne i8 [[FROMBOOL4]], 0
765 ; CHECK-NEXT: ret i1 [[TOBOOL4]]
768 switch i32 %flag, label %if.then3 [
769 i32 0, label %if.then
770 i32 1, label %if.then2
774 %cmp = icmp uge i32 %blksA, %nblks
775 %frombool1 = zext i1 %cmp to i8
779 %add = add i32 %nblks, %blksB
780 %cmp2 = icmp ule i32 %add, %blksA
781 %frombool3 = zext i1 %cmp2 to i8
785 %add2 = add i32 %nblks, %blksA
786 %cmp3 = icmp ule i32 %add2, %blksA
787 %frombool4 = zext i1 %cmp3 to i8
791 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.then2 ], [ %frombool4, %if.then3 ]
792 %tobool4 = icmp ne i8 %obeys.0, 0
797 define i32 @test_pr30188(i1 zeroext %flag, i32 %x) {
798 ; CHECK-LABEL: @test_pr30188(
800 ; CHECK-NEXT: [[Y:%.*]] = alloca i32, align 4
801 ; CHECK-NEXT: [[Z:%.*]] = alloca i32, align 4
802 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
804 ; CHECK-NEXT: store i32 [[X:%.*]], ptr [[Y]], align 4
805 ; CHECK-NEXT: br label [[IF_END:%.*]]
807 ; CHECK-NEXT: store i32 [[X]], ptr [[Z]], align 4
808 ; CHECK-NEXT: br label [[IF_END]]
810 ; CHECK-NEXT: ret i32 1
815 br i1 %flag, label %if.then, label %if.else
830 define i32 @test_pr30188a(i1 zeroext %flag, i32 %x) {
831 ; CHECK-LABEL: @test_pr30188a(
833 ; CHECK-NEXT: [[Y:%.*]] = alloca i32, align 4
834 ; CHECK-NEXT: [[Z:%.*]] = alloca i32, align 4
835 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
837 ; CHECK-NEXT: call void @g()
838 ; CHECK-NEXT: [[ONE:%.*]] = load i32, ptr [[Y]], align 4
839 ; CHECK-NEXT: [[TWO:%.*]] = add i32 [[ONE]], 2
840 ; CHECK-NEXT: store i32 [[TWO]], ptr [[Y]], align 4
841 ; CHECK-NEXT: br label [[IF_END:%.*]]
843 ; CHECK-NEXT: [[THREE:%.*]] = load i32, ptr [[Z]], align 4
844 ; CHECK-NEXT: [[FOUR:%.*]] = add i32 [[THREE]], 2
845 ; CHECK-NEXT: store i32 [[FOUR]], ptr [[Y]], align 4
846 ; CHECK-NEXT: br label [[IF_END]]
848 ; CHECK-NEXT: ret i32 1
853 br i1 %flag, label %if.then, label %if.else
857 %one = load i32, ptr %y
858 %two = add i32 %one, 2
859 store i32 %two, ptr %y
863 %three = load i32, ptr %z
864 %four = add i32 %three, 2
865 store i32 %four, ptr %y
873 ; The phi is confusing - both add instructions are used by it, but
874 ; not on their respective unconditional arcs. It should not be
876 define void @test_pr30292(i1 %cond, i1 %cond2, i32 %a, i32 %b) {
877 ; CHECK-LABEL: @test_pr30292(
879 ; CHECK-NEXT: [[ADD1:%.*]] = add i32 [[A:%.*]], 1
880 ; CHECK-NEXT: br label [[SUCC:%.*]]
882 ; CHECK-NEXT: call void @g()
883 ; CHECK-NEXT: [[ADD2:%.*]] = add i32 [[A]], 1
884 ; CHECK-NEXT: br label [[SUCC]]
886 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[ADD1]], [[SUCC]] ], [ [[ADD2]], [[TWO:%.*]] ]
887 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[TWO]], label [[SUCC]]
890 %add1 = add i32 %a, 1
894 br i1 %cond, label %two, label %succ
898 %add2 = add i32 %a, 1
902 %p = phi i32 [ 0, %entry ], [ %add1, %one ], [ %add2, %two ]
908 define zeroext i1 @test_pr30244(i1 zeroext %flag, i1 zeroext %flag2, i32 %blksA, i32 %blksB, i32 %nblks) {
909 ; CHECK-LABEL: @test_pr30244(
911 ; CHECK-NEXT: [[P:%.*]] = alloca i8, align 1
912 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
914 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge i32 [[BLKSA:%.*]], [[NBLKS:%.*]]
915 ; CHECK-NEXT: [[FROMBOOL1:%.*]] = zext i1 [[CMP]] to i8
916 ; CHECK-NEXT: store i8 [[FROMBOOL1]], ptr [[P]], align 1
917 ; CHECK-NEXT: br label [[IF_END:%.*]]
919 ; CHECK-NEXT: br i1 [[FLAG2:%.*]], label [[IF_THEN2:%.*]], label [[IF_END]]
921 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[NBLKS]], [[BLKSB:%.*]]
922 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ule i32 [[ADD]], [[BLKSA]]
923 ; CHECK-NEXT: [[FROMBOOL3:%.*]] = zext i1 [[CMP2]] to i8
924 ; CHECK-NEXT: store i8 [[FROMBOOL3]], ptr [[P]], align 1
925 ; CHECK-NEXT: br label [[IF_END]]
927 ; CHECK-NEXT: ret i1 true
931 br i1 %flag, label %if.then, label %if.else
934 %cmp = icmp uge i32 %blksA, %nblks
935 %frombool1 = zext i1 %cmp to i8
936 store i8 %frombool1, ptr %p
940 br i1 %flag2, label %if.then2, label %if.end
943 %add = add i32 %nblks, %blksB
944 %cmp2 = icmp ule i32 %add, %blksA
945 %frombool3 = zext i1 %cmp2 to i8
946 store i8 %frombool3, ptr %p
954 define i32 @test_pr30373a(i1 zeroext %flag, i32 %x, i32 %y) {
955 ; CHECK-LABEL: @test_pr30373a(
957 ; CHECK-NEXT: [[X_Y:%.*]] = select i1 [[FLAG:%.*]], i32 [[X:%.*]], i32 [[Y:%.*]]
958 ; CHECK-NEXT: [[X1:%.*]] = call i32 @foo(i32 [[X_Y]], i32 0) #[[ATTR0]]
959 ; CHECK-NEXT: [[Y1:%.*]] = call i32 @foo(i32 [[X_Y]], i32 1) #[[ATTR0]]
960 ; CHECK-NEXT: [[Z1:%.*]] = lshr i32 [[Y1]], 8
961 ; CHECK-NEXT: [[RET:%.*]] = add i32 [[X1]], [[Z1]]
962 ; CHECK-NEXT: ret i32 [[RET]]
965 br i1 %flag, label %if.then, label %if.else
968 %x0 = call i32 @foo(i32 %x, i32 0) nounwind readnone
969 %y0 = call i32 @foo(i32 %x, i32 1) nounwind readnone
970 %z0 = lshr i32 %y0, 8
974 %x1 = call i32 @foo(i32 %y, i32 0) nounwind readnone
975 %y1 = call i32 @foo(i32 %y, i32 1) nounwind readnone
976 %z1 = lshr exact i32 %y1, 8
980 %xx = phi i32 [ %x0, %if.then ], [ %x1, %if.else ]
981 %yy = phi i32 [ %z0, %if.then ], [ %z1, %if.else ]
982 %ret = add i32 %xx, %yy
987 define i32 @test_pr30373b(i1 zeroext %flag, i32 %x, i32 %y) {
988 ; CHECK-LABEL: @test_pr30373b(
990 ; CHECK-NEXT: [[X_Y:%.*]] = select i1 [[FLAG:%.*]], i32 [[X:%.*]], i32 [[Y:%.*]]
991 ; CHECK-NEXT: [[X1:%.*]] = call i32 @foo(i32 [[X_Y]], i32 0) #[[ATTR0]]
992 ; CHECK-NEXT: [[Y1:%.*]] = call i32 @foo(i32 [[X_Y]], i32 1) #[[ATTR0]]
993 ; CHECK-NEXT: [[Z1:%.*]] = lshr i32 [[Y1]], 8
994 ; CHECK-NEXT: [[RET:%.*]] = add i32 [[X1]], [[Z1]]
995 ; CHECK-NEXT: ret i32 [[RET]]
998 br i1 %flag, label %if.then, label %if.else
1001 %x0 = call i32 @foo(i32 %x, i32 0) nounwind readnone
1002 %y0 = call i32 @foo(i32 %x, i32 1) nounwind readnone
1003 %z0 = lshr exact i32 %y0, 8
1007 %x1 = call i32 @foo(i32 %y, i32 0) nounwind readnone
1008 %y1 = call i32 @foo(i32 %y, i32 1) nounwind readnone
1009 %z1 = lshr i32 %y1, 8
1013 %xx = phi i32 [ %x0, %if.then ], [ %x1, %if.else ]
1014 %yy = phi i32 [ %z0, %if.then ], [ %z1, %if.else ]
1015 %ret = add i32 %xx, %yy
1021 ; FIXME: Should turn into select
1022 define float @allow_intrinsic_remove_constant(i1 zeroext %flag, float %w, float %x, float %y) {
1023 ; CHECK-LABEL: @allow_intrinsic_remove_constant(
1024 ; CHECK-NEXT: entry:
1025 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
1027 ; CHECK-NEXT: [[DUMMY:%.*]] = fadd float [[W:%.*]], 4.000000e+00
1028 ; CHECK-NEXT: [[SV1:%.*]] = call float @llvm.fma.f32(float [[DUMMY]], float 2.000000e+00, float 1.000000e+00)
1029 ; CHECK-NEXT: br label [[IF_END:%.*]]
1031 ; CHECK-NEXT: [[DUMMY1:%.*]] = fadd float [[W]], 8.000000e+00
1032 ; CHECK-NEXT: [[SV2:%.*]] = call float @llvm.fma.f32(float 2.000000e+00, float [[DUMMY1]], float 1.000000e+00)
1033 ; CHECK-NEXT: br label [[IF_END]]
1035 ; CHECK-NEXT: [[P:%.*]] = phi float [ [[SV1]], [[IF_THEN]] ], [ [[SV2]], [[IF_ELSE]] ]
1036 ; CHECK-NEXT: ret float [[P]]
1039 br i1 %flag, label %if.then, label %if.else
1042 %dummy = fadd float %w, 4.0
1043 %sv1 = call float @llvm.fma.f32(float %dummy, float 2.0, float 1.0)
1047 %dummy1 = fadd float %w, 8.0
1048 %sv2 = call float @llvm.fma.f32(float 2.0, float %dummy1, float 1.0)
1052 %p = phi float [ %sv1, %if.then ], [ %sv2, %if.else ]
1056 declare float @llvm.fma.f32(float, float, float)
1058 define i32 @no_remove_constant_immarg(i1 zeroext %flag, i32 %w, i32 %x, i32 %y) {
1059 ; CHECK-LABEL: @no_remove_constant_immarg(
1060 ; CHECK-NEXT: entry:
1061 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
1063 ; CHECK-NEXT: [[DUMMY:%.*]] = add i32 [[W:%.*]], 5
1064 ; CHECK-NEXT: [[SV1:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X:%.*]], i1 true)
1065 ; CHECK-NEXT: br label [[IF_END:%.*]]
1067 ; CHECK-NEXT: [[DUMMY1:%.*]] = add i32 [[W]], 6
1068 ; CHECK-NEXT: [[SV2:%.*]] = call i32 @llvm.ctlz.i32(i32 [[X]], i1 false)
1069 ; CHECK-NEXT: br label [[IF_END]]
1071 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ [[SV1]], [[IF_THEN]] ], [ [[SV2]], [[IF_ELSE]] ]
1072 ; CHECK-NEXT: ret i32 1
1075 br i1 %flag, label %if.then, label %if.else
1078 %dummy = add i32 %w, 5
1079 %sv1 = call i32 @llvm.ctlz.i32(i32 %x, i1 true)
1083 %dummy1 = add i32 %w, 6
1084 %sv2 = call i32 @llvm.ctlz.i32(i32 %x, i1 false)
1088 %p = phi i32 [ %sv1, %if.then ], [ %sv2, %if.else ]
1092 declare void @llvm.memcpy.p1.p1.i64(ptr addrspace(1) nocapture, ptr addrspace(1) nocapture readonly, i64, i1)
1094 ; Make sure a memcpy size isn't replaced with a variable
1095 define void @no_replace_memcpy_size(i1 zeroext %flag, ptr addrspace(1) %dst, ptr addrspace(1) %src) {
1096 ; CHECK-LABEL: @no_replace_memcpy_size(
1097 ; CHECK-NEXT: entry:
1098 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
1100 ; CHECK-NEXT: call void @llvm.memcpy.p1.p1.i64(ptr addrspace(1) [[DST:%.*]], ptr addrspace(1) [[SRC:%.*]], i64 1024, i1 false)
1101 ; CHECK-NEXT: br label [[IF_END:%.*]]
1103 ; CHECK-NEXT: call void @llvm.memcpy.p1.p1.i64(ptr addrspace(1) [[DST]], ptr addrspace(1) [[SRC]], i64 4096, i1 false)
1104 ; CHECK-NEXT: br label [[IF_END]]
1106 ; CHECK-NEXT: ret void
1109 br i1 %flag, label %if.then, label %if.else
1112 call void @llvm.memcpy.p1.p1.i64(ptr addrspace(1) %dst, ptr addrspace(1) %src, i64 1024, i1 false)
1116 call void @llvm.memcpy.p1.p1.i64(ptr addrspace(1) %dst, ptr addrspace(1) %src, i64 4096, i1 false)
1123 declare void @llvm.memmove.p1.p1.i64(ptr addrspace(1) nocapture, ptr addrspace(1) nocapture readonly, i64, i1)
1125 ; Make sure a memmove size isn't replaced with a variable
1126 define void @no_replace_memmove_size(i1 zeroext %flag, ptr addrspace(1) %dst, ptr addrspace(1) %src) {
1127 ; CHECK-LABEL: @no_replace_memmove_size(
1128 ; CHECK-NEXT: entry:
1129 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
1131 ; CHECK-NEXT: call void @llvm.memmove.p1.p1.i64(ptr addrspace(1) [[DST:%.*]], ptr addrspace(1) [[SRC:%.*]], i64 1024, i1 false)
1132 ; CHECK-NEXT: br label [[IF_END:%.*]]
1134 ; CHECK-NEXT: call void @llvm.memmove.p1.p1.i64(ptr addrspace(1) [[DST]], ptr addrspace(1) [[SRC]], i64 4096, i1 false)
1135 ; CHECK-NEXT: br label [[IF_END]]
1137 ; CHECK-NEXT: ret void
1140 br i1 %flag, label %if.then, label %if.else
1143 call void @llvm.memmove.p1.p1.i64(ptr addrspace(1) %dst, ptr addrspace(1) %src, i64 1024, i1 false)
1147 call void @llvm.memmove.p1.p1.i64(ptr addrspace(1) %dst, ptr addrspace(1) %src, i64 4096, i1 false)
1154 declare void @llvm.memset.p1.i64(ptr addrspace(1) nocapture, i8, i64, i1)
1156 ; Make sure a memset size isn't replaced with a variable
1157 define void @no_replace_memset_size(i1 zeroext %flag, ptr addrspace(1) %dst) {
1158 ; CHECK-LABEL: @no_replace_memset_size(
1159 ; CHECK-NEXT: entry:
1160 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
1162 ; CHECK-NEXT: call void @llvm.memset.p1.i64(ptr addrspace(1) [[DST:%.*]], i8 0, i64 1024, i1 false)
1163 ; CHECK-NEXT: br label [[IF_END:%.*]]
1165 ; CHECK-NEXT: call void @llvm.memset.p1.i64(ptr addrspace(1) [[DST]], i8 0, i64 4096, i1 false)
1166 ; CHECK-NEXT: br label [[IF_END]]
1168 ; CHECK-NEXT: ret void
1171 br i1 %flag, label %if.then, label %if.else
1174 call void @llvm.memset.p1.i64(ptr addrspace(1) %dst, i8 0, i64 1024, i1 false)
1178 call void @llvm.memset.p1.i64(ptr addrspace(1) %dst, i8 0, i64 4096, i1 false)
1185 ; Check that simplifycfg doesn't sink and merge inline-asm instructions.
1187 define i32 @test_inline_asm1(i32 %c, i32 %r6) {
1188 ; CHECK-LABEL: @test_inline_asm1(
1189 ; CHECK-NEXT: entry:
1190 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[C:%.*]], 0
1191 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
1193 ; CHECK-NEXT: [[TMP0:%.*]] = call i32 asm "rorl $2, $0", "=&r,0,n,~{dirflag},~{fpsr},~{flags}"(i32 [[R6:%.*]], i32 8)
1194 ; CHECK-NEXT: br label [[IF_END:%.*]]
1196 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 asm "rorl $2, $0", "=&r,0,n,~{dirflag},~{fpsr},~{flags}"(i32 [[R6]], i32 6)
1197 ; CHECK-NEXT: br label [[IF_END]]
1199 ; CHECK-NEXT: [[R6_ADDR_0:%.*]] = phi i32 [ [[TMP0]], [[IF_THEN]] ], [ [[TMP1]], [[IF_ELSE]] ]
1200 ; CHECK-NEXT: ret i32 [[R6_ADDR_0]]
1203 %tobool = icmp eq i32 %c, 0
1204 br i1 %tobool, label %if.else, label %if.then
1207 %0 = call i32 asm "rorl $2, $0", "=&r,0,n,~{dirflag},~{fpsr},~{flags}"(i32 %r6, i32 8)
1211 %1 = call i32 asm "rorl $2, $0", "=&r,0,n,~{dirflag},~{fpsr},~{flags}"(i32 %r6, i32 6)
1215 %r6.addr.0 = phi i32 [ %0, %if.then ], [ %1, %if.else ]
1220 declare i32 @call_target()
1222 define void @test_operand_bundles(i1 %cond, ptr %ptr) {
1223 ; CHECK-LABEL: @test_operand_bundles(
1224 ; CHECK-NEXT: entry:
1225 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[LEFT:%.*]], label [[RIGHT:%.*]]
1227 ; CHECK-NEXT: [[VAL0:%.*]] = call i32 @call_target() [ "deopt"(i32 10) ]
1228 ; CHECK-NEXT: br label [[MERGE:%.*]]
1230 ; CHECK-NEXT: [[VAL1:%.*]] = call i32 @call_target() [ "deopt"(i32 20) ]
1231 ; CHECK-NEXT: br label [[MERGE]]
1233 ; CHECK-NEXT: [[VAL1_SINK:%.*]] = phi i32 [ [[VAL1]], [[RIGHT]] ], [ [[VAL0]], [[LEFT]] ]
1234 ; CHECK-NEXT: store i32 [[VAL1_SINK]], ptr [[PTR:%.*]], align 4
1235 ; CHECK-NEXT: ret void
1238 br i1 %cond, label %left, label %right
1241 %val0 = call i32 @call_target() [ "deopt"(i32 10) ]
1242 store i32 %val0, ptr %ptr
1246 %val1 = call i32 @call_target() [ "deopt"(i32 20) ]
1247 store i32 %val1, ptr %ptr
1255 %TP = type {i32, i32}
1257 define i32 @test_insertvalue(i1 zeroext %flag, %TP %P) {
1258 ; CHECK-LABEL: @test_insertvalue(
1259 ; CHECK-NEXT: entry:
1260 ; CHECK-NEXT: [[DOT:%.*]] = select i1 [[FLAG:%.*]], i32 0, i32 1
1261 ; CHECK-NEXT: [[I2:%.*]] = insertvalue [[TP:%.*]] [[P:%.*]], i32 [[DOT]], 0
1262 ; CHECK-NEXT: ret i32 1
1265 br i1 %flag, label %if.then, label %if.else
1268 %i1 = insertvalue %TP %P, i32 0, 0
1272 %i2 = insertvalue %TP %P, i32 1, 0
1276 %i = phi %TP [%i1, %if.then], [%i2, %if.else]
1282 declare void @baz(i32)
1284 define void @test_sink_void_calls(i32 %x) {
1285 ; CHECK-LABEL: @test_sink_void_calls(
1286 ; CHECK-NEXT: entry:
1287 ; CHECK-NEXT: switch i32 [[X:%.*]], label [[DEFAULT:%.*]] [
1288 ; CHECK-NEXT: i32 0, label [[RETURN:%.*]]
1289 ; CHECK-NEXT: i32 1, label [[BB1:%.*]]
1290 ; CHECK-NEXT: i32 2, label [[BB2:%.*]]
1291 ; CHECK-NEXT: i32 3, label [[BB3:%.*]]
1292 ; CHECK-NEXT: i32 4, label [[BB4:%.*]]
1295 ; CHECK-NEXT: br label [[RETURN]]
1297 ; CHECK-NEXT: br label [[RETURN]]
1299 ; CHECK-NEXT: br label [[RETURN]]
1301 ; CHECK-NEXT: br label [[RETURN]]
1303 ; CHECK-NEXT: unreachable
1305 ; CHECK-NEXT: [[DOTSINK:%.*]] = phi i32 [ 90, [[BB4]] ], [ 78, [[BB3]] ], [ 56, [[BB2]] ], [ 34, [[BB1]] ], [ 12, [[ENTRY:%.*]] ]
1306 ; CHECK-NEXT: call void @baz(i32 [[DOTSINK]])
1307 ; CHECK-NEXT: ret void
1310 switch i32 %x, label %default [
1318 call void @baz(i32 12)
1321 call void @baz(i32 34)
1324 call void @baz(i32 56)
1327 call void @baz(i32 78)
1330 call void @baz(i32 90)
1337 ; Check that the calls get sunk to the return block.
1338 ; We would previously not sink calls without uses, see PR41259.
1341 define i32 @test_not_sink_lifetime_marker(i1 zeroext %flag, i32 %x) {
1342 ; CHECK-LABEL: @test_not_sink_lifetime_marker(
1343 ; CHECK-NEXT: entry:
1344 ; CHECK-NEXT: [[Y:%.*]] = alloca i32, align 4
1345 ; CHECK-NEXT: [[Z:%.*]] = alloca i32, align 4
1346 ; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
1348 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr [[Y]])
1349 ; CHECK-NEXT: br label [[IF_END:%.*]]
1351 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr [[Z]])
1352 ; CHECK-NEXT: br label [[IF_END]]
1354 ; CHECK-NEXT: ret i32 1
1359 br i1 %flag, label %if.then, label %if.else
1362 call void @llvm.lifetime.end.p0(i64 4, ptr %y)
1366 call void @llvm.lifetime.end.p0(i64 4, ptr %z)
1373 define void @direct_caller(i1 %c) {
1374 ; CHECK-LABEL: @direct_caller(
1375 ; CHECK-NEXT: br i1 [[C:%.*]], label [[CALL_FOO:%.*]], label [[CALL_BAR:%.*]]
1377 ; CHECK-NEXT: call void @direct_callee()
1378 ; CHECK-NEXT: br label [[END:%.*]]
1380 ; CHECK-NEXT: call void @direct_callee2()
1381 ; CHECK-NEXT: br label [[END]]
1383 ; CHECK-NEXT: ret void
1385 br i1 %c, label %call_foo, label %call_bar
1388 call void @direct_callee()
1392 call void @direct_callee2()
1399 define void @indirect_caller(i1 %c, i32 %v, ptr %foo, ptr %bar) {
1400 ; CHECK-LABEL: @indirect_caller(
1402 ; CHECK-NEXT: [[FOO_BAR:%.*]] = select i1 [[C:%.*]], ptr [[FOO:%.*]], ptr [[BAR:%.*]]
1403 ; CHECK-NEXT: tail call void [[FOO_BAR]](i32 [[V:%.*]])
1404 ; CHECK-NEXT: ret void
1406 br i1 %c, label %call_foo, label %call_bar
1409 tail call void %foo(i32 %v)
1413 tail call void %bar(i32 %v)
1420 define void @maybe_indirect_caller(ptr %fun) {
1421 ; CHECK-LABEL: @maybe_indirect_caller(
1422 ; CHECK-NEXT: [[C:%.*]] = icmp eq ptr [[FUN:%.*]], @direct_callee
1423 ; CHECK-NEXT: br i1 [[C]], label [[IF_TRUE_DIRECT_TARG:%.*]], label [[IF_FALSE_ORIG_INDIRECT:%.*]]
1424 ; CHECK: if.true.direct_targ:
1425 ; CHECK-NEXT: tail call void @direct_callee()
1426 ; CHECK-NEXT: br label [[IF_END_ICP:%.*]]
1427 ; CHECK: if.false.orig_indirect:
1428 ; CHECK-NEXT: tail call void [[FUN]]()
1429 ; CHECK-NEXT: br label [[IF_END_ICP]]
1430 ; CHECK: if.end.icp:
1431 ; CHECK-NEXT: ret void
1433 %c = icmp eq ptr %fun, @direct_callee
1434 br i1 %c, label %if.true.direct_targ, label %if.false.orig_indirect
1436 if.true.direct_targ:
1437 tail call void @direct_callee()
1438 br label %if.end.icp
1440 if.false.orig_indirect:
1441 tail call void %fun()
1442 br label %if.end.icp
1447 define void @maybe_indirect_caller2(ptr %fun) {
1448 ; CHECK-LABEL: @maybe_indirect_caller2(
1449 ; CHECK-NEXT: [[C:%.*]] = icmp eq ptr [[FUN:%.*]], @direct_callee
1450 ; CHECK-NEXT: br i1 [[C]], label [[IF_TRUE_DIRECT_TARG:%.*]], label [[IF_FALSE_ORIG_INDIRECT:%.*]]
1451 ; CHECK: if.false.orig_indirect:
1452 ; CHECK-NEXT: tail call void [[FUN]]()
1453 ; CHECK-NEXT: br label [[IF_END_ICP:%.*]]
1454 ; CHECK: if.true.direct_targ:
1455 ; CHECK-NEXT: tail call void @direct_callee()
1456 ; CHECK-NEXT: br label [[IF_END_ICP]]
1457 ; CHECK: if.end.icp:
1458 ; CHECK-NEXT: ret void
1460 %c = icmp eq ptr %fun, @direct_callee
1461 br i1 %c, label %if.true.direct_targ, label %if.false.orig_indirect
1463 if.false.orig_indirect:
1464 tail call void %fun()
1465 br label %if.end.icp
1467 if.true.direct_targ:
1468 tail call void @direct_callee()
1469 br label %if.end.icp
1474 declare void @direct_callee()
1475 declare void @direct_callee2()
1476 declare void @direct_callee3()
1478 declare void @llvm.lifetime.start.p0(i64, ptr nocapture)
1479 declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
1481 define void @creating_too_many_phis(i1 %cond, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i32 %h) {
1482 ; CHECK-LABEL: @creating_too_many_phis(
1483 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB0:%.*]], label [[BB1:%.*]]
1485 ; CHECK-NEXT: [[V0:%.*]] = add i32 [[A:%.*]], [[B:%.*]]
1486 ; CHECK-NEXT: [[V1:%.*]] = add i32 [[V0]], [[C:%.*]]
1487 ; CHECK-NEXT: [[V2:%.*]] = add i32 [[D:%.*]], [[E:%.*]]
1488 ; CHECK-NEXT: [[R3:%.*]] = add i32 [[V1]], [[V2]]
1489 ; CHECK-NEXT: br label [[END:%.*]]
1491 ; CHECK-NEXT: [[V4:%.*]] = add i32 [[A]], [[B]]
1492 ; CHECK-NEXT: [[V5:%.*]] = add i32 [[V4]], [[C]]
1493 ; CHECK-NEXT: [[V6:%.*]] = add i32 [[G:%.*]], [[H:%.*]]
1494 ; CHECK-NEXT: [[R7:%.*]] = add i32 [[V5]], [[V6]]
1495 ; CHECK-NEXT: br label [[END]]
1497 ; CHECK-NEXT: [[R7_SINK:%.*]] = phi i32 [ [[R7]], [[BB1]] ], [ [[R3]], [[BB0]] ]
1498 ; CHECK-NEXT: call void @use32(i32 [[R7_SINK]])
1499 ; CHECK-NEXT: ret void
1501 br i1 %cond, label %bb0, label %bb1
1504 %v0 = add i32 %a, %b
1505 %v1 = add i32 %v0, %c
1506 %v2 = add i32 %d, %e
1507 %r3 = add i32 %v1, %v2
1508 call void @use32(i32 %r3)
1512 %v4 = add i32 %a, %b
1513 %v5 = add i32 %v4, %c
1514 %v6 = add i32 %g, %h
1515 %r7 = add i32 %v5, %v6
1516 call void @use32(i32 %r7)
1522 declare void @use32(i32)
1524 define void @multiple_cond_preds(i1 %c0, i1 %c1, i1 %c2) {
1525 ; CHECK-LABEL: @multiple_cond_preds(
1526 ; CHECK-NEXT: dispatch0:
1527 ; CHECK-NEXT: br i1 [[C0:%.*]], label [[DISPATCH1:%.*]], label [[DISPATCH2:%.*]]
1529 ; CHECK-NEXT: call void @direct_callee2()
1530 ; CHECK-NEXT: br i1 [[C1:%.*]], label [[END_SINK_SPLIT:%.*]], label [[END:%.*]]
1532 ; CHECK-NEXT: call void @direct_callee3()
1533 ; CHECK-NEXT: br i1 [[C2:%.*]], label [[END_SINK_SPLIT]], label [[END]]
1534 ; CHECK: end.sink.split:
1535 ; CHECK-NEXT: call void @direct_callee()
1536 ; CHECK-NEXT: br label [[END]]
1538 ; CHECK-NEXT: ret void
1541 br i1 %c0, label %dispatch1, label %dispatch2
1544 call void @direct_callee2()
1545 br i1 %c1, label %uncond_pred0, label %end
1548 call void @direct_callee3()
1549 br i1 %c2, label %uncond_pred1, label %end
1552 call void @direct_callee()
1556 call void @direct_callee()
1563 define void @nontemporal(ptr %ptr, i1 %cond) {
1564 ; CHECK-LABEL: @nontemporal(
1565 ; CHECK-NEXT: entry:
1566 ; CHECK-NEXT: store i64 0, ptr [[PTR:%.*]], align 8, !nontemporal !7
1567 ; CHECK-NEXT: ret void
1570 br i1 %cond, label %if.then, label %if.else
1573 store i64 0, ptr %ptr, align 8, !nontemporal !12
1577 store i64 0, ptr %ptr, align 8, !nontemporal !12
1584 define void @nontemporal_mismatch(ptr %ptr, i1 %cond) {
1585 ; CHECK-LABEL: @nontemporal_mismatch(
1586 ; CHECK-NEXT: entry:
1587 ; CHECK-NEXT: store i64 0, ptr [[PTR:%.*]], align 8
1588 ; CHECK-NEXT: ret void
1591 br i1 %cond, label %if.then, label %if.else
1594 store i64 0, ptr %ptr, align 8, !nontemporal !12
1598 store i64 0, ptr %ptr, align 8