Skip to content

Commit ca9a44e

Browse files
committed
[DAG] visitORCommutative - use sd_match to reduce the need for commutative operand matching. NFCI.
Use sd_match to match commutative inner AND/OR/XOR node arguments instead of some messy manual matching of each commutation.
1 parent bd84f5d commit ca9a44e

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7655,23 +7655,17 @@ static SDValue visitORCommutative(SelectionDAG &DAG, SDValue N0, SDValue N1,
76557655
}
76567656
}
76577657

7658-
if (N0.getOpcode() == ISD::XOR) {
7659-
// fold or (xor x, y), x --> or x, y
7660-
// or (xor x, y), (x and/or y) --> or x, y
7661-
SDValue N00 = N0.getOperand(0);
7662-
SDValue N01 = N0.getOperand(1);
7663-
if (N00 == N1)
7664-
return DAG.getNode(ISD::OR, SDLoc(N), VT, N01, N1);
7665-
if (N01 == N1)
7666-
return DAG.getNode(ISD::OR, SDLoc(N), VT, N00, N1);
7658+
SDValue X, Y;
76677659

7668-
if (N1.getOpcode() == ISD::AND || N1.getOpcode() == ISD::OR) {
7669-
SDValue N10 = N1.getOperand(0);
7670-
SDValue N11 = N1.getOperand(1);
7671-
if ((N00 == N10 && N01 == N11) || (N00 == N11 && N01 == N10))
7672-
return DAG.getNode(ISD::OR, SDLoc(N), VT, N00, N01);
7673-
}
7674-
}
7660+
// fold or (xor X, N1), N1 --> or X, N1
7661+
if (sd_match(N0, m_Xor(m_Value(X), m_Specific(N1))))
7662+
return DAG.getNode(ISD::OR, SDLoc(N), VT, X, N1);
7663+
7664+
// fold or (xor x, y), (x and/or y) --> or x, y
7665+
if (sd_match(N0, m_Xor(m_Value(X), m_Value(Y))) &&
7666+
(sd_match(N1, m_And(m_Specific(X), m_Specific(Y))) ||
7667+
sd_match(N1, m_Or(m_Specific(X), m_Specific(Y)))))
7668+
return DAG.getNode(ISD::OR, SDLoc(N), VT, X, Y);
76757669

76767670
if (SDValue R = foldLogicOfShifts(N, N0, N1, DAG))
76777671
return R;

0 commit comments

Comments
 (0)