Skip to content

Commit c4e2fcf

Browse files
committed
[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 e9cb50a.
1 parent 4fa812b commit c4e2fcf

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5450,16 +5450,8 @@ Instruction *InstCombinerImpl::foldICmpEquality(ICmpInst &I) {
54505450
Constant *Cst;
54515451
if (match(&I, m_c_ICmp(PredUnused,
54525452
m_OneUse(m_Xor(m_Value(A), m_ImmConstant(Cst))),
5453-
m_Value(B)))) {
5454-
// Special case:
5455-
// icmp eq/ne OneUse(A ^ Cst1), Cst2 --> icmp eq/ne A, Cst1 ^ Cst2
5456-
// We handle this to avoid infinite loops.
5457-
if (match(B, m_ImmConstant())) {
5458-
if (Value *V = simplifyXorInst(B, Cst, SQ.getWithInstruction(&I)))
5459-
return new ICmpInst(Pred, A, V);
5460-
} else
5461-
return new ICmpInst(Pred, Builder.CreateXor(A, B), Cst);
5462-
}
5453+
m_CombineAnd(m_Value(B), m_Unless(m_ImmConstant())))))
5454+
return new ICmpInst(Pred, Builder.CreateXor(A, B), Cst);
54635455

54645456
return nullptr;
54655457
}

llvm/test/Transforms/InstCombine/icmp-equality-xor.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ define i1 @foo2(i32 %x, i32 %y) {
136136
define <2 x i1> @foo3(<2 x i8> %x) {
137137
; CHECK-LABEL: @foo3(
138138
; CHECK-NEXT: entry:
139-
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i8> [[X:%.*]], <i8 -9, i8 -80>
139+
; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i8> [[X:%.*]], <i8 -2, i8 -1>
140+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i8> [[XOR]], <i8 9, i8 79>
140141
; CHECK-NEXT: ret <2 x i1> [[CMP]]
141142
;
142143
entry:

0 commit comments

Comments
 (0)