Sanjoy Das | 2143447 | 2016-08-14 01:04:46 +0000 | [diff] [blame] | 1 | ; RUN: opt -verify-loop-info -irce -S < %s | FileCheck %s |
Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 2 | |
| 3 | define void @single_access_with_preloop(i32 *%arr, i32 *%a_len_ptr, i32 %n, i32 %offset) { |
| 4 | entry: |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 5 | %len = load i32, i32* %a_len_ptr, !range !0 |
Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 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: |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 19 | %addr = getelementptr i32, i32* %arr, i32 %array.idx |
Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 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 | |
Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 31 | ; CHECK-LABEL: @single_access_with_preloop( |
| 32 | ; CHECK: loop.preheader: |
Max Kazantsev | 2684678 | 2017-11-20 06:07:57 +0000 | [diff] [blame] | 33 | ; CHECK: [[check_min_sint_offset:[^ ]+]] = icmp sgt i32 %offset, -2147483647 |
| 34 | ; CHECK: [[safe_offset_preloop:[^ ]+]] = select i1 [[check_min_sint_offset]], i32 %offset, i32 -2147483647 |
| 35 | ; If Offset was a SINT_MIN, we could have an overflow here. That is why we calculated its safe version. |
| 36 | ; CHECK: [[not_safe_start:[^ ]+]] = add i32 [[safe_offset_preloop]], -1 |
Sanjoy Das | 7fc60da | 2015-02-21 22:07:32 +0000 | [diff] [blame] | 37 | ; CHECK: [[not_n:[^ ]+]] = sub i32 -1, %n |
Sanjoy Das | e75ed92 | 2015-02-26 08:19:31 +0000 | [diff] [blame] | 38 | ; CHECK: [[not_exit_preloop_at_cond_loclamp:[^ ]+]] = icmp sgt i32 [[not_safe_start]], [[not_n]] |
| 39 | ; CHECK: [[not_exit_preloop_at_loclamp:[^ ]+]] = select i1 [[not_exit_preloop_at_cond_loclamp]], i32 [[not_safe_start]], i32 [[not_n]] |
| 40 | ; CHECK: [[exit_preloop_at_loclamp:[^ ]+]] = sub i32 -1, [[not_exit_preloop_at_loclamp]] |
| 41 | ; CHECK: [[exit_preloop_at_cond:[^ ]+]] = icmp sgt i32 [[exit_preloop_at_loclamp]], 0 |
| 42 | ; CHECK: [[exit_preloop_at:[^ ]+]] = select i1 [[exit_preloop_at_cond]], i32 [[exit_preloop_at_loclamp]], i32 0 |
Sanjoy Das | 7fc60da | 2015-02-21 22:07:32 +0000 | [diff] [blame] | 43 | |
Sanjoy Das | e75ed92 | 2015-02-26 08:19:31 +0000 | [diff] [blame] | 44 | |
Max Kazantsev | 2684678 | 2017-11-20 06:07:57 +0000 | [diff] [blame] | 45 | ; CHECK: [[len_minus_sint_max:[^ ]+]] = add i32 %len, -2147483647 |
| 46 | ; CHECK: [[check_len_min_sint_offset:[^ ]+]] = icmp sgt i32 %offset, [[len_minus_sint_max]] |
| 47 | ; CHECK: [[safe_offset_mainloop:[^ ]+]] = select i1 [[check_len_min_sint_offset]], i32 %offset, i32 [[len_minus_sint_max]] |
| 48 | ; CHECK: [[not_safe_start_2:[^ ]+]] = add i32 [[safe_offset_mainloop]], -1 |
| 49 | ; If Offset was a SINT_MIN, we could have an overflow here. That is why we calculated its safe version. |
Max Kazantsev | 1ac6e8a | 2017-11-17 06:49:26 +0000 | [diff] [blame] | 50 | ; CHECK: [[not_safe_upper_end:[^ ]+]] = sub i32 [[not_safe_start_2]], %len |
| 51 | ; CHECK: [[not_exit_mainloop_at_cond_loclamp:[^ ]+]] = icmp sgt i32 [[not_safe_upper_end]], [[not_n]] |
| 52 | ; CHECK: [[not_exit_mainloop_at_loclamp:[^ ]+]] = select i1 [[not_exit_mainloop_at_cond_loclamp]], i32 [[not_safe_upper_end]], i32 [[not_n]] |
Max Kazantsev | 2684678 | 2017-11-20 06:07:57 +0000 | [diff] [blame] | 53 | ; CHECK: [[check_offset_mainloop_2:[^ ]+]] = icmp sgt i32 %offset, 0 |
| 54 | ; CHECK: [[safe_offset_mainloop_2:[^ ]+]] = select i1 [[check_offset_mainloop_2]], i32 %offset, i32 0 |
| 55 | ; CHECK: [[not_safe_lower_end:[^ ]+]] = add i32 [[safe_offset_mainloop_2]], -2147483648 |
Max Kazantsev | 1ac6e8a | 2017-11-17 06:49:26 +0000 | [diff] [blame] | 56 | ; CHECK: [[not_exit_mainloop_at_cond_hiclamp:[^ ]+]] = icmp sgt i32 [[not_exit_mainloop_at_loclamp]], [[not_safe_lower_end]] |
| 57 | ; 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]] |
| 58 | ; CHECK: [[exit_mainloop_at_hiclamp:[^ ]+]] = sub i32 -1, [[not_exit_mainloop_at_hiclamp]] |
| 59 | ; CHECK: [[exit_mainloop_at_cmp:[^ ]+]] = icmp sgt i32 [[exit_mainloop_at_hiclamp]], 0 |
| 60 | ; CHECK: [[exit_mainloop_at:[^ ]+]] = select i1 [[exit_mainloop_at_cmp]], i32 [[exit_mainloop_at_hiclamp]], i32 0 |
Sanjoy Das | e75ed92 | 2015-02-26 08:19:31 +0000 | [diff] [blame] | 61 | |
Max Kazantsev | 1ac6e8a | 2017-11-17 06:49:26 +0000 | [diff] [blame] | 62 | ; CHECK: mainloop: |
| 63 | ; CHECK: br label %loop |
| 64 | |
| 65 | ; CHECK: loop: |
| 66 | ; CHECK: %abc.high = icmp slt i32 %array.idx, %len |
| 67 | ; CHECK: %abc.low = icmp sge i32 %array.idx, 0 |
| 68 | ; CHECK: %abc = and i1 true, true |
Max Kazantsev | 2684678 | 2017-11-20 06:07:57 +0000 | [diff] [blame] | 69 | ; CHECK: br i1 %abc, label %in.bounds, label %out.of.bounds.loopexit11 |
Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 70 | |
Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 71 | ; CHECK: in.bounds: |
Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 72 | ; CHECK: [[continue_mainloop_cond:[^ ]+]] = icmp slt i32 %idx.next, [[exit_mainloop_at]] |
| 73 | ; CHECK: br i1 [[continue_mainloop_cond]], label %loop, label %main.exit.selector |
| 74 | |
Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 75 | ; CHECK: main.exit.selector: |
Sanjoy Das | f45e03e | 2016-08-02 19:31:54 +0000 | [diff] [blame] | 76 | ; CHECK: [[mainloop_its_left:[^ ]+]] = icmp slt i32 %idx.next.lcssa, %n |
Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 77 | ; CHECK: br i1 [[mainloop_its_left]], label %main.pseudo.exit, label %exit.loopexit |
| 78 | |
Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 79 | ; CHECK: in.bounds.preloop: |
Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 80 | ; CHECK: [[continue_preloop_cond:[^ ]+]] = icmp slt i32 %idx.next.preloop, [[exit_preloop_at]] |
| 81 | ; CHECK: br i1 [[continue_preloop_cond]], label %loop.preloop, label %preloop.exit.selector |
| 82 | |
Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 83 | ; CHECK: preloop.exit.selector: |
Sanjoy Das | 2143447 | 2016-08-14 01:04:46 +0000 | [diff] [blame] | 84 | ; CHECK: [[preloop_its_left:[^ ]+]] = icmp slt i32 %idx.next.preloop.lcssa, %n |
Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 85 | ; CHECK: br i1 [[preloop_its_left]], label %preloop.pseudo.exit, label %exit.loopexit |
| 86 | |
Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 87 | ; CHECK: in.bounds.postloop: |
Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 88 | ; CHECK: %next.postloop = icmp slt i32 %idx.next.postloop, %n |
| 89 | ; CHECK: br i1 %next.postloop, label %loop.postloop, label %exit.loopexit |
| 90 | |
| 91 | !0 = !{i32 0, i32 2147483647} |
Sanjoy Das | dcf2651 | 2015-01-27 21:38:12 +0000 | [diff] [blame] | 92 | !1 = !{!"branch_weights", i32 64, i32 4} |