Max Kazantsev | 9ac7021 | 2017-10-25 06:47:39 +0000 | [diff] [blame] | 1 | ; RUN: opt -verify-loop-info -irce-print-changed-loops -irce -S < %s 2>&1 | FileCheck %s |
Max Kazantsev | 2c627a9 | 2017-07-18 04:53:48 +0000 | [diff] [blame] | 2 | |
| 3 | ; CHECK: irce: in function test_01: constrained Loop at depth 1 containing: %loop<header><exiting>,%in.bounds<latch><exiting> |
Max Kazantsev | 07da1ab | 2017-08-04 05:40:20 +0000 | [diff] [blame] | 4 | ; CHECK: irce: in function test_01u: constrained Loop at depth 1 containing: %loop<header><exiting>,%in.bounds<latch><exiting> |
Max Kazantsev | 2c627a9 | 2017-07-18 04:53:48 +0000 | [diff] [blame] | 5 | ; CHECK-NOT: irce: in function test_02: constrained Loop at depth 1 containing: %loop<header><exiting>,%in.bounds<latch><exiting> |
| 6 | ; CHECK: irce: in function test_03: constrained Loop at depth 1 containing: %loop<header><exiting>,%in.bounds<latch><exiting> |
| 7 | ; CHECK-NOT: irce: in function test_04: constrained Loop at depth 1 containing: %loop<header><exiting>,%in.bounds<latch><exiting> |
| 8 | ; CHECK: irce: in function test_05: constrained Loop at depth 1 containing: %loop<header><exiting>,%in.bounds<latch><exiting> |
| 9 | ; CHECK-NOT: irce: in function test_06: constrained Loop at depth 1 containing: %loop<header><exiting>,%in.bounds<latch><exiting> |
| 10 | ; CHECK: irce: in function test_07: constrained Loop at depth 1 containing: %loop<header><exiting>,%in.bounds<latch><exiting> |
| 11 | ; CHECK-NOT: irce: in function test_08: constrained Loop at depth 1 containing: %loop<header><exiting>,%in.bounds<latch><exiting> |
| 12 | |
Max Kazantsev | 07da1ab | 2017-08-04 05:40:20 +0000 | [diff] [blame] | 13 | ; Show that IRCE can turn 'ne' condition to 'slt' in increasing IV when the IV |
| 14 | ; can be negative at some point. |
Max Kazantsev | 2c627a9 | 2017-07-18 04:53:48 +0000 | [diff] [blame] | 15 | define void @test_01(i32* %arr, i32* %a_len_ptr) #0 { |
| 16 | |
| 17 | ; CHECK: test_01 |
| 18 | ; CHECK: main.exit.selector: |
| 19 | ; CHECK-NEXT: [[PSEUDO_PHI:%[^ ]+]] = phi i32 [ %idx.next, %in.bounds ] |
| 20 | ; CHECK-NEXT: [[COND:%[^ ]+]] = icmp slt i32 [[PSEUDO_PHI]], 100 |
| 21 | ; CHECK-NEXT: br i1 [[COND]] |
| 22 | |
| 23 | entry: |
| 24 | %len = load i32, i32* %a_len_ptr, !range !0 |
| 25 | br label %loop |
| 26 | |
| 27 | loop: |
Max Kazantsev | 07da1ab | 2017-08-04 05:40:20 +0000 | [diff] [blame] | 28 | %idx = phi i32 [ -3, %entry ], [ %idx.next, %in.bounds ] |
| 29 | %idx.next = add i32 %idx, 1 |
| 30 | %abc = icmp slt i32 %idx, %len |
| 31 | br i1 %abc, label %in.bounds, label %out.of.bounds |
| 32 | |
| 33 | in.bounds: |
| 34 | %addr = getelementptr i32, i32* %arr, i32 %idx |
| 35 | store i32 0, i32* %addr |
| 36 | %next = icmp ne i32 %idx.next, 100 |
| 37 | br i1 %next, label %loop, label %exit |
| 38 | |
| 39 | out.of.bounds: |
| 40 | ret void |
| 41 | |
| 42 | exit: |
| 43 | ret void |
| 44 | } |
| 45 | |
| 46 | ; Show that IRCE can turn 'ne' condition to 'ult' in increasing IV when IV is |
| 47 | ; non-negative. |
| 48 | define void @test_01u(i32* %arr, i32* %a_len_ptr) #0 { |
| 49 | |
| 50 | ; CHECK: test_01u |
| 51 | ; CHECK: main.exit.selector: |
| 52 | ; CHECK-NEXT: [[PSEUDO_PHI:%[^ ]+]] = phi i32 [ %idx.next, %in.bounds ] |
| 53 | ; CHECK-NEXT: [[COND:%[^ ]+]] = icmp ult i32 [[PSEUDO_PHI]], 100 |
| 54 | ; CHECK-NEXT: br i1 [[COND]] |
| 55 | |
| 56 | entry: |
| 57 | %len = load i32, i32* %a_len_ptr, !range !0 |
| 58 | br label %loop |
| 59 | |
| 60 | loop: |
Max Kazantsev | 2c627a9 | 2017-07-18 04:53:48 +0000 | [diff] [blame] | 61 | %idx = phi i32 [ 0, %entry ], [ %idx.next, %in.bounds ] |
| 62 | %idx.next = add i32 %idx, 1 |
| 63 | %abc = icmp slt i32 %idx, %len |
Max Kazantsev | d18b019 | 2017-08-01 10:13:29 +0000 | [diff] [blame] | 64 | br i1 %abc, label %in.bounds, label %out.of.bounds |
Max Kazantsev | 2c627a9 | 2017-07-18 04:53:48 +0000 | [diff] [blame] | 65 | |
| 66 | in.bounds: |
| 67 | %addr = getelementptr i32, i32* %arr, i32 %idx |
| 68 | store i32 0, i32* %addr |
| 69 | %next = icmp ne i32 %idx.next, 100 |
| 70 | br i1 %next, label %loop, label %exit |
| 71 | |
| 72 | out.of.bounds: |
| 73 | ret void |
| 74 | |
| 75 | exit: |
| 76 | ret void |
| 77 | } |
| 78 | |
| 79 | ; Show that if n is not known to be greater than the starting value, IRCE |
| 80 | ; doesn't apply. |
| 81 | define void @test_02(i32* %arr, i32* %a_len_ptr) #0 { |
| 82 | |
| 83 | ; CHECK: test_02( |
| 84 | |
| 85 | entry: |
| 86 | %len = load i32, i32* %a_len_ptr, !range !0 |
| 87 | br label %loop |
| 88 | |
| 89 | loop: |
| 90 | %idx = phi i32 [ 0, %entry ], [ %idx.next, %in.bounds ] |
| 91 | %idx.next = add i32 %idx, 1 |
| 92 | %abc = icmp slt i32 %idx, %len |
Max Kazantsev | d18b019 | 2017-08-01 10:13:29 +0000 | [diff] [blame] | 93 | br i1 %abc, label %in.bounds, label %out.of.bounds |
Max Kazantsev | 2c627a9 | 2017-07-18 04:53:48 +0000 | [diff] [blame] | 94 | |
| 95 | in.bounds: |
| 96 | %addr = getelementptr i32, i32* %arr, i32 %idx |
| 97 | store i32 0, i32* %addr |
| 98 | %next = icmp ne i32 %idx.next, -100 |
| 99 | br i1 %next, label %loop, label %exit |
| 100 | |
| 101 | out.of.bounds: |
| 102 | ret void |
| 103 | |
| 104 | exit: |
| 105 | ret void |
| 106 | } |
| 107 | |
| 108 | ; Show that IRCE can turn 'eq' condition to 'sge' in increasing IV. |
| 109 | define void @test_03(i32* %arr, i32* %a_len_ptr) #0 { |
| 110 | |
| 111 | ; CHECK: test_03( |
| 112 | ; CHECK: main.exit.selector: |
| 113 | ; CHECK-NEXT: [[PSEUDO_PHI:%[^ ]+]] = phi i32 [ %idx.next, %in.bounds ] |
| 114 | ; CHECK-NEXT: [[COND:%[^ ]+]] = icmp slt i32 [[PSEUDO_PHI]], 100 |
| 115 | ; CHECK-NEXT: br i1 [[COND]] |
| 116 | |
| 117 | entry: |
| 118 | %len = load i32, i32* %a_len_ptr, !range !0 |
| 119 | br label %loop |
| 120 | |
| 121 | loop: |
| 122 | %idx = phi i32 [ 0, %entry ], [ %idx.next, %in.bounds ] |
| 123 | %idx.next = add i32 %idx, 1 |
| 124 | %abc = icmp slt i32 %idx, %len |
Max Kazantsev | d18b019 | 2017-08-01 10:13:29 +0000 | [diff] [blame] | 125 | br i1 %abc, label %in.bounds, label %out.of.bounds |
Max Kazantsev | 2c627a9 | 2017-07-18 04:53:48 +0000 | [diff] [blame] | 126 | |
| 127 | in.bounds: |
| 128 | %addr = getelementptr i32, i32* %arr, i32 %idx |
| 129 | store i32 0, i32* %addr |
| 130 | %next = icmp eq i32 %idx.next, 100 |
| 131 | br i1 %next, label %exit, label %loop |
| 132 | |
| 133 | out.of.bounds: |
| 134 | ret void |
| 135 | |
| 136 | exit: |
| 137 | ret void |
| 138 | } |
| 139 | |
| 140 | ; Show that if n is not known to be greater than the starting value, IRCE |
| 141 | ; doesn't apply. |
| 142 | define void @test_04(i32* %arr, i32* %a_len_ptr) #0 { |
| 143 | |
| 144 | ; CHECK: test_04( |
| 145 | |
| 146 | entry: |
| 147 | %len = load i32, i32* %a_len_ptr, !range !0 |
| 148 | br label %loop |
| 149 | |
| 150 | loop: |
| 151 | %idx = phi i32 [ 0, %entry ], [ %idx.next, %in.bounds ] |
| 152 | %idx.next = add i32 %idx, 1 |
| 153 | %abc = icmp slt i32 %idx, %len |
Max Kazantsev | d18b019 | 2017-08-01 10:13:29 +0000 | [diff] [blame] | 154 | br i1 %abc, label %in.bounds, label %out.of.bounds |
Max Kazantsev | 2c627a9 | 2017-07-18 04:53:48 +0000 | [diff] [blame] | 155 | |
| 156 | in.bounds: |
| 157 | %addr = getelementptr i32, i32* %arr, i32 %idx |
| 158 | store i32 0, i32* %addr |
| 159 | %next = icmp eq i32 %idx.next, -100 |
| 160 | br i1 %next, label %exit, label %loop |
| 161 | |
| 162 | out.of.bounds: |
| 163 | ret void |
| 164 | |
| 165 | exit: |
| 166 | ret void |
| 167 | } |
| 168 | |
| 169 | ; Show that IRCE can turn 'ne' condition to 'sgt' in decreasing IV. |
| 170 | define void @test_05(i32* %arr, i32* %a_len_ptr) #0 { |
| 171 | |
| 172 | ; CHECK: test_05( |
| 173 | ; CHECK: preloop.exit.selector: |
| 174 | ; CHECK-NEXT: [[PSEUDO_PHI:%[^ ]+]] = phi i32 [ %idx.next.preloop, %in.bounds.preloop ] |
| 175 | ; CHECK-NEXT: [[COND:%[^ ]+]] = icmp sgt i32 [[PSEUDO_PHI]], 0 |
| 176 | ; CHECK-NEXT: br i1 [[COND]] |
| 177 | |
| 178 | entry: |
| 179 | %len = load i32, i32* %a_len_ptr, !range !0 |
| 180 | br label %loop |
| 181 | |
| 182 | loop: |
| 183 | %idx = phi i32 [ 100, %entry ], [ %idx.next, %in.bounds ] |
| 184 | %idx.next = add i32 %idx, -1 |
| 185 | %abc = icmp slt i32 %idx, %len |
Max Kazantsev | d18b019 | 2017-08-01 10:13:29 +0000 | [diff] [blame] | 186 | br i1 %abc, label %in.bounds, label %out.of.bounds |
Max Kazantsev | 2c627a9 | 2017-07-18 04:53:48 +0000 | [diff] [blame] | 187 | |
| 188 | in.bounds: |
| 189 | %addr = getelementptr i32, i32* %arr, i32 %idx |
| 190 | store i32 0, i32* %addr |
| 191 | %next = icmp ne i32 %idx.next, 0 |
| 192 | br i1 %next, label %loop, label %exit |
| 193 | |
| 194 | out.of.bounds: |
| 195 | ret void |
| 196 | |
| 197 | exit: |
| 198 | ret void |
| 199 | } |
| 200 | |
| 201 | ; Show that IRCE cannot turn 'ne' condition to 'sgt' in decreasing IV if the end |
| 202 | ; value is not proved to be less than the start value. |
| 203 | define void @test_06(i32* %arr, i32* %a_len_ptr) #0 { |
| 204 | |
| 205 | ; CHECK: test_06( |
| 206 | |
| 207 | entry: |
| 208 | %len = load i32, i32* %a_len_ptr, !range !0 |
| 209 | br label %loop |
| 210 | |
| 211 | loop: |
| 212 | %idx = phi i32 [ 100, %entry ], [ %idx.next, %in.bounds ] |
| 213 | %idx.next = add i32 %idx, -1 |
| 214 | %abc = icmp slt i32 %idx, %len |
Max Kazantsev | d18b019 | 2017-08-01 10:13:29 +0000 | [diff] [blame] | 215 | br i1 %abc, label %in.bounds, label %out.of.bounds |
Max Kazantsev | 2c627a9 | 2017-07-18 04:53:48 +0000 | [diff] [blame] | 216 | |
| 217 | in.bounds: |
| 218 | %addr = getelementptr i32, i32* %arr, i32 %idx |
| 219 | store i32 0, i32* %addr |
| 220 | %next = icmp ne i32 %idx.next, 120 |
| 221 | br i1 %next, label %loop, label %exit |
| 222 | |
| 223 | out.of.bounds: |
| 224 | ret void |
| 225 | |
| 226 | exit: |
| 227 | ret void |
| 228 | } |
| 229 | |
| 230 | ; Show that IRCE can turn 'eq' condition to 'slt' in decreasing IV. |
| 231 | define void @test_07(i32* %arr, i32* %a_len_ptr) #0 { |
| 232 | |
| 233 | ; CHECK: test_07( |
| 234 | ; CHECK: preloop.exit.selector: |
| 235 | ; CHECK-NEXT: [[PSEUDO_PHI:%[^ ]+]] = phi i32 [ %idx.next.preloop, %in.bounds.preloop ] |
| 236 | ; CHECK-NEXT: [[COND:%[^ ]+]] = icmp sgt i32 [[PSEUDO_PHI]], 0 |
| 237 | ; CHECK-NEXT: br i1 [[COND]] |
| 238 | |
| 239 | entry: |
| 240 | %len = load i32, i32* %a_len_ptr, !range !0 |
| 241 | br label %loop |
| 242 | |
| 243 | loop: |
| 244 | %idx = phi i32 [ 100, %entry ], [ %idx.next, %in.bounds ] |
| 245 | %idx.next = add i32 %idx, -1 |
| 246 | %abc = icmp slt i32 %idx, %len |
Max Kazantsev | d18b019 | 2017-08-01 10:13:29 +0000 | [diff] [blame] | 247 | br i1 %abc, label %in.bounds, label %out.of.bounds |
Max Kazantsev | 2c627a9 | 2017-07-18 04:53:48 +0000 | [diff] [blame] | 248 | |
| 249 | in.bounds: |
| 250 | %addr = getelementptr i32, i32* %arr, i32 %idx |
| 251 | store i32 0, i32* %addr |
| 252 | %next = icmp eq i32 %idx.next, 0 |
| 253 | br i1 %next, label %exit, label %loop |
| 254 | |
| 255 | out.of.bounds: |
| 256 | ret void |
| 257 | |
| 258 | exit: |
| 259 | ret void |
| 260 | } |
| 261 | |
| 262 | ; Show that IRCE cannot turn 'eq' condition to 'slt' in decreasing IV if the end |
| 263 | ; value is not proved to be less than the start value. |
| 264 | define void @test_08(i32* %arr, i32* %a_len_ptr) #0 { |
| 265 | |
| 266 | ; CHECK: test_08( |
| 267 | |
| 268 | entry: |
| 269 | %len = load i32, i32* %a_len_ptr, !range !0 |
| 270 | br label %loop |
| 271 | |
| 272 | loop: |
| 273 | %idx = phi i32 [ 100, %entry ], [ %idx.next, %in.bounds ] |
| 274 | %idx.next = add i32 %idx, -1 |
| 275 | %abc = icmp slt i32 %idx, %len |
Max Kazantsev | d18b019 | 2017-08-01 10:13:29 +0000 | [diff] [blame] | 276 | br i1 %abc, label %in.bounds, label %out.of.bounds |
Max Kazantsev | 2c627a9 | 2017-07-18 04:53:48 +0000 | [diff] [blame] | 277 | |
| 278 | in.bounds: |
| 279 | %addr = getelementptr i32, i32* %arr, i32 %idx |
| 280 | store i32 0, i32* %addr |
| 281 | %next = icmp eq i32 %idx.next, 120 |
| 282 | br i1 %next, label %exit, label %loop |
| 283 | |
| 284 | out.of.bounds: |
| 285 | ret void |
| 286 | |
| 287 | exit: |
| 288 | ret void |
| 289 | } |
| 290 | |
| 291 | !0 = !{i32 0, i32 50} |