[llvm] [InstCombine] Generalize sub(C, or(X, C)) --> and(X, ~C) fold (PR #202274)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 17 07:59:43 PDT 2026


================
@@ -2438,6 +2438,18 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
     }
   }
 
+  {
+    const APInt *C, *OrC;
+    Value *X;
+    if (match(Op0, m_APInt(C)) &&
+        match(Op1, m_OneUse(m_Or(m_Value(X), m_APInt(OrC)))) && *OrC == *C) {
+      APInt NotC = ~*C;
+      if ((NotC << 1).isZero())
----------------
mygitljf wrote:

Thanks! I’ve updated this to check the APInt predicates directly, removing both the shift and the temporary.

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


More information about the llvm-commits mailing list