[llvm] [InstCombine] Simplify the pattern `a ne/eq (zext (a ne/eq c))` (PR #65852)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 14 23:23:54 PDT 2023
================
@@ -6309,7 +6309,69 @@ Instruction *InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) {
Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULE)
return BinaryOperator::CreateOr(Builder.CreateIsNull(X), Y);
+ ICmpInst::Predicate Pred1, Pred2;
const APInt *C;
+ // icmp eq/ne X, (zext (icmp eq/ne X, C))
+ if (match(&I, m_c_ICmp(Pred1, m_Value(X),
+ m_ZExt(m_ICmp(Pred2, m_Deferred(X), m_APInt(C))))) &&
+ ICmpInst::isEquality(Pred1) && ICmpInst::isEquality(Pred2)) {
+ if (C->isZero()) {
+ if (Pred2 == ICmpInst::ICMP_EQ) {
+ // icmp eq X, (zext (icmp eq X, 0)) --> false
+ // icmp ne X, (zext (icmp eq X, 0)) --> true
+ return replaceInstUsesWith(
+ I,
+ Constant::getIntegerValue(
+ I.getType(),
+ APInt(1U, static_cast<uint64_t>(Pred1 == ICmpInst::ICMP_NE))));
----------------
nikic wrote:
```suggestion
ConstantInt::getBool(
I.getType(), Pred1 == ICmpInst::ICMP_NE)));
```
etc
https://github.com/llvm/llvm-project/pull/65852
More information about the llvm-commits
mailing list