| 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_no_preloop_no_offset(i32 *%arr, i32 *%a_len_ptr, i32 %n) { |
| 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 | %abc = icmp slt i32 %idx, %len |
| Sanjoy Das | dcf2651 | 2015-01-27 21:38:12 +0000 | [diff] [blame] | 13 | br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1 |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 14 | |
| 15 | in.bounds: |
| David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 16 | %addr = getelementptr i32, i32* %arr, i32 %idx |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 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 | |
| Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 28 | ; CHECK-LABEL: @single_access_no_preloop_no_offset( |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 29 | |
| Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 30 | ; CHECK: loop: |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 31 | ; CHECK: br i1 true, label %in.bounds, label %out.of.bounds |
| 32 | |
| Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 33 | ; CHECK: main.exit.selector: |
| Sanjoy Das | f45e03e | 2016-08-02 19:31:54 +0000 | [diff] [blame] | 34 | ; CHECK-NEXT: %idx.next.lcssa = phi i32 [ %idx.next, %in.bounds ] |
| 35 | ; CHECK-NEXT: [[continue:%[^ ]+]] = icmp slt i32 %idx.next.lcssa, %n |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 36 | ; CHECK-NEXT: br i1 [[continue]], label %main.pseudo.exit, label %exit.loopexit |
| 37 | |
| Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 38 | ; CHECK: main.pseudo.exit: |
| Sanjoy Das | f45e03e | 2016-08-02 19:31:54 +0000 | [diff] [blame] | 39 | ; CHECK-NEXT: %idx.copy = phi i32 [ 0, %loop.preheader ], [ %idx.next.lcssa, %main.exit.selector ] |
| 40 | ; CHECK-NEXT: %indvar.end = phi i32 [ 0, %loop.preheader ], [ %idx.next.lcssa, %main.exit.selector ] |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 41 | ; CHECK-NEXT: br label %postloop |
| 42 | |
| Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 43 | ; CHECK: postloop: |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 44 | ; CHECK-NEXT: br label %loop.postloop |
| 45 | |
| Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 46 | ; CHECK: loop.postloop: |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 47 | ; CHECK-NEXT: %idx.postloop = phi i32 [ %idx.next.postloop, %in.bounds.postloop ], [ %idx.copy, %postloop ] |
| 48 | ; CHECK-NEXT: %idx.next.postloop = add i32 %idx.postloop, 1 |
| 49 | ; CHECK-NEXT: %abc.postloop = icmp slt i32 %idx.postloop, %len |
| 50 | ; CHECK-NEXT: br i1 %abc.postloop, label %in.bounds.postloop, label %out.of.bounds |
| 51 | |
| Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 52 | ; CHECK: in.bounds.postloop: |
| David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 53 | ; CHECK-NEXT: %addr.postloop = getelementptr i32, i32* %arr, i32 %idx.postloop |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 54 | ; CHECK-NEXT: store i32 0, i32* %addr.postloop |
| 55 | ; CHECK-NEXT: %next.postloop = icmp slt i32 %idx.next.postloop, %n |
| 56 | ; CHECK-NEXT: br i1 %next.postloop, label %loop.postloop, label %exit.loopexit |
| 57 | |
| 58 | |
| 59 | define void @single_access_no_preloop_with_offset(i32 *%arr, i32 *%a_len_ptr, i32 %n) { |
| 60 | entry: |
| David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 61 | %len = load i32, i32* %a_len_ptr, !range !0 |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 62 | %first.itr.check = icmp sgt i32 %n, 0 |
| 63 | br i1 %first.itr.check, label %loop, label %exit |
| 64 | |
| 65 | loop: |
| 66 | %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ] |
| 67 | %idx.next = add i32 %idx, 1 |
| 68 | %idx.for.abc = add i32 %idx, 4 |
| 69 | %abc = icmp slt i32 %idx.for.abc, %len |
| Sanjoy Das | dcf2651 | 2015-01-27 21:38:12 +0000 | [diff] [blame] | 70 | br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1 |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 71 | |
| 72 | in.bounds: |
| David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 73 | %addr = getelementptr i32, i32* %arr, i32 %idx.for.abc |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 74 | store i32 0, i32* %addr |
| 75 | %next = icmp slt i32 %idx.next, %n |
| 76 | br i1 %next, label %loop, label %exit |
| 77 | |
| 78 | out.of.bounds: |
| 79 | ret void |
| 80 | |
| 81 | exit: |
| 82 | ret void |
| 83 | } |
| 84 | |
| Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 85 | ; CHECK-LABEL: @single_access_no_preloop_with_offset( |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 86 | |
| Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 87 | ; CHECK: loop.preheader: |
| Sanjoy Das | 7fc60da | 2015-02-21 22:07:32 +0000 | [diff] [blame] | 88 | ; CHECK: [[not_n:[^ ]+]] = sub i32 -1, %n |
| 89 | ; CHECK: [[not_safe_range_end:[^ ]+]] = sub i32 3, %len |
| Sanjoy Das | e75ed92 | 2015-02-26 08:19:31 +0000 | [diff] [blame] | 90 | ; CHECK: [[not_exit_main_loop_at_hiclamp_cmp:[^ ]+]] = icmp sgt i32 [[not_n]], [[not_safe_range_end]] |
| 91 | ; CHECK: [[not_exit_main_loop_at_hiclamp:[^ ]+]] = select i1 [[not_exit_main_loop_at_hiclamp_cmp]], i32 [[not_n]], i32 [[not_safe_range_end]] |
| 92 | ; CHECK: [[exit_main_loop_at_hiclamp:[^ ]+]] = sub i32 -1, [[not_exit_main_loop_at_hiclamp]] |
| 93 | ; CHECK: [[exit_main_loop_at_loclamp_cmp:[^ ]+]] = icmp sgt i32 [[exit_main_loop_at_hiclamp]], 0 |
| 94 | ; CHECK: [[exit_main_loop_at_loclamp:[^ ]+]] = select i1 [[exit_main_loop_at_loclamp_cmp]], i32 [[exit_main_loop_at_hiclamp]], i32 0 |
| 95 | ; CHECK: [[enter_main_loop:[^ ]+]] = icmp slt i32 0, [[exit_main_loop_at_loclamp]] |
| Sanjoy Das | cf18186 | 2016-08-06 00:01:56 +0000 | [diff] [blame] | 96 | ; CHECK: br i1 [[enter_main_loop]], label %loop.preheader2, label %main.pseudo.exit |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 97 | |
| Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 98 | ; CHECK: loop: |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 99 | ; CHECK: br i1 true, label %in.bounds, label %out.of.bounds |
| 100 | |
| Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 101 | ; CHECK: in.bounds: |
| Sanjoy Das | e75ed92 | 2015-02-26 08:19:31 +0000 | [diff] [blame] | 102 | ; CHECK: [[continue_main_loop:[^ ]+]] = icmp slt i32 %idx.next, [[exit_main_loop_at_loclamp]] |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 103 | ; CHECK: br i1 [[continue_main_loop]], label %loop, label %main.exit.selector |
| 104 | |
| Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 105 | ; CHECK: main.pseudo.exit: |
| Sanjoy Das | f45e03e | 2016-08-02 19:31:54 +0000 | [diff] [blame] | 106 | ; CHECK: %idx.copy = phi i32 [ 0, %loop.preheader ], [ %idx.next.lcssa, %main.exit.selector ] |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 107 | ; CHECK: br label %postloop |
| 108 | |
| Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 109 | ; CHECK: loop.postloop: |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 110 | ; CHECK: %idx.postloop = phi i32 [ %idx.next.postloop, %in.bounds.postloop ], [ %idx.copy, %postloop ] |
| 111 | |
| Sanjoy Das | aae623f | 2016-07-22 00:41:02 +0000 | [diff] [blame] | 112 | ; CHECK: in.bounds.postloop: |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 113 | ; CHECK: %next.postloop = icmp slt i32 %idx.next.postloop, %n |
| 114 | ; CHECK: br i1 %next.postloop, label %loop.postloop, label %exit.loopexit |
| 115 | |
| Max Kazantsev | 25d8655 | 2017-10-11 06:53:07 +0000 | [diff] [blame] | 116 | ; Make sure that we do not do IRCE if we know that the safe iteration range of |
| 117 | ; the main loop is empty. |
| 118 | |
| 119 | define void @single_access_empty_range(i32 *%arr, i32 *%a_len_ptr, i32 %n) { |
| 120 | entry: |
| 121 | %len = load i32, i32* %a_len_ptr, !range !0 |
| 122 | %first.itr.check = icmp sgt i32 %n, 0 |
| 123 | br i1 %first.itr.check, label %loop, label %exit |
| 124 | |
| 125 | loop: |
| 126 | %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ] |
| 127 | %idx.next = add i32 %idx, 1 |
| 128 | %abc = icmp slt i32 %idx, 0 |
| 129 | br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1 |
| 130 | |
| 131 | in.bounds: |
| 132 | %addr = getelementptr i32, i32* %arr, i32 %idx |
| 133 | store i32 0, i32* %addr |
| 134 | %next = icmp slt i32 %idx.next, %n |
| 135 | br i1 %next, label %loop, label %exit |
| 136 | |
| 137 | out.of.bounds: |
| 138 | ret void |
| 139 | |
| 140 | exit: |
| 141 | ret void |
| 142 | } |
| 143 | |
| 144 | ; CHECK-LABEL: @single_access_empty_range( |
| 145 | ; CHECK-NOT: br i1 false |
| 146 | ; CHECK-NOT: preloop |
| 147 | ; CHECK-NOT: postloop |
| 148 | |
| 149 | define void @single_access_empty_range_2(i32 *%arr, i32 *%a_len_ptr, i32 %n) { |
| 150 | entry: |
| 151 | %len = load i32, i32* %a_len_ptr, !range !0 |
| 152 | %first.itr.check = icmp sgt i32 %n, 0 |
| 153 | br i1 %first.itr.check, label %loop, label %exit |
| 154 | |
| 155 | loop: |
| 156 | %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds2 ] |
| 157 | %idx.next = add i32 %idx, 1 |
| 158 | %abc = icmp slt i32 %idx, 60 |
| 159 | br i1 %abc, label %in.bounds1, label %out.of.bounds, !prof !1 |
| 160 | |
| 161 | in.bounds1: |
| 162 | %def = icmp slt i32 %idx, 0 |
| 163 | br i1 %def, label %in.bounds2, label %out.of.bounds, !prof !1 |
| 164 | |
| 165 | in.bounds2: |
| 166 | %addr = getelementptr i32, i32* %arr, i32 %idx |
| 167 | store i32 0, i32* %addr |
| 168 | %next = icmp slt i32 %idx.next, %n |
| 169 | br i1 %next, label %loop, label %exit |
| 170 | |
| 171 | out.of.bounds: |
| 172 | ret void |
| 173 | |
| 174 | exit: |
| 175 | ret void |
| 176 | } |
| 177 | |
| 178 | ; CHECK-LABEL: @single_access_empty_range_2( |
| 179 | ; CHECK-NOT: br i1 false |
| 180 | ; CHECK-NOT: preloop |
| 181 | |
| Sanjoy Das | a1837a3 | 2015-01-16 01:03:22 +0000 | [diff] [blame] | 182 | !0 = !{i32 0, i32 2147483647} |
| Sanjoy Das | dcf2651 | 2015-01-27 21:38:12 +0000 | [diff] [blame] | 183 | !1 = !{!"branch_weights", i32 64, i32 4} |