1; RUN: opt -irce -S < %s | FileCheck %s 2 3define void @single_access_no_preloop_no_offset(i32 *%arr, i32 *%a_len_ptr, i32 %n) { 4 entry: 5 %len = load i32, i32* %a_len_ptr, !range !0 6 %first.itr.check = icmp sgt i32 %n, 0 7 br i1 %first.itr.check, label %loop, label %exit 8 9 loop: 10 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ] 11 %idx.next = add i32 %idx, 1 12 %abc = icmp slt i32 %idx, %len 13 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1 14 15 in.bounds: 16 %addr = getelementptr i32, i32* %arr, i32 %idx 17 store i32 0, i32* %addr 18 %next = icmp slt i32 %idx.next, %n 19 br i1 %next, label %loop, label %exit 20 21 out.of.bounds: 22 ret void 23 24 exit: 25 ret void 26} 27 28; CHECK-LABEL: single_access_no_preloop 29 30; CHECK-LABEL: loop: 31; CHECK: br i1 true, label %in.bounds, label %out.of.bounds 32 33; CHECK-LABEL: main.exit.selector: 34; CHECK-NEXT: [[continue:%[^ ]+]] = icmp slt i32 %idx.next, %n 35; CHECK-NEXT: br i1 [[continue]], label %main.pseudo.exit, label %exit.loopexit 36 37; CHECK-LABEL: main.pseudo.exit: 38; CHECK-NEXT: %idx.copy = phi i32 [ 0, %loop.preheader ], [ %idx.next, %main.exit.selector ] 39; CHECK-NEXT: %indvar.end = phi i32 [ 0, %loop.preheader ], [ %idx.next, %main.exit.selector ] 40; CHECK-NEXT: br label %postloop 41 42; CHECK-LABEL: postloop: 43; CHECK-NEXT: br label %loop.postloop 44 45; CHECK-LABEL: loop.postloop: 46; CHECK-NEXT: %idx.postloop = phi i32 [ %idx.next.postloop, %in.bounds.postloop ], [ %idx.copy, %postloop ] 47; CHECK-NEXT: %idx.next.postloop = add i32 %idx.postloop, 1 48; CHECK-NEXT: %abc.postloop = icmp slt i32 %idx.postloop, %len 49; CHECK-NEXT: br i1 %abc.postloop, label %in.bounds.postloop, label %out.of.bounds 50 51; CHECK-LABEL: in.bounds.postloop: 52; CHECK-NEXT: %addr.postloop = getelementptr i32, i32* %arr, i32 %idx.postloop 53; CHECK-NEXT: store i32 0, i32* %addr.postloop 54; CHECK-NEXT: %next.postloop = icmp slt i32 %idx.next.postloop, %n 55; CHECK-NEXT: br i1 %next.postloop, label %loop.postloop, label %exit.loopexit 56 57 58define void @single_access_no_preloop_with_offset(i32 *%arr, i32 *%a_len_ptr, i32 %n) { 59 entry: 60 %len = load i32, i32* %a_len_ptr, !range !0 61 %first.itr.check = icmp sgt i32 %n, 0 62 br i1 %first.itr.check, label %loop, label %exit 63 64 loop: 65 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ] 66 %idx.next = add i32 %idx, 1 67 %idx.for.abc = add i32 %idx, 4 68 %abc = icmp slt i32 %idx.for.abc, %len 69 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1 70 71 in.bounds: 72 %addr = getelementptr i32, i32* %arr, i32 %idx.for.abc 73 store i32 0, i32* %addr 74 %next = icmp slt i32 %idx.next, %n 75 br i1 %next, label %loop, label %exit 76 77 out.of.bounds: 78 ret void 79 80 exit: 81 ret void 82} 83 84; CHECK-LABEL: single_access_no_preloop_with_offset 85 86; CHECK-LABEL: loop.preheader: 87; CHECK: [[not_n:[^ ]+]] = sub i32 -1, %n 88; CHECK: [[not_safe_range_end:[^ ]+]] = sub i32 3, %len 89; CHECK: [[not_exit_main_loop_at_hiclamp_cmp:[^ ]+]] = icmp sgt i32 [[not_n]], [[not_safe_range_end]] 90; CHECK: [[not_exit_main_loop_at_hiclamp:[^ ]+]] = select i1 [[not_exit_main_loop_at_hiclamp_cmp]], i32 [[not_n]], i32 [[not_safe_range_end]] 91; CHECK: [[exit_main_loop_at_hiclamp:[^ ]+]] = sub i32 -1, [[not_exit_main_loop_at_hiclamp]] 92; CHECK: [[exit_main_loop_at_loclamp_cmp:[^ ]+]] = icmp sgt i32 [[exit_main_loop_at_hiclamp]], 0 93; CHECK: [[exit_main_loop_at_loclamp:[^ ]+]] = select i1 [[exit_main_loop_at_loclamp_cmp]], i32 [[exit_main_loop_at_hiclamp]], i32 0 94; CHECK: [[enter_main_loop:[^ ]+]] = icmp slt i32 0, [[exit_main_loop_at_loclamp]] 95; CHECK: br i1 [[enter_main_loop]], label %loop, label %main.pseudo.exit 96 97; CHECK-LABEL: loop: 98; CHECK: br i1 true, label %in.bounds, label %out.of.bounds 99 100; CHECK-LABEL: in.bounds: 101; CHECK: [[continue_main_loop:[^ ]+]] = icmp slt i32 %idx.next, [[exit_main_loop_at_loclamp]] 102; CHECK: br i1 [[continue_main_loop]], label %loop, label %main.exit.selector 103 104; CHECK-LABEL: main.pseudo.exit: 105; CHECK: %idx.copy = phi i32 [ 0, %loop.preheader ], [ %idx.next, %main.exit.selector ] 106; CHECK: br label %postloop 107 108; CHECK-LABEL: loop.postloop: 109; CHECK: %idx.postloop = phi i32 [ %idx.next.postloop, %in.bounds.postloop ], [ %idx.copy, %postloop ] 110 111; CHECK-LABEL: in.bounds.postloop: 112; CHECK: %next.postloop = icmp slt i32 %idx.next.postloop, %n 113; CHECK: br i1 %next.postloop, label %loop.postloop, label %exit.loopexit 114 115!0 = !{i32 0, i32 2147483647} 116!1 = !{!"branch_weights", i32 64, i32 4} 117