summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@intel.com>2018-07-19 22:24:43 +0000
committerCraig Topper <craig.topper@intel.com>2018-07-19 22:24:43 +0000
commitc12c5d421fc92a8f689ce0cabc4962f69774d1be (patch)
tree397bd5f5f235ddbe819abdbfb907cd84a1882fb7 /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
parent44edc281d9c3a2845936a0cc27c87ca4b2fb0347 (diff)
downloadbcm5719-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/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp5
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);
OpenPOWER on IntegriCloud