diff options
author | Craig Topper <craig.topper@intel.com> | 2018-07-19 22:24:43 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@intel.com> | 2018-07-19 22:24:43 +0000 |
commit | c12c5d421fc92a8f689ce0cabc4962f69774d1be (patch) | |
tree | 397bd5f5f235ddbe819abdbfb907cd84a1882fb7 /llvm/lib | |
parent | 44edc281d9c3a2845936a0cc27c87ca4b2fb0347 (diff) | |
download | bcm5719-llvm-c12c5d421fc92a8f689ce0cabc4962f69774d1be.tar.gz bcm5719-llvm-c12c5d421fc92a8f689ce0cabc4962f69774d1be.zip |
[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
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
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); |