[llvm] c4e2fcf - [InstCombine] Don't simplify `icmp eq/ne OneUse(A ^ Cst1), Cst2` in foldICmpEquality
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 29 06:22:04 PDT 2023
Author: Yingwei Zheng
Date: 2023-09-29T21:21:00+08:00
New Revision: c4e2fcff788025415b523486efdbdac4f2b08c1e
URL: https://github.com/llvm/llvm-project/commit/c4e2fcff788025415b523486efdbdac4f2b08c1e
DIFF: https://github.com/llvm/llvm-project/commit/c4e2fcff788025415b523486efdbdac4f2b08c1e.diff
LOG: [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 e9cb50a1e351e90be1a8e4ac1a4564cfc44a984b.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-equality-xor.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 768dc9524353123..9f034aba874a8c4 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -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;
}
diff --git a/llvm/test/Transforms/InstCombine/icmp-equality-xor.ll b/llvm/test/Transforms/InstCombine/icmp-equality-xor.ll
index f9ba74bcbf7b99f..f5d5ef32c81e81c 100644
--- a/llvm/test/Transforms/InstCombine/icmp-equality-xor.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-equality-xor.ll
@@ -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:
More information about the llvm-commits
mailing list