1 ; RUN: opt -verify-loop-info -passes=irce -S < %s | FileCheck %s
2 ; RUN: opt -verify-loop-info -passes='require<branch-prob>,irce' -S < %s | FileCheck %s
4 define void @single_access_with_preloop(ptr %arr, ptr %a_len_ptr, i32 %n, i32 %offset) {
6 %len = load i32, ptr %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, ptr %arr, i32 %array.idx
21 store i32 0, ptr %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: [[safe_offset_preloop:[^ ]+]] = call i32 @llvm.smax.i32(i32 %offset, i32 -2147483647)
35 ; If Offset was a SINT_MIN, we could have an overflow here. That is why we calculated its safe version.
36 ; CHECK: [[safe_start:[^ ]+]] = sub i32 0, [[safe_offset_preloop]]
37 ; CHECK: [[exit_preloop_at_loclamp:[^ ]+]] = call i32 @llvm.smin.i32(i32 %n, i32 [[safe_start]])
38 ; CHECK: [[exit_preloop_at:[^ ]+]] = call i32 @llvm.smax.i32(i32 [[exit_preloop_at_loclamp]], i32 0)
41 ; CHECK: [[len_minus_sint_max:[^ ]+]] = add nuw nsw i32 %len, -2147483647
42 ; CHECK: [[safe_offset_mainloop:[^ ]+]] = call i32 @llvm.smax.i32(i32 %offset, i32 [[len_minus_sint_max]])
43 ; If Offset was a SINT_MIN, we could have an overflow here. That is why we calculated its safe version.
44 ; CHECK: [[safe_upper_end:[^ ]+]] = sub i32 %len, [[safe_offset_mainloop]]
45 ; CHECK: [[exit_mainloop_at_loclamp:[^ ]+]] = call i32 @llvm.smin.i32(i32 %n, i32 [[safe_upper_end]])
46 ; CHECK: [[safe_offset_mainloop_2:[^ ]+]] = call i32 @llvm.smax.i32(i32 %offset, i32 0)
47 ; CHECK: [[safe_lower_end:[^ ]+]] = sub i32 2147483647, [[safe_offset_mainloop_2]]
48 ; CHECK: [[exit_mainloop_at_hiclamp:[^ ]+]] = call i32 @llvm.smin.i32(i32 [[exit_mainloop_at_loclamp]], i32 [[safe_lower_end]])
49 ; CHECK: [[exit_mainloop_at:[^ ]+]] = call i32 @llvm.smax.i32(i32 [[exit_mainloop_at_hiclamp]], i32 0)
52 ; CHECK: br label %loop
55 ; CHECK: %abc.high = icmp slt i32 %array.idx, %len
56 ; CHECK: %abc.low = icmp sge i32 %array.idx, 0
57 ; CHECK: %abc = and i1 true, true
58 ; CHECK: br i1 %abc, label %in.bounds, label %[[loopexit:[^ ,]+]]
61 ; CHECK: [[continue_mainloop_cond:[^ ]+]] = icmp slt i32 %idx.next, [[exit_mainloop_at]]
62 ; CHECK: br i1 [[continue_mainloop_cond]], label %loop, label %main.exit.selector
64 ; CHECK: main.exit.selector:
65 ; CHECK: [[mainloop_its_left:[^ ]+]] = icmp slt i32 %idx.next.lcssa, %n
66 ; CHECK: br i1 [[mainloop_its_left]], label %main.pseudo.exit, label %exit.loopexit
68 ; CHECK: in.bounds.preloop:
69 ; CHECK: [[continue_preloop_cond:[^ ]+]] = icmp slt i32 %idx.next.preloop, [[exit_preloop_at]]
70 ; CHECK: br i1 [[continue_preloop_cond]], label %loop.preloop, label %preloop.exit.selector
72 ; CHECK: preloop.exit.selector:
73 ; CHECK: [[preloop_its_left:[^ ]+]] = icmp slt i32 %idx.next.preloop.lcssa, %n
74 ; CHECK: br i1 [[preloop_its_left]], label %preloop.pseudo.exit, label %exit.loopexit
76 ; CHECK: in.bounds.postloop:
77 ; CHECK: %next.postloop = icmp slt i32 %idx.next.postloop, %n
78 ; CHECK: br i1 %next.postloop, label %loop.postloop, label %exit.loopexit
80 !0 = !{i32 0, i32 2147483647}
81 !1 = !{!"branch_weights", i32 64, i32 4}