[llvm] e9cb50a - [InstCombine] Fix infinite loop in #67273
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 29 05:27:17 PDT 2023
Author: Yingwei Zheng
Date: 2023-09-29T20:26:39+08:00
New Revision: e9cb50a1e351e90be1a8e4ac1a4564cfc44a984b
URL: https://github.com/llvm/llvm-project/commit/e9cb50a1e351e90be1a8e4ac1a4564cfc44a984b
DIFF: https://github.com/llvm/llvm-project/commit/e9cb50a1e351e90be1a8e4ac1a4564cfc44a984b.diff
LOG: [InstCombine] Fix infinite loop in #67273
Closes #67783.
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 091f7e1a6b74289..768dc9524353123 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -5450,8 +5450,16 @@ 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))))
- return new ICmpInst(Pred, Builder.CreateXor(A, B), 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);
+ }
return nullptr;
}
diff --git a/llvm/test/Transforms/InstCombine/icmp-equality-xor.ll b/llvm/test/Transforms/InstCombine/icmp-equality-xor.ll
index 89ac2da2f6d1df5..f9ba74bcbf7b99f 100644
--- a/llvm/test/Transforms/InstCombine/icmp-equality-xor.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-equality-xor.ll
@@ -131,3 +131,16 @@ define i1 @foo2(i32 %x, i32 %y) {
%cmp = icmp eq i32 %and, %and1
ret i1 %cmp
}
+
+; tests from PR67783
+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: ret <2 x i1> [[CMP]]
+;
+entry:
+ %xor = xor <2 x i8> %x, <i8 -2, i8 -1>
+ %cmp = icmp ne <2 x i8> %xor, <i8 9, i8 79>
+ ret <2 x i1> %cmp
+}
More information about the llvm-commits
mailing list