[InstCombine] Don't simplify icmp eq/ne OneUse(A ^ Cst1), Cst2 in foldICmpEquality

This special case will be handled in foldICmpXorConstant later.
See also commit e9cb50a1e3.
This commit is contained in:
Yingwei Zheng
2023-09-29 21:18:15 +08:00
parent 4fa812bb52
commit c4e2fcff78
2 changed files with 4 additions and 11 deletions

View File

@@ -5450,16 +5450,8 @@ Instruction *InstCombinerImpl::foldICmpEquality(ICmpInst &I) {
Constant *Cst;
if (match(&I, m_c_ICmp(PredUnused,
m_OneUse(m_Xor(m_Value(A), m_ImmConstant(Cst))),
m_Value(B)))) {
// Special case:
// icmp eq/ne OneUse(A ^ Cst1), Cst2 --> icmp eq/ne A, Cst1 ^ Cst2
// We handle this to avoid infinite loops.
if (match(B, m_ImmConstant())) {
if (Value *V = simplifyXorInst(B, Cst, SQ.getWithInstruction(&I)))
return new ICmpInst(Pred, A, V);
} else
return new ICmpInst(Pred, Builder.CreateXor(A, B), Cst);
}
m_CombineAnd(m_Value(B), m_Unless(m_ImmConstant())))))
return new ICmpInst(Pred, Builder.CreateXor(A, B), Cst);
return nullptr;
}

View File

@@ -136,7 +136,8 @@ define i1 @foo2(i32 %x, i32 %y) {
define <2 x i1> @foo3(<2 x i8> %x) {
; CHECK-LABEL: @foo3(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i8> [[X:%.*]], <i8 -9, i8 -80>
; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i8> [[X:%.*]], <i8 -2, i8 -1>
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i8> [[XOR]], <i8 9, i8 79>
; CHECK-NEXT: ret <2 x i1> [[CMP]]
;
entry: