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
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 define i64 @multi_exit_exit_count_with_udiv_by_value_in_latch(ptr %dst, i64 %N) {
8 ; CHECK-LABEL: 'multi_exit_exit_count_with_udiv_by_value_in_latch'
9 ; CHECK-NEXT: Determining loop execution counts for: @multi_exit_exit_count_with_udiv_by_value_in_latch
10 ; CHECK-NEXT: Loop %loop.header: <multiple exits> backedge-taken count is ((0 smax %N) umin_seq (42 /u %N))
11 ; CHECK-NEXT: exit count for loop.header: (0 smax %N)
12 ; CHECK-NEXT: exit count for loop.latch: (42 /u %N)
13 ; CHECK-NEXT: Loop %loop.header: constant max backedge-taken count is i64 42
14 ; CHECK-NEXT: Loop %loop.header: symbolic max backedge-taken count is ((0 smax %N) umin_seq (42 /u %N))
15 ; CHECK-NEXT: symbolic max exit count for loop.header: (0 smax %N)
16 ; CHECK-NEXT: symbolic max exit count for loop.latch: (42 /u %N)
17 ; CHECK-NEXT: Loop %loop.header: Trip multiple is 1
23 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
24 %gep = getelementptr inbounds i32, ptr %dst, i64 %iv
26 %c.0 = icmp slt i64 %iv, %N
27 br i1 %c.0, label %loop.latch, label %exit
30 %iv.next = add i64 %iv, 1
32 %c.1 = icmp slt i64 %iv, %d
33 br i1 %c.1, label %loop.header, label %exit
36 %p = phi i64 [ 1, %loop.header ], [ 0, %loop.latch]
40 ; The UDiv in the latch may never be executed. The backedge-taken-count
41 ; expressions must account for the fact that evaluating the UDiv
42 ; unconditionally may trigger UB.
43 define i64 @multi_exit_exit_count_with_udiv_by_value_in_latch_different_bounds(ptr %dst, i64 %N, i64 %M) {
44 ; CHECK-LABEL: 'multi_exit_exit_count_with_udiv_by_value_in_latch_different_bounds'
45 ; CHECK-NEXT: Determining loop execution counts for: @multi_exit_exit_count_with_udiv_by_value_in_latch_different_bounds
46 ; CHECK-NEXT: Loop %loop.header: <multiple exits> backedge-taken count is ((0 smax %N) umin_seq (42 /u %M))
47 ; CHECK-NEXT: exit count for loop.header: (0 smax %N)
48 ; CHECK-NEXT: exit count for loop.latch: (42 /u %M)
49 ; CHECK-NEXT: Loop %loop.header: constant max backedge-taken count is i64 42
50 ; CHECK-NEXT: Loop %loop.header: symbolic max backedge-taken count is ((0 smax %N) umin_seq (42 /u %M))
51 ; CHECK-NEXT: symbolic max exit count for loop.header: (0 smax %N)
52 ; CHECK-NEXT: symbolic max exit count for loop.latch: (42 /u %M)
53 ; CHECK-NEXT: Loop %loop.header: Trip multiple is 1
59 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
60 %gep = getelementptr inbounds i32, ptr %dst, i64 %iv
62 %c.0 = icmp slt i64 %iv, %N
63 br i1 %c.0, label %loop.latch, label %exit
66 %iv.next = add i64 %iv, 1
68 %c.1 = icmp slt i64 %iv, %d
69 br i1 %c.1, label %loop.header, label %exit
72 %p = phi i64 [ 1, %loop.header ], [ 0, %loop.latch]
76 ; The UDiv in the latch cannot trigger UB, evaluating it unconditionally in the
77 ; trip count expression is fine.
78 define i64 @multi_exit_exit_count_with_udiv_by_constant_in_latch(ptr %dst, i64 %N) {
79 ; CHECK-LABEL: 'multi_exit_exit_count_with_udiv_by_constant_in_latch'
80 ; CHECK-NEXT: Determining loop execution counts for: @multi_exit_exit_count_with_udiv_by_constant_in_latch
81 ; CHECK-NEXT: Loop %loop.header: <multiple exits> backedge-taken count is ((%N /u 42) umin (0 smax %N))
82 ; CHECK-NEXT: exit count for loop.header: (0 smax %N)
83 ; CHECK-NEXT: exit count for loop.latch: (%N /u 42)
84 ; CHECK-NEXT: Loop %loop.header: constant max backedge-taken count is i64 439208192231179800
85 ; CHECK-NEXT: Loop %loop.header: symbolic max backedge-taken count is ((%N /u 42) umin (0 smax %N))
86 ; CHECK-NEXT: symbolic max exit count for loop.header: (0 smax %N)
87 ; CHECK-NEXT: symbolic max exit count for loop.latch: (%N /u 42)
88 ; CHECK-NEXT: Loop %loop.header: Trip multiple is 1
94 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
95 %gep = getelementptr inbounds i32, ptr %dst, i64 %iv
97 %c.0 = icmp slt i64 %iv, %N
98 br i1 %c.0, label %loop.latch, label %exit
101 %iv.next = add i64 %iv, 1
103 %c.1 = icmp slt i64 %iv, %d
104 br i1 %c.1, label %loop.header, label %exit
107 %p = phi i64 [ 1, %loop.header ], [ 0, %loop.latch]