]> granicus.if.org Git - clang/commitdiff
[WebAssembly] abs and sqrt builtins
authorThomas Lively <tlively@google.com>
Fri, 5 Oct 2018 01:02:54 +0000 (01:02 +0000)
committerThomas Lively <tlively@google.com>
Fri, 5 Oct 2018 01:02:54 +0000 (01:02 +0000)
Summary: Depends on D52910.

Reviewers: aheejin, dschuff, craig.topper

Subscribers: sbc100, jgravelle-google, sunfish, kristina, cfe-commits

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

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

include/clang/Basic/BuiltinsWebAssembly.def
lib/CodeGen/CGBuiltin.cpp
test/CodeGen/builtins-wasm.c

index 03032703243cb2ada24185d440debd424e0e3142..494d3cf3ac18c229e3e67e3b253b471103d2895b 100644 (file)
@@ -75,4 +75,10 @@ BUILTIN(__builtin_wasm_all_true_i16x8, "iV8s", "nc")
 BUILTIN(__builtin_wasm_all_true_i32x4, "iV4i", "nc")
 BUILTIN(__builtin_wasm_all_true_i64x2, "iV2LLi", "nc")
 
+BUILTIN(__builtin_wasm_abs_f32x4, "V4fV4f", "nc")
+BUILTIN(__builtin_wasm_abs_f64x2, "V2dV2d", "nc")
+
+BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
+BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
+
 #undef BUILTIN
index 57d7d8b46ef18c14f56db2d716579022bcd669d8..21ed587c7bcb790a22e244f33463437ab124ad94 100644 (file)
@@ -12565,6 +12565,18 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
     Value *Callee = CGM.getIntrinsic(IntNo, Vec->getType());
     return Builder.CreateCall(Callee, {Vec});
   }
+  case WebAssembly::BI__builtin_wasm_abs_f32x4:
+  case WebAssembly::BI__builtin_wasm_abs_f64x2: {
+    Value *Vec = EmitScalarExpr(E->getArg(0));
+    Value *Callee = CGM.getIntrinsic(Intrinsic::fabs, Vec->getType());
+    return Builder.CreateCall(Callee, {Vec});
+  }
+  case WebAssembly::BI__builtin_wasm_sqrt_f32x4:
+  case WebAssembly::BI__builtin_wasm_sqrt_f64x2: {
+    Value *Vec = EmitScalarExpr(E->getArg(0));
+    Value *Callee = CGM.getIntrinsic(Intrinsic::sqrt, Vec->getType());
+    return Builder.CreateCall(Callee, {Vec});
+  }
 
   default:
     return nullptr;
index f92b80700e45142c1a93b2c1c752bdba96a28e8d..0151582395fa81b75faf9df64ea4c5202aadcc19 100644 (file)
@@ -276,3 +276,27 @@ int f40(i64x2 x) {
   // WEBASSEMBLY: call i32 @llvm.wasm.alltrue.v2i64(<2 x i64> %x)
   // WEBASSEMBLY: ret
 }
+
+f32x4 f41(f32x4 x) {
+  return __builtin_wasm_abs_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.fabs.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f42(f64x2 x) {
+  return __builtin_wasm_abs_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}
+
+f32x4 f43(f32x4 x) {
+  return __builtin_wasm_sqrt_f32x4(x);
+  // WEBASSEMBLY: call <4 x float> @llvm.sqrt.v4f32(<4 x float> %x)
+  // WEBASSEMBLY: ret
+}
+
+f64x2 f44(f64x2 x) {
+  return __builtin_wasm_sqrt_f64x2(x);
+  // WEBASSEMBLY: call <2 x double> @llvm.sqrt.v2f64(<2 x double> %x)
+  // WEBASSEMBLY: ret
+}