1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2 ; RUN: opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s | FileCheck %s
3 ; RUN: opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=2 -S %s | FileCheck %s
4 ; RUN: opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -S %s | FileCheck %s
6 ; Test cases for selecting the index with the minimum value.
8 define i64 @test_vectorize_select_umin_idx(ptr %src, i64 %n) {
9 ; CHECK-LABEL: define i64 @test_vectorize_select_umin_idx(
10 ; CHECK-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) {
11 ; CHECK-NEXT: [[ENTRY:.*]]:
12 ; CHECK-NEXT: br label %[[LOOP:.*]]
14 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
15 ; CHECK-NEXT: [[MIN_IDX:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_IDX_NEXT:%.*]], %[[LOOP]] ]
16 ; CHECK-NEXT: [[MIN_VAL:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_VAL_NEXT:%.*]], %[[LOOP]] ]
17 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i64, ptr [[SRC]], i64 [[IV]]
18 ; CHECK-NEXT: [[L:%.*]] = load i64, ptr [[GEP]], align 4
19 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[MIN_VAL]], [[L]]
20 ; CHECK-NEXT: [[MIN_VAL_NEXT]] = tail call i64 @llvm.umin.i64(i64 [[MIN_VAL]], i64 [[L]])
21 ; CHECK-NEXT: [[MIN_IDX_NEXT]] = select i1 [[CMP]], i64 [[IV]], i64 [[MIN_IDX]]
22 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
23 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
24 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[LOOP]]
26 ; CHECK-NEXT: [[RES:%.*]] = phi i64 [ [[MIN_IDX_NEXT]], %[[LOOP]] ]
27 ; CHECK-NEXT: ret i64 [[RES]]
33 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
34 %min.idx = phi i64 [ 0, %entry ], [ %min.idx.next, %loop ]
35 %min.val = phi i64 [ 0, %entry ], [ %min.val.next, %loop ]
36 %gep = getelementptr i64, ptr %src, i64 %iv
37 %l = load i64, ptr %gep
38 %cmp = icmp ugt i64 %min.val, %l
39 %min.val.next = tail call i64 @llvm.umin.i64(i64 %min.val, i64 %l)
40 %min.idx.next = select i1 %cmp, i64 %iv, i64 %min.idx
41 %iv.next = add nuw nsw i64 %iv, 1
42 %exitcond.not = icmp eq i64 %iv.next, %n
43 br i1 %exitcond.not, label %exit, label %loop
46 %res = phi i64 [ %min.idx.next, %loop ]
50 define i64 @test_vectorize_select_umin_idx_all_exit_inst(ptr %src, ptr %umin, i64 %n) {
51 ; CHECK-LABEL: define i64 @test_vectorize_select_umin_idx_all_exit_inst(
52 ; CHECK-SAME: ptr [[SRC:%.*]], ptr [[UMIN:%.*]], i64 [[N:%.*]]) {
53 ; CHECK-NEXT: [[ENTRY:.*]]:
54 ; CHECK-NEXT: br label %[[LOOP:.*]]
56 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
57 ; CHECK-NEXT: [[MIN_IDX:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_IDX_NEXT:%.*]], %[[LOOP]] ]
58 ; CHECK-NEXT: [[MIN_VAL:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_VAL_NEXT:%.*]], %[[LOOP]] ]
59 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i64, ptr [[SRC]], i64 [[IV]]
60 ; CHECK-NEXT: [[L:%.*]] = load i64, ptr [[GEP]], align 4
61 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[MIN_VAL]], [[L]]
62 ; CHECK-NEXT: [[MIN_VAL_NEXT]] = tail call i64 @llvm.umin.i64(i64 [[MIN_VAL]], i64 [[L]])
63 ; CHECK-NEXT: [[MIN_IDX_NEXT]] = select i1 [[CMP]], i64 [[IV]], i64 [[MIN_IDX]]
64 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
65 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
66 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[LOOP]]
68 ; CHECK-NEXT: [[RES:%.*]] = phi i64 [ [[MIN_IDX_NEXT]], %[[LOOP]] ]
69 ; CHECK-NEXT: [[RES_UMIN:%.*]] = phi i64 [ [[MIN_VAL_NEXT]], %[[LOOP]] ]
70 ; CHECK-NEXT: store i64 [[RES_UMIN]], ptr [[UMIN]], align 4
71 ; CHECK-NEXT: ret i64 [[RES]]
77 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
78 %min.idx = phi i64 [ 0, %entry ], [ %min.idx.next, %loop ]
79 %min.val = phi i64 [ 0, %entry ], [ %min.val.next, %loop ]
80 %gep = getelementptr i64, ptr %src, i64 %iv
81 %l = load i64, ptr %gep
82 %cmp = icmp ugt i64 %min.val, %l
83 %min.val.next = tail call i64 @llvm.umin.i64(i64 %min.val, i64 %l)
84 %min.idx.next = select i1 %cmp, i64 %iv, i64 %min.idx
85 %iv.next = add nuw nsw i64 %iv, 1
86 %exitcond.not = icmp eq i64 %iv.next, %n
87 br i1 %exitcond.not, label %exit, label %loop
90 %res = phi i64 [ %min.idx.next, %loop ]
91 %res.umin = phi i64 [ %min.val.next, %loop ]
92 store i64 %res.umin, ptr %umin
96 define i64 @test_vectorize_select_umin_idx_min_ops_switched(ptr %src, i64 %n) {
97 ; CHECK-LABEL: define i64 @test_vectorize_select_umin_idx_min_ops_switched(
98 ; CHECK-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) {
99 ; CHECK-NEXT: [[ENTRY:.*]]:
100 ; CHECK-NEXT: br label %[[LOOP:.*]]
102 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
103 ; CHECK-NEXT: [[MIN_IDX:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_IDX_NEXT:%.*]], %[[LOOP]] ]
104 ; CHECK-NEXT: [[MIN_VAL:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_VAL_NEXT:%.*]], %[[LOOP]] ]
105 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i64, ptr [[SRC]], i64 [[IV]]
106 ; CHECK-NEXT: [[L:%.*]] = load i64, ptr [[GEP]], align 4
107 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[MIN_VAL]], [[L]]
108 ; CHECK-NEXT: [[MIN_VAL_NEXT]] = tail call i64 @llvm.umin.i64(i64 [[L]], i64 [[MIN_VAL]])
109 ; CHECK-NEXT: [[MIN_IDX_NEXT]] = select i1 [[CMP]], i64 [[IV]], i64 [[MIN_IDX]]
110 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
111 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
112 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[LOOP]]
114 ; CHECK-NEXT: [[RES:%.*]] = phi i64 [ [[MIN_IDX_NEXT]], %[[LOOP]] ]
115 ; CHECK-NEXT: ret i64 [[RES]]
121 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
122 %min.idx = phi i64 [ 0, %entry ], [ %min.idx.next, %loop ]
123 %min.val = phi i64 [ 0, %entry ], [ %min.val.next, %loop ]
124 %gep = getelementptr i64, ptr %src, i64 %iv
125 %l = load i64, ptr %gep
126 %cmp = icmp ugt i64 %min.val, %l
127 %min.val.next = tail call i64 @llvm.umin.i64(i64 %l, i64 %min.val)
128 %min.idx.next = select i1 %cmp, i64 %iv, i64 %min.idx
129 %iv.next = add nuw nsw i64 %iv, 1
130 %exitcond.not = icmp eq i64 %iv.next, %n
131 br i1 %exitcond.not, label %exit, label %loop
134 %res = phi i64 [ %min.idx.next, %loop ]
138 define i64 @test_not_vectorize_select_no_min_reduction(ptr %src, i64 %n) {
139 ; CHECK-LABEL: define i64 @test_not_vectorize_select_no_min_reduction(
140 ; CHECK-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) {
141 ; CHECK-NEXT: [[ENTRY:.*]]:
142 ; CHECK-NEXT: br label %[[LOOP:.*]]
144 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
145 ; CHECK-NEXT: [[MIN_IDX:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_IDX_NEXT:%.*]], %[[LOOP]] ]
146 ; CHECK-NEXT: [[MIN_VAL:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_VAL_NEXT:%.*]], %[[LOOP]] ]
147 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i64, ptr [[SRC]], i64 [[IV]]
148 ; CHECK-NEXT: [[L:%.*]] = load i64, ptr [[GEP]], align 4
149 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[MIN_VAL]], [[L]]
150 ; CHECK-NEXT: [[MIN_VAL_NEXT]] = add i64 [[L]], 1
151 ; CHECK-NEXT: [[FOO:%.*]] = call i64 @llvm.umin.i64(i64 [[MIN_VAL]], i64 [[L]])
152 ; CHECK-NEXT: [[MIN_IDX_NEXT]] = select i1 [[CMP]], i64 [[IV]], i64 [[MIN_IDX]]
153 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
154 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
155 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[LOOP]]
157 ; CHECK-NEXT: [[RES:%.*]] = phi i64 [ [[MIN_IDX_NEXT]], %[[LOOP]] ]
158 ; CHECK-NEXT: ret i64 [[RES]]
164 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
165 %min.idx = phi i64 [ 0, %entry ], [ %min.idx.next, %loop ]
166 %min.val = phi i64 [ 0, %entry ], [ %min.val.next, %loop ]
167 %gep = getelementptr i64, ptr %src, i64 %iv
168 %l = load i64, ptr %gep
169 %cmp = icmp ugt i64 %min.val, %l
170 %min.val.next = add i64 %l, 1
171 %foo = call i64 @llvm.umin.i64(i64 %min.val, i64 %l)
172 %min.idx.next = select i1 %cmp, i64 %iv, i64 %min.idx
173 %iv.next = add nuw nsw i64 %iv, 1
174 %exitcond.not = icmp eq i64 %iv.next, %n
175 br i1 %exitcond.not, label %exit, label %loop
178 %res = phi i64 [ %min.idx.next, %loop ]
183 define i64 @test_not_vectorize_cmp_value(i64 %x, i64 %n) {
184 ; CHECK-LABEL: define i64 @test_not_vectorize_cmp_value(
185 ; CHECK-SAME: i64 [[X:%.*]], i64 [[N:%.*]]) {
186 ; CHECK-NEXT: [[ENTRY:.*]]:
187 ; CHECK-NEXT: br label %[[LOOP:.*]]
189 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
190 ; CHECK-NEXT: [[MIN_IDX:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_IDX_NEXT:%.*]], %[[LOOP]] ]
191 ; CHECK-NEXT: [[MIN_VAL:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_VAL_NEXT:%.*]], %[[LOOP]] ]
192 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[MIN_VAL]], [[X]]
193 ; CHECK-NEXT: [[MIN_VAL_NEXT]] = tail call i64 @llvm.umin.i64(i64 [[MIN_VAL]], i64 0)
194 ; CHECK-NEXT: [[MIN_IDX_NEXT]] = select i1 [[CMP]], i64 [[IV]], i64 [[MIN_IDX]]
195 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
196 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
197 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[LOOP]]
199 ; CHECK-NEXT: [[RES:%.*]] = phi i64 [ [[MIN_IDX_NEXT]], %[[LOOP]] ]
200 ; CHECK-NEXT: ret i64 [[RES]]
206 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
207 %min.idx = phi i64 [ 0, %entry ], [ %min.idx.next, %loop ]
208 %min.val = phi i64 [ 0, %entry ], [ %min.val.next, %loop ]
209 %cmp = icmp ugt i64 %min.val, %x
210 %min.val.next = tail call i64 @llvm.umin.i64(i64 %min.val, i64 0)
211 %min.idx.next = select i1 %cmp, i64 %iv, i64 %min.idx
212 %iv.next = add nuw nsw i64 %iv, 1
213 %exitcond.not = icmp eq i64 %iv.next, %n
214 br i1 %exitcond.not, label %exit, label %loop
217 %res = phi i64 [ %min.idx.next, %loop ]
221 define i32 @test_vectorize_select_umin_idx_with_trunc(i64 %n) {
222 ; CHECK-LABEL: define i32 @test_vectorize_select_umin_idx_with_trunc(
223 ; CHECK-SAME: i64 [[N:%.*]]) {
224 ; CHECK-NEXT: [[ENTRY:.*]]:
225 ; CHECK-NEXT: br label %[[LOOP:.*]]
227 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
228 ; CHECK-NEXT: [[MIN_IDX:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[MIN_IDX_NEXT:%.*]], %[[LOOP]] ]
229 ; CHECK-NEXT: [[MIN_VAL:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_VAL_NEXT:%.*]], %[[LOOP]] ]
230 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[MIN_VAL]], 0
231 ; CHECK-NEXT: [[MIN_VAL_NEXT]] = tail call i64 @llvm.umin.i64(i64 [[MIN_VAL]], i64 0)
232 ; CHECK-NEXT: [[TRUNC:%.*]] = trunc i64 [[IV]] to i32
233 ; CHECK-NEXT: [[MIN_IDX_NEXT]] = select i1 [[CMP]], i32 [[TRUNC]], i32 [[MIN_IDX]]
234 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
235 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
236 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[LOOP]]
238 ; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[MIN_IDX_NEXT]], %[[LOOP]] ]
239 ; CHECK-NEXT: ret i32 [[RES]]
245 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
246 %min.idx = phi i32 [ 0, %entry ], [ %min.idx.next, %loop ]
247 %min.val = phi i64 [ 0, %entry ], [ %min.val.next, %loop ]
248 %cmp = icmp ugt i64 %min.val, 0
249 %min.val.next = tail call i64 @llvm.umin.i64(i64 %min.val, i64 0)
250 %trunc = trunc i64 %iv to i32
251 %min.idx.next = select i1 %cmp, i32 %trunc, i32 %min.idx
252 %iv.next = add nuw nsw i64 %iv, 1
253 %exitcond.not = icmp eq i64 %iv.next, %n
254 br i1 %exitcond.not, label %exit, label %loop
257 %res = phi i32 [ %min.idx.next, %loop ]
261 define ptr @test_with_ptr_index(ptr %start, ptr %end) {
262 ; CHECK-LABEL: define ptr @test_with_ptr_index(
263 ; CHECK-SAME: ptr [[START:%.*]], ptr [[END:%.*]]) {
264 ; CHECK-NEXT: [[ENTRY:.*]]:
265 ; CHECK-NEXT: br label %[[LOOP:.*]]
267 ; CHECK-NEXT: [[IV:%.*]] = phi ptr [ [[START]], %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
268 ; CHECK-NEXT: [[MIN_IDX:%.*]] = phi ptr [ null, %[[ENTRY]] ], [ [[MIN_IDX_NEXT:%.*]], %[[LOOP]] ]
269 ; CHECK-NEXT: [[MIN_VAL:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_VAL_NEXT:%.*]], %[[LOOP]] ]
270 ; CHECK-NEXT: [[CMP7_US:%.*]] = icmp ult i64 0, 0
271 ; CHECK-NEXT: [[MIN_VAL_NEXT]] = tail call i64 @llvm.umin.i64(i64 [[MIN_VAL]], i64 0)
272 ; CHECK-NEXT: [[MIN_IDX_NEXT]] = select i1 [[CMP7_US]], ptr [[IV]], ptr [[MIN_IDX]]
273 ; CHECK-NEXT: [[IV_NEXT]] = getelementptr i32, ptr [[IV]], i64 1
274 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq ptr [[IV_NEXT]], [[END]]
275 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[LOOP]]
277 ; CHECK-NEXT: [[RES:%.*]] = phi ptr [ [[MIN_IDX_NEXT]], %[[LOOP]] ]
278 ; CHECK-NEXT: ret ptr [[RES]]
284 %iv = phi ptr [ %start, %entry ], [ %iv.next, %loop ]
285 %min.idx = phi ptr [ null, %entry ], [ %min.idx.next, %loop ]
286 %min.val = phi i64 [ 0, %entry ], [ %min.val.next, %loop ]
287 %cmp7.us = icmp ult i64 0, 0
288 %min.val.next = tail call i64 @llvm.umin.i64(i64 %min.val, i64 0)
289 %min.idx.next = select i1 %cmp7.us, ptr %iv, ptr %min.idx
290 %iv.next = getelementptr i32, ptr %iv, i64 1
291 %exitcond.not = icmp eq ptr %iv.next, %end
292 br i1 %exitcond.not, label %exit, label %loop
295 %res = phi ptr [ %min.idx.next, %loop ]
299 define void @pointer_index(ptr %start) {
300 ; CHECK-LABEL: define void @pointer_index(
301 ; CHECK-SAME: ptr [[START:%.*]]) {
302 ; CHECK-NEXT: [[ENTRY:.*]]:
303 ; CHECK-NEXT: br label %[[LOOP:.*]]
305 ; CHECK-NEXT: [[PTR_IV:%.*]] = phi ptr [ [[START]], %[[ENTRY]] ], [ [[PTR_IV_NEXT:%.*]], %[[LOOP]] ]
306 ; CHECK-NEXT: [[PTR_IDX:%.*]] = phi ptr [ [[START]], %[[ENTRY]] ], [ [[PTR_SELECT:%.*]], %[[LOOP]] ]
307 ; CHECK-NEXT: [[CMP_I_I_I_I2531:%.*]] = icmp ult i16 0, 0
308 ; CHECK-NEXT: [[PTR_SELECT]] = select i1 [[CMP_I_I_I_I2531]], ptr [[PTR_IV]], ptr [[PTR_IDX]]
309 ; CHECK-NEXT: [[PTR_IV_NEXT]] = getelementptr inbounds i16, ptr [[PTR_IV]], i64 1
310 ; CHECK-NEXT: [[CMP_I_I10_NOT_I_I_I:%.*]] = icmp eq ptr [[PTR_IV_NEXT]], null
311 ; CHECK-NEXT: br i1 [[CMP_I_I10_NOT_I_I_I]], label %[[EXIT:.*]], label %[[LOOP]]
313 ; CHECK-NEXT: ret void
319 %ptr.iv = phi ptr [ %start, %entry ], [ %ptr.iv.next, %loop ]
320 %ptr.idx = phi ptr [ %start, %entry ], [ %ptr.select, %loop ]
321 %cmp.i.i.i.i2531 = icmp ult i16 0, 0
322 %ptr.select = select i1 %cmp.i.i.i.i2531, ptr %ptr.iv, ptr %ptr.idx
323 %ptr.iv.next = getelementptr inbounds i16, ptr %ptr.iv, i64 1
324 %cmp.i.i10.not.i.i.i = icmp eq ptr %ptr.iv.next, null
325 br i1 %cmp.i.i10.not.i.i.i, label %exit, label %loop
331 define ptr @pointer_index_2(ptr %start, ptr %end) {
332 ; CHECK-LABEL: define ptr @pointer_index_2(
333 ; CHECK-SAME: ptr [[START:%.*]], ptr [[END:%.*]]) {
334 ; CHECK-NEXT: [[ENTRY:.*]]:
335 ; CHECK-NEXT: br label %[[LOOP:.*]]
337 ; CHECK-NEXT: [[MIN_VAL:%.*]] = phi i16 [ 0, %[[ENTRY]] ], [ [[MIN_VAL_NEXT:%.*]], %[[LOOP]] ]
338 ; CHECK-NEXT: [[PTR_IV:%.*]] = phi ptr [ [[START]], %[[ENTRY]] ], [ [[PTR_IV_NEXT:%.*]], %[[LOOP]] ]
339 ; CHECK-NEXT: [[MIN_IDX:%.*]] = phi ptr [ [[START]], %[[ENTRY]] ], [ [[MIN_IDX_NEXT:%.*]], %[[LOOP]] ]
340 ; CHECK-NEXT: [[CMP_I_I_I_I:%.*]] = icmp ult i16 0, [[MIN_VAL]]
341 ; CHECK-NEXT: [[MIN_VAL_NEXT]] = call i16 @llvm.umin.i16(i16 0, i16 [[MIN_VAL]])
342 ; CHECK-NEXT: [[MIN_IDX_NEXT]] = select i1 [[CMP_I_I_I_I]], ptr [[PTR_IV]], ptr [[MIN_IDX]]
343 ; CHECK-NEXT: [[PTR_IV_NEXT]] = getelementptr inbounds i16, ptr [[PTR_IV]], i64 1
344 ; CHECK-NEXT: [[EXIT_COND:%.*]] = icmp eq ptr [[PTR_IV_NEXT]], [[END]]
345 ; CHECK-NEXT: br i1 [[EXIT_COND]], label %[[EXIT:.*]], label %[[LOOP]]
347 ; CHECK-NEXT: [[RES:%.*]] = phi ptr [ [[MIN_IDX_NEXT]], %[[LOOP]] ]
348 ; CHECK-NEXT: ret ptr [[RES]]
354 %min.val = phi i16 [ 0, %entry ], [ %min.val.next, %loop ]
355 %ptr.iv = phi ptr [ %start, %entry ], [ %ptr.iv.next, %loop ]
356 %min.idx = phi ptr [ %start, %entry ], [ %min.idx.next, %loop ]
357 %cmp.i.i.i.i = icmp ult i16 0, %min.val
358 %min.val.next = call i16 @llvm.umin.i16(i16 0, i16 %min.val)
359 %min.idx.next = select i1 %cmp.i.i.i.i, ptr %ptr.iv, ptr %min.idx
360 %ptr.iv.next = getelementptr inbounds i16, ptr %ptr.iv, i64 1
361 %exit.cond = icmp eq ptr %ptr.iv.next, %end
362 br i1 %exit.cond, label %exit, label %loop
365 %res = phi ptr [ %min.idx.next, %loop ]
369 define i64 @test_no_vectorize_select_iv_decrement(ptr %src) {
370 ; CHECK-LABEL: define i64 @test_no_vectorize_select_iv_decrement(
371 ; CHECK-SAME: ptr [[SRC:%.*]]) {
372 ; CHECK-NEXT: [[ENTRY:.*]]:
373 ; CHECK-NEXT: br label %[[LOOP:.*]]
375 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 1000, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
376 ; CHECK-NEXT: [[MIN_IDX:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_IDX_NEXT:%.*]], %[[LOOP]] ]
377 ; CHECK-NEXT: [[MIN_VAL:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_VAL_NEXT:%.*]], %[[LOOP]] ]
378 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i64, ptr [[SRC]], i64 [[IV]]
379 ; CHECK-NEXT: [[L:%.*]] = load i64, ptr [[GEP]], align 4
380 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[MIN_VAL]], [[L]]
381 ; CHECK-NEXT: [[MIN_VAL_NEXT]] = tail call i64 @llvm.umin.i64(i64 [[MIN_VAL]], i64 [[L]])
382 ; CHECK-NEXT: [[MIN_IDX_NEXT]] = select i1 [[CMP]], i64 [[IV]], i64 [[MIN_IDX]]
383 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], -1
384 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 0
385 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[LOOP]]
387 ; CHECK-NEXT: [[RES:%.*]] = phi i64 [ [[MIN_IDX_NEXT]], %[[LOOP]] ]
388 ; CHECK-NEXT: ret i64 [[RES]]
394 %iv = phi i64 [ 1000, %entry ], [ %iv.next, %loop ]
395 %min.idx = phi i64 [ 0, %entry ], [ %min.idx.next, %loop ]
396 %min.val = phi i64 [ 0, %entry ], [ %min.val.next, %loop ]
397 %gep = getelementptr i64, ptr %src, i64 %iv
398 %l = load i64, ptr %gep
399 %cmp = icmp ugt i64 %min.val, %l
400 %min.val.next = tail call i64 @llvm.umin.i64(i64 %min.val, i64 %l)
401 %min.idx.next = select i1 %cmp, i64 %iv, i64 %min.idx
402 %iv.next = add nuw nsw i64 %iv, -1
403 %exitcond.not = icmp eq i64 %iv.next, 0
404 br i1 %exitcond.not, label %exit, label %loop
407 %res = phi i64 [ %min.idx.next, %loop ]
411 define i64 @test_no_vectorize_select_iv_sub(ptr %src) {
412 ; CHECK-LABEL: define i64 @test_no_vectorize_select_iv_sub(
413 ; CHECK-SAME: ptr [[SRC:%.*]]) {
414 ; CHECK-NEXT: [[ENTRY:.*]]:
415 ; CHECK-NEXT: br label %[[LOOP:.*]]
417 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 1000, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
418 ; CHECK-NEXT: [[MIN_IDX:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_IDX_NEXT:%.*]], %[[LOOP]] ]
419 ; CHECK-NEXT: [[MIN_VAL:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_VAL_NEXT:%.*]], %[[LOOP]] ]
420 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i64, ptr [[SRC]], i64 [[IV]]
421 ; CHECK-NEXT: [[L:%.*]] = load i64, ptr [[GEP]], align 4
422 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[MIN_VAL]], [[L]]
423 ; CHECK-NEXT: [[MIN_VAL_NEXT]] = tail call i64 @llvm.umin.i64(i64 [[MIN_VAL]], i64 [[L]])
424 ; CHECK-NEXT: [[MIN_IDX_NEXT]] = select i1 [[CMP]], i64 [[IV]], i64 [[MIN_IDX]]
425 ; CHECK-NEXT: [[IV_NEXT]] = sub i64 [[IV]], 1
426 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 0
427 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[LOOP]]
429 ; CHECK-NEXT: [[RES:%.*]] = phi i64 [ [[MIN_IDX_NEXT]], %[[LOOP]] ]
430 ; CHECK-NEXT: ret i64 [[RES]]
436 %iv = phi i64 [ 1000, %entry ], [ %iv.next, %loop ]
437 %min.idx = phi i64 [ 0, %entry ], [ %min.idx.next, %loop ]
438 %min.val = phi i64 [ 0, %entry ], [ %min.val.next, %loop ]
439 %gep = getelementptr i64, ptr %src, i64 %iv
440 %l = load i64, ptr %gep
441 %cmp = icmp ugt i64 %min.val, %l
442 %min.val.next = tail call i64 @llvm.umin.i64(i64 %min.val, i64 %l)
443 %min.idx.next = select i1 %cmp, i64 %iv, i64 %min.idx
444 %iv.next = sub i64 %iv, 1
445 %exitcond.not = icmp eq i64 %iv.next, 0
446 br i1 %exitcond.not, label %exit, label %loop
449 %res = phi i64 [ %min.idx.next, %loop ]
453 define i64 @test_no_vectorize_select_iv_mul(ptr %src) {
454 ; CHECK-LABEL: define i64 @test_no_vectorize_select_iv_mul(
455 ; CHECK-SAME: ptr [[SRC:%.*]]) {
456 ; CHECK-NEXT: [[ENTRY:.*]]:
457 ; CHECK-NEXT: br label %[[LOOP:.*]]
459 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 1, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
460 ; CHECK-NEXT: [[MIN_IDX:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_IDX_NEXT:%.*]], %[[LOOP]] ]
461 ; CHECK-NEXT: [[MIN_VAL:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[MIN_VAL_NEXT:%.*]], %[[LOOP]] ]
462 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i64, ptr [[SRC]], i64 [[IV]]
463 ; CHECK-NEXT: [[L:%.*]] = load i64, ptr [[GEP]], align 4
464 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[MIN_VAL]], [[L]]
465 ; CHECK-NEXT: [[MIN_VAL_NEXT]] = tail call i64 @llvm.umin.i64(i64 [[MIN_VAL]], i64 [[L]])
466 ; CHECK-NEXT: [[MIN_IDX_NEXT]] = select i1 [[CMP]], i64 [[IV]], i64 [[MIN_IDX]]
467 ; CHECK-NEXT: [[IV_NEXT]] = mul i64 [[IV]], 2
468 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 128
469 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[LOOP]]
471 ; CHECK-NEXT: [[RES:%.*]] = phi i64 [ [[MIN_IDX_NEXT]], %[[LOOP]] ]
472 ; CHECK-NEXT: ret i64 [[RES]]
478 %iv = phi i64 [ 1, %entry ], [ %iv.next, %loop ]
479 %min.idx = phi i64 [ 0, %entry ], [ %min.idx.next, %loop ]
480 %min.val = phi i64 [ 0, %entry ], [ %min.val.next, %loop ]
481 %gep = getelementptr i64, ptr %src, i64 %iv
482 %l = load i64, ptr %gep
483 %cmp = icmp ugt i64 %min.val, %l
484 %min.val.next = tail call i64 @llvm.umin.i64(i64 %min.val, i64 %l)
485 %min.idx.next = select i1 %cmp, i64 %iv, i64 %min.idx
486 %iv.next = mul i64 %iv, 2
487 %exitcond.not = icmp eq i64 %iv.next, 128
488 br i1 %exitcond.not, label %exit, label %loop
491 %res = phi i64 [ %min.idx.next, %loop ]
495 declare i64 @llvm.umin.i64(i64, i64)
496 declare i16 @llvm.umin.i16(i16, i16)