Skip to content

Commit 5cbff43

Browse files
committed
[InstCombine] Test for trunc to i1 in foldLogOpOfMaskedICmps.
1 parent 13245ce commit 5cbff43

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

llvm/test/Transforms/InstCombine/onehot_merge.ll

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,3 +1159,39 @@ define i1 @two_types_of_bittest(i8 %x, i8 %c) {
11591159
%ret = and i1 %icmp1, %icmp2
11601160
ret i1 %ret
11611161
}
1162+
1163+
define i1 @trunc_bittest_and_icmp_bittest(i8 %x, i8 %c) {
1164+
; CHECK-LABEL: @trunc_bittest_and_icmp_bittest(
1165+
; CHECK-NEXT: [[T0:%.*]] = shl nuw i8 1, [[C:%.*]]
1166+
; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[X:%.*]] to i1
1167+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], [[T0]]
1168+
; CHECK-NEXT: [[ICMP2:%.*]] = icmp ne i8 [[AND]], 0
1169+
; CHECK-NEXT: [[RET:%.*]] = and i1 [[ICMP2]], [[TRUNC]]
1170+
; CHECK-NEXT: ret i1 [[RET]]
1171+
;
1172+
%t0 = shl i8 1, %c
1173+
%trunc = trunc i8 %x to i1
1174+
%and = and i8 %x, %t0
1175+
%icmp2 = icmp ne i8 %and, 0
1176+
%ret = and i1 %trunc, %icmp2
1177+
ret i1 %ret
1178+
}
1179+
1180+
define i1 @trunc_bittest_or_icmp_bittest(i8 %x, i8 %c) {
1181+
; CHECK-LABEL: @trunc_bittest_or_icmp_bittest(
1182+
; CHECK-NEXT: [[T0:%.*]] = shl nuw i8 1, [[C:%.*]]
1183+
; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[X:%.*]] to i1
1184+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], [[T0]]
1185+
; CHECK-NEXT: [[ICMP2:%.*]] = icmp eq i8 [[AND]], 0
1186+
; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[TRUNC]], true
1187+
; CHECK-NEXT: [[RET:%.*]] = or i1 [[ICMP2]], [[NOT]]
1188+
; CHECK-NEXT: ret i1 [[RET]]
1189+
;
1190+
%t0 = shl i8 1, %c
1191+
%trunc = trunc i8 %x to i1
1192+
%and = and i8 %x, %t0
1193+
%icmp2 = icmp eq i8 %and, 0
1194+
%not = xor i1 %trunc, true
1195+
%ret = or i1 %not, %icmp2
1196+
ret i1 %ret
1197+
}

0 commit comments

Comments
 (0)