[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
Tue Jun 3 05:53:45 PDT 2025


================
@@ -11609,6 +11617,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, NotY;
+  if (sd_match(N, m_BitwiseLogic(m_Value(X), m_Add(m_AllOf(m_Value(NotY),
+                                                           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(NotY),
+                                                           m_Not(m_Value(Y))),
----------------
RKSimon wrote:

can you do m_OneUse(m_Not(m_Value(Y)))) and drop the NotY->hasOneUse()? Would that then allow you to remove NotY entirely?

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


More information about the llvm-commits mailing list