[llvm] [DAG] Fold (and X, (add (not Y), Z)) -> (and X, (not (sub Y, Z))). (PR #141476)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 15 06:43:03 PDT 2025


================
@@ -11652,6 +11660,25 @@ SDValue DAGCombiner::foldShiftToAvg(SDNode *N) {
   return DAG.getNode(FloorISD, SDLoc(N), N->getValueType(0), {A, B});
 }
 
+SDValue DAGCombiner::foldBitwiseOpWithNeg(SDNode *N, const SDLoc &DL, EVT VT) {
+  unsigned Opc = N->getOpcode();
+  SDValue X, Y, Z;
+  if (sd_match(N, m_BitwiseLogic(m_Value(X),
+                                 m_Add(m_AllOf(m_Value(Y), m_Not(m_Value(Y))),
+                                       m_Value(Z)))))
+    return DAG.getNode(Opc, DL, VT, X,
+                       DAG.getNOT(DL, DAG.getNode(ISD::SUB, DL, VT, Y, Z), VT));
+
+  if (sd_match(N, m_BitwiseLogic(m_Value(X),
+                                 m_Sub(m_AllOf(m_Value(Y), m_Not(m_Value(Y)),
+                                               m_OneUse(m_Not(m_Value(Y)))),
----------------
RKSimon wrote:

The m_OneUse isn't doing anything as the previous pattern is matching all m_Not cases

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


More information about the llvm-commits mailing list