summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2008-11-21 02:03:52 +0000
committerBill Wendling <isanbard@gmail.com>2008-11-21 02:03:52 +0000
commit74296c60ff44ae8dc251e9e79fd566e6f653c5ac (patch)
treed88390516ec792cafaa9fd946cc1b6c59ed5c5a3 /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
parent45f1ae028e126314db9291280a7a750ae23f7518 (diff)
downloadbcm5719-llvm-74296c60ff44ae8dc251e9e79fd566e6f653c5ac.tar.gz
bcm5719-llvm-74296c60ff44ae8dc251e9e79fd566e6f653c5ac.zip
Implement the sadd_with_overflow intrinsic. This is converted into
"ISD::ADDO". ISD::ADDO is lowered into a target-independent form that does the addition and then checks if the result is less than one of the operands. (If it is, then there was an overflow.) llvm-svn: 59779
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index eb6481c996a..cbb6506b65b 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -190,6 +190,7 @@ namespace {
SDValue visitBUILD_VECTOR(SDNode *N);
SDValue visitCONCAT_VECTORS(SDNode *N);
SDValue visitVECTOR_SHUFFLE(SDNode *N);
+ SDValue visitADDO(SDNode *N);
SDValue XformToShuffleWithZero(SDNode *N);
SDValue ReassociateOps(unsigned Opc, SDValue LHS, SDValue RHS);
@@ -727,6 +728,7 @@ SDValue DAGCombiner::visit(SDNode *N) {
case ISD::BUILD_VECTOR: return visitBUILD_VECTOR(N);
case ISD::CONCAT_VECTORS: return visitCONCAT_VECTORS(N);
case ISD::VECTOR_SHUFFLE: return visitVECTOR_SHUFFLE(N);
+ case ISD::ADDO: return visitADDO(N);
}
return SDValue();
}
@@ -5143,6 +5145,34 @@ SDValue DAGCombiner::visitVECTOR_SHUFFLE(SDNode *N) {
return SDValue();
}
+SDValue DAGCombiner::visitADDO(SDNode *N) {
+ SDValue Chain = N->getOperand(2);
+ SDValue LHS = N->getOperand(0);
+ SDValue RHS = N->getOperand(1);
+
+ SDValue Sum = DAG.getNode(ISD::ADD, LHS.getValueType(), LHS, RHS);
+ AddToWorkList(Sum.getNode());
+ SDValue Cmp = DAG.getSetCC(MVT::i1, Sum, LHS, ISD::SETLT);
+ AddToWorkList(Cmp.getNode());
+
+ MVT ValueVTs[] = { LHS.getValueType(), MVT::i1, MVT::Other };
+ SDValue Ops[] = { Sum, Cmp, Chain };
+
+ SDValue Merge = DAG.getMergeValues(DAG.getVTList(&ValueVTs[0], 3),
+ &Ops[0], 3);
+ SDNode *MNode = Merge.getNode();
+
+ AddToWorkList(MNode);
+ DAG.ReplaceAllUsesOfValueWith(SDValue(N, 0), SDValue(MNode, 0));
+ DAG.ReplaceAllUsesOfValueWith(SDValue(N, 1), SDValue(MNode, 1));
+ DAG.ReplaceAllUsesOfValueWith(SDValue(N, 2), SDValue(MNode, 2));
+
+ // Since the node is now dead, remove it from the graph.
+ removeFromWorkList(N);
+ DAG.DeleteNode(N);
+ return SDValue(N, 0);
+}
+
/// XformToShuffleWithZero - Returns a vector_shuffle if it able to transform
/// an AND to a vector_shuffle with the destination vector and a zero vector.
/// e.g. AND V, <0xffffffff, 0, 0xffffffff, 0>. ==>
OpenPOWER on IntegriCloud