Commit 905abe5b authored by Leonard Chan's avatar Leonard Chan
Browse files

[Intrinsic] Signed and Unsigned Saturation Subtraction Intirnsics

Add an intrinsic that takes 2 integers and perform saturation subtraction on
them.

This is a part of implementing fixed point arithmetic in clang where some of
the more complex operations will be implemented as intrinsics.

Differential Revision: https://reviews.llvm.org/D53783

llvm-svn: 345512
parent 71c989ae
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -264,6 +264,14 @@ namespace ISD {
    /// resulting value is this minimum value.
    SADDSAT, UADDSAT,

    /// RESULT = [US]SUBSAT(LHS, RHS) - Perform saturation subtraction on 2
    /// integers with the same bit width (W). If the true value of LHS - RHS
    /// exceeds the largest value that can be represented by W bits, the
    /// resulting value is this maximum value. Otherwise, if this value is less
    /// than the smallest value that can be represented by W bits, the
    /// resulting value is this minimum value.
    SSUBSAT, USUBSAT,

    /// Simple binary floating point operators.
    FADD, FSUB, FMUL, FDIV, FREM,

+4 −3
Original line number Diff line number Diff line
@@ -3736,9 +3736,10 @@ public:
  SDValue getVectorElementPointer(SelectionDAG &DAG, SDValue VecPtr, EVT VecVT,
                                  SDValue Index) const;

  /// Method for building the DAG expansion of ISD::[US]ADDSAT. This method
  /// accepts integers or vectors of integers as its arguments.
  SDValue getExpandedSaturationAddition(SDNode *Node, SelectionDAG &DAG) const;
  /// Method for building the DAG expansion of ISD::[US][ADD|SUB]SAT. This
  /// method accepts integers or vectors of integers as its arguments.
  SDValue getExpandedSaturationAdditionSubtraction(SDNode *Node,
                                                   SelectionDAG &DAG) const;

  //===--------------------------------------------------------------------===//
  // Instruction Emitting Hooks
+6 −0
Original line number Diff line number Diff line
@@ -716,6 +716,12 @@ def int_sadd_sat : Intrinsic<[llvm_anyint_ty],
def int_uadd_sat : Intrinsic<[llvm_anyint_ty],
                             [LLVMMatchType<0>, LLVMMatchType<0>],
                             [IntrNoMem, IntrSpeculatable, Commutative]>;
def int_ssub_sat : Intrinsic<[llvm_anyint_ty],
                             [LLVMMatchType<0>, LLVMMatchType<0>],
                             [IntrNoMem, IntrSpeculatable]>;
def int_usub_sat : Intrinsic<[llvm_anyint_ty],
                             [LLVMMatchType<0>, LLVMMatchType<0>],
                             [IntrNoMem, IntrSpeculatable]>;

//===------------------------- Memory Use Markers -------------------------===//
//
+2 −0
Original line number Diff line number Diff line
@@ -375,6 +375,8 @@ def umax : SDNode<"ISD::UMAX" , SDTIntBinOp,

def saddsat    : SDNode<"ISD::SADDSAT"   , SDTIntBinOp, [SDNPCommutative]>;
def uaddsat    : SDNode<"ISD::UADDSAT"   , SDTIntBinOp, [SDNPCommutative]>;
def ssubsat    : SDNode<"ISD::SSUBSAT"   , SDTIntBinOp>;
def usubsat    : SDNode<"ISD::USUBSAT"   , SDTIntBinOp>;

def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
def sext_invec : SDNode<"ISD::SIGN_EXTEND_VECTOR_INREG", SDTExtInvec>;
+7 −3
Original line number Diff line number Diff line
@@ -1115,7 +1115,9 @@ void SelectionDAGLegalize::LegalizeOp(SDNode *Node) {
                                            Node->getValueType(0));
    break;
  case ISD::SADDSAT:
  case ISD::UADDSAT: {
  case ISD::UADDSAT:
  case ISD::SSUBSAT:
  case ISD::USUBSAT: {
    Action = TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0));
    break;
  }
@@ -3254,8 +3256,10 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
    break;
  }
  case ISD::SADDSAT:
  case ISD::UADDSAT: {
    Results.push_back(TLI.getExpandedSaturationAddition(Node, DAG));
  case ISD::UADDSAT:
  case ISD::SSUBSAT:
  case ISD::USUBSAT: {
    Results.push_back(TLI.getExpandedSaturationAdditionSubtraction(Node, DAG));
    break;
  }
  case ISD::SADDO:
Loading