Skip to content

Commit b45efac

Browse files
committed
[DAG] Fold (bitwiseop X, (add (not Y), Z)) -> (bitwiseop X, (not (sub Y, Z))).
1 parent eda3e96 commit b45efac

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7528,6 +7528,13 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
75287528
return DAG.getNode(ISD::AND, DL, VT, X,
75297529
DAG.getNOT(DL, DAG.getNode(Opc, DL, VT, Y, Z), VT));
75307530

7531+
// Fold (and X, (add (not Y), Z)) -> (and X, (not (sub Y, Z)))
7532+
if (sd_match(N, m_And(m_Value(X), m_Add(m_Value(NotY), m_Value(Z)))) &&
7533+
sd_match(NotY, m_Not(m_Value(Y))) &&
7534+
(TLI.hasAndNot(SDValue(N, 0)) || NotY->hasOneUse()))
7535+
return DAG.getNode(ISD::AND, DL, VT, X,
7536+
DAG.getNOT(DL, DAG.getNode(ISD::SUB, DL, VT, Y, Z), VT));
7537+
75317538
// Fold (and (srl X, C), 1) -> (srl X, BW-1) for signbit extraction
75327539
// If we are shifting down an extended sign bit, see if we can simplify
75337540
// this to shifting the MSB directly to expose further simplifications.

0 commit comments

Comments
 (0)