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 4define void @multiple_access_no_preloop( 5 i32* %arr_a, i32* %a_len_ptr, i32* %arr_b, i32* %b_len_ptr, i32 %n) { 6 7 entry: 8 %len.a = load i32, i32* %a_len_ptr, !range !0 9 %len.b = load i32, i32* %b_len_ptr, !range !0 10 %first.itr.check = icmp sgt i32 %n, 0 11 br i1 %first.itr.check, label %loop, label %exit 12 13 loop: 14 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds.b ] 15 %idx.next = add i32 %idx, 1 16 %abc.a = icmp slt i32 %idx, %len.a 17 br i1 %abc.a, label %in.bounds.a, label %out.of.bounds, !prof !1 18 19 in.bounds.a: 20 %addr.a = getelementptr i32, i32* %arr_a, i32 %idx 21 store i32 0, i32* %addr.a 22 %abc.b = icmp slt i32 %idx, %len.b 23 br i1 %abc.b, label %in.bounds.b, label %out.of.bounds, !prof !1 24 25 in.bounds.b: 26 %addr.b = getelementptr i32, i32* %arr_b, i32 %idx 27 store i32 -1, i32* %addr.b 28 %next = icmp slt i32 %idx.next, %n 29 br i1 %next, label %loop, label %exit 30 31 out.of.bounds: 32 ret void 33 34 exit: 35 ret void 36} 37 38; CHECK-LABEL: @multiple_access_no_preloop( 39 40; CHECK: loop.preheader: 41; CHECK: [[not_len_b:[^ ]+]] = sub i32 -1, %len.b 42; CHECK: [[not_len_a:[^ ]+]] = sub i32 -1, %len.a 43; CHECK: [[smax_not_len_cond:[^ ]+]] = icmp sgt i32 [[not_len_b]], [[not_len_a]] 44; CHECK: [[smax_not_len:[^ ]+]] = select i1 [[smax_not_len_cond]], i32 [[not_len_b]], i32 [[not_len_a]] 45; CHECK: [[not_n:[^ ]+]] = sub i32 -1, %n 46; CHECK: [[not_upper_limit_cond_loclamp:[^ ]+]] = icmp sgt i32 [[smax_not_len]], [[not_n]] 47; CHECK: [[not_upper_limit_loclamp:[^ ]+]] = select i1 [[not_upper_limit_cond_loclamp]], i32 [[smax_not_len]], i32 [[not_n]] 48; CHECK: [[upper_limit_loclamp:[^ ]+]] = sub i32 -1, [[not_upper_limit_loclamp]] 49; CHECK: [[upper_limit_cmp:[^ ]+]] = icmp sgt i32 [[upper_limit_loclamp]], 0 50; CHECK: [[upper_limit:[^ ]+]] = select i1 [[upper_limit_cmp]], i32 [[upper_limit_loclamp]], i32 0 51 52; CHECK: loop: 53; CHECK: br i1 true, label %in.bounds.a, label %out.of.bounds 54 55; CHECK: in.bounds.a: 56; CHECK: br i1 true, label %in.bounds.b, label %out.of.bounds 57 58; CHECK: in.bounds.b: 59; CHECK: [[main_loop_cond:[^ ]+]] = icmp slt i32 %idx.next, [[upper_limit]] 60; CHECK: br i1 [[main_loop_cond]], label %loop, label %main.exit.selector 61 62; CHECK: in.bounds.b.postloop: 63; CHECK: %next.postloop = icmp slt i32 %idx.next.postloop, %n 64; CHECK: br i1 %next.postloop, label %loop.postloop, label %exit.loopexit 65 66!0 = !{i32 0, i32 2147483647} 67!1 = !{!"branch_weights", i32 64, i32 4} 68