@@ -7353,6 +7353,21 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
73537353 if (SDValue R = foldLogicOfShifts(N, N1, N0, DAG))
73547354 return R;
73557355
7356+ // If the target supports ANDNOT, attempt to reconstruct an ANDNOT pattern
7357+ // that might have become separated by a bitwise-agnostic instruction.
7358+ if (TLI.hasAndNot(SDValue(N, 0))) {
7359+ SDValue X, Y;
7360+
7361+ // Fold (and X, (bswap (not Y))) -> (and X, (not (bswap Y)))
7362+ // Fold (and X, (bitreverse (not Y))) -> (and X, (not (bitreverse Y)))
7363+ for (unsigned Opc : {ISD::BSWAP, ISD::BITREVERSE})
7364+ if (sd_match(N, m_And(m_Value(X),
7365+ m_OneUse(m_UnaryOp(Opc, m_Not(m_Value(Y)))))) &&
7366+ !sd_match(X, m_Not(m_Value())))
7367+ return DAG.getNode(ISD::AND, DL, VT, X,
7368+ DAG.getNOT(DL, DAG.getNode(Opc, DL, VT, Y), VT));
7369+ }
7370+
73567371 // Masking the negated extension of a boolean is just the zero-extended
73577372 // boolean:
73587373 // and (sub 0, zext(bool X)), 1 --> zext(bool X)
0 commit comments