[llvm] [PatternMatch] Add `m_c_XorLike` matcher; NFC (PR #122642)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 13 07:22:01 PST 2025


================
@@ -1430,6 +1430,34 @@ m_NUWAddLike(const LHS &L, const RHS &R) {
   return m_CombineOr(m_NUWAdd(L, R), m_DisjointOr(L, R));
 }
 
+template <typename LHS, typename RHS>
+struct XorLike_match {
+  LHS L;
+  RHS R;
+
+  XorLike_match(const LHS &L, const RHS &R) : L(L), R(R) {}
+
+  template <typename OpTy> bool match(OpTy *V) {
+    if (auto *Op = dyn_cast<BinaryOperator>(V)) {
+      if (Op->getOpcode() == Instruction::Sub && Op->hasNoUnsignedWrap() &&
+          PatternMatch::match(Op->getOperand(0), m_LowBitMask()))
+		  ; // Pass
----------------
goldsteinn wrote:

Probably assuming canonicalization. But IMO at least letting `sub` case fall through is simpler codes and could theoretically handle cases.

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


More information about the llvm-commits mailing list