1 ; RUN: opt -mtriple=thumbv8.1m.main-none-none-eabi -hardware-loops %s -S -o - | FileCheck %s
2 ; RUN: opt -mtriple=thumbv8.1m.main-none-none-eabi -hardware-loops -disable-arm-loloops=true %s -S -o - | FileCheck %s --check-prefix=DISABLED
3 ; RUN: llc -mtriple=thumbv8.1m.main-none-none-eabi %s -o - | FileCheck %s --check-prefix=CHECK-LLC
5 ; DISABLED-NOT: llvm.{{.*}}.loop.iterations
6 ; DISABLED-NOT: llvm.loop.decrement
8 @g = common local_unnamed_addr global i32* null, align 4
10 ; CHECK-LABEL: do_copy
11 ; CHECK: [[START:%[^ ]+]] = call i32 @llvm.start.loop.iterations.i32(i32 %n)
12 ; CHECK: br label %while.body
14 ; CHECK: [[REM:%[^ ]+]] = phi i32 [ [[START]], %entry ], [ [[LOOP_DEC:%[^ ]+]], %while.body ]
15 ; CHECK: [[LOOP_DEC]] = call i32 @llvm.loop.decrement.reg.i32(i32 [[REM]], i32 1)
16 ; CHECK: [[CMP:%[^ ]+]] = icmp ne i32 [[LOOP_DEC]], 0
17 ; CHECK: br i1 [[CMP]], label %while.body, label %while.end
19 ; CHECK-LLC-LABEL:do_copy:
20 ; CHECK-LLC-NOT: mov lr, r0
21 ; CHECK-LLC: dls lr, r0
22 ; CHECK-LLC-NOT: mov lr, r0
23 ; CHECK-LLC: [[LOOP_HEADER:\.LBB[0-9_]+]]:
24 ; CHECK-LLC: le lr, [[LOOP_HEADER]]
25 ; CHECK-LLC-NOT: b [[LOOP_EXIT:\.LBB[0-9._]+]]
26 ; CHECK-LLC: @ %while.end
27 define i32 @do_copy(i32 %n, i32* nocapture %p, i32* nocapture readonly %q) {
32 %q.addr.05 = phi i32* [ %incdec.ptr, %while.body ], [ %q, %entry ]
33 %p.addr.04 = phi i32* [ %incdec.ptr1, %while.body ], [ %p, %entry ]
34 %x.addr.03 = phi i32 [ %dec, %while.body ], [ %n, %entry ]
35 %dec = add nsw i32 %x.addr.03, -1
36 %incdec.ptr = getelementptr inbounds i32, i32* %q.addr.05, i32 1
37 %0 = load i32, i32* %q.addr.05, align 4
38 %incdec.ptr1 = getelementptr inbounds i32, i32* %p.addr.04, i32 1
39 store i32 %0, i32* %p.addr.04, align 4
40 %tobool = icmp eq i32 %dec, 0
41 br i1 %tobool, label %while.end, label %while.body
47 ; CHECK-LABEL: do_inc1
49 ; CHECK: [[TEST:%[^ ]+]] = call { i32, i1 } @llvm.test.start.loop.iterations.i32(i32 %n)
50 ; CHECK: [[TEST1:%[^ ]+]] = extractvalue { i32, i1 } [[TEST]], 1
51 ; CHECK: [[TEST0:%[^ ]+]] = extractvalue { i32, i1 } [[TEST]], 0
52 ; CHECK: br i1 [[TEST1]], label %while.body.lr.ph, label %while.end
54 ; CHECK: while.body.lr.ph:
55 ; CHECK: br label %while.body
57 ; CHECK: [[REM:%[^ ]+]] = phi i32 [ [[TEST0]], %while.body.lr.ph ], [ [[LOOP_DEC:%[^ ]+]], %while.body ]
58 ; CHECK: [[LOOP_DEC]] = call i32 @llvm.loop.decrement.reg.i32(i32 [[REM]], i32 1)
59 ; CHECK: [[CMP:%[^ ]+]] = icmp ne i32 [[LOOP_DEC]], 0
60 ; CHECK: br i1 [[CMP]], label %while.body, label %while.end.loopexit
62 ; CHECK-LLC-LABEL:do_inc1:
63 ; CHECK-LLC: wls lr, {{.*}}, [[LOOP_EXIT:.[LBB_0-3]+]]
64 ; CHECK-LLC-NOT: mov lr,
65 ; CHECK-LLC: [[LOOP_HEADER:\.LBB[0-9_]+]]:
66 ; CHECK-LLC: le lr, [[LOOP_HEADER]]
67 ; CHECK-LLC-NOT: b [[LOOP_EXIT:\.LBB[0-9_]+]]
68 ; CHECK-LLC: [[LOOP_EXIT]]:
70 define i32 @do_inc1(i32 %n) {
72 %cmp7 = icmp eq i32 %n, 0
73 br i1 %cmp7, label %while.end, label %while.body.lr.ph
76 %0 = load i32*, i32** @g, align 4
80 %i.09 = phi i32 [ 0, %while.body.lr.ph ], [ %inc1, %while.body ]
81 %res.08 = phi i32 [ 0, %while.body.lr.ph ], [ %add, %while.body ]
82 %arrayidx = getelementptr inbounds i32, i32* %0, i32 %i.09
83 %1 = load i32, i32* %arrayidx, align 4
84 %add = add nsw i32 %1, %res.08
85 %inc1 = add nuw i32 %i.09, 1
86 %exitcond = icmp eq i32 %inc1, %n
87 br i1 %exitcond, label %while.end.loopexit, label %while.body
93 %res.0.lcssa = phi i32 [ 0, %entry ], [ %add, %while.end.loopexit ]
97 ; CHECK-LABEL: do_inc2
99 ; CHECK: [[ROUND:%[^ ]+]] = add i32 %n, -1
100 ; CHECK: [[HALVE:%[^ ]+]] = lshr i32 [[ROUND]], 1
101 ; CHECK: [[COUNT:%[^ ]+]] = add nuw i32 [[HALVE]], 1
103 ; CHECK: while.body.lr.ph:
104 ; CHECK: [[START:%[^ ]+]] = call i32 @llvm.start.loop.iterations.i32(i32 [[COUNT]])
105 ; CHECK: br label %while.body
107 ; CHECK: [[REM:%[^ ]+]] = phi i32 [ [[START]], %while.body.lr.ph ], [ [[LOOP_DEC:%[^ ]+]], %while.body ]
108 ; CHECK: [[LOOP_DEC]] = call i32 @llvm.loop.decrement.reg.i32(i32 [[REM]], i32 1)
109 ; CHECK: [[CMP:%[^ ]+]] = icmp ne i32 [[LOOP_DEC]], 0
110 ; CHECK: br i1 [[CMP]], label %while.body, label %while.end.loopexit
112 ; CHECK-LLC: do_inc2:
113 ; CHECK-LLC-NOT: mov lr,
114 ; CHECK-LLC: add.w lr,
115 ; CHECK-LLC-NOT: dls lr,
116 ; CHECK-LLC-NOT: mov lr,
117 ; CHECK-LLC: [[LOOP_HEADER:\.LBB[0-9._]+]]:
118 ; CHECK-LLC: le lr, [[LOOP_HEADER]]
120 define i32 @do_inc2(i32 %n) {
122 %cmp7 = icmp sgt i32 %n, 0
123 br i1 %cmp7, label %while.body.lr.ph, label %while.end
126 %0 = load i32*, i32** @g, align 4
130 %i.09 = phi i32 [ 0, %while.body.lr.ph ], [ %add1, %while.body ]
131 %res.08 = phi i32 [ 0, %while.body.lr.ph ], [ %add, %while.body ]
132 %arrayidx = getelementptr inbounds i32, i32* %0, i32 %i.09
133 %1 = load i32, i32* %arrayidx, align 4
134 %add = add nsw i32 %1, %res.08
135 %add1 = add nuw nsw i32 %i.09, 2
136 %cmp = icmp slt i32 %add1, %n
137 br i1 %cmp, label %while.body, label %while.end.loopexit
143 %res.0.lcssa = phi i32 [ 0, %entry ], [ %add, %while.end.loopexit ]
147 ; CHECK-LABEL: do_dec2
150 ; CHECK: [[ROUND:%[^ ]+]] = add i32 %n, 1
151 ; CHECK: [[SMIN:%[^ ]+]] = call i32 @llvm.smin.i32(i32 %n, i32 2)
152 ; CHECK: [[SUB:%[^ ]+]] = sub i32 [[ROUND]], [[SMIN]]
153 ; CHECK: [[HALVE:%[^ ]+]] = lshr i32 [[SUB]], 1
154 ; CHECK: [[COUNT:%[^ ]+]] = add nuw i32 [[HALVE]], 1
156 ; CHECK: while.body.lr.ph:
157 ; CHECK: [[START:%[^ ]+]] = call i32 @llvm.start.loop.iterations.i32(i32 [[COUNT]])
158 ; CHECK: br label %while.body
160 ; CHECK: [[REM:%[^ ]+]] = phi i32 [ [[START]], %while.body.lr.ph ], [ [[LOOP_DEC:%[^ ]+]], %while.body ]
161 ; CHECK: [[LOOP_DEC]] = call i32 @llvm.loop.decrement.reg.i32(i32 [[REM]], i32 1)
162 ; CHECK: [[CMP:%[^ ]+]] = icmp ne i32 [[LOOP_DEC]], 0
163 ; CHECK: br i1 [[CMP]], label %while.body, label %while.end.loopexit
166 ; CHECK-LLC-NOT: mov lr,
167 ; CHECK-LLC: add.w lr,
168 ; CHECK-LLC-NOT: dls lr,
169 ; CHECK-LLC-NOT: mov lr,
170 ; CHECK-LLC: [[LOOP_HEADER:\.LBB[0-9_]+]]:
171 ; CHECK-LLC: le lr, [[LOOP_HEADER]]
173 define i32 @do_dec2(i32 %n) {
175 %cmp6 = icmp sgt i32 %n, 0
176 br i1 %cmp6, label %while.body.lr.ph, label %while.end
179 %0 = load i32*, i32** @g, align 4
183 %i.08 = phi i32 [ %n, %while.body.lr.ph ], [ %sub, %while.body ]
184 %res.07 = phi i32 [ 0, %while.body.lr.ph ], [ %add, %while.body ]
185 %arrayidx = getelementptr inbounds i32, i32* %0, i32 %i.08
186 %1 = load i32, i32* %arrayidx, align 4
187 %add = add nsw i32 %1, %res.07
188 %sub = add nsw i32 %i.08, -2
189 %cmp = icmp sgt i32 %i.08, 2
190 br i1 %cmp, label %while.body, label %while.end.loopexit
196 %res.0.lcssa = phi i32 [ 0, %entry ], [ %add, %while.end.loopexit ]