[llvm] [IR] Add icmp like matcher (NFC) (PR #192746)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 18 00:20:42 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) &&
+ PatternMatch::match(V, m_NUWTrunc(m_Value(A))) && L.match(A) &&
+ R.match(ConstantInt::getNullValue(A->getType()))) {
+ Pred = ICmpInst::ICMP_NE;
+ return true;
+ }
+ return false;
+ }
+};
+
+template <typename LHS, typename RHS>
+inline IcmpLike_match<LHS, RHS> m_IcmpLike(CmpPredicate &Pred, const LHS &L,
----------------
dtcxzyw wrote:
```suggestion
inline IcmpLike_match<LHS, RHS> m_ICmpLike(CmpPredicate &Pred, const LHS &L,
```
https://github.com/llvm/llvm-project/pull/192746
More information about the llvm-commits
mailing list