1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
|
; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" -scalar-evolution-max-iterations=0 -scalar-evolution-classify-expressions=0 2>&1 | FileCheck %s
define void @slt(i16 %a, i16 %b, i1 %c) {
; CHECK-LABEL: 'slt'
; CHECK-NEXT: Determining loop execution counts for: @slt
; CHECK-NEXT: Loop %loop: backedge-taken count is (19 + (-1 * %count)<nsw>)<nsw>
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i16 18
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (19 + (-1 * %count)<nsw>)<nsw>
; CHECK-NEXT: Loop %loop: Trip multiple is 1
entry:
br i1 %c, label %b1, label %b2
b1:
%cmp1 = icmp slt i16 %a, 1
br i1 %cmp1, label %exit, label %preheader
b2:
%cmp2 = icmp slt i16 %b, 4
br i1 %cmp2, label %exit, label %preheader
preheader:
%count = phi i16 [ %a, %b1 ], [ %b, %b2 ]
%cmp3 = icmp sle i16 %count, 19
br i1 %cmp3, label %loop, label %exit
loop:
%iv = phi i16 [ %iv.next, %loop ], [ %count, %preheader ]
%iv.next = add i16 %iv, 1
%exitcond = icmp eq i16 %iv.next, 20
br i1 %exitcond, label %exit, label %loop
exit:
ret void
}
define void @ult(i16 %a, i16 %b, i1 %c) {
; CHECK-LABEL: 'ult'
; CHECK-NEXT: Determining loop execution counts for: @ult
; CHECK-NEXT: Loop %loop: backedge-taken count is (21 + (-1 * %count))
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i16 19
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (21 + (-1 * %count))
; CHECK-NEXT: Loop %loop: Trip multiple is 1
entry:
br i1 %c, label %b1, label %b2
b1:
%cmp1 = icmp ult i16 %a, 2
br i1 %cmp1, label %exit, label %preheader
b2:
%cmp2 = icmp ult i16 %b, 5
br i1 %cmp2, label %exit, label %preheader
preheader:
%count = phi i16 [ %a, %b1 ], [ %b, %b2 ]
%cmp3 = icmp ule i16 %count, 20
br i1 %cmp3, label %loop, label %exit
loop:
%iv = phi i16 [ %iv.next, %loop ], [ %count, %preheader ]
%iv.next = add i16 %iv, 1
%exitcond = icmp eq i16 %iv.next, 22
br i1 %exitcond, label %exit, label %loop
exit:
ret void
}
define void @sgt(i16 %a, i16 %b, i1 %c) {
; CHECK-LABEL: 'sgt'
; CHECK-NEXT: Determining loop execution counts for: @sgt
; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + %count)
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i16 9
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (-1 + %count)
; CHECK-NEXT: Loop %loop: Trip multiple is 1
entry:
br i1 %c, label %b1, label %b2
b1:
%cmp1 = icmp sgt i16 %a, 10
br i1 %cmp1, label %exit, label %preheader
b2:
%cmp2 = icmp sgt i16 %b, 8
br i1 %cmp2, label %exit, label %preheader
preheader:
%count = phi i16 [ %a, %b1 ], [ %b, %b2 ]
%cmp3 = icmp sge i16 %count, 1
br i1 %cmp3, label %loop, label %exit
loop:
%iv = phi i16 [ %iv.next, %loop ], [ %count, %preheader ]
%iv.next = add i16 %iv, -1
%exitcond = icmp eq i16 %iv.next, 0
br i1 %exitcond, label %exit, label %loop
exit:
ret void
}
define void @ugt(i16 %a, i16 %b, i1 %c) {
; CHECK-LABEL: 'ugt'
; CHECK-NEXT: Determining loop execution counts for: @ugt
; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + %count)<nsw>
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i16 10
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (-1 + %count)<nsw>
; CHECK-NEXT: Loop %loop: Trip multiple is 1
entry:
br i1 %c, label %b1, label %b2
b1:
%cmp1 = icmp ugt i16 %a, 11
br i1 %cmp1, label %exit, label %preheader
b2:
%cmp2 = icmp ugt i16 %b, 7
br i1 %cmp2, label %exit, label %preheader
preheader:
%count = phi i16 [ %a, %b1 ], [ %b, %b2 ]
%cmp3 = icmp ne i16 %count, 0
br i1 %cmp3, label %loop, label %exit
loop:
%iv = phi i16 [ %iv.next, %loop ], [ %count, %preheader ]
%iv.next = add i16 %iv, -1
%exitcond = icmp eq i16 %iv.next, 0
br i1 %exitcond, label %exit, label %loop
exit:
ret void
}
define void @three_incoming(i16 %a, i16 %b, i1 %c, i1 %d) {
; CHECK-LABEL: 'three_incoming'
; CHECK-NEXT: Determining loop execution counts for: @three_incoming
; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + %count)<nsw>
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i16 11
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (-1 + %count)<nsw>
; CHECK-NEXT: Loop %loop: Trip multiple is 1
entry:
br i1 %c, label %b1, label %entry2
entry2:
br i1 %d, label %b2, label %b3
b1:
%cmp1 = icmp ugt i16 %a, 10
br i1 %cmp1, label %exit, label %preheader
b2:
%cmp2 = icmp ugt i16 %b, 8
br i1 %cmp2, label %exit, label %preheader
b3:
%cmp3 = icmp ugt i16 %b, 12
br i1 %cmp3, label %exit, label %preheader
preheader:
%count = phi i16 [ %a, %b1 ], [ %b, %b2 ], [ %b, %b3 ]
%cmp4 = icmp ne i16 %count, 0
br i1 %cmp4, label %loop, label %exit
loop:
%iv = phi i16 [ %iv.next, %loop ], [ %count, %preheader ]
%iv.next = add i16 %iv, -1
%exitcond = icmp eq i16 %iv.next, 0
br i1 %exitcond, label %exit, label %loop
exit:
ret void
}
define void @mixed(i16 %a, i16 %b, i1 %c) {
; CHECK-LABEL: 'mixed'
; CHECK-NEXT: Determining loop execution counts for: @mixed
; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + %count)
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i16 -2
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (-1 + %count)
; CHECK-NEXT: Loop %loop: Trip multiple is 1
entry:
br i1 %c, label %b1, label %b2
b1:
%cmp1 = icmp ugt i16 %a, 10
br i1 %cmp1, label %exit, label %preheader
b2:
%cmp2 = icmp sgt i16 %b, 8
br i1 %cmp2, label %exit, label %preheader
preheader:
%count = phi i16 [ %a, %b1 ], [ %b, %b2 ]
%cmp3 = icmp ne i16 %count, 0
br i1 %cmp3, label %loop, label %exit
loop:
%iv = phi i16 [ %iv.next, %loop ], [ %count, %preheader ]
%iv.next = add i16 %iv, -1
%exitcond = icmp eq i16 %iv.next, 0
br i1 %exitcond, label %exit, label %loop
exit:
ret void
}
define void @one_constant(i16 %a, i16 %b, i1 %c, i16 %d) {
; CHECK-LABEL: 'one_constant'
; CHECK-NEXT: Determining loop execution counts for: @one_constant
; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + %count)
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i16 -2
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (-1 + %count)
; CHECK-NEXT: Loop %loop: Trip multiple is 1
entry:
br i1 %c, label %b1, label %b2
b1:
%cmp1 = icmp ugt i16 %a, 10
br i1 %cmp1, label %exit, label %preheader
b2:
%cmp2 = icmp ugt i16 %b, %d
br i1 %cmp2, label %exit, label %preheader
preheader:
%count = phi i16 [ %a, %b1 ], [ %b, %b2 ]
%cmp3 = icmp ne i16 %count, 0
br i1 %cmp3, label %loop, label %exit
loop:
%iv = phi i16 [ %iv.next, %loop ], [ %count, %preheader ]
%iv.next = add i16 %iv, -1
%exitcond = icmp eq i16 %iv.next, 0
br i1 %exitcond, label %exit, label %loop
exit:
ret void
}
define void @epilogue(i64 %count) {
; CHECK-LABEL: 'epilogue'
; CHECK-NEXT: Determining loop execution counts for: @epilogue
; CHECK-NEXT: Loop %epilogue: backedge-taken count is (-1 + %count.epilogue)
; CHECK-NEXT: Loop %epilogue: constant max backedge-taken count is i64 6
; CHECK-NEXT: Loop %epilogue: symbolic max backedge-taken count is (-1 + %count.epilogue)
; CHECK-NEXT: Loop %epilogue: Trip multiple is 1
; CHECK-NEXT: Loop %while.body: backedge-taken count is ((-8 + %count) /u 8)
; CHECK-NEXT: Loop %while.body: constant max backedge-taken count is i64 2305843009213693951
; CHECK-NEXT: Loop %while.body: symbolic max backedge-taken count is ((-8 + %count) /u 8)
; CHECK-NEXT: Loop %while.body: Trip multiple is 1
entry:
%cmp = icmp ugt i64 %count, 7
br i1 %cmp, label %while.body, label %epilogue.preheader
while.body:
%iv = phi i64 [ %sub, %while.body ], [ %count, %entry ]
%sub = add i64 %iv, -8
%exitcond.not = icmp ugt i64 %sub, 7
br i1 %exitcond.not, label %while.body, label %while.loopexit
while.loopexit:
%sub.exit = phi i64 [ %sub, %while.body ]
br label %epilogue.preheader
epilogue.preheader:
%count.epilogue = phi i64 [ %count, %entry ], [ %sub.exit, %while.loopexit ]
%epilogue.cmp = icmp eq i64 %count.epilogue, 0
br i1 %epilogue.cmp, label %exit, label %epilogue
epilogue:
%iv.epilogue = phi i64 [ %dec, %epilogue ], [ %count.epilogue, %epilogue.preheader ]
%dec = add i64 %iv.epilogue, -1
%exitcond.epilogue = icmp eq i64 %dec, 0
br i1 %exitcond.epilogue, label %exit, label %epilogue
exit:
ret void
}
declare void @llvm.assume(i1)
; Checks that the presence of assumptions does not interfere with
; exiting loop guard collection via following loop predecessors.
define void @pr120442(i1 %c.1, i1 %c.2) {
; CHECK-LABEL: 'pr120442'
; CHECK-NEXT: Determining loop execution counts for: @pr120442
; CHECK-NEXT: Loop %inner.header: backedge-taken count is i32 0
; CHECK-NEXT: Loop %inner.header: constant max backedge-taken count is i32 0
; CHECK-NEXT: Loop %inner.header: symbolic max backedge-taken count is i32 0
; CHECK-NEXT: Loop %inner.header: Trip multiple is 1
entry:
call void @llvm.assume(i1 %c.1)
call void @llvm.assume(i1 %c.2)
br label %outer.header
outer.header:
%phi7 = phi i32 [ 0, %bb ], [ 0, %entry ]
br label %inner.header
bb:
br i1 false, label %outer.header, label %bb
inner.header:
%phi = phi i32 [ %add, %inner.header ], [ 0, %outer.header ]
%add = add i32 %phi, 1
%icmp = icmp ugt i32 %add, 0
br i1 %icmp, label %exit, label %inner.header
exit:
ret void
}
; Checks correct traversal for loops without a unique predecessor
; outside the loop.
define void @pr120615() {
; CHECK-LABEL: pr120615
; CHECK-NEXT: Determining loop execution counts for: @pr120615
; CHECK-NEXT: Loop %header: backedge-taken count is i32 0
; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 0
; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is i32 0
; CHECK-NEXT: Loop %header: Trip multiple is 1
entry:
br label %header
bb:
br label %header
header:
%0 = phi i32 [ %1, %header ], [ 0, %bb ], [ 0, %entry ]
%1 = add i32 %0, 1
%icmp = icmp slt i32 %0, 0
br i1 %icmp, label %header, label %exit
exit:
ret void
}
; Checks correct traversal for loops without a unique predecessor
; outside the loop.
define void @pr122913() {
; CHECK-LABEL: pr122913
; CHECK-NEXT: Determining loop execution counts for: @pr122913
; CHECK-NEXT: Loop %header: backedge-taken count is i1 false
; CHECK-NEXT: Loop %header: constant max backedge-taken count is i1 false
; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is i1 false
; CHECK-NEXT: Loop %header: Trip multiple is 1
entry:
br i1 1, label %bb, label %header
bb:
br i1 1, label %exit, label %header
header:
%0 = phi i32 [ %1, %body ], [ 0, %bb ], [ 0, %entry ]
br label %body
body:
%1 = add i32 %0, 1
%2 = icmp ult i32 %1, 0
br i1 %2, label %header, label %exit
exit:
ret void
}
|