[PATCH 1/1] DAGCombiner: Add (A - (0-B)) -> A+B optimization
Jan Vesely
jan.vesely at rutgers.edu
Tue Sep 23 11:57:32 PDT 2014
Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
---
lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 33e7059..bc39fe3 100644
--- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -1794,6 +1794,10 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
// fold (A+B)-B -> A
if (N0.getOpcode() == ISD::ADD && N0.getOperand(1) == N1)
return N0.getOperand(0);
+ // fold (A - (0-B)) -> A+B
+ if (N1.getOpcode() == ISD::SUB && isa<ConstantSDNode>(N1.getOperand(0)) &&
+ cast<ConstantSDNode>(N1.getOperand(0))->isNullValue())
+ return DAG.getNode(ISD::ADD, SDLoc(N), VT, N0, N1.getOperand(1));
// fold C2-(A+C1) -> (C2-C1)-A
if (N1.getOpcode() == ISD::ADD && N0C && N1C1) {
SDValue NewC = DAG.getConstant(N0C->getAPIntValue() - N1C1->getAPIntValue(),
--
1.9.3
More information about the llvm-commits
mailing list