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
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s
declare void @use(i32)
; PR1949
define i1 @test1(i32 %a) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[A:%.*]], -5
; CHECK-NEXT: ret i1 [[C]]
;
%b = add i32 %a, 4
%c = icmp ult i32 %b, 4
ret i1 %c
}
define <2 x i1> @test1vec(<2 x i32> %a) {
; CHECK-LABEL: @test1vec(
; CHECK-NEXT: [[C:%.*]] = icmp ugt <2 x i32> [[A:%.*]], <i32 -5, i32 -5>
; CHECK-NEXT: ret <2 x i1> [[C]]
;
%b = add <2 x i32> %a, <i32 4, i32 4>
%c = icmp ult <2 x i32> %b, <i32 4, i32 4>
ret <2 x i1> %c
}
define i1 @test2(i32 %a) {
; CHECK-LABEL: @test2(
; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[A:%.*]], 4
; CHECK-NEXT: ret i1 [[C]]
;
%b = sub i32 %a, 4
%c = icmp ugt i32 %b, -5
ret i1 %c
}
define <2 x i1> @test2vec(<2 x i32> %a) {
; CHECK-LABEL: @test2vec(
; CHECK-NEXT: [[C:%.*]] = icmp ult <2 x i32> [[A:%.*]], <i32 4, i32 4>
; CHECK-NEXT: ret <2 x i1> [[C]]
;
%b = sub <2 x i32> %a, <i32 4, i32 4>
%c = icmp ugt <2 x i32> %b, <i32 -5, i32 -5>
ret <2 x i1> %c
}
define i1 @test3(i32 %a) {
; CHECK-LABEL: @test3(
; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[A:%.*]], 2147483643
; CHECK-NEXT: ret i1 [[C]]
;
%b = add i32 %a, 4
%c = icmp slt i32 %b, 2147483652
ret i1 %c
}
define <2 x i1> @test3vec(<2 x i32> %a) {
; CHECK-LABEL: @test3vec(
; CHECK-NEXT: [[C:%.*]] = icmp sgt <2 x i32> [[A:%.*]], <i32 2147483643, i32 2147483643>
; CHECK-NEXT: ret <2 x i1> [[C]]
;
%b = add <2 x i32> %a, <i32 4, i32 4>
%c = icmp slt <2 x i32> %b, <i32 2147483652, i32 2147483652>
ret <2 x i1> %c
}
define i1 @test4(i32 %a) {
; CHECK-LABEL: @test4(
; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[A:%.*]], -4
; CHECK-NEXT: ret i1 [[C]]
;
%b = add i32 %a, 2147483652
%c = icmp sge i32 %b, 4
ret i1 %c
}
define { i32, i1 } @test4multiuse(i32 %a) {
; CHECK-LABEL: @test4multiuse(
; CHECK-NEXT: [[B:%.*]] = add i32 [[A:%.*]], -2147483644
; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[B]], -4
; CHECK-NEXT: [[TMP:%.*]] = insertvalue { i32, i1 } undef, i32 [[B]], 0
; CHECK-NEXT: [[RES:%.*]] = insertvalue { i32, i1 } [[TMP]], i1 [[C]], 1
; CHECK-NEXT: ret { i32, i1 } [[RES]]
;
%b = add i32 %a, -2147483644
%c = icmp slt i32 %b, -4
%tmp = insertvalue { i32, i1 } undef, i32 %b, 0
%res = insertvalue { i32, i1 } %tmp, i1 %c, 1
ret { i32, i1 } %res
}
define <2 x i1> @test4vec(<2 x i32> %a) {
; CHECK-LABEL: @test4vec(
; CHECK-NEXT: [[C:%.*]] = icmp slt <2 x i32> [[A:%.*]], <i32 -4, i32 -4>
; CHECK-NEXT: ret <2 x i1> [[C]]
;
%b = add <2 x i32> %a, <i32 2147483652, i32 2147483652>
%c = icmp sge <2 x i32> %b, <i32 4, i32 4>
ret <2 x i1> %c
}
; icmp Pred (add nsw X, C2), C --> icmp Pred X, (C - C2), when C - C2 does not overflow.
; This becomes equality because it's at the limit.
define i1 @nsw_slt1(i8 %a) {
; CHECK-LABEL: @nsw_slt1(
; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[A:%.*]], -128
; CHECK-NEXT: ret i1 [[C]]
;
%b = add nsw i8 %a, 100
%c = icmp slt i8 %b, -27
ret i1 %c
}
define <2 x i1> @nsw_slt1_splat_vec(<2 x i8> %a) {
; CHECK-LABEL: @nsw_slt1_splat_vec(
; CHECK-NEXT: [[C:%.*]] = icmp eq <2 x i8> [[A:%.*]], <i8 -128, i8 -128>
; CHECK-NEXT: ret <2 x i1> [[C]]
;
%b = add nsw <2 x i8> %a, <i8 100, i8 100>
%c = icmp slt <2 x i8> %b, <i8 -27, i8 -27>
ret <2 x i1> %c
}
; icmp Pred (add nsw X, C2), C --> icmp Pred X, (C - C2), when C - C2 does not overflow.
; This becomes equality because it's at the limit.
define i1 @nsw_slt2(i8 %a) {
; CHECK-LABEL: @nsw_slt2(
; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[A:%.*]], 127
; CHECK-NEXT: ret i1 [[C]]
;
%b = add nsw i8 %a, -100
%c = icmp slt i8 %b, 27
ret i1 %c
}
define <2 x i1> @nsw_slt2_splat_vec(<2 x i8> %a) {
; CHECK-LABEL: @nsw_slt2_splat_vec(
; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i8> [[A:%.*]], <i8 127, i8 127>
; CHECK-NEXT: ret <2 x i1> [[C]]
;
%b = add nsw <2 x i8> %a, <i8 -100, i8 -100>
%c = icmp slt <2 x i8> %b, <i8 27, i8 27>
ret <2 x i1> %c
}
; icmp Pred (add nsw X, C2), C --> icmp Pred X, (C - C2), when C - C2 does not overflow.
; Less than the limit, so the predicate doesn't change.
define i1 @nsw_slt3(i8 %a) {
; CHECK-LABEL: @nsw_slt3(
; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[A:%.*]], -126
; CHECK-NEXT: ret i1 [[C]]
;
%b = add nsw i8 %a, 100
%c = icmp slt i8 %b, -26
ret i1 %c
}
; icmp Pred (add nsw X, C2), C --> icmp Pred X, (C - C2), when C - C2 does not overflow.
; Less than the limit, so the predicate doesn't change.
define i1 @nsw_slt4(i8 %a) {
; CHECK-LABEL: @nsw_slt4(
; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[A:%.*]], 126
; CHECK-NEXT: ret i1 [[C]]
;
%b = add nsw i8 %a, -100
%c = icmp slt i8 %b, 26
ret i1 %c
}
; icmp Pred (add nsw X, C2), C --> icmp Pred X, (C - C2), when C - C2 does not overflow.
; Try sgt to make sure that works too.
define i1 @nsw_sgt1(i8 %a) {
; CHECK-LABEL: @nsw_sgt1(
; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[A:%.*]], 127
; CHECK-NEXT: ret i1 [[C]]
;
%b = add nsw i8 %a, -100
%c = icmp sgt i8 %b, 26
ret i1 %c
}
define <2 x i1> @nsw_sgt1_splat_vec(<2 x i8> %a) {
; CHECK-LABEL: @nsw_sgt1_splat_vec(
; CHECK-NEXT: [[C:%.*]] = icmp eq <2 x i8> [[A:%.*]], <i8 127, i8 127>
; CHECK-NEXT: ret <2 x i1> [[C]]
;
%b = add nsw <2 x i8> %a, <i8 -100, i8 -100>
%c = icmp sgt <2 x i8> %b, <i8 26, i8 26>
ret <2 x i1> %c
}
define i1 @nsw_sgt2(i8 %a) {
; CHECK-LABEL: @nsw_sgt2(
; CHECK-NEXT: [[C:%.*]] = icmp sgt i8 [[A:%.*]], -126
; CHECK-NEXT: ret i1 [[C]]
;
%b = add nsw i8 %a, 100
%c = icmp sgt i8 %b, -26
ret i1 %c
}
define <2 x i1> @nsw_sgt2_splat_vec(<2 x i8> %a) {
; CHECK-LABEL: @nsw_sgt2_splat_vec(
; CHECK-NEXT: [[C:%.*]] = icmp sgt <2 x i8> [[A:%.*]], <i8 -126, i8 -126>
; CHECK-NEXT: ret <2 x i1> [[C]]
;
%b = add nsw <2 x i8> %a, <i8 100, i8 100>
%c = icmp sgt <2 x i8> %b, <i8 -26, i8 -26>
ret <2 x i1> %c
}
; icmp Pred (add nsw X, C2), C --> icmp Pred X, (C - C2), when C - C2 does not overflow.
; Comparison with 0 doesn't need special-casing.
define i1 @slt_zero_add_nsw(i32 %a) {
; CHECK-LABEL: @slt_zero_add_nsw(
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[A:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%add = add nsw i32 %a, 1
%cmp = icmp slt i32 %add, 0
ret i1 %cmp
}
; The same fold should work with vectors.
define <2 x i1> @slt_zero_add_nsw_splat_vec(<2 x i8> %a) {
; CHECK-LABEL: @slt_zero_add_nsw_splat_vec(
; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[A:%.*]], <i8 -1, i8 -1>
; CHECK-NEXT: ret <2 x i1> [[CMP]]
;
%add = add nsw <2 x i8> %a, <i8 1, i8 1>
%cmp = icmp slt <2 x i8> %add, zeroinitializer
ret <2 x i1> %cmp
}
; Test the edges - instcombine should not interfere with simplification to constants.
; Constant subtraction does not overflow, but this is false.
define i1 @nsw_slt3_ov_no(i8 %a) {
; CHECK-LABEL: @nsw_slt3_ov_no(
; CHECK-NEXT: ret i1 false
;
%b = add nsw i8 %a, 100
%c = icmp slt i8 %b, -28
ret i1 %c
}
; Test the edges - instcombine should not interfere with simplification to constants.
; Constant subtraction overflows. This is false.
define i1 @nsw_slt4_ov(i8 %a) {
; CHECK-LABEL: @nsw_slt4_ov(
; CHECK-NEXT: ret i1 false
;
%b = add nsw i8 %a, 100
%c = icmp slt i8 %b, -29
ret i1 %c
}
; Test the edges - instcombine should not interfere with simplification to constants.
; Constant subtraction overflows. This is true.
define i1 @nsw_slt5_ov(i8 %a) {
; CHECK-LABEL: @nsw_slt5_ov(
; CHECK-NEXT: ret i1 true
;
%b = add nsw i8 %a, -100
%c = icmp slt i8 %b, 28
ret i1 %c
}
; InstCombine should not thwart this opportunity to simplify completely.
define i1 @slt_zero_add_nsw_signbit(i8 %x) {
; CHECK-LABEL: @slt_zero_add_nsw_signbit(
; CHECK-NEXT: ret i1 true
;
%y = add nsw i8 %x, -128
%z = icmp slt i8 %y, 0
ret i1 %z
}
; InstCombine should not thwart this opportunity to simplify completely.
define i1 @slt_zero_add_nuw_signbit(i8 %x) {
; CHECK-LABEL: @slt_zero_add_nuw_signbit(
; CHECK-NEXT: ret i1 true
;
%y = add nuw i8 %x, 128
%z = icmp slt i8 %y, 0
ret i1 %z
}
define i1 @reduce_add_ult(i32 %in) {
; CHECK-LABEL: @reduce_add_ult(
; CHECK-NEXT: [[A18:%.*]] = icmp ult i32 [[IN:%.*]], 9
; CHECK-NEXT: ret i1 [[A18]]
;
%a6 = add nuw i32 %in, 3
%a18 = icmp ult i32 %a6, 12
ret i1 %a18
}
define i1 @reduce_add_ugt(i32 %in) {
; CHECK-LABEL: @reduce_add_ugt(
; CHECK-NEXT: [[A18:%.*]] = icmp ugt i32 [[IN:%.*]], 9
; CHECK-NEXT: ret i1 [[A18]]
;
%a6 = add nuw i32 %in, 3
%a18 = icmp ugt i32 %a6, 12
ret i1 %a18
}
define i1 @reduce_add_ule(i32 %in) {
; CHECK-LABEL: @reduce_add_ule(
; CHECK-NEXT: [[A18:%.*]] = icmp ult i32 [[IN:%.*]], 10
; CHECK-NEXT: ret i1 [[A18]]
;
%a6 = add nuw i32 %in, 3
%a18 = icmp ule i32 %a6, 12
ret i1 %a18
}
define i1 @reduce_add_uge(i32 %in) {
; CHECK-LABEL: @reduce_add_uge(
; CHECK-NEXT: [[A18:%.*]] = icmp ugt i32 [[IN:%.*]], 8
; CHECK-NEXT: ret i1 [[A18]]
;
%a6 = add nuw i32 %in, 3
%a18 = icmp uge i32 %a6, 12
ret i1 %a18
}
define i1 @ult_add_ssubov(i32 %in) {
; CHECK-LABEL: @ult_add_ssubov(
; CHECK-NEXT: ret i1 false
;
%a6 = add nuw i32 %in, 71
%a18 = icmp ult i32 %a6, 3
ret i1 %a18
}
define i1 @ult_add_nonuw(i8 %in) {
; CHECK-LABEL: @ult_add_nonuw(
; CHECK-NEXT: [[A6:%.*]] = add i8 [[IN:%.*]], 71
; CHECK-NEXT: [[A18:%.*]] = icmp ult i8 [[A6]], 12
; CHECK-NEXT: ret i1 [[A18]]
;
%a6 = add i8 %in, 71
%a18 = icmp ult i8 %a6, 12
ret i1 %a18
}
define i1 @uge_add_nonuw(i32 %in) {
; CHECK-LABEL: @uge_add_nonuw(
; CHECK-NEXT: [[A6:%.*]] = add i32 [[IN:%.*]], 3
; CHECK-NEXT: [[A18:%.*]] = icmp ugt i32 [[A6]], 11
; CHECK-NEXT: ret i1 [[A18]]
;
%a6 = add i32 %in, 3
%a18 = icmp uge i32 %a6, 12
ret i1 %a18
}
; Test unsigned add overflow patterns. The div ops are only here to
; thwart complexity based canonicalization of the operand order.
define i1 @op_ugt_sum_commute1(i8 %p1, i8 %p2) {
; CHECK-LABEL: @op_ugt_sum_commute1(
; CHECK-NEXT: [[X:%.*]] = sdiv i8 42, [[P1:%.*]]
; CHECK-NEXT: [[Y:%.*]] = sdiv i8 42, [[P2:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = xor i8 [[X]], -1
; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[Y]], [[TMP1]]
; CHECK-NEXT: ret i1 [[C]]
;
%x = sdiv i8 42, %p1
%y = sdiv i8 42, %p2
%a = add i8 %x, %y
%c = icmp ugt i8 %x, %a
ret i1 %c
}
define <2 x i1> @op_ugt_sum_vec_commute2(<2 x i8> %p1, <2 x i8> %p2) {
; CHECK-LABEL: @op_ugt_sum_vec_commute2(
; CHECK-NEXT: [[X:%.*]] = sdiv <2 x i8> <i8 42, i8 -42>, [[P1:%.*]]
; CHECK-NEXT: [[Y:%.*]] = sdiv <2 x i8> <i8 42, i8 -42>, [[P2:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i8> [[X]], <i8 -1, i8 -1>
; CHECK-NEXT: [[C:%.*]] = icmp ugt <2 x i8> [[Y]], [[TMP1]]
; CHECK-NEXT: ret <2 x i1> [[C]]
;
%x = sdiv <2 x i8> <i8 42, i8 -42>, %p1
%y = sdiv <2 x i8> <i8 42, i8 -42>, %p2
%a = add <2 x i8> %y, %x
%c = icmp ugt <2 x i8> %x, %a
ret <2 x i1> %c
}
define i1 @sum_ugt_op_uses(i8 %p1, i8 %p2, i8* %p3) {
; CHECK-LABEL: @sum_ugt_op_uses(
; CHECK-NEXT: [[X:%.*]] = sdiv i8 42, [[P1:%.*]]
; CHECK-NEXT: [[Y:%.*]] = sdiv i8 42, [[P2:%.*]]
; CHECK-NEXT: [[A:%.*]] = add nsw i8 [[X]], [[Y]]
; CHECK-NEXT: store i8 [[A]], i8* [[P3:%.*]], align 1
; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[X]], [[A]]
; CHECK-NEXT: ret i1 [[C]]
;
%x = sdiv i8 42, %p1
%y = sdiv i8 42, %p2
%a = add i8 %x, %y
store i8 %a, i8* %p3
%c = icmp ugt i8 %x, %a
ret i1 %c
}
define <2 x i1> @sum_ult_op_vec_commute1(<2 x i8> %p1, <2 x i8> %p2) {
; CHECK-LABEL: @sum_ult_op_vec_commute1(
; CHECK-NEXT: [[X:%.*]] = sdiv <2 x i8> <i8 42, i8 -42>, [[P1:%.*]]
; CHECK-NEXT: [[Y:%.*]] = sdiv <2 x i8> <i8 -42, i8 42>, [[P2:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i8> [[X]], <i8 -1, i8 -1>
; CHECK-NEXT: [[C:%.*]] = icmp ugt <2 x i8> [[Y]], [[TMP1]]
; CHECK-NEXT: ret <2 x i1> [[C]]
;
%x = sdiv <2 x i8> <i8 42, i8 -42>, %p1
%y = sdiv <2 x i8> <i8 -42, i8 42>, %p2
%a = add <2 x i8> %x, %y
%c = icmp ult <2 x i8> %a, %x
ret <2 x i1> %c
}
define i1 @sum_ult_op_commute2(i8 %p1, i8 %p2) {
; CHECK-LABEL: @sum_ult_op_commute2(
; CHECK-NEXT: [[X:%.*]] = sdiv i8 42, [[P1:%.*]]
; CHECK-NEXT: [[Y:%.*]] = sdiv i8 42, [[P2:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = xor i8 [[X]], -1
; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[Y]], [[TMP1]]
; CHECK-NEXT: ret i1 [[C]]
;
%x = sdiv i8 42, %p1
%y = sdiv i8 42, %p2
%a = add i8 %y, %x
%c = icmp ult i8 %a, %x
ret i1 %c
}
define i1 @sum_ult_op_uses(i8 %x, i8 %y, i8* %p) {
; CHECK-LABEL: @sum_ult_op_uses(
; CHECK-NEXT: [[A:%.*]] = add i8 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: store i8 [[A]], i8* [[P:%.*]], align 1
; CHECK-NEXT: [[C:%.*]] = icmp ult i8 [[A]], [[X]]
; CHECK-NEXT: ret i1 [[C]]
;
%a = add i8 %y, %x
store i8 %a, i8* %p
%c = icmp ult i8 %a, %x
ret i1 %c
}
; X + Z >s Y + Z -> X > Y if there is no overflow.
define i1 @common_op_nsw(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @common_op_nsw(
; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%lhs = add nsw i32 %x, %z
%rhs = add nsw i32 %y, %z
%c = icmp sgt i32 %lhs, %rhs
ret i1 %c
}
define i1 @common_op_nsw_extra_uses(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @common_op_nsw_extra_uses(
; CHECK-NEXT: [[LHS:%.*]] = add nsw i32 [[X:%.*]], [[Z:%.*]]
; CHECK-NEXT: call void @use(i32 [[LHS]])
; CHECK-NEXT: [[RHS:%.*]] = add nsw i32 [[Y:%.*]], [[Z]]
; CHECK-NEXT: call void @use(i32 [[RHS]])
; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[X]], [[Y]]
; CHECK-NEXT: ret i1 [[C]]
;
%lhs = add nsw i32 %x, %z
call void @use(i32 %lhs)
%rhs = add nsw i32 %y, %z
call void @use(i32 %rhs)
%c = icmp sgt i32 %lhs, %rhs
ret i1 %c
}
; X + Z >u Z + Y -> X > Y if there is no overflow.
define i1 @common_op_nuw(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @common_op_nuw(
; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%lhs = add nuw i32 %x, %z
%rhs = add nuw i32 %z, %y
%c = icmp ugt i32 %lhs, %rhs
ret i1 %c
}
define i1 @common_op_nuw_extra_uses(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @common_op_nuw_extra_uses(
; CHECK-NEXT: [[LHS:%.*]] = add nuw i32 [[X:%.*]], [[Z:%.*]]
; CHECK-NEXT: call void @use(i32 [[LHS]])
; CHECK-NEXT: [[RHS:%.*]] = add nuw i32 [[Z]], [[Y:%.*]]
; CHECK-NEXT: call void @use(i32 [[RHS]])
; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[X]], [[Y]]
; CHECK-NEXT: ret i1 [[C]]
;
%lhs = add nuw i32 %x, %z
call void @use(i32 %lhs)
%rhs = add nuw i32 %z, %y
call void @use(i32 %rhs)
%c = icmp ugt i32 %lhs, %rhs
ret i1 %c
}
define i1 @common_op_nsw_commute(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @common_op_nsw_commute(
; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%lhs = add nsw i32 %z, %x
%rhs = add nsw i32 %y, %z
%c = icmp slt i32 %lhs, %rhs
ret i1 %c
}
define i1 @common_op_nuw_commute(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @common_op_nuw_commute(
; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%lhs = add nuw i32 %z, %x
%rhs = add nuw i32 %z, %y
%c = icmp ult i32 %lhs, %rhs
ret i1 %c
}
; X + Y > X -> Y > 0 if there is no overflow.
define i1 @common_op_test29(i32 %x, i32 %y) {
; CHECK-LABEL: @common_op_test29(
; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[Y:%.*]], 0
; CHECK-NEXT: ret i1 [[C]]
;
%lhs = add nsw i32 %x, %y
%c = icmp sgt i32 %lhs, %x
ret i1 %c
}
; X + Y > X -> Y > 0 if there is no overflow.
define i1 @sum_nuw(i32 %x, i32 %y) {
; CHECK-LABEL: @sum_nuw(
; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[Y:%.*]], 0
; CHECK-NEXT: ret i1 [[C]]
;
%lhs = add nuw i32 %x, %y
%c = icmp ugt i32 %lhs, %x
ret i1 %c
}
; X > X + Y -> 0 > Y if there is no overflow.
define i1 @sum_nsw_commute(i32 %x, i32 %y) {
; CHECK-LABEL: @sum_nsw_commute(
; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[Y:%.*]], 0
; CHECK-NEXT: ret i1 [[C]]
;
%rhs = add nsw i32 %x, %y
%c = icmp sgt i32 %x, %rhs
ret i1 %c
}
; X > X + Y -> 0 > Y if there is no overflow.
define i1 @sum_nuw_commute(i32 %x, i32 %y) {
; CHECK-LABEL: @sum_nuw_commute(
; CHECK-NEXT: ret i1 false
;
%rhs = add nuw i32 %x, %y
%c = icmp ugt i32 %x, %rhs
ret i1 %c
}
; PR2698 - https://bugs.llvm.org/show_bug.cgi?id=2698
declare void @use1(i1)
declare void @use8(i8)
define void @bzip1(i8 %a, i8 %b, i8 %x) {
; CHECK-LABEL: @bzip1(
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: call void @use1(i1 [[CMP]])
; CHECK-NEXT: ret void
;
%add1 = add i8 %a, %x
%add2 = add i8 %b, %x
%cmp = icmp eq i8 %add1, %add2
call void @use1(i1 %cmp)
ret void
}
define void @bzip2(i8 %a, i8 %b, i8 %x) {
; CHECK-LABEL: @bzip2(
; CHECK-NEXT: [[ADD1:%.*]] = add i8 [[A:%.*]], [[X:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A]], [[B:%.*]]
; CHECK-NEXT: call void @use1(i1 [[CMP]])
; CHECK-NEXT: call void @use8(i8 [[ADD1]])
; CHECK-NEXT: ret void
;
%add1 = add i8 %a, %x
%add2 = add i8 %b, %x
%cmp = icmp eq i8 %add1, %add2
call void @use1(i1 %cmp)
call void @use8(i8 %add1)
ret void
}
|