Skip to content

Commit bdd40e3

Browse files
committed
[SCEV] Add tests for umin_seq change in #92177
SCEV-only tests for #92177
1 parent 5a2a51b commit bdd40e3

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -passes='print<scalar-evolution>' -scalar-evolution-classify-expressions=0 -disable-output %s 2>&1 | FileCheck %s
3+
4+
; The UDiv in the latch may never be executed. The backedge-taken-count
5+
; expressions must account for the fact that evaluating the UDiv
6+
; unconditionally may trigger UB.
7+
; FIXME: umin_seq should be used instead of umin for BTCs.
8+
define i64 @multi_exit_exit_count_with_udiv_by_value_in_latch(ptr %dst, i64 %N) {
9+
; CHECK-LABEL: 'multi_exit_exit_count_with_udiv_by_value_in_latch'
10+
; CHECK-NEXT: Determining loop execution counts for: @multi_exit_exit_count_with_udiv_by_value_in_latch
11+
; CHECK-NEXT: Loop %loop.header: <multiple exits> backedge-taken count is ((42 /u %N) umin (0 smax %N))
12+
; CHECK-NEXT: exit count for loop.header: (0 smax %N)
13+
; CHECK-NEXT: exit count for loop.latch: (42 /u %N)
14+
; CHECK-NEXT: Loop %loop.header: constant max backedge-taken count is i64 42
15+
; CHECK-NEXT: Loop %loop.header: symbolic max backedge-taken count is ((42 /u %N) umin (0 smax %N))
16+
; CHECK-NEXT: symbolic max exit count for loop.header: (0 smax %N)
17+
; CHECK-NEXT: symbolic max exit count for loop.latch: (42 /u %N)
18+
; CHECK-NEXT: Loop %loop.header: Trip multiple is 1
19+
;
20+
entry:
21+
br label %loop.header
22+
23+
loop.header:
24+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
25+
%gep = getelementptr inbounds i32, ptr %dst, i64 %iv
26+
store i32 1, ptr %gep
27+
%c.0 = icmp slt i64 %iv, %N
28+
br i1 %c.0, label %loop.latch, label %exit
29+
30+
loop.latch:
31+
%iv.next = add i64 %iv, 1
32+
%d = udiv i64 42, %N
33+
%c.1 = icmp slt i64 %iv, %d
34+
br i1 %c.1, label %loop.header, label %exit
35+
36+
exit:
37+
%p = phi i64 [ 1, %loop.header ], [ 0, %loop.latch]
38+
ret i64 %p
39+
}
40+
41+
; The UDiv in the latch may never be executed. The backedge-taken-count
42+
; expressions must account for the fact that evaluating the UDiv
43+
; unconditionally may trigger UB.
44+
; FIXME: umin_seq should be used instead of umin for BTCs.
45+
define i64 @multi_exit_exit_count_with_udiv_by_value_in_latch_different_bounds(ptr %dst, i64 %N, i64 %M) {
46+
; CHECK-LABEL: 'multi_exit_exit_count_with_udiv_by_value_in_latch_different_bounds'
47+
; CHECK-NEXT: Determining loop execution counts for: @multi_exit_exit_count_with_udiv_by_value_in_latch_different_bounds
48+
; CHECK-NEXT: Loop %loop.header: <multiple exits> backedge-taken count is ((0 smax %N) umin_seq (42 /u %M))
49+
; CHECK-NEXT: exit count for loop.header: (0 smax %N)
50+
; CHECK-NEXT: exit count for loop.latch: (42 /u %M)
51+
; CHECK-NEXT: Loop %loop.header: constant max backedge-taken count is i64 42
52+
; CHECK-NEXT: Loop %loop.header: symbolic max backedge-taken count is ((0 smax %N) umin_seq (42 /u %M))
53+
; CHECK-NEXT: symbolic max exit count for loop.header: (0 smax %N)
54+
; CHECK-NEXT: symbolic max exit count for loop.latch: (42 /u %M)
55+
; CHECK-NEXT: Loop %loop.header: Trip multiple is 1
56+
;
57+
entry:
58+
br label %loop.header
59+
60+
loop.header:
61+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
62+
%gep = getelementptr inbounds i32, ptr %dst, i64 %iv
63+
store i32 1, ptr %gep
64+
%c.0 = icmp slt i64 %iv, %N
65+
br i1 %c.0, label %loop.latch, label %exit
66+
67+
loop.latch:
68+
%iv.next = add i64 %iv, 1
69+
%d = udiv i64 42, %M
70+
%c.1 = icmp slt i64 %iv, %d
71+
br i1 %c.1, label %loop.header, label %exit
72+
73+
exit:
74+
%p = phi i64 [ 1, %loop.header ], [ 0, %loop.latch]
75+
ret i64 %p
76+
}
77+
78+
; The UDiv in the latch cannot trigger UB, evaluating it unconditionally in the
79+
; trip count expression is fine.
80+
define i64 @multi_exit_exit_count_with_udiv_by_constant_in_latch(ptr %dst, i64 %N) {
81+
; CHECK-LABEL: 'multi_exit_exit_count_with_udiv_by_constant_in_latch'
82+
; CHECK-NEXT: Determining loop execution counts for: @multi_exit_exit_count_with_udiv_by_constant_in_latch
83+
; CHECK-NEXT: Loop %loop.header: <multiple exits> backedge-taken count is ((%N /u 42) umin (0 smax %N))
84+
; CHECK-NEXT: exit count for loop.header: (0 smax %N)
85+
; CHECK-NEXT: exit count for loop.latch: (%N /u 42)
86+
; CHECK-NEXT: Loop %loop.header: constant max backedge-taken count is i64 439208192231179800
87+
; CHECK-NEXT: Loop %loop.header: symbolic max backedge-taken count is ((%N /u 42) umin (0 smax %N))
88+
; CHECK-NEXT: symbolic max exit count for loop.header: (0 smax %N)
89+
; CHECK-NEXT: symbolic max exit count for loop.latch: (%N /u 42)
90+
; CHECK-NEXT: Loop %loop.header: Trip multiple is 1
91+
;
92+
entry:
93+
br label %loop.header
94+
95+
loop.header:
96+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
97+
%gep = getelementptr inbounds i32, ptr %dst, i64 %iv
98+
store i32 1, ptr %gep
99+
%c.0 = icmp slt i64 %iv, %N
100+
br i1 %c.0, label %loop.latch, label %exit
101+
102+
loop.latch:
103+
%iv.next = add i64 %iv, 1
104+
%d = udiv i64 %N, 42
105+
%c.1 = icmp slt i64 %iv, %d
106+
br i1 %c.1, label %loop.header, label %exit
107+
108+
exit:
109+
%p = phi i64 [ 1, %loop.header ], [ 0, %loop.latch]
110+
ret i64 %p
111+
}

0 commit comments

Comments
 (0)