From c12c5d421fc92a8f689ce0cabc4962f69774d1be Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 19 Jul 2018 22:24:43 +0000 Subject: [DAGCombiner] Teach DAGCombiner that A-(-B) is A+B. We already knew A+(-B) is A-B in visitAdd. This does the opposite for visitSub. llvm-svn: 337502 --- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'llvm/lib') diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index ab712418338..8ec1a3ed9fc 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -2582,6 +2582,11 @@ SDValue DAGCombiner::visitSUB(SDNode *N) { if (isAllOnesConstantOrAllOnesSplatConstant(N0)) return DAG.getNode(ISD::XOR, DL, VT, N1, N0); + // fold (A - (0-B)) -> A+B + if (N1.getOpcode() == ISD::SUB && + isNullConstantOrNullSplatConstant(N1.getOperand(0))) + return DAG.getNode(ISD::ADD, DL, VT, N0, N1.getOperand(1)); + // fold A-(A-B) -> B if (N1.getOpcode() == ISD::SUB && N0 == N1.getOperand(0)) return N1.getOperand(1); -- cgit v1.2.3