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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 17 06:49:45 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())
----------------
arsenm wrote:

Should be able to check if these bits are 0 without the shift and temporary 

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


More information about the llvm-commits mailing list