1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2 ; RUN: opt -S -passes="print<scalar-evolution>,loop-unroll" -unroll-runtime < %s 2>/dev/null | FileCheck %s
4 ; Make sure we use %add.lcssa rather than %load when expanding the
5 ; backedge taken count.
7 define void @test(i1 %c, ptr %p) {
8 ; CHECK-LABEL: define void @test(
9 ; CHECK-SAME: i1 [[C:%.*]], ptr [[P:%.*]]) {
10 ; CHECK-NEXT: [[ENTRY:.*:]]
11 ; CHECK-NEXT: br label %[[LOOP_1_PEEL_BEGIN:.*]]
12 ; CHECK: [[LOOP_1_PEEL_BEGIN]]:
13 ; CHECK-NEXT: br label %[[LOOP_1_PEEL:.*]]
14 ; CHECK: [[LOOP_1_PEEL]]:
15 ; CHECK-NEXT: [[LOAD_PEEL:%.*]] = load i64, ptr [[P]], align 8
16 ; CHECK-NEXT: [[ADD_PEEL:%.*]] = add i64 [[LOAD_PEEL]], 1
17 ; CHECK-NEXT: br i1 [[C]], label %[[IF:.*]], label %[[LOOP_1_PEEL_NEXT:.*]]
18 ; CHECK: [[LOOP_1_PEEL_NEXT]]:
19 ; CHECK-NEXT: br label %[[LOOP_1_PEEL_NEXT1:.*]]
20 ; CHECK: [[LOOP_1_PEEL_NEXT1]]:
21 ; CHECK-NEXT: br label %[[ENTRY_PEEL_NEWPH:.*]]
22 ; CHECK: [[ENTRY_PEEL_NEWPH]]:
23 ; CHECK-NEXT: br label %[[LOOP_1:.*]]
25 ; CHECK-NEXT: [[LOAD:%.*]] = load i64, ptr [[P]], align 8
26 ; CHECK-NEXT: [[ADD:%.*]] = add i64 [[LOAD]], 1
27 ; CHECK-NEXT: br i1 [[C]], label %[[IF_LOOPEXIT:.*]], label %[[LOOP_1]], !llvm.loop [[LOOP0:![0-9]+]]
28 ; CHECK: [[IF_LOOPEXIT]]:
29 ; CHECK-NEXT: [[ADD_LCSSA_PH:%.*]] = phi i64 [ [[ADD]], %[[LOOP_1]] ]
30 ; CHECK-NEXT: br label %[[IF]]
32 ; CHECK-NEXT: [[ADD_LCSSA:%.*]] = phi i64 [ [[ADD_PEEL]], %[[LOOP_1_PEEL]] ], [ [[ADD_LCSSA_PH]], %[[IF_LOOPEXIT]] ]
33 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i64, ptr [[P]], i64 [[ADD_LCSSA]]
34 ; CHECK-NEXT: [[TMP0:%.*]] = shl i64 [[ADD_LCSSA]], 3
35 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i64 [[TMP0]], 3
36 ; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
37 ; CHECK-NEXT: [[XTRAITER:%.*]] = and i64 [[TMP2]], 7
38 ; CHECK-NEXT: [[LCMP_MOD:%.*]] = icmp ne i64 [[XTRAITER]], 0
39 ; CHECK-NEXT: br i1 [[LCMP_MOD]], label %[[LOOP_2_PROL_PREHEADER:.*]], label %[[LOOP_2_PROL_LOOPEXIT:.*]]
40 ; CHECK: [[LOOP_2_PROL_PREHEADER]]:
41 ; CHECK-NEXT: br label %[[LOOP_2_PROL:.*]]
42 ; CHECK: [[LOOP_2_PROL]]:
43 ; CHECK-NEXT: [[IV_PROL:%.*]] = phi ptr [ [[P]], %[[LOOP_2_PROL_PREHEADER]] ], [ [[IV_NEXT_PROL:%.*]], %[[LOOP_2_PROL]] ]
44 ; CHECK-NEXT: [[PROL_ITER:%.*]] = phi i64 [ 0, %[[LOOP_2_PROL_PREHEADER]] ], [ [[PROL_ITER_NEXT:%.*]], %[[LOOP_2_PROL]] ]
45 ; CHECK-NEXT: [[IV_NEXT_PROL]] = getelementptr i8, ptr [[IV_PROL]], i64 8
46 ; CHECK-NEXT: [[ICMP_PROL:%.*]] = icmp eq ptr [[IV_PROL]], [[GEP]]
47 ; CHECK-NEXT: [[PROL_ITER_NEXT]] = add i64 [[PROL_ITER]], 1
48 ; CHECK-NEXT: [[PROL_ITER_CMP:%.*]] = icmp ne i64 [[PROL_ITER_NEXT]], [[XTRAITER]]
49 ; CHECK-NEXT: br i1 [[PROL_ITER_CMP]], label %[[LOOP_2_PROL]], label %[[LOOP_2_PROL_LOOPEXIT_UNR_LCSSA:.*]], !llvm.loop [[LOOP2:![0-9]+]]
50 ; CHECK: [[LOOP_2_PROL_LOOPEXIT_UNR_LCSSA]]:
51 ; CHECK-NEXT: [[IV_UNR_PH:%.*]] = phi ptr [ [[IV_NEXT_PROL]], %[[LOOP_2_PROL]] ]
52 ; CHECK-NEXT: br label %[[LOOP_2_PROL_LOOPEXIT]]
53 ; CHECK: [[LOOP_2_PROL_LOOPEXIT]]:
54 ; CHECK-NEXT: [[IV_UNR:%.*]] = phi ptr [ [[P]], %[[IF]] ], [ [[IV_UNR_PH]], %[[LOOP_2_PROL_LOOPEXIT_UNR_LCSSA]] ]
55 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ult i64 [[TMP1]], 7
56 ; CHECK-NEXT: br i1 [[TMP3]], label %[[EXIT:.*]], label %[[IF_NEW:.*]]
58 ; CHECK-NEXT: br label %[[LOOP_2:.*]]
60 ; CHECK-NEXT: [[IV:%.*]] = phi ptr [ [[IV_UNR]], %[[IF_NEW]] ], [ [[IV_NEXT_7:%.*]], %[[LOOP_2]] ]
61 ; CHECK-NEXT: [[IV_NEXT:%.*]] = getelementptr i8, ptr [[IV]], i64 8
62 ; CHECK-NEXT: [[IV_NEXT_1:%.*]] = getelementptr i8, ptr [[IV_NEXT]], i64 8
63 ; CHECK-NEXT: [[IV_NEXT_2:%.*]] = getelementptr i8, ptr [[IV_NEXT_1]], i64 8
64 ; CHECK-NEXT: [[IV_NEXT_3:%.*]] = getelementptr i8, ptr [[IV_NEXT_2]], i64 8
65 ; CHECK-NEXT: [[IV_NEXT_4:%.*]] = getelementptr i8, ptr [[IV_NEXT_3]], i64 8
66 ; CHECK-NEXT: [[IV_NEXT_5:%.*]] = getelementptr i8, ptr [[IV_NEXT_4]], i64 8
67 ; CHECK-NEXT: [[IV_NEXT_6:%.*]] = getelementptr i8, ptr [[IV_NEXT_5]], i64 8
68 ; CHECK-NEXT: [[IV_NEXT_7]] = getelementptr i8, ptr [[IV_NEXT_6]], i64 8
69 ; CHECK-NEXT: [[ICMP_7:%.*]] = icmp eq ptr [[IV_NEXT_6]], [[GEP]]
70 ; CHECK-NEXT: br i1 [[ICMP_7]], label %[[EXIT_UNR_LCSSA:.*]], label %[[LOOP_2]]
71 ; CHECK: [[EXIT_UNR_LCSSA]]:
72 ; CHECK-NEXT: br label %[[EXIT]]
74 ; CHECK-NEXT: ret void
80 %phi = phi ptr [ null, %entry ], [ %p, %loop.1 ]
81 %load = load i64, ptr %p, align 8
82 %add = add i64 %load, 1
83 br i1 %c, label %if, label %loop.1
86 %add.lcssa = phi i64 [ %add, %loop.1 ]
87 %gep = getelementptr i64, ptr %p, i64 %add.lcssa
91 %iv = phi ptr [ %p, %if ], [ %iv.next, %loop.2 ]
92 %iv.next = getelementptr i8, ptr %iv, i64 8
93 %icmp = icmp eq ptr %iv, %gep
94 br i1 %icmp, label %exit, label %loop.2
100 ; CHECK: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]]}
101 ; CHECK: [[META1]] = !{!"llvm.loop.peeled.count", i32 1}
102 ; CHECK: [[LOOP2]] = distinct !{[[LOOP2]], [[META3:![0-9]+]]}
103 ; CHECK: [[META3]] = !{!"llvm.loop.unroll.disable"}