1 ; RUN: opt -verify-loop-info -irce -S < %s | FileCheck %s
2 ; RUN: opt -verify-loop-info -passes='require<branch-prob>,loop(irce)' -S < %s | FileCheck %s
4 define void @single_access_with_preloop(i32 *%arr, i32 *%a_len_ptr, i32 %n, i32 %offset) {
6 %len = load i32, i32* %a_len_ptr, !range !0
7 %first.itr.check = icmp sgt i32 %n, 0
8 br i1 %first.itr.check, label %loop, label %exit
11 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
12 %idx.next = add i32 %idx, 1
13 %array.idx = add i32 %idx, %offset
14 %abc.high = icmp slt i32 %array.idx, %len
15 %abc.low = icmp sge i32 %array.idx, 0
16 %abc = and i1 %abc.low, %abc.high
17 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1
20 %addr = getelementptr i32, i32* %arr, i32 %array.idx
21 store i32 0, i32* %addr
22 %next = icmp slt i32 %idx.next, %n
23 br i1 %next, label %loop, label %exit
32 ; CHECK-LABEL: @single_access_with_preloop(
33 ; CHECK: loop.preheader:
34 ; CHECK: [[check_min_sint_offset:[^ ]+]] = icmp sgt i32 %offset, -2147483647
35 ; CHECK: [[safe_offset_preloop:[^ ]+]] = select i1 [[check_min_sint_offset]], i32 %offset, i32 -2147483647
36 ; If Offset was a SINT_MIN, we could have an overflow here. That is why we calculated its safe version.
37 ; CHECK: [[safe_start:[^ ]+]] = sub i32 0, [[safe_offset_preloop]]
38 ; CHECK: [[exit_preloop_at_cond_loclamp:[^ ]+]] = icmp slt i32 %n, [[safe_start]]
39 ; CHECK: [[exit_preloop_at_loclamp:[^ ]+]] = select i1 [[exit_preloop_at_cond_loclamp]], i32 %n, i32 [[safe_start]]
40 ; CHECK: [[exit_preloop_at_cond:[^ ]+]] = icmp sgt i32 [[exit_preloop_at_loclamp]], 0
41 ; CHECK: [[exit_preloop_at:[^ ]+]] = select i1 [[exit_preloop_at_cond]], i32 [[exit_preloop_at_loclamp]], i32 0
44 ; CHECK: [[len_minus_sint_max:[^ ]+]] = add nuw nsw i32 %len, -2147483647
45 ; CHECK: [[check_len_min_sint_offset:[^ ]+]] = icmp sgt i32 %offset, [[len_minus_sint_max]]
46 ; CHECK: [[safe_offset_mainloop:[^ ]+]] = select i1 [[check_len_min_sint_offset]], i32 %offset, i32 [[len_minus_sint_max]]
47 ; If Offset was a SINT_MIN, we could have an overflow here. That is why we calculated its safe version.
48 ; CHECK: [[safe_upper_end:[^ ]+]] = sub i32 %len, [[safe_offset_mainloop]]
49 ; CHECK: [[exit_mainloop_at_cond_loclamp:[^ ]+]] = icmp slt i32 %n, [[safe_upper_end]]
50 ; CHECK: [[exit_mainloop_at_loclamp:[^ ]+]] = select i1 [[exit_mainloop_at_cond_loclamp]], i32 %n, i32 [[safe_upper_end]]
51 ; CHECK: [[check_offset_mainloop_2:[^ ]+]] = icmp sgt i32 %offset, 0
52 ; CHECK: [[safe_offset_mainloop_2:[^ ]+]] = select i1 [[check_offset_mainloop_2]], i32 %offset, i32 0
53 ; CHECK: [[safe_lower_end:[^ ]+]] = sub i32 2147483647, [[safe_offset_mainloop_2]]
54 ; CHECK: [[exit_mainloop_at_cond_hiclamp:[^ ]+]] = icmp slt i32 [[exit_mainloop_at_loclamp]], [[safe_lower_end]]
55 ; CHECK: [[exit_mainloop_at_hiclamp:[^ ]+]] = select i1 [[exit_mainloop_at_cond_hiclamp]], i32 [[exit_mainloop_at_loclamp]], i32 [[safe_lower_end]]
56 ; CHECK: [[exit_mainloop_at_cmp:[^ ]+]] = icmp sgt i32 [[exit_mainloop_at_hiclamp]], 0
57 ; CHECK: [[exit_mainloop_at:[^ ]+]] = select i1 [[exit_mainloop_at_cmp]], i32 [[exit_mainloop_at_hiclamp]], i32 0
60 ; CHECK: br label %loop
63 ; CHECK: %abc.high = icmp slt i32 %array.idx, %len
64 ; CHECK: %abc.low = icmp sge i32 %array.idx, 0
65 ; CHECK: %abc = and i1 true, true
66 ; CHECK: br i1 %abc, label %in.bounds, label %[[loopexit:[^ ,]+]]
69 ; CHECK: [[continue_mainloop_cond:[^ ]+]] = icmp slt i32 %idx.next, [[exit_mainloop_at]]
70 ; CHECK: br i1 [[continue_mainloop_cond]], label %loop, label %main.exit.selector
72 ; CHECK: main.exit.selector:
73 ; CHECK: [[mainloop_its_left:[^ ]+]] = icmp slt i32 %idx.next.lcssa, %n
74 ; CHECK: br i1 [[mainloop_its_left]], label %main.pseudo.exit, label %exit.loopexit
76 ; CHECK: in.bounds.preloop:
77 ; CHECK: [[continue_preloop_cond:[^ ]+]] = icmp slt i32 %idx.next.preloop, [[exit_preloop_at]]
78 ; CHECK: br i1 [[continue_preloop_cond]], label %loop.preloop, label %preloop.exit.selector
80 ; CHECK: preloop.exit.selector:
81 ; CHECK: [[preloop_its_left:[^ ]+]] = icmp slt i32 %idx.next.preloop.lcssa, %n
82 ; CHECK: br i1 [[preloop_its_left]], label %preloop.pseudo.exit, label %exit.loopexit
84 ; CHECK: in.bounds.postloop:
85 ; CHECK: %next.postloop = icmp slt i32 %idx.next.postloop, %n
86 ; CHECK: br i1 %next.postloop, label %loop.postloop, label %exit.loopexit
88 !0 = !{i32 0, i32 2147483647}
89 !1 = !{!"branch_weights", i32 64, i32 4}