llvm.org GIT mirror llvm / d09e4ee
[InstSimplify] move icmp with constant tests to another file; NFC ...because like the corresponding code, this is just too big to keep adding to. And the next step is to add a vector version of each of these tests to show missed folds. Also, auto-generate CHECK lines and add comments for the tests that correspond to the source code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279530 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 3 years ago
2 changed file(s) with 222 addition(s) and 165 deletion(s). Raw diff Collapse all Expand all
None ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -instsimplify -S | FileCheck %s
21 target datalayout = "p:32:32"
32
369368 ; CHECK: ret i1 false
370369 }
371370
372 define i1 @shl2(i32 %X) {
373 ; CHECK: @shl2
374 %sub = shl nsw i32 -1, %X
375 %cmp = icmp eq i32 %sub, 31
376 ret i1 %cmp
377 ; CHECK-NEXT: ret i1 false
378 }
379
380371 define i1 @shl3(i32 %X) {
381372 ; CHECK: @shl3
382373 %sub = shl nuw i32 4, %X
385376 ; CHECK-NEXT: ret i1 false
386377 }
387378
388 define i1 @shl4(i32 %X) {
389 ; CHECK: @shl4
390 %sub = shl nsw i32 -1, %X
391 %cmp = icmp sle i32 %sub, -1
392 ret i1 %cmp
393 ; CHECK-NEXT: ret i1 true
394 }
395
396 define i1 @shl5(i32 %X) {
397 ; CHECK: @shl5
398 %sub = shl nuw i32 4, %X
399 %cmp = icmp ugt i32 %sub, 3
400 ret i1 %cmp
401 ; CHECK-NEXT: ret i1 true
402 }
403
404379 define i1 @lshr1(i32 %x) {
405380 ; CHECK-LABEL: @lshr1(
406381 %s = lshr i32 -1, %x
407382 %c = icmp eq i32 %s, 0
408 ret i1 %c
409 ; CHECK: ret i1 false
410 }
411
412 define i1 @lshr2(i32 %x) {
413 ; CHECK-LABEL: @lshr2(
414 %s = lshr i32 %x, 30
415 %c = icmp ugt i32 %s, 8
416383 ret i1 %c
417384 ; CHECK: ret i1 false
418385 }
445412 ; CHECK-LABEL: @ashr1(
446413 %s = ashr i32 -1, %x
447414 %c = icmp eq i32 %s, 0
448 ret i1 %c
449 ; CHECK: ret i1 false
450 }
451
452 define i1 @ashr2(i32 %x) {
453 ; CHECK-LABEL: @ashr2(
454 %s = ashr i32 %x, 30
455 %c = icmp slt i32 %s, -5
456415 ret i1 %c
457416 ; CHECK: ret i1 false
458417 }
534493 ; CHECK: ret i1 false
535494 }
536495
537 define i1 @urem3(i32 %X) {
538 ; CHECK-LABEL: @urem3(
539 %A = urem i32 %X, 10
540 %B = icmp ult i32 %A, 15
541 ret i1 %B
542 ; CHECK: ret i1 true
543 }
544
545496 define i1 @urem4(i32 %X) {
546497 ; CHECK-LABEL: @urem4(
547498 %A = urem i32 %X, 15
575526 ; CHECK-NOT: ret i1 false
576527 }
577528
578 define i1 @srem1(i32 %X) {
579 ; CHECK-LABEL: @srem1(
580 %A = srem i32 %X, -5
581 %B = icmp sgt i32 %A, 5
582 ret i1 %B
583 ; CHECK: ret i1 false
584 }
585
586529 ; PR9343 #15
587530 ; CHECK-LABEL: @srem2(
588531 ; CHECK: ret i1 false
605548 ret i1 %E
606549 }
607550
608 define i1 @udiv1(i32 %X) {
609 ; CHECK-LABEL: @udiv1(
610 %A = udiv i32 %X, 1000000
611 %B = icmp ult i32 %A, 5000
612 ret i1 %B
613 ; CHECK: ret i1 true
614 }
615
616551 define i1 @udiv2(i32 %X, i32 %Y, i32 %Z) {
617552 ; CHECK-LABEL: @udiv2(
618553 %A = udiv exact i32 10, %Z
636571 %C = icmp ule i32 %A, %X
637572 ret i1 %C
638573 ; CHECK: ret i1 true
639 }
640
641 define i1 @udiv5(i32 %X) {
642 ; CHECK-LABEL: @udiv5(
643 %A = udiv i32 123, %X
644 %C = icmp ugt i32 %A, 124
645 ret i1 %C
646 ; CHECK: ret i1 false
647574 }
648575
649576 ; PR11340
653580 %C = icmp eq i32 %A, 0
654581 ret i1 %C
655582 ; CHECK: ret i1 %C
656 }
657
658
659 define i1 @sdiv1(i32 %X) {
660 ; CHECK-LABEL: @sdiv1(
661 %A = sdiv i32 %X, 1000000
662 %B = icmp slt i32 %A, 3000
663 ret i1 %B
664 ; CHECK: ret i1 true
665 }
666
667 define i1 @or1(i32 %X) {
668 ; CHECK-LABEL: @or1(
669 %A = or i32 %X, 62
670 %B = icmp ult i32 %A, 50
671 ret i1 %B
672 ; CHECK: ret i1 false
673 }
674
675 define i1 @and1(i32 %X) {
676 ; CHECK-LABEL: @and1(
677 %A = and i32 %X, 62
678 %B = icmp ugt i32 %A, 70
679 ret i1 %B
680 ; CHECK: ret i1 false
681583 }
682584
683585 define i1 @mul1(i32 %X) {
894796 ; CHECK-NEXT: ret i1 true
895797 }
896798
897 define i1 @compare_dividend(i32 %a) {
898 %div = sdiv i32 2, %a
899 %cmp = icmp eq i32 %div, 3
900 ret i1 %cmp
901
902 ; CHECK-LABEL: @compare_dividend
903 ; CHECK-NEXT: ret i1 false
904 }
905
906799 define i1 @lshr_ugt_false(i32 %a) {
907800 %shr = lshr i32 1, %a
908801 %cmp = icmp ugt i32 %shr, 1
909802 ret i1 %cmp
910803 ; CHECK-LABEL: @lshr_ugt_false
911 ; CHECK-NEXT: ret i1 false
912 }
913
914 define i1 @exact_lshr_ugt_false(i32 %a) {
915 %shr = lshr exact i32 30, %a
916 %cmp = icmp ult i32 %shr, 15
917 ret i1 %cmp
918 ; CHECK-LABEL: @exact_lshr_ugt_false
919 ; CHECK-NEXT: ret i1 false
920 }
921
922 define i1 @lshr_sgt_false(i32 %a) {
923 %shr = lshr i32 1, %a
924 %cmp = icmp sgt i32 %shr, 1
925 ret i1 %cmp
926 ; CHECK-LABEL: @lshr_sgt_false
927 ; CHECK-NEXT: ret i1 false
928 }
929
930 define i1 @ashr_sgt_false(i32 %a) {
931 %shr = ashr i32 -30, %a
932 %cmp = icmp sgt i32 %shr, -1
933 ret i1 %cmp
934 ; CHECK-LABEL: @ashr_sgt_false
935 ; CHECK-NEXT: ret i1 false
936 }
937
938 define i1 @exact_ashr_sgt_false(i32 %a) {
939 %shr = ashr exact i32 -30, %a
940 %cmp = icmp sgt i32 %shr, -15
941 ret i1 %cmp
942 ; CHECK-LABEL: @exact_ashr_sgt_false
943804 ; CHECK-NEXT: ret i1 false
944805 }
945806
1109970 ; CHECK-NEXT: ret i1 true
1110971 }
1111972
1112 define i1 @icmp_shl_nsw_neg1(i64 %a) {
1113 %shl = shl nsw i64 -1, %a
1114 %cmp = icmp sge i64 %shl, 3
1115 ret i1 %cmp
1116
1117 ; CHECK-LABEL: @icmp_shl_nsw_neg1
1118 ; CHECK-NEXT: ret i1 false
1119 }
1120
1121 define i1 @icmp_shl_nsw_1(i64 %a) {
1122 %shl = shl nsw i64 1, %a
1123 %cmp = icmp sge i64 %shl, 0
1124 ret i1 %cmp
1125
1126 ; CHECK-LABEL: @icmp_shl_nsw_1
1127 ; CHECK-NEXT: ret i1 true
1128 }
1129
1130973 define i1 @icmp_shl_1_V_ugt_2147483648(i32 %V) {
1131974 %shl = shl i32 1, %V
1132975 %cmp = icmp ugt i32 %shl, 2147483648
12251068 ret i1 %D
12261069 ; CHECK-LABEL: @tautological8(
12271070 ; CHECK: ret i1 false
1228 }
1229
1230 define i1 @tautological9(i32 %x) {
1231 %add = add nuw i32 %x, 13
1232 %cmp = icmp ne i32 %add, 12
1233 ret i1 %cmp
1234 ; CHECK-LABEL: @tautological9(
1235 ; CHECK: ret i1 true
12361071 }
12371072
12381073 declare void @helper_i1(i1)
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -instsimplify -S | FileCheck %s
2
3 ; Fold icmp with a constant operand.
4
5 define i1 @tautological_ule(i8 %x) {
6 ; CHECK-LABEL: @tautological_ule(
7 ; CHECK-NEXT: ret i1 true
8 ;
9 %cmp = icmp ule i8 %x, 255
10 ret i1 %cmp
11 }
12
13 define i1 @tautological_ugt(i8 %x) {
14 ; CHECK-LABEL: @tautological_ugt(
15 ; CHECK-NEXT: ret i1 false
16 ;
17 %cmp = icmp ugt i8 %x, 255
18 ret i1 %cmp
19 }
20
21 ; 'urem x, C2' produces [0, C2)
22 define i1 @urem3(i32 %X) {
23 ; CHECK-LABEL: @urem3(
24 ; CHECK-NEXT: ret i1 true
25 ;
26 %A = urem i32 %X, 10
27 %B = icmp ult i32 %A, 15
28 ret i1 %B
29 }
30
31 ;'srem x, C2' produces (-|C2|, |C2|)
32 define i1 @srem1(i32 %X) {
33 ; CHECK-LABEL: @srem1(
34 ; CHECK-NEXT: ret i1 false
35 ;
36 %A = srem i32 %X, -5
37 %B = icmp sgt i32 %A, 5
38 ret i1 %B
39 }
40
41 ;'udiv C2, x' produces [0, C2]
42 define i1 @udiv5(i32 %X) {
43 ; CHECK-LABEL: @udiv5(
44 ; CHECK-NEXT: ret i1 false
45 ;
46 %A = udiv i32 123, %X
47 %C = icmp ugt i32 %A, 124
48 ret i1 %C
49 }
50
51 ; 'udiv x, C2' produces [0, UINT_MAX / C2]
52 define i1 @udiv1(i32 %X) {
53 ; CHECK-LABEL: @udiv1(
54 ; CHECK-NEXT: ret i1 true
55 ;
56 %A = udiv i32 %X, 1000000
57 %B = icmp ult i32 %A, 5000
58 ret i1 %B
59 }
60
61 ; 'sdiv C2, x' produces [-|C2|, |C2|]
62 define i1 @compare_dividend(i32 %a) {
63 ; CHECK-LABEL: @compare_dividend(
64 ; CHECK-NEXT: ret i1 false
65 ;
66 %div = sdiv i32 2, %a
67 %cmp = icmp eq i32 %div, 3
68 ret i1 %cmp
69 }
70
71 ; 'sdiv x, C2' produces [INT_MIN / C2, INT_MAX / C2]
72 ; where C2 != -1 and C2 != 0 and C2 != 1
73 define i1 @sdiv1(i32 %X) {
74 ; CHECK-LABEL: @sdiv1(
75 ; CHECK-NEXT: ret i1 true
76 ;
77 %A = sdiv i32 %X, 1000000
78 %B = icmp slt i32 %A, 3000
79 ret i1 %B
80 }
81
82 ; 'shl nuw C2, x' produces [C2, C2 << CLZ(C2)]
83 define i1 @shl5(i32 %X) {
84 ; CHECK-LABEL: @shl5(
85 ; CHECK-NEXT: ret i1 true
86 ;
87 %sub = shl nuw i32 4, %X
88 %cmp = icmp ugt i32 %sub, 3
89 ret i1 %cmp
90 }
91
92 ; 'shl nsw C2, x' produces [C2 << CLO(C2)-1, C2]
93 define i1 @shl2(i32 %X) {
94 ; CHECK-LABEL: @shl2(
95 ; CHECK-NEXT: ret i1 false
96 ;
97 %sub = shl nsw i32 -1, %X
98 %cmp = icmp eq i32 %sub, 31
99 ret i1 %cmp
100 }
101
102 ; 'shl nsw C2, x' produces [C2 << CLO(C2)-1, C2]
103 define i1 @shl4(i32 %X) {
104 ; CHECK-LABEL: @shl4(
105 ; CHECK-NEXT: ret i1 true
106 ;
107 %sub = shl nsw i32 -1, %X
108 %cmp = icmp sle i32 %sub, -1
109 ret i1 %cmp
110 }
111
112 ; 'shl nsw C2, x' produces [C2, C2 << CLZ(C2)-1]
113 define i1 @icmp_shl_nsw_1(i64 %a) {
114 ; CHECK-LABEL: @icmp_shl_nsw_1(
115 ; CHECK-NEXT: ret i1 true
116 ;
117 %shl = shl nsw i64 1, %a
118 %cmp = icmp sge i64 %shl, 0
119 ret i1 %cmp
120 }
121
122 ; 'shl nsw C2, x' produces [C2 << CLO(C2)-1, C2]
123 define i1 @icmp_shl_nsw_neg1(i64 %a) {
124 ; CHECK-LABEL: @icmp_shl_nsw_neg1(
125 ; CHECK-NEXT: ret i1 false
126 ;
127 %shl = shl nsw i64 -1, %a
128 %cmp = icmp sge i64 %shl, 3
129 ret i1 %cmp
130 }
131
132 ; 'lshr x, C2' produces [0, UINT_MAX >> C2]
133 define i1 @lshr2(i32 %x) {
134 ; CHECK-LABEL: @lshr2(
135 ; CHECK-NEXT: ret i1 false
136 ;
137 %s = lshr i32 %x, 30
138 %c = icmp ugt i32 %s, 8
139 ret i1 %c
140 }
141
142 ; 'lshr C2, x' produces [C2 >> (Width-1), C2]
143 define i1 @exact_lshr_ugt_false(i32 %a) {
144 ; CHECK-LABEL: @exact_lshr_ugt_false(
145 ; CHECK-NEXT: ret i1 false
146 ;
147 %shr = lshr exact i32 30, %a
148 %cmp = icmp ult i32 %shr, 15
149 ret i1 %cmp
150 }
151
152 ; 'lshr C2, x' produces [C2 >> (Width-1), C2]
153 define i1 @lshr_sgt_false(i32 %a) {
154 ; CHECK-LABEL: @lshr_sgt_false(
155 ; CHECK-NEXT: ret i1 false
156 ;
157 %shr = lshr i32 1, %a
158 %cmp = icmp sgt i32 %shr, 1
159 ret i1 %cmp
160 }
161
162 ; 'ashr x, C2' produces [INT_MIN >> C2, INT_MAX >> C2]
163 define i1 @ashr2(i32 %x) {
164 ; CHECK-LABEL: @ashr2(
165 ; CHECK-NEXT: ret i1 false
166 ;
167 %s = ashr i32 %x, 30
168 %c = icmp slt i32 %s, -5
169 ret i1 %c
170 }
171
172 ; 'ashr C2, x' produces [C2, C2 >> (Width-1)]
173 define i1 @ashr_sgt_false(i32 %a) {
174 ; CHECK-LABEL: @ashr_sgt_false(
175 ; CHECK-NEXT: ret i1 false
176 ;
177 %shr = ashr i32 -30, %a
178 %cmp = icmp sgt i32 %shr, -1
179 ret i1 %cmp
180 }
181
182 ; 'ashr C2, x' produces [C2, C2 >> (Width-1)]
183 define i1 @exact_ashr_sgt_false(i32 %a) {
184 ; CHECK-LABEL: @exact_ashr_sgt_false(
185 ; CHECK-NEXT: ret i1 false
186 ;
187 %shr = ashr exact i32 -30, %a
188 %cmp = icmp sgt i32 %shr, -15
189 ret i1 %cmp
190 }
191
192 ; 'or x, C2' produces [C2, UINT_MAX]
193 define i1 @or1(i32 %X) {
194 ; CHECK-LABEL: @or1(
195 ; CHECK-NEXT: ret i1 false
196 ;
197 %A = or i32 %X, 62
198 %B = icmp ult i32 %A, 50
199 ret i1 %B
200 }
201
202 ; 'and x, C2' produces [0, C2]
203 define i1 @and1(i32 %X) {
204 ; CHECK-LABEL: @and1(
205 ; CHECK-NEXT: ret i1 false
206 ;
207 %A = and i32 %X, 62
208 %B = icmp ugt i32 %A, 70
209 ret i1 %B
210 }
211
212 ; 'add nuw x, C2' produces [C2, UINT_MAX]
213 define i1 @tautological9(i32 %x) {
214 ; CHECK-LABEL: @tautological9(
215 ; CHECK-NEXT: ret i1 true
216 ;
217 %add = add nuw i32 %x, 13
218 %cmp = icmp ne i32 %add, 12
219 ret i1 %cmp
220 }
221