Skip to content

Commit

Permalink
[InstCombine] Don't simplify icmp eq/ne OneUse(A ^ Cst1), Cst2 in f…
Browse files Browse the repository at this point in the history
…oldICmpEquality

This special case will be handled in foldICmpXorConstant later.
See also commit e9cb50a.
  • Loading branch information
dtcxzyw committed Sep 29, 2023
1 parent 4fa812b commit c4e2fcf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
12 changes: 2 additions & 10 deletions llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion llvm/test/Transforms/InstCombine/icmp-equality-xor.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c4e2fcf

Please sign in to comment.