[bazel] Replace strip_include_prefix in lldb with includes (#125293)
[llvm-project.git] / llvm / test / Analysis / ScalarEvolution / umin-seq-operand-may-trigger-ub.ll
blobf84f35d4e8ca20623817c1853e6f5c3499e1a608
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
19 entry:
20   br label %loop.header
22 loop.header:
23   %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
24   %gep = getelementptr inbounds i32, ptr %dst, i64 %iv
25   store i32 1, ptr %gep
26   %c.0 = icmp slt i64 %iv, %N
27   br i1 %c.0, label %loop.latch, label %exit
29 loop.latch:
30   %iv.next = add i64 %iv, 1
31   %d = udiv i64 42, %N
32   %c.1 = icmp slt i64 %iv, %d
33   br i1 %c.1, label %loop.header, label %exit
35 exit:
36   %p = phi i64 [ 1, %loop.header ], [ 0, %loop.latch]
37   ret i64 %p
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
55 entry:
56   br label %loop.header
58 loop.header:
59   %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
60   %gep = getelementptr inbounds i32, ptr %dst, i64 %iv
61   store i32 1, ptr %gep
62   %c.0 = icmp slt i64 %iv, %N
63   br i1 %c.0, label %loop.latch, label %exit
65 loop.latch:
66   %iv.next = add i64 %iv, 1
67   %d = udiv i64 42, %M
68   %c.1 = icmp slt i64 %iv, %d
69   br i1 %c.1, label %loop.header, label %exit
71 exit:
72   %p = phi i64 [ 1, %loop.header ], [ 0, %loop.latch]
73   ret i64 %p
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
90 entry:
91   br label %loop.header
93 loop.header:
94   %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
95   %gep = getelementptr inbounds i32, ptr %dst, i64 %iv
96   store i32 1, ptr %gep
97   %c.0 = icmp slt i64 %iv, %N
98   br i1 %c.0, label %loop.latch, label %exit
100 loop.latch:
101   %iv.next = add i64 %iv, 1
102   %d = udiv i64 %N, 42
103   %c.1 = icmp slt i64 %iv, %d
104   br i1 %c.1, label %loop.header, label %exit
106 exit:
107   %p = phi i64 [ 1, %loop.header ], [ 0, %loop.latch]
108   ret i64 %p