Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 1 | ; RUN: opt -irce -S < %s | FileCheck %s |
| 2 | |
| 3 | define void @single_access_with_preloop(i32 *%arr, i32 *%a_len_ptr, i32 %n, i32 %offset) { |
| 4 | entry: |
| 5 | %len = load 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 | %array.idx = add i32 %idx, %offset |
| 13 | %abc.high = icmp slt i32 %array.idx, %len |
| 14 | %abc.low = icmp sge i32 %array.idx, 0 |
| 15 | %abc = and i1 %abc.low, %abc.high |
Sanjoy Das | dcf2651 | 2015-01-27 21:38:12 +0000 | [diff] [blame] | 16 | br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1 |
Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 17 | |
| 18 | in.bounds: |
| 19 | %addr = getelementptr i32* %arr, i32 %array.idx |
| 20 | store i32 0, i32* %addr |
| 21 | %next = icmp slt i32 %idx.next, %n |
| 22 | br i1 %next, label %loop, label %exit |
| 23 | |
| 24 | out.of.bounds: |
| 25 | ret void |
| 26 | |
| 27 | exit: |
| 28 | ret void |
| 29 | } |
| 30 | |
| 31 | ; CHECK-LABEL: loop.preheader: |
| 32 | ; CHECK: [[safe_start:[^ ]+]] = sub i32 0, %offset |
| 33 | ; CHECK: [[safe_end:[^ ]+]] = sub i32 %len, %offset |
| 34 | ; CHECK: [[exit_preloop_at_cond:[^ ]+]] = icmp slt i32 %n, [[safe_start]] |
| 35 | ; CHECK: [[exit_preloop_at:[^ ]+]] = select i1 [[exit_preloop_at_cond]], i32 %n, i32 [[safe_start]] |
| 36 | ; CHECK: [[exit_mainloop_at_cond:[^ ]+]] = icmp slt i32 %n, [[safe_end]] |
| 37 | ; CHECK: [[exit_mainloop_at:[^ ]+]] = select i1 [[exit_mainloop_at_cond]], i32 %n, i32 [[safe_end]] |
| 38 | |
| 39 | ; CHECK-LABEL: in.bounds: |
| 40 | ; CHECK: [[continue_mainloop_cond:[^ ]+]] = icmp slt i32 %idx.next, [[exit_mainloop_at]] |
| 41 | ; CHECK: br i1 [[continue_mainloop_cond]], label %loop, label %main.exit.selector |
| 42 | |
| 43 | ; CHECK-LABEL: main.exit.selector: |
| 44 | ; CHECK: [[mainloop_its_left:[^ ]+]] = icmp slt i32 %idx.next, %n |
| 45 | ; CHECK: br i1 [[mainloop_its_left]], label %main.pseudo.exit, label %exit.loopexit |
| 46 | |
| 47 | ; CHECK-LABEL: in.bounds.preloop: |
| 48 | ; CHECK: [[continue_preloop_cond:[^ ]+]] = icmp slt i32 %idx.next.preloop, [[exit_preloop_at]] |
| 49 | ; CHECK: br i1 [[continue_preloop_cond]], label %loop.preloop, label %preloop.exit.selector |
| 50 | |
| 51 | ; CHECK-LABEL: preloop.exit.selector: |
| 52 | ; CHECK: [[preloop_its_left:[^ ]+]] = icmp slt i32 %idx.next.preloop, %n |
| 53 | ; CHECK: br i1 [[preloop_its_left]], label %preloop.pseudo.exit, label %exit.loopexit |
| 54 | |
| 55 | ; CHECK-LABEL: in.bounds.postloop: |
| 56 | ; CHECK: %next.postloop = icmp slt i32 %idx.next.postloop, %n |
| 57 | ; CHECK: br i1 %next.postloop, label %loop.postloop, label %exit.loopexit |
| 58 | |
| 59 | !0 = !{i32 0, i32 2147483647} |
Sanjoy Das | dcf2651 | 2015-01-27 21:38:12 +0000 | [diff] [blame] | 60 | !1 = !{!"branch_weights", i32 64, i32 4} |