Skip to content

Commit 56ae4f2

Browse files
committed
[InstCombine] add tests for logical and/or with not ops; NFC
1 parent ee9bb25 commit 56ae4f2

File tree

2 files changed

+295
-0
lines changed

2 files changed

+295
-0
lines changed

llvm/test/Transforms/InstCombine/not.ll

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,60 @@ define i8 @not_or_neg_use2(i8 %x, i8 %y) {
467467
%not = xor i8 %o, -1
468468
ret i8 %not
469469
}
470+
471+
define i1 @not_select_bool(i1 %x, i1 %y, i1 %z) {
472+
; CHECK-LABEL: @not_select_bool(
473+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 [[Z:%.*]]
474+
; CHECK-NEXT: [[R:%.*]] = xor i1 [[SEL]], true
475+
; CHECK-NEXT: ret i1 [[R]]
476+
;
477+
%sel = select i1 %x, i1 %y, i1 %z
478+
%r = xor i1 %sel, true
479+
ret i1 %r
480+
}
481+
482+
define i1 @not_select_bool_const1(i1 %x, i1 %y) {
483+
; CHECK-LABEL: @not_select_bool_const1(
484+
; CHECK-NEXT: [[NOT_X:%.*]] = xor i1 [[X:%.*]], true
485+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[NOT_X]], i1 true, i1 [[Y:%.*]]
486+
; CHECK-NEXT: [[R:%.*]] = xor i1 [[SEL]], true
487+
; CHECK-NEXT: ret i1 [[R]]
488+
;
489+
%sel = select i1 %x, i1 %y, i1 true
490+
%r = xor i1 %sel, true
491+
ret i1 %r
492+
}
493+
494+
define i1 @not_select_bool_const2(i1 %x, i1 %y) {
495+
; CHECK-LABEL: @not_select_bool_const2(
496+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false
497+
; CHECK-NEXT: [[R:%.*]] = xor i1 [[SEL]], true
498+
; CHECK-NEXT: ret i1 [[R]]
499+
;
500+
%sel = select i1 %x, i1 %y, i1 false
501+
%r = xor i1 %sel, true
502+
ret i1 %r
503+
}
504+
505+
define i1 @not_select_bool_const3(i1 %x, i1 %y) {
506+
; CHECK-LABEL: @not_select_bool_const3(
507+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
508+
; CHECK-NEXT: [[R:%.*]] = xor i1 [[SEL]], true
509+
; CHECK-NEXT: ret i1 [[R]]
510+
;
511+
%sel = select i1 %x, i1 true, i1 %y
512+
%r = xor i1 %sel, true
513+
ret i1 %r
514+
}
515+
516+
define i1 @not_select_bool_const4(i1 %x, i1 %y) {
517+
; CHECK-LABEL: @not_select_bool_const4(
518+
; CHECK-NEXT: [[NOT_X:%.*]] = xor i1 [[X:%.*]], true
519+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[NOT_X]], i1 [[Y:%.*]], i1 false
520+
; CHECK-NEXT: [[R:%.*]] = xor i1 [[SEL]], true
521+
; CHECK-NEXT: ret i1 [[R]]
522+
;
523+
%sel = select i1 %x, i1 false, i1 %y
524+
%r = xor i1 %sel, true
525+
ret i1 %r
526+
}

llvm/test/Transforms/InstCombine/select-and-or.ll

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
22
; RUN: opt -S -instcombine < %s | FileCheck %s
33

4+
declare void @use(i1)
5+
46
; Should not be converted to "and", which has different poison semantics.
57
define i1 @logical_and(i1 %a, i1 %b) {
68
; CHECK-LABEL: @logical_and(
@@ -176,3 +178,239 @@ define i1 @logical_and_noundef_b(i1 %a, i1 noundef %b) {
176178
%res = select i1 %a, i1 %b, i1 false
177179
ret i1 %res
178180
}
181+
182+
define i1 @not_not_true(i1 %x, i1 %y) {
183+
; CHECK-LABEL: @not_not_true(
184+
; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
185+
; CHECK-NEXT: [[R:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[NOTY]]
186+
; CHECK-NEXT: ret i1 [[R]]
187+
;
188+
%notx = xor i1 %x, true
189+
%noty = xor i1 %y, true
190+
%r = select i1 %notx, i1 %noty, i1 true
191+
ret i1 %r
192+
}
193+
194+
define i1 @not_not_false(i1 %x, i1 %y) {
195+
; CHECK-LABEL: @not_not_false(
196+
; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true
197+
; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
198+
; CHECK-NEXT: [[R:%.*]] = select i1 [[NOTX]], i1 [[NOTY]], i1 false
199+
; CHECK-NEXT: ret i1 [[R]]
200+
;
201+
%notx = xor i1 %x, true
202+
%noty = xor i1 %y, true
203+
%r = select i1 %notx, i1 %noty, i1 false
204+
ret i1 %r
205+
}
206+
207+
define i1 @not_true_not(i1 %x, i1 %y) {
208+
; CHECK-LABEL: @not_true_not(
209+
; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true
210+
; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
211+
; CHECK-NEXT: [[R:%.*]] = select i1 [[NOTX]], i1 true, i1 [[NOTY]]
212+
; CHECK-NEXT: ret i1 [[R]]
213+
;
214+
%notx = xor i1 %x, true
215+
%noty = xor i1 %y, true
216+
%r = select i1 %notx, i1 true, i1 %noty
217+
ret i1 %r
218+
}
219+
220+
define i1 @not_false_not(i1 %x, i1 %y) {
221+
; CHECK-LABEL: @not_false_not(
222+
; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
223+
; CHECK-NEXT: [[R:%.*]] = select i1 [[X:%.*]], i1 [[NOTY]], i1 false
224+
; CHECK-NEXT: ret i1 [[R]]
225+
;
226+
%notx = xor i1 %x, true
227+
%noty = xor i1 %y, true
228+
%r = select i1 %notx, i1 false, i1 %noty
229+
ret i1 %r
230+
}
231+
232+
define i1 @not_not_true_use1(i1 %x, i1 %y) {
233+
; CHECK-LABEL: @not_not_true_use1(
234+
; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true
235+
; CHECK-NEXT: call void @use(i1 [[NOTX]])
236+
; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
237+
; CHECK-NEXT: [[R:%.*]] = select i1 [[X]], i1 true, i1 [[NOTY]]
238+
; CHECK-NEXT: ret i1 [[R]]
239+
;
240+
%notx = xor i1 %x, true
241+
call void @use(i1 %notx)
242+
%noty = xor i1 %y, true
243+
%r = select i1 %notx, i1 %noty, i1 true
244+
ret i1 %r
245+
}
246+
247+
define i1 @not_not_false_use1(i1 %x, i1 %y) {
248+
; CHECK-LABEL: @not_not_false_use1(
249+
; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true
250+
; CHECK-NEXT: call void @use(i1 [[NOTX]])
251+
; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
252+
; CHECK-NEXT: [[R:%.*]] = select i1 [[NOTX]], i1 [[NOTY]], i1 false
253+
; CHECK-NEXT: ret i1 [[R]]
254+
;
255+
%notx = xor i1 %x, true
256+
call void @use(i1 %notx)
257+
%noty = xor i1 %y, true
258+
%r = select i1 %notx, i1 %noty, i1 false
259+
ret i1 %r
260+
}
261+
262+
define i1 @not_true_not_use1(i1 %x, i1 %y) {
263+
; CHECK-LABEL: @not_true_not_use1(
264+
; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true
265+
; CHECK-NEXT: call void @use(i1 [[NOTX]])
266+
; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
267+
; CHECK-NEXT: [[R:%.*]] = select i1 [[NOTX]], i1 true, i1 [[NOTY]]
268+
; CHECK-NEXT: ret i1 [[R]]
269+
;
270+
%notx = xor i1 %x, true
271+
call void @use(i1 %notx)
272+
%noty = xor i1 %y, true
273+
%r = select i1 %notx, i1 true, i1 %noty
274+
ret i1 %r
275+
}
276+
277+
define i1 @not_false_not_use1(i1 %x, i1 %y) {
278+
; CHECK-LABEL: @not_false_not_use1(
279+
; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true
280+
; CHECK-NEXT: call void @use(i1 [[NOTX]])
281+
; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
282+
; CHECK-NEXT: [[R:%.*]] = select i1 [[X]], i1 [[NOTY]], i1 false
283+
; CHECK-NEXT: ret i1 [[R]]
284+
;
285+
%notx = xor i1 %x, true
286+
call void @use(i1 %notx)
287+
%noty = xor i1 %y, true
288+
%r = select i1 %notx, i1 false, i1 %noty
289+
ret i1 %r
290+
}
291+
292+
define i1 @not_not_true_use2(i1 %x, i1 %y) {
293+
; CHECK-LABEL: @not_not_true_use2(
294+
; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
295+
; CHECK-NEXT: call void @use(i1 [[NOTY]])
296+
; CHECK-NEXT: [[R:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[NOTY]]
297+
; CHECK-NEXT: ret i1 [[R]]
298+
;
299+
%notx = xor i1 %x, true
300+
%noty = xor i1 %y, true
301+
call void @use(i1 %noty)
302+
%r = select i1 %notx, i1 %noty, i1 true
303+
ret i1 %r
304+
}
305+
306+
define i1 @not_not_false_use2(i1 %x, i1 %y) {
307+
; CHECK-LABEL: @not_not_false_use2(
308+
; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true
309+
; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
310+
; CHECK-NEXT: call void @use(i1 [[NOTY]])
311+
; CHECK-NEXT: [[R:%.*]] = select i1 [[NOTX]], i1 [[NOTY]], i1 false
312+
; CHECK-NEXT: ret i1 [[R]]
313+
;
314+
%notx = xor i1 %x, true
315+
%noty = xor i1 %y, true
316+
call void @use(i1 %noty)
317+
%r = select i1 %notx, i1 %noty, i1 false
318+
ret i1 %r
319+
}
320+
321+
define i1 @not_true_not_use2(i1 %x, i1 %y) {
322+
; CHECK-LABEL: @not_true_not_use2(
323+
; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true
324+
; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
325+
; CHECK-NEXT: call void @use(i1 [[NOTY]])
326+
; CHECK-NEXT: [[R:%.*]] = select i1 [[NOTX]], i1 true, i1 [[NOTY]]
327+
; CHECK-NEXT: ret i1 [[R]]
328+
;
329+
%notx = xor i1 %x, true
330+
%noty = xor i1 %y, true
331+
call void @use(i1 %noty)
332+
%r = select i1 %notx, i1 true, i1 %noty
333+
ret i1 %r
334+
}
335+
336+
define i1 @not_false_not_use2(i1 %x, i1 %y) {
337+
; CHECK-LABEL: @not_false_not_use2(
338+
; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
339+
; CHECK-NEXT: call void @use(i1 [[NOTY]])
340+
; CHECK-NEXT: [[R:%.*]] = select i1 [[X:%.*]], i1 [[NOTY]], i1 false
341+
; CHECK-NEXT: ret i1 [[R]]
342+
;
343+
%notx = xor i1 %x, true
344+
%noty = xor i1 %y, true
345+
call void @use(i1 %noty)
346+
%r = select i1 %notx, i1 false, i1 %noty
347+
ret i1 %r
348+
}
349+
350+
define i1 @not_not_true_use3(i1 %x, i1 %y) {
351+
; CHECK-LABEL: @not_not_true_use3(
352+
; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true
353+
; CHECK-NEXT: call void @use(i1 [[NOTX]])
354+
; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
355+
; CHECK-NEXT: call void @use(i1 [[NOTY]])
356+
; CHECK-NEXT: [[R:%.*]] = select i1 [[X]], i1 true, i1 [[NOTY]]
357+
; CHECK-NEXT: ret i1 [[R]]
358+
;
359+
%notx = xor i1 %x, true
360+
call void @use(i1 %notx)
361+
%noty = xor i1 %y, true
362+
call void @use(i1 %noty)
363+
%r = select i1 %notx, i1 %noty, i1 true
364+
ret i1 %r
365+
}
366+
367+
define i1 @not_not_false_use3(i1 %x, i1 %y) {
368+
; CHECK-LABEL: @not_not_false_use3(
369+
; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true
370+
; CHECK-NEXT: call void @use(i1 [[NOTX]])
371+
; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
372+
; CHECK-NEXT: call void @use(i1 [[NOTY]])
373+
; CHECK-NEXT: [[R:%.*]] = select i1 [[NOTX]], i1 [[NOTY]], i1 false
374+
; CHECK-NEXT: ret i1 [[R]]
375+
;
376+
%notx = xor i1 %x, true
377+
call void @use(i1 %notx)
378+
%noty = xor i1 %y, true
379+
call void @use(i1 %noty)
380+
%r = select i1 %notx, i1 %noty, i1 false
381+
ret i1 %r
382+
}
383+
384+
define i1 @not_true_not_use3(i1 %x, i1 %y) {
385+
; CHECK-LABEL: @not_true_not_use3(
386+
; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true
387+
; CHECK-NEXT: call void @use(i1 [[NOTX]])
388+
; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
389+
; CHECK-NEXT: call void @use(i1 [[NOTY]])
390+
; CHECK-NEXT: [[R:%.*]] = select i1 [[NOTX]], i1 true, i1 [[NOTY]]
391+
; CHECK-NEXT: ret i1 [[R]]
392+
;
393+
%notx = xor i1 %x, true
394+
call void @use(i1 %notx)
395+
%noty = xor i1 %y, true
396+
call void @use(i1 %noty)
397+
%r = select i1 %notx, i1 true, i1 %noty
398+
ret i1 %r
399+
}
400+
401+
define i1 @not_false_not_use3(i1 %x, i1 %y) {
402+
; CHECK-LABEL: @not_false_not_use3(
403+
; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true
404+
; CHECK-NEXT: call void @use(i1 [[NOTX]])
405+
; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
406+
; CHECK-NEXT: call void @use(i1 [[NOTY]])
407+
; CHECK-NEXT: [[R:%.*]] = select i1 [[X]], i1 [[NOTY]], i1 false
408+
; CHECK-NEXT: ret i1 [[R]]
409+
;
410+
%notx = xor i1 %x, true
411+
call void @use(i1 %notx)
412+
%noty = xor i1 %y, true
413+
call void @use(i1 %noty)
414+
%r = select i1 %notx, i1 false, i1 %noty
415+
ret i1 %r
416+
}

0 commit comments

Comments
 (0)