1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -indvars -dce -S | 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]], i32* @A
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]], i32* @A
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]], i32* @A
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]], i32* @A
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
118 store i32 %i, i32* @A
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]], i32* @A
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
147 store i32 %i, i32* @A
149 %c = icmp ule i32 %i2, 1000
150 br i1 %c, label %loop, label %loopexit
157 @data = common global [240 x i8] zeroinitializer, align 16
159 define void @test_zext(i8* %a) #0 {
160 ; CHECK-LABEL: @test_zext(
162 ; CHECK-NEXT: br label [[LOOP:%.*]]
164 ; CHECK-NEXT: [[P_0:%.*]] = phi i8* [ getelementptr inbounds ([240 x i8], [240 x i8]* @data, i64 0, i64 0), [[ENTRY:%.*]] ], [ [[TMP3:%.*]], [[LOOP]] ]
165 ; CHECK-NEXT: [[DOT0:%.*]] = phi i8* [ [[A:%.*]], [[ENTRY]] ], [ [[TMP:%.*]], [[LOOP]] ]
166 ; CHECK-NEXT: [[TMP]] = getelementptr inbounds i8, i8* [[DOT0]], i64 1
167 ; CHECK-NEXT: [[TMP2:%.*]] = load i8, i8* [[DOT0]], align 1
168 ; CHECK-NEXT: [[TMP3]] = getelementptr inbounds i8, i8* [[P_0]], i64 1
169 ; CHECK-NEXT: store i8 [[TMP2]], i8* [[P_0]], align 1
170 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i8* [[P_0]], getelementptr inbounds ([240 x i8], [240 x i8]* @data, i64 0, i64 239)
171 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT:%.*]]
173 ; CHECK-NEXT: ret void
179 %i.0 = phi i8 [ 0, %entry ], [ %tmp4, %loop ]
180 %p.0 = phi i8* [ getelementptr inbounds ([240 x i8], [240 x i8]* @data, i64 0, i64 0), %entry ], [ %tmp3, %loop ]
181 %.0 = phi i8* [ %a, %entry ], [ %tmp, %loop ]
182 %tmp = getelementptr inbounds i8, i8* %.0, i64 1
183 %tmp2 = load i8, i8* %.0, align 1
184 %tmp3 = getelementptr inbounds i8, i8* %p.0, i64 1
185 store i8 %tmp2, i8* %p.0, align 1
186 %tmp4 = add i8 %i.0, 1
187 %tmp5 = icmp ult i8 %tmp4, -16
188 br i1 %tmp5, label %loop, label %exit
194 ; It is okay to do LFTR on this loop even though the trip count is a
195 ; division because in this case the division can be optimized to a
197 define void @test_udiv_as_shift(i8* %a, i8 %n) nounwind uwtable ssp {
198 ; CHECK-LABEL: @test_udiv_as_shift(
200 ; CHECK-NEXT: [[E:%.*]] = icmp sgt i8 [[N:%.*]], 3
201 ; CHECK-NEXT: br i1 [[E]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
202 ; CHECK: loop.preheader:
203 ; CHECK-NEXT: [[TMP0:%.*]] = add i8 [[N]], 3
204 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i8 [[TMP0]], 2
205 ; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i8 [[TMP1]], 1
206 ; CHECK-NEXT: br label [[LOOP:%.*]]
208 ; CHECK-NEXT: [[I1:%.*]] = phi i8 [ [[I1_INC:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
209 ; CHECK-NEXT: [[I1_INC]] = add nuw nsw i8 [[I1]], 1
210 ; CHECK-NEXT: store volatile i8 0, i8* [[A:%.*]]
211 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i8 [[I1_INC]], [[TMP2]]
212 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]]
213 ; CHECK: exit.loopexit:
214 ; CHECK-NEXT: br label [[EXIT]]
216 ; CHECK-NEXT: ret void
219 %e = icmp sgt i8 %n, 3
220 br i1 %e, label %loop, label %exit
223 %i = phi i8 [ 0, %entry ], [ %i.inc, %loop ]
224 %i1 = phi i8 [ 0, %entry ], [ %i1.inc, %loop ]
225 %i.inc = add nsw i8 %i, 4
226 %i1.inc = add i8 %i1, 1
227 store volatile i8 0, i8* %a
228 %c = icmp slt i8 %i, %n
229 br i1 %c, label %loop, label %exit
235 ; Don't RAUW the loop's original comparison instruction if it has other uses
236 ; which aren't dominated by the new comparison instruction (which we insert
237 ; at the branch user).
238 define void @use_before_branch() {
239 ; CHECK-LABEL: @use_before_branch(
241 ; CHECK-NEXT: br label [[LOOPENTRY_0:%.*]]
242 ; CHECK: loopentry.0:
243 ; CHECK-NEXT: [[MB_Y_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[TMP_152:%.*]], [[LOOPENTRY_1:%.*]] ]
244 ; CHECK-NEXT: [[TMP_14:%.*]] = icmp ule i32 [[MB_Y_0]], 3
245 ; CHECK-NEXT: br i1 [[TMP_14]], label [[LOOPENTRY_1]], label [[LOOPEXIT_0:%.*]]
246 ; CHECK: loopentry.1:
247 ; CHECK-NEXT: [[TMP_152]] = add nuw nsw i32 [[MB_Y_0]], 2
248 ; CHECK-NEXT: br label [[LOOPENTRY_0]]
250 ; CHECK-NEXT: unreachable
253 br label %loopentry.0
256 %mb_y.0 = phi i32 [ 0, %entry ], [ %tmp.152, %loopentry.1 ]
257 %tmp.14 = icmp sle i32 %mb_y.0, 3
258 %tmp.15 = zext i1 %tmp.14 to i32
259 br i1 %tmp.14, label %loopentry.1, label %loopexit.0
262 %tmp.152 = add i32 %mb_y.0, 2
263 br label %loopentry.0
265 loopexit.0: ; preds = %loopentry.0
269 @.str3 = private constant [6 x i8] c"%lld\0A\00", align 1
270 declare i32 @printf(i8* noalias nocapture, ...) nounwind
272 ; PR13371: indvars pass incorrectly substitutes 'undef' values
274 ; LFTR should not user %undef as the loop counter.
275 define i64 @no_undef_counter() nounwind {
276 ; CHECK-LABEL: @no_undef_counter(
277 ; CHECK-NEXT: func_start:
278 ; CHECK-NEXT: br label [[BLOCK9:%.*]]
280 ; CHECK-NEXT: [[UNDEF:%.*]] = phi i64 [ [[NEXT_UNDEF:%.*]], [[BLOCK9]] ], [ undef, [[FUNC_START:%.*]] ]
281 ; CHECK-NEXT: [[ITER:%.*]] = phi i64 [ [[NEXT_ITER:%.*]], [[BLOCK9]] ], [ 1, [[FUNC_START]] ]
282 ; CHECK-NEXT: [[NEXT_ITER]] = add nuw nsw i64 [[ITER]], 1
283 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 (i8*, ...) @printf(i8* noalias nocapture getelementptr inbounds ([6 x i8], [6 x i8]* @.str3, i64 0, i64 0), i64 [[NEXT_ITER]], i64 [[UNDEF]])
284 ; CHECK-NEXT: [[NEXT_UNDEF]] = add nsw i64 [[UNDEF]], 1
285 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[NEXT_ITER]], 100
286 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[BLOCK9]], label [[EXIT:%.*]]
288 ; CHECK-NEXT: ret i64 0
292 block9: ; preds = %block9,%func_start
293 %undef = phi i64 [ %next_undef, %block9 ], [ undef, %func_start ]
294 %iter = phi i64 [ %next_iter, %block9 ], [ 1, %func_start ]
295 %next_iter = add nsw i64 %iter, 1
296 %0 = tail call i32 (i8*, ...) @printf(i8* noalias nocapture getelementptr inbounds ([6 x i8], [6 x i8]* @.str3, i64 0, i64 0), i64 %next_iter, i64 %undef)
297 %next_undef = add nsw i64 %undef, 1
298 %_tmp_3 = icmp slt i64 %next_iter, 100
299 br i1 %_tmp_3, label %block9, label %exit
300 exit: ; preds = %block9
304 define void @extend_const() #0 {
305 ; CHECK-LABEL: @extend_const(
307 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
309 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ 0, [[ENTRY:%.*]] ]
310 ; CHECK-NEXT: call void @bar(i32 [[INDVARS_IV]]) #2
311 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1
312 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[INDVARS_IV_NEXT]], 512
313 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END:%.*]]
315 ; CHECK-NEXT: ret void
320 for.body: ; preds = %entry, %for.body
321 %i.01 = phi i16 [ 0, %entry ], [ %inc, %for.body ]
322 %conv2 = sext i16 %i.01 to i32
323 call void @bar(i32 %conv2) #1
324 %inc = add i16 %i.01, 1
325 %cmp = icmp slt i16 %inc, 512
326 br i1 %cmp, label %for.body, label %for.end
328 for.end: ; preds = %for.body
332 ; Check that post-incrementing the backedge taken count does not overflow.
333 define i32 @extend_const_postinc() #0 {
334 ; CHECK-LABEL: @extend_const_postinc(
336 ; CHECK-NEXT: br label [[DO_BODY:%.*]]
338 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ [[INDVARS_IV_NEXT:%.*]], [[DO_BODY]] ], [ 0, [[ENTRY:%.*]] ]
339 ; CHECK-NEXT: call void @bar(i32 [[INDVARS_IV]]) #2
340 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[INDVARS_IV]], 255
341 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1
342 ; CHECK-NEXT: br i1 [[CMP]], label [[DO_END:%.*]], label [[DO_BODY]]
344 ; CHECK-NEXT: ret i32 0
349 do.body: ; preds = %do.body, %entry
350 %first.0 = phi i8 [ 0, %entry ], [ %inc, %do.body ]
351 %conv = zext i8 %first.0 to i32
352 call void @bar(i32 %conv) #1
353 %inc = add i8 %first.0, 1
354 %cmp = icmp eq i8 %first.0, -1
355 br i1 %cmp, label %do.end, label %do.body
357 do.end: ; preds = %do.body
361 declare void @bar(i32)
363 attributes #0 = { nounwind uwtable }
364 attributes #1 = { nounwind }
366 ; With the given initial value for IV, it is not legal to widen
367 ; trip count to IV size
368 define void @wide_trip_count_test1(float* %autoc,
369 ; CHECK-LABEL: @wide_trip_count_test1(
371 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[DATA_LEN:%.*]], [[SAMPLE:%.*]]
372 ; CHECK-NEXT: [[CMP4:%.*]] = icmp eq i32 [[DATA_LEN]], [[SAMPLE]]
373 ; CHECK-NEXT: br i1 [[CMP4]], label [[FOR_END:%.*]], label [[FOR_BODY_PREHEADER:%.*]]
374 ; CHECK: for.body.preheader:
375 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
377 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ 68719476736, [[FOR_BODY_PREHEADER]] ]
378 ; CHECK-NEXT: [[TEMP:%.*]] = trunc i64 [[INDVARS_IV]] to i32
379 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[TEMP]], [[SAMPLE]]
380 ; CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[ADD]] to i64
381 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, float* [[DATA:%.*]], i64 [[IDXPROM]]
382 ; CHECK-NEXT: [[TEMP1:%.*]] = load float, float* [[ARRAYIDX]], align 4
383 ; CHECK-NEXT: [[MUL:%.*]] = fmul float [[TEMP1]], [[D:%.*]]
384 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds float, float* [[AUTOC:%.*]], i64 [[INDVARS_IV]]
385 ; CHECK-NEXT: [[TEMP2:%.*]] = load float, float* [[ARRAYIDX2]], align 4
386 ; CHECK-NEXT: [[ADD3:%.*]] = fadd float [[TEMP2]], [[MUL]]
387 ; CHECK-NEXT: store float [[ADD3]], float* [[ARRAYIDX2]], align 4
388 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
389 ; CHECK-NEXT: [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
390 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[LFTR_WIDEIV]], [[SUB]]
391 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
392 ; CHECK: for.end.loopexit:
393 ; CHECK-NEXT: br label [[FOR_END]]
395 ; CHECK-NEXT: ret void
398 float %d, i32 %data_len, i32 %sample) nounwind {
400 %sub = sub i32 %data_len, %sample
401 %cmp4 = icmp eq i32 %data_len, %sample
402 br i1 %cmp4, label %for.end, label %for.body
404 for.body: ; preds = %entry, %for.body
405 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 68719476736, %entry ]
406 %temp = trunc i64 %indvars.iv to i32
407 %add = add i32 %temp, %sample
408 %idxprom = zext i32 %add to i64
409 %arrayidx = getelementptr inbounds float, float* %data, i64 %idxprom
410 %temp1 = load float, float* %arrayidx, align 4
411 %mul = fmul float %temp1, %d
412 %arrayidx2 = getelementptr inbounds float, float* %autoc, i64 %indvars.iv
413 %temp2 = load float, float* %arrayidx2, align 4
414 %add3 = fadd float %temp2, %mul
415 store float %add3, float* %arrayidx2, align 4
416 %indvars.iv.next = add i64 %indvars.iv, 1
417 %temp3 = trunc i64 %indvars.iv.next to i32
418 %cmp = icmp ult i32 %temp3, %sub
419 br i1 %cmp, label %for.body, label %for.end
421 for.end: ; preds = %for.body, %entry
425 ; Trip count should be widened and LFTR should canonicalize the condition
426 define float @wide_trip_count_test2(float* %a,
427 ; CHECK-LABEL: @wide_trip_count_test2(
429 ; CHECK-NEXT: [[CMP5:%.*]] = icmp ugt i32 [[M:%.*]], 500
430 ; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_END:%.*]]
431 ; CHECK: for.body.preheader:
432 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[M]] to i64
433 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
435 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ 500, [[FOR_BODY_PREHEADER]] ]
436 ; CHECK-NEXT: [[SUM_07:%.*]] = phi float [ [[ADD:%.*]], [[FOR_BODY]] ], [ 0.000000e+00, [[FOR_BODY_PREHEADER]] ]
437 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, float* [[B:%.*]], i64 [[INDVARS_IV]]
438 ; CHECK-NEXT: [[TEMP:%.*]] = load float, float* [[ARRAYIDX]], align 4
439 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds float, float* [[A:%.*]], i64 [[INDVARS_IV]]
440 ; CHECK-NEXT: [[TEMP1:%.*]] = load float, float* [[ARRAYIDX2]], align 4
441 ; CHECK-NEXT: [[MUL:%.*]] = fmul float [[TEMP]], [[TEMP1]]
442 ; CHECK-NEXT: [[ADD]] = fadd float [[SUM_07]], [[MUL]]
443 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
444 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]]
445 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
446 ; CHECK: for.end.loopexit:
447 ; CHECK-NEXT: [[ADD_LCSSA:%.*]] = phi float [ [[ADD]], [[FOR_BODY]] ]
448 ; CHECK-NEXT: br label [[FOR_END]]
450 ; CHECK-NEXT: [[SUM_0_LCSSA:%.*]] = phi float [ 0.000000e+00, [[ENTRY:%.*]] ], [ [[ADD_LCSSA]], [[FOR_END_LOOPEXIT]] ]
451 ; CHECK-NEXT: ret float [[SUM_0_LCSSA]]
454 i32 zeroext %m) local_unnamed_addr #0 {
456 %cmp5 = icmp ugt i32 %m, 500
457 br i1 %cmp5, label %for.body.preheader, label %for.end
459 for.body.preheader: ; preds = %entry
462 for.body: ; preds = %for.body.preheader, %for.body
463 %sum.07 = phi float [ %add, %for.body ], [ 0.000000e+00, %for.body.preheader ]
464 %i.06 = phi i32 [ %inc, %for.body ], [ 500, %for.body.preheader ]
465 %idxprom = zext i32 %i.06 to i64
466 %arrayidx = getelementptr inbounds float, float* %b, i64 %idxprom
467 %temp = load float, float* %arrayidx, align 4
468 %arrayidx2 = getelementptr inbounds float, float* %a, i64 %idxprom
469 %temp1 = load float, float* %arrayidx2, align 4
470 %mul = fmul float %temp, %temp1
471 %add = fadd float %sum.07, %mul
472 %inc = add i32 %i.06, 1
473 %cmp = icmp ult i32 %inc, %m
474 br i1 %cmp, label %for.body, label %for.end.loopexit
476 for.end.loopexit: ; preds = %for.body
479 for.end: ; preds = %for.end.loopexit, %entry
480 %sum.0.lcssa = phi float [ 0.000000e+00, %entry ], [ %add, %for.end.loopexit ]
481 ret float %sum.0.lcssa
484 ; Trip count should be widened and LFTR should canonicalize the condition
485 define float @wide_trip_count_test3(float* %b,
486 ; CHECK-LABEL: @wide_trip_count_test3(
488 ; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[M:%.*]], -10
489 ; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_END:%.*]]
490 ; CHECK: for.body.preheader:
491 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = sext i32 [[M]] to i64
492 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
494 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ -10, [[FOR_BODY_PREHEADER]] ]
495 ; CHECK-NEXT: [[SUM_07:%.*]] = phi float [ [[ADD1:%.*]], [[FOR_BODY]] ], [ 0.000000e+00, [[FOR_BODY_PREHEADER]] ]
496 ; CHECK-NEXT: [[TMP0:%.*]] = add nsw i64 [[INDVARS_IV]], 20
497 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, float* [[B:%.*]], i64 [[TMP0]]
498 ; CHECK-NEXT: [[TEMP:%.*]] = load float, float* [[ARRAYIDX]], align 4
499 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[INDVARS_IV]] to i32
500 ; CHECK-NEXT: [[CONV:%.*]] = sitofp i32 [[TMP1]] to float
501 ; CHECK-NEXT: [[MUL:%.*]] = fmul float [[CONV]], [[TEMP]]
502 ; CHECK-NEXT: [[ADD1]] = fadd float [[SUM_07]], [[MUL]]
503 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nsw i64 [[INDVARS_IV]], 1
504 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]]
505 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
506 ; CHECK: for.end.loopexit:
507 ; CHECK-NEXT: [[ADD1_LCSSA:%.*]] = phi float [ [[ADD1]], [[FOR_BODY]] ]
508 ; CHECK-NEXT: br label [[FOR_END]]
510 ; CHECK-NEXT: [[SUM_0_LCSSA:%.*]] = phi float [ 0.000000e+00, [[ENTRY:%.*]] ], [ [[ADD1_LCSSA]], [[FOR_END_LOOPEXIT]] ]
511 ; CHECK-NEXT: ret float [[SUM_0_LCSSA]]
513 i32 signext %m) local_unnamed_addr #0 {
515 %cmp5 = icmp sgt i32 %m, -10
516 br i1 %cmp5, label %for.body.preheader, label %for.end
518 for.body.preheader: ; preds = %entry
521 for.body: ; preds = %for.body.preheader, %for.body
522 %sum.07 = phi float [ %add1, %for.body ], [ 0.000000e+00, %for.body.preheader ]
523 %i.06 = phi i32 [ %inc, %for.body ], [ -10, %for.body.preheader ]
524 %add = add nsw i32 %i.06, 20
525 %idxprom = sext i32 %add to i64
526 %arrayidx = getelementptr inbounds float, float* %b, i64 %idxprom
527 %temp = load float, float* %arrayidx, align 4
528 %conv = sitofp i32 %i.06 to float
529 %mul = fmul float %conv, %temp
530 %add1 = fadd float %sum.07, %mul
531 %inc = add nsw i32 %i.06, 1
532 %cmp = icmp slt i32 %inc, %m
533 br i1 %cmp, label %for.body, label %for.end.loopexit
535 for.end.loopexit: ; preds = %for.body
538 for.end: ; preds = %for.end.loopexit, %entry
539 %sum.0.lcssa = phi float [ 0.000000e+00, %entry ], [ %add1, %for.end.loopexit ]
540 ret float %sum.0.lcssa
543 ; Trip count should be widened and LFTR should canonicalize the condition
544 define float @wide_trip_count_test4(float* %b,
545 ; CHECK-LABEL: @wide_trip_count_test4(
547 ; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[M:%.*]], 10
548 ; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_END:%.*]]
549 ; CHECK: for.body.preheader:
550 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[M]] to i64
551 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
553 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ 10, [[FOR_BODY_PREHEADER]] ]
554 ; CHECK-NEXT: [[SUM_07:%.*]] = phi float [ [[ADD1:%.*]], [[FOR_BODY]] ], [ 0.000000e+00, [[FOR_BODY_PREHEADER]] ]
555 ; CHECK-NEXT: [[TMP0:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 20
556 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, float* [[B:%.*]], i64 [[TMP0]]
557 ; CHECK-NEXT: [[TEMP:%.*]] = load float, float* [[ARRAYIDX]], align 4
558 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[INDVARS_IV]] to i32
559 ; CHECK-NEXT: [[CONV:%.*]] = sitofp i32 [[TMP1]] to float
560 ; CHECK-NEXT: [[MUL:%.*]] = fmul float [[CONV]], [[TEMP]]
561 ; CHECK-NEXT: [[ADD1]] = fadd float [[SUM_07]], [[MUL]]
562 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
563 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]]
564 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
565 ; CHECK: for.end.loopexit:
566 ; CHECK-NEXT: [[ADD1_LCSSA:%.*]] = phi float [ [[ADD1]], [[FOR_BODY]] ]
567 ; CHECK-NEXT: br label [[FOR_END]]
569 ; CHECK-NEXT: [[SUM_0_LCSSA:%.*]] = phi float [ 0.000000e+00, [[ENTRY:%.*]] ], [ [[ADD1_LCSSA]], [[FOR_END_LOOPEXIT]] ]
570 ; CHECK-NEXT: ret float [[SUM_0_LCSSA]]
572 i32 signext %m) local_unnamed_addr #0 {
574 %cmp5 = icmp sgt i32 %m, 10
575 br i1 %cmp5, label %for.body.preheader, label %for.end
577 for.body.preheader: ; preds = %entry
580 for.body: ; preds = %for.body.preheader, %for.body
581 %sum.07 = phi float [ %add1, %for.body ], [ 0.000000e+00, %for.body.preheader ]
582 %i.06 = phi i32 [ %inc, %for.body ], [ 10, %for.body.preheader ]
583 %add = add nsw i32 %i.06, 20
584 %idxprom = sext i32 %add to i64
585 %arrayidx = getelementptr inbounds float, float* %b, i64 %idxprom
586 %temp = load float, float* %arrayidx, align 4
587 %conv = sitofp i32 %i.06 to float
588 %mul = fmul float %conv, %temp
589 %add1 = fadd float %sum.07, %mul
590 %inc = add nsw i32 %i.06, 1
591 %cmp = icmp slt i32 %inc, %m
592 br i1 %cmp, label %for.body, label %for.end.loopexit
594 for.end.loopexit: ; preds = %for.body
595 %add1.lcssa = phi float [ %add1, %for.body ]
598 for.end: ; preds = %for.end.loopexit, %entry
599 %sum.0.lcssa = phi float [ 0.000000e+00, %entry ], [ %add1.lcssa, %for.end.loopexit ]
600 ret float %sum.0.lcssa
603 define void @ptr_non_cmp_exit_test() {
604 ; CHECK-LABEL: @ptr_non_cmp_exit_test(
606 ; CHECK-NEXT: br label [[FOR_BODY29:%.*]]
608 ; CHECK-NEXT: [[IV:%.*]] = phi i8* [ null, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY29]] ]
609 ; CHECK-NEXT: [[TMP0:%.*]] = load volatile i8, i8* [[IV]], align 1
610 ; CHECK-NEXT: [[IV_NEXT]] = getelementptr inbounds i8, i8* [[IV]], i64 1
611 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i8* [[IV]], inttoptr (i64 10 to i8*)
612 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY29]], label [[EXIT:%.*]]
614 ; CHECK-NEXT: ret void
620 %iv = phi i8* [ null, %entry ], [ %iv.next, %for.body29 ]
621 load volatile i8, i8* %iv, align 1
622 %iv.next = getelementptr inbounds i8, i8* %iv, i64 1
623 %cmp = icmp ne i8* %iv.next, inttoptr (i64 11 to i8*)
624 %and = and i1 %cmp, %cmp
625 br i1 %and, label %for.body29, label %exit