1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes='loop(indvars),dce' -S -indvars-predicate-loops=0 | FileCheck %s
4 ; Provide legal integer types.
5 target datalayout = "n8:16:32:64"
7 @A = external global i32
9 ;; Convert a pre-increment check on the latch into a post increment check
10 define i32 @pre_to_post_add() {
11 ; CHECK-LABEL: @pre_to_post_add(
13 ; CHECK-NEXT: br label [[LOOP:%.*]]
15 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
16 ; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1
17 ; CHECK-NEXT: store i32 [[I]], ptr @A, align 4
18 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[I_NEXT]], 1001
19 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[LOOPEXIT:%.*]]
21 ; CHECK-NEXT: ret i32 1000
27 %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
28 %i.next = add i32 %i, 1
30 %c = icmp slt i32 %i, 1000
31 br i1 %c, label %loop, label %loopexit
37 ; TODO: we should be able to convert the subtract into a post-decrement check
38 define i32 @pre_to_post_sub() {
39 ; CHECK-LABEL: @pre_to_post_sub(
41 ; CHECK-NEXT: br label [[LOOP:%.*]]
43 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 1000, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
44 ; CHECK-NEXT: [[I_NEXT]] = sub nsw i32 [[I]], 1
45 ; CHECK-NEXT: store i32 [[I]], ptr @A, align 4
46 ; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[I]], 0
47 ; CHECK-NEXT: br i1 [[C]], label [[LOOP]], label [[LOOPEXIT:%.*]]
49 ; CHECK-NEXT: ret i32 0
55 %i = phi i32 [ 1000, %entry ], [ %i.next, %loop ]
56 %i.next = sub i32 %i, 1
58 %c = icmp sgt i32 %i, 0
59 br i1 %c, label %loop, label %loopexit
67 ; LFTR should eliminate the need for the computation of i*i completely. It
68 ; is only used to compute the exit value.
69 define i32 @quadratic_slt() {
70 ; CHECK-LABEL: @quadratic_slt(
72 ; CHECK-NEXT: br label [[LOOP:%.*]]
74 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 7, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
75 ; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1
76 ; CHECK-NEXT: store i32 [[I]], ptr @A, align 4
77 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[I_NEXT]], 33
78 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[LOOPEXIT:%.*]]
80 ; CHECK-NEXT: ret i32 32
86 %i = phi i32 [ 7, %entry ], [ %i.next, %loop ]
87 %i.next = add i32 %i, 1
90 %c = icmp slt i32 %i2, 1000
91 br i1 %c, label %loop, label %loopexit
98 ; Same as previous but with sle test
99 define i32 @quadratic_sle() {
100 ; CHECK-LABEL: @quadratic_sle(
102 ; CHECK-NEXT: br label [[LOOP:%.*]]
104 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 7, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
105 ; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1
106 ; CHECK-NEXT: store i32 [[I]], ptr @A, align 4
107 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[I_NEXT]], 33
108 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[LOOPEXIT:%.*]]
110 ; CHECK-NEXT: ret i32 32
116 %i = phi i32 [ 7, %entry ], [ %i.next, %loop ]
117 %i.next = add i32 %i, 1
120 %c = icmp sle i32 %i2, 1000
121 br i1 %c, label %loop, label %loopexit
127 ; Same as previous but with ule test
128 define i32 @quadratic_ule() {
129 ; CHECK-LABEL: @quadratic_ule(
131 ; CHECK-NEXT: br label [[LOOP:%.*]]
133 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 7, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
134 ; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1
135 ; CHECK-NEXT: store i32 [[I]], ptr @A, align 4
136 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[I_NEXT]], 33
137 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[LOOPEXIT:%.*]]
139 ; CHECK-NEXT: ret i32 32
145 %i = phi i32 [ 7, %entry ], [ %i.next, %loop ]
146 %i.next = add i32 %i, 1
149 %c = icmp ule i32 %i2, 1000
150 br i1 %c, label %loop, label %loopexit
156 define i32 @quadratic_sgt_loopdec() {
157 ; CHECK-LABEL: @quadratic_sgt_loopdec(
159 ; CHECK-NEXT: br label [[LOOP:%.*]]
161 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 10, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
162 ; CHECK-NEXT: [[I_NEXT]] = call i32 @llvm.loop.decrement.reg.i32(i32 [[I]], i32 1)
163 ; CHECK-NEXT: store i32 [[I]], ptr @A, align 4
164 ; CHECK-NEXT: [[I2:%.*]] = mul i32 [[I]], [[I]]
165 ; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[I2]], 0
166 ; CHECK-NEXT: br i1 [[C]], label [[LOOP]], label [[LOOPEXIT:%.*]]
168 ; CHECK-NEXT: ret i32 0
175 %i = phi i32 [ 10, %entry ], [ %i.next, %loop ]
176 %i.next = call i32 @llvm.loop.decrement.reg.i32(i32 %i, i32 1)
179 %c = icmp sgt i32 %i2, 0
180 br i1 %c, label %loop, label %loopexit
186 @data = common global [240 x i8] zeroinitializer, align 16
188 define void @test_zext(ptr %a) #0 {
189 ; CHECK-LABEL: @test_zext(
191 ; CHECK-NEXT: br label [[LOOP:%.*]]
193 ; CHECK-NEXT: [[P_0:%.*]] = phi ptr [ @data, [[ENTRY:%.*]] ], [ [[T3:%.*]], [[LOOP]] ]
194 ; CHECK-NEXT: [[DOT0:%.*]] = phi ptr [ [[A:%.*]], [[ENTRY]] ], [ [[T:%.*]], [[LOOP]] ]
195 ; CHECK-NEXT: [[T]] = getelementptr inbounds i8, ptr [[DOT0]], i64 1
196 ; CHECK-NEXT: [[T2:%.*]] = load i8, ptr [[DOT0]], align 1
197 ; CHECK-NEXT: [[T3]] = getelementptr inbounds i8, ptr [[P_0]], i64 1
198 ; CHECK-NEXT: store i8 [[T2]], ptr [[P_0]], align 1
199 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne ptr [[P_0]], getelementptr inbounds nuw (i8, ptr @data, i64 239)
200 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT:%.*]]
202 ; CHECK-NEXT: ret void
208 %i.0 = phi i8 [ 0, %entry ], [ %t4, %loop ]
209 %p.0 = phi ptr [ @data, %entry ], [ %t3, %loop ]
210 %.0 = phi ptr [ %a, %entry ], [ %t, %loop ]
211 %t = getelementptr inbounds i8, ptr %.0, i64 1
212 %t2 = load i8, ptr %.0, align 1
213 %t3 = getelementptr inbounds i8, ptr %p.0, i64 1
214 store i8 %t2, ptr %p.0, align 1
216 %t5 = icmp ult i8 %t4, -16
217 br i1 %t5, label %loop, label %exit
223 ; It is okay to do LFTR on this loop even though the trip count is a
224 ; division because in this case the division can be optimized to a
226 define void @test_udiv_as_shift(ptr %a, i8 %n) nounwind uwtable ssp {
227 ; CHECK-LABEL: @test_udiv_as_shift(
229 ; CHECK-NEXT: [[E:%.*]] = icmp sgt i8 [[N:%.*]], 3
230 ; CHECK-NEXT: br i1 [[E]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
231 ; CHECK: loop.preheader:
232 ; CHECK-NEXT: [[TMP0:%.*]] = add i8 [[N]], 3
233 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i8 [[TMP0]], 2
234 ; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i8 [[TMP1]], 1
235 ; CHECK-NEXT: br label [[LOOP:%.*]]
237 ; CHECK-NEXT: [[I1:%.*]] = phi i8 [ [[I1_INC:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
238 ; CHECK-NEXT: [[I1_INC]] = add nuw nsw i8 [[I1]], 1
239 ; CHECK-NEXT: store volatile i8 0, ptr [[A:%.*]], align 1
240 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i8 [[I1_INC]], [[TMP2]]
241 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
242 ; CHECK: exit.loopexit:
243 ; CHECK-NEXT: br label [[EXIT]]
245 ; CHECK-NEXT: ret void
248 %e = icmp sgt i8 %n, 3
249 br i1 %e, label %loop, label %exit
252 %i = phi i8 [ 0, %entry ], [ %i.inc, %loop ]
253 %i1 = phi i8 [ 0, %entry ], [ %i1.inc, %loop ]
254 %i.inc = add nsw i8 %i, 4
255 %i1.inc = add i8 %i1, 1
256 store volatile i8 0, ptr %a
257 %c = icmp slt i8 %i, %n
258 br i1 %c, label %loop, label %exit
264 ; Don't RAUW the loop's original comparison instruction if it has other uses
265 ; which aren't dominated by the new comparison instruction (which we insert
266 ; at the branch user).
267 define void @use_before_branch() {
268 ; CHECK-LABEL: @use_before_branch(
270 ; CHECK-NEXT: br label [[LOOPENTRY_0:%.*]]
271 ; CHECK: loopentry.0:
272 ; CHECK-NEXT: [[MB_Y_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[T152:%.*]], [[LOOPENTRY_1:%.*]] ]
273 ; CHECK-NEXT: [[T14:%.*]] = icmp ule i32 [[MB_Y_0]], 3
274 ; CHECK-NEXT: br i1 [[T14]], label [[LOOPENTRY_1]], label [[LOOPEXIT_0:%.*]]
275 ; CHECK: loopentry.1:
276 ; CHECK-NEXT: [[T152]] = add nuw nsw i32 [[MB_Y_0]], 2
277 ; CHECK-NEXT: br label [[LOOPENTRY_0]]
279 ; CHECK-NEXT: unreachable
282 br label %loopentry.0
285 %mb_y.0 = phi i32 [ 0, %entry ], [ %t152, %loopentry.1 ]
286 %t14 = icmp sle i32 %mb_y.0, 3
287 %t15 = zext i1 %t14 to i32
288 br i1 %t14, label %loopentry.1, label %loopexit.0
291 %t152 = add i32 %mb_y.0, 2
292 br label %loopentry.0
294 loopexit.0: ; preds = %loopentry.0
298 @.str3 = private constant [6 x i8] c"%lld\0A\00", align 1
299 declare i32 @printf(ptr noalias nocapture, ...) nounwind
301 ; PR13371: indvars pass incorrectly substitutes 'undef' values
303 ; LFTR should not user %undef as the loop counter.
304 define i64 @no_undef_counter() nounwind {
305 ; CHECK-LABEL: @no_undef_counter(
306 ; CHECK-NEXT: func_start:
307 ; CHECK-NEXT: br label [[BLOCK9:%.*]]
309 ; CHECK-NEXT: [[UNDEF:%.*]] = phi i64 [ [[NEXT_UNDEF:%.*]], [[BLOCK9]] ], [ undef, [[FUNC_START:%.*]] ]
310 ; CHECK-NEXT: [[ITER:%.*]] = phi i64 [ [[NEXT_ITER:%.*]], [[BLOCK9]] ], [ 1, [[FUNC_START]] ]
311 ; CHECK-NEXT: [[NEXT_ITER]] = add nuw nsw i64 [[ITER]], 1
312 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 (ptr, ...) @printf(ptr noalias nocapture @.str3, i64 [[NEXT_ITER]], i64 [[UNDEF]])
313 ; CHECK-NEXT: [[NEXT_UNDEF]] = add nsw i64 [[UNDEF]], 1
314 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[NEXT_ITER]], 100
315 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[BLOCK9]], label [[EXIT:%.*]]
317 ; CHECK-NEXT: ret i64 0
321 block9: ; preds = %block9,%func_start
322 %undef = phi i64 [ %next_undef, %block9 ], [ undef, %func_start ]
323 %iter = phi i64 [ %next_iter, %block9 ], [ 1, %func_start ]
324 %next_iter = add nsw i64 %iter, 1
325 %0 = tail call i32 (ptr, ...) @printf(ptr noalias nocapture @.str3, i64 %next_iter, i64 %undef)
326 %next_undef = add nsw i64 %undef, 1
327 %_tmp_3 = icmp slt i64 %next_iter, 100
328 br i1 %_tmp_3, label %block9, label %exit
329 exit: ; preds = %block9
333 define void @extend_const() #0 {
334 ; CHECK-LABEL: @extend_const(
336 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
338 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ 0, [[ENTRY:%.*]] ]
339 ; CHECK-NEXT: call void @bar(i32 [[INDVARS_IV]]) #[[ATTR2:[0-9]+]]
340 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1
341 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[INDVARS_IV_NEXT]], 512
342 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END:%.*]]
344 ; CHECK-NEXT: ret void
349 for.body: ; preds = %entry, %for.body
350 %i.01 = phi i16 [ 0, %entry ], [ %inc, %for.body ]
351 %conv2 = sext i16 %i.01 to i32
352 call void @bar(i32 %conv2) #1
353 %inc = add i16 %i.01, 1
354 %cmp = icmp slt i16 %inc, 512
355 br i1 %cmp, label %for.body, label %for.end
357 for.end: ; preds = %for.body
361 ; Check that post-incrementing the backedge taken count does not overflow.
362 define i32 @extend_const_postinc() #0 {
363 ; CHECK-LABEL: @extend_const_postinc(
365 ; CHECK-NEXT: br label [[DO_BODY:%.*]]
367 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ [[INDVARS_IV_NEXT:%.*]], [[DO_BODY]] ], [ 0, [[ENTRY:%.*]] ]
368 ; CHECK-NEXT: call void @bar(i32 [[INDVARS_IV]]) #[[ATTR2]]
369 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[INDVARS_IV]], 255
370 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1
371 ; CHECK-NEXT: br i1 [[CMP]], label [[DO_END:%.*]], label [[DO_BODY]]
373 ; CHECK-NEXT: ret i32 0
378 do.body: ; preds = %do.body, %entry
379 %first.0 = phi i8 [ 0, %entry ], [ %inc, %do.body ]
380 %conv = zext i8 %first.0 to i32
381 call void @bar(i32 %conv) #1
382 %inc = add i8 %first.0, 1
383 %cmp = icmp eq i8 %first.0, -1
384 br i1 %cmp, label %do.end, label %do.body
386 do.end: ; preds = %do.body
390 declare void @bar(i32)
392 attributes #0 = { nounwind uwtable }
393 attributes #1 = { nounwind }
395 ; With the given initial value for IV, it is not legal to widen
396 ; trip count to IV size
397 define void @wide_trip_count_test1(ptr %autoc,
398 ; CHECK-LABEL: @wide_trip_count_test1(
400 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[DATA_LEN:%.*]], [[SAMPLE:%.*]]
401 ; CHECK-NEXT: [[CMP4:%.*]] = icmp eq i32 [[DATA_LEN]], [[SAMPLE]]
402 ; CHECK-NEXT: br i1 [[CMP4]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]]
403 ; CHECK: for.body.preheader:
404 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
406 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ 68719476736, [[FOR_BODY_PREHEADER]] ]
407 ; CHECK-NEXT: [[TEMP:%.*]] = trunc i64 [[INDVARS_IV]] to i32
408 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[TEMP]], [[SAMPLE]]
409 ; CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[ADD]] to i64
410 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, ptr [[DATA:%.*]], i64 [[IDXPROM]]
411 ; CHECK-NEXT: [[TEMP1:%.*]] = load float, ptr [[ARRAYIDX]], align 4
412 ; CHECK-NEXT: [[MUL:%.*]] = fmul float [[TEMP1]], [[D:%.*]]
413 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds float, ptr [[AUTOC:%.*]], i64 [[INDVARS_IV]]
414 ; CHECK-NEXT: [[TEMP2:%.*]] = load float, ptr [[ARRAYIDX2]], align 4
415 ; CHECK-NEXT: [[ADD3:%.*]] = fadd float [[TEMP2]], [[MUL]]
416 ; CHECK-NEXT: store float [[ADD3]], ptr [[ARRAYIDX2]], align 4
417 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
418 ; CHECK-NEXT: [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
419 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[LFTR_WIDEIV]], [[SUB]]
420 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
421 ; CHECK: for.end.loopexit:
422 ; CHECK-NEXT: br label [[FOR_END]]
424 ; CHECK-NEXT: ret void
427 float %d, i32 %data_len, i32 %sample) nounwind {
429 %sub = sub i32 %data_len, %sample
430 %cmp4 = icmp eq i32 %data_len, %sample
431 br i1 %cmp4, label %for.end, label %for.body
433 for.body: ; preds = %entry, %for.body
434 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 68719476736, %entry ]
435 %temp = trunc i64 %indvars.iv to i32
436 %add = add i32 %temp, %sample
437 %idxprom = zext i32 %add to i64
438 %arrayidx = getelementptr inbounds float, ptr %data, i64 %idxprom
439 %temp1 = load float, ptr %arrayidx, align 4
440 %mul = fmul float %temp1, %d
441 %arrayidx2 = getelementptr inbounds float, ptr %autoc, i64 %indvars.iv
442 %temp2 = load float, ptr %arrayidx2, align 4
443 %add3 = fadd float %temp2, %mul
444 store float %add3, ptr %arrayidx2, align 4
445 %indvars.iv.next = add i64 %indvars.iv, 1
446 %temp3 = trunc i64 %indvars.iv.next to i32
447 %cmp = icmp ult i32 %temp3, %sub
448 br i1 %cmp, label %for.body, label %for.end
450 for.end: ; preds = %for.body, %entry
454 ; Trip count should be widened and LFTR should canonicalize the condition
455 define float @wide_trip_count_test2(ptr %a,
456 ; CHECK-LABEL: @wide_trip_count_test2(
458 ; CHECK-NEXT: [[CMP5:%.*]] = icmp ugt i32 [[M:%.*]], 500
459 ; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_END:%.*]]
460 ; CHECK: for.body.preheader:
461 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[M]] to i64
462 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
464 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ 500, [[FOR_BODY_PREHEADER]] ]
465 ; CHECK-NEXT: [[SUM_07:%.*]] = phi float [ [[ADD:%.*]], [[FOR_BODY]] ], [ 0.000000e+00, [[FOR_BODY_PREHEADER]] ]
466 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, ptr [[B:%.*]], i64 [[INDVARS_IV]]
467 ; CHECK-NEXT: [[TEMP:%.*]] = load float, ptr [[ARRAYIDX]], align 4
468 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds float, ptr [[A:%.*]], i64 [[INDVARS_IV]]
469 ; CHECK-NEXT: [[TEMP1:%.*]] = load float, ptr [[ARRAYIDX2]], align 4
470 ; CHECK-NEXT: [[MUL:%.*]] = fmul float [[TEMP]], [[TEMP1]]
471 ; CHECK-NEXT: [[ADD]] = fadd float [[SUM_07]], [[MUL]]
472 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
473 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]]
474 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
475 ; CHECK: for.end.loopexit:
476 ; CHECK-NEXT: [[ADD_LCSSA:%.*]] = phi float [ [[ADD]], [[FOR_BODY]] ]
477 ; CHECK-NEXT: br label [[FOR_END]]
479 ; CHECK-NEXT: [[SUM_0_LCSSA:%.*]] = phi float [ 0.000000e+00, [[ENTRY:%.*]] ], [ [[ADD_LCSSA]], [[FOR_END_LOOPEXIT]] ]
480 ; CHECK-NEXT: ret float [[SUM_0_LCSSA]]
483 i32 zeroext %m) local_unnamed_addr #0 {
485 %cmp5 = icmp ugt i32 %m, 500
486 br i1 %cmp5, label %for.body.preheader, label %for.end
488 for.body.preheader: ; preds = %entry
491 for.body: ; preds = %for.body.preheader, %for.body
492 %sum.07 = phi float [ %add, %for.body ], [ 0.000000e+00, %for.body.preheader ]
493 %i.06 = phi i32 [ %inc, %for.body ], [ 500, %for.body.preheader ]
494 %idxprom = zext i32 %i.06 to i64
495 %arrayidx = getelementptr inbounds float, ptr %b, i64 %idxprom
496 %temp = load float, ptr %arrayidx, align 4
497 %arrayidx2 = getelementptr inbounds float, ptr %a, i64 %idxprom
498 %temp1 = load float, ptr %arrayidx2, align 4
499 %mul = fmul float %temp, %temp1
500 %add = fadd float %sum.07, %mul
501 %inc = add i32 %i.06, 1
502 %cmp = icmp ult i32 %inc, %m
503 br i1 %cmp, label %for.body, label %for.end.loopexit
505 for.end.loopexit: ; preds = %for.body
508 for.end: ; preds = %for.end.loopexit, %entry
509 %sum.0.lcssa = phi float [ 0.000000e+00, %entry ], [ %add, %for.end.loopexit ]
510 ret float %sum.0.lcssa
513 ; Trip count should be widened and LFTR should canonicalize the condition
514 define float @wide_trip_count_test3(ptr %b,
515 ; CHECK-LABEL: @wide_trip_count_test3(
517 ; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[M:%.*]], -10
518 ; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_END:%.*]]
519 ; CHECK: for.body.preheader:
520 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = sext i32 [[M]] to i64
521 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
523 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ -10, [[FOR_BODY_PREHEADER]] ]
524 ; CHECK-NEXT: [[SUM_07:%.*]] = phi float [ [[ADD1:%.*]], [[FOR_BODY]] ], [ 0.000000e+00, [[FOR_BODY_PREHEADER]] ]
525 ; CHECK-NEXT: [[TMP0:%.*]] = add nsw i64 [[INDVARS_IV]], 20
526 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, ptr [[B:%.*]], i64 [[TMP0]]
527 ; CHECK-NEXT: [[TEMP:%.*]] = load float, ptr [[ARRAYIDX]], align 4
528 ; CHECK-NEXT: [[TMP1:%.*]] = trunc nsw i64 [[INDVARS_IV]] to i32
529 ; CHECK-NEXT: [[CONV:%.*]] = sitofp i32 [[TMP1]] to float
530 ; CHECK-NEXT: [[MUL:%.*]] = fmul float [[CONV]], [[TEMP]]
531 ; CHECK-NEXT: [[ADD1]] = fadd float [[SUM_07]], [[MUL]]
532 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nsw i64 [[INDVARS_IV]], 1
533 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]]
534 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
535 ; CHECK: for.end.loopexit:
536 ; CHECK-NEXT: [[ADD1_LCSSA:%.*]] = phi float [ [[ADD1]], [[FOR_BODY]] ]
537 ; CHECK-NEXT: br label [[FOR_END]]
539 ; CHECK-NEXT: [[SUM_0_LCSSA:%.*]] = phi float [ 0.000000e+00, [[ENTRY:%.*]] ], [ [[ADD1_LCSSA]], [[FOR_END_LOOPEXIT]] ]
540 ; CHECK-NEXT: ret float [[SUM_0_LCSSA]]
542 i32 signext %m) local_unnamed_addr #0 {
544 %cmp5 = icmp sgt i32 %m, -10
545 br i1 %cmp5, label %for.body.preheader, label %for.end
547 for.body.preheader: ; preds = %entry
550 for.body: ; preds = %for.body.preheader, %for.body
551 %sum.07 = phi float [ %add1, %for.body ], [ 0.000000e+00, %for.body.preheader ]
552 %i.06 = phi i32 [ %inc, %for.body ], [ -10, %for.body.preheader ]
553 %add = add nsw i32 %i.06, 20
554 %idxprom = sext i32 %add to i64
555 %arrayidx = getelementptr inbounds float, ptr %b, i64 %idxprom
556 %temp = load float, ptr %arrayidx, align 4
557 %conv = sitofp i32 %i.06 to float
558 %mul = fmul float %conv, %temp
559 %add1 = fadd float %sum.07, %mul
560 %inc = add nsw i32 %i.06, 1
561 %cmp = icmp slt i32 %inc, %m
562 br i1 %cmp, label %for.body, label %for.end.loopexit
564 for.end.loopexit: ; preds = %for.body
567 for.end: ; preds = %for.end.loopexit, %entry
568 %sum.0.lcssa = phi float [ 0.000000e+00, %entry ], [ %add1, %for.end.loopexit ]
569 ret float %sum.0.lcssa
572 ; Trip count should be widened and LFTR should canonicalize the condition
573 define float @wide_trip_count_test4(ptr %b,
574 ; CHECK-LABEL: @wide_trip_count_test4(
576 ; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[M:%.*]], 10
577 ; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_END:%.*]]
578 ; CHECK: for.body.preheader:
579 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[M]] to i64
580 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
582 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ 10, [[FOR_BODY_PREHEADER]] ]
583 ; CHECK-NEXT: [[SUM_07:%.*]] = phi float [ [[ADD1:%.*]], [[FOR_BODY]] ], [ 0.000000e+00, [[FOR_BODY_PREHEADER]] ]
584 ; CHECK-NEXT: [[TMP0:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 20
585 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, ptr [[B:%.*]], i64 [[TMP0]]
586 ; CHECK-NEXT: [[TEMP:%.*]] = load float, ptr [[ARRAYIDX]], align 4
587 ; CHECK-NEXT: [[TMP1:%.*]] = trunc nuw nsw i64 [[INDVARS_IV]] to i32
588 ; CHECK-NEXT: [[CONV:%.*]] = sitofp i32 [[TMP1]] to float
589 ; CHECK-NEXT: [[MUL:%.*]] = fmul float [[CONV]], [[TEMP]]
590 ; CHECK-NEXT: [[ADD1]] = fadd float [[SUM_07]], [[MUL]]
591 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
592 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]]
593 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
594 ; CHECK: for.end.loopexit:
595 ; CHECK-NEXT: [[ADD1_LCSSA:%.*]] = phi float [ [[ADD1]], [[FOR_BODY]] ]
596 ; CHECK-NEXT: br label [[FOR_END]]
598 ; CHECK-NEXT: [[SUM_0_LCSSA:%.*]] = phi float [ 0.000000e+00, [[ENTRY:%.*]] ], [ [[ADD1_LCSSA]], [[FOR_END_LOOPEXIT]] ]
599 ; CHECK-NEXT: ret float [[SUM_0_LCSSA]]
601 i32 signext %m) local_unnamed_addr #0 {
603 %cmp5 = icmp sgt i32 %m, 10
604 br i1 %cmp5, label %for.body.preheader, label %for.end
606 for.body.preheader: ; preds = %entry
609 for.body: ; preds = %for.body.preheader, %for.body
610 %sum.07 = phi float [ %add1, %for.body ], [ 0.000000e+00, %for.body.preheader ]
611 %i.06 = phi i32 [ %inc, %for.body ], [ 10, %for.body.preheader ]
612 %add = add nsw i32 %i.06, 20
613 %idxprom = sext i32 %add to i64
614 %arrayidx = getelementptr inbounds float, ptr %b, i64 %idxprom
615 %temp = load float, ptr %arrayidx, align 4
616 %conv = sitofp i32 %i.06 to float
617 %mul = fmul float %conv, %temp
618 %add1 = fadd float %sum.07, %mul
619 %inc = add nsw i32 %i.06, 1
620 %cmp = icmp slt i32 %inc, %m
621 br i1 %cmp, label %for.body, label %for.end.loopexit
623 for.end.loopexit: ; preds = %for.body
624 %add1.lcssa = phi float [ %add1, %for.body ]
627 for.end: ; preds = %for.end.loopexit, %entry
628 %sum.0.lcssa = phi float [ 0.000000e+00, %entry ], [ %add1.lcssa, %for.end.loopexit ]
629 ret float %sum.0.lcssa
632 define void @ptr_non_cmp_exit_test() {
633 ; CHECK-LABEL: @ptr_non_cmp_exit_test(
635 ; CHECK-NEXT: br label [[FOR_BODY29:%.*]]
637 ; CHECK-NEXT: [[IV:%.*]] = phi ptr [ null, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY29]] ]
638 ; CHECK-NEXT: [[TMP0:%.*]] = load volatile i8, ptr [[IV]], align 1
639 ; CHECK-NEXT: [[IV_NEXT]] = getelementptr inbounds i8, ptr [[IV]], i64 1
640 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne ptr [[IV]], inttoptr (i64 10 to ptr)
641 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY29]], label [[EXIT:%.*]]
643 ; CHECK-NEXT: ret void
649 %iv = phi ptr [ null, %entry ], [ %iv.next, %for.body29 ]
650 load volatile i8, ptr %iv, align 1
651 %iv.next = getelementptr inbounds i8, ptr %iv, i64 1
652 %cmp = icmp ne ptr %iv.next, inttoptr (i64 11 to ptr)
653 %and = and i1 %cmp, %cmp
654 br i1 %and, label %for.body29, label %exit
660 define void @PR49993() {
661 ; CHECK-LABEL: @PR49993(
663 ; CHECK-NEXT: br label [[IF_END:%.*]]
665 ; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[ADD:%.*]], [[D:%.*]] ], [ [[REM10:%.*]], [[IF_END]] ]
666 ; CHECK-NEXT: [[ADD]] = add nsw i32 [[PHI]], 1
667 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[PHI]], 3
668 ; CHECK-NEXT: br i1 [[CMP]], label [[D]], label [[IF_END_LOOPEXIT:%.*]]
669 ; CHECK: if.end.loopexit:
670 ; CHECK-NEXT: br label [[IF_END]]
672 ; CHECK-NEXT: [[REM1:%.*]] = urem i32 undef, undef
673 ; CHECK-NEXT: [[REM2:%.*]] = urem i32 [[REM1]], undef
674 ; CHECK-NEXT: [[REM3:%.*]] = urem i32 [[REM2]], undef
675 ; CHECK-NEXT: [[REM4:%.*]] = urem i32 [[REM3]], undef
676 ; CHECK-NEXT: [[REM5:%.*]] = urem i32 [[REM4]], undef
677 ; CHECK-NEXT: [[REM6:%.*]] = urem i32 [[REM5]], undef
678 ; CHECK-NEXT: [[REM7:%.*]] = urem i32 [[REM6]], undef
679 ; CHECK-NEXT: [[REM8:%.*]] = urem i32 [[REM7]], undef
680 ; CHECK-NEXT: [[REM9:%.*]] = urem i32 [[REM8]], undef
681 ; CHECK-NEXT: [[REM10]] = urem i32 [[REM9]], undef
682 ; CHECK-NEXT: br label [[D]]
688 %phi = phi i32 [ %add, %d ], [ %rem10, %if.end ]
689 %add = add nsw i32 %phi, 1
690 %cmp = icmp slt i32 %phi, 3
691 br i1 %cmp, label %d, label %if.end
694 %rem1 = urem i32 undef, undef
695 %rem2 = urem i32 %rem1, undef
696 %rem3 = urem i32 %rem2, undef
697 %rem4 = urem i32 %rem3, undef
698 %rem5 = urem i32 %rem4, undef
699 %rem6 = urem i32 %rem5, undef
700 %rem7 = urem i32 %rem6, undef
701 %rem8 = urem i32 %rem7, undef
702 %rem9 = urem i32 %rem8, undef
703 %rem10 = urem i32 %rem9, undef
707 declare i32 @llvm.loop.decrement.reg.i32(i32, i32)
709 ; This used to crash, we're basically just checking that it doesn't.
710 define void @switch_preheader() {
711 ; CHECK-LABEL: @switch_preheader(
712 ; CHECK-NEXT: switch i32 -1, label [[X:%.*]] [
715 ; CHECK-NEXT: br i1 false, label [[X]], label [[BB:%.*]]
717 ; CHECK-NEXT: ret void
719 switch i32 -1, label %x []
722 br i1 false, label %x, label %BB