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

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 30 12:42:23 PDT 2023


================
@@ -6380,7 +6380,71 @@ Instruction *InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) {
       Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULE)
     return BinaryOperator::CreateOr(Builder.CreateIsNull(X), Y);
 
+  // icmp eq/ne X, (zext/sext (icmp eq/ne X, C))
+  ICmpInst::Predicate Pred1, Pred2;
   const APInt *C;
+  Instruction *ExtI;
+  if (match(&I, m_c_ICmp(Pred1, m_Value(X),
+                         m_CombineAnd(m_Instruction(ExtI),
+                                      m_ZExtOrSExt(m_ICmp(Pred2, m_Deferred(X),
+                                                          m_APInt(C))))))) {
----------------
nikic wrote:

As far as I can tell, nothing here checks that Pred1 and Pred2 are equality predicates, so all the "else" branches below assuming that "else" is eq/ne are wrong? I don't see any negative tests for non-equality predicates either.

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


More information about the cfe-commits mailing list