diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 62759b97b571a..397b8f85b3d2e 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -2540,10 +2540,6 @@ SDValue DAGCombiner::visitADDSAT(SDNode *N) { if (isNullConstant(N1)) return N0; - // fold (add_sat x, y) -> (or x, y) for bool types. - if (VT.getScalarType() == MVT::i1) - return DAG.getNode(ISD::OR, DL, VT, N0, N1); - // If it cannot overflow, transform into an add. if (Opcode == ISD::UADDSAT) if (DAG.computeOverflowKind(N0, N1) == SelectionDAG::OFK_Never) @@ -3581,10 +3577,6 @@ SDValue DAGCombiner::visitSUBSAT(SDNode *N) { if (isNullConstant(N1)) return N0; - // fold (sub_sat x, y) -> (and x, ~y) for bool types. - if (VT.getScalarType() == MVT::i1) - return DAG.getNode(ISD::AND, DL, VT, N0, DAG.getNOT(DL, N1, VT)); - return SDValue(); } diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 3fd3e61c49cee..1538d2ac240db 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -5342,6 +5342,14 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT, assert(VT.isInteger() && "This operator does not apply to FP types!"); assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT && "Binary operator types must match!"); + if (VT.isVector() && VT.getVectorElementType() == MVT::i1) { + // fold (add_sat x, y) -> (or x, y) for bool types. + if (Opcode == ISD::SADDSAT || Opcode == ISD::UADDSAT) + return getNode(ISD::OR, DL, VT, N1, N2); + // fold (sub_sat x, y) -> (and x, ~y) for bool types. + if (Opcode == ISD::SSUBSAT || Opcode == ISD::USUBSAT) + return getNode(ISD::AND, DL, VT, N1, getNOT(DL, N2, VT)); + } break; case ISD::SMIN: case ISD::UMAX: