[llvm] [DAG] Fold (and X, (bswap/bitreverse (not Y))) -> (and X, (not (bswap/bitreverse Y))) on ANDNOT capable targets (PR #112547)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 18 10:39:17 PDT 2024


================
@@ -7350,6 +7350,17 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
   if (SDValue R = foldLogicOfShifts(N, N1, N0, DAG))
     return R;
 
+  // Fold (and X, (bswap (not Y))) -> (and X, (not (bswap Y)))
+  // Fold (and X, (bitreverse (not Y))) -> (and X, (not (bitreverse Y)))
+  SDValue X, Y, NotY;
+  for (unsigned Opc : {ISD::BSWAP, ISD::BITREVERSE})
+    if (sd_match(N,
+                 m_And(m_Value(X), m_OneUse(m_UnaryOp(Opc, m_Value(NotY))))) &&
+        sd_match(NotY, m_Not(m_Value(Y))) &&
+        (TLI.hasAndNot(SDValue(N, 0)) || NotY->hasOneUse()))
----------------
goldsteinn wrote:

Maybe should be `|| (NotY->hasOneUse() && sd_match(X, m_Not(m_Value()))`

There is a lot of diff from just re-assosiating the not which seems netural.

No strong opinion, however.

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


More information about the llvm-commits mailing list