1 ; RUN: opt -S -verify-loop-info -irce < %s | FileCheck %s
2 ; RUN: opt -S -verify-loop-info -passes='require<branch-prob>,loop(irce)' < %s | FileCheck %s
4 define void @f_0(i32 *%arr, i32 *%a_len_ptr, i32 %n, i1* %cond_buf) {
7 ; CHECK: loop.preheader:
8 ; CHECK: [[len_sub:[^ ]+]] = add nsw i32 %len, -4
9 ; CHECK: [[exit_main_loop_at_hiclamp_cmp:[^ ]+]] = icmp slt i32 %n, [[len_sub]]
10 ; CHECK: [[exit_main_loop_at_hiclamp:[^ ]+]] = select i1 [[exit_main_loop_at_hiclamp_cmp]], i32 %n, i32 [[len_sub]]
11 ; CHECK: [[exit_main_loop_at_loclamp_cmp:[^ ]+]] = icmp sgt i32 [[exit_main_loop_at_hiclamp]], 0
12 ; CHECK: [[exit_main_loop_at_loclamp:[^ ]+]] = select i1 [[exit_main_loop_at_loclamp_cmp]], i32 [[exit_main_loop_at_hiclamp]], i32 0
13 ; CHECK: [[enter_main_loop:[^ ]+]] = icmp slt i32 0, [[exit_main_loop_at_loclamp]]
14 ; CHECK: br i1 [[enter_main_loop]], label %[[loop_preheader2:[^ ,]+]], label %main.pseudo.exit
16 ; CHECK: [[loop_preheader2]]:
17 ; CHECK: br label %loop
20 %len = load i32, i32* %a_len_ptr, !range !0
21 %first.itr.check = icmp sgt i32 %n, 0
22 br i1 %first.itr.check, label %loop, label %exit
25 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
26 %idx.next = add i32 %idx, 1
27 %idx.for.abc = add i32 %idx, 4
28 %abc.actual = icmp slt i32 %idx.for.abc, %len
29 %cond = load volatile i1, i1* %cond_buf
30 %abc = and i1 %cond, %abc.actual
31 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1
34 ; CHECK: %cond = load volatile i1, i1* %cond_buf
35 ; CHECK: %abc = and i1 %cond, true
36 ; CHECK: br i1 %abc, label %in.bounds, label %[[loop_exit:[^ ,]+]], !prof !1
38 ; CHECK: [[loop_exit]]:
39 ; CHECK: br label %out.of.bounds
42 %addr = getelementptr i32, i32* %arr, i32 %idx.for.abc
43 store i32 0, i32* %addr
44 %next = icmp slt i32 %idx.next, %n
45 br i1 %next, label %loop, label %exit
55 i32* %arr_a, i32* %a_len_ptr, i32* %arr_b, i32* %b_len_ptr, i32 %n) {
58 ; CHECK: loop.preheader:
59 ; CHECK: [[smax_len_cond:[^ ]+]] = icmp slt i32 %len.b, %len.a
60 ; CHECK: [[smax_len:[^ ]+]] = select i1 [[smax_len_cond]], i32 %len.b, i32 %len.a
61 ; CHECK: [[upper_limit_cond_loclamp:[^ ]+]] = icmp slt i32 [[smax_len]], %n
62 ; CHECK: [[upper_limit_loclamp:[^ ]+]] = select i1 [[upper_limit_cond_loclamp]], i32 [[smax_len]], i32 %n
63 ; CHECK: [[upper_limit_cmp:[^ ]+]] = icmp sgt i32 [[upper_limit_loclamp]], 0
64 ; CHECK: [[upper_limit:[^ ]+]] = select i1 [[upper_limit_cmp]], i32 [[upper_limit_loclamp]], i32 0
67 %len.a = load i32, i32* %a_len_ptr, !range !0
68 %len.b = load i32, i32* %b_len_ptr, !range !0
69 %first.itr.check = icmp sgt i32 %n, 0
70 br i1 %first.itr.check, label %loop, label %exit
73 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
74 %idx.next = add i32 %idx, 1
75 %abc.a = icmp slt i32 %idx, %len.a
76 %abc.b = icmp slt i32 %idx, %len.b
77 %abc = and i1 %abc.a, %abc.b
78 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1
81 ; CHECK: %abc = and i1 true, true
82 ; CHECK: br i1 %abc, label %in.bounds, label %[[oob_loopexit:[^ ,]+]], !prof !1
84 ; CHECK: [[oob_loopexit]]:
85 ; CHECK-NEXT: br label %out.of.bounds
89 %addr.a = getelementptr i32, i32* %arr_a, i32 %idx
90 store i32 0, i32* %addr.a
91 %addr.b = getelementptr i32, i32* %arr_b, i32 %idx
92 store i32 -1, i32* %addr.b
93 %next = icmp slt i32 %idx.next, %n
94 br i1 %next, label %loop, label %exit
103 !0 = !{i32 0, i32 2147483647}
104 !1 = !{!"branch_weights", i32 64, i32 4}