[WebAssembly] Implement fma.
authorDan Gohman <dan433584@gmail.com>
Thu, 10 Dec 2015 04:52:33 +0000 (04:52 +0000)
committerDan Gohman <dan433584@gmail.com>
Thu, 10 Dec 2015 04:52:33 +0000 (04:52 +0000)
It is lowered to a libcall for now, but this is expected to change in the future.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255219 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
test/CodeGen/WebAssembly/f32.ll
test/CodeGen/WebAssembly/f64.ll

index fae10947ec6b37aef4199705aaa5f4dfefa08ebe..4ef0846d311a2a0f31e2984747b5ddc460d9a155 100644 (file)
@@ -134,7 +134,7 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
       setCondCodeAction(CC, T, Expand);
     // Expand floating-point library function operators.
     for (auto Op : {ISD::FSIN, ISD::FCOS, ISD::FSINCOS, ISD::FPOWI, ISD::FPOW,
       setCondCodeAction(CC, T, Expand);
     // Expand floating-point library function operators.
     for (auto Op : {ISD::FSIN, ISD::FCOS, ISD::FSINCOS, ISD::FPOWI, ISD::FPOW,
-                    ISD::FREM})
+                    ISD::FREM, ISD::FMA})
       setOperationAction(Op, T, Expand);
     // Note supported floating-point library function operators that otherwise
     // default to expand.
       setOperationAction(Op, T, Expand);
     // Note supported floating-point library function operators that otherwise
     // default to expand.
index a15b37beab84bdb68da47770a7c94f09aa6c1ddf..10fe1856037961fff73235498e36a3ce35a758a5 100644 (file)
@@ -13,6 +13,7 @@ declare float @llvm.floor.f32(float)
 declare float @llvm.trunc.f32(float)
 declare float @llvm.nearbyint.f32(float)
 declare float @llvm.rint.f32(float)
 declare float @llvm.trunc.f32(float)
 declare float @llvm.nearbyint.f32(float)
 declare float @llvm.rint.f32(float)
+declare float @llvm.fma.f32(float, float, float)
 
 ; CHECK-LABEL: fadd32:
 ; CHECK-NEXT: .param f32, f32{{$}}
 
 ; CHECK-LABEL: fadd32:
 ; CHECK-NEXT: .param f32, f32{{$}}
@@ -143,3 +144,11 @@ define float @fmax32(float %x) {
   %b = select i1 %a, float %x, float 0.0
   ret float %b
 }
   %b = select i1 %a, float %x, float 0.0
   ret float %b
 }
+
+; CHECK-LABEL: fma32:
+; CHECK: call $push0=, fmaf, $0, $1, $2{{$}}
+; CHECK-NEXT: return $pop0{{$}}
+define float @fma32(float %a, float %b, float %c) {
+  %d = call float @llvm.fma.f32(float %a, float %b, float %c)
+  ret float %d
+}
index 1407f713b48070eb402b7a3b400c21608cf38fd6..51eb33790a9e6020d3960a3031eb5d40827284df 100644 (file)
@@ -13,6 +13,7 @@ declare double @llvm.floor.f64(double)
 declare double @llvm.trunc.f64(double)
 declare double @llvm.nearbyint.f64(double)
 declare double @llvm.rint.f64(double)
 declare double @llvm.trunc.f64(double)
 declare double @llvm.nearbyint.f64(double)
 declare double @llvm.rint.f64(double)
+declare double @llvm.fma.f64(double, double, double)
 
 ; CHECK-LABEL: fadd64:
 ; CHECK-NEXT: .param f64, f64{{$}}
 
 ; CHECK-LABEL: fadd64:
 ; CHECK-NEXT: .param f64, f64{{$}}
@@ -143,3 +144,11 @@ define double @fmax64(double %x) {
   %b = select i1 %a, double %x, double 0.0
   ret double %b
 }
   %b = select i1 %a, double %x, double 0.0
   ret double %b
 }
+
+; CHECK-LABEL: fma64:
+; CHECK: call $push0=, fma, $0, $1, $2{{$}}
+; CHECK-NEXT: return $pop0{{$}}
+define double @fma64(double %a, double %b, double %c) {
+  %d = call double @llvm.fma.f64(double %a, double %b, double %c)
+  ret double %d
+}