diff --git a/docs/LangRef.html b/docs/LangRef.html index 1f43ab67f24..f13f13909bc 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -277,6 +277,11 @@
  • 'llvm.umul.with.overflow.* Intrinsics
  • +
  • Specialised Arithmetic Intrinsics +
      +
    1. 'llvm.fmuladd Intrinsic
    2. +
    +
  • Half Precision Floating Point Intrinsics
    1. 'llvm.convert.to.fp16' Intrinsic
    2. @@ -7945,6 +7950,52 @@ LLVM.

      + +

      + Specialised Arithmetic Intrinsics +

      + + + +

      + 'llvm.fmuladd.*' Intrinsic +

      + +
      + +
      Syntax:
      +
      +  declare float @llvm.fmuladd.f32(float %a, float %b, float %c)
      +  declare double @llvm.fmuladd.f64(double %a, double %b, double %c)
      +
      + +
      Overview:
      +

      The 'llvm.fmuladd.*' intrinsic functions represent multiply-add +expressions that can be fused if the code generator determines that the fused +expression would be legal and efficient.

      + +
      Arguments:
      +

      The 'llvm.fmuladd.*' intrinsics each take three arguments: two +multiplicands, a and b, and an addend c.

      + +
      Semantics:
      +

      The expression:

      +
      +  %0 = call float @llvm.fmuladd.f32(%a, %b, %c)
      +
      +

      is equivalent to the expression a * b + c, except that rounding will not be +performed between the multiplication and addition steps if the code generator +fuses the operations. Fusion is not guaranteed, even if the target platform +supports it. If a fused multiply-add is required the corresponding llvm.fma.* +intrinsic function should be used instead.

      + +
      Examples:
      +
      +  %r2 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) ; yields {float}:r2 = (a * b) + c
      +
      + +
      +

      Half Precision Floating Point Intrinsics diff --git a/include/llvm/Intrinsics.td b/include/llvm/Intrinsics.td index 01d2cca47a6..e2be4c4f6ab 100644 --- a/include/llvm/Intrinsics.td +++ b/include/llvm/Intrinsics.td @@ -266,6 +266,10 @@ let Properties = [IntrNoMem] in { def int_fma : Intrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>]>; + + def int_fmuladd : Intrinsic<[llvm_anyfloat_ty], + [LLVMMatchType<0>, LLVMMatchType<0>, + LLVMMatchType<0>]>; } // NOTE: these are internal interfaces. diff --git a/include/llvm/Target/TargetLowering.h b/include/llvm/Target/TargetLowering.h index 27447b5df7b..915dd9d4e8e 100644 --- a/include/llvm/Target/TargetLowering.h +++ b/include/llvm/Target/TargetLowering.h @@ -1657,6 +1657,14 @@ public: return false; } + /// isFMAFasterThanMulAndAdd - Return true if an FMA operation is faster than + /// a pair of mul and add instructions. fmuladd intrinsics will be expanded to + /// FMAs when this method returns true (and FMAs are legal), otherwise fmuladd + /// is expanded to mul + add. + virtual bool isFMAFasterThanMulAndAdd(EVT) const { + return false; + } + /// isNarrowingProfitable - Return true if it's profitable to narrow /// operations of type VT1 to VT2. e.g. on x86, it's profitable to narrow /// from i32 to i8 but not from i32 to i16. diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index ab3ce48aacb..4152aa1ae16 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -4932,6 +4932,27 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) { getValue(I.getArgOperand(1)), getValue(I.getArgOperand(2)))); return 0; + case Intrinsic::fmuladd: { + EVT VT = TLI.getValueType(I.getType()); + if (TLI.isOperationLegal(ISD::FMA, VT) && TLI.isFMAFasterThanMulAndAdd(VT)){ + setValue(&I, DAG.getNode(ISD::FMA, dl, + getValue(I.getArgOperand(0)).getValueType(), + getValue(I.getArgOperand(0)), + getValue(I.getArgOperand(1)), + getValue(I.getArgOperand(2)))); + } else { + SDValue Mul = DAG.getNode(ISD::FMUL, dl, + getValue(I.getArgOperand(0)).getValueType(), + getValue(I.getArgOperand(0)), + getValue(I.getArgOperand(1))); + SDValue Add = DAG.getNode(ISD::FADD, dl, + getValue(I.getArgOperand(0)).getValueType(), + Mul, + getValue(I.getArgOperand(2))); + setValue(&I, Add); + } + return 0; + } case Intrinsic::convert_to_fp16: setValue(&I, DAG.getNode(ISD::FP32_TO_FP16, dl, MVT::i16, getValue(I.getArgOperand(0))));