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