Skip to content

Commit 056cf93

Browse files
authored
[DAG] Fold (and X, (bswap/bitreverse (not Y))) -> (and X, (not (bswap/bitreverse Y))) (#112547)
On ANDNOT capable targets we can always do this profitably, without ANDNOT we only attempt this if we don't introduce an additional NOT Fixes #112425
1 parent d6d4569 commit 056cf93

File tree

2 files changed

+505
-189
lines changed

2 files changed

+505
-189
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7353,6 +7353,17 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
73537353
if (SDValue R = foldLogicOfShifts(N, N1, N0, DAG))
73547354
return R;
73557355

7356+
// Fold (and X, (bswap (not Y))) -> (and X, (not (bswap Y)))
7357+
// Fold (and X, (bitreverse (not Y))) -> (and X, (not (bitreverse Y)))
7358+
SDValue X, Y, NotY;
7359+
for (unsigned Opc : {ISD::BSWAP, ISD::BITREVERSE})
7360+
if (sd_match(N,
7361+
m_And(m_Value(X), m_OneUse(m_UnaryOp(Opc, m_Value(NotY))))) &&
7362+
sd_match(NotY, m_Not(m_Value(Y))) &&
7363+
(TLI.hasAndNot(SDValue(N, 0)) || NotY->hasOneUse()))
7364+
return DAG.getNode(ISD::AND, DL, VT, X,
7365+
DAG.getNOT(DL, DAG.getNode(Opc, DL, VT, Y), VT));
7366+
73567367
// Masking the negated extension of a boolean is just the zero-extended
73577368
// boolean:
73587369
// and (sub 0, zext(bool X)), 1 --> zext(bool X)

0 commit comments

Comments
 (0)