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 3 4 define void @single_access_with_preloop(i32 *%arr, i32 *%a_len_ptr, i32 %n, i32 %offset) { 5 entry: 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 9 10 loop: 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 18 19 in.bounds: 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 24 25 out.of.bounds: 26 ret void 27 28 exit: 29 ret void 30 } 31 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: [[not_safe_start:[^ ]+]] = add i32 [[safe_offset_preloop]], -1 38 ; CHECK: [[not_n:[^ ]+]] = sub i32 -1, %n 39 ; CHECK: [[not_exit_preloop_at_cond_loclamp:[^ ]+]] = icmp sgt i32 [[not_safe_start]], [[not_n]] 40 ; CHECK: [[not_exit_preloop_at_loclamp:[^ ]+]] = select i1 [[not_exit_preloop_at_cond_loclamp]], i32 [[not_safe_start]], i32 [[not_n]] 41 ; CHECK: [[exit_preloop_at_loclamp:[^ ]+]] = sub i32 -1, [[not_exit_preloop_at_loclamp]] 42 ; CHECK: [[exit_preloop_at_cond:[^ ]+]] = icmp sgt i32 [[exit_preloop_at_loclamp]], 0 43 ; CHECK: [[exit_preloop_at:[^ ]+]] = select i1 [[exit_preloop_at_cond]], i32 [[exit_preloop_at_loclamp]], i32 0 44 45 46 ; CHECK: [[len_minus_sint_max:[^ ]+]] = add i32 %len, -2147483647 47 ; CHECK: [[check_len_min_sint_offset:[^ ]+]] = icmp sgt i32 %offset, [[len_minus_sint_max]] 48 ; CHECK: [[safe_offset_mainloop:[^ ]+]] = select i1 [[check_len_min_sint_offset]], i32 %offset, i32 [[len_minus_sint_max]] 49 ; CHECK: [[not_safe_start_2:[^ ]+]] = add i32 [[safe_offset_mainloop]], -1 50 ; If Offset was a SINT_MIN, we could have an overflow here. That is why we calculated its safe version. 51 ; CHECK: [[not_safe_upper_end:[^ ]+]] = sub i32 [[not_safe_start_2]], %len 52 ; CHECK: [[not_exit_mainloop_at_cond_loclamp:[^ ]+]] = icmp sgt i32 [[not_safe_upper_end]], [[not_n]] 53 ; CHECK: [[not_exit_mainloop_at_loclamp:[^ ]+]] = select i1 [[not_exit_mainloop_at_cond_loclamp]], i32 [[not_safe_upper_end]], i32 [[not_n]] 54 ; CHECK: [[check_offset_mainloop_2:[^ ]+]] = icmp sgt i32 %offset, 0 55 ; CHECK: [[safe_offset_mainloop_2:[^ ]+]] = select i1 [[check_offset_mainloop_2]], i32 %offset, i32 0 56 ; CHECK: [[not_safe_lower_end:[^ ]+]] = add i32 [[safe_offset_mainloop_2]], -2147483648 57 ; CHECK: [[not_exit_mainloop_at_cond_hiclamp:[^ ]+]] = icmp sgt i32 [[not_exit_mainloop_at_loclamp]], [[not_safe_lower_end]] 58 ; CHECK: [[not_exit_mainloop_at_hiclamp:[^ ]+]] = select i1 [[not_exit_mainloop_at_cond_hiclamp]], i32 [[not_exit_mainloop_at_loclamp]], i32 [[not_safe_lower_end]] 59 ; CHECK: [[exit_mainloop_at_hiclamp:[^ ]+]] = sub i32 -1, [[not_exit_mainloop_at_hiclamp]] 60 ; CHECK: [[exit_mainloop_at_cmp:[^ ]+]] = icmp sgt i32 [[exit_mainloop_at_hiclamp]], 0 61 ; CHECK: [[exit_mainloop_at:[^ ]+]] = select i1 [[exit_mainloop_at_cmp]], i32 [[exit_mainloop_at_hiclamp]], i32 0 62 63 ; CHECK: mainloop: 64 ; CHECK: br label %loop 65 66 ; CHECK: loop: 67 ; CHECK: %abc.high = icmp slt i32 %array.idx, %len 68 ; CHECK: %abc.low = icmp sge i32 %array.idx, 0 69 ; CHECK: %abc = and i1 true, true 70 ; CHECK: br i1 %abc, label %in.bounds, label %out.of.bounds.loopexit11 71 72 ; CHECK: in.bounds: 73 ; CHECK: [[continue_mainloop_cond:[^ ]+]] = icmp slt i32 %idx.next, [[exit_mainloop_at]] 74 ; CHECK: br i1 [[continue_mainloop_cond]], label %loop, label %main.exit.selector 75 76 ; CHECK: main.exit.selector: 77 ; CHECK: [[mainloop_its_left:[^ ]+]] = icmp slt i32 %idx.next.lcssa, %n 78 ; CHECK: br i1 [[mainloop_its_left]], label %main.pseudo.exit, label %exit.loopexit 79 80 ; CHECK: in.bounds.preloop: 81 ; CHECK: [[continue_preloop_cond:[^ ]+]] = icmp slt i32 %idx.next.preloop, [[exit_preloop_at]] 82 ; CHECK: br i1 [[continue_preloop_cond]], label %loop.preloop, label %preloop.exit.selector 83 84 ; CHECK: preloop.exit.selector: 85 ; CHECK: [[preloop_its_left:[^ ]+]] = icmp slt i32 %idx.next.preloop.lcssa, %n 86 ; CHECK: br i1 [[preloop_its_left]], label %preloop.pseudo.exit, label %exit.loopexit 87 88 ; CHECK: in.bounds.postloop: 89 ; CHECK: %next.postloop = icmp slt i32 %idx.next.postloop, %n 90 ; CHECK: br i1 %next.postloop, label %loop.postloop, label %exit.loopexit 91 92 !0 = !{i32 0, i32 2147483647} 93 !1 = !{!"branch_weights", i32 64, i32 4} 94