Skip to content

Commit be4b836

Browse files
committed
[InstCombine] Add tests for "eq of parts" with logical op (NFC)
We currently only handle this with a bitwise and/or instruction, but not a logical.
1 parent 352df10 commit be4b836

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

llvm/test/Transforms/InstCombine/eq-of-parts.ll

+62
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,37 @@ define i1 @eq_21_extra_use_eq2(i32 %x, i32 %y) {
352352
ret i1 %c.210
353353
}
354354

355+
; Logical and instead of bitwise and.
356+
357+
define i1 @eq_21_logical(i32 %x, i32 %y) {
358+
; CHECK-LABEL: @eq_21_logical(
359+
; CHECK-NEXT: [[X_321:%.*]] = lshr i32 [[X:%.*]], 8
360+
; CHECK-NEXT: [[X_1:%.*]] = trunc i32 [[X_321]] to i8
361+
; CHECK-NEXT: [[X_32:%.*]] = lshr i32 [[X]], 16
362+
; CHECK-NEXT: [[X_2:%.*]] = trunc i32 [[X_32]] to i8
363+
; CHECK-NEXT: [[Y_321:%.*]] = lshr i32 [[Y:%.*]], 8
364+
; CHECK-NEXT: [[Y_1:%.*]] = trunc i32 [[Y_321]] to i8
365+
; CHECK-NEXT: [[Y_32:%.*]] = lshr i32 [[Y]], 16
366+
; CHECK-NEXT: [[Y_2:%.*]] = trunc i32 [[Y_32]] to i8
367+
; CHECK-NEXT: [[C_1:%.*]] = icmp eq i8 [[X_1]], [[Y_1]]
368+
; CHECK-NEXT: [[C_2:%.*]] = icmp eq i8 [[X_2]], [[Y_2]]
369+
; CHECK-NEXT: [[C_210:%.*]] = select i1 [[C_2]], i1 [[C_1]], i1 false
370+
; CHECK-NEXT: ret i1 [[C_210]]
371+
;
372+
%x.321 = lshr i32 %x, 8
373+
%x.1 = trunc i32 %x.321 to i8
374+
%x.32 = lshr i32 %x, 16
375+
%x.2 = trunc i32 %x.32 to i8
376+
%y.321 = lshr i32 %y, 8
377+
%y.1 = trunc i32 %y.321 to i8
378+
%y.32 = lshr i32 %y, 16
379+
%y.2 = trunc i32 %y.32 to i8
380+
%c.1 = icmp eq i8 %x.1, %y.1
381+
%c.2 = icmp eq i8 %x.2, %y.2
382+
%c.210 = select i1 %c.2, i1 %c.1, i1 false
383+
ret i1 %c.210
384+
}
385+
355386
; Negative tests.
356387

357388
define i1 @eq_21_wrong_op1(i32 %x, i32 %y, i32 %z) {
@@ -992,6 +1023,37 @@ define i1 @ne_21_extra_use_ne2(i32 %x, i32 %y) {
9921023
ret i1 %c.210
9931024
}
9941025

1026+
; Logical or instead of bitwise or.
1027+
1028+
define i1 @ne_21_logical(i32 %x, i32 %y) {
1029+
; CHECK-LABEL: @ne_21_logical(
1030+
; CHECK-NEXT: [[X_321:%.*]] = lshr i32 [[X:%.*]], 8
1031+
; CHECK-NEXT: [[X_1:%.*]] = trunc i32 [[X_321]] to i8
1032+
; CHECK-NEXT: [[X_32:%.*]] = lshr i32 [[X]], 16
1033+
; CHECK-NEXT: [[X_2:%.*]] = trunc i32 [[X_32]] to i8
1034+
; CHECK-NEXT: [[Y_321:%.*]] = lshr i32 [[Y:%.*]], 8
1035+
; CHECK-NEXT: [[Y_1:%.*]] = trunc i32 [[Y_321]] to i8
1036+
; CHECK-NEXT: [[Y_32:%.*]] = lshr i32 [[Y]], 16
1037+
; CHECK-NEXT: [[Y_2:%.*]] = trunc i32 [[Y_32]] to i8
1038+
; CHECK-NEXT: [[C_1:%.*]] = icmp ne i8 [[X_1]], [[Y_1]]
1039+
; CHECK-NEXT: [[C_2:%.*]] = icmp ne i8 [[X_2]], [[Y_2]]
1040+
; CHECK-NEXT: [[C_210:%.*]] = select i1 [[C_2]], i1 true, i1 [[C_1]]
1041+
; CHECK-NEXT: ret i1 [[C_210]]
1042+
;
1043+
%x.321 = lshr i32 %x, 8
1044+
%x.1 = trunc i32 %x.321 to i8
1045+
%x.32 = lshr i32 %x, 16
1046+
%x.2 = trunc i32 %x.32 to i8
1047+
%y.321 = lshr i32 %y, 8
1048+
%y.1 = trunc i32 %y.321 to i8
1049+
%y.32 = lshr i32 %y, 16
1050+
%y.2 = trunc i32 %y.32 to i8
1051+
%c.1 = icmp ne i8 %x.1, %y.1
1052+
%c.2 = icmp ne i8 %x.2, %y.2
1053+
%c.210 = select i1 %c.2, i1 true, i1 %c.1
1054+
ret i1 %c.210
1055+
}
1056+
9951057
; Negative tests.
9961058

9971059
define i1 @ne_21_wrong_op1(i32 %x, i32 %y, i32 %z) {

0 commit comments

Comments
 (0)