[llvm] 3560e1d - [DAG] visitADDLike - convert (A-B)+(C-D) --> (A+C)-(B+D) fold to sd_match. NFC.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 15 09:26:40 PDT 2024
Author: Simon Pilgrim
Date: 2024-07-15T17:20:58+01:00
New Revision: 3560e1d0cefa45285f3063c3f74270bcbd744da3
URL: https://github.com/llvm/llvm-project/commit/3560e1d0cefa45285f3063c3f74270bcbd744da3
DIFF: https://github.com/llvm/llvm-project/commit/3560e1d0cefa45285f3063c3f74270bcbd744da3.diff
LOG: [DAG] visitADDLike - convert (A-B)+(C-D) --> (A+C)-(B+D) fold to sd_match. NFC.
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 129a896e105e0..92424722bb0d1 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -2743,7 +2743,7 @@ SDValue DAGCombiner::visitADDLike(SDNode *N) {
return SD;
}
- SDValue A, B, C;
+ SDValue A, B, C, D;
// fold ((0-A) + B) -> B-A
if (sd_match(N0, m_Neg(m_Value(A))))
@@ -2783,18 +2783,12 @@ SDValue DAGCombiner::visitADDLike(SDNode *N) {
return DAG.getNode(N1.getOpcode(), DL, VT, B, C);
// fold (A-B)+(C-D) to (A+C)-(B+D) when A or C is constant
- if (N0.getOpcode() == ISD::SUB && N1.getOpcode() == ISD::SUB &&
- N0->hasOneUse() && N1->hasOneUse()) {
- SDValue N00 = N0.getOperand(0);
- SDValue N01 = N0.getOperand(1);
- SDValue N10 = N1.getOperand(0);
- SDValue N11 = N1.getOperand(1);
-
- if (isConstantOrConstantVector(N00) || isConstantOrConstantVector(N10))
- return DAG.getNode(ISD::SUB, DL, VT,
- DAG.getNode(ISD::ADD, SDLoc(N0), VT, N00, N10),
- DAG.getNode(ISD::ADD, SDLoc(N1), VT, N01, N11));
- }
+ if (sd_match(N0, m_OneUse(m_Sub(m_Value(A), m_Value(B)))) &&
+ sd_match(N1, m_OneUse(m_Sub(m_Value(C), m_Value(D)))) &&
+ (isConstantOrConstantVector(A) || isConstantOrConstantVector(C)))
+ return DAG.getNode(ISD::SUB, DL, VT,
+ DAG.getNode(ISD::ADD, SDLoc(N0), VT, A, C),
+ DAG.getNode(ISD::ADD, SDLoc(N1), VT, B, D));
// fold (add (umax X, C), -C) --> (usubsat X, C)
if (N0.getOpcode() == ISD::UMAX && hasOperation(ISD::USUBSAT, VT)) {
More information about the llvm-commits
mailing list