1 ; RUN: opt -S -verify-loop-info -irce < %s | FileCheck %s
2 ; RUN: opt -S -verify-loop-info -passes='require<branch-prob>,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:[^ ]+]] = call i32 @llvm.smin.i32(i32 %n, i32 [[len_sub]])
10 ; CHECK: [[exit_main_loop_at_loclamp:[^ ]+]] = call i32 @llvm.smax.i32(i32 [[exit_main_loop_at_hiclamp]], i32 0)
11 ; CHECK: [[enter_main_loop:[^ ]+]] = icmp slt i32 0, [[exit_main_loop_at_loclamp]]
12 ; CHECK: br i1 [[enter_main_loop]], label %[[loop_preheader2:[^ ,]+]], label %main.pseudo.exit
14 ; CHECK: [[loop_preheader2]]:
15 ; CHECK: br label %loop
18 %len = load i32, i32* %a_len_ptr, !range !0
19 %first.itr.check = icmp sgt i32 %n, 0
20 br i1 %first.itr.check, label %loop, label %exit
23 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
24 %idx.next = add i32 %idx, 1
25 %idx.for.abc = add i32 %idx, 4
26 %abc.actual = icmp slt i32 %idx.for.abc, %len
27 %cond = load volatile i1, i1* %cond_buf
28 %abc = and i1 %cond, %abc.actual
29 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1
32 ; CHECK: %cond = load volatile i1, i1* %cond_buf
33 ; CHECK: %abc = and i1 %cond, true
34 ; CHECK: br i1 %abc, label %in.bounds, label %[[loop_exit:[^ ,]+]], !prof !1
36 ; CHECK: [[loop_exit]]:
37 ; CHECK: br label %out.of.bounds
40 %addr = getelementptr i32, i32* %arr, i32 %idx.for.abc
41 store i32 0, i32* %addr
42 %next = icmp slt i32 %idx.next, %n
43 br i1 %next, label %loop, label %exit
53 i32* %arr_a, i32* %a_len_ptr, i32* %arr_b, i32* %b_len_ptr, i32 %n) {
56 ; CHECK: loop.preheader:
57 ; CHECK: [[smax_len:[^ ]+]] = call i32 @llvm.smin.i32(i32 %len.b, i32 %len.a)
58 ; CHECK: [[upper_limit_loclamp:[^ ]+]] = call i32 @llvm.smin.i32(i32 [[smax_len]], i32 %n)
59 ; CHECK: [[upper_limit:[^ ]+]] = call i32 @llvm.smax.i32(i32 [[upper_limit_loclamp]], i32 0)
62 %len.a = load i32, i32* %a_len_ptr, !range !0
63 %len.b = load i32, i32* %b_len_ptr, !range !0
64 %first.itr.check = icmp sgt i32 %n, 0
65 br i1 %first.itr.check, label %loop, label %exit
68 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
69 %idx.next = add i32 %idx, 1
70 %abc.a = icmp slt i32 %idx, %len.a
71 %abc.b = icmp slt i32 %idx, %len.b
72 %abc = and i1 %abc.a, %abc.b
73 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1
76 ; CHECK: %abc = and i1 true, true
77 ; CHECK: br i1 %abc, label %in.bounds, label %[[oob_loopexit:[^ ,]+]], !prof !1
79 ; CHECK: [[oob_loopexit]]:
80 ; CHECK-NEXT: br label %out.of.bounds
84 %addr.a = getelementptr i32, i32* %arr_a, i32 %idx
85 store i32 0, i32* %addr.a
86 %addr.b = getelementptr i32, i32* %arr_b, i32 %idx
87 store i32 -1, i32* %addr.b
88 %next = icmp slt i32 %idx.next, %n
89 br i1 %next, label %loop, label %exit
98 !0 = !{i32 0, i32 2147483647}
99 !1 = !{!"branch_weights", i32 64, i32 4}