Skip to content

Commit f7b5f0c

Browse files
committed
[DAG] Fold (and X, (rot (not Y), Z)) -> (and X, (not (rot Y, Z)))
On ANDNOT capable targets we can always do this profitably, without ANDNOT we only attempt this if we don't introduce an additional NOT Followup to #112547
1 parent 0394888 commit f7b5f0c

File tree

2 files changed

+314
-160
lines changed

2 files changed

+314
-160
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7355,7 +7355,7 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
73557355

73567356
// Fold (and X, (bswap (not Y))) -> (and X, (not (bswap Y)))
73577357
// Fold (and X, (bitreverse (not Y))) -> (and X, (not (bitreverse Y)))
7358-
SDValue X, Y, NotY;
7358+
SDValue X, Y, Z, NotY;
73597359
for (unsigned Opc : {ISD::BSWAP, ISD::BITREVERSE})
73607360
if (sd_match(N,
73617361
m_And(m_Value(X), m_OneUse(m_UnaryOp(Opc, m_Value(NotY))))) &&
@@ -7364,6 +7364,15 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
73647364
return DAG.getNode(ISD::AND, DL, VT, X,
73657365
DAG.getNOT(DL, DAG.getNode(Opc, DL, VT, Y), VT));
73667366

7367+
// Fold (and X, (rot (not Y), Z)) -> (and X, (not (rot Y, Z)))
7368+
for (unsigned Opc : {ISD::ROTL, ISD::ROTR})
7369+
if (sd_match(N, m_And(m_Value(X),
7370+
m_OneUse(m_BinOp(Opc, m_Value(NotY), m_Value(Z))))) &&
7371+
sd_match(NotY, m_Not(m_Value(Y))) &&
7372+
(TLI.hasAndNot(SDValue(N, 0)) || NotY->hasOneUse()))
7373+
return DAG.getNode(ISD::AND, DL, VT, X,
7374+
DAG.getNOT(DL, DAG.getNode(Opc, DL, VT, Y, Z), VT));
7375+
73677376
// Masking the negated extension of a boolean is just the zero-extended
73687377
// boolean:
73697378
// and (sub 0, zext(bool X)), 1 --> zext(bool X)

0 commit comments

Comments
 (0)