llvm.org GIT mirror llvm / release_60 test / Transforms / CorrelatedValuePropagation / range.ll
release_60

Tree @release_60 (Download .tar.gz)

range.ll @release_60raw · history · blame

  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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
; RUN: opt -correlated-propagation -S < %s | FileCheck %s

declare i32 @foo()

define i32 @test1(i32 %a) nounwind {
  %a.off = add i32 %a, -8
  %cmp = icmp ult i32 %a.off, 8
  br i1 %cmp, label %then, label %else

then:
  %dead = icmp eq i32 %a, 7
  br i1 %dead, label %end, label %else

else:
  ret i32 1

end:
  ret i32 2

; CHECK-LABEL: @test1(
; CHECK: then:
; CHECK-NEXT: br i1 false, label %end, label %else
}

define i32 @test2(i32 %a) nounwind {
  %a.off = add i32 %a, -8
  %cmp = icmp ult i32 %a.off, 8
  br i1 %cmp, label %then, label %else

then:
  %dead = icmp ugt i32 %a, 15
  br i1 %dead, label %end, label %else

else:
  ret i32 1

end:
  ret i32 2

; CHECK-LABEL: @test2(
; CHECK: then:
; CHECK-NEXT: br i1 false, label %end, label %else
}

; CHECK-LABEL: @test3(
define i32 @test3(i32 %c) nounwind {
  %cmp = icmp slt i32 %c, 2
  br i1 %cmp, label %if.then, label %if.end

if.then:
  ret i32 1

if.end:
  %cmp1 = icmp slt i32 %c, 3
  br i1 %cmp1, label %if.then2, label %if.end8

; CHECK: if.then2
if.then2:
  %cmp2 = icmp eq i32 %c, 2
; CHECK: br i1 true
  br i1 %cmp2, label %if.then4, label %if.end6

; CHECK: if.end6
if.end6:
  ret i32 2

if.then4:
  ret i32 3

if.end8:
  ret i32 4
}

; CHECK-LABEL: @test4(
define i32 @test4(i32 %c) nounwind {
  switch i32 %c, label %sw.default [
    i32 1, label %sw.bb
    i32 2, label %sw.bb
    i32 4, label %sw.bb
  ]

; CHECK: sw.bb
sw.bb:
  %cmp = icmp sge i32 %c, 1
; CHECK: br i1 true
  br i1 %cmp, label %if.then, label %if.end

if.then:
  br label %return

if.end:
  br label %return

sw.default:
  br label %return

return:
  %retval.0 = phi i32 [ 42, %sw.default ], [ 4, %if.then ], [ 9, %if.end ]
  ret i32 %retval.0
}

; CHECK-LABEL: @test5(
define i1 @test5(i32 %c) nounwind {
  %cmp = icmp slt i32 %c, 5
  br i1 %cmp, label %if.then, label %if.end

if.then:
  %cmp1 = icmp eq i32 %c, 4
  br i1 %cmp1, label %if.end, label %if.end8

if.end:
  ret i1 true

if.end8:
  %cmp2 = icmp eq i32 %c, 3
  %cmp3 = icmp eq i32 %c, 4
  %cmp4 = icmp eq i32 %c, 6
; CHECK: %or = or i1 false, false
  %or = or i1 %cmp3, %cmp4
; CHECK: ret i1 %cmp2
  ret i1 %cmp2
}

; CHECK-LABEL: @test6(
define i1 @test6(i32 %c) nounwind {
  %cmp = icmp ule i32 %c, 7
  br i1 %cmp, label %if.then, label %if.end

if.then:
; CHECK: icmp eq i32 %c, 6
; CHECK: br i1
  switch i32 %c, label %if.end [
    i32 6, label %sw.bb
    i32 8, label %sw.bb
  ]

if.end:
  ret i1 true

sw.bb:
  %cmp2 = icmp eq i32 %c, 6
; CHECK: ret i1 true
  ret i1 %cmp2
}

; CHECK-LABEL: @test7(
define i1 @test7(i32 %c) nounwind {
entry:
 switch i32 %c, label %sw.default [
   i32 6, label %sw.bb
   i32 7, label %sw.bb
 ]

sw.bb:
 ret i1 true

sw.default:
 %cmp5 = icmp eq i32 %c, 5
 %cmp6 = icmp eq i32 %c, 6
 %cmp7 = icmp eq i32 %c, 7
 %cmp8 = icmp eq i32 %c, 8
; CHECK: %or = or i1 %cmp5, false
 %or = or i1 %cmp5, %cmp6
; CHECK: %or2 = or i1 false, %cmp8
 %or2 = or i1 %cmp7, %cmp8
 ret i1 false
}

define i1 @test8(i64* %p) {
; CHECK-LABEL: @test8
; CHECK: ret i1 false
  %a = load i64, i64* %p, !range !{i64 4, i64 255}
  %res = icmp eq i64 %a, 0
  ret i1 %res
}

define i1 @test9(i64* %p) {
; CHECK-LABEL: @test9
; CHECK: ret i1 true
  %a = load i64, i64* %p, !range !{i64 0, i64 1}
  %res = icmp eq i64 %a, 0
  ret i1 %res
}

define i1 @test10(i64* %p) {
; CHECK-LABEL: @test10
; CHECK: ret i1 false
  %a = load i64, i64* %p, !range !{i64 4, i64 8, i64 15, i64 20}
  %res = icmp eq i64 %a, 0
  ret i1 %res
}

@g = external global i32

define i1 @test11() {
; CHECK: @test11
; CHECK: ret i1 true
  %positive = load i32, i32* @g, !range !{i32 1, i32 2048}
  %add = add i32 %positive, 1
  %test = icmp sgt i32 %add, 0
  br label %next

next:
  ret i1 %test
}

define i32 @test12(i32 %a, i32 %b) {
; CHECK-LABEL: @test12(
; CHECK: then:
; CHECK-NEXT: br i1 false, label %end, label %else
  %cmp = icmp ult i32 %a, %b
  br i1 %cmp, label %then, label %else

then:
  %dead = icmp eq i32 %a, -1
  br i1 %dead, label %end, label %else

else:
  ret i32 1

end:
  ret i32 2
}

define i32 @test12_swap(i32 %a, i32 %b) {
; CHECK-LABEL: @test12_swap(
; CHECK: then:
; CHECK-NEXT: br i1 false, label %end, label %else
  %cmp = icmp ugt i32 %b, %a
  br i1 %cmp, label %then, label %else

then:
  %dead = icmp eq i32 %a, -1
  br i1 %dead, label %end, label %else

else:
  ret i32 1

end:
  ret i32 2
}

define i32 @test12_neg(i32 %a, i32 %b) {
; The same as @test12 but the second check is on the false path
; CHECK-LABEL: @test12_neg(
; CHECK: else:
; CHECK-NEXT: %alive = icmp eq i32 %a, -1
  %cmp = icmp ult i32 %a, %b
  br i1 %cmp, label %then, label %else

else:
  %alive = icmp eq i32 %a, -1
  br i1 %alive, label %end, label %then

then:
  ret i32 1

end:
  ret i32 2
}

define i32 @test12_signed(i32 %a, i32 %b) {
; The same as @test12 but with signed comparison
; CHECK-LABEL: @test12_signed(
; CHECK: then:
; CHECK-NEXT: br i1 false, label %end, label %else
  %cmp = icmp slt i32 %a, %b
  br i1 %cmp, label %then, label %else

then:
  %dead = icmp eq i32 %a, 2147483647
  br i1 %dead, label %end, label %else

else:
  ret i32 1

end:
  ret i32 2
}

define i32 @test13(i32 %a, i32 %b) {
; CHECK-LABEL: @test13(
; CHECK: then:
; CHECK-NEXT: br i1 false, label %end, label %else
  %a.off = add i32 %a, -8
  %cmp = icmp ult i32 %a.off, %b
  br i1 %cmp, label %then, label %else

then:
  %dead = icmp eq i32 %a, 7
  br i1 %dead, label %end, label %else

else:
  ret i32 1

end:
  ret i32 2
}

define i32 @test13_swap(i32 %a, i32 %b) {
; CHECK-LABEL: @test13_swap(
; CHECK: then:
; CHECK-NEXT: br i1 false, label %end, label %else
  %a.off = add i32 %a, -8
  %cmp = icmp ugt i32 %b, %a.off
  br i1 %cmp, label %then, label %else

then:
  %dead = icmp eq i32 %a, 7
  br i1 %dead, label %end, label %else

else:
  ret i32 1

end:
  ret i32 2
}

define i1 @test14_slt(i32 %a) {
; CHECK-LABEL: @test14_slt(
; CHECK: then:
; CHECK-NEXT: %result = or i1 false, false
  %a.off = add i32 %a, -8
  %cmp = icmp slt i32 %a.off, 8
  br i1 %cmp, label %then, label %else

then:
  %dead.1 = icmp eq i32 %a, -2147483641
  %dead.2 = icmp eq i32 %a, 16
  %result = or i1 %dead.1, %dead.2
  ret i1 %result

else:
  ret i1 false
}

define i1 @test14_sle(i32 %a) {
; CHECK-LABEL: @test14_sle(
; CHECK: then:
; CHECK-NEXT: %alive = icmp eq i32 %a, 16
; CHECK-NEXT: %result = or i1 false, %alive
  %a.off = add i32 %a, -8
  %cmp = icmp sle i32 %a.off, 8
  br i1 %cmp, label %then, label %else

then:
  %dead = icmp eq i32 %a, -2147483641
  %alive = icmp eq i32 %a, 16
  %result = or i1 %dead, %alive
  ret i1 %result

else:
  ret i1 false
}

define i1 @test14_sgt(i32 %a) {
; CHECK-LABEL: @test14_sgt(
; CHECK: then:
; CHECK-NEXT: %result = or i1 false, false
  %a.off = add i32 %a, -8
  %cmp = icmp sgt i32 %a.off, 8
  br i1 %cmp, label %then, label %else

then:
  %dead.1 = icmp eq i32 %a, -2147483640
  %dead.2 = icmp eq i32 %a, 16
  %result = or i1 %dead.1, %dead.2
  ret i1 %result

else:
  ret i1 false
}

define i1 @test14_sge(i32 %a) {
; CHECK-LABEL: @test14_sge(
; CHECK: then:
; CHECK-NEXT: %alive = icmp eq i32 %a, 16
; CHECK-NEXT: %result = or i1 false, %alive
  %a.off = add i32 %a, -8
  %cmp = icmp sge i32 %a.off, 8
  br i1 %cmp, label %then, label %else

then:
  %dead = icmp eq i32 %a, -2147483640
  %alive = icmp eq i32 %a, 16
  %result = or i1 %dead, %alive
  ret i1 %result

else:
  ret i1 false
}

define i1 @test14_ule(i32 %a) {
; CHECK-LABEL: @test14_ule(
; CHECK: then:
; CHECK-NEXT: %alive = icmp eq i32 %a, 16
; CHECK-NEXT: %result = or i1 false, %alive
  %a.off = add i32 %a, -8
  %cmp = icmp ule i32 %a.off, 8
  br i1 %cmp, label %then, label %else

then:
  %dead = icmp eq i32 %a, 7
  %alive = icmp eq i32 %a, 16
  %result = or i1 %dead, %alive
  ret i1 %result

else:
  ret i1 false
}

define i1 @test14_ugt(i32 %a) {
; CHECK-LABEL: @test14_ugt(
; CHECK: then:
; CHECK-NEXT: %result = or i1 false, false
  %a.off = add i32 %a, -8
  %cmp = icmp ugt i32 %a.off, 8
  br i1 %cmp, label %then, label %else

then:
  %dead.1 = icmp eq i32 %a, 8
  %dead.2 = icmp eq i32 %a, 16
  %result = or i1 %dead.1, %dead.2
  ret i1 %result

else:
  ret i1 false
}

define i1 @test14_uge(i32 %a) {
; CHECK-LABEL: @test14_uge(
; CHECK: then:
; CHECK-NEXT: %alive = icmp eq i32 %a, 16
; CHECK-NEXT: %result = or i1 false, %alive
  %a.off = add i32 %a, -8
  %cmp = icmp uge i32 %a.off, 8
  br i1 %cmp, label %then, label %else

then:
  %dead = icmp eq i32 %a, 8
  %alive = icmp eq i32 %a, 16
  %result = or i1 %dead, %alive
  ret i1 %result

else:
  ret i1 false
}

@limit = external global i32
define i1 @test15(i32 %a) {
; CHECK-LABEL: @test15(
; CHECK: then:
; CHECK-NEXT: ret i1 false
  %limit = load i32, i32* @limit, !range !{i32 0, i32 256}
  %cmp = icmp ult i32 %a, %limit
  br i1 %cmp, label %then, label %else

then:
  %result = icmp eq i32 %a, 255
  ret i1 %result

else:
  ret i1 false
}

define i32 @test16(i8 %a) {
entry:
  %b = zext i8 %a to i32
  br label %dispatch

dispatch:
  %cmp = icmp eq i8 %a, 93
  br i1 %cmp, label %target93, label %dispatch

; CHECK-LABEL: @test16(
; CHECK: target93:
; CHECK-NEXT: ret i32 93
target93:
  ret i32 %b
}

define i32 @test16_i1(i1 %a) {
entry:
  %b = zext i1 %a to i32
  br label %dispatch

dispatch:
  br i1 %a, label %true, label %dispatch

; CHECK-LABEL: @test16_i1(
; CHECK: true:
; CHECK-NEXT: ret i32 1
true:
  ret i32 %b
}

define i8 @test17(i8 %a) {
entry:
  %c = add i8 %a, 3
  br label %dispatch

dispatch:
  %cmp = icmp eq i8 %a, 93
  br i1 %cmp, label %target93, label %dispatch

; CHECK-LABEL: @test17(
; CHECK: target93:
; CHECK-NEXT: ret i8 96
target93:
  ret i8 %c
}

define i8 @test17_2(i8 %a) {
entry:
  %c = add i8 %a, %a
  br label %dispatch

dispatch:
  %cmp = icmp eq i8 %a, 93
  br i1 %cmp, label %target93, label %dispatch

; CHECK-LABEL: @test17_2(
; CHECK: target93:
; CHECK-NEXT: ret i8 -70
target93:
  ret i8 %c
}

define i1 @test17_i1(i1 %a) {
entry:
  %c = and i1 %a, true
  br label %dispatch

dispatch:
  br i1 %a, label %true, label %dispatch

; CHECK-LABEL: @test17_i1(
; CHECK: true:
; CHECK-NEXT: ret i1 true
true:
  ret i1 %c
}

define i32 @test18(i8 %a) {
entry:
  %b = zext i8 %a to i32
  br label %dispatch

dispatch:
  switch i8 %a, label %dispatch [
    i8 93, label %target93
    i8 -111, label %dispatch
  ]

; CHECK-LABEL: @test18(
; CHECK: target93:
; CHECK-NEXT: ret i32 93
target93:
  ret i32 %b
}

define i8 @test19(i8 %a) {
entry:
  %c = add i8 %a, 3
  br label %dispatch

dispatch:
  switch i8 %a, label %dispatch [
    i8 93, label %target93
    i8 -111, label %dispatch
  ]

; CHECK-LABEL: @test19(
; CHECK: target93:
; CHECK-NEXT: ret i8 96
target93:
  ret i8 %c
}

define i1 @test20(i64 %a) {
entry:
  %b = and i64 %a, 7
  br label %dispatch

dispatch:
  switch i64 %a, label %default [
    i64 0, label %exit2
    i64 -2147483647, label %exit2
  ]

default:
  %c = icmp eq i64 %b, 0
  br label %exit

exit:
; Negative test. Shouldn't be incorrectly optimized to "ret i1 false".
; CHECK-LABEL: @test20(
; CHECK: exit:
; CHECK-NOT: ret i1 false
; CHECK: exit2:
  ret i1 %c

exit2:
  ret i1 false
}