[llvm] ca9a44e - [DAG] visitORCommutative - use sd_match to reduce the need for commutative operand matching. NFCI.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 22 02:42:13 PDT 2024
Author: Simon Pilgrim
Date: 2024-04-22T10:41:57+01:00
New Revision: ca9a44ef4791931fe77d123709fa1a9d18f827fd
URL: https://github.com/llvm/llvm-project/commit/ca9a44ef4791931fe77d123709fa1a9d18f827fd
DIFF: https://github.com/llvm/llvm-project/commit/ca9a44ef4791931fe77d123709fa1a9d18f827fd.diff
LOG: [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.
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 0c3eb3cabc885f..e6e0a1fc7d8277 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -7655,23 +7655,17 @@ static SDValue visitORCommutative(SelectionDAG &DAG, SDValue N0, SDValue N1,
}
}
- if (N0.getOpcode() == ISD::XOR) {
- // fold or (xor x, y), x --> or x, y
- // or (xor x, y), (x and/or y) --> or x, y
- SDValue N00 = N0.getOperand(0);
- SDValue N01 = N0.getOperand(1);
- if (N00 == N1)
- return DAG.getNode(ISD::OR, SDLoc(N), VT, N01, N1);
- if (N01 == N1)
- return DAG.getNode(ISD::OR, SDLoc(N), VT, N00, N1);
+ SDValue X, Y;
- if (N1.getOpcode() == ISD::AND || N1.getOpcode() == ISD::OR) {
- SDValue N10 = N1.getOperand(0);
- SDValue N11 = N1.getOperand(1);
- if ((N00 == N10 && N01 == N11) || (N00 == N11 && N01 == N10))
- return DAG.getNode(ISD::OR, SDLoc(N), VT, N00, N01);
- }
- }
+ // fold or (xor X, N1), N1 --> or X, N1
+ if (sd_match(N0, m_Xor(m_Value(X), m_Specific(N1))))
+ return DAG.getNode(ISD::OR, SDLoc(N), VT, X, N1);
+
+ // fold or (xor x, y), (x and/or y) --> or x, y
+ if (sd_match(N0, m_Xor(m_Value(X), m_Value(Y))) &&
+ (sd_match(N1, m_And(m_Specific(X), m_Specific(Y))) ||
+ sd_match(N1, m_Or(m_Specific(X), m_Specific(Y)))))
+ return DAG.getNode(ISD::OR, SDLoc(N), VT, X, Y);
if (SDValue R = foldLogicOfShifts(N, N0, N1, DAG))
return R;
More information about the llvm-commits
mailing list