[clang-tools-extra] [InstCombine] Simplify the pattern `a ne/eq (zext (a ne/eq c))` (PR #65852)

via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 18 09:49:33 PDT 2023


================
@@ -6380,7 +6380,56 @@ 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))))) &&
----------------
goldsteinn wrote:

Think it may be worth it to handle `sext` as well. X86 vec compare intrinsics for example expand to `(sext (icmp))`

Think logic is just about exactly the same but the `C->isOne()` case becomes: `isZext ? C->isOne() : C->isAllOnes()`

https://github.com/llvm/llvm-project/pull/65852


More information about the cfe-commits mailing list