aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-10-11 06:07:15 +0000
committerChris Lattner <sabre@nondot.org>2005-10-11 06:07:15 +0000
commit05b57433e68de3ba0f6eb01f4a0271fee3abeb09 (patch)
tree9064ce74634e581b8826ad99d03b6edc4ba578ab /lib/CodeGen/SelectionDAG/DAGCombiner.cpp
parent04ecf6d65fb5c8703eff8a3dcd5a8208e91318fe (diff)
Add a canonicalization that got lost, fixing PowerPC/fold-li.ll:SUB
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23693 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r--lib/CodeGen/SelectionDAG/DAGCombiner.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index efeee071f0..0098a56a9a 100644
--- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -517,9 +517,11 @@ SDOperand DAGCombiner::visitSUB(SDNode *N) {
if (N0C && N1C)
return DAG.getConstant(N0C->getValue() - N1C->getValue(),
N->getValueType(0));
- // fold (sub x, 0) -> x
- if (N1C && N1C->isNullValue())
- return N0;
+ // fold (sub x, c) -> (add x, -c)
+ if (N1C)
+ return DAG.getNode(ISD::ADD, N0.getValueType(), N0,
+ DAG.getConstant(-N1C->getValue(), N0.getValueType()));
+
// fold (A+B)-A -> B
if (N0.getOpcode() == ISD::ADD && N0.getOperand(0) == N1)
return N0.getOperand(1);