1 ; RUN: opt -mtriple=thumbv8.1m.main-arm-none-eabi -hardware-loops -disable-arm-loloops=false %s -S -o - | FileCheck %s
2 ; RUN: opt -mtriple=thumbv8.1m.main-arm-none-eabi -hardware-loops -disable-arm-loloops=true %s -S -o - | FileCheck %s --check-prefix=DISABLED
3 ; RUN: opt -mtriple=thumbv8.1m.main-arm-none-eabi -mattr=-lob -hardware-loops %s -S -o - | FileCheck %s --check-prefix=DISABLED
4 ; RUN: llc -mtriple=thumbv8.1m.main-arm-none-eabi -disable-arm-loloops=false %s -o - | FileCheck %s --check-prefix=CHECK-LLC
6 ; DISABLED-NOT: llvm.{{.*}}.loop.iterations
7 ; DISABLED-NOT: llvm.loop.decrement
9 @g = common local_unnamed_addr global i32* null, align 4
11 ; CHECK-LABEL: do_copy
12 ; CHECK: call void @llvm.set.loop.iterations.i32(i32 %n)
13 ; CHECK: br label %while.body
15 ; CHECK: [[REM:%[^ ]+]] = phi i32 [ %n, %entry ], [ [[LOOP_DEC:%[^ ]+]], %while.body ]
16 ; CHECK: [[LOOP_DEC]] = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 [[REM]], i32 1)
17 ; CHECK: [[CMP:%[^ ]+]] = icmp ne i32 [[LOOP_DEC]], 0
18 ; CHECK: br i1 [[CMP]], label %while.body, label %while.end
20 ; CHECK-LLC-LABEL:do_copy:
21 ; CHECK-LLC-NOT: mov lr, r0
22 ; CHECK-LLC: dls lr, r0
23 ; CHECK-LLC-NOT: mov lr, r0
24 ; CHECK-LLC: [[LOOP_HEADER:\.LBB[0-9_]+]]:
25 ; CHECK-LLC: le lr, [[LOOP_HEADER]]
26 ; CHECK-LLC-NOT: b [[LOOP_EXIT:\.LBB[0-9._]+]]
27 ; CHECK-LLC: @ %while.end
28 define i32 @do_copy(i32 %n, i32* nocapture %p, i32* nocapture readonly %q) {
33 %q.addr.05 = phi i32* [ %incdec.ptr, %while.body ], [ %q, %entry ]
34 %p.addr.04 = phi i32* [ %incdec.ptr1, %while.body ], [ %p, %entry ]
35 %x.addr.03 = phi i32 [ %dec, %while.body ], [ %n, %entry ]
36 %dec = add nsw i32 %x.addr.03, -1
37 %incdec.ptr = getelementptr inbounds i32, i32* %q.addr.05, i32 1
38 %0 = load i32, i32* %q.addr.05, align 4
39 %incdec.ptr1 = getelementptr inbounds i32, i32* %p.addr.04, i32 1
40 store i32 %0, i32* %p.addr.04, align 4
41 %tobool = icmp eq i32 %dec, 0
42 br i1 %tobool, label %while.end, label %while.body
48 ; CHECK-LABEL: do_inc1
50 ; CHECK: [[TEST:%[^ ]+]] = call i1 @llvm.test.set.loop.iterations.i32(i32 %n)
51 ; CHECK: br i1 [[TEST]], label %while.body.lr.ph, label %while.end
53 ; CHECK: while.body.lr.ph:
54 ; CHECK: br label %while.body
56 ; CHECK: [[REM:%[^ ]+]] = phi i32 [ %n, %while.body.lr.ph ], [ [[LOOP_DEC:%[^ ]+]], %while.body ]
57 ; CHECK: [[LOOP_DEC]] = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 [[REM]], i32 1)
58 ; CHECK: [[CMP:%[^ ]+]] = icmp ne i32 [[LOOP_DEC]], 0
59 ; CHECK: br i1 [[CMP]], label %while.body, label %while.end.loopexit
61 ; CHECK-LLC-LABEL:do_inc1:
62 ; CHECK-LLC: wls lr, {{.*}}, [[LOOP_EXIT:.[LBB_0-3]+]]
63 ; CHECK-LLC-NOT: mov lr,
64 ; CHECK-LLC: [[LOOP_HEADER:\.LBB[0-9_]+]]:
65 ; CHECK-LLC: le lr, [[LOOP_HEADER]]
66 ; CHECK-LLC-NOT: b [[LOOP_EXIT:\.LBB[0-9_]+]]
67 ; CHECK-LLC: [[LOOP_EXIT]]:
69 define i32 @do_inc1(i32 %n) {
71 %cmp7 = icmp eq i32 %n, 0
72 br i1 %cmp7, label %while.end, label %while.body.lr.ph
75 %0 = load i32*, i32** @g, align 4
79 %i.09 = phi i32 [ 0, %while.body.lr.ph ], [ %inc1, %while.body ]
80 %res.08 = phi i32 [ 0, %while.body.lr.ph ], [ %add, %while.body ]
81 %arrayidx = getelementptr inbounds i32, i32* %0, i32 %i.09
82 %1 = load i32, i32* %arrayidx, align 4
83 %add = add nsw i32 %1, %res.08
84 %inc1 = add nuw i32 %i.09, 1
85 %exitcond = icmp eq i32 %inc1, %n
86 br i1 %exitcond, label %while.end.loopexit, label %while.body
92 %res.0.lcssa = phi i32 [ 0, %entry ], [ %add, %while.end.loopexit ]
96 ; CHECK-LABEL: do_inc2
98 ; CHECK: [[ROUND:%[^ ]+]] = add i32 %n, -1
99 ; CHECK: [[HALVE:%[^ ]+]] = lshr i32 [[ROUND]], 1
100 ; CHECK: [[COUNT:%[^ ]+]] = add nuw i32 [[HALVE]], 1
102 ; CHECK: while.body.lr.ph:
103 ; CHECK: call void @llvm.set.loop.iterations.i32(i32 [[COUNT]])
104 ; CHECK: br label %while.body
106 ; CHECK: [[REM:%[^ ]+]] = phi i32 [ [[COUNT]], %while.body.lr.ph ], [ [[LOOP_DEC:%[^ ]+]], %while.body ]
107 ; CHECK: [[LOOP_DEC]] = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 [[REM]], i32 1)
108 ; CHECK: [[CMP:%[^ ]+]] = icmp ne i32 [[LOOP_DEC]], 0
109 ; CHECK: br i1 [[CMP]], label %while.body, label %while.end.loopexit
111 ; CHECK-LLC: do_inc2:
112 ; CHECK-LLC-NOT: mov lr,
113 ; CHECK-LLC: dls lr, {{.*}}
114 ; CHECK-LLC-NOT: mov lr,
115 ; CHECK-LLC: [[LOOP_HEADER:\.LBB[0-9._]+]]:
116 ; CHECK-LLC: le lr, [[LOOP_HEADER]]
118 define i32 @do_inc2(i32 %n) {
120 %cmp7 = icmp sgt i32 %n, 0
121 br i1 %cmp7, label %while.body.lr.ph, label %while.end
124 %0 = load i32*, i32** @g, align 4
128 %i.09 = phi i32 [ 0, %while.body.lr.ph ], [ %add1, %while.body ]
129 %res.08 = phi i32 [ 0, %while.body.lr.ph ], [ %add, %while.body ]
130 %arrayidx = getelementptr inbounds i32, i32* %0, i32 %i.09
131 %1 = load i32, i32* %arrayidx, align 4
132 %add = add nsw i32 %1, %res.08
133 %add1 = add nuw nsw i32 %i.09, 2
134 %cmp = icmp slt i32 %add1, %n
135 br i1 %cmp, label %while.body, label %while.end.loopexit
141 %res.0.lcssa = phi i32 [ 0, %entry ], [ %add, %while.end.loopexit ]
145 ; CHECK-LABEL: do_dec2
148 ; CHECK: [[ROUND:%[^ ]+]] = add i32 %n, 1
149 ; CHECK: [[CMP:%[^ ]+]] = icmp slt i32 %n, 2
150 ; CHECK: [[SMIN:%[^ ]+]] = select i1 [[CMP]], i32 %n, i32 2
151 ; CHECK: [[SUB:%[^ ]+]] = sub i32 [[ROUND]], [[SMIN]]
152 ; CHECK: [[HALVE:%[^ ]+]] = lshr i32 [[SUB]], 1
153 ; CHECK: [[COUNT:%[^ ]+]] = add nuw i32 [[HALVE]], 1
155 ; CHECK: while.body.lr.ph:
156 ; CHECK: call void @llvm.set.loop.iterations.i32(i32 [[COUNT]])
157 ; CHECK: br label %while.body
159 ; CHECK: [[REM:%[^ ]+]] = phi i32 [ [[COUNT]], %while.body.lr.ph ], [ [[LOOP_DEC:%[^ ]+]], %while.body ]
160 ; CHECK: [[LOOP_DEC]] = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 [[REM]], i32 1)
161 ; CHECK: [[CMP:%[^ ]+]] = icmp ne i32 [[LOOP_DEC]], 0
162 ; CHECK: br i1 [[CMP]], label %while.body, label %while.end.loopexit
165 ; CHECK-LLC-NOT: mov lr,
166 ; CHECK-LLC: dls lr, {{.*}}
167 ; CHECK-LLC-NOT: mov lr,
168 ; CHECK-LLC: [[LOOP_HEADER:\.LBB[0-9_]+]]:
169 ; CHECK-LLC: le lr, [[LOOP_HEADER]]
171 define i32 @do_dec2(i32 %n) {
173 %cmp6 = icmp sgt i32 %n, 0
174 br i1 %cmp6, label %while.body.lr.ph, label %while.end
177 %0 = load i32*, i32** @g, align 4
181 %i.08 = phi i32 [ %n, %while.body.lr.ph ], [ %sub, %while.body ]
182 %res.07 = phi i32 [ 0, %while.body.lr.ph ], [ %add, %while.body ]
183 %arrayidx = getelementptr inbounds i32, i32* %0, i32 %i.08
184 %1 = load i32, i32* %arrayidx, align 4
185 %add = add nsw i32 %1, %res.07
186 %sub = add nsw i32 %i.08, -2
187 %cmp = icmp sgt i32 %i.08, 2
188 br i1 %cmp, label %while.body, label %while.end.loopexit
194 %res.0.lcssa = phi i32 [ 0, %entry ], [ %add, %while.end.loopexit ]