Skip to content

Commit c8d6351

Browse files
committed
[SCEV] Add coverage for howFarToZero w/ non-constant strides
Specifically, cases which require context sensative reasoning which the current code doesn't do.
1 parent 4f40dfc commit c8d6351

File tree

1 file changed

+221
-0
lines changed

1 file changed

+221
-0
lines changed

llvm/test/Analysis/ScalarEvolution/trip-count-unknown-stride.ll

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,228 @@ for.end: ; preds = %for.body, %entry
267267
ret void
268268
}
269269

270+
define void @ne_nsw_pos_step(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
271+
;
272+
; CHECK-LABEL: 'ne_nsw_pos_step'
273+
; CHECK-NEXT: Determining loop execution counts for: @ne_nsw_pos_step
274+
; CHECK-NEXT: Loop %for.body: Unpredictable backedge-taken count.
275+
; CHECK-NEXT: Loop %for.body: Unpredictable constant max backedge-taken count.
276+
; CHECK-NEXT: Loop %for.body: Unpredictable symbolic max backedge-taken count.
277+
;
278+
entry:
279+
%pos_step = icmp sgt i32 %s, 0
280+
call void @llvm.assume(i1 %pos_step)
281+
%cmp4 = icmp sgt i32 %n, 0
282+
br i1 %cmp4, label %for.body, label %for.end
283+
284+
for.body: ; preds = %entry, %for.body
285+
%i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
286+
%arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
287+
%0 = load i32, ptr %arrayidx, align 4
288+
%inc = add nsw i32 %0, 1
289+
store i32 %inc, ptr %arrayidx, align 4
290+
%add = add nsw i32 %i.05, %s
291+
%cmp = icmp ne i32 %add, %n
292+
br i1 %cmp, label %for.body, label %for.end
293+
294+
for.end: ; preds = %for.body, %entry
295+
ret void
296+
}
297+
298+
define void @ne_nsw_neg_step(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
299+
;
300+
; CHECK-LABEL: 'ne_nsw_neg_step'
301+
; CHECK-NEXT: Determining loop execution counts for: @ne_nsw_neg_step
302+
; CHECK-NEXT: Loop %for.body: Unpredictable backedge-taken count.
303+
; CHECK-NEXT: Loop %for.body: Unpredictable constant max backedge-taken count.
304+
; CHECK-NEXT: Loop %for.body: Unpredictable symbolic max backedge-taken count.
305+
;
306+
entry:
307+
%neg_step = icmp slt i32 %s, 0
308+
call void @llvm.assume(i1 %neg_step)
309+
%cmp4 = icmp sgt i32 %n, 0
310+
br i1 %cmp4, label %for.body, label %for.end
311+
312+
for.body: ; preds = %entry, %for.body
313+
%i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
314+
%arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
315+
%0 = load i32, ptr %arrayidx, align 4
316+
%inc = add nsw i32 %0, 1
317+
store i32 %inc, ptr %arrayidx, align 4
318+
%add = add nsw i32 %i.05, %s
319+
%cmp = icmp ne i32 %add, %n
320+
br i1 %cmp, label %for.body, label %for.end
321+
322+
for.end: ; preds = %for.body, %entry
323+
ret void
324+
}
325+
326+
define void @ne_nsw_nonneg_step(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
327+
;
328+
; CHECK-LABEL: 'ne_nsw_nonneg_step'
329+
; CHECK-NEXT: Determining loop execution counts for: @ne_nsw_nonneg_step
330+
; CHECK-NEXT: Loop %for.body: Unpredictable backedge-taken count.
331+
; CHECK-NEXT: Loop %for.body: Unpredictable constant max backedge-taken count.
332+
; CHECK-NEXT: Loop %for.body: Unpredictable symbolic max backedge-taken count.
333+
;
334+
entry:
335+
%nonneg_step = icmp sge i32 %s, 0
336+
call void @llvm.assume(i1 %nonneg_step)
337+
%cmp4 = icmp sgt i32 %n, 0
338+
br i1 %cmp4, label %for.body, label %for.end
339+
340+
for.body: ; preds = %entry, %for.body
341+
%i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
342+
%arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
343+
%0 = load i32, ptr %arrayidx, align 4
344+
%inc = add nsw i32 %0, 1
345+
store i32 %inc, ptr %arrayidx, align 4
346+
%add = add nsw i32 %i.05, %s
347+
%cmp = icmp ne i32 %add, %n
348+
br i1 %cmp, label %for.body, label %for.end
349+
350+
for.end: ; preds = %for.body, %entry
351+
ret void
352+
}
353+
354+
define void @ne_nsw_unknown_step(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
355+
;
356+
; CHECK-LABEL: 'ne_nsw_unknown_step'
357+
; CHECK-NEXT: Determining loop execution counts for: @ne_nsw_unknown_step
358+
; CHECK-NEXT: Loop %for.body: Unpredictable backedge-taken count.
359+
; CHECK-NEXT: Loop %for.body: Unpredictable constant max backedge-taken count.
360+
; CHECK-NEXT: Loop %for.body: Unpredictable symbolic max backedge-taken count.
361+
;
362+
entry:
363+
%cmp4 = icmp sgt i32 %n, 0
364+
br i1 %cmp4, label %for.body, label %for.end
365+
366+
for.body: ; preds = %entry, %for.body
367+
%i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
368+
%arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
369+
%0 = load i32, ptr %arrayidx, align 4
370+
%inc = add nsw i32 %0, 1
371+
store i32 %inc, ptr %arrayidx, align 4
372+
%add = add nsw i32 %i.05, %s
373+
%cmp = icmp ne i32 %add, %n
374+
br i1 %cmp, label %for.body, label %for.end
375+
376+
for.end: ; preds = %for.body, %entry
377+
ret void
378+
}
379+
380+
define void @ne_nuw_pos_step(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
381+
;
382+
; CHECK-LABEL: 'ne_nuw_pos_step'
383+
; CHECK-NEXT: Determining loop execution counts for: @ne_nuw_pos_step
384+
; CHECK-NEXT: Loop %for.body: Unpredictable backedge-taken count.
385+
; CHECK-NEXT: Loop %for.body: Unpredictable constant max backedge-taken count.
386+
; CHECK-NEXT: Loop %for.body: Unpredictable symbolic max backedge-taken count.
387+
;
388+
entry:
389+
%pos_step = icmp sgt i32 %s, 0
390+
call void @llvm.assume(i1 %pos_step)
391+
%cmp4 = icmp sgt i32 %n, 0
392+
br i1 %cmp4, label %for.body, label %for.end
393+
394+
for.body: ; preds = %entry, %for.body
395+
%i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
396+
%arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
397+
%0 = load i32, ptr %arrayidx, align 4
398+
%inc = add nuw i32 %0, 1
399+
store i32 %inc, ptr %arrayidx, align 4
400+
%add = add nuw i32 %i.05, %s
401+
%cmp = icmp ne i32 %add, %n
402+
br i1 %cmp, label %for.body, label %for.end
403+
404+
for.end: ; preds = %for.body, %entry
405+
ret void
406+
}
407+
408+
define void @ne_nuw_neg_step(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
409+
;
410+
; CHECK-LABEL: 'ne_nuw_neg_step'
411+
; CHECK-NEXT: Determining loop execution counts for: @ne_nuw_neg_step
412+
; CHECK-NEXT: Loop %for.body: Unpredictable backedge-taken count.
413+
; CHECK-NEXT: Loop %for.body: Unpredictable constant max backedge-taken count.
414+
; CHECK-NEXT: Loop %for.body: Unpredictable symbolic max backedge-taken count.
415+
;
416+
entry:
417+
%neg_step = icmp slt i32 %s, 0
418+
call void @llvm.assume(i1 %neg_step)
419+
%cmp4 = icmp sgt i32 %n, 0
420+
br i1 %cmp4, label %for.body, label %for.end
421+
422+
for.body: ; preds = %entry, %for.body
423+
%i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
424+
%arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
425+
%0 = load i32, ptr %arrayidx, align 4
426+
%inc = add nuw i32 %0, 1
427+
store i32 %inc, ptr %arrayidx, align 4
428+
%add = add nuw i32 %i.05, %s
429+
%cmp = icmp ne i32 %add, %n
430+
br i1 %cmp, label %for.body, label %for.end
431+
432+
for.end: ; preds = %for.body, %entry
433+
ret void
434+
}
435+
436+
define void @ne_nuw_nonneg_step(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
437+
;
438+
; CHECK-LABEL: 'ne_nuw_nonneg_step'
439+
; CHECK-NEXT: Determining loop execution counts for: @ne_nuw_nonneg_step
440+
; CHECK-NEXT: Loop %for.body: Unpredictable backedge-taken count.
441+
; CHECK-NEXT: Loop %for.body: Unpredictable constant max backedge-taken count.
442+
; CHECK-NEXT: Loop %for.body: Unpredictable symbolic max backedge-taken count.
443+
;
444+
entry:
445+
%nonneg_step = icmp sge i32 %s, 0
446+
call void @llvm.assume(i1 %nonneg_step)
447+
%cmp4 = icmp sgt i32 %n, 0
448+
br i1 %cmp4, label %for.body, label %for.end
449+
450+
for.body: ; preds = %entry, %for.body
451+
%i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
452+
%arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
453+
%0 = load i32, ptr %arrayidx, align 4
454+
%inc = add nuw i32 %0, 1
455+
store i32 %inc, ptr %arrayidx, align 4
456+
%add = add nuw i32 %i.05, %s
457+
%cmp = icmp ne i32 %add, %n
458+
br i1 %cmp, label %for.body, label %for.end
459+
460+
for.end: ; preds = %for.body, %entry
461+
ret void
462+
}
463+
464+
define void @ne_nuw_unknown_step(ptr nocapture %A, i32 %n, i32 %s) mustprogress {
465+
;
466+
; CHECK-LABEL: 'ne_nuw_unknown_step'
467+
; CHECK-NEXT: Determining loop execution counts for: @ne_nuw_unknown_step
468+
; CHECK-NEXT: Loop %for.body: Unpredictable backedge-taken count.
469+
; CHECK-NEXT: Loop %for.body: Unpredictable constant max backedge-taken count.
470+
; CHECK-NEXT: Loop %for.body: Unpredictable symbolic max backedge-taken count.
471+
;
472+
entry:
473+
%cmp4 = icmp sgt i32 %n, 0
474+
br i1 %cmp4, label %for.body, label %for.end
475+
476+
for.body: ; preds = %entry, %for.body
477+
%i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
478+
%arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05
479+
%0 = load i32, ptr %arrayidx, align 4
480+
%inc = add nuw i32 %0, 1
481+
store i32 %inc, ptr %arrayidx, align 4
482+
%add = add nuw i32 %i.05, %s
483+
%cmp = icmp ne i32 %add, %n
484+
br i1 %cmp, label %for.body, label %for.end
485+
486+
for.end: ; preds = %for.body, %entry
487+
ret void
488+
}
489+
270490

491+
declare void @llvm.assume(i1)
271492

272493
!8 = distinct !{!8, !9}
273494
!9 = !{!"llvm.loop.mustprogress"}

0 commit comments

Comments
 (0)