diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2019-01-14 15:28:53 +0000 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2019-01-14 15:28:53 +0000 |
commit | fa1f5187482c12e949953e0b65f652af022e9d43 (patch) | |
tree | 6baa0fa0324258e5b713017efdc58512e62460db /llvm/lib | |
parent | 8c2e9e1fef3b9f7cf82e1463ae46a460c2bb73f5 (diff) | |
download | bcm5719-llvm-fa1f5187482c12e949953e0b65f652af022e9d43.tar.gz bcm5719-llvm-fa1f5187482c12e949953e0b65f652af022e9d43.zip |
[DAGCombiner] Enable sub saturation constant folding
llvm-svn: 351072
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 25f2fc66b73..d564bda7987 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -2800,7 +2800,12 @@ SDValue DAGCombiner::visitSUBSAT(SDNode *N) { if (N0.isUndef() || N1.isUndef()) return DAG.getConstant(0, DL, VT); - // TODO Constant Folding + if (DAG.isConstantIntBuildVectorOrConstantInt(N0) && + DAG.isConstantIntBuildVectorOrConstantInt(N1)) { + // fold (sub_sat c1, c2) -> c3 + return DAG.FoldConstantArithmetic(N->getOpcode(), DL, VT, N0.getNode(), + N1.getNode()); + } // fold (sub_sat x, 0) -> x if (isNullConstant(N1)) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index dc5b5e3123f..07ad9c7ce1b 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -4490,6 +4490,8 @@ static std::pair<APInt, bool> FoldValue(unsigned Opcode, const APInt &C1, case ISD::UMAX: return std::make_pair(C1.uge(C2) ? C1 : C2, true); case ISD::SADDSAT: return std::make_pair(C1.sadd_sat(C2), true); case ISD::UADDSAT: return std::make_pair(C1.uadd_sat(C2), true); + case ISD::SSUBSAT: return std::make_pair(C1.ssub_sat(C2), true); + case ISD::USUBSAT: return std::make_pair(C1.usub_sat(C2), true); case ISD::UDIV: if (!C2.getBoolValue()) break; |