diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2019-01-14 14:16:24 +0000 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2019-01-14 14:16:24 +0000 |
commit | 1a2c188792b0d3d8346eb2301cf1781819de22c2 (patch) | |
tree | e932ba53acf2e49013041f805d023be20b4af32a /llvm/lib/CodeGen/SelectionDAG | |
parent | 2ffed8a14001f81c006315a1ffac947154e93e8e (diff) |
[DAGCombiner] Add add/sub saturation undef handling
Match ConstantFolding.cpp:
(add_sat x, undef) -> -1
(sub_sat x, undef) -> 0
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 6 |
2 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 9a40774cff8..25f2fc66b73 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -2194,6 +2194,10 @@ SDValue DAGCombiner::visitADDSAT(SDNode *N) { return N1; } + // fold (add_sat x, undef) -> -1 + if (N0.isUndef() || N1.isUndef()) + return DAG.getAllOnesConstant(DL, VT); + if (DAG.isConstantIntBuildVectorOrConstantInt(N0)) { // canonicalize constant to RHS if (!DAG.isConstantIntBuildVectorOrConstantInt(N1)) @@ -2792,6 +2796,10 @@ SDValue DAGCombiner::visitSUBSAT(SDNode *N) { return N0; } + // fold (sub_sat x, undef) -> 0 + if (N0.isUndef() || N1.isUndef()) + return DAG.getConstant(0, DL, VT); + // TODO Constant Folding // fold (sub_sat x, 0) -> x diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index a0ee80c0dcd..dc5b5e3123f 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -5180,6 +5180,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT, case ISD::SDIV: case ISD::UREM: case ISD::SREM: + case ISD::SSUBSAT: + case ISD::USUBSAT: return getConstant(0, DL, VT); // fold op(undef, arg2) -> 0 } } @@ -5203,8 +5205,12 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT, return getUNDEF(VT); // fold op(arg1, undef) -> undef case ISD::MUL: case ISD::AND: + case ISD::SSUBSAT: + case ISD::USUBSAT: return getConstant(0, DL, VT); // fold op(arg1, undef) -> 0 case ISD::OR: + case ISD::SADDSAT: + case ISD::UADDSAT: return getAllOnesConstant(DL, VT); } } |