Skip to content

Commit dde1040

Browse files
committed
[InstCombine] handle trunc to i1 in foldLogOpOfMaskedICmps.
1 parent 5cbff43 commit dde1040

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3336,12 +3336,6 @@ Value *InstCombinerImpl::foldAndOrOfICmps(ICmpInst *LHS, ICmpInst *RHS,
33363336
}
33373337
}
33383338

3339-
// handle (roughly):
3340-
// (icmp ne (A & B), C) | (icmp ne (A & D), E)
3341-
// (icmp eq (A & B), C) & (icmp eq (A & D), E)
3342-
if (Value *V = foldLogOpOfMaskedICmps(LHS, RHS, IsAnd, IsLogical, Builder, Q))
3343-
return V;
3344-
33453339
if (Value *V =
33463340
foldAndOrOfICmpEqConstantAndICmp(LHS, RHS, IsAnd, IsLogical, Builder))
33473341
return V;
@@ -3516,6 +3510,13 @@ Value *InstCombinerImpl::foldBooleanAndOr(Value *LHS, Value *RHS,
35163510
if (!LHS->getType()->isIntOrIntVectorTy(1))
35173511
return nullptr;
35183512

3513+
// handle (roughly):
3514+
// (icmp ne (A & B), C) | (icmp ne (A & D), E)
3515+
// (icmp eq (A & B), C) & (icmp eq (A & D), E)
3516+
if (Value *V = foldLogOpOfMaskedICmps(LHS, RHS, IsAnd, IsLogical, Builder,
3517+
SQ.getWithInstruction(&I)))
3518+
return V;
3519+
35193520
if (auto *LHSCmp = dyn_cast<ICmpInst>(LHS))
35203521
if (auto *RHSCmp = dyn_cast<ICmpInst>(RHS))
35213522
if (Value *Res = foldAndOrOfICmps(LHSCmp, RHSCmp, I, IsAnd, IsLogical))

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,10 +1455,8 @@ define i1 @and_trunc_i1(i8 %a1, i8 %a2) {
14551455
define i1 @and_trunc_i1_wrong_const(i8 %a1, i8 %a2) {
14561456
; CHECK-LABEL: @and_trunc_i1_wrong_const(
14571457
; CHECK-NEXT: [[XOR:%.*]] = xor i8 [[A1:%.*]], [[A2:%.*]]
1458-
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[XOR]], 4
1459-
; CHECK-NEXT: [[LOBIT:%.*]] = trunc i8 [[XOR]] to i1
1460-
; CHECK-NEXT: [[LOBIT_INV:%.*]] = xor i1 [[LOBIT]], true
1461-
; CHECK-NEXT: [[AND:%.*]] = and i1 [[CMP]], [[LOBIT_INV]]
1458+
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[XOR]], -3
1459+
; CHECK-NEXT: [[AND:%.*]] = icmp eq i8 [[TMP1]], 0
14621460
; CHECK-NEXT: ret i1 [[AND]]
14631461
;
14641462
%xor = xor i8 %a1, %a2

llvm/test/Transforms/InstCombine/onehot_merge.ll

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,10 +1163,9 @@ define i1 @two_types_of_bittest(i8 %x, i8 %c) {
11631163
define i1 @trunc_bittest_and_icmp_bittest(i8 %x, i8 %c) {
11641164
; CHECK-LABEL: @trunc_bittest_and_icmp_bittest(
11651165
; 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]]
1166+
; CHECK-NEXT: [[TMP1:%.*]] = or i8 [[T0]], 1
1167+
; CHECK-NEXT: [[TMP2:%.*]] = and i8 [[X:%.*]], [[TMP1]]
1168+
; CHECK-NEXT: [[RET:%.*]] = icmp eq i8 [[TMP2]], [[TMP1]]
11701169
; CHECK-NEXT: ret i1 [[RET]]
11711170
;
11721171
%t0 = shl i8 1, %c
@@ -1180,11 +1179,9 @@ define i1 @trunc_bittest_and_icmp_bittest(i8 %x, i8 %c) {
11801179
define i1 @trunc_bittest_or_icmp_bittest(i8 %x, i8 %c) {
11811180
; CHECK-LABEL: @trunc_bittest_or_icmp_bittest(
11821181
; 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]]
1182+
; CHECK-NEXT: [[TMP1:%.*]] = or i8 [[T0]], 1
1183+
; CHECK-NEXT: [[TMP2:%.*]] = and i8 [[X:%.*]], [[TMP1]]
1184+
; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[TMP2]], [[TMP1]]
11881185
; CHECK-NEXT: ret i1 [[RET]]
11891186
;
11901187
%t0 = shl i8 1, %c

0 commit comments

Comments
 (0)