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
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; This test makes sure that all icmp instructions are eliminated.
; RUN: opt < %s -instcombine -S | FileCheck %s
@X = external global i32
define i1 @test1(i32 %A) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: ret i1 false
;
%B = icmp eq i32 %A, %A
; Never true
%C = icmp eq i32* @X, null
%D = and i1 %B, %C
ret i1 %D
}
define i1 @test2(i32 %A) {
; CHECK-LABEL: @test2(
; CHECK-NEXT: ret i1 true
;
%B = icmp ne i32 %A, %A
; Never false
%C = icmp ne i32* @X, null
%D = or i1 %B, %C
ret i1 %D
}
define i1 @test3(i32 %A) {
; CHECK-LABEL: @test3(
; CHECK-NEXT: ret i1 false
;
%B = icmp slt i32 %A, %A
ret i1 %B
}
define i1 @test4(i32 %A) {
; CHECK-LABEL: @test4(
; CHECK-NEXT: ret i1 false
;
%B = icmp sgt i32 %A, %A
ret i1 %B
}
define i1 @test5(i32 %A) {
; CHECK-LABEL: @test5(
; CHECK-NEXT: ret i1 true
;
%B = icmp sle i32 %A, %A
ret i1 %B
}
define i1 @test6(i32 %A) {
; CHECK-LABEL: @test6(
; CHECK-NEXT: ret i1 true
;
%B = icmp sge i32 %A, %A
ret i1 %B
}
define i1 @test7(i32 %A) {
; CHECK-LABEL: @test7(
; CHECK-NEXT: ret i1 true
;
%B = icmp uge i32 %A, 0
ret i1 %B
}
define i1 @test8(i32 %A) {
; CHECK-LABEL: @test8(
; CHECK-NEXT: ret i1 false
;
%B = icmp ult i32 %A, 0
ret i1 %B
}
;; test operations on boolean values these should all be eliminated$a
define i1 @test9(i1 %A) {
; CHECK-LABEL: @test9(
; CHECK-NEXT: ret i1 false
;
%B = icmp ult i1 %A, false
ret i1 %B
}
define i1 @test10(i1 %A) {
; CHECK-LABEL: @test10(
; CHECK-NEXT: ret i1 false
;
%B = icmp ugt i1 %A, true
ret i1 %B
}
define i1 @test11(i1 %A) {
; CHECK-LABEL: @test11(
; CHECK-NEXT: ret i1 true
;
%B = icmp ule i1 %A, true
ret i1 %B
}
define i1 @test12(i1 %A) {
; CHECK-LABEL: @test12(
; CHECK-NEXT: ret i1 true
;
%B = icmp uge i1 %A, false
ret i1 %B
}
define i1 @test13(i1 %A, i1 %B) {
; CHECK-LABEL: @test13(
; CHECK-NEXT: [[TMP1:%.*]] = xor i1 %B, true
; CHECK-NEXT: [[C:%.*]] = or i1 [[TMP1]], %A
; CHECK-NEXT: ret i1 [[C]]
;
%C = icmp uge i1 %A, %B
ret i1 %C
}
define <2 x i1> @test13vec(<2 x i1> %A, <2 x i1> %B) {
; CHECK-LABEL: @test13vec(
; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i1> %B, <i1 true, i1 true>
; CHECK-NEXT: [[C:%.*]] = or <2 x i1> [[TMP1]], %A
; CHECK-NEXT: ret <2 x i1> [[C]]
;
%C = icmp uge <2 x i1> %A, %B
ret <2 x i1> %C
}
define i1 @test14(i1 %A, i1 %B) {
; CHECK-LABEL: @test14(
; CHECK-NEXT: [[TMP1:%.*]] = xor i1 %A, %B
; CHECK-NEXT: [[C:%.*]] = xor i1 [[TMP1]], true
; CHECK-NEXT: ret i1 [[C]]
;
%C = icmp eq i1 %A, %B
ret i1 %C
}
define <3 x i1> @test14vec(<3 x i1> %A, <3 x i1> %B) {
; CHECK-LABEL: @test14vec(
; CHECK-NEXT: [[TMP1:%.*]] = xor <3 x i1> %A, %B
; CHECK-NEXT: [[C:%.*]] = xor <3 x i1> [[TMP1]], <i1 true, i1 true, i1 true>
; CHECK-NEXT: ret <3 x i1> [[C]]
;
%C = icmp eq <3 x i1> %A, %B
ret <3 x i1> %C
}
define i1 @bool_eq0(i64 %a) {
; CHECK-LABEL: @bool_eq0(
; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i64 %a, 1
; CHECK-NEXT: ret i1 [[TMP1]]
;
%b = icmp sgt i64 %a, 0
%c = icmp eq i64 %a, 1
%notc = icmp eq i1 %c, false
%and = and i1 %b, %notc
ret i1 %and
}
; This is equivalent to the previous test.
define i1 @xor_of_icmps(i64 %a) {
; CHECK-LABEL: @xor_of_icmps(
; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i64 %a, 1
; CHECK-NEXT: ret i1 [[TMP1]]
;
%b = icmp sgt i64 %a, 0
%c = icmp eq i64 %a, 1
%xor = xor i1 %c, %b
ret i1 %xor
}
; This is also equivalent to the previous test.
define i1 @xor_of_icmps_commute(i64 %a) {
; CHECK-LABEL: @xor_of_icmps_commute(
; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i64 %a, 1
; CHECK-NEXT: ret i1 [[TMP1]]
;
%b = icmp sgt i64 %a, 0
%c = icmp eq i64 %a, 1
%xor = xor i1 %b, %c
ret i1 %xor
}
; FIXME: This is (a != 5).
define i1 @xor_of_icmps_folds_more(i64 %a) {
; CHECK-LABEL: @xor_of_icmps_folds_more(
; CHECK-NEXT: [[B:%.*]] = icmp sgt i64 %a, 4
; CHECK-NEXT: [[C:%.*]] = icmp slt i64 %a, 6
; CHECK-NEXT: [[XOR:%.*]] = xor i1 [[B]], [[C]]
; CHECK-NEXT: ret i1 [[XOR]]
;
%b = icmp sgt i64 %a, 4
%c = icmp slt i64 %a, 6
%xor = xor i1 %b, %c
ret i1 %xor
}
; https://bugs.llvm.org/show_bug.cgi?id=2844
define i32 @PR2844(i32 %x) {
; CHECK-LABEL: @PR2844(
; CHECK-NEXT: [[A:%.*]] = icmp ne i32 %x, 0
; CHECK-NEXT: [[B:%.*]] = icmp sgt i32 %x, -638208502
; CHECK-NEXT: [[TMP1:%.*]] = and i1 [[A]], [[B]]
; CHECK-NEXT: [[SEL:%.*]] = zext i1 [[TMP1]] to i32
; CHECK-NEXT: ret i32 [[SEL]]
;
%A = icmp eq i32 %x, 0
%B = icmp slt i32 %x, -638208501
%or = or i1 %A, %B
%sel = select i1 %or, i32 0, i32 1
ret i32 %sel
}
define i1 @test16(i32 %A) {
; CHECK-LABEL: @test16(
; CHECK-NEXT: ret i1 false
;
%B = and i32 %A, 5
; Is never true
%C = icmp eq i32 %B, 8
ret i1 %C
}
define i1 @test17(i8 %A) {
; CHECK-LABEL: @test17(
; CHECK-NEXT: ret i1 false
;
%B = or i8 %A, 1
; Always false
%C = icmp eq i8 %B, 2
ret i1 %C
}
define i1 @test18(i1 %C, i32 %a) {
; CHECK-LABEL: @test18(
; CHECK-NEXT: entry:
; CHECK-NEXT: br i1 %C, label %endif, label %else
; CHECK: else:
; CHECK-NEXT: br label %endif
; CHECK: endif:
; CHECK-NEXT: ret i1 true
;
entry:
br i1 %C, label %endif, label %else
else:
br label %endif
endif:
%b.0 = phi i32 [ 0, %entry ], [ 1, %else ]
%tmp.4 = icmp slt i32 %b.0, 123
ret i1 %tmp.4
}
define i1 @test19(i1 %A, i1 %B) {
; CHECK-LABEL: @test19(
; CHECK-NEXT: [[TMP1:%.*]] = xor i1 %A, %B
; CHECK-NEXT: [[C:%.*]] = xor i1 [[TMP1]], true
; CHECK-NEXT: ret i1 [[C]]
;
%a = zext i1 %A to i32
%b = zext i1 %B to i32
%C = icmp eq i32 %a, %b
ret i1 %C
}
define i32 @test20(i32 %A) {
; CHECK-LABEL: @test20(
; CHECK-NEXT: [[B:%.*]] = and i32 %A, 1
; CHECK-NEXT: ret i32 [[B]]
;
%B = and i32 %A, 1
%C = icmp ne i32 %B, 0
%D = zext i1 %C to i32
ret i32 %D
}
define <2 x i32> @test20vec(<2 x i32> %A) {
; CHECK-LABEL: @test20vec(
; CHECK-NEXT: [[B:%.*]] = and <2 x i32> [[A:%.*]], <i32 1, i32 1>
; CHECK-NEXT: ret <2 x i32> [[B]]
;
%B = and <2 x i32> %A, <i32 1, i32 1>
%C = icmp ne <2 x i32> %B, zeroinitializer
%D = zext <2 x i1> %C to <2 x i32>
ret <2 x i32> %D
}
define i32 @test21(i32 %a) {
; CHECK-LABEL: @test21(
; CHECK-NEXT: [[TMP_6:%.*]] = lshr i32 %a, 2
; CHECK-NEXT: [[TMP_6_LOBIT:%.*]] = and i32 [[TMP_6]], 1
; CHECK-NEXT: ret i32 [[TMP_6_LOBIT]]
;
%tmp.6 = and i32 %a, 4
%not.tmp.7 = icmp ne i32 %tmp.6, 0
%retval = zext i1 %not.tmp.7 to i32
ret i32 %retval
}
define <2 x i32> @test21vec(<2 x i32> %a) {
; CHECK-LABEL: @test21vec(
; CHECK-NEXT: [[TMP_6:%.*]] = lshr <2 x i32> [[A:%.*]], <i32 2, i32 2>
; CHECK-NEXT: [[TMP_6_LOBIT:%.*]] = and <2 x i32> [[TMP_6]], <i32 1, i32 1>
; CHECK-NEXT: ret <2 x i32> [[TMP_6_LOBIT]]
;
%tmp.6 = and <2 x i32> %a, <i32 4, i32 4>
%not.tmp.7 = icmp ne <2 x i32> %tmp.6, zeroinitializer
%retval = zext <2 x i1> %not.tmp.7 to <2 x i32>
ret <2 x i32> %retval
}
define i1 @test22(i32 %A, i32 %X) {
; CHECK-LABEL: @test22(
; CHECK-NEXT: ret i1 true
;
%B = and i32 %A, 100663295
%C = icmp ult i32 %B, 268435456
%Y = and i32 %X, 7
%Z = icmp sgt i32 %Y, -1
%R = or i1 %C, %Z
ret i1 %R
}
define i32 @test23(i32 %a) {
; CHECK-LABEL: @test23(
; CHECK-NEXT: [[TMP_1:%.*]] = and i32 %a, 1
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[TMP_1]], 1
; CHECK-NEXT: ret i32 [[TMP1]]
;
%tmp.1 = and i32 %a, 1
%tmp.2 = icmp eq i32 %tmp.1, 0
%tmp.3 = zext i1 %tmp.2 to i32
ret i32 %tmp.3
}
define <2 x i32> @test23vec(<2 x i32> %a) {
; CHECK-LABEL: @test23vec(
; CHECK-NEXT: [[TMP_1:%.*]] = and <2 x i32> [[A:%.*]], <i32 1, i32 1>
; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i32> [[TMP_1]], <i32 1, i32 1>
; CHECK-NEXT: ret <2 x i32> [[TMP1]]
;
%tmp.1 = and <2 x i32> %a, <i32 1, i32 1>
%tmp.2 = icmp eq <2 x i32> %tmp.1, zeroinitializer
%tmp.3 = zext <2 x i1> %tmp.2 to <2 x i32>
ret <2 x i32> %tmp.3
}
define i32 @test24(i32 %a) {
; CHECK-LABEL: @test24(
; CHECK-NEXT: [[TMP_1:%.*]] = lshr i32 %a, 2
; CHECK-NEXT: [[TMP_1_LOBIT:%.*]] = and i32 [[TMP_1]], 1
; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[TMP_1_LOBIT]], 1
; CHECK-NEXT: ret i32 [[TMP1]]
;
%tmp1 = and i32 %a, 4
%tmp.1 = lshr i32 %tmp1, 2
%tmp.2 = icmp eq i32 %tmp.1, 0
%tmp.3 = zext i1 %tmp.2 to i32
ret i32 %tmp.3
}
define <2 x i32> @test24vec(<2 x i32> %a) {
; CHECK-LABEL: @test24vec(
; CHECK-NEXT: [[TMP_1:%.*]] = lshr <2 x i32> [[A:%.*]], <i32 2, i32 2>
; CHECK-NEXT: [[TMP_1_LOBIT:%.*]] = and <2 x i32> [[TMP_1]], <i32 1, i32 1>
; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i32> [[TMP_1_LOBIT]], <i32 1, i32 1>
; CHECK-NEXT: ret <2 x i32> [[TMP1]]
;
%tmp1 = and <2 x i32> %a, <i32 4, i32 4>
%tmp.1 = lshr <2 x i32> %tmp1, <i32 2, i32 2>
%tmp.2 = icmp eq <2 x i32> %tmp.1, zeroinitializer
%tmp.3 = zext <2 x i1> %tmp.2 to <2 x i32>
ret <2 x i32> %tmp.3
}
define i1 @test25(i32 %A) {
; CHECK-LABEL: @test25(
; CHECK-NEXT: ret i1 false
;
%B = and i32 %A, 2
%C = icmp ugt i32 %B, 2
ret i1 %C
}
|