1 ; RUN: opt -hardware-loops -force-hardware-loops=true -hardware-loop-decrement=1 -hardware-loop-counter-bitwidth=32 -S %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-DEC
2 ; RUN: opt -hardware-loops -force-hardware-loops=true -hardware-loop-decrement=1 -hardware-loop-counter-bitwidth=32 -force-hardware-loop-phi=true -S %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-REGDEC
3 ; RUN: opt -hardware-loops -force-hardware-loops=true -hardware-loop-decrement=1 -hardware-loop-counter-bitwidth=32 -force-nested-hardware-loop=true -S %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-DEC --check-prefix=CHECK-NESTED
4 ; RUN: opt -hardware-loops -force-hardware-loops=true -hardware-loop-decrement=1 -hardware-loop-counter-bitwidth=32 -force-hardware-loop-guard=true -S %s -o - | FileCheck %s --check-prefix=CHECK-GUARD
5 ; RUN: opt -hardware-loops -force-hardware-loops=true -hardware-loop-decrement=1 -hardware-loop-counter-bitwidth=32 -force-hardware-loop-phi=true -force-hardware-loop-guard=true -S %s -o - | FileCheck %s --check-prefix=CHECK-GUARD
7 ; CHECK-LABEL: while_lt
8 define void @while_lt(i32 %i, i32 %N, i32* nocapture %A) {
10 %cmp4 = icmp ult i32 %i, %N
11 br i1 %cmp4, label %while.body, label %while.end
13 ; CHECK-GUARD-LABEL: while_lt
14 ; CHECK-GUARD: [[COUNT:%[^ ]+]] = sub i32 %N, %i
15 ; CHECK-GUARD: call void @llvm.set.loop.iterations.i32(i32 [[COUNT]])
16 ; CHECK-GUARD: br label %while.body
18 ; CHECK: while.body.preheader:
19 ; CHECK: [[COUNT:%[^ ]+]] = sub i32 %N, %i
20 ; CHECK: call void @llvm.set.loop.iterations.i32(i32 [[COUNT]])
21 ; CHECK: br label %while.body
23 ; CHECK-REGDEC: [[REM:%[^ ]+]] = phi i32 [ [[COUNT]], %while.body.preheader ], [ [[LOOP_DEC:%[^ ]+]], %while.body ]
24 ; CHECK-REGDEC: [[LOOP_DEC]] = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 [[REM]], i32 1)
25 ; CHECK-REGDEC: [[CMP:%[^ ]+]] = icmp ne i32 [[LOOP_DEC]], 0
26 ; CHECK-REGDEC: br i1 [[CMP]], label %while.body, label %while.end
28 ; CHECK-DEC: [[LOOP_DEC:%[^ ]+]] = call i1 @llvm.loop.decrement.i32(i32 1)
29 ; CHECK-DEC: br i1 [[LOOP_DEC]], label %while.body, label %while.end
32 %i.addr.05 = phi i32 [ %inc, %while.body ], [ %i, %entry ]
33 %arrayidx = getelementptr inbounds i32, i32* %A, i32 %i.addr.05
34 store i32 %i.addr.05, i32* %arrayidx, align 4
35 %inc = add nuw i32 %i.addr.05, 1
36 %exitcond = icmp eq i32 %inc, %N
37 br i1 %exitcond, label %while.end, label %while.body
43 ; CHECK-LABEL: while_gt
44 ; CHECK: while.body.preheader:
45 ; CHECK: [[COUNT:%[^ ]+]] = sub i32 %i, %N
46 ; CHECK: call void @llvm.set.loop.iterations.i32(i32 [[COUNT]])
47 ; CHECK: br label %while.body
49 ; CHECK-REGDEC: [[REM:%[^ ]+]] = phi i32 [ [[COUNT]], %while.body.preheader ], [ [[LOOP_DEC:%[^ ]+]], %while.body ]
50 ; CHECK-REGDEC: [[LOOP_DEC]] = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 [[REM]], i32 1)
51 ; CHECK-REGDEC: [[CMP:%[^ ]+]] = icmp ne i32 [[LOOP_DEC]], 0
52 ; CHECK-REGDEC: br i1 [[CMP]], label %while.body, label %while.end
54 ; CHECK-DEC: [[LOOP_DEC:%[^ ]+]] = call i1 @llvm.loop.decrement.i32(i32 1)
55 ; CHECK-DEC: br i1 [[LOOP_DEC]], label %while.body, label %while.end
57 define void @while_gt(i32 %i, i32 %N, i32* nocapture %A) {
59 %cmp4 = icmp sgt i32 %i, %N
60 br i1 %cmp4, label %while.body, label %while.end
63 %i.addr.05 = phi i32 [ %dec, %while.body ], [ %i, %entry ]
64 %arrayidx = getelementptr inbounds i32, i32* %A, i32 %i.addr.05
65 store i32 %i.addr.05, i32* %arrayidx, align 4
66 %dec = add nsw i32 %i.addr.05, -1
67 %cmp = icmp sgt i32 %dec, %N
68 br i1 %cmp, label %while.body, label %while.end
74 ; CHECK-GUARD-LABEL: while_gte
76 ; CHECK-GUARD: br i1 %cmp4, label %while.end, label %while.body.preheader
77 ; CHECK-GUARD: while.body.preheader:
78 ; CHECK-GUARD: [[ADD:%[^ ]+]] = add i32 %i, 1
79 ; CHECK-GUARD: [[SEL:%[^ ]+]] = icmp slt i32 %N, %i
80 ; CHECK-GUARD: [[MIN:%[^ ]+]] = select i1 [[SEL]], i32 %N, i32 %i
81 ; CHECK-GUARD: [[COUNT:%[^ ]+]] = sub i32 [[ADD]], [[MIN]]
82 ; CHECK-GUARD: call void @llvm.set.loop.iterations.i32(i32 [[COUNT]])
83 ; CHECK-GUARD: br label %while.body
85 ; CHECK-LABEL: while_gte
86 ; CHECK: while.body.preheader:
87 ; CHECK: [[ADD:%[^ ]+]] = add i32 %i, 1
88 ; CHECK: [[SEL:%[^ ]+]] = icmp slt i32 %N, %i
89 ; CHECK: [[MIN:%[^ ]+]] = select i1 [[SEL]], i32 %N, i32 %i
90 ; CHECK: [[COUNT:%[^ ]+]] = sub i32 [[ADD]], [[MIN]]
91 ; CHECK: call void @llvm.set.loop.iterations.i32(i32 [[COUNT]])
92 ; CHECK: br label %while.body
94 ; CHECK-REGDEC: [[REM:%[^ ]+]] = phi i32 [ [[COUNT]], %while.body.preheader ], [ [[LOOP_DEC:%[^ ]+]], %while.body ]
95 ; CHECK-REGDEC: [[LOOP_DEC]] = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 [[REM]], i32 1)
96 ; CHECK-REGDEC: [[CMP:%[^ ]+]] = icmp ne i32 [[LOOP_DEC]], 0
97 ; CHECK-REGDEC: br i1 [[CMP]], label %while.body, label %while.end
99 ; CHECK-DEC: [[LOOP_DEC:%[^ ]+]] = call i1 @llvm.loop.decrement.i32(i32 1)
100 ; CHECK-DEC: br i1 [[LOOP_DEC]], label %while.body, label %while.end
102 define void @while_gte(i32 %i, i32 %N, i32* nocapture %A) {
104 %cmp4 = icmp slt i32 %i, %N
105 br i1 %cmp4, label %while.end, label %while.body
108 %i.addr.05 = phi i32 [ %dec, %while.body ], [ %i, %entry ]
109 %arrayidx = getelementptr inbounds i32, i32* %A, i32 %i.addr.05
110 store i32 %i.addr.05, i32* %arrayidx, align 4
111 %dec = add nsw i32 %i.addr.05, -1
112 %cmp = icmp sgt i32 %i.addr.05, %N
113 br i1 %cmp, label %while.body, label %while.end
119 ; CHECK-GUARD-LABEL: while_ne
120 ; CHECK-GUARD: entry:
121 ; CHECK-GUARD: [[TEST:%[^ ]+]] = call i1 @llvm.test.set.loop.iterations.i32(i32 %N)
122 ; CHECK-GUARD: br i1 [[TEST]], label %while.body.preheader, label %while.end
123 ; CHECK-GUARD: while.body.preheader:
124 ; CHECK-GUARD: br label %while.body
125 define void @while_ne(i32 %N, i32* nocapture %A) {
127 %cmp = icmp ne i32 %N, 0
128 br i1 %cmp, label %while.body, label %while.end
131 %i.addr.05 = phi i32 [ %inc, %while.body ], [ 0, %entry ]
132 %arrayidx = getelementptr inbounds i32, i32* %A, i32 %i.addr.05
133 store i32 %i.addr.05, i32* %arrayidx, align 4
134 %inc = add nuw i32 %i.addr.05, 1
135 %exitcond = icmp eq i32 %inc, %N
136 br i1 %exitcond, label %while.end, label %while.body
142 ; CHECK-GUARD-LABEL: while_eq
143 ; CHECK-GUARD: entry:
144 ; CHECK-GUARD: [[TEST:%[^ ]+]] = call i1 @llvm.test.set.loop.iterations.i32(i32 %N)
145 ; CHECK-GUARD: br i1 [[TEST]], label %while.body.preheader, label %while.end
146 ; CHECK-GUARD: while.body.preheader:
147 ; CHECK-GUARD: br label %while.body
148 define void @while_eq(i32 %N, i32* nocapture %A) {
150 %cmp = icmp eq i32 %N, 0
151 br i1 %cmp, label %while.end, label %while.body
154 %i.addr.05 = phi i32 [ %inc, %while.body ], [ 0, %entry ]
155 %arrayidx = getelementptr inbounds i32, i32* %A, i32 %i.addr.05
156 store i32 %i.addr.05, i32* %arrayidx, align 4
157 %inc = add nuw i32 %i.addr.05, 1
158 %exitcond = icmp eq i32 %inc, %N
159 br i1 %exitcond, label %while.end, label %while.body
165 ; CHECK-GUARD-LABEL: while_preheader_eq
166 ; CHECK-GUARD: entry:
167 ; CHECK-GUARD: br label %preheader
168 ; CHECK-GUARD: preheader:
169 ; CHECK-GUARD: [[TEST:%[^ ]+]] = call i1 @llvm.test.set.loop.iterations.i32(i32 %N)
170 ; CHECK-GUARD: br i1 [[TEST]], label %while.body.preheader, label %while.end
171 ; CHECK-GUARD: while.body.preheader:
172 ; CHECK-GUARD: br label %while.body
173 define void @while_preheader_eq(i32 %N, i32* nocapture %A) {
178 %cmp = icmp eq i32 %N, 0
179 br i1 %cmp, label %while.end, label %while.body
182 %i.addr.05 = phi i32 [ %inc, %while.body ], [ 0, %preheader ]
183 %arrayidx = getelementptr inbounds i32, i32* %A, i32 %i.addr.05
184 store i32 %i.addr.05, i32* %arrayidx, align 4
185 %inc = add nuw i32 %i.addr.05, 1
186 %exitcond = icmp eq i32 %inc, %N
187 br i1 %exitcond, label %while.end, label %while.body
193 ; CHECK-LABEL: nested
194 ; CHECK-NESTED: call void @llvm.set.loop.iterations.i32(i32 %N)
195 ; CHECK-NESTED: br label %while.cond1.preheader.us
197 ; CHECK: call void @llvm.set.loop.iterations.i32(i32 %N)
198 ; CHECK: br label %while.body3.us
200 ; CHECK-DEC: [[LOOP_DEC:%[^ ]+]] = call i1 @llvm.loop.decrement.i32(i32 1)
202 ; CHECK-REGDEC: [[REM:%[^ ]+]] = phi i32 [ %N, %while.cond1.preheader.us ], [ [[LOOP_DEC:%[^ ]+]], %while.body3.us ]
203 ; CHECK-REGDEC: [[LOOP_DEC]] = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 [[REM]], i32 1)
204 ; CHECK-REGDEC: [[CMP:%[^ ]+]] = icmp ne i32 [[LOOP_DEC]], 0
205 ; CHECK-REGDEC: br i1 [[CMP]], label %while.body3.us, label %while.cond1.while.end_crit_edge.us
207 ; CHECK-NESTED: [[LOOP_DEC1:%[^ ]+]] = call i1 @llvm.loop.decrement.i32(i32 1)
208 ; CHECK-NESTED: br i1 [[LOOP_DEC1]], label %while.cond1.preheader.us, label %while.end7
210 ; CHECK-GUARD: while.cond1.preheader.us:
211 ; CHECK-GUARD: call void @llvm.set.loop.iterations.i32(i32 %N)
212 ; CHECK-GUARD: br label %while.body3.us
214 define void @nested(i32* nocapture %A, i32 %N) {
216 %cmp20 = icmp eq i32 %N, 0
217 br i1 %cmp20, label %while.end7, label %while.cond1.preheader.us
219 while.cond1.preheader.us:
220 %i.021.us = phi i32 [ %inc6.us, %while.cond1.while.end_crit_edge.us ], [ 0, %entry ]
221 %mul.us = mul i32 %i.021.us, %N
222 br label %while.body3.us
225 %j.019.us = phi i32 [ 0, %while.cond1.preheader.us ], [ %inc.us, %while.body3.us ]
226 %add.us = add i32 %j.019.us, %mul.us
227 %arrayidx.us = getelementptr inbounds i32, i32* %A, i32 %add.us
228 store i32 %add.us, i32* %arrayidx.us, align 4
229 %inc.us = add nuw i32 %j.019.us, 1
230 %exitcond = icmp eq i32 %inc.us, %N
231 br i1 %exitcond, label %while.cond1.while.end_crit_edge.us, label %while.body3.us
233 while.cond1.while.end_crit_edge.us:
234 %inc6.us = add nuw i32 %i.021.us, 1
235 %exitcond23 = icmp eq i32 %inc6.us, %N
236 br i1 %exitcond23, label %while.end7, label %while.cond1.preheader.us