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