Skip to content

Commit b340ec7

Browse files
author
git apple-llvm automerger
committed
Merge commit 'e9cb50a1e351' from llvm.org/main into next
2 parents e80034c + e9cb50a commit b340ec7

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5450,8 +5450,16 @@ 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-
return new ICmpInst(Pred, Builder.CreateXor(A, B), 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+
}
54555463

54565464
return nullptr;
54575465
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,16 @@ define i1 @foo2(i32 %x, i32 %y) {
131131
%cmp = icmp eq i32 %and, %and1
132132
ret i1 %cmp
133133
}
134+
135+
; tests from PR67783
136+
define <2 x i1> @foo3(<2 x i8> %x) {
137+
; CHECK-LABEL: @foo3(
138+
; CHECK-NEXT: entry:
139+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i8> [[X:%.*]], <i8 -9, i8 -80>
140+
; CHECK-NEXT: ret <2 x i1> [[CMP]]
141+
;
142+
entry:
143+
%xor = xor <2 x i8> %x, <i8 -2, i8 -1>
144+
%cmp = icmp ne <2 x i8> %xor, <i8 9, i8 79>
145+
ret <2 x i1> %cmp
146+
}

0 commit comments

Comments
 (0)