Skip to content

Commit 5cd45e4

Browse files
committed
[SCEV] Precommit test for widened signed induction variables
These tests highlight that we have missed oppurtunities proving trip count bounds when our start/end values are sign extended from smaller types and we have either a loop guard to relate our start vs end, or a nsw/nuw fact to bound end.
1 parent 47bc565 commit 5cd45e4

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,74 @@ loop:
140140
exit:
141141
ret void
142142
}
143+
144+
define void @dual_sext_ne_with_slt_guard(i8 %s, i8 %n) {
145+
; CHECK-LABEL: 'dual_sext_ne_with_slt_guard'
146+
; CHECK-NEXT: Determining loop execution counts for: @dual_sext_ne_with_slt_guard
147+
; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + (sext i8 %n to i64) + (-1 * (sext i8 %s to i64))<nsw>)
148+
; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is i64 -1
149+
; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + (sext i8 %n to i64) + (-1 * (sext i8 %s to i64))<nsw>)
150+
; CHECK-NEXT: Loop %for.body: Trip multiple is 1
151+
;
152+
entry:
153+
%cmp4 = icmp slt i8 %s, %n
154+
br i1 %cmp4, label %for.body.preheader, label %exit
155+
156+
for.body.preheader:
157+
%0 = sext i8 %s to i64
158+
%wide.trip.count = sext i8 %n to i64
159+
br label %for.body
160+
161+
for.body:
162+
%iv = phi i64 [ %0, %for.body.preheader ], [ %iv.next, %for.body ]
163+
%iv.next = add nsw i64 %iv, 1
164+
%exitcond.not = icmp eq i64 %iv.next, %wide.trip.count
165+
br i1 %exitcond.not, label %exit, label %for.body
166+
167+
exit:
168+
ret void
169+
}
170+
171+
define void @dual_sext_ne_with_nsw_inc(i8 %s, i64 %n) {
172+
; CHECK-LABEL: 'dual_sext_ne_with_nsw_inc'
173+
; CHECK-NEXT: Determining loop execution counts for: @dual_sext_ne_with_nsw_inc
174+
; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + (-1 * (sext i8 %s to i64))<nsw> + %n)
175+
; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is i64 -1
176+
; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + (-1 * (sext i8 %s to i64))<nsw> + %n)
177+
; CHECK-NEXT: Loop %for.body: Trip multiple is 1
178+
;
179+
entry:
180+
%0 = sext i8 %s to i64
181+
br label %for.body
182+
183+
for.body:
184+
%iv = phi i64 [ %0, %entry ], [ %iv.next, %for.body ]
185+
%iv.next = add nsw i64 %iv, 1
186+
%exitcond.not = icmp eq i64 %iv.next, %n
187+
br i1 %exitcond.not, label %exit, label %for.body
188+
189+
exit:
190+
ret void
191+
}
192+
193+
define void @dual_sext_ne_with_nuw_inc(i8 %s, i64 %n) {
194+
; CHECK-LABEL: 'dual_sext_ne_with_nuw_inc'
195+
; CHECK-NEXT: Determining loop execution counts for: @dual_sext_ne_with_nuw_inc
196+
; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + (-1 * (sext i8 %s to i64))<nsw> + %n)
197+
; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is i64 -1
198+
; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + (-1 * (sext i8 %s to i64))<nsw> + %n)
199+
; CHECK-NEXT: Loop %for.body: Trip multiple is 1
200+
;
201+
entry:
202+
%0 = sext i8 %s to i64
203+
br label %for.body
204+
205+
for.body:
206+
%iv = phi i64 [ %0, %entry ], [ %iv.next, %for.body ]
207+
%iv.next = add nuw i64 %iv, 1
208+
%exitcond.not = icmp eq i64 %iv.next, %n
209+
br i1 %exitcond.not, label %exit, label %for.body
210+
211+
exit:
212+
ret void
213+
}

0 commit comments

Comments
 (0)