[llvm] [IR] Add icmp like matcher (NFC) (PR #192746)

Andreas Jonson via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 18 00:49:03 PDT 2026


================
@@ -2314,6 +2314,35 @@ template <typename OpTy> inline auto m_ZExtOrTruncOrSelf(const OpTy &Op) {
   return m_CombineOr(m_ZExt(Op), m_Trunc(Op), Op);
 }
 
+template <typename LHS_t, typename RHS_t> struct IcmpLike_match {
+  CmpPredicate &Pred;
+  LHS_t L;
+  RHS_t R;
+
+  IcmpLike_match(CmpPredicate &P, const LHS_t &Left, const RHS_t &Right)
+      : Pred(P), L(Left), R(Right) {}
+
+  template <typename OpTy> bool match(OpTy *V) const {
+    if (PatternMatch::match(V, m_ICmp(Pred, L, R)))
+      return true;
+    Value *A;
+    // trunc nuw x to i1 is equivalent to icmp ne x, 0
+    if (V->getType()->isIntOrIntVectorTy(1) &&
----------------
andjo403 wrote:

was thinking of maybe using the pattern instead of this dyn_cast to check if it was icmp like and then the type check is needed but that is maybe not a good way to do it https://github.com/llvm/llvm-project/blob/8872678ae766ed41dd5db2854bc525085e802d34/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp#L1135-L1145 

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


More information about the llvm-commits mailing list